"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./utils.mjs.js");require("../../utils/dist/useId.mjs.js");var t=require("../../utils/dist/domHelpers.mjs.js"),n=require("../../utils/dist/platform.mjs.js"),o=require("react");require("../../utils/dist/runAfterTransition.mjs.js"),require("../../utils/dist/useLayoutEffect.mjs.js"),require("../../utils/dist/useEffectEvent.mjs.js");var r=require("../../utils/dist/isVirtualEvent.mjs.js");require("react-dom");let i=null,s=new Set,u=new Map,d=!1,a=!1;const l={Tab:!0,Escape:!0};function c(e,t){for(let n of s)n(e,t)}function v(e){d=!0,function(e){return!(e.metaKey||!n.isMac()&&e.altKey||e.ctrlKey||"Control"===e.key||"Shift"===e.key||"Meta"===e.key)}(e)&&(i="keyboard",c("keyboard",e))}function m(e){i="pointer","mousedown"!==e.type&&"pointerdown"!==e.type||(d=!0,c("pointer",e))}function f(e){r.isVirtualClick(e)&&(d=!0,i="virtual")}function E(t){t.target!==window&&t.target!==document&&!e.ignoreFocusEvent&&t.isTrusted&&(d||a||(i="virtual",c("virtual",t)),d=!1,a=!1)}function p(){d=!1,a=!0}function w(e){if("undefined"==typeof window||"undefined"==typeof document||u.get(t.getOwnerWindow(e)))return;const n=t.getOwnerWindow(e),o=t.getOwnerDocument(e);let r=n.HTMLElement.prototype.focus;n.HTMLElement.prototype.focus=function(){d=!0,r.apply(this,arguments)},o.addEventListener("keydown",v,!0),o.addEventListener("keyup",v,!0),o.addEventListener("click",f,!0),n.addEventListener("focus",E,!0),n.addEventListener("blur",p,!1),"undefined"!=typeof PointerEvent?(o.addEventListener("pointerdown",m,!0),o.addEventListener("pointermove",m,!0),o.addEventListener("pointerup",m,!0)):"test"===process.env.NODE_ENV&&(o.addEventListener("mousedown",m,!0),o.addEventListener("mousemove",m,!0),o.addEventListener("mouseup",m,!0)),n.addEventListener("beforeunload",(()=>{L(e)}),{once:!0}),u.set(n,{focus:r})}const L=(e,n)=>{const o=t.getOwnerWindow(e),r=t.getOwnerDocument(e);n&&r.removeEventListener("DOMContentLoaded",n),u.has(o)&&(o.HTMLElement.prototype.focus=u.get(o).focus,r.removeEventListener("keydown",v,!0),r.removeEventListener("keyup",v,!0),r.removeEventListener("click",f,!0),o.removeEventListener("focus",E,!0),o.removeEventListener("blur",p,!1),"undefined"!=typeof PointerEvent?(r.removeEventListener("pointerdown",m,!0),r.removeEventListener("pointermove",m,!0),r.removeEventListener("pointerup",m,!0)):"test"===process.env.NODE_ENV&&(r.removeEventListener("mousedown",m,!0),r.removeEventListener("mousemove",m,!0),r.removeEventListener("mouseup",m,!0)),u.delete(o))};function y(e){const n=t.getOwnerDocument(e);let o;return"loading"!==n.readyState?w(e):(o=()=>{w(e)},n.addEventListener("DOMContentLoaded",o)),()=>L(e,o)}function g(){return"pointer"!==i}"undefined"!=typeof document&&y();const b=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);exports.addWindowFocusTracking=y,exports.hasSetupGlobalListeners=u,exports.isFocusVisible=g,exports.useFocusVisibleListener=function(e,n,r){w(),o.useEffect((()=>{let n=(n,o)=>{(function(e,n,o){let r=t.getOwnerDocument(null==o?void 0:o.target);const i="undefined"!=typeof window?t.getOwnerWindow(null==o?void 0:o.target).HTMLInputElement:HTMLInputElement,s="undefined"!=typeof window?t.getOwnerWindow(null==o?void 0:o.target).HTMLTextAreaElement:HTMLTextAreaElement,u="undefined"!=typeof window?t.getOwnerWindow(null==o?void 0:o.target).HTMLElement:HTMLElement,d="undefined"!=typeof window?t.getOwnerWindow(null==o?void 0:o.target).KeyboardEvent:KeyboardEvent;return!((e=e||r.activeElement instanceof i&&!b.has(r.activeElement.type)||r.activeElement instanceof s||r.activeElement instanceof u&&r.activeElement.isContentEditable)&&"keyboard"===n&&o instanceof d&&!l[o.key])})(!!(null==r?void 0:r.isTextInput),n,o)&&e(g())};return s.add(n),()=>{s.delete(n)}}),n)};
//# sourceMappingURL=useFocusVisible.mjs.js.map
