@siberiacancode/reactuse 0.2.24 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +23 -17
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +38 -29
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +18 -18
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +21 -2
- package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +2 -0
- package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +2 -2
- package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -1
- package/dist/types/utils/helpers/getElement.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),v=require("../useRefState/useRefState.cjs"),d=require("../../utils/helpers/isTarget.cjs"),m=require("../../utils/helpers/getElement.cjs"),E=(...s)=>{const t=d.isTarget(s[0])?s[0]:void 0,[o,i]=l.useState(null),n=v.useRefState(window);return l.useEffect(()=>{if(!t&&!n.state)return;const e=t?m.getElement(t):n.current;if(!e)return;const c=new MutationObserver(f=>{f.filter(r=>r.removedNodes.length).map(r=>Array.from(r.removedNodes)).flat().forEach(r=>{i(a=>r===a?document.activeElement:a)})});c.observe(e,{childList:!0,subtree:!0});const u=()=>i(document?.activeElement);return e.addEventListener("focus",u,!0),e.addEventListener("blur",u,!0),()=>{c.disconnect(),e.removeEventListener("focus",u,!0),e.removeEventListener("blur",u,!0)}},[t,n.state]),t?o:{ref:n,value:o}};exports.useActiveElement=E;
|
|
2
2
|
//# sourceMappingURL=useActiveElement.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement =
|
|
1
|
+
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.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\nexport interface UseActiveElement {\n (): HTMLElement | null;\n\n <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(\n target?: never\n ): {\n ref: StateRef<Target>;\n value: ActiveElement | null;\n };\n\n <ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;\n}\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to observe active element changes\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement(ref);\n *\n * @overload\n * @template ActiveElement The active element type\n * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element\n *\n * @example\n * const { ref, value } = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const [value, setValue] = useState<HTMLElement | null>(null);\n const internalRef = useRefState(window);\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 observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setValue((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as HTMLElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(element, {\n childList: true,\n subtree: true\n });\n\n const onActiveElementChange = () => setValue(document?.activeElement as HTMLElement | null);\n\n element.addEventListener('focus', onActiveElementChange, true);\n element.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n observer.disconnect();\n element.removeEventListener('focus', onActiveElementChange, true);\n element.removeEventListener('blur', onActiveElementChange, true);\n };\n }, [target, internalRef.state]);\n\n if (target) return value;\n return {\n ref: internalRef,\n value\n };\n}) as UseActiveElement;\n"],"names":["useActiveElement","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","element","getElement","observer","mutations","mutation","node","prevActiveElement","onActiveElementChange"],"mappings":"mPA4CaA,EAAoB,IAAIC,IAAkB,CACrD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5C,CAACG,EAAOC,CAAQ,EAAIC,EAAAA,SAA6B,IAAI,EACrDC,EAAcC,EAAAA,YAAY,MAAM,EAsCtC,OApCAC,EAAAA,UAAU,IAAM,CACd,GAAI,CAACP,GAAU,CAACK,EAAY,MAAO,OAEnC,MAAMG,EAAWR,EAASS,EAAAA,WAAWT,CAAM,EAAIK,EAAY,QAC3D,GAAI,CAACG,EAAS,OAEd,MAAME,EAAW,IAAI,iBAAkBC,GAAc,CACnDA,EACG,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBV,EAAUW,GACJD,IAASC,EAA0B,SAAS,cACzCA,CACR,CAAA,CACF,CAAA,CACJ,EAEDJ,EAAS,QAAQF,EAAS,CACxB,UAAW,GACX,QAAS,EAAA,CACV,EAED,MAAMO,EAAwB,IAAMZ,EAAS,UAAU,aAAmC,EAE1F,OAAAK,EAAQ,iBAAiB,QAASO,EAAuB,EAAI,EAC7DP,EAAQ,iBAAiB,OAAQO,EAAuB,EAAI,EAErD,IAAM,CACXL,EAAS,WAAA,EACTF,EAAQ,oBAAoB,QAASO,EAAuB,EAAI,EAChEP,EAAQ,oBAAoB,OAAQO,EAAuB,EAAI,CAAA,CACjE,EACC,CAACf,EAAQK,EAAY,KAAK,CAAC,EAE1BL,EAAeE,EACZ,CACL,IAAKG,EACL,MAAAH,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react"),m=require("../useRefState/useRefState.cjs"),R=require("../../utils/helpers/isTarget.cjs"),q=require("../../utils/helpers/getElement.cjs"),H=(...n)=>{const c=R.isTarget(n[0])?n[0]:void 0,f=n[1]||(typeof n[0]=="object"?n[0]:{}),{enabled:v=!0}=f,l=m.useRefState(),o=L.useRef(f);if(o.current=f,L.useEffect(()=>{if(!v||!c&&!l.state)return;const e=c?q.getElement(c):l.state;if(!e)return;let s=!0,a=0,h=0;const g=()=>{if(o.current.force)return;const{scrollHeight:t,clientHeight:u,scrollTop:r}=e,i=t-u,d=i/2;console.log(i,r,d,r<h,i-r<=d),r<h?s=!1:i-r<=d&&(s=!0),h=r},S=t=>{o.current.force||(t.deltaY<0?s=!1:g())},E=t=>{o.current.force||(a=t.touches[0].clientY)},T=t=>{if(o.current.force)return;const u=t.touches[0].clientY;a-u<0?s=!1:g(),a=u},Y=()=>{!s&&!o.current.force||e.scrollTo({top:e.scrollHeight})};e.addEventListener("wheel",S),e.addEventListener("touchstart",E),e.addEventListener("touchmove",T);const b=new MutationObserver(Y);return b.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{b.disconnect(),e.removeEventListener("wheel",S),e.removeEventListener("touchstart",E),e.removeEventListener("touchmove",T)}},[v,c,l.state]),!c)return l};exports.useAutoScroll=H;
|
|
2
2
|
//# sourceMappingURL=useAutoScroll.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoScroll.cjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to auto-scroll\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {void}\n *\n * @example\n * useAutoScroll(ref);\n *\n * @overload\n * @template Target\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {StateRef<Target>} A React ref to attach to the list element\n *\n * @example\n * const ref = useAutoScroll();\n */\nexport const useAutoScroll = ((...params: any[]) => {\n const target = (
|
|
1
|
+
{"version":3,"file":"useAutoScroll.cjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n /** Whether to force auto-scrolling regardless of user interactions */\n force?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to auto-scroll\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {void}\n *\n * @example\n * useAutoScroll(ref);\n *\n * @overload\n * @template Target\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {StateRef<Target>} A React ref to attach to the list element\n *\n * @example\n * const ref = useAutoScroll();\n */\nexport const useAutoScroll = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n const options = (params[1] ||\n (typeof params[0] === 'object' ? params[0] : {})) as UseAutoScrollOptions;\n const { enabled = true } = options;\n\n const internalRef = useRefState<HTMLElement>();\n const internalOptionsRef = useRef<UseAutoScrollOptions>(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.state) as HTMLElement;\n\n if (!element) return;\n\n let shouldAutoScroll = true;\n let touchStartY = 0;\n let lastScrollTop = 0;\n\n const onCheckScrollPosition = () => {\n if (internalOptionsRef.current.force) return;\n\n const { scrollHeight, clientHeight, scrollTop } = element;\n const maxScrollHeight = scrollHeight - clientHeight;\n const scrollThreshold = maxScrollHeight / 2;\n console.log(\n maxScrollHeight,\n scrollTop,\n scrollThreshold,\n scrollTop < lastScrollTop,\n maxScrollHeight - scrollTop <= scrollThreshold\n );\n\n if (scrollTop < lastScrollTop) shouldAutoScroll = false;\n else if (maxScrollHeight - scrollTop <= scrollThreshold) shouldAutoScroll = true;\n\n lastScrollTop = scrollTop;\n };\n\n const onWheel = (event: WheelEvent) => {\n if (internalOptionsRef.current.force) return;\n\n if (event.deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n };\n\n const onTouchStart = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n touchStartY = event.touches[0].clientY;\n };\n\n const onTouchMove = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n\n const touchEndY = event.touches[0].clientY;\n const deltaY = touchStartY - touchEndY;\n\n if (deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n\n touchStartY = touchEndY;\n };\n\n const onMutation = () => {\n if (!shouldAutoScroll && !internalOptionsRef.current.force) return;\n element.scrollTo({ top: element.scrollHeight });\n };\n\n element.addEventListener('wheel', onWheel);\n element.addEventListener('touchstart', onTouchStart);\n element.addEventListener('touchmove', onTouchMove);\n\n const observer = new MutationObserver(onMutation);\n\n observer.observe(element, {\n childList: true,\n subtree: true,\n characterData: true\n });\n\n return () => {\n observer.disconnect();\n element.removeEventListener('wheel', onWheel);\n element.removeEventListener('touchstart', onTouchStart);\n element.removeEventListener('touchmove', onTouchMove);\n };\n }, [enabled, target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseAutoScroll;\n"],"names":["useAutoScroll","params","target","isTarget","options","enabled","internalRef","useRefState","internalOptionsRef","useRef","useEffect","element","getElement","shouldAutoScroll","touchStartY","lastScrollTop","onCheckScrollPosition","scrollHeight","clientHeight","scrollTop","maxScrollHeight","scrollThreshold","onWheel","event","onTouchStart","onTouchMove","touchEndY","onMutation","observer"],"mappings":"mPA6CaA,EAAiB,IAAIC,IAAkB,CAClD,MAAMC,EAASC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC3CG,EAAWH,EAAO,CAAC,IACtB,OAAOA,EAAO,CAAC,GAAM,SAAWA,EAAO,CAAC,EAAI,CAAA,GACzC,CAAE,QAAAI,EAAU,EAAA,EAASD,EAErBE,EAAcC,EAAAA,YAAA,EACdC,EAAqBC,EAAAA,OAA6BL,CAAO,EAmF/D,GAlFAI,EAAmB,QAAUJ,EAE7BM,EAAAA,UAAU,IAAM,CACd,GAAI,CAACL,GAAY,CAACH,GAAU,CAACI,EAAY,MAAQ,OAEjD,MAAMK,EAAWT,EAASU,EAAAA,WAAWV,CAAM,EAAII,EAAY,MAE3D,GAAI,CAACK,EAAS,OAEd,IAAIE,EAAmB,GACnBC,EAAc,EACdC,EAAgB,EAEpB,MAAMC,EAAwB,IAAM,CAClC,GAAIR,EAAmB,QAAQ,MAAO,OAEtC,KAAM,CAAE,aAAAS,EAAc,aAAAC,EAAc,UAAAC,CAAA,EAAcR,EAC5CS,EAAkBH,EAAeC,EACjCG,EAAkBD,EAAkB,EAC1C,QAAQ,IACNA,EACAD,EACAE,EACAF,EAAYJ,EACZK,EAAkBD,GAAaE,CAAA,EAG7BF,EAAYJ,EAAeF,EAAmB,GACzCO,EAAkBD,GAAaE,IAAiBR,EAAmB,IAE5EE,EAAgBI,CAAA,EAGZG,EAAWC,GAAsB,CACjCf,EAAmB,QAAQ,QAE3Be,EAAM,OAAS,EAAGV,EAAmB,GACpCG,EAAA,EAAsB,EAGvBQ,EAAgBD,GAAsB,CACtCf,EAAmB,QAAQ,QAC/BM,EAAcS,EAAM,QAAQ,CAAC,EAAE,QAAA,EAG3BE,EAAeF,GAAsB,CACzC,GAAIf,EAAmB,QAAQ,MAAO,OAEtC,MAAMkB,EAAYH,EAAM,QAAQ,CAAC,EAAE,QACpBT,EAAcY,EAEhB,EAAGb,EAAmB,GAC9BG,EAAA,EAELF,EAAcY,CAAA,EAGVC,EAAa,IAAM,CACnB,CAACd,GAAoB,CAACL,EAAmB,QAAQ,OACrDG,EAAQ,SAAS,CAAE,IAAKA,EAAQ,aAAc,CAAA,EAGhDA,EAAQ,iBAAiB,QAASW,CAAO,EACzCX,EAAQ,iBAAiB,aAAca,CAAY,EACnDb,EAAQ,iBAAiB,YAAac,CAAW,EAEjD,MAAMG,EAAW,IAAI,iBAAiBD,CAAU,EAEhD,OAAAC,EAAS,QAAQjB,EAAS,CACxB,UAAW,GACX,QAAS,GACT,cAAe,EAAA,CAChB,EAEM,IAAM,CACXiB,EAAS,WAAA,EACTjB,EAAQ,oBAAoB,QAASW,CAAO,EAC5CX,EAAQ,oBAAoB,aAAca,CAAY,EACtDb,EAAQ,oBAAoB,YAAac,CAAW,CAAA,CACtD,EACC,CAACpB,EAASH,EAAQI,EAAY,KAAK,CAAC,EAEnC,CAAAJ,EACJ,OAAOI,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),f=t=>{if(!t)return{days:0,hours:0,minutes:0,seconds:0,count:0};const s=Math.floor(t/86400),d=Math.floor(t%86400/3600),e=Math.floor(t%3600/60),u=Math.floor(t%60);return{days:s,hours:d,minutes:e,seconds:u,count:t}},y=(...t)=>{const s=(typeof t[0]=="number"?t[0]:t[0]?.initialTime)??0,e=(typeof t[0]=="number"?t[1]:t[0])?.immediately??!1,[u,l]=i.useState(f(s)),[c,r]=i.useState(!e&&!s);return i.useEffect(()=>{if(c)return;const a=()=>{l(n=>{const o=n.count+1;return o%60===0?{...n,minutes:n.minutes+1,seconds:0,count:o}:o%(60*60)===0?{...n,hours:n.hours+1,minutes:0,seconds:0,count:o}:o%(60*60*24)===0?{...n,days:n.days+1,hours:0,minutes:0,seconds:0,count:o}:{...n,seconds:n.seconds+1,count:o}})},h=setInterval(()=>a(),1e3);return()=>clearInterval(h)},[c]),{...u,paused:c,pause:()=>r(!0),start:()=>r(!1),reset:()=>l(f(s)),toggle:()=>r(a=>!a)}};exports.useStopwatch=y;
|
|
2
2
|
//# sourceMappingURL=useStopwatch.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStopwatch.cjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The
|
|
1
|
+
{"version":3,"file":"useStopwatch.cjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The immediately state of the timer */\n immediately?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const immediately = options?.immediately ?? false;\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!immediately && !initialTime);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","immediately","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":"yGAEMA,EAAoBC,GAAiB,CACzC,GAAI,CAACA,EACH,MAAO,CACL,KAAM,EACN,MAAO,EACP,QAAS,EACT,QAAS,EACT,MAAO,CAAA,EAGX,MAAMC,EAAO,KAAK,MAAMD,EAAO,KAAK,EAC9BE,EAAQ,KAAK,MAAOF,EAAO,MAAS,IAAI,EACxCG,EAAU,KAAK,MAAOH,EAAO,KAAQ,EAAE,EACvCI,EAAU,KAAK,MAAMJ,EAAO,EAAE,EAEpC,MAAO,CAAE,KAAAC,EAAM,MAAAC,EAAO,QAAAC,EAAS,QAAAC,EAAS,MAAOJ,CAAA,CACjD,EA2DaK,EAAgB,IAAIC,IAAkB,CACjD,MAAMC,GACH,OAAOD,EAAO,CAAC,GAAM,SACjBA,EAAO,CAAC,EACRA,EAAO,CAAC,GAAsD,cAAgB,EAO/EE,GAJJ,OAAOF,EAAO,CAAC,GAAM,SAChBA,EAAO,CAAC,EACRA,EAAO,CAAC,IAEc,aAAe,GAEtC,CAACN,EAAMS,CAAO,EAAIC,EAAAA,SAASX,EAAiBQ,CAAW,CAAC,EACxD,CAACI,EAAQC,CAAS,EAAIF,EAAAA,SAAS,CAACF,GAAe,CAACD,CAAW,EAEjEM,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAIF,EAAQ,OACZ,MAAMG,EAAa,IAAM,CACvBL,EAASM,GAAa,CACpB,MAAMC,EAAeD,EAAS,MAAQ,EAEtC,OAAIC,EAAe,KAAO,EACjB,CACL,GAAGD,EACH,QAASA,EAAS,QAAU,EAC5B,QAAS,EACT,MAAOC,CAAA,EAIPA,GAAgB,GAAK,MAAQ,EACxB,CACL,GAAGD,EACH,MAAOA,EAAS,MAAQ,EACxB,QAAS,EACT,QAAS,EACT,MAAOC,CAAA,EAIPA,GAAgB,GAAK,GAAK,MAAQ,EAC7B,CACL,GAAGD,EACH,KAAMA,EAAS,KAAO,EACtB,MAAO,EACP,QAAS,EACT,QAAS,EACT,MAAOC,CAAA,EAIJ,CACL,GAAGD,EACH,QAASA,EAAS,QAAU,EAC5B,MAAOC,CAAA,CACT,CACD,CAAA,EAGGC,EAAW,YAAY,IAAMH,EAAA,EAAc,GAAI,EACrD,MAAO,IAAM,cAAcG,CAAQ,CAAA,EAClC,CAACN,CAAM,CAAC,EAEJ,CACL,GAAGX,EACH,OAAAW,EACA,MAAO,IAAMC,EAAU,EAAI,EAC3B,MAAO,IAAMA,EAAU,EAAK,EAC5B,MAAO,IAAMH,EAAQV,EAAiBQ,CAAW,CAAC,EAClD,OAAQ,IAAMK,EAAWM,GAAc,CAACA,CAAS,CAAA,CAErD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.cjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category
|
|
1
|
+
{"version":3,"file":"useWindowEvent.cjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category Sensors\n *\n * @template Event Key of window event map.\n * @param {Event} event The event to listen for.\n * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered\n * @param {UseEventListenerOptions} [options] The options for the event listener\n * @returns {void}\n *\n * @example\n * useWindowEvent('click', () => console.log('clicked'));\n */\nexport const useWindowEvent = <Event extends keyof WindowEventMap>(\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","target"],"mappings":"4LAoBaA,EAAiB,CAC5BC,EACAC,EACAC,IACGC,EAAAA,iBAAiBC,EAAAA,OAAO,MAAM,EAAGJ,EAAOC,EAAUC,CAAO"}
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { useState as a, useEffect as l } from "react";
|
|
2
|
+
import { useRefState as v } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as d } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
import { getElement as E } from "../../utils/helpers/getElement.mjs";
|
|
5
|
+
const p = (...u) => {
|
|
6
|
+
const t = d(u[0]) ? u[0] : void 0, [s, i] = a(null), n = v(window);
|
|
7
|
+
return l(() => {
|
|
8
|
+
if (!t && !n.state) return;
|
|
9
|
+
const e = t ? E(t) : n.current;
|
|
10
|
+
if (!e) return;
|
|
11
|
+
const c = new MutationObserver((f) => {
|
|
12
|
+
f.filter((r) => r.removedNodes.length).map((r) => Array.from(r.removedNodes)).flat().forEach((r) => {
|
|
13
|
+
i((m) => r === m ? document.activeElement : m);
|
|
13
14
|
});
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
+
c.observe(e, {
|
|
16
17
|
childList: !0,
|
|
17
18
|
subtree: !0
|
|
18
|
-
})
|
|
19
|
-
|
|
19
|
+
});
|
|
20
|
+
const o = () => i(document?.activeElement);
|
|
21
|
+
return e.addEventListener("focus", o, !0), e.addEventListener("blur", o, !0), () => {
|
|
22
|
+
c.disconnect(), e.removeEventListener("focus", o, !0), e.removeEventListener("blur", o, !0);
|
|
20
23
|
};
|
|
21
|
-
}, []),
|
|
24
|
+
}, [t, n.state]), t ? s : {
|
|
25
|
+
ref: n,
|
|
26
|
+
value: s
|
|
27
|
+
};
|
|
22
28
|
};
|
|
23
29
|
export {
|
|
24
|
-
|
|
30
|
+
p as useActiveElement
|
|
25
31
|
};
|
|
26
32
|
//# sourceMappingURL=useActiveElement.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement =
|
|
1
|
+
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.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\nexport interface UseActiveElement {\n (): HTMLElement | null;\n\n <Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(\n target?: never\n ): {\n ref: StateRef<Target>;\n value: ActiveElement | null;\n };\n\n <ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;\n}\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to observe active element changes\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement(ref);\n *\n * @overload\n * @template ActiveElement The active element type\n * @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element\n *\n * @example\n * const { ref, value } = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const [value, setValue] = useState<HTMLElement | null>(null);\n const internalRef = useRefState(window);\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 observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setValue((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as HTMLElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(element, {\n childList: true,\n subtree: true\n });\n\n const onActiveElementChange = () => setValue(document?.activeElement as HTMLElement | null);\n\n element.addEventListener('focus', onActiveElementChange, true);\n element.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n observer.disconnect();\n element.removeEventListener('focus', onActiveElementChange, true);\n element.removeEventListener('blur', onActiveElementChange, true);\n };\n }, [target, internalRef.state]);\n\n if (target) return value;\n return {\n ref: internalRef,\n value\n };\n}) as UseActiveElement;\n"],"names":["useActiveElement","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","element","getElement","observer","mutations","mutation","node","prevActiveElement","onActiveElementChange"],"mappings":";;;;AA4CO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5C,CAACG,GAAOC,CAAQ,IAAIC,EAA6B,IAAI,GACrDC,IAAcC,EAAY,MAAM;AAsCtC,SApCAC,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACK,EAAY,MAAO;AAEnC,UAAMG,IAAWR,IAASS,EAAWT,CAAM,IAAIK,EAAY;AAC3D,QAAI,CAACG,EAAS;AAEd,UAAME,IAAW,IAAI,iBAAiB,CAACC,MAAc;AACnD,MAAAA,EACG,OAAO,CAACC,MAAaA,EAAS,aAAa,MAAM,EACjD,IAAI,CAACA,MAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAAQ,CAACC,MAAS;AACjB,QAAAV,EAAS,CAACW,MACJD,MAASC,IAA0B,SAAS,gBACzCA,CACR;AAAA,MAAA,CACF;AAAA,IAAA,CACJ;AAED,IAAAJ,EAAS,QAAQF,GAAS;AAAA,MACxB,WAAW;AAAA,MACX,SAAS;AAAA,IAAA,CACV;AAED,UAAMO,IAAwB,MAAMZ,EAAS,UAAU,aAAmC;AAE1F,WAAAK,EAAQ,iBAAiB,SAASO,GAAuB,EAAI,GAC7DP,EAAQ,iBAAiB,QAAQO,GAAuB,EAAI,GAErD,MAAM;AACX,MAAAL,EAAS,WAAA,GACTF,EAAQ,oBAAoB,SAASO,GAAuB,EAAI,GAChEP,EAAQ,oBAAoB,QAAQO,GAAuB,EAAI;AAAA,IAAA;AAAA,EACjE,GACC,CAACf,GAAQK,EAAY,KAAK,CAAC,GAE1BL,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,OAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,39 +1,48 @@
|
|
|
1
|
-
import { useEffect as Y } from "react";
|
|
2
|
-
import { useRefState as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { useRef as T, useEffect as Y } from "react";
|
|
2
|
+
import { useRefState as b } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as H } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
import { getElement as R } from "../../utils/helpers/getElement.mjs";
|
|
5
|
+
const O = (...n) => {
|
|
6
|
+
const c = H(n[0]) ? n[0] : void 0, f = n[1] || (typeof n[0] == "object" ? n[0] : {}), { enabled: v = !0 } = f, l = b(), r = T(f);
|
|
7
|
+
if (r.current = f, Y(() => {
|
|
8
|
+
if (!v || !c && !l.state) return;
|
|
9
|
+
const e = c ? R(c) : l.state;
|
|
10
|
+
if (!e) return;
|
|
11
|
+
let s = !0, h = 0, a = 0;
|
|
12
|
+
const m = () => {
|
|
13
|
+
if (r.current.force) return;
|
|
14
|
+
const { scrollHeight: t, clientHeight: i, scrollTop: o } = e, u = t - i, d = u / 2;
|
|
15
|
+
console.log(
|
|
16
|
+
u,
|
|
17
|
+
o,
|
|
18
|
+
d,
|
|
19
|
+
o < a,
|
|
20
|
+
u - o <= d
|
|
21
|
+
), o < a ? s = !1 : u - o <= d && (s = !0), a = o;
|
|
22
|
+
}, E = (t) => {
|
|
23
|
+
r.current.force || (t.deltaY < 0 ? s = !1 : m());
|
|
24
|
+
}, g = (t) => {
|
|
25
|
+
r.current.force || (h = t.touches[0].clientY);
|
|
26
|
+
}, S = (t) => {
|
|
27
|
+
if (r.current.force) return;
|
|
28
|
+
const i = t.touches[0].clientY;
|
|
29
|
+
h - i < 0 ? s = !1 : m(), h = i;
|
|
30
|
+
}, L = () => {
|
|
31
|
+
!s && !r.current.force || e.scrollTo({ top: e.scrollHeight });
|
|
23
32
|
};
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
return
|
|
33
|
+
e.addEventListener("wheel", E), e.addEventListener("touchstart", g), e.addEventListener("touchmove", S);
|
|
34
|
+
const p = new MutationObserver(L);
|
|
35
|
+
return p.observe(e, {
|
|
27
36
|
childList: !0,
|
|
28
37
|
subtree: !0,
|
|
29
38
|
characterData: !0
|
|
30
39
|
}), () => {
|
|
31
|
-
|
|
40
|
+
p.disconnect(), e.removeEventListener("wheel", E), e.removeEventListener("touchstart", g), e.removeEventListener("touchmove", S);
|
|
32
41
|
};
|
|
33
|
-
}, [
|
|
34
|
-
return
|
|
42
|
+
}, [v, c, l.state]), !c)
|
|
43
|
+
return l;
|
|
35
44
|
};
|
|
36
45
|
export {
|
|
37
|
-
|
|
46
|
+
O as useAutoScroll
|
|
38
47
|
};
|
|
39
48
|
//# sourceMappingURL=useAutoScroll.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoScroll.mjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to auto-scroll\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {void}\n *\n * @example\n * useAutoScroll(ref);\n *\n * @overload\n * @template Target\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {StateRef<Target>} A React ref to attach to the list element\n *\n * @example\n * const ref = useAutoScroll();\n */\nexport const useAutoScroll = ((...params: any[]) => {\n const target = (
|
|
1
|
+
{"version":3,"file":"useAutoScroll.mjs","sources":["../../../../src/hooks/useAutoScroll/useAutoScroll.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use auto scroll options type */\nexport interface UseAutoScrollOptions {\n /** Whether auto-scrolling is enabled */\n enabled?: boolean;\n /** Whether to force auto-scrolling regardless of user interactions */\n force?: boolean;\n}\n\nexport interface UseAutoScroll {\n (target: HookTarget, options?: UseAutoScrollOptions): void;\n\n <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;\n}\n\n/**\n * @name useAutoScroll\n * @description - Hook that automatically scrolls a list element to the bottom\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to auto-scroll\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {void}\n *\n * @example\n * useAutoScroll(ref);\n *\n * @overload\n * @template Target\n * @param {boolean} [options.enabled] Whether auto-scrolling is enabled\n * @returns {StateRef<Target>} A React ref to attach to the list element\n *\n * @example\n * const ref = useAutoScroll();\n */\nexport const useAutoScroll = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n const options = (params[1] ||\n (typeof params[0] === 'object' ? params[0] : {})) as UseAutoScrollOptions;\n const { enabled = true } = options;\n\n const internalRef = useRefState<HTMLElement>();\n const internalOptionsRef = useRef<UseAutoScrollOptions>(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.state) as HTMLElement;\n\n if (!element) return;\n\n let shouldAutoScroll = true;\n let touchStartY = 0;\n let lastScrollTop = 0;\n\n const onCheckScrollPosition = () => {\n if (internalOptionsRef.current.force) return;\n\n const { scrollHeight, clientHeight, scrollTop } = element;\n const maxScrollHeight = scrollHeight - clientHeight;\n const scrollThreshold = maxScrollHeight / 2;\n console.log(\n maxScrollHeight,\n scrollTop,\n scrollThreshold,\n scrollTop < lastScrollTop,\n maxScrollHeight - scrollTop <= scrollThreshold\n );\n\n if (scrollTop < lastScrollTop) shouldAutoScroll = false;\n else if (maxScrollHeight - scrollTop <= scrollThreshold) shouldAutoScroll = true;\n\n lastScrollTop = scrollTop;\n };\n\n const onWheel = (event: WheelEvent) => {\n if (internalOptionsRef.current.force) return;\n\n if (event.deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n };\n\n const onTouchStart = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n touchStartY = event.touches[0].clientY;\n };\n\n const onTouchMove = (event: TouchEvent) => {\n if (internalOptionsRef.current.force) return;\n\n const touchEndY = event.touches[0].clientY;\n const deltaY = touchStartY - touchEndY;\n\n if (deltaY < 0) shouldAutoScroll = false;\n else onCheckScrollPosition();\n\n touchStartY = touchEndY;\n };\n\n const onMutation = () => {\n if (!shouldAutoScroll && !internalOptionsRef.current.force) return;\n element.scrollTo({ top: element.scrollHeight });\n };\n\n element.addEventListener('wheel', onWheel);\n element.addEventListener('touchstart', onTouchStart);\n element.addEventListener('touchmove', onTouchMove);\n\n const observer = new MutationObserver(onMutation);\n\n observer.observe(element, {\n childList: true,\n subtree: true,\n characterData: true\n });\n\n return () => {\n observer.disconnect();\n element.removeEventListener('wheel', onWheel);\n element.removeEventListener('touchstart', onTouchStart);\n element.removeEventListener('touchmove', onTouchMove);\n };\n }, [enabled, target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseAutoScroll;\n"],"names":["useAutoScroll","params","target","isTarget","options","enabled","internalRef","useRefState","internalOptionsRef","useRef","useEffect","element","getElement","shouldAutoScroll","touchStartY","lastScrollTop","onCheckScrollPosition","scrollHeight","clientHeight","scrollTop","maxScrollHeight","scrollThreshold","onWheel","event","onTouchStart","onTouchMove","touchEndY","onMutation","observer"],"mappings":";;;;AA6CO,MAAMA,IAAiB,IAAIC,MAAkB;AAClD,QAAMC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC3CG,IAAWH,EAAO,CAAC,MACtB,OAAOA,EAAO,CAAC,KAAM,WAAWA,EAAO,CAAC,IAAI,CAAA,IACzC,EAAE,SAAAI,IAAU,GAAA,IAASD,GAErBE,IAAcC,EAAA,GACdC,IAAqBC,EAA6BL,CAAO;AAmF/D,MAlFAI,EAAmB,UAAUJ,GAE7BM,EAAU,MAAM;AACd,QAAI,CAACL,KAAY,CAACH,KAAU,CAACI,EAAY,MAAQ;AAEjD,UAAMK,IAAWT,IAASU,EAAWV,CAAM,IAAII,EAAY;AAE3D,QAAI,CAACK,EAAS;AAEd,QAAIE,IAAmB,IACnBC,IAAc,GACdC,IAAgB;AAEpB,UAAMC,IAAwB,MAAM;AAClC,UAAIR,EAAmB,QAAQ,MAAO;AAEtC,YAAM,EAAE,cAAAS,GAAc,cAAAC,GAAc,WAAAC,EAAA,IAAcR,GAC5CS,IAAkBH,IAAeC,GACjCG,IAAkBD,IAAkB;AAC1C,cAAQ;AAAA,QACNA;AAAA,QACAD;AAAA,QACAE;AAAA,QACAF,IAAYJ;AAAA,QACZK,IAAkBD,KAAaE;AAAA,MAAA,GAG7BF,IAAYJ,IAAeF,IAAmB,KACzCO,IAAkBD,KAAaE,MAAiBR,IAAmB,KAE5EE,IAAgBI;AAAA,IAAA,GAGZG,IAAU,CAACC,MAAsB;AACrC,MAAIf,EAAmB,QAAQ,UAE3Be,EAAM,SAAS,IAAGV,IAAmB,KACpCG,EAAA;AAAA,IAAsB,GAGvBQ,IAAe,CAACD,MAAsB;AAC1C,MAAIf,EAAmB,QAAQ,UAC/BM,IAAcS,EAAM,QAAQ,CAAC,EAAE;AAAA,IAAA,GAG3BE,IAAc,CAACF,MAAsB;AACzC,UAAIf,EAAmB,QAAQ,MAAO;AAEtC,YAAMkB,IAAYH,EAAM,QAAQ,CAAC,EAAE;AAGnC,MAFeT,IAAcY,IAEhB,IAAGb,IAAmB,KAC9BG,EAAA,GAELF,IAAcY;AAAA,IAAA,GAGVC,IAAa,MAAM;AACvB,MAAI,CAACd,KAAoB,CAACL,EAAmB,QAAQ,SACrDG,EAAQ,SAAS,EAAE,KAAKA,EAAQ,cAAc;AAAA,IAAA;AAGhD,IAAAA,EAAQ,iBAAiB,SAASW,CAAO,GACzCX,EAAQ,iBAAiB,cAAca,CAAY,GACnDb,EAAQ,iBAAiB,aAAac,CAAW;AAEjD,UAAMG,IAAW,IAAI,iBAAiBD,CAAU;AAEhD,WAAAC,EAAS,QAAQjB,GAAS;AAAA,MACxB,WAAW;AAAA,MACX,SAAS;AAAA,MACT,eAAe;AAAA,IAAA,CAChB,GAEM,MAAM;AACX,MAAAiB,EAAS,WAAA,GACTjB,EAAQ,oBAAoB,SAASW,CAAO,GAC5CX,EAAQ,oBAAoB,cAAca,CAAY,GACtDb,EAAQ,oBAAoB,aAAac,CAAW;AAAA,IAAA;AAAA,EACtD,GACC,CAACpB,GAASH,GAAQI,EAAY,KAAK,CAAC,GAEnC,CAAAJ;AACJ,WAAOI;AACT;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as f, useEffect as
|
|
1
|
+
import { useState as f, useEffect as y } from "react";
|
|
2
2
|
const l = (t) => {
|
|
3
3
|
if (!t)
|
|
4
4
|
return {
|
|
@@ -8,14 +8,14 @@ const l = (t) => {
|
|
|
8
8
|
seconds: 0,
|
|
9
9
|
count: 0
|
|
10
10
|
};
|
|
11
|
-
const s = Math.floor(t / 86400),
|
|
12
|
-
return { days: s, hours:
|
|
13
|
-
},
|
|
14
|
-
const s = (typeof t[0] == "number" ? t[0] : t[0]?.initialTime) ?? 0, e = typeof t[0] == "number" ? t[1] : t[0], [
|
|
15
|
-
return
|
|
16
|
-
if (
|
|
11
|
+
const s = Math.floor(t / 86400), d = Math.floor(t % 86400 / 3600), e = Math.floor(t % 3600 / 60), u = Math.floor(t % 60);
|
|
12
|
+
return { days: s, hours: d, minutes: e, seconds: u, count: t };
|
|
13
|
+
}, g = (...t) => {
|
|
14
|
+
const s = (typeof t[0] == "number" ? t[0] : t[0]?.initialTime) ?? 0, e = (typeof t[0] == "number" ? t[1] : t[0])?.immediately ?? !1, [u, i] = f(l(s)), [c, r] = f(!e && !s);
|
|
15
|
+
return y(() => {
|
|
16
|
+
if (c) return;
|
|
17
17
|
const a = () => {
|
|
18
|
-
|
|
18
|
+
i((n) => {
|
|
19
19
|
const o = n.count + 1;
|
|
20
20
|
return o % 60 === 0 ? {
|
|
21
21
|
...n,
|
|
@@ -41,18 +41,18 @@ const l = (t) => {
|
|
|
41
41
|
count: o
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
|
-
},
|
|
45
|
-
return () => clearInterval(
|
|
46
|
-
}, [
|
|
47
|
-
...
|
|
48
|
-
paused:
|
|
49
|
-
pause: () =>
|
|
50
|
-
start: () =>
|
|
51
|
-
reset: () =>
|
|
52
|
-
toggle: () =>
|
|
44
|
+
}, h = setInterval(() => a(), 1e3);
|
|
45
|
+
return () => clearInterval(h);
|
|
46
|
+
}, [c]), {
|
|
47
|
+
...u,
|
|
48
|
+
paused: c,
|
|
49
|
+
pause: () => r(!0),
|
|
50
|
+
start: () => r(!1),
|
|
51
|
+
reset: () => i(l(s)),
|
|
52
|
+
toggle: () => r((a) => !a)
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
55
|
export {
|
|
56
|
-
|
|
56
|
+
g as useStopwatch
|
|
57
57
|
};
|
|
58
58
|
//# sourceMappingURL=useStopwatch.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The
|
|
1
|
+
{"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The immediately state of the timer */\n immediately?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const immediately = options?.immediately ?? false;\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!immediately && !initialTime);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","immediately","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA;AAGX,QAAMC,IAAO,KAAK,MAAMD,IAAO,KAAK,GAC9BE,IAAQ,KAAK,MAAOF,IAAO,QAAS,IAAI,GACxCG,IAAU,KAAK,MAAOH,IAAO,OAAQ,EAAE,GACvCI,IAAU,KAAK,MAAMJ,IAAO,EAAE;AAEpC,SAAO,EAAE,MAAAC,GAAM,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,OAAOJ,EAAA;AACjD,GA2DaK,IAAgB,IAAIC,MAAkB;AACjD,QAAMC,KACH,OAAOD,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAAsD,gBAAgB,GAO/EE,KAJJ,OAAOF,EAAO,CAAC,KAAM,WAChBA,EAAO,CAAC,IACRA,EAAO,CAAC,IAEc,eAAe,IAEtC,CAACN,GAAMS,CAAO,IAAIC,EAASX,EAAiBQ,CAAW,CAAC,GACxD,CAACI,GAAQC,CAAS,IAAIF,EAAS,CAACF,KAAe,CAACD,CAAW;AAEjE,SAAAM,EAAU,MAAM;AACd,QAAIF,EAAQ;AACZ,UAAMG,IAAa,MAAM;AACvB,MAAAL,EAAQ,CAACM,MAAa;AACpB,cAAMC,IAAeD,EAAS,QAAQ;AAEtC,eAAIC,IAAe,OAAO,IACjB;AAAA,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIPA,KAAgB,KAAK,QAAQ,IACxB;AAAA,UACL,GAAGD;AAAA,UACH,OAAOA,EAAS,QAAQ;AAAA,UACxB,SAAS;AAAA,UACT,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIPA,KAAgB,KAAK,KAAK,QAAQ,IAC7B;AAAA,UACL,GAAGD;AAAA,UACH,MAAMA,EAAS,OAAO;AAAA,UACtB,OAAO;AAAA,UACP,SAAS;AAAA,UACT,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIJ;AAAA,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,OAAOC;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA,GAGGC,IAAW,YAAY,MAAMH,EAAA,GAAc,GAAI;AACrD,WAAO,MAAM,cAAcG,CAAQ;AAAA,EAAA,GAClC,CAACN,CAAM,CAAC,GAEJ;AAAA,IACL,GAAGX;AAAA,IACH,QAAAW;AAAA,IACA,OAAO,MAAMC,EAAU,EAAI;AAAA,IAC3B,OAAO,MAAMA,EAAU,EAAK;AAAA,IAC5B,OAAO,MAAMH,EAAQV,EAAiBQ,CAAW,CAAC;AAAA,IAClD,QAAQ,MAAMK,EAAU,CAACM,MAAc,CAACA,CAAS;AAAA,EAAA;AAErD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category
|
|
1
|
+
{"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category Sensors\n *\n * @template Event Key of window event map.\n * @param {Event} event The event to listen for.\n * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered\n * @param {UseEventListenerOptions} [options] The options for the event listener\n * @returns {void}\n *\n * @example\n * useWindowEvent('click', () => console.log('clicked'));\n */\nexport const useWindowEvent = <Event extends keyof WindowEventMap>(\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","target"],"mappings":";;AAoBO,MAAMA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiBC,EAAO,MAAM,GAAGJ,GAAOC,GAAUC,CAAO;"}
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
+
import { HookTarget } from '../../utils/helpers';
|
|
2
|
+
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
export interface UseActiveElement {
|
|
4
|
+
(): HTMLElement | null;
|
|
5
|
+
<Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(target?: never): {
|
|
6
|
+
ref: StateRef<Target>;
|
|
7
|
+
value: ActiveElement | null;
|
|
8
|
+
};
|
|
9
|
+
<ActiveElement extends HTMLElement = HTMLElement>(target: HookTarget): ActiveElement | null;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* @name useActiveElement
|
|
3
13
|
* @description - Hook that returns the active element
|
|
4
14
|
* @category Elements
|
|
5
15
|
*
|
|
16
|
+
* @overload
|
|
17
|
+
* @param {HookTarget} [target=window] The target element to observe active element changes
|
|
6
18
|
* @returns {ActiveElement | null} The active element
|
|
7
19
|
*
|
|
8
20
|
* @example
|
|
9
|
-
* const activeElement = useActiveElement();
|
|
21
|
+
* const activeElement = useActiveElement(ref);
|
|
22
|
+
*
|
|
23
|
+
* @overload
|
|
24
|
+
* @template ActiveElement The active element type
|
|
25
|
+
* @returns {{ ref: StateRef<Element>; activeElement: ActiveElement | null }} An object containing the ref and active element
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const { ref, value } = useActiveElement();
|
|
10
29
|
*
|
|
11
30
|
* @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}
|
|
12
31
|
*/
|
|
13
|
-
export declare const useActiveElement:
|
|
32
|
+
export declare const useActiveElement: UseActiveElement;
|
|
@@ -4,6 +4,8 @@ import { StateRef } from '../useRefState/useRefState';
|
|
|
4
4
|
export interface UseAutoScrollOptions {
|
|
5
5
|
/** Whether auto-scrolling is enabled */
|
|
6
6
|
enabled?: boolean;
|
|
7
|
+
/** Whether to force auto-scrolling regardless of user interactions */
|
|
8
|
+
force?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface UseAutoScroll {
|
|
9
11
|
(target: HookTarget, options?: UseAutoScrollOptions): void;
|
|
@@ -25,8 +25,8 @@ export interface UseStopwatchReturn {
|
|
|
25
25
|
}
|
|
26
26
|
/** The use stopwatch options */
|
|
27
27
|
export interface UseStopwatchOptions {
|
|
28
|
-
/** The
|
|
29
|
-
|
|
28
|
+
/** The immediately state of the timer */
|
|
29
|
+
immediately?: boolean;
|
|
30
30
|
}
|
|
31
31
|
interface UseStopwatch {
|
|
32
32
|
(initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;
|
|
@@ -2,7 +2,7 @@ import { UseEventListenerOptions } from '../useEventListener/useEventListener';
|
|
|
2
2
|
/**
|
|
3
3
|
* @name useWindowEvent
|
|
4
4
|
* @description - Hook attaches an event listener to the window object for the specified event
|
|
5
|
-
* @category
|
|
5
|
+
* @category Sensors
|
|
6
6
|
*
|
|
7
7
|
* @template Event Key of window event map.
|
|
8
8
|
* @param {Event} event The event to listen for.
|
|
@@ -9,4 +9,4 @@ export declare const target: (target: Target) => {
|
|
|
9
9
|
value: Target;
|
|
10
10
|
type: symbol;
|
|
11
11
|
};
|
|
12
|
-
export declare const getElement: (target: HookTarget) =>
|
|
12
|
+
export declare const getElement: (target: HookTarget) => Document | Element | Window | null | undefined;
|