import*as e from"react";import{RemoveScrollBar as t}from"../../../react-remove-scroll-bar/dist/es2015/component.js";import{styleSingleton as n}from"../../../react-style-singleton/dist/es2015/component.js";import{locationCouldBeScrolled as r,handleScroll as c}from"./handleScroll.js";import{nonPassive as u}from"./aggresiveCapture.js";var o=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},a=function(e){return[e.deltaX,e.deltaY]},i=function(e){return e&&"current"in e?e.current:e},l=function(e){return"\n  .block-interactivity-"+e+" {pointer-events: none;}\n  .allow-interactivity-"+e+" {pointer-events: all;}\n"},s=0,f=[];function d(d){var v=e.useRef([]),m=e.useRef([0,0]),h=e.useRef(),p=e.useState(s++)[0],g=e.useState((function(){return n()}))[0],b=e.useRef(d);e.useEffect((function(){b.current=d}),[d]),e.useEffect((function(){if(d.inert){document.body.classList.add("block-interactivity-"+p);var e=[d.lockRef.current].concat((d.shards||[]).map(i)).filter(Boolean);return e.forEach((function(e){return e.classList.add("allow-interactivity-"+p)})),function(){document.body.classList.remove("block-interactivity-"+p),e.forEach((function(e){return e.classList.remove("allow-interactivity-"+p)}))}}}),[d.inert,d.lockRef.current,d.shards]);var k=e.useCallback((function(e,t){if("touches"in e&&2===e.touches.length)return!b.current.allowPinchZoom;var n,u=o(e),a=m.current,i="deltaX"in e?e.deltaX:a[0]-u[0],l="deltaY"in e?e.deltaY:a[1]-u[1],s=e.target,f=Math.abs(i)>Math.abs(l)?"h":"v",d=r(f,s);if(!d)return!0;if(d?n=f:(n="v"===f?"h":"v",d=r(f,s)),!d)return!1;if(!h.current&&"changedTouches"in e&&(i||l)&&(h.current=n),!n)return!0;var v=h.current||n;return c(v,t,e,"h"===v?i:l,!0)}),[]),E=e.useCallback((function(e){var t=e;if(f.length&&f[f.length-1]===g){var n="deltaY"in t?a(t):o(t),r=v.current.filter((function(e){return e.name===t.type&&e.target===t.target&&(r=e.delta,c=n,r[0]===c[0]&&r[1]===c[1]);var r,c}))[0];if(r&&r.should)t.preventDefault();else if(!r){var c=(b.current.shards||[]).map(i).filter(Boolean).filter((function(e){return e.contains(t.target)}));(c.length>0?k(t,c[0]):!b.current.noIsolation)&&t.preventDefault()}}}),[]),y=e.useCallback((function(e,t,n,r){var c={name:e,delta:t,target:n,should:r};v.current.push(c),setTimeout((function(){v.current=v.current.filter((function(e){return e!==c}))}),1)}),[]),C=e.useCallback((function(e){m.current=o(e),h.current=void 0}),[]),L=e.useCallback((function(e){y(e.type,a(e),e.target,k(e,d.lockRef.current))}),[]),R=e.useCallback((function(e){y(e.type,o(e),e.target,k(e,d.lockRef.current))}),[]);e.useEffect((function(){return f.push(g),d.setCallbacks({onScrollCapture:L,onWheelCapture:L,onTouchMoveCapture:R}),document.addEventListener("wheel",E,u),document.addEventListener("touchmove",E,u),document.addEventListener("touchstart",C,u),function(){f=f.filter((function(e){return e!==g})),document.removeEventListener("wheel",E,u),document.removeEventListener("touchmove",E,u),document.removeEventListener("touchstart",C,u)}}),[]);var w=d.removeScrollBar,T=d.inert;return e.createElement(e.Fragment,null,T?e.createElement(g,{styles:l(p)}):null,w?e.createElement(t,{gapMode:"margin"}):null)}export{d as RemoveScrollSideCar,a as getDeltaXY,o as getTouchXY};
//# sourceMappingURL=SideEffect.js.map
