@alessiofrittoli/react-hooks 1.2.0 → 2.0.0
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/README.md +387 -73
- package/dist/eslint.js +1 -1
- package/dist/eslint.mjs +1 -1
- package/dist/index.d.mts +940 -11
- package/dist/index.d.ts +940 -11
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +132 -146
- package/dist/browser-api/index.d.mts +0 -6
- package/dist/browser-api/index.d.ts +0 -6
- package/dist/browser-api/index.js +0 -1
- package/dist/browser-api/index.mjs +0 -1
- package/dist/browser-api/storage/index.d.mts +0 -4
- package/dist/browser-api/storage/index.d.ts +0 -4
- package/dist/browser-api/storage/index.js +0 -1
- package/dist/browser-api/storage/index.mjs +0 -1
- package/dist/browser-api/storage/useLocalStorage.d.mts +0 -11
- package/dist/browser-api/storage/useLocalStorage.d.ts +0 -11
- package/dist/browser-api/storage/useLocalStorage.js +0 -1
- package/dist/browser-api/storage/useLocalStorage.mjs +0 -1
- package/dist/browser-api/storage/useSessionStorage.d.mts +0 -11
- package/dist/browser-api/storage/useSessionStorage.d.ts +0 -11
- package/dist/browser-api/storage/useSessionStorage.js +0 -1
- package/dist/browser-api/storage/useSessionStorage.mjs +0 -1
- package/dist/browser-api/storage/useStorage.d.mts +0 -12
- package/dist/browser-api/storage/useStorage.d.ts +0 -12
- package/dist/browser-api/storage/useStorage.js +0 -1
- package/dist/browser-api/storage/useStorage.mjs +0 -1
- package/dist/browser-api/useIsPortrait.d.mts +0 -10
- package/dist/browser-api/useIsPortrait.d.ts +0 -10
- package/dist/browser-api/useIsPortrait.js +0 -1
- package/dist/browser-api/useIsPortrait.mjs +0 -1
- package/dist/browser-api/useMediaQuery.d.mts +0 -11
- package/dist/browser-api/useMediaQuery.d.ts +0 -11
- package/dist/browser-api/useMediaQuery.js +0 -1
- package/dist/browser-api/useMediaQuery.mjs +0 -1
- package/dist/chunk-26XSIIUK.mjs +0 -1
- package/dist/chunk-2CZNCZFR.mjs +0 -0
- package/dist/chunk-43RVMR6S.mjs +0 -1
- package/dist/chunk-4BGMCO3F.js +0 -1
- package/dist/chunk-65SF33P4.mjs +0 -1
- package/dist/chunk-6BSD56XC.js +0 -1
- package/dist/chunk-6IRIG5HU.mjs +0 -1
- package/dist/chunk-7ILYMOVB.js +0 -1
- package/dist/chunk-AJKPRTOJ.mjs +0 -1
- package/dist/chunk-EFFJB2GR.js +0 -1
- package/dist/chunk-FUCUVFLW.js +0 -1
- package/dist/chunk-G55NP3QG.js +0 -1
- package/dist/chunk-HO57SPST.js +0 -1
- package/dist/chunk-HZLWSH3W.mjs +0 -1
- package/dist/chunk-IDNLFWFO.js +0 -1
- package/dist/chunk-RENUP2VU.mjs +0 -1
- package/dist/chunk-SNMJ53QB.js +0 -1
- package/dist/chunk-SW7BCMZF.js +0 -1
- package/dist/chunk-TA6PCHH4.js +0 -1
- package/dist/chunk-UAJXVBNR.mjs +0 -1
- package/dist/chunk-UXNKH2MC.mjs +0 -1
- package/dist/chunk-VLSP3MAN.js +0 -1
- package/dist/chunk-WLIFJNZA.mjs +0 -0
- package/dist/chunk-WOVEE75M.js +0 -1
- package/dist/chunk-YAZXPL6I.mjs +0 -1
- package/dist/chunk-YLUTFORB.js +0 -1
- package/dist/chunk-YQO25XKN.mjs +0 -0
- package/dist/chunk-ZNAB4TYW.mjs +0 -0
- package/dist/dom-api/index.d.mts +0 -2
- package/dist/dom-api/index.d.ts +0 -2
- package/dist/dom-api/index.js +0 -1
- package/dist/dom-api/index.mjs +0 -1
- package/dist/dom-api/useFocusTrap.d.mts +0 -15
- package/dist/dom-api/useFocusTrap.d.ts +0 -15
- package/dist/dom-api/useFocusTrap.js +0 -1
- package/dist/dom-api/useFocusTrap.mjs +0 -1
- package/dist/dom-api/useScrollBlock.d.mts +0 -8
- package/dist/dom-api/useScrollBlock.d.ts +0 -8
- package/dist/dom-api/useScrollBlock.js +0 -1
- package/dist/dom-api/useScrollBlock.mjs +0 -1
- package/dist/misc/index.d.mts +0 -3
- package/dist/misc/index.d.ts +0 -3
- package/dist/misc/index.js +0 -1
- package/dist/misc/index.mjs +0 -1
- package/dist/misc/useIsClient.d.mts +0 -8
- package/dist/misc/useIsClient.d.ts +0 -8
- package/dist/misc/useIsClient.js +0 -1
- package/dist/misc/useIsClient.mjs +0 -1
- package/dist/misc/useIsFirstRender.d.mts +0 -9
- package/dist/misc/useIsFirstRender.d.ts +0 -9
- package/dist/misc/useIsFirstRender.js +0 -1
- package/dist/misc/useIsFirstRender.mjs +0 -1
- package/dist/misc/usePagination.d.mts +0 -12
- package/dist/misc/usePagination.d.ts +0 -12
- package/dist/misc/usePagination.js +0 -1
- package/dist/misc/usePagination.mjs +0 -1
- package/dist/misc/useUpdateEffect.d.mts +0 -9
- package/dist/misc/useUpdateEffect.d.ts +0 -9
- package/dist/misc/useUpdateEffect.js +0 -1
- package/dist/misc/useUpdateEffect.mjs +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
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"
|
|
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,147 +1,133 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"typescript-eslint": "^8.31.1"
|
|
135
|
-
},
|
|
136
|
-
"dependencies": {
|
|
137
|
-
"@alessiofrittoli/math-utils": "^1.13.0",
|
|
138
|
-
"@alessiofrittoli/type-utils": "^1.8.0",
|
|
139
|
-
"@alessiofrittoli/web-utils": "^1.10.0"
|
|
140
|
-
},
|
|
141
|
-
"peerDependencies": {
|
|
142
|
-
"@types/react": "^19",
|
|
143
|
-
"@types/react-dom": "^19",
|
|
144
|
-
"react": "^19",
|
|
145
|
-
"react-dom": "^19"
|
|
146
|
-
}
|
|
147
|
-
}
|
|
2
|
+
"name": "@alessiofrittoli/react-hooks",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "TypeScript React utility Hooks",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Alessio Frittoli",
|
|
7
|
+
"email": "info@alessiofrittoli.it",
|
|
8
|
+
"url": "https://alessiofrittoli.it"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": [
|
|
12
|
+
{
|
|
13
|
+
"type": "github",
|
|
14
|
+
"url": "https://github.com/sponsors/alessiofrittoli"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react",
|
|
19
|
+
"react-hooks"
|
|
20
|
+
],
|
|
21
|
+
"homepage": "https://github.com/alessiofrittoli/react-hooks#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/alessiofrittoli/react-hooks/issues",
|
|
24
|
+
"email": "info@alessiofrittoli.it"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/alessiofrittoli/react-hooks.git"
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
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
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./eslint": {
|
|
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
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"sideEffects": false,
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@alessiofrittoli/event-emitter": "^1.4.0",
|
|
61
|
+
"@alessiofrittoli/node-scripts": "^2.5.0",
|
|
62
|
+
"@eslint/compat": "^1.2.9",
|
|
63
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
64
|
+
"@eslint/js": "^9.26.0",
|
|
65
|
+
"@jest/globals": "^29.7.0",
|
|
66
|
+
"@testing-library/dom": "^10.4.0",
|
|
67
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
68
|
+
"@testing-library/react": "^16.3.0",
|
|
69
|
+
"@testing-library/user-event": "^14.6.1",
|
|
70
|
+
"@types/jest": "^29.5.14",
|
|
71
|
+
"@types/node": "^22.15.18",
|
|
72
|
+
"@types/react": "^19.1.4",
|
|
73
|
+
"@types/react-dom": "^19.1.5",
|
|
74
|
+
"concurrently": "^9.1.2",
|
|
75
|
+
"dotenv": "^16.5.0",
|
|
76
|
+
"eslint": "^9.26.0",
|
|
77
|
+
"eslint-plugin-react": "^7.37.5",
|
|
78
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
79
|
+
"globals": "^16.1.0",
|
|
80
|
+
"http-server": "^14.1.1",
|
|
81
|
+
"jest": "^29.7.0",
|
|
82
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
83
|
+
"react": "^19.1.0",
|
|
84
|
+
"react-dom": "^19.1.0",
|
|
85
|
+
"ts-jest": "^29.3.3",
|
|
86
|
+
"ts-node": "^10.9.2",
|
|
87
|
+
"tsup": "^8.4.0",
|
|
88
|
+
"typescript": "^5.8.3",
|
|
89
|
+
"typescript-eslint": "^8.32.1"
|
|
90
|
+
},
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"@alessiofrittoli/math-utils": "^1.13.0",
|
|
93
|
+
"@alessiofrittoli/type-utils": "^1.8.0",
|
|
94
|
+
"@alessiofrittoli/web-utils": "^1.10.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@types/react": "^19",
|
|
98
|
+
"@types/react-dom": "^19",
|
|
99
|
+
"react": "^19",
|
|
100
|
+
"react-dom": "^19"
|
|
101
|
+
},
|
|
102
|
+
"scripts": {
|
|
103
|
+
"//1a": "*********************************************************************",
|
|
104
|
+
"//1b": "******************** DEV - BUILD - LINT - RELEASE *******************",
|
|
105
|
+
"//1c": "*********************************************************************",
|
|
106
|
+
"dev": "NODE_ENV=development tsup --watch",
|
|
107
|
+
"build:prod": "NODE_ENV=production tsup",
|
|
108
|
+
"build": "pnpm lint && pnpm test:ci && pnpm build:prod",
|
|
109
|
+
"lint": "eslint",
|
|
110
|
+
"release": "node scripts/publish.js --verbose --npm",
|
|
111
|
+
"//2a": "*********************************************************************",
|
|
112
|
+
"//2b": "***************************** UNIT TESTS ****************************",
|
|
113
|
+
"//2c": "*********************************************************************",
|
|
114
|
+
"test": "jest --verbose",
|
|
115
|
+
"test:watch": "jest --watchAll --verbose",
|
|
116
|
+
"test:ci": "jest --ci --verbose",
|
|
117
|
+
"//3a": "*********************************************************************",
|
|
118
|
+
"//3b": "************************ UNIT TESTS COVERAGE ************************",
|
|
119
|
+
"//3c": "*********************************************************************",
|
|
120
|
+
"test:coverage": "pnpm test:watch --coverage",
|
|
121
|
+
"test:coverage:ci": "pnpm test:ci --coverage",
|
|
122
|
+
"test:serve-coverage": "http-server ./coverage/lcov-report --gzip true -p 0 -o --silent",
|
|
123
|
+
"test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\"",
|
|
124
|
+
"//4a": "*********************************************************************",
|
|
125
|
+
"//4b": "************************ TARGETED UNIT TESTS ************************",
|
|
126
|
+
"//4c": "*********************************************************************",
|
|
127
|
+
"test:storage": "pnpm test:watch browser-api/storage/*",
|
|
128
|
+
"test:browser-api": "pnpm test:watch --testPathPattern='browser-api/(?!storage/).*\\.test\\.(js|jsx|ts|tsx)'",
|
|
129
|
+
"test:dom-api": "pnpm test:watch dom-api/*",
|
|
130
|
+
"test:misc": "pnpm test:watch misc/*",
|
|
131
|
+
"test:timers": "pnpm test:watch timers/*"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -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 +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};
|
package/dist/chunk-26XSIIUK.mjs
DELETED
|
@@ -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};
|
package/dist/chunk-2CZNCZFR.mjs
DELETED
|
File without changes
|
package/dist/chunk-43RVMR6S.mjs
DELETED
|
@@ -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};
|
package/dist/chunk-4BGMCO3F.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/chunk-65SF33P4.mjs
DELETED
|
@@ -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};
|
package/dist/chunk-6BSD56XC.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/chunk-6IRIG5HU.mjs
DELETED
|
@@ -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};
|
package/dist/chunk-7ILYMOVB.js
DELETED
|
@@ -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;
|
package/dist/chunk-AJKPRTOJ.mjs
DELETED
|
@@ -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};
|
package/dist/chunk-EFFJB2GR.js
DELETED
|
@@ -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;
|
package/dist/chunk-FUCUVFLW.js
DELETED
|
@@ -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;
|
package/dist/chunk-G55NP3QG.js
DELETED
|
@@ -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;
|
package/dist/chunk-HO57SPST.js
DELETED
|
@@ -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;
|
package/dist/chunk-HZLWSH3W.mjs
DELETED
|
@@ -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};
|