import{disposables as s}from'../../utils/disposables.js';import{createStore as d}from'../../utils/store.js';import{adjustScrollbarPadding as i}from'./adjust-scrollbar-padding.js';import{handleIOSLocking as l}from'./handle-ios-locking.js';import{preventScroll as p}from'./prevent-scroll.js';function r(e){let o={};for(let t of e)Object.assign(o,t(o));return o}let c=d(()=>new Map,{PUSH(e,o){var n;let t=(n=this.get(e))!=null?n:{doc:e,count:0,d:s(),meta:new Set,computedMeta:{}};return t.count++,t.meta.add(o),t.computedMeta=r(t.meta),this.set(e,t),this},POP(e,o){let t=this.get(e);return t&&(t.count--,t.meta.delete(o),t.computedMeta=r(t.meta)),this},SCROLL_PREVENT(e){let o={doc:e.doc,d:e.d,meta(){return e.computedMeta}},t=[l(),i(),p()];t.forEach(({before:n})=>n==null?void 0:n(o)),t.forEach(({after:n})=>n==null?void 0:n(o))},SCROLL_ALLOW({d:e}){e.dispose()},TEARDOWN({doc:e}){this.delete(e)}});c.subscribe(()=>{let e=c.getSnapshot(),o=new Map;for(let[t]of e)o.set(t,t.documentElement.style.overflow);for(let t of e.values()){let n=o.get(t.doc)==="hidden",a=t.count!==0;(a&&!n||!a&&n)&&c.dispatch(t.count>0?"SCROLL_PREVENT":"SCROLL_ALLOW",t),t.count===0&&c.dispatch("TEARDOWN",t)}});export{c as overflows};
