/*! * focus-trap 7.6.2 * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE */ "use strict";var e=require("tabbable");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n0){var n=e[e.length-1];n!==t&&n.pause()}var o=e.indexOf(t);-1===o||e.splice(o,1),e.push(t)},u=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},c=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},s=function(e){return c(e)&&!e.shiftKey},l=function(e){return c(e)&&e.shiftKey},b=function(e){return setTimeout(e,0)},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o1&&void 0!==arguments[1]?arguments[1]:{},n=t.hasFallback,o=void 0!==n&&n,r=t.params,i=void 0===r?[]:r,u=y[e];if("function"==typeof u&&(u=u.apply(void 0,a(i))),!0===u&&(u=void 0),!u){if(void 0===u||!1===u)return u;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var c=u;if("string"==typeof u){try{c=p.querySelector(u)}catch(t){throw new Error("`".concat(e,'` appears to be an invalid selector; error="').concat(t.message,'"'))}if(!c&&!o)throw new Error("`".concat(e,"` as selector refers to no known node"))}return c},N=function(){var t=F("initialFocus",{hasFallback:!0});if(!1===t)return!1;if(void 0===t||t&&!e.isFocusable(t,y.tabbableOptions))if(g(p.activeElement)>=0)t=p.activeElement;else{var n=h.tabbableGroups[0];t=n&&n.firstTabbableNode||F("fallbackFocus")}else null===t&&(t=F("fallbackFocus"));if(!t)throw new Error("Your focus-trap needs to have at least one focusable element");return t},T=function(){if(h.containerGroups=h.containers.map((function(t){var n=e.tabbable(t,y.tabbableOptions),o=e.focusable(t,y.tabbableOptions),r=n.length>0?n[0]:void 0,a=n.length>0?n[n.length-1]:void 0,i=o.find((function(t){return e.isTabbable(t)})),u=o.slice().reverse().find((function(t){return e.isTabbable(t)})),c=!!n.find((function(t){return e.getTabIndex(t)>0}));return{container:t,tabbableNodes:n,focusableNodes:o,posTabIndexesFound:c,firstTabbableNode:r,lastTabbableNode:a,firstDomTabbableNode:i,lastDomTabbableNode:u,nextTabbableNode:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=n.indexOf(t);return a<0?r?o.slice(o.indexOf(t)+1).find((function(t){return e.isTabbable(t)})):o.slice(0,o.indexOf(t)).reverse().find((function(t){return e.isTabbable(t)})):n[a+(r?1:-1)]}}})),h.tabbableGroups=h.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),h.tabbableGroups.length<=0&&!F("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");if(h.containerGroups.find((function(e){return e.posTabIndexesFound}))&&h.containerGroups.length>1)throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.")},O=function(e){var t=e.activeElement;if(t)return t.shadowRoot&&null!==t.shadowRoot.activeElement?O(t.shadowRoot):t},E=function(e){!1!==e&&e!==O(document)&&(e&&e.focus?(e.focus({preventScroll:!!y.preventScroll}),h.mostRecentlyFocusedNode=e,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(e)&&e.select()):E(N()))},k=function(e){var t=F("setReturnFocus",{params:[e]});return t||!1!==t&&e},D=function(t){var n=t.target,o=t.event,r=t.isBackward,a=void 0!==r&&r;n=n||f(o),T();var i=null;if(h.tabbableGroups.length>0){var u=g(n,o),s=u>=0?h.containerGroups[u]:void 0;if(u<0)i=a?h.tabbableGroups[h.tabbableGroups.length-1].lastTabbableNode:h.tabbableGroups[0].firstTabbableNode;else if(a){var l=h.tabbableGroups.findIndex((function(e){var t=e.firstTabbableNode;return n===t}));if(l<0&&(s.container===n||e.isFocusable(n,y.tabbableOptions)&&!e.isTabbable(n,y.tabbableOptions)&&!s.nextTabbableNode(n,!1))&&(l=u),l>=0){var b=0===l?h.tabbableGroups.length-1:l-1,d=h.tabbableGroups[b];i=e.getTabIndex(n)>=0?d.lastTabbableNode:d.lastDomTabbableNode}else c(o)||(i=s.nextTabbableNode(n,!1))}else{var v=h.tabbableGroups.findIndex((function(e){var t=e.lastTabbableNode;return n===t}));if(v<0&&(s.container===n||e.isFocusable(n,y.tabbableOptions)&&!e.isTabbable(n,y.tabbableOptions)&&!s.nextTabbableNode(n))&&(v=u),v>=0){var p=v===h.tabbableGroups.length-1?0:v+1,m=h.tabbableGroups[p];i=e.getTabIndex(n)>=0?m.firstTabbableNode:m.firstDomTabbableNode}else c(o)||(i=s.nextTabbableNode(n))}}else i=F("fallbackFocus");return i},P=function(e){var t=f(e);g(t,e)>=0||(d(y.clickOutsideDeactivates,e)?o.deactivate({returnFocus:y.returnFocusOnDeactivate}):d(y.allowOutsideClick,e)||e.preventDefault())},x=function(t){var n=f(t),o=g(n,t)>=0;if(o||n instanceof Document)o&&(h.mostRecentlyFocusedNode=n);else{var r;t.stopImmediatePropagation();var a=!0;if(h.mostRecentlyFocusedNode)if(e.getTabIndex(h.mostRecentlyFocusedNode)>0){var i=g(h.mostRecentlyFocusedNode),u=h.containerGroups[i].tabbableNodes;if(u.length>0){var c=u.findIndex((function(e){return e===h.mostRecentlyFocusedNode}));c>=0&&(y.isKeyForward(h.recentNavEvent)?c+1=0&&(r=u[c-1],a=!1))}}else h.containerGroups.some((function(t){return t.tabbableNodes.some((function(t){return e.getTabIndex(t)>0}))}))||(a=!1);else a=!1;a&&(r=D({target:h.mostRecentlyFocusedNode,isBackward:y.isKeyBackward(h.recentNavEvent)})),E(r||(h.mostRecentlyFocusedNode||N()))}h.recentNavEvent=void 0},G=function(e){(y.isKeyForward(e)||y.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];h.recentNavEvent=e;var n=D({event:e,isBackward:t});n&&(c(e)&&e.preventDefault(),E(n))}(e,y.isKeyBackward(e))},I=function(e){var t;"Escape"!==(null==(t=e)?void 0:t.key)&&"Esc"!==(null==t?void 0:t.key)&&27!==(null==t?void 0:t.keyCode)||!1===d(y.escapeDeactivates,e)||(e.preventDefault(),o.deactivate())},R=function(e){var t=f(e);g(t,e)>=0||d(y.clickOutsideDeactivates,e)||d(y.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(h.active)return i(m,o),h.delayInitialFocusTimer=y.delayInitialFocus?b((function(){E(N())})):E(N()),p.addEventListener("focusin",x,!0),p.addEventListener("mousedown",P,{capture:!0,passive:!1}),p.addEventListener("touchstart",P,{capture:!0,passive:!1}),p.addEventListener("click",R,{capture:!0,passive:!1}),p.addEventListener("keydown",G,{capture:!0,passive:!1}),p.addEventListener("keydown",I),o},A=function(){if(h.active)return p.removeEventListener("focusin",x,!0),p.removeEventListener("mousedown",P,!0),p.removeEventListener("touchstart",P,!0),p.removeEventListener("click",R,!0),p.removeEventListener("keydown",G,!0),p.removeEventListener("keydown",I),o},L="undefined"!=typeof window&&"MutationObserver"in window?new MutationObserver((function(e){e.some((function(e){return Array.from(e.removedNodes).some((function(e){return e===h.mostRecentlyFocusedNode}))}))&&E(N())})):void 0,S=function(){L&&(L.disconnect(),h.active&&!h.paused&&h.containers.map((function(e){L.observe(e,{subtree:!0,childList:!0})})))};return(o={get active(){return h.active},get paused(){return h.paused},activate:function(e){if(h.active)return this;var t=w(e,"onActivate"),n=w(e,"onPostActivate"),o=w(e,"checkCanFocusTrap");o||T(),h.active=!0,h.paused=!1,h.nodeFocusedBeforeActivation=p.activeElement,null==t||t();var r=function(){o&&T(),j(),S(),null==n||n()};return o?(o(h.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!h.active)return this;var t=r({onDeactivate:y.onDeactivate,onPostDeactivate:y.onPostDeactivate,checkCanReturnFocus:y.checkCanReturnFocus},e);clearTimeout(h.delayInitialFocusTimer),h.delayInitialFocusTimer=void 0,A(),h.active=!1,h.paused=!1,S(),u(m,o);var n=w(t,"onDeactivate"),a=w(t,"onPostDeactivate"),i=w(t,"checkCanReturnFocus"),c=w(t,"returnFocus","returnFocusOnDeactivate");null==n||n();var s=function(){b((function(){c&&E(k(h.nodeFocusedBeforeActivation)),null==a||a()}))};return c&&i?(i(k(h.nodeFocusedBeforeActivation)).then(s,s),this):(s(),this)},pause:function(e){if(h.paused||!h.active)return this;var t=w(e,"onPause"),n=w(e,"onPostPause");return h.paused=!0,null==t||t(),A(),S(),null==n||n(),this},unpause:function(e){if(!h.paused||!h.active)return this;var t=w(e,"onUnpause"),n=w(e,"onPostUnpause");return h.paused=!1,null==t||t(),T(),j(),S(),null==n||n(),this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return h.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),h.active&&T(),S(),this}}).updateContainerElements(t),o}; //# sourceMappingURL=focus-trap.min.js.map