"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../utils/dom.js"),n=require("../utils/focus-management.js"),u=require("../utils/platform.js"),r=require("./use-document-event.js"),o=require("./use-latest-value.js"),s=require("./use-window-event.js");exports.useOutsideClick=function(l,c,i){let a=o.useLatestValue(i),d=e.useCallback((function(e,t){if(e.defaultPrevented)return;let u=t(e);if(null===u||!u.getRootNode().contains(u)||!u.isConnected)return;let r=function e(t){return"function"==typeof t?e(t()):Array.isArray(t)||t instanceof Set?t:[t]}(c);for(let t of r)if(null!==t&&(t.contains(u)||e.composed&&e.composedPath().includes(t)))return;return!n.isFocusableElement(u,n.FocusableMode.Loose)&&-1!==u.tabIndex&&e.preventDefault(),a.current(e,u)}),[a,c]),f=e.useRef(null);r.useDocumentEvent(l,"pointerdown",(e=>{var t,n;u.isMobile()||(f.current=(null==(n=null==(t=e.composedPath)?void 0:t.call(e))?void 0:n[0])||e.target)}),!0),r.useDocumentEvent(l,"pointerup",(e=>{if(u.isMobile()||!f.current)return;let t=f.current;return f.current=null,d(e,(()=>t))}),!0);let m=e.useRef({x:0,y:0});r.useDocumentEvent(l,"touchstart",(e=>{m.current.x=e.touches[0].clientX,m.current.y=e.touches[0].clientY}),!0),r.useDocumentEvent(l,"touchend",(e=>{let n=e.changedTouches[0].clientX,u=e.changedTouches[0].clientY;if(!(Math.abs(n-m.current.x)>=30||Math.abs(u-m.current.y)>=30))return d(e,(()=>t.isHTMLorSVGElement(e.target)?e.target:null))}),!0),s.useWindowEvent(l,"blur",(e=>d(e,(()=>t.isHTMLIframeElement(window.document.activeElement)?window.document.activeElement:null))),!0)};
//# sourceMappingURL=use-outside-click.js.map
