@jbpark/use-hooks 1.0.0 → 1.1.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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),p=(e=!0)=>{i.useEffect(()=>{if(!e)return;const t=window.scrollY,l=/iPad|iPhone|iPod/.test(navigator.userAgent),o={documentElement:{overflow:document.documentElement.style.overflow,height:document.documentElement.style.height,position:document.documentElement.style.position,width:document.documentElement.style.width},body:{overflow:document.body.style.overflow,height:document.body.style.height,position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,right:document.body.style.right,width:document.body.style.width,webkitOverflowScrolling:document.body.style.getPropertyValue("-webkit-overflow-scrolling")}};if(document.documentElement.style.overflow="hidden",document.documentElement.style.height="100%",document.documentElement.style.position="fixed",document.documentElement.style.width="100%",document.body.style.overflow="hidden",document.body.style.height="100%",document.body.style.position="fixed",document.body.style.top=`-${t}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",l){document.body.style.setProperty("-webkit-overflow-scrolling","touch");const r=s=>{(s.target===document.body||s.target===document.documentElement||s.target===window)&&(s.preventDefault(),s.stopPropagation(),s.stopImmediatePropagation())},c=()=>{window.scrollTo(0,0),document.body.scrollTop=0,document.documentElement.scrollTop=0},n=["scroll","touchmove","touchstart","touchend"];n.forEach(s=>{window.addEventListener(s,r,{passive:!1,capture:!0}),document.addEventListener(s,r,{passive:!1,capture:!0}),document.body.addEventListener(s,r,{passive:!1,capture:!0})});const u=setInterval(c,16);return()=>{clearInterval(u),n.forEach(s=>{window.removeEventListener(s,r,{capture:!0}),document.removeEventListener(s,r,{capture:!0}),document.body.removeEventListener(s,r,{capture:!0})}),document.documentElement.style.overflow=o.documentElement.overflow,document.documentElement.style.height=o.documentElement.height,document.documentElement.style.position=o.documentElement.position,document.documentElement.style.width=o.documentElement.width,document.body.style.overflow=o.body.overflow,document.body.style.height=o.body.height,document.body.style.position=o.body.position,document.body.style.top=o.body.top,document.body.style.left=o.body.left,document.body.style.right=o.body.right,document.body.style.width=o.body.width,o.body.webkitOverflowScrolling?document.body.style.setProperty("-webkit-overflow-scrolling",o.body.webkitOverflowScrolling):document.body.style.removeProperty("-webkit-overflow-scrolling"),window.scrollTo(0,t)}}return()=>{document.documentElement.style.overflow=o.documentElement.overflow,document.documentElement.style.height=o.documentElement.height,document.documentElement.style.position=o.documentElement.position,document.documentElement.style.width=o.documentElement.width,document.body.style.overflow=o.body.overflow,document.body.style.height=o.body.height,document.body.style.position=o.body.position,document.body.style.top=o.body.top,document.body.style.left=o.body.left,document.body.style.right=o.body.right,document.body.style.width=o.body.width,window.scrollTo(0,t)}},[e])},b=e=>{const[t,l]=i.useState(null);return i.useEffect(()=>{const o=n=>typeof n=="string"?document.querySelector(n):n.current,r=()=>{const n=o(e);l(n?n.getBoundingClientRect():null)},c=()=>{requestAnimationFrame(r)};return r(),window.addEventListener("scroll",c,{passive:!0}),window.addEventListener("resize",c,{passive:!0}),()=>{window.removeEventListener("scroll",c),window.removeEventListener("resize",c)}},[e]),t};function E(e,t){t===void 0&&(t=0);var l=i.useRef(!1),o=i.useRef(),r=i.useRef(e),c=i.useCallback(function(){return l.current},[]),n=i.useCallback(function(){l.current=!1,o.current&&clearTimeout(o.current),o.current=setTimeout(function(){l.current=!0,r.current()},t)},[t]),u=i.useCallback(function(){l.current=null,o.current&&clearTimeout(o.current)},[]);return i.useEffect(function(){r.current=e},[e]),i.useEffect(function(){return n(),u},[t]),[c,u,n]}function S(e,t,l){t===void 0&&(t=0),l===void 0&&(l=[]);var o=E(e,t),r=o[0],c=o[1],n=o[2];return i.useEffect(n,l),[r,c]}const m={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},L=e=>{let t="xs";return e>=m["2xl"]?t="2xl":e>=m.xl?t="xl":e>=m.lg?t="lg":e>=m.md?t="md":e>=m.sm?t="sm":t="xs",{current:t,xs:e<m.sm,sm:e>=m.sm&&e<m.md,md:e>=m.md&&e<m.lg,lg:e>=m.lg&&e<m.xl,xl:e>=m.xl&&e<m["2xl"],"2xl":e>=m["2xl"]}},T=(e=200)=>{const[t,l]=i.useState({width:0,height:0}),[o,r]=i.useState({current:"xs",xs:!0,sm:!1,md:!1,lg:!1,xl:!1,"2xl":!1}),[c,n]=i.useState({width:0,height:0}),u=i.useRef(null),s=i.useRef(null);return S(()=>{n(t)},e,[t]),i.useEffect(()=>{const d=()=>{const a=u.current??document.body;if(!a)return;const{offsetWidth:h,offsetHeight:v}=a;l(g=>g.width!==h||g.height!==v?{width:h,height:v}:g),r(g=>{const y=L(h);return g.current!==y.current?y:g})},w=()=>{const a=u.current??document.body;a&&(d(),s.current&&s.current.disconnect(),s.current=new ResizeObserver(()=>{requestAnimationFrame(()=>{d()})}),s.current.observe(a))},f=()=>{s.current&&(s.current.disconnect(),s.current=null)};return w(),()=>{f()}},[]),{size:c,breakpoint:o,ref:u}},x=e=>{const[t,l]=i.useState(!0),[o,r]=i.useState();return i.useEffect(()=>{if(!e){l(!1);return}const c=new Image;c.src=e,c.onload=()=>l(!1),c.onerror=n=>{l(!1),r(n)}},[e]),{loading:t,error:o}},V=(e,t)=>{const l=i.useRef(t),[o,r]=i.useState(()=>{if(typeof window>"u")return t;try{const n=window.localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}});i.useEffect(()=>{if(!(typeof window>"u"))try{const n=window.localStorage.getItem(e);n?r(JSON.parse(n)):window.localStorage.setItem(e,JSON.stringify(l.current))}catch(n){console.error(`Error reading localStorage key "${e}":`,n)}},[e]);const c=i.useCallback(n=>{try{r(u=>{const s=n instanceof Function?n(u):n;return localStorage.setItem(e,JSON.stringify(s)),s})}catch(u){console.error(`Error setting localStorage key "${e}":`,u)}},[e]);return[o,c]},R=(e,t)=>{const l=i.useRef(e);i.useEffect(()=>{l.current=e},[e]),i.useEffect(()=>{let o;function r(){const c=l.current();c instanceof Promise?c.then(()=>{t&&(o=setTimeout(r,t))}):t&&(o=setTimeout(r,t))}if(t)return o=setTimeout(r,t),()=>o&&clearTimeout(o)},[t])},z=()=>{const[e,t]=i.useState(null),[l,o]=i.useState({scrollY:0,scrollPercentage:0,isAtTop:!0,isAtBottom:!1,scrollableHeight:0,clientHeight:0,scrollHeight:0}),r=i.useCallback(c=>{t(c)},[]);return i.useEffect(()=>{if(!e)return;const c=()=>{const{scrollTop:s,scrollHeight:d,clientHeight:w}=e,f=d-w;if(f<=0){o({scrollY:0,scrollPercentage:0,isAtTop:!0,isAtBottom:!0,scrollableHeight:0,clientHeight:w,scrollHeight:d});return}const a=Math.min(100,Math.max(0,s/f*100));o({scrollY:s,scrollPercentage:a,isAtTop:s<=0,isAtBottom:s>=f-1,scrollableHeight:f,clientHeight:w,scrollHeight:d})};c();const n=()=>{c()};e.addEventListener("scroll",n,{passive:!0});const u=new ResizeObserver(()=>{c()});return u.observe(e),()=>{e.removeEventListener("scroll",n),u.unobserve(e)}},[e]),{...l,element:e,setRef:r}};function P(e){const t=i.useRef([]),l=i.useCallback(r=>{if(t.current[r]&&(t.current[r].scrollIntoView({behavior:"smooth",block:"start",inline:"start",...e}),e?.offset)){const c=t.current[r].getBoundingClientRect().top+window.scrollY-e.offset;window.scrollTo({top:c,behavior:e.behavior||"smooth"})}},[e]),o=i.useCallback((r,c)=>{t.current[c]=r},[]);return{elementRefs:t,setElementRef:o,scrollToElement:l}}const H=()=>{const[e,t]=i.useState({x:0,y:0,percent:{x:0,y:0}});return i.useEffect(()=>{const l=()=>{const n=window.scrollX||0,u=window.scrollY||0,s=/iPad|iPhone|iPod/.test(navigator.userAgent),d=window.visualViewport,w=s&&d?d.width:window.innerWidth,f=s&&d?d.height:window.innerHeight,a=Math.max(0,document.documentElement.scrollWidth-w),h=Math.max(0,document.documentElement.scrollHeight-f),v=a===0?0:Math.min(100,n/a*100),g=h===0?0:Math.min(100,u/h*100);t({x:n,y:u,percent:{x:Math.floor(Math.max(0,v)),y:Math.floor(Math.max(0,g))}})};l();const o=()=>{l()},r=()=>{setTimeout(l,100)},c=()=>{setTimeout(l,50)};return window.addEventListener("scroll",o,{passive:!0}),window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",c),()=>{window.removeEventListener("scroll",o),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",c)}},[]),e},I=(e={})=>{const{isInApp:t=!1,debounce:l=100}=e,[o,r]=i.useState({width:0,height:0,offsetLeft:0,offsetTop:0,pageLeft:0,pageTop:0,scale:1}),c=i.useCallback(()=>{const u=window.innerHeight,s=window.visualViewport?.height||u,d=document.documentElement.clientHeight,w=document.body.clientHeight;return window.visualViewport&&Math.abs(s-u)>100?s:Math.max(u,d,w)},[]),n=i.useCallback(()=>{if(window.visualViewport&&!t)return window.visualViewport;const u=window.visualViewport?.width||window.innerWidth,s=t?c():window.visualViewport?.height||window.innerHeight;return{width:u,height:s,offsetLeft:window.visualViewport?.offsetLeft||0,offsetTop:window.visualViewport?.offsetTop||0,pageLeft:window.scrollX??window.pageXOffset??0,pageTop:window.scrollY??window.pageYOffset??0,scale:window.visualViewport?.scale||1}},[t,c]);return i.useEffect(()=>{let u;const s=()=>{clearTimeout(u),u=setTimeout(()=>{r(n())},l)},d=()=>r(n());d();const w=["resize","orientationchange"];t&&w.push("focus","blur","touchstart","touchend"),w.forEach(a=>{a==="resize"||a==="orientationchange"?window.addEventListener(a,s):window.addEventListener(a,d,{passive:!0})}),window.visualViewport&&(window.visualViewport.addEventListener("resize",d),window.visualViewport.addEventListener("scroll",d));let f;if(t){let a=n().height;f=setInterval(()=>{const h=n().height;Math.abs(h-a)>50&&(a=h,d())},500)}return()=>{clearTimeout(u),f&&clearInterval(f),w.forEach(a=>{window.removeEventListener(a,a==="resize"||a==="orientationchange"?s:d)}),window.visualViewport&&(window.visualViewport.removeEventListener("resize",d),window.visualViewport.removeEventListener("scroll",d))}},[n,t,l]),o};exports.useBodyScrollLock=p;exports.useElementRect=b;exports.useElementSize=T;exports.useImageLoader=x;exports.useLocalStorage=V;exports.useRecursiveTimeout=R;exports.useScrollPosition=z;exports.useScrollToElements=P;exports.useViewport=I;exports.useWindowScroll=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),E=(e=!0)=>{s.useEffect(()=>{if(!e)return;const o=window.scrollY,i=/iPad|iPhone|iPod/.test(navigator.userAgent),t={documentElement:{overflow:document.documentElement.style.overflow,height:document.documentElement.style.height,position:document.documentElement.style.position,width:document.documentElement.style.width},body:{overflow:document.body.style.overflow,height:document.body.style.height,position:document.body.style.position,top:document.body.style.top,left:document.body.style.left,right:document.body.style.right,width:document.body.style.width,webkitOverflowScrolling:document.body.style.getPropertyValue("-webkit-overflow-scrolling")}};if(document.documentElement.style.overflow="hidden",document.documentElement.style.height="100%",document.documentElement.style.position="fixed",document.documentElement.style.width="100%",document.body.style.overflow="hidden",document.body.style.height="100%",document.body.style.position="fixed",document.body.style.top=`-${o}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",i){document.body.style.setProperty("-webkit-overflow-scrolling","touch");const r=l=>{(l.target===document.body||l.target===document.documentElement||l.target===window)&&(l.preventDefault(),l.stopPropagation(),l.stopImmediatePropagation())},c=()=>{window.scrollTo(0,0),document.body.scrollTop=0,document.documentElement.scrollTop=0},n=["scroll","touchmove","touchstart","touchend"];n.forEach(l=>{window.addEventListener(l,r,{passive:!1,capture:!0}),document.addEventListener(l,r,{passive:!1,capture:!0}),document.body.addEventListener(l,r,{passive:!1,capture:!0})});const u=setInterval(c,16);return()=>{clearInterval(u),n.forEach(l=>{window.removeEventListener(l,r,{capture:!0}),document.removeEventListener(l,r,{capture:!0}),document.body.removeEventListener(l,r,{capture:!0})}),document.documentElement.style.overflow=t.documentElement.overflow,document.documentElement.style.height=t.documentElement.height,document.documentElement.style.position=t.documentElement.position,document.documentElement.style.width=t.documentElement.width,document.body.style.overflow=t.body.overflow,document.body.style.height=t.body.height,document.body.style.position=t.body.position,document.body.style.top=t.body.top,document.body.style.left=t.body.left,document.body.style.right=t.body.right,document.body.style.width=t.body.width,t.body.webkitOverflowScrolling?document.body.style.setProperty("-webkit-overflow-scrolling",t.body.webkitOverflowScrolling):document.body.style.removeProperty("-webkit-overflow-scrolling"),window.scrollTo(0,o)}}return()=>{document.documentElement.style.overflow=t.documentElement.overflow,document.documentElement.style.height=t.documentElement.height,document.documentElement.style.position=t.documentElement.position,document.documentElement.style.width=t.documentElement.width,document.body.style.overflow=t.body.overflow,document.body.style.height=t.body.height,document.body.style.position=t.body.position,document.body.style.top=t.body.top,document.body.style.left=t.body.left,document.body.style.right=t.body.right,document.body.style.width=t.body.width,window.scrollTo(0,o)}},[e])},S=e=>{const[o,i]=s.useState(null);return s.useEffect(()=>{const t=n=>typeof n=="string"?document.querySelector(n):n.current,r=()=>{const n=t(e);i(n?n.getBoundingClientRect():null)},c=()=>{requestAnimationFrame(r)};return r(),window.addEventListener("scroll",c,{passive:!0}),window.addEventListener("resize",c,{passive:!0}),()=>{window.removeEventListener("scroll",c),window.removeEventListener("resize",c)}},[e]),o};function L(e,o){o===void 0&&(o=0);var i=s.useRef(!1),t=s.useRef(),r=s.useRef(e),c=s.useCallback(function(){return i.current},[]),n=s.useCallback(function(){i.current=!1,t.current&&clearTimeout(t.current),t.current=setTimeout(function(){i.current=!0,r.current()},o)},[o]),u=s.useCallback(function(){i.current=null,t.current&&clearTimeout(t.current)},[]);return s.useEffect(function(){r.current=e},[e]),s.useEffect(function(){return n(),u},[o]),[c,u,n]}function T(e,o,i){o===void 0&&(o=0),i===void 0&&(i=[]);var t=L(e,o),r=t[0],c=t[1],n=t[2];return s.useEffect(n,i),[r,c]}const w={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},x=e=>{let o="xs";return e>=w["2xl"]?o="2xl":e>=w.xl?o="xl":e>=w.lg?o="lg":e>=w.md?o="md":e>=w.sm?o="sm":o="xs",{current:o,xs:e<w.sm,sm:e>=w.sm&&e<w.md,md:e>=w.md&&e<w.lg,lg:e>=w.lg&&e<w.xl,xl:e>=w.xl&&e<w["2xl"],"2xl":e>=w["2xl"]}},V=e=>{const{delay:o=100,container:i}=e||{},[t,r]=s.useState({width:0,height:0}),[c,n]=s.useState({current:"xs",xs:!0,sm:!1,md:!1,lg:!1,xl:!1,"2xl":!1}),[u,l]=s.useState({width:0,height:0}),d=s.useRef(null),a=s.useRef(null);return T(()=>{l(t)},o,[t]),s.useEffect(()=>{const f=()=>{const g=i??d.current??document.body;if(!g)return;const{offsetWidth:y,offsetHeight:p}=g;r(v=>v.width!==y||v.height!==p?{width:y,height:p}:v),n(v=>{const b=x(y);return v.current!==b.current?b:v})},m=()=>{const g=i??d.current??document.body;g&&(f(),a.current&&a.current.disconnect(),a.current=new ResizeObserver(()=>{requestAnimationFrame(()=>{f()})}),a.current.observe(g))},h=()=>{a.current&&(a.current.disconnect(),a.current=null)};return m(),()=>{h()}},[i]),{size:u,breakpoint:c,ref:d}},R=e=>{const[o,i]=s.useState(!0),[t,r]=s.useState();return s.useEffect(()=>{if(!e){i(!1);return}const c=new Image;c.src=e,c.onload=()=>i(!1),c.onerror=n=>{i(!1),r(n)}},[e]),{loading:o,error:t}},z=(e,o)=>{const i=s.useRef(o),[t,r]=s.useState(()=>{if(typeof window>"u")return o;try{const n=window.localStorage.getItem(e);return n?JSON.parse(n):o}catch{return o}});s.useEffect(()=>{if(!(typeof window>"u"))try{const n=window.localStorage.getItem(e);n?r(JSON.parse(n)):window.localStorage.setItem(e,JSON.stringify(i.current))}catch(n){console.error(`Error reading localStorage key "${e}":`,n)}},[e]);const c=s.useCallback(n=>{try{r(u=>{const l=n instanceof Function?n(u):n;return localStorage.setItem(e,JSON.stringify(l)),l})}catch(u){console.error(`Error setting localStorage key "${e}":`,u)}},[e]);return[t,c]},P=(e,o)=>{const i=s.useRef(e);s.useEffect(()=>{i.current=e},[e]),s.useEffect(()=>{let t;function r(){const c=i.current();c instanceof Promise?c.then(()=>{o&&(t=setTimeout(r,o))}):o&&(t=setTimeout(r,o))}if(o)return t=setTimeout(r,o),()=>t&&clearTimeout(t)},[o])},H=()=>{const[e,o]=s.useState(null),[i,t]=s.useState({scrollY:0,scrollPercentage:0,isAtTop:!0,isAtBottom:!1,scrollableHeight:0,clientHeight:0,scrollHeight:0}),r=s.useCallback(c=>{o(c)},[]);return s.useEffect(()=>{if(!e)return;const c=()=>{const{scrollTop:l,scrollHeight:d,clientHeight:a}=e,f=d-a;if(f<=0){t({scrollY:0,scrollPercentage:0,isAtTop:!0,isAtBottom:!0,scrollableHeight:0,clientHeight:a,scrollHeight:d});return}const m=Math.min(100,Math.max(0,l/f*100));t({scrollY:l,scrollPercentage:m,isAtTop:l<=0,isAtBottom:l>=f-1,scrollableHeight:f,clientHeight:a,scrollHeight:d})};c();const n=()=>{c()};e.addEventListener("scroll",n,{passive:!0});const u=new ResizeObserver(()=>{c()});return u.observe(e),()=>{e.removeEventListener("scroll",n),u.unobserve(e)}},[e]),{...i,element:e,setRef:r}};function I(e){const o=s.useRef([]),i=s.useCallback(r=>{if(o.current[r]&&(o.current[r].scrollIntoView({behavior:"smooth",block:"start",inline:"start",...e}),e?.offset)){const c=o.current[r].getBoundingClientRect().top+window.scrollY-e.offset;window.scrollTo({top:c,behavior:e.behavior||"smooth"})}},[e]),t=s.useCallback((r,c)=>{o.current[c]=r},[]);return{elementRefs:o,setElementRef:t,scrollToElement:i}}const k=()=>{const[e,o]=s.useState({x:0,y:0,percent:{x:0,y:0}});return s.useEffect(()=>{const i=()=>{const n=window.scrollX||0,u=window.scrollY||0,l=/iPad|iPhone|iPod/.test(navigator.userAgent),d=window.visualViewport,a=l&&d?d.width:window.innerWidth,f=l&&d?d.height:window.innerHeight,m=Math.max(0,document.documentElement.scrollWidth-a),h=Math.max(0,document.documentElement.scrollHeight-f),g=m===0?0:Math.min(100,n/m*100),y=h===0?0:Math.min(100,u/h*100);o({x:n,y:u,percent:{x:Math.floor(Math.max(0,g)),y:Math.floor(Math.max(0,y))}})};i();const t=()=>{i()},r=()=>{setTimeout(i,100)},c=()=>{setTimeout(i,50)};return window.addEventListener("scroll",t,{passive:!0}),window.addEventListener("resize",r),window.addEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.addEventListener("resize",c),()=>{window.removeEventListener("scroll",t),window.removeEventListener("resize",r),window.removeEventListener("orientationchange",r),window.visualViewport&&window.visualViewport.removeEventListener("resize",c)}},[]),e},O=(e={})=>{const{isInApp:o=!1,debounce:i=100}=e,[t,r]=s.useState({width:0,height:0,offsetLeft:0,offsetTop:0,pageLeft:0,pageTop:0,scale:1}),c=s.useCallback(()=>{const u=window.innerHeight,l=window.visualViewport?.height||u,d=document.documentElement.clientHeight,a=document.body.clientHeight;return window.visualViewport&&Math.abs(l-u)>100?l:Math.max(u,d,a)},[]),n=s.useCallback(()=>{if(window.visualViewport&&!o)return window.visualViewport;const u=window.visualViewport?.width||window.innerWidth,l=o?c():window.visualViewport?.height||window.innerHeight;return{width:u,height:l,offsetLeft:window.visualViewport?.offsetLeft||0,offsetTop:window.visualViewport?.offsetTop||0,pageLeft:window.scrollX??window.pageXOffset??0,pageTop:window.scrollY??window.pageYOffset??0,scale:window.visualViewport?.scale||1}},[o,c]);return s.useEffect(()=>{let u;const l=()=>{clearTimeout(u),u=setTimeout(()=>{r(n())},i)},d=()=>r(n());d();const a=["resize","orientationchange"];o&&a.push("focus","blur","touchstart","touchend"),a.forEach(m=>{m==="resize"||m==="orientationchange"?window.addEventListener(m,l):window.addEventListener(m,d,{passive:!0})}),window.visualViewport&&(window.visualViewport.addEventListener("resize",d),window.visualViewport.addEventListener("scroll",d));let f;if(o){let m=n().height;f=setInterval(()=>{const h=n().height;Math.abs(h-m)>50&&(m=h,d())},500)}return()=>{clearTimeout(u),f&&clearInterval(f),a.forEach(m=>{window.removeEventListener(m,m==="resize"||m==="orientationchange"?l:d)}),window.visualViewport&&(window.visualViewport.removeEventListener("resize",d),window.visualViewport.removeEventListener("scroll",d))}},[n,o,i]),t};exports.useBodyScrollLock=E;exports.useElementRect=S;exports.useElementSize=V;exports.useImageLoader=R;exports.useLocalStorage=z;exports.useRecursiveTimeout=P;exports.useScrollPosition=H;exports.useScrollToElements=I;exports.useViewport=O;exports.useWindowScroll=k;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,11 @@ declare interface BreakpointInfo {
14
14
 
15
15
  declare type ElementReference<T> = string | RefObject<T>;
16
16
 
17
+ declare interface Options {
18
+ delay?: number;
19
+ container?: HTMLElement | null;
20
+ }
21
+
17
22
  declare interface Props extends ScrollIntoViewOptions {
18
23
  offset?: number;
19
24
  }
@@ -22,7 +27,7 @@ export declare const useBodyScrollLock: (enabled?: boolean) => void;
22
27
 
23
28
  export declare const useElementRect: <T>(elementRef: ElementReference<T>) => DOMRect | null;
24
29
 
25
- export declare const useElementSize: <T extends HTMLElement>(delay?: number) => {
30
+ export declare const useElementSize: <T extends HTMLElement>(options?: Options) => {
26
31
  size: {
27
32
  width: number;
28
33
  height: number;
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { useEffect as w, useState as h, useRef as p, useCallback as v } from "react";
2
- const V = (e = !0) => {
3
- w(() => {
1
+ import { useEffect as f, useState as h, useRef as v, useCallback as g } from "react";
2
+ const H = (e = !0) => {
3
+ f(() => {
4
4
  if (!e)
5
5
  return;
6
- const t = window.scrollY, c = /iPad|iPhone|iPod/.test(navigator.userAgent), o = {
6
+ const o = window.scrollY, i = /iPad|iPhone|iPod/.test(navigator.userAgent), t = {
7
7
  documentElement: {
8
8
  overflow: document.documentElement.style.overflow,
9
9
  height: document.documentElement.style.height,
@@ -23,78 +23,78 @@ const V = (e = !0) => {
23
23
  )
24
24
  }
25
25
  };
26
- if (document.documentElement.style.overflow = "hidden", document.documentElement.style.height = "100%", document.documentElement.style.position = "fixed", document.documentElement.style.width = "100%", document.body.style.overflow = "hidden", document.body.style.height = "100%", document.body.style.position = "fixed", document.body.style.top = `-${t}px`, document.body.style.left = "0", document.body.style.right = "0", document.body.style.width = "100%", c) {
26
+ if (document.documentElement.style.overflow = "hidden", document.documentElement.style.height = "100%", document.documentElement.style.position = "fixed", document.documentElement.style.width = "100%", document.body.style.overflow = "hidden", document.body.style.height = "100%", document.body.style.position = "fixed", document.body.style.top = `-${o}px`, document.body.style.left = "0", document.body.style.right = "0", document.body.style.width = "100%", i) {
27
27
  document.body.style.setProperty("-webkit-overflow-scrolling", "touch");
28
- const r = (i) => {
29
- (i.target === document.body || i.target === document.documentElement || i.target === window) && (i.preventDefault(), i.stopPropagation(), i.stopImmediatePropagation());
28
+ const r = (c) => {
29
+ (c.target === document.body || c.target === document.documentElement || c.target === window) && (c.preventDefault(), c.stopPropagation(), c.stopImmediatePropagation());
30
30
  }, s = () => {
31
31
  window.scrollTo(0, 0), document.body.scrollTop = 0, document.documentElement.scrollTop = 0;
32
32
  }, n = ["scroll", "touchmove", "touchstart", "touchend"];
33
- n.forEach((i) => {
34
- window.addEventListener(i, r, {
33
+ n.forEach((c) => {
34
+ window.addEventListener(c, r, {
35
35
  passive: !1,
36
36
  capture: !0
37
- }), document.addEventListener(i, r, {
37
+ }), document.addEventListener(c, r, {
38
38
  passive: !1,
39
39
  capture: !0
40
- }), document.body.addEventListener(i, r, {
40
+ }), document.body.addEventListener(c, r, {
41
41
  passive: !1,
42
42
  capture: !0
43
43
  });
44
44
  });
45
45
  const l = setInterval(s, 16);
46
46
  return () => {
47
- clearInterval(l), n.forEach((i) => {
48
- window.removeEventListener(i, r, { capture: !0 }), document.removeEventListener(i, r, { capture: !0 }), document.body.removeEventListener(i, r, {
47
+ clearInterval(l), n.forEach((c) => {
48
+ window.removeEventListener(c, r, { capture: !0 }), document.removeEventListener(c, r, { capture: !0 }), document.body.removeEventListener(c, r, {
49
49
  capture: !0
50
50
  });
51
- }), document.documentElement.style.overflow = o.documentElement.overflow, document.documentElement.style.height = o.documentElement.height, document.documentElement.style.position = o.documentElement.position, document.documentElement.style.width = o.documentElement.width, document.body.style.overflow = o.body.overflow, document.body.style.height = o.body.height, document.body.style.position = o.body.position, document.body.style.top = o.body.top, document.body.style.left = o.body.left, document.body.style.right = o.body.right, document.body.style.width = o.body.width, o.body.webkitOverflowScrolling ? document.body.style.setProperty(
51
+ }), document.documentElement.style.overflow = t.documentElement.overflow, document.documentElement.style.height = t.documentElement.height, document.documentElement.style.position = t.documentElement.position, document.documentElement.style.width = t.documentElement.width, document.body.style.overflow = t.body.overflow, document.body.style.height = t.body.height, document.body.style.position = t.body.position, document.body.style.top = t.body.top, document.body.style.left = t.body.left, document.body.style.right = t.body.right, document.body.style.width = t.body.width, t.body.webkitOverflowScrolling ? document.body.style.setProperty(
52
52
  "-webkit-overflow-scrolling",
53
- o.body.webkitOverflowScrolling
54
- ) : document.body.style.removeProperty("-webkit-overflow-scrolling"), window.scrollTo(0, t);
53
+ t.body.webkitOverflowScrolling
54
+ ) : document.body.style.removeProperty("-webkit-overflow-scrolling"), window.scrollTo(0, o);
55
55
  };
56
56
  }
57
57
  return () => {
58
- document.documentElement.style.overflow = o.documentElement.overflow, document.documentElement.style.height = o.documentElement.height, document.documentElement.style.position = o.documentElement.position, document.documentElement.style.width = o.documentElement.width, document.body.style.overflow = o.body.overflow, document.body.style.height = o.body.height, document.body.style.position = o.body.position, document.body.style.top = o.body.top, document.body.style.left = o.body.left, document.body.style.right = o.body.right, document.body.style.width = o.body.width, window.scrollTo(0, t);
58
+ document.documentElement.style.overflow = t.documentElement.overflow, document.documentElement.style.height = t.documentElement.height, document.documentElement.style.position = t.documentElement.position, document.documentElement.style.width = t.documentElement.width, document.body.style.overflow = t.body.overflow, document.body.style.height = t.body.height, document.body.style.position = t.body.position, document.body.style.top = t.body.top, document.body.style.left = t.body.left, document.body.style.right = t.body.right, document.body.style.width = t.body.width, window.scrollTo(0, o);
59
59
  };
60
60
  }, [e]);
61
- }, z = (e) => {
62
- const [t, c] = h(null);
63
- return w(() => {
64
- const o = (n) => typeof n == "string" ? document.querySelector(n) : n.current, r = () => {
65
- const n = o(e);
66
- c(n ? n.getBoundingClientRect() : null);
61
+ }, P = (e) => {
62
+ const [o, i] = h(null);
63
+ return f(() => {
64
+ const t = (n) => typeof n == "string" ? document.querySelector(n) : n.current, r = () => {
65
+ const n = t(e);
66
+ i(n ? n.getBoundingClientRect() : null);
67
67
  }, s = () => {
68
68
  requestAnimationFrame(r);
69
69
  };
70
70
  return r(), window.addEventListener("scroll", s, { passive: !0 }), window.addEventListener("resize", s, { passive: !0 }), () => {
71
71
  window.removeEventListener("scroll", s), window.removeEventListener("resize", s);
72
72
  };
73
- }, [e]), t;
73
+ }, [e]), o;
74
74
  };
75
- function S(e, t) {
76
- t === void 0 && (t = 0);
77
- var c = p(!1), o = p(), r = p(e), s = v(function() {
78
- return c.current;
79
- }, []), n = v(function() {
80
- c.current = !1, o.current && clearTimeout(o.current), o.current = setTimeout(function() {
81
- c.current = !0, r.current();
82
- }, t);
83
- }, [t]), l = v(function() {
84
- c.current = null, o.current && clearTimeout(o.current);
75
+ function x(e, o) {
76
+ o === void 0 && (o = 0);
77
+ var i = v(!1), t = v(), r = v(e), s = g(function() {
78
+ return i.current;
79
+ }, []), n = g(function() {
80
+ i.current = !1, t.current && clearTimeout(t.current), t.current = setTimeout(function() {
81
+ i.current = !0, r.current();
82
+ }, o);
83
+ }, [o]), l = g(function() {
84
+ i.current = null, t.current && clearTimeout(t.current);
85
85
  }, []);
86
- return w(function() {
86
+ return f(function() {
87
87
  r.current = e;
88
- }, [e]), w(function() {
88
+ }, [e]), f(function() {
89
89
  return n(), l;
90
- }, [t]), [s, l, n];
90
+ }, [o]), [s, l, n];
91
91
  }
92
- function L(e, t, c) {
93
- t === void 0 && (t = 0), c === void 0 && (c = []);
94
- var o = S(e, t), r = o[0], s = o[1], n = o[2];
95
- return w(n, c), [r, s];
92
+ function T(e, o, i) {
93
+ o === void 0 && (o = 0), i === void 0 && (i = []);
94
+ var t = x(e, o), r = t[0], s = t[1], n = t[2];
95
+ return f(n, i), [r, s];
96
96
  }
97
- const a = {
97
+ const m = {
98
98
  // < 640px
99
99
  sm: 640,
100
100
  // >= 640px
@@ -106,19 +106,19 @@ const a = {
106
106
  // >= 1280px
107
107
  "2xl": 1536
108
108
  // >= 1536px
109
- }, x = (e) => {
110
- let t = "xs";
111
- return e >= a["2xl"] ? t = "2xl" : e >= a.xl ? t = "xl" : e >= a.lg ? t = "lg" : e >= a.md ? t = "md" : e >= a.sm ? t = "sm" : t = "xs", {
112
- current: t,
113
- xs: e < a.sm,
114
- sm: e >= a.sm && e < a.md,
115
- md: e >= a.md && e < a.lg,
116
- lg: e >= a.lg && e < a.xl,
117
- xl: e >= a.xl && e < a["2xl"],
118
- "2xl": e >= a["2xl"]
109
+ }, V = (e) => {
110
+ let o = "xs";
111
+ return e >= m["2xl"] ? o = "2xl" : e >= m.xl ? o = "xl" : e >= m.lg ? o = "lg" : e >= m.md ? o = "md" : e >= m.sm ? o = "sm" : o = "xs", {
112
+ current: o,
113
+ xs: e < m.sm,
114
+ sm: e >= m.sm && e < m.md,
115
+ md: e >= m.md && e < m.lg,
116
+ lg: e >= m.lg && e < m.xl,
117
+ xl: e >= m.xl && e < m["2xl"],
118
+ "2xl": e >= m["2xl"]
119
119
  };
120
- }, H = (e = 200) => {
121
- const [t, c] = h({ width: 0, height: 0 }), [o, r] = h({
120
+ }, I = (e) => {
121
+ const { delay: o = 100, container: i } = e || {}, [t, r] = h({ width: 0, height: 0 }), [s, n] = h({
122
122
  current: "xs",
123
123
  xs: !0,
124
124
  sm: !1,
@@ -126,82 +126,82 @@ const a = {
126
126
  lg: !1,
127
127
  xl: !1,
128
128
  "2xl": !1
129
- }), [s, n] = h({ width: 0, height: 0 }), l = p(null), i = p(null);
130
- return L(
129
+ }), [l, c] = h({ width: 0, height: 0 }), d = v(null), u = v(null);
130
+ return T(
131
131
  () => {
132
- n(t);
132
+ c(t);
133
133
  },
134
- e,
134
+ o,
135
135
  [t]
136
- ), w(() => {
137
- const d = () => {
138
- const u = l.current ?? document.body;
139
- if (!u)
136
+ ), f(() => {
137
+ const w = () => {
138
+ const p = i ?? d.current ?? document.body;
139
+ if (!p)
140
140
  return;
141
- const { offsetWidth: g, offsetHeight: b } = u;
142
- c((y) => y.width !== g || y.height !== b ? { width: g, height: b } : y), r((y) => {
143
- const E = x(g);
144
- return y.current !== E.current ? E : y;
141
+ const { offsetWidth: E, offsetHeight: S } = p;
142
+ r((b) => b.width !== E || b.height !== S ? { width: E, height: S } : b), n((b) => {
143
+ const L = V(E);
144
+ return b.current !== L.current ? L : b;
145
145
  });
146
- }, m = () => {
147
- const u = l.current ?? document.body;
148
- u && (d(), i.current && i.current.disconnect(), i.current = new ResizeObserver(() => {
146
+ }, a = () => {
147
+ const p = i ?? d.current ?? document.body;
148
+ p && (w(), u.current && u.current.disconnect(), u.current = new ResizeObserver(() => {
149
149
  requestAnimationFrame(() => {
150
- d();
150
+ w();
151
151
  });
152
- }), i.current.observe(u));
153
- }, f = () => {
154
- i.current && (i.current.disconnect(), i.current = null);
152
+ }), u.current.observe(p));
153
+ }, y = () => {
154
+ u.current && (u.current.disconnect(), u.current = null);
155
155
  };
156
- return m(), () => {
157
- f();
156
+ return a(), () => {
157
+ y();
158
158
  };
159
- }, []), {
160
- size: s,
161
- breakpoint: o,
162
- ref: l
159
+ }, [i]), {
160
+ size: l,
161
+ breakpoint: s,
162
+ ref: d
163
163
  };
164
- }, P = (e) => {
165
- const [t, c] = h(!0), [o, r] = h();
166
- return w(() => {
164
+ }, R = (e) => {
165
+ const [o, i] = h(!0), [t, r] = h();
166
+ return f(() => {
167
167
  if (!e) {
168
- c(!1);
168
+ i(!1);
169
169
  return;
170
170
  }
171
171
  const s = new Image();
172
- s.src = e, s.onload = () => c(!1), s.onerror = (n) => {
173
- c(!1), r(n);
172
+ s.src = e, s.onload = () => i(!1), s.onerror = (n) => {
173
+ i(!1), r(n);
174
174
  };
175
175
  }, [e]), {
176
- loading: t,
177
- error: o
176
+ loading: o,
177
+ error: t
178
178
  };
179
- }, I = (e, t) => {
180
- const c = p(t), [o, r] = h(() => {
179
+ }, O = (e, o) => {
180
+ const i = v(o), [t, r] = h(() => {
181
181
  if (typeof window > "u")
182
- return t;
182
+ return o;
183
183
  try {
184
184
  const n = window.localStorage.getItem(e);
185
- return n ? JSON.parse(n) : t;
185
+ return n ? JSON.parse(n) : o;
186
186
  } catch {
187
- return t;
187
+ return o;
188
188
  }
189
189
  });
190
- w(() => {
190
+ f(() => {
191
191
  if (!(typeof window > "u"))
192
192
  try {
193
193
  const n = window.localStorage.getItem(e);
194
- n ? r(JSON.parse(n)) : window.localStorage.setItem(e, JSON.stringify(c.current));
194
+ n ? r(JSON.parse(n)) : window.localStorage.setItem(e, JSON.stringify(i.current));
195
195
  } catch (n) {
196
196
  console.error(`Error reading localStorage key "${e}":`, n);
197
197
  }
198
198
  }, [e]);
199
- const s = v(
199
+ const s = g(
200
200
  (n) => {
201
201
  try {
202
202
  r((l) => {
203
- const i = n instanceof Function ? n(l) : n;
204
- return localStorage.setItem(e, JSON.stringify(i)), i;
203
+ const c = n instanceof Function ? n(l) : n;
204
+ return localStorage.setItem(e, JSON.stringify(c)), c;
205
205
  });
206
206
  } catch (l) {
207
207
  console.error(`Error setting localStorage key "${e}":`, l);
@@ -209,24 +209,24 @@ const a = {
209
209
  },
210
210
  [e]
211
211
  );
212
- return [o, s];
213
- }, R = (e, t) => {
214
- const c = p(e);
215
- w(() => {
216
- c.current = e;
217
- }, [e]), w(() => {
218
- let o;
212
+ return [t, s];
213
+ }, A = (e, o) => {
214
+ const i = v(e);
215
+ f(() => {
216
+ i.current = e;
217
+ }, [e]), f(() => {
218
+ let t;
219
219
  function r() {
220
- const s = c.current();
220
+ const s = i.current();
221
221
  s instanceof Promise ? s.then(() => {
222
- t && (o = setTimeout(r, t));
223
- }) : t && (o = setTimeout(r, t));
222
+ o && (t = setTimeout(r, o));
223
+ }) : o && (t = setTimeout(r, o));
224
224
  }
225
- if (t)
226
- return o = setTimeout(r, t), () => o && clearTimeout(o);
227
- }, [t]);
228
- }, O = () => {
229
- const [e, t] = h(null), [c, o] = h({
225
+ if (o)
226
+ return t = setTimeout(r, o), () => t && clearTimeout(t);
227
+ }, [o]);
228
+ }, M = () => {
229
+ const [e, o] = h(null), [i, t] = h({
230
230
  scrollY: 0,
231
231
  scrollPercentage: 0,
232
232
  isAtTop: !0,
@@ -234,37 +234,37 @@ const a = {
234
234
  scrollableHeight: 0,
235
235
  clientHeight: 0,
236
236
  scrollHeight: 0
237
- }), r = v((s) => {
238
- t(s);
237
+ }), r = g((s) => {
238
+ o(s);
239
239
  }, []);
240
- return w(() => {
240
+ return f(() => {
241
241
  if (!e)
242
242
  return;
243
243
  const s = () => {
244
- const { scrollTop: i, scrollHeight: d, clientHeight: m } = e, f = d - m;
245
- if (f <= 0) {
246
- o({
244
+ const { scrollTop: c, scrollHeight: d, clientHeight: u } = e, w = d - u;
245
+ if (w <= 0) {
246
+ t({
247
247
  scrollY: 0,
248
248
  scrollPercentage: 0,
249
249
  isAtTop: !0,
250
250
  isAtBottom: !0,
251
251
  scrollableHeight: 0,
252
- clientHeight: m,
252
+ clientHeight: u,
253
253
  scrollHeight: d
254
254
  });
255
255
  return;
256
256
  }
257
- const u = Math.min(
257
+ const a = Math.min(
258
258
  100,
259
- Math.max(0, i / f * 100)
259
+ Math.max(0, c / w * 100)
260
260
  );
261
- o({
262
- scrollY: i,
263
- scrollPercentage: u,
264
- isAtTop: i <= 0,
265
- isAtBottom: i >= f - 1,
266
- scrollableHeight: f,
267
- clientHeight: m,
261
+ t({
262
+ scrollY: c,
263
+ scrollPercentage: a,
264
+ isAtTop: c <= 0,
265
+ isAtBottom: c >= w - 1,
266
+ scrollableHeight: w,
267
+ clientHeight: u,
268
268
  scrollHeight: d
269
269
  });
270
270
  };
@@ -279,18 +279,18 @@ const a = {
279
279
  return l.observe(e), () => {
280
280
  e.removeEventListener("scroll", n), l.unobserve(e);
281
281
  };
282
- }, [e]), { ...c, element: e, setRef: r };
282
+ }, [e]), { ...i, element: e, setRef: r };
283
283
  };
284
- function A(e) {
285
- const t = p([]), c = v(
284
+ function Y(e) {
285
+ const o = v([]), i = g(
286
286
  (r) => {
287
- if (t.current[r] && (t.current[r].scrollIntoView({
287
+ if (o.current[r] && (o.current[r].scrollIntoView({
288
288
  behavior: "smooth",
289
289
  block: "start",
290
290
  inline: "start",
291
291
  ...e
292
292
  }), e?.offset)) {
293
- const s = t.current[r].getBoundingClientRect().top + window.scrollY - e.offset;
293
+ const s = o.current[r].getBoundingClientRect().top + window.scrollY - e.offset;
294
294
  window.scrollTo({
295
295
  top: s,
296
296
  behavior: e.behavior || "smooth"
@@ -298,13 +298,13 @@ function A(e) {
298
298
  }
299
299
  },
300
300
  [e]
301
- ), o = v((r, s) => {
302
- t.current[s] = r;
301
+ ), t = g((r, s) => {
302
+ o.current[s] = r;
303
303
  }, []);
304
- return { elementRefs: t, setElementRef: o, scrollToElement: c };
304
+ return { elementRefs: o, setElementRef: t, scrollToElement: i };
305
305
  }
306
- const M = () => {
307
- const [e, t] = h({
306
+ const k = () => {
307
+ const [e, o] = h({
308
308
  x: 0,
309
309
  y: 0,
310
310
  percent: {
@@ -312,41 +312,41 @@ const M = () => {
312
312
  y: 0
313
313
  }
314
314
  });
315
- return w(() => {
316
- const c = () => {
317
- const n = window.scrollX || 0, l = window.scrollY || 0, i = /iPad|iPhone|iPod/.test(navigator.userAgent), d = window.visualViewport, m = i && d ? d.width : window.innerWidth, f = i && d ? d.height : window.innerHeight, u = Math.max(
315
+ return f(() => {
316
+ const i = () => {
317
+ const n = window.scrollX || 0, l = window.scrollY || 0, c = /iPad|iPhone|iPod/.test(navigator.userAgent), d = window.visualViewport, u = c && d ? d.width : window.innerWidth, w = c && d ? d.height : window.innerHeight, a = Math.max(
318
318
  0,
319
- document.documentElement.scrollWidth - m
320
- ), g = Math.max(
319
+ document.documentElement.scrollWidth - u
320
+ ), y = Math.max(
321
321
  0,
322
- document.documentElement.scrollHeight - f
323
- ), b = u === 0 ? 0 : Math.min(100, n / u * 100), y = g === 0 ? 0 : Math.min(100, l / g * 100);
324
- t({
322
+ document.documentElement.scrollHeight - w
323
+ ), p = a === 0 ? 0 : Math.min(100, n / a * 100), E = y === 0 ? 0 : Math.min(100, l / y * 100);
324
+ o({
325
325
  x: n,
326
326
  y: l,
327
327
  percent: {
328
- x: Math.floor(Math.max(0, b)),
329
- y: Math.floor(Math.max(0, y))
328
+ x: Math.floor(Math.max(0, p)),
329
+ y: Math.floor(Math.max(0, E))
330
330
  }
331
331
  });
332
332
  };
333
- c();
334
- const o = () => {
335
- c();
333
+ i();
334
+ const t = () => {
335
+ i();
336
336
  }, r = () => {
337
- setTimeout(c, 100);
337
+ setTimeout(i, 100);
338
338
  }, s = () => {
339
- setTimeout(c, 50);
339
+ setTimeout(i, 50);
340
340
  };
341
- return window.addEventListener("scroll", o, { passive: !0 }), window.addEventListener("resize", r), window.addEventListener("orientationchange", r), window.visualViewport && window.visualViewport.addEventListener("resize", s), () => {
342
- window.removeEventListener("scroll", o), window.removeEventListener("resize", r), window.removeEventListener("orientationchange", r), window.visualViewport && window.visualViewport.removeEventListener(
341
+ return window.addEventListener("scroll", t, { passive: !0 }), window.addEventListener("resize", r), window.addEventListener("orientationchange", r), window.visualViewport && window.visualViewport.addEventListener("resize", s), () => {
342
+ window.removeEventListener("scroll", t), window.removeEventListener("resize", r), window.removeEventListener("orientationchange", r), window.visualViewport && window.visualViewport.removeEventListener(
343
343
  "resize",
344
344
  s
345
345
  );
346
346
  };
347
347
  }, []), e;
348
- }, Y = (e = {}) => {
349
- const { isInApp: t = !1, debounce: c = 100 } = e, [o, r] = h({
348
+ }, B = (e = {}) => {
349
+ const { isInApp: o = !1, debounce: i = 100 } = e, [t, r] = h({
350
350
  width: 0,
351
351
  height: 0,
352
352
  offsetLeft: 0,
@@ -354,62 +354,62 @@ const M = () => {
354
354
  pageLeft: 0,
355
355
  pageTop: 0,
356
356
  scale: 1
357
- }), s = v(() => {
358
- const l = window.innerHeight, i = window.visualViewport?.height || l, d = document.documentElement.clientHeight, m = document.body.clientHeight;
359
- return window.visualViewport && Math.abs(i - l) > 100 ? i : Math.max(l, d, m);
360
- }, []), n = v(() => {
361
- if (window.visualViewport && !t)
357
+ }), s = g(() => {
358
+ const l = window.innerHeight, c = window.visualViewport?.height || l, d = document.documentElement.clientHeight, u = document.body.clientHeight;
359
+ return window.visualViewport && Math.abs(c - l) > 100 ? c : Math.max(l, d, u);
360
+ }, []), n = g(() => {
361
+ if (window.visualViewport && !o)
362
362
  return window.visualViewport;
363
- const l = window.visualViewport?.width || window.innerWidth, i = t ? s() : window.visualViewport?.height || window.innerHeight;
363
+ const l = window.visualViewport?.width || window.innerWidth, c = o ? s() : window.visualViewport?.height || window.innerHeight;
364
364
  return {
365
365
  width: l,
366
- height: i,
366
+ height: c,
367
367
  offsetLeft: window.visualViewport?.offsetLeft || 0,
368
368
  offsetTop: window.visualViewport?.offsetTop || 0,
369
369
  pageLeft: window.scrollX ?? window.pageXOffset ?? 0,
370
370
  pageTop: window.scrollY ?? window.pageYOffset ?? 0,
371
371
  scale: window.visualViewport?.scale || 1
372
372
  };
373
- }, [t, s]);
374
- return w(() => {
373
+ }, [o, s]);
374
+ return f(() => {
375
375
  let l;
376
- const i = () => {
376
+ const c = () => {
377
377
  clearTimeout(l), l = setTimeout(() => {
378
378
  r(n());
379
- }, c);
379
+ }, i);
380
380
  }, d = () => r(n());
381
381
  d();
382
- const m = ["resize", "orientationchange"];
383
- t && m.push("focus", "blur", "touchstart", "touchend"), m.forEach((u) => {
384
- u === "resize" || u === "orientationchange" ? window.addEventListener(u, i) : window.addEventListener(u, d, { passive: !0 });
382
+ const u = ["resize", "orientationchange"];
383
+ o && u.push("focus", "blur", "touchstart", "touchend"), u.forEach((a) => {
384
+ a === "resize" || a === "orientationchange" ? window.addEventListener(a, c) : window.addEventListener(a, d, { passive: !0 });
385
385
  }), window.visualViewport && (window.visualViewport.addEventListener("resize", d), window.visualViewport.addEventListener("scroll", d));
386
- let f;
387
- if (t) {
388
- let u = n().height;
389
- f = setInterval(() => {
390
- const g = n().height;
391
- Math.abs(g - u) > 50 && (u = g, d());
386
+ let w;
387
+ if (o) {
388
+ let a = n().height;
389
+ w = setInterval(() => {
390
+ const y = n().height;
391
+ Math.abs(y - a) > 50 && (a = y, d());
392
392
  }, 500);
393
393
  }
394
394
  return () => {
395
- clearTimeout(l), f && clearInterval(f), m.forEach((u) => {
395
+ clearTimeout(l), w && clearInterval(w), u.forEach((a) => {
396
396
  window.removeEventListener(
397
- u,
398
- u === "resize" || u === "orientationchange" ? i : d
397
+ a,
398
+ a === "resize" || a === "orientationchange" ? c : d
399
399
  );
400
400
  }), window.visualViewport && (window.visualViewport.removeEventListener("resize", d), window.visualViewport.removeEventListener("scroll", d));
401
401
  };
402
- }, [n, t, c]), o;
402
+ }, [n, o, i]), t;
403
403
  };
404
404
  export {
405
- V as useBodyScrollLock,
406
- z as useElementRect,
407
- H as useElementSize,
408
- P as useImageLoader,
409
- I as useLocalStorage,
410
- R as useRecursiveTimeout,
411
- O as useScrollPosition,
412
- A as useScrollToElements,
413
- Y as useViewport,
414
- M as useWindowScroll
405
+ H as useBodyScrollLock,
406
+ P as useElementRect,
407
+ I as useElementSize,
408
+ R as useImageLoader,
409
+ O as useLocalStorage,
410
+ A as useRecursiveTimeout,
411
+ M as useScrollPosition,
412
+ Y as useScrollToElements,
413
+ B as useViewport,
414
+ k as useWindowScroll
415
415
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbpark/use-hooks",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "일반적인 UI 및 상호작용 패턴을 위한 재사용 가능한 React 19 훅 모음",
5
5
  "keywords": [
6
6
  "react",
@@ -42,7 +42,7 @@
42
42
  "lint": "eslint .",
43
43
  "preview": "vite preview",
44
44
  "prepublishOnly": "npm run build",
45
- "prepare": "husky install"
45
+ "prepare": "husky"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": "^19.1.1",