/**
 * tua-body-scroll-lock v1.6.3
 * (c) 2026 Evinma, BuptStEve
 * @license MIT
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bodyScrollLock={})}(this,(function(e){"use strict";var t=function(){return"undefined"==typeof window},n=function(e){e=e||navigator.userAgent;var t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s/]+([\d.]+)?/.test(e)}};function o(e){if(t())return!1;if(!e)throw new Error("options must be provided");var n=!1,o={get passive(){n=!0}},i=function(){},l="__TUA_BSL_TEST_PASSIVE__";window.addEventListener(l,i,o),window.removeEventListener(l,i,o);var c=e.capture;return n?e:void 0!==c&&c}function i(){return"__BSL_PREVENT_DEFAULT__"in window||(window.__BSL_PREVENT_DEFAULT__=function(e){e.cancelable&&e.preventDefault()}),window.__BSL_PREVENT_DEFAULT__}function l(e){return e?Array.isArray(e)?e:[e]:[]}function c(e,t,n){var o,i,l,c,r=e.scrollTop,d=e.scrollLeft,s=e.scrollWidth,u=e.scrollHeight,a=e.clientWidth,f=e.clientHeight,h=function(e){var t=window.getComputedStyle(e).flexDirection;return{column:"column-reverse"===t,row:"row-reverse"===t}}(e);return h.column?(o=n>0&&Math.abs(r)+f+1>=u,i=n<0&&Math.abs(r)<=1):(o=n>0&&0===r,i=n<0&&r+f+1>=u),h.row?(l=t>0&&Math.abs(d)+a+1>=s,c=t<0&&Math.abs(d)<=1):(l=t>0&&0===d,c=t<0&&d+a+1>=s),{isOnTop:o,isOnBottom:i,isOnLeft:l,isOnRight:c}}var r={lockedNum:0,lockedElements:[],unLockCallback:null,documentListenerAdded:!1,initialClientPos:{clientX:0,clientY:0}};function d(e){if(t())return r;if(!(null==e?void 0:e.useGlobalLockState))return d.lockState;var n="__BSL_LOCK_STATE__"in window?Object.assign(Object.assign({},r),window.__BSL_LOCK_STATE__):r;return window.__BSL_LOCK_STATE__=n,n}function s(e){var t,n=document.documentElement,o=Object.assign({},n.style),i=null===(t=null==e?void 0:e.withPaddingRight)||void 0===t||t,l=window.innerWidth-n.clientWidth,c=parseInt(window.getComputedStyle(n).paddingRight,10);return n.style.overflow="hidden",n.style.boxSizing="border-box",i&&(n.style.paddingRight="".concat(l+c,"px")),function(){["overflow","boxSizing","paddingRight"].forEach((function(e){n.style[e]=o[e]||""}))}}function u(e){e.documentListenerAdded&&(document.removeEventListener("touchmove",i(),o({passive:!1})),e.documentListenerAdded=!1)}d.lockState=r,e.clearBodyLocks=function(e){var o;if(!t()){var i=d(e);if(i.lockedNum=0,null===(o=i.unLockCallback)||void 0===o||o.call(i),n().ios){if(i.lockedElements.length)for(var l=i.lockedElements.pop();l;)l.ontouchmove=null,l.ontouchstart=null,l=i.lockedElements.pop();u(i)}}},e.getLockState=d,e.lock=function(e,r){if(!t()){var u=n(),a=d(r);u.ios?(l(e).filter((function(e){return e&&-1===a.lockedElements.indexOf(e)})).forEach((function(e){e.ontouchstart=function(e){var t=e.targetTouches[0],n=t.clientX,o=t.clientY;a.initialClientPos={clientX:n,clientY:o}},e.ontouchmove=function(t){!function(e,t,n){if(t){var o=e.targetTouches[0].clientX-n.clientX,l=e.targetTouches[0].clientY-n.clientY,r=Math.abs(l)>Math.abs(o),d=c(t,o,l),s=d.isOnTop,u=d.isOnBottom,a=d.isOnLeft,f=d.isOnRight;if(r&&(s||u)||!r&&(a||f))return i()(e)}e.stopPropagation()}(t,e,a.initialClientPos)},a.lockedElements.push(e)})),function(e){if(!n().ios)return;if(e.documentListenerAdded)return;document.addEventListener("touchmove",i(),o({passive:!1})),e.documentListenerAdded=!0}(a),(null==r?void 0:r.setOverflowForIOS)&&(a.unLockCallback=s(r))):a.lockedNum<=0&&(a.unLockCallback=u.android?function(e){var t=document.documentElement,n=document.body,o=t.scrollTop||n.scrollTop,i=Object.assign({},t.style),l=Object.assign({},n.style);return t.style.height="100%",t.style.overflow="hidden",n.style.top="-".concat(o,"px"),n.style.width="100%",n.style.height="auto",n.style.position="fixed",n.style.overflow=(null==e?void 0:e.overflowType)||"hidden",function(){t.style.height=i.height||"",t.style.overflow=i.overflow||"",["top","width","height","overflow","position"].forEach((function(e){n.style[e]=l[e]||""})),"scrollBehavior"in document.documentElement.style?window.scrollTo({top:o,behavior:"instant"}):window.scrollTo(0,o)}}(r):s(r)),a.lockedNum+=1}},e.unlock=function(e,o){var i;if(!t()){var c=d(o);c.lockedNum-=1,c.lockedNum>0||(null===(i=c.unLockCallback)||void 0===i||i.call(c),n().ios&&(l(e).forEach((function(e){var t=c.lockedElements.indexOf(e);e&&-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,c.lockedElements.splice(t,1))})),u(c)))}}}));
