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