UNPKG

@substrate-system/scroll-lock

Version:
3 lines (2 loc) 1.51 kB
"use strict";var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var l=(e,t)=>c(e,"name",{value:t,configurable:!0});var u=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},a=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of i(t))!m.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(r=s(t,n))||r.enumerable});return e};var p=e=>a(c({},"__esModule",{value:!0}),e);var k={};u(k,{lockBodyScrolling:()=>E,unlockBodyScrolling:()=>f});module.exports=p(k);const d=new Set;function y(){const e=document.documentElement.clientWidth;return Math.abs(window.innerWidth-e)}l(y,"getScrollbarWidth");function g(){const e=Number(getComputedStyle(document.body).paddingRight.replace(/px/,""));return isNaN(e)||!e?0:e}l(g,"getExistingBodyPadding");function E(e){if(d.add(e),!document.documentElement.classList.contains("scroll-lock")){const t=y()+g();let o=getComputedStyle(document.documentElement).scrollbarGutter;(!o||o==="auto")&&(o="stable"),t<2&&(o=""),document.documentElement.style.setProperty("--scroll-lock-gutter",o),document.documentElement.classList.add("scroll-lock"),document.documentElement.style.setProperty("--scroll-lock-size",`${t}px`)}}l(E,"lockBodyScrolling");function f(e){d.delete(e),d.size===0&&(document.documentElement.classList.remove("scroll-lock"),document.documentElement.style.removeProperty("--scroll-lock-size"))}l(f,"unlockBodyScrolling"); //# sourceMappingURL=index.min.cjs.map