import"react";import e from"../../../prop-types/index.js";import n from"../../../react-clientside-effect/lib/index.es.js";import{getFocusabledIn as t}from"../../../focus-lock/dist/es2015/focusables.js";import{focusInside as o}from"../../../focus-lock/dist/es2015/focusInside.js";import{focusIsHidden as r}from"../../../focus-lock/dist/es2015/focusIsHidden.js";import{setFocus as u}from"../../../focus-lock/dist/es2015/setFocus.js";import{deferAction as i}from"./util.js";import{mediumFocus as c,mediumBlur as s,mediumEffect as d}from"./medium.js";var a=function(){return document&&document.activeElement===document.body||r()},f=null,m=null,l=null,v=!1,p=function(){return!0};function b(e,n,t,o){var r=null,u=e;do{var i=o[u];if(i.guard)i.node.dataset.focusAutoGuard&&(r=i);else{if(!i.lockItem)break;if(u!==e)return;r=null}}while((u+=t)!==n);r&&(r.node.tabIndex=0)}var E=function(e){return e&&"current"in e?e.current:e},g=function(){var e,n=!1;if(f){var r=f,i=r.observed,c=r.persistentFocus,s=r.autoFocus,d=r.shards,g=r.crossFrame,j=i||l&&l.portaledElement,h=document&&document.activeElement;if(j){var w=[j].concat(d.map(E).filter(Boolean));if(h&&!function(e){return(f.whiteList||p)(e)}(h)||(c||(g?Boolean(v):"meanwhile"===v)||!a()||!m&&s)&&(!j||o(w)||(e=h,l&&l.portaledElement===e)||(document&&!m&&h&&!s?(h.blur&&h.blur(),document.body.focus()):(n=u(w,m),l={})),v=!1,m=document&&document.activeElement),document){var I=document&&document.activeElement,L=t(w),k=L.map((function(e){return e.node})).indexOf(I);k>-1&&(L.filter((function(e){var n=e.guard,t=e.node;return n&&t.dataset.focusAutoGuard})).forEach((function(e){return e.node.removeAttribute("tabIndex")})),b(k,L.length,1,L),b(k,-1,-1,L))}}}return n},j=function(e){g()&&e&&(e.stopPropagation(),e.preventDefault())},h=function(){return i(g)};"production"===process.env.NODE_ENV||e.node.isRequired;var w=function(){v="just",setTimeout((function(){v="meanwhile"}),0)};c.assignSyncMedium((function(e){var n=e.target,t=e.currentTarget;t.contains(n)||(l={observerNode:t,portaledElement:n})})),s.assignMedium(h),d.assignMedium((function(e){return e({moveFocusInside:u,focusInside:o})}));var I=n((function(e){return e.filter((function(e){return!e.disabled}))}),(function(e){var n=e.slice(-1)[0];n&&!f&&(document.addEventListener("focusin",j,!0),document.addEventListener("focusout",h),window.addEventListener("blur",w));var t=f,o=t&&n&&n.id===t.id;f=n,t&&!o&&(t.onDeactivation(),e.filter((function(e){return e.id===t.id})).length||t.returnFocus(!n)),n?(m=null,o&&t.observed===n.observed||n.onActivation(),g(),i(g)):(document.removeEventListener("focusin",j,!0),document.removeEventListener("focusout",h),window.removeEventListener("blur",w),m=null)}))((function(){return null}));export default I;
//# sourceMappingURL=Trap.js.map
