@alessiofrittoli/react-hooks 1.2.0 → 2.0.1

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 (96) hide show
  1. package/README.md +387 -73
  2. package/dist/eslint.js +1 -1
  3. package/dist/eslint.mjs +1 -1
  4. package/dist/index.d.mts +940 -11
  5. package/dist/index.d.ts +940 -11
  6. package/dist/index.js +1 -1
  7. package/dist/index.mjs +1 -1
  8. package/package.json +26 -34
  9. package/dist/browser-api/index.d.mts +0 -6
  10. package/dist/browser-api/index.d.ts +0 -6
  11. package/dist/browser-api/index.js +0 -1
  12. package/dist/browser-api/index.mjs +0 -1
  13. package/dist/browser-api/storage/index.d.mts +0 -4
  14. package/dist/browser-api/storage/index.d.ts +0 -4
  15. package/dist/browser-api/storage/index.js +0 -1
  16. package/dist/browser-api/storage/index.mjs +0 -1
  17. package/dist/browser-api/storage/useLocalStorage.d.mts +0 -11
  18. package/dist/browser-api/storage/useLocalStorage.d.ts +0 -11
  19. package/dist/browser-api/storage/useLocalStorage.js +0 -1
  20. package/dist/browser-api/storage/useLocalStorage.mjs +0 -1
  21. package/dist/browser-api/storage/useSessionStorage.d.mts +0 -11
  22. package/dist/browser-api/storage/useSessionStorage.d.ts +0 -11
  23. package/dist/browser-api/storage/useSessionStorage.js +0 -1
  24. package/dist/browser-api/storage/useSessionStorage.mjs +0 -1
  25. package/dist/browser-api/storage/useStorage.d.mts +0 -12
  26. package/dist/browser-api/storage/useStorage.d.ts +0 -12
  27. package/dist/browser-api/storage/useStorage.js +0 -1
  28. package/dist/browser-api/storage/useStorage.mjs +0 -1
  29. package/dist/browser-api/useIsPortrait.d.mts +0 -10
  30. package/dist/browser-api/useIsPortrait.d.ts +0 -10
  31. package/dist/browser-api/useIsPortrait.js +0 -1
  32. package/dist/browser-api/useIsPortrait.mjs +0 -1
  33. package/dist/browser-api/useMediaQuery.d.mts +0 -11
  34. package/dist/browser-api/useMediaQuery.d.ts +0 -11
  35. package/dist/browser-api/useMediaQuery.js +0 -1
  36. package/dist/browser-api/useMediaQuery.mjs +0 -1
  37. package/dist/chunk-26XSIIUK.mjs +0 -1
  38. package/dist/chunk-2CZNCZFR.mjs +0 -0
  39. package/dist/chunk-43RVMR6S.mjs +0 -1
  40. package/dist/chunk-4BGMCO3F.js +0 -1
  41. package/dist/chunk-65SF33P4.mjs +0 -1
  42. package/dist/chunk-6BSD56XC.js +0 -1
  43. package/dist/chunk-6IRIG5HU.mjs +0 -1
  44. package/dist/chunk-7ILYMOVB.js +0 -1
  45. package/dist/chunk-AJKPRTOJ.mjs +0 -1
  46. package/dist/chunk-EFFJB2GR.js +0 -1
  47. package/dist/chunk-FUCUVFLW.js +0 -1
  48. package/dist/chunk-G55NP3QG.js +0 -1
  49. package/dist/chunk-HO57SPST.js +0 -1
  50. package/dist/chunk-HZLWSH3W.mjs +0 -1
  51. package/dist/chunk-IDNLFWFO.js +0 -1
  52. package/dist/chunk-RENUP2VU.mjs +0 -1
  53. package/dist/chunk-SNMJ53QB.js +0 -1
  54. package/dist/chunk-SW7BCMZF.js +0 -1
  55. package/dist/chunk-TA6PCHH4.js +0 -1
  56. package/dist/chunk-UAJXVBNR.mjs +0 -1
  57. package/dist/chunk-UXNKH2MC.mjs +0 -1
  58. package/dist/chunk-VLSP3MAN.js +0 -1
  59. package/dist/chunk-WLIFJNZA.mjs +0 -0
  60. package/dist/chunk-WOVEE75M.js +0 -1
  61. package/dist/chunk-YAZXPL6I.mjs +0 -1
  62. package/dist/chunk-YLUTFORB.js +0 -1
  63. package/dist/chunk-YQO25XKN.mjs +0 -0
  64. package/dist/chunk-ZNAB4TYW.mjs +0 -0
  65. package/dist/dom-api/index.d.mts +0 -2
  66. package/dist/dom-api/index.d.ts +0 -2
  67. package/dist/dom-api/index.js +0 -1
  68. package/dist/dom-api/index.mjs +0 -1
  69. package/dist/dom-api/useFocusTrap.d.mts +0 -15
  70. package/dist/dom-api/useFocusTrap.d.ts +0 -15
  71. package/dist/dom-api/useFocusTrap.js +0 -1
  72. package/dist/dom-api/useFocusTrap.mjs +0 -1
  73. package/dist/dom-api/useScrollBlock.d.mts +0 -8
  74. package/dist/dom-api/useScrollBlock.d.ts +0 -8
  75. package/dist/dom-api/useScrollBlock.js +0 -1
  76. package/dist/dom-api/useScrollBlock.mjs +0 -1
  77. package/dist/misc/index.d.mts +0 -3
  78. package/dist/misc/index.d.ts +0 -3
  79. package/dist/misc/index.js +0 -1
  80. package/dist/misc/index.mjs +0 -1
  81. package/dist/misc/useIsClient.d.mts +0 -8
  82. package/dist/misc/useIsClient.d.ts +0 -8
  83. package/dist/misc/useIsClient.js +0 -1
  84. package/dist/misc/useIsClient.mjs +0 -1
  85. package/dist/misc/useIsFirstRender.d.mts +0 -9
  86. package/dist/misc/useIsFirstRender.d.ts +0 -9
  87. package/dist/misc/useIsFirstRender.js +0 -1
  88. package/dist/misc/useIsFirstRender.mjs +0 -1
  89. package/dist/misc/usePagination.d.mts +0 -12
  90. package/dist/misc/usePagination.d.ts +0 -12
  91. package/dist/misc/usePagination.js +0 -1
  92. package/dist/misc/usePagination.mjs +0 -1
  93. package/dist/misc/useUpdateEffect.d.mts +0 -9
  94. package/dist/misc/useUpdateEffect.d.ts +0 -9
  95. package/dist/misc/useUpdateEffect.js +0 -1
  96. package/dist/misc/useUpdateEffect.mjs +0 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-YLUTFORB.js');var _chunkVLSP3MANjs = require('./chunk-VLSP3MAN.js');var _chunkEFFJB2GRjs = require('./chunk-EFFJB2GR.js');var _chunkHO57SPSTjs = require('./chunk-HO57SPST.js');require('./chunk-TA6PCHH4.js');require('./chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('./chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('./chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var _chunkWOVEE75Mjs = require('./chunk-WOVEE75M.js');var _chunkFUCUVFLWjs = require('./chunk-FUCUVFLW.js');require('./chunk-6BSD56XC.js');var _chunkSW7BCMZFjs = require('./chunk-SW7BCMZF.js');var _chunkSNMJ53QBjs = require('./chunk-SNMJ53QB.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a; exports.useIsClient = _chunkVLSP3MANjs.a; exports.useIsFirstRender = _chunkHO57SPSTjs.a; exports.useIsPortrait = _chunkWOVEE75Mjs.a; exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useMediaQuery = _chunkFUCUVFLWjs.a; exports.useScrollBlock = _chunkSNMJ53QBjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a; exports.useUpdateEffect = _chunkEFFJB2GRjs.a;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var _LocalStorage = require('@alessiofrittoli/web-utils/storage/LocalStorage');var _SessionStorage = require('@alessiofrittoli/web-utils/storage/SessionStorage');var v=(e,r,t="local")=>{let n=_react.useCallback.call(void 0, ()=>_nullishCoalesce((t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).get(e), () => (r)),[t,e,r]),[i,a]=_react.useState.call(void 0, r),o=_react.useCallback.call(void 0, s=>{a(l=>{let u=s instanceof Function?s(l):s;return(typeof window<"u"&&t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).set(e,u),u})},[t,e]);return _react.useEffect.call(void 0, ()=>{a(n())},[n]),[i,o]};var D=(e,r)=>v(e,r,"local");var he=(e,r)=>v(e,r,"session");var w=()=>{let[e,r]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>r(!0),[]),e};var I=()=>{let e=_react.useRef.call(void 0, !0);return e.current?(e.current=!1,!0):e.current};var M=(e,r)=>{let t=I();_react.useEffect.call(void 0, ()=>{if(!t)return e()},r)};var _browserapi = require('@alessiofrittoli/web-utils/browser-api');var E=e=>{let[r,t]=_react.useState.call(void 0, _browserapi.getMediaMatches.call(void 0, e)),n=_react.useCallback.call(void 0, ()=>t(_browserapi.getMediaMatches.call(void 0, e)),[e]);return _react.useEffect.call(void 0, ()=>{let i=window.matchMedia(e);return n(),i.addEventListener("change",n),()=>{i.removeEventListener("change",n)}},[e,n]),r};var Je=(e={})=>{let r=w(),t=E("(prefers-color-scheme: dark)"),{initial:n=t,docClassNames:i=[]}=e,[a,o]=D("dark-mode",n),s=_nullishCoalesce(a, () => (t)),[l,u]=i,c=_react.useRef.call(void 0, {light:"",dark:""});return M(()=>{o(t)},[t,o]),_react.useEffect.call(void 0, ()=>{l&&document.documentElement.classList.toggle(l,s),u&&document.documentElement.classList.toggle(u,!s)},[s,l,u]),_react.useEffect.call(void 0, ()=>{document.head.querySelectorAll('meta[name="theme-color"]').forEach(p=>{let m=p.getAttribute("media"),f=p.getAttribute("content");if(f){if(!m||m==="(prefers-color-scheme: light)"){c.current.light=f;return}c.current.dark=f}})},[]),M(()=>{let p=c.current.dark,m=c.current.light;a&&!p||!a&&!m||document.head.querySelectorAll('meta[name="theme-color"]').forEach(f=>{f.setAttribute("content",a?p:m)})},[a]),{isDarkMode:r?s:!1,isDarkOS:r?t:!1,toggleDarkMode:_react.useCallback.call(void 0, ()=>o(p=>!p),[o]),enableDarkMode:_react.useCallback.call(void 0, ()=>o(!0),[o]),disableDarkMode:_react.useCallback.call(void 0, ()=>o(!1),[o])}};function _e(e,r){let{target:t,query:n,options:i,listener:a,onLoad:o,onCleanUp:s}=r;_react.useEffect.call(void 0, ()=>{let l=Array.isArray(e)?e:[e],u=_nullishCoalesce((n?window.matchMedia(n):t&&"current"in t?t.current:t), () => (window));if(u.addEventListener)return _optionalChain([o, 'optionalCall', _2 => _2()]),l.map(c=>{u.addEventListener(c,a,i)}),()=>{l.map(c=>{u.removeEventListener(c,a,i)}),_optionalChain([s, 'optionalCall', _3 => _3()])}},[e,t,n,i,a,o,s])}var _device = require('@alessiofrittoli/web-utils/device');var ot=()=>E(_device.portraitMediaQuery);var ne=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),ut= exports.useFocusTrap =e=>{let[r,t]=_react.useState.call(void 0, !1),n=_react.useRef.call(void 0, null),i=_react.useCallback.call(void 0, o=>{n.current=document.activeElement;let s=o||_optionalChain([e, 'optionalAccess', _4 => _4.current])||!1;if(s)return t(s)},[e]),a=_react.useCallback.call(void 0, ()=>{_optionalChain([n, 'access', _5 => _5.current, 'optionalAccess', _6 => _6.focus, 'call', _7 => _7()]),t(!1)},[]);return _react.useEffect.call(void 0, ()=>{if(!r)return;let o=s=>{if(s.key!=="Tab")return;let l=Array.from(r.querySelectorAll(ne)),u=l.at(0),c=l.at(-1);if(!s.shiftKey){document.activeElement===c&&(s.preventDefault(),_optionalChain([u, 'optionalAccess', _8 => _8.focus, 'call', _9 => _9()]));return}document.activeElement===u&&(s.preventDefault(),_optionalChain([c, 'optionalAccess', _10 => _10.focus, 'call', _11 => _11()]))};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[r]),[i,a]};var pt=(e,r={})=>{let{initial:t=!1,once:n,amount:i,margin:a,root:o,enable:s=!0,onStart:l}=r,u=_react.useRef.call(void 0, !0),[c,p]=_react.useState.call(void 0, t),[m,f]=_react.useState.call(void 0, s),T=_react.useMemo.call(void 0, ()=>{if(!m||typeof IntersectionObserver>"u")return;let F=i==="all"?1:i==="some"?.5:i;try{return new IntersectionObserver(async([y],g)=>{if(!y)return;let k=y.isIntersecting;try{if(await _optionalChain([l, 'optionalCall', _12 => _12(y,g)]),!u.current)return;p(k)}catch(Q){console.error(Q)}k&&n&&g.disconnect()},{root:o||void 0,rootMargin:a,threshold:F})}catch(y){console.error(y)}},[o,a,i,n,m,l]);return _react.useEffect.call(void 0, ()=>{if(u.current=!0,!(!m||!e.current||!T))return T.observe(e.current),()=>{u.current=!1,T.disconnect()}},[e,T,m]),{inView:c,enabled:m,observer:T,setInView:p,setEnabled:f}};var _dom = require('@alessiofrittoli/web-utils/dom');var vt=e=>{let r=_react.useCallback.call(void 0, ()=>_dom.blockScroll.call(void 0, _optionalChain([e, 'optionalAccess', _13 => _13.current])||void 0),[e]),t=_react.useCallback.call(void 0, ()=>_dom.restoreScroll.call(void 0, _optionalChain([e, 'optionalAccess', _14 => _14.current])||void 0),[e]);return[r,t]};var A=(e,r={})=>{let{delay:t=1,args:n}=r;_react.useEffect.call(void 0, ()=>{let i=setTimeout(e,t,...n||[]);return()=>clearTimeout(i)},[t,n,e])};var kt=(e,r=500)=>{let[t,n]=_react.useState.call(void 0, e),i=_react.useMemo.call(void 0, ()=>[e],[e]);return A(n,{delay:r,args:i}),t};function U(e,r={}){let{delay:t=1,args:n,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,s=_react.useRef.call(void 0, void 0),[l,u]=_react.useState.call(void 0, i),c=_react.useCallback.call(void 0, ()=>s.current?(clearInterval(s.current),s.current=void 0,!0):!1,[]),p=_react.useCallback.call(void 0, ()=>{let f=c();return a&&(n?e(...n):e()),s.current=setInterval(e,t,...n||[]),!f&&o&&u(!0),s.current},[t,n,o,a,e,c]),m=_react.useCallback.call(void 0, ()=>{c()&&o&&u(!1)},[o,c]);return _react.useEffect.call(void 0, ()=>{if(i)return p(),m},[i,p,m]),o?{isActive:l,start:p,stop:m}:{start:p,stop:m}}var Ht=(e,r={})=>{let{delay:t=1,args:n}=r;_react.useEffect.call(void 0, ()=>{let i=setInterval(e,t,...n||[]);return()=>clearInterval(i)},[t,n,e])};function At(e,r={}){let{autoplay:t=!0}=r,n=U(e,{autoplay:!1,...r}),{start:i,stop:a}=n,o=_react.useCallback.call(void 0, ()=>document.hidden?a():i(),[i,a]),s=_react.useCallback.call(void 0, ()=>{if(document.addEventListener("visibilitychange",o),!document.hidden)return i()},[i,o]),l=_react.useCallback.call(void 0, ()=>{a(),document.removeEventListener("visibilitychange",o)},[a,o]);return _react.useEffect.call(void 0, ()=>{if(t)return s(),l},[t,s,l]),{...n,start:s,stop:l}}function $t(e,r={}){let{delay:t=1,args:n,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,s=_react.useRef.call(void 0, void 0),[l,u]=_react.useState.call(void 0, i),c=_react.useCallback.call(void 0, ()=>s.current?(clearTimeout(s.current),s.current=void 0,!0):!1,[]),p=_react.useCallback.call(void 0, ()=>{let f=c();return a&&(n?e(...n):e()),s.current=setTimeout(()=>{if(s.current=void 0,o&&u(!1),n)return e(...n);e()},t),!f&&o&&u(!0),s.current},[t,n,o,a,e,c]),m=_react.useCallback.call(void 0, ()=>{c()&&o&&u(!1)},[o,c]);return _react.useEffect.call(void 0, ()=>{if(i)return p(),m},[i,p,m]),o?{isActive:l,start:p,stop:m}:{start:p,stop:m}}exports.useDarkMode = Je; exports.useDebounce = kt; exports.useEventListener = _e; exports.useFocusTrap = ut; exports.useInView = pt; exports.useInterval = U; exports.useIntervalWhenVisible = At; exports.useIsClient = w; exports.useIsFirstRender = I; exports.useIsPortrait = ot; exports.useLightInterval = Ht; exports.useLightTimeout = A; exports.useLocalStorage = D; exports.useMediaQuery = E; exports.useScrollBlock = vt; exports.useSessionStorage = he; exports.useStorage = v; exports.useTimeout = $t; exports.useUpdateEffect = M;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import"./chunk-ZNAB4TYW.mjs";import{a as x}from"./chunk-65SF33P4.mjs";import{a as b}from"./chunk-UAJXVBNR.mjs";import{a}from"./chunk-26XSIIUK.mjs";import"./chunk-YQO25XKN.mjs";import"./chunk-2CZNCZFR.mjs";import{a as r}from"./chunk-YAZXPL6I.mjs";import{a as e}from"./chunk-UXNKH2MC.mjs";import{a as o}from"./chunk-HZLWSH3W.mjs";import{a as m}from"./chunk-RENUP2VU.mjs";import{a as f}from"./chunk-AJKPRTOJ.mjs";import"./chunk-WLIFJNZA.mjs";import{a as p}from"./chunk-6IRIG5HU.mjs";import{a as t}from"./chunk-43RVMR6S.mjs";export{p as useFocusTrap,x as useIsClient,a as useIsFirstRender,m as useIsPortrait,r as useLocalStorage,f as useMediaQuery,t as useScrollBlock,e as useSessionStorage,o as useStorage,b as useUpdateEffect};
1
+ import{useCallback as R,useEffect as j,useState as B}from"react";import{LocalStorage as h}from"@alessiofrittoli/web-utils/storage/LocalStorage";import{SessionStorage as D}from"@alessiofrittoli/web-utils/storage/SessionStorage";var E=(e,r,t="local")=>{let n=R(()=>(t==="local"?h:D).get(e)??r,[t,e,r]),[i,a]=B(r),o=R(s=>{a(l=>{let u=s instanceof Function?s(l):s;return(typeof window<"u"&&t==="local"?h:D).set(e,u),u})},[t,e]);return j(()=>{a(n())},[n]),[i,o]};var w=(e,r)=>E(e,r,"local");var De=(e,r)=>E(e,r,"session");import{useCallback as S,useEffect as V,useRef as Y}from"react";import{useEffect as N,useState as q}from"react";var I=()=>{let[e,r]=q(!1);return N(()=>r(!0),[]),e};import{useRef as P}from"react";var H=()=>{let e=P(!0);return e.current?(e.current=!1,!0):e.current};import{useEffect as z}from"react";var x=(e,r)=>{let t=H();z(()=>{if(!t)return e()},r)};import{useCallback as G,useEffect as J,useState as X}from"react";import{getMediaMatches as C}from"@alessiofrittoli/web-utils/browser-api";var M=e=>{let[r,t]=X(C(e)),n=G(()=>t(C(e)),[e]);return J(()=>{let i=window.matchMedia(e);return n(),i.addEventListener("change",n),()=>{i.removeEventListener("change",n)}},[e,n]),r};var Xe=(e={})=>{let r=I(),t=M("(prefers-color-scheme: dark)"),{initial:n=t,docClassNames:i=[]}=e,[a,o]=w("dark-mode",n),s=a??t,[l,u]=i,c=Y({light:"",dark:""});return x(()=>{o(t)},[t,o]),V(()=>{l&&document.documentElement.classList.toggle(l,s),u&&document.documentElement.classList.toggle(u,!s)},[s,l,u]),V(()=>{document.head.querySelectorAll('meta[name="theme-color"]').forEach(p=>{let m=p.getAttribute("media"),T=p.getAttribute("content");if(T){if(!m||m==="(prefers-color-scheme: light)"){c.current.light=T;return}c.current.dark=T}})},[]),x(()=>{let p=c.current.dark,m=c.current.light;a&&!p||!a&&!m||document.head.querySelectorAll('meta[name="theme-color"]').forEach(T=>{T.setAttribute("content",a?p:m)})},[a]),{isDarkMode:r?s:!1,isDarkOS:r?t:!1,toggleDarkMode:S(()=>o(p=>!p),[o]),enableDarkMode:S(()=>o(!0),[o]),disableDarkMode:S(()=>o(!1),[o])}};import{useEffect as Z}from"react";function et(e,r){let{target:t,query:n,options:i,listener:a,onLoad:o,onCleanUp:s}=r;Z(()=>{let l=Array.isArray(e)?e:[e],u=(n?window.matchMedia(n):t&&"current"in t?t.current:t)??window;if(u.addEventListener)return o?.(),l.map(c=>{u.addEventListener(c,a,i)}),()=>{l.map(c=>{u.removeEventListener(c,a,i)}),s?.()}},[e,t,n,i,a,o,s])}import{portraitMediaQuery as _}from"@alessiofrittoli/web-utils/device";var st=()=>M(_);import{useCallback as K,useEffect as ee,useRef as te,useState as ne}from"react";var re=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),ct=e=>{let[r,t]=ne(!1),n=te(null),i=K(o=>{n.current=document.activeElement;let s=o||e?.current||!1;if(s)return t(s)},[e]),a=K(()=>{n.current?.focus(),t(!1)},[]);return ee(()=>{if(!r)return;let o=s=>{if(s.key!=="Tab")return;let l=Array.from(r.querySelectorAll(re)),u=l.at(0),c=l.at(-1);if(!s.shiftKey){document.activeElement===c&&(s.preventDefault(),u?.focus());return}document.activeElement===u&&(s.preventDefault(),c?.focus())};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[r]),[i,a]};import{useEffect as oe,useMemo as se,useRef as ie,useState as W}from"react";var dt=(e,r={})=>{let{initial:t=!1,once:n,amount:i,margin:a,root:o,enable:s=!0,onStart:l}=r,u=ie(!0),[c,p]=W(t),[m,T]=W(s),y=se(()=>{if(!m||typeof IntersectionObserver>"u")return;let Q=i==="all"?1:i==="some"?.5:i;try{return new IntersectionObserver(async([v],k)=>{if(!v)return;let O=v.isIntersecting;try{if(await l?.(v,k),!u.current)return;p(O)}catch($){console.error($)}O&&n&&k.disconnect()},{root:o||void 0,rootMargin:a,threshold:Q})}catch(v){console.error(v)}},[o,a,i,n,m,l]);return oe(()=>{if(u.current=!0,!(!m||!e.current||!y))return y.observe(e.current),()=>{u.current=!1,y.disconnect()}},[e,y,m]),{inView:c,enabled:m,observer:y,setInView:p,setEnabled:T}};import{useCallback as A}from"react";import{blockScroll as ae,restoreScroll as ue}from"@alessiofrittoli/web-utils/dom";var Et=e=>{let r=A(()=>ae(e?.current||void 0),[e]),t=A(()=>ue(e?.current||void 0),[e]);return[r,t]};import{useMemo as le,useState as me}from"react";import{useEffect as ce}from"react";var U=(e,r={})=>{let{delay:t=1,args:n}=r;ce(()=>{let i=setTimeout(e,t,...n||[]);return()=>clearTimeout(i)},[t,n,e])};var Ot=(e,r=500)=>{let[t,n]=me(e),i=le(()=>[e],[e]);return U(n,{delay:r,args:i}),t};import{useCallback as b,useEffect as pe,useRef as de,useState as fe}from"react";function F(e,r={}){let{delay:t=1,args:n,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,s=de(void 0),[l,u]=fe(i),c=b(()=>s.current?(clearInterval(s.current),s.current=void 0,!0):!1,[]),p=b(()=>{let T=c();return a&&(n?e(...n):e()),s.current=setInterval(e,t,...n||[]),!T&&o&&u(!0),s.current},[t,n,o,a,e,c]),m=b(()=>{c()&&o&&u(!1)},[o,c]);return pe(()=>{if(i)return p(),m},[i,p,m]),o?{isActive:l,start:p,stop:m}:{start:p,stop:m}}import{useEffect as Te}from"react";var Ct=(e,r={})=>{let{delay:t=1,args:n}=r;Te(()=>{let i=setInterval(e,t,...n||[]);return()=>clearInterval(i)},[t,n,e])};import{useCallback as L,useEffect as ye}from"react";function Ut(e,r={}){let{autoplay:t=!0}=r,n=F(e,{autoplay:!1,...r}),{start:i,stop:a}=n,o=L(()=>document.hidden?a():i(),[i,a]),s=L(()=>{if(document.addEventListener("visibilitychange",o),!document.hidden)return i()},[i,o]),l=L(()=>{a(),document.removeEventListener("visibilitychange",o)},[a,o]);return ye(()=>{if(t)return s(),l},[t,s,l]),{...n,start:s,stop:l}}import{useCallback as g,useEffect as ve,useRef as Ee,useState as Me}from"react";function jt(e,r={}){let{delay:t=1,args:n,autoplay:i=!0,runOnStart:a=!1,updateState:o=!1}=r,s=Ee(void 0),[l,u]=Me(i),c=g(()=>s.current?(clearTimeout(s.current),s.current=void 0,!0):!1,[]),p=g(()=>{let T=c();return a&&(n?e(...n):e()),s.current=setTimeout(()=>{if(s.current=void 0,o&&u(!1),n)return e(...n);e()},t),!T&&o&&u(!0),s.current},[t,n,o,a,e,c]),m=g(()=>{c()&&o&&u(!1)},[o,c]);return ve(()=>{if(i)return p(),m},[i,p,m]),o?{isActive:l,start:p,stop:m}:{start:p,stop:m}}export{Xe as useDarkMode,Ot as useDebounce,et as useEventListener,ct as useFocusTrap,dt as useInView,F as useInterval,Ut as useIntervalWhenVisible,I as useIsClient,H as useIsFirstRender,st as useIsPortrait,Ct as useLightInterval,U as useLightTimeout,w as useLocalStorage,M as useMediaQuery,Et as useScrollBlock,De as useSessionStorage,E as useStorage,jt as useTimeout,x as useUpdateEffect};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/react-hooks",
3
- "version": "1.2.0",
3
+ "version": "2.0.1",
4
4
  "description": "TypeScript React utility Hooks",
5
5
  "author": {
6
6
  "name": "Alessio Frittoli",
@@ -35,34 +35,24 @@
35
35
  ],
36
36
  "exports": {
37
37
  ".": {
38
- "types": "./dist/index.d.ts",
39
- "import": "./dist/index.mjs",
40
- "require": "./dist/index.js"
41
- },
42
- "./browser-api": {
43
- "types": "./dist/browser-api/index.d.ts",
44
- "import": "./dist/browser-api/index.mjs",
45
- "require": "./dist/browser-api/index.js"
46
- },
47
- "./browser-api/storage": {
48
- "types": "./dist/browser-api/storage/index.d.ts",
49
- "import": "./dist/browser-api/storage/index.mjs",
50
- "require": "./dist/browser-api/storage/index.js"
51
- },
52
- "./dom-api": {
53
- "types": "./dist/dom-api/index.d.ts",
54
- "import": "./dist/dom-api/index.mjs",
55
- "require": "./dist/dom-api/index.js"
56
- },
57
- "./misc": {
58
- "types": "./dist/misc/index.d.ts",
59
- "import": "./dist/misc/index.mjs",
60
- "require": "./dist/misc/index.js"
38
+ "import": {
39
+ "types": "./dist/index.d.mts",
40
+ "default": "./dist/index.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/index.d.ts",
44
+ "default": "./dist/index.js"
45
+ }
61
46
  },
62
47
  "./eslint": {
63
- "types": "./dist/eslint.d.ts",
64
- "import": "./dist/eslint.mjs",
65
- "require": "./dist/eslint.js"
48
+ "import": {
49
+ "types": "./dist/eslint.d.mts",
50
+ "default": "./dist/eslint.mjs"
51
+ },
52
+ "require": {
53
+ "types": "./dist/eslint.d.ts",
54
+ "default": "./dist/eslint.js"
55
+ }
66
56
  }
67
57
  },
68
58
  "sideEffects": false,
@@ -94,7 +84,8 @@
94
84
  "test:storage": "pnpm test:watch browser-api/storage/*",
95
85
  "test:browser-api": "pnpm test:watch --testPathPattern='browser-api/(?!storage/).*\\.test\\.(js|jsx|ts|tsx)'",
96
86
  "test:dom-api": "pnpm test:watch dom-api/*",
97
- "test:misc": "pnpm test:watch misc/*"
87
+ "test:misc": "pnpm test:watch misc/*",
88
+ "test:timers": "pnpm test:watch timers/*"
98
89
  },
99
90
  "pnpm": {
100
91
  "onlyBuiltDependencies": [
@@ -103,6 +94,7 @@
103
94
  ]
104
95
  },
105
96
  "devDependencies": {
97
+ "@alessiofrittoli/event-emitter": "^1.4.0",
106
98
  "@alessiofrittoli/node-scripts": "^2.5.0",
107
99
  "@eslint/compat": "^1.2.9",
108
100
  "@eslint/eslintrc": "^3.3.1",
@@ -113,25 +105,25 @@
113
105
  "@testing-library/react": "^16.3.0",
114
106
  "@testing-library/user-event": "^14.6.1",
115
107
  "@types/jest": "^29.5.14",
116
- "@types/node": "^22.15.3",
117
- "@types/react": "^19.1.2",
118
- "@types/react-dom": "^19.1.3",
108
+ "@types/node": "^22.15.18",
109
+ "@types/react": "^19.1.4",
110
+ "@types/react-dom": "^19.1.5",
119
111
  "concurrently": "^9.1.2",
120
112
  "dotenv": "^16.5.0",
121
113
  "eslint": "^9.26.0",
122
114
  "eslint-plugin-react": "^7.37.5",
123
115
  "eslint-plugin-react-hooks": "^5.2.0",
124
- "globals": "^16.0.0",
116
+ "globals": "^16.1.0",
125
117
  "http-server": "^14.1.1",
126
118
  "jest": "^29.7.0",
127
119
  "jest-environment-jsdom": "^29.7.0",
128
120
  "react": "^19.1.0",
129
121
  "react-dom": "^19.1.0",
130
- "ts-jest": "^29.3.2",
122
+ "ts-jest": "^29.3.3",
131
123
  "ts-node": "^10.9.2",
132
124
  "tsup": "^8.4.0",
133
125
  "typescript": "^5.8.3",
134
- "typescript-eslint": "^8.31.1"
126
+ "typescript-eslint": "^8.32.1"
135
127
  },
136
128
  "dependencies": {
137
129
  "@alessiofrittoli/math-utils": "^1.13.0",
@@ -1,6 +0,0 @@
1
- export { useStorage } from './storage/useStorage.mjs';
2
- export { useLocalStorage } from './storage/useLocalStorage.mjs';
3
- export { useSessionStorage } from './storage/useSessionStorage.mjs';
4
- export { useIsPortrait } from './useIsPortrait.mjs';
5
- export { useMediaQuery } from './useMediaQuery.mjs';
6
- import 'react';
@@ -1,6 +0,0 @@
1
- export { useStorage } from './storage/useStorage.js';
2
- export { useLocalStorage } from './storage/useLocalStorage.js';
3
- export { useSessionStorage } from './storage/useSessionStorage.js';
4
- export { useIsPortrait } from './useIsPortrait.js';
5
- export { useMediaQuery } from './useMediaQuery.js';
6
- import 'react';
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-TA6PCHH4.js');require('../chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('../chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('../chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('../chunk-7ILYMOVB.js');var _chunkWOVEE75Mjs = require('../chunk-WOVEE75M.js');var _chunkFUCUVFLWjs = require('../chunk-FUCUVFLW.js');exports.useIsPortrait = _chunkWOVEE75Mjs.a; exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useMediaQuery = _chunkFUCUVFLWjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a;
@@ -1 +0,0 @@
1
- import"../chunk-YQO25XKN.mjs";import"../chunk-2CZNCZFR.mjs";import{a as b}from"../chunk-YAZXPL6I.mjs";import{a as c}from"../chunk-UXNKH2MC.mjs";import{a}from"../chunk-HZLWSH3W.mjs";import{a as e}from"../chunk-RENUP2VU.mjs";import{a as d}from"../chunk-AJKPRTOJ.mjs";export{e as useIsPortrait,b as useLocalStorage,d as useMediaQuery,c as useSessionStorage,a as useStorage};
@@ -1,4 +0,0 @@
1
- export { useStorage } from './useStorage.mjs';
2
- export { useLocalStorage } from './useLocalStorage.mjs';
3
- export { useSessionStorage } from './useSessionStorage.mjs';
4
- import 'react';
@@ -1,4 +0,0 @@
1
- export { useStorage } from './useStorage.js';
2
- export { useLocalStorage } from './useLocalStorage.js';
3
- export { useSessionStorage } from './useSessionStorage.js';
4
- import 'react';
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-4BGMCO3F.js');var _chunkIDNLFWFOjs = require('../../chunk-IDNLFWFO.js');var _chunkG55NP3QGjs = require('../../chunk-G55NP3QG.js');var _chunk7ILYMOVBjs = require('../../chunk-7ILYMOVB.js');exports.useLocalStorage = _chunkIDNLFWFOjs.a; exports.useSessionStorage = _chunkG55NP3QGjs.a; exports.useStorage = _chunk7ILYMOVBjs.a;
@@ -1 +0,0 @@
1
- import"../../chunk-2CZNCZFR.mjs";import{a as b}from"../../chunk-YAZXPL6I.mjs";import{a as c}from"../../chunk-UXNKH2MC.mjs";import{a}from"../../chunk-HZLWSH3W.mjs";export{b as useLocalStorage,c as useSessionStorage,a as useStorage};
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- /**
4
- * useLocalStorage hook.
5
- *
6
- * @param key The local storage item key.
7
- * @param initialValue The local storage item initial value.
8
- */
9
- declare const useLocalStorage: <T = string>(key: string, initialValue?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
10
-
11
- export { useLocalStorage };
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- /**
4
- * useLocalStorage hook.
5
- *
6
- * @param key The local storage item key.
7
- * @param initialValue The local storage item initial value.
8
- */
9
- declare const useLocalStorage: <T = string>(key: string, initialValue?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
10
-
11
- export { useLocalStorage };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIDNLFWFOjs = require('../../chunk-IDNLFWFO.js');require('../../chunk-7ILYMOVB.js');exports.useLocalStorage = _chunkIDNLFWFOjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../../chunk-YAZXPL6I.mjs";import"../../chunk-HZLWSH3W.mjs";export{a as useLocalStorage};
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- /**
4
- * useSessionStorage hook.
5
- *
6
- * @param key The session item key.
7
- * @param initialValue The session item initial value.
8
- */
9
- declare const useSessionStorage: <T = string>(key: string, initialValue?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
10
-
11
- export { useSessionStorage };
@@ -1,11 +0,0 @@
1
- import * as react from 'react';
2
-
3
- /**
4
- * useSessionStorage hook.
5
- *
6
- * @param key The session item key.
7
- * @param initialValue The session item initial value.
8
- */
9
- declare const useSessionStorage: <T = string>(key: string, initialValue?: T) => [T | null | undefined, (value: react.SetStateAction<T | null | undefined>) => void];
10
-
11
- export { useSessionStorage };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkG55NP3QGjs = require('../../chunk-G55NP3QG.js');require('../../chunk-7ILYMOVB.js');exports.useSessionStorage = _chunkG55NP3QGjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../../chunk-UXNKH2MC.mjs";import"../../chunk-HZLWSH3W.mjs";export{a as useSessionStorage};
@@ -1,12 +0,0 @@
1
- type Value<T> = T | undefined | null;
2
- type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
3
- /**
4
- * Easly handle Local or Session Storage State.
5
- *
6
- * @param key The storage item key.
7
- * @param initialValue The storage item initial value.
8
- * @param type ( Optional ) The storage API to use. Default: `local`.
9
- */
10
- declare const useStorage: <T = string>(key: string, initialValue?: T, type?: "local" | "session") => [Value<T>, SetValue<Value<T>>];
11
-
12
- export { useStorage };
@@ -1,12 +0,0 @@
1
- type Value<T> = T | undefined | null;
2
- type SetValue<T> = React.Dispatch<React.SetStateAction<T>>;
3
- /**
4
- * Easly handle Local or Session Storage State.
5
- *
6
- * @param key The storage item key.
7
- * @param initialValue The storage item initial value.
8
- * @param type ( Optional ) The storage API to use. Default: `local`.
9
- */
10
- declare const useStorage: <T = string>(key: string, initialValue?: T, type?: "local" | "session") => [Value<T>, SetValue<Value<T>>];
11
-
12
- export { useStorage };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('../../chunk-7ILYMOVB.js');exports.useStorage = _chunk7ILYMOVBjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../../chunk-HZLWSH3W.mjs";export{a as useStorage};
@@ -1,10 +0,0 @@
1
- /**
2
- * Check if device is portrait oriented.
3
- *
4
- * State get updated when device orientation changes.
5
- *
6
- * @returns `true` if the device is portrait oriented, `false` otherwise.
7
- */
8
- declare const useIsPortrait: () => boolean;
9
-
10
- export { useIsPortrait };
@@ -1,10 +0,0 @@
1
- /**
2
- * Check if device is portrait oriented.
3
- *
4
- * State get updated when device orientation changes.
5
- *
6
- * @returns `true` if the device is portrait oriented, `false` otherwise.
7
- */
8
- declare const useIsPortrait: () => boolean;
9
-
10
- export { useIsPortrait };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkWOVEE75Mjs = require('../chunk-WOVEE75M.js');require('../chunk-FUCUVFLW.js');exports.useIsPortrait = _chunkWOVEE75Mjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../chunk-RENUP2VU.mjs";import"../chunk-AJKPRTOJ.mjs";export{a as useIsPortrait};
@@ -1,11 +0,0 @@
1
- /**
2
- * Get Document Media matches and listen for changes.
3
- *
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)
5
- *
6
- * @param query A string specifying the media query to parse into a `MediaQueryList`.
7
- * @returns A boolean value that returns `true` if the document currently matches the media query list, or `false` if not.
8
- */
9
- declare const useMediaQuery: (query: string) => boolean;
10
-
11
- export { useMediaQuery };
@@ -1,11 +0,0 @@
1
- /**
2
- * Get Document Media matches and listen for changes.
3
- *
4
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)
5
- *
6
- * @param query A string specifying the media query to parse into a `MediaQueryList`.
7
- * @returns A boolean value that returns `true` if the document currently matches the media query list, or `false` if not.
8
- */
9
- declare const useMediaQuery: (query: string) => boolean;
10
-
11
- export { useMediaQuery };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFUCUVFLWjs = require('../chunk-FUCUVFLW.js');exports.useMediaQuery = _chunkFUCUVFLWjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../chunk-AJKPRTOJ.mjs";export{a as useMediaQuery};
@@ -1 +0,0 @@
1
- import{useRef as e}from"react";var n=()=>{let r=e(!0);return r.current?(r.current=!1,!0):r.current};export{n as a};
File without changes
@@ -1 +0,0 @@
1
- import{useCallback as o}from"react";import{blockScroll as e,restoreScroll as n}from"@alessiofrittoli/web-utils/dom";var d=l=>{let r=o(()=>e(l?.current||void 0),[l]),c=o(()=>n(l?.current||void 0),[l]);return[r,c]};export{d as a};
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- import{useEffect as s,useState as n}from"react";var u=()=>{let[e,t]=n(!1);return s(()=>t(!0),[]),e};export{u as a};
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- import{useCallback as l,useEffect as m,useRef as p,useState as T}from"react";var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),y=n=>{let[r,o]=T(!1),s=p(null),f=l(t=>{s.current=document.activeElement;let e=t||n?.current||!1;if(e)return o(e)},[n]),i=l(()=>{s.current?.focus(),o(!1)},[]);return m(()=>{if(!r)return;let t=e=>{if(e.key!=="Tab")return;let c=Array.from(r.querySelectorAll(E)),u=c.at(0),a=c.at(-1);if(!e.shiftKey){document.activeElement===a&&(e.preventDefault(),u?.focus());return}document.activeElement===u&&(e.preventDefault(),a?.focus())};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[r]),[f,i]};export{y as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _react = require('react');var _LocalStorage = require('@alessiofrittoli/web-utils/storage/LocalStorage');var _SessionStorage = require('@alessiofrittoli/web-utils/storage/SessionStorage');var w=(e,o,t="local")=>{let s=_react.useCallback.call(void 0, ()=>_nullishCoalesce((t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).get(e), () => (o)),[t,e,o]),[S,l]=_react.useState.call(void 0, o),T=_react.useCallback.call(void 0, a=>{l(V=>{let n=a instanceof Function?a(V):a;return(typeof window<"u"&&t==="local"?_LocalStorage.LocalStorage:_SessionStorage.SessionStorage).set(e,n),n})},[t,e]);return _react.useEffect.call(void 0, ()=>{l(s())},[s]),[S,T]};exports.a = w;
@@ -1 +0,0 @@
1
- import{useCallback as i,useEffect as o,useState as r}from"react";import{getMediaMatches as n}from"@alessiofrittoli/web-utils/browser-api";var g=e=>{let[s,c]=r(n(e)),t=i(()=>c(n(e)),[e]);return o(()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t)}},[e,t]),s};export{g as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHO57SPSTjs = require('./chunk-HO57SPST.js');var _react = require('react');var n=(t,r)=>{let s=_chunkHO57SPSTjs.a.call(void 0, );_react.useEffect.call(void 0, ()=>{if(!s)return t()},r)};exports.a = n;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var _browserapi = require('@alessiofrittoli/web-utils/browser-api');var M=e=>{let[s,c]=_react.useState.call(void 0, _browserapi.getMediaMatches.call(void 0, e)),t=_react.useCallback.call(void 0, ()=>c(_browserapi.getMediaMatches.call(void 0, e)),[e]);return _react.useEffect.call(void 0, ()=>{let a=window.matchMedia(e);return t(),a.addEventListener("change",t),()=>{a.removeEventListener("change",t)}},[e,t]),s};exports.a = M;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var i=(o,e)=>_chunk7ILYMOVBjs.a.call(void 0, o,e,"session");exports.a = i;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var u=()=>{let r=_react.useRef.call(void 0, !0);return r.current?(r.current=!1,!0):r.current};exports.a = u;
@@ -1 +0,0 @@
1
- import{useCallback as r,useEffect as f,useState as d}from"react";import{LocalStorage as u}from"@alessiofrittoli/web-utils/storage/LocalStorage";import{SessionStorage as c}from"@alessiofrittoli/web-utils/storage/SessionStorage";var R=(e,o,t="local")=>{let s=r(()=>(t==="local"?u:c).get(e)??o,[t,e,o]),[S,l]=d(o),T=r(a=>{l(V=>{let n=a instanceof Function?a(V):a;return(typeof window<"u"&&t==="local"?u:c).set(e,n),n})},[t,e]);return f(()=>{l(s())},[s]),[S,T]};export{R as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7ILYMOVBjs = require('./chunk-7ILYMOVB.js');var a=(r,t)=>_chunk7ILYMOVBjs.a.call(void 0, r,t,"local");exports.a = a;
@@ -1 +0,0 @@
1
- import{a as r}from"./chunk-AJKPRTOJ.mjs";import{portraitMediaQuery as o}from"@alessiofrittoli/web-utils/device";var m=()=>r(o);export{m as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var _dom = require('@alessiofrittoli/web-utils/dom');var S=l=>{let r=_react.useCallback.call(void 0, ()=>_dom.blockScroll.call(void 0, _optionalChain([l, 'optionalAccess', _ => _.current])||void 0),[l]),c=_react.useCallback.call(void 0, ()=>_dom.restoreScroll.call(void 0, _optionalChain([l, 'optionalAccess', _2 => _2.current])||void 0),[l]);return[r,c]};exports.a = S;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var E=["input","select","textarea","button","[href]",'[tabindex]:not([tabindex="-1"])'].join(", "),b= exports.a =n=>{let[r,o]=_react.useState.call(void 0, !1),s=_react.useRef.call(void 0, null),f=_react.useCallback.call(void 0, t=>{s.current=document.activeElement;let e=t||_optionalChain([n, 'optionalAccess', _ => _.current])||!1;if(e)return o(e)},[n]),i=_react.useCallback.call(void 0, ()=>{_optionalChain([s, 'access', _2 => _2.current, 'optionalAccess', _3 => _3.focus, 'call', _4 => _4()]),o(!1)},[]);return _react.useEffect.call(void 0, ()=>{if(!r)return;let t=e=>{if(e.key!=="Tab")return;let c=Array.from(r.querySelectorAll(E)),u=c.at(0),a=c.at(-1);if(!e.shiftKey){document.activeElement===a&&(e.preventDefault(),_optionalChain([u, 'optionalAccess', _5 => _5.focus, 'call', _6 => _6()]));return}document.activeElement===u&&(e.preventDefault(),_optionalChain([a, 'optionalAccess', _7 => _7.focus, 'call', _8 => _8()]))};return document.addEventListener("keydown",t),()=>{document.removeEventListener("keydown",t)}},[r]),[f,i]};exports.a = b;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-26XSIIUK.mjs";import{useEffect as c}from"react";var a=(t,r)=>{let s=e();c(()=>{if(!s)return t()},r)};export{a};
@@ -1 +0,0 @@
1
- import{a as s}from"./chunk-HZLWSH3W.mjs";var n=(o,e)=>s(o,e,"session");export{n as a};
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var o=()=>{let[e,t]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>t(!0),[]),e};exports.a = o;
File without changes
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFUCUVFLWjs = require('./chunk-FUCUVFLW.js');var _device = require('@alessiofrittoli/web-utils/device');var a=()=>_chunkFUCUVFLWjs.a.call(void 0, _device.portraitMediaQuery);exports.a = a;
@@ -1 +0,0 @@
1
- import{a as o}from"./chunk-HZLWSH3W.mjs";var g=(r,t)=>o(r,t,"local");export{g as a};
@@ -1 +0,0 @@
1
- "use strict";
File without changes
File without changes
@@ -1,2 +0,0 @@
1
- export { useFocusTrap } from './useFocusTrap.mjs';
2
- export { useScrollBlock } from './useScrollBlock.mjs';
@@ -1,2 +0,0 @@
1
- export { useFocusTrap } from './useFocusTrap.js';
2
- export { useScrollBlock } from './useScrollBlock.js';
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-6BSD56XC.js');var _chunkSW7BCMZFjs = require('../chunk-SW7BCMZF.js');var _chunkSNMJ53QBjs = require('../chunk-SNMJ53QB.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a; exports.useScrollBlock = _chunkSNMJ53QBjs.a;
@@ -1 +0,0 @@
1
- import"../chunk-WLIFJNZA.mjs";import{a}from"../chunk-6IRIG5HU.mjs";import{a as b}from"../chunk-43RVMR6S.mjs";export{a as useFocusTrap,b as useScrollBlock};
@@ -1,15 +0,0 @@
1
- type SetFocusTrap = (target?: HTMLElement) => void;
2
- type RestoreFocusTrap = () => void;
3
- /**
4
- * Trap focus inside the given HTML Element.
5
- *
6
- * @param target (Optional) The target HTMLElement React RefObject to trap focus within.
7
- * If no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.
8
- *
9
- * @returns A tuple containing:
10
- * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.
11
- * - `restoreFocusTrap`: A function to restore the previous focus state.
12
- */
13
- declare const useFocusTrap: (target?: React.RefObject<HTMLElement | null>) => readonly [SetFocusTrap, RestoreFocusTrap];
14
-
15
- export { useFocusTrap };
@@ -1,15 +0,0 @@
1
- type SetFocusTrap = (target?: HTMLElement) => void;
2
- type RestoreFocusTrap = () => void;
3
- /**
4
- * Trap focus inside the given HTML Element.
5
- *
6
- * @param target (Optional) The target HTMLElement React RefObject to trap focus within.
7
- * If no target is given, you must provide the target HTMLElement when calling `setFocusTrap`.
8
- *
9
- * @returns A tuple containing:
10
- * - `setFocusTrap`: A function to enable the focus trap. Optionally accept an HTMLElement as target.
11
- * - `restoreFocusTrap`: A function to restore the previous focus state.
12
- */
13
- declare const useFocusTrap: (target?: React.RefObject<HTMLElement | null>) => readonly [SetFocusTrap, RestoreFocusTrap];
14
-
15
- export { useFocusTrap };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSW7BCMZFjs = require('../chunk-SW7BCMZF.js');exports.useFocusTrap = _chunkSW7BCMZFjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../chunk-6IRIG5HU.mjs";export{a as useFocusTrap};
@@ -1,8 +0,0 @@
1
- /**
2
- * Prevent Element overflow.
3
- *
4
- * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.
5
- */
6
- declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
7
-
8
- export { useScrollBlock };
@@ -1,8 +0,0 @@
1
- /**
2
- * Prevent Element overflow.
3
- *
4
- * @param target (Optional) The React RefObject target HTMLElement. Default: `Document.documentElement`.
5
- */
6
- declare const useScrollBlock: (target?: React.RefObject<HTMLElement | null>) => readonly [() => void, () => void];
7
-
8
- export { useScrollBlock };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSNMJ53QBjs = require('../chunk-SNMJ53QB.js');exports.useScrollBlock = _chunkSNMJ53QBjs.a;
@@ -1 +0,0 @@
1
- import{a}from"../chunk-43RVMR6S.mjs";export{a as useScrollBlock};
@@ -1,3 +0,0 @@
1
- export { useIsClient } from './useIsClient.mjs';
2
- export { useIsFirstRender } from './useIsFirstRender.mjs';
3
- export { useUpdateEffect } from './useUpdateEffect.mjs';
@@ -1,3 +0,0 @@
1
- export { useIsClient } from './useIsClient.js';
2
- export { useIsFirstRender } from './useIsFirstRender.js';
3
- export { useUpdateEffect } from './useUpdateEffect.js';
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-YLUTFORB.js');var _chunkVLSP3MANjs = require('../chunk-VLSP3MAN.js');var _chunkEFFJB2GRjs = require('../chunk-EFFJB2GR.js');var _chunkHO57SPSTjs = require('../chunk-HO57SPST.js');exports.useIsClient = _chunkVLSP3MANjs.a; exports.useIsFirstRender = _chunkHO57SPSTjs.a; exports.useUpdateEffect = _chunkEFFJB2GRjs.a;
@@ -1 +0,0 @@
1
- import"../chunk-ZNAB4TYW.mjs";import{a}from"../chunk-65SF33P4.mjs";import{a as c}from"../chunk-UAJXVBNR.mjs";import{a as b}from"../chunk-26XSIIUK.mjs";export{a as useIsClient,b as useIsFirstRender,c as useUpdateEffect};
@@ -1,8 +0,0 @@
1
- /**
2
- * Check if the React Hook or Component where this hook is executed is running in a browser environment.
3
- *
4
- * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
5
- */
6
- declare const useIsClient: () => boolean;
7
-
8
- export { useIsClient };
@@ -1,8 +0,0 @@
1
- /**
2
- * Check if the React Hook or Component where this hook is executed is running in a browser environment.
3
- *
4
- * @returns `true` if the React Hook or Component is running in a browser environment, `false` otherwise.
5
- */
6
- declare const useIsClient: () => boolean;
7
-
8
- export { useIsClient };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkVLSP3MANjs = require('../chunk-VLSP3MAN.js');exports.useIsClient = _chunkVLSP3MANjs.a;