import{d as L,ap as h,$ as c,l as s,q as E,at as S}from"./index-CoQ-x5A8.js";import{h as P,f as q,k as H}from"./use-timeout-RziKd5AU.js";function W(t,e,l){let o;function r(){o!==void 0&&(h.remove(o),o=void 0)}return L(()=>{t.value===!0&&r()}),{removeFromHistory:r,addToHistory(){o={condition:()=>l.value===!0,handler:e},h.add(o)}}}let a=0,p,v,d,w=!1,m,y,g,n=null;function x(t){C(t)&&E(t)}function C(t){if(t.target===document.body||t.target.classList.contains("q-layout__backdrop"))return!0;const e=S(t),l=t.shiftKey&&!t.deltaX,o=!l&&Math.abs(t.deltaX)<=Math.abs(t.deltaY),r=l||o?t.deltaY:t.deltaX;for(let f=0;f<e.length;f++){const i=e[f];if(H(i,o))return o?r<0&&i.scrollTop===0?!0:r>0&&i.scrollTop+i.clientHeight===i.scrollHeight:r<0&&i.scrollLeft===0?!0:r>0&&i.scrollLeft+i.clientWidth===i.scrollWidth}return!0}function b(t){t.target===document&&(document.scrollingElement.scrollTop=document.scrollingElement.scrollTop)}function u(t){w!==!0&&(w=!0,requestAnimationFrame(()=>{w=!1;const{height:e}=t.target,{clientHeight:l,scrollTop:o}=document.scrollingElement;(d===void 0||e!==window.innerHeight)&&(d=l-e,document.scrollingElement.scrollTop=o),o>d&&(document.scrollingElement.scrollTop-=Math.ceil((o-d)/8))}))}function T(t){const e=document.body,l=window.visualViewport!==void 0;if(t==="add"){const{overflowY:o,overflowX:r}=window.getComputedStyle(e);p=P(window),v=q(window),m=e.style.left,y=e.style.top,g=window.location.href,e.style.left=`-${p}px`,e.style.top=`-${v}px`,r!=="hidden"&&(r==="scroll"||e.scrollWidth>window.innerWidth)&&e.classList.add("q-body--force-scrollbar-x"),o!=="hidden"&&(o==="scroll"||e.scrollHeight>window.innerHeight)&&e.classList.add("q-body--force-scrollbar-y"),e.classList.add("q-body--prevent-scroll"),document.qScrollPrevented=!0,c.is.ios===!0&&(l===!0?(window.scrollTo(0,0),window.visualViewport.addEventListener("resize",u,s.passiveCapture),window.visualViewport.addEventListener("scroll",u,s.passiveCapture),window.scrollTo(0,0)):window.addEventListener("scroll",b,s.passiveCapture))}c.is.desktop===!0&&c.is.mac===!0&&window[`${t}EventListener`]("wheel",x,s.notPassive),t==="remove"&&(c.is.ios===!0&&(l===!0?(window.visualViewport.removeEventListener("resize",u,s.passiveCapture),window.visualViewport.removeEventListener("scroll",u,s.passiveCapture)):window.removeEventListener("scroll",b,s.passiveCapture)),e.classList.remove("q-body--prevent-scroll"),e.classList.remove("q-body--force-scrollbar-x"),e.classList.remove("q-body--force-scrollbar-y"),document.qScrollPrevented=!1,e.style.left=m,e.style.top=y,window.location.href===g&&window.scrollTo(p,v),d=void 0)}function V(t){let e="add";if(t===!0){if(a++,n!==null){clearTimeout(n),n=null;return}if(a>1)return}else{if(a===0||(a--,a>0))return;if(e="remove",c.is.ios===!0&&c.is.nativeMobile===!0){n!==null&&clearTimeout(n),n=setTimeout(()=>{T(e),n=null},100);return}}T(e)}function X(){let t;return{preventBodyScroll(e){e!==t&&(t!==void 0||e===!0)&&(t=e,V(e))}}}function Y(t,e,l){return l<=e?e:Math.min(l,Math.max(e,t))}function A(t,e,l){if(l<=e)return e;const o=l-e+1;let r=e+(t-e)%o;return r<e&&(r=o+r),r===0?0:r}export{X as a,Y as b,A as n,W as u};
