/*! * focus-trap 7.4.3 * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE */ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tabbable");function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function n(e){for(var n=1;n0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},o=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},i=function(e){return"Tab"===e.key||9===e.keyCode},u=function(e){return i(e)&&!e.shiftKey},c=function(e){return i(e)&&e.shiftKey},s=function(e){return setTimeout(e,0)},l=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},b=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a1?n-1:0),r=1;r=0)t=p.activeElement;else{var n=h.tabbableGroups[0];t=n&&n.firstTabbableNode||O("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,m.tabbableOptions),a=e.focusable(t,m.tabbableOptions);return{container:t,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(e){return e===t}));if(!(r<0))return n?a.slice(r+1).find((function(t){return e.isTabbable(t,m.tabbableOptions)})):a.slice(0,r).reverse().find((function(t){return e.isTabbable(t,m.tabbableOptions)}))}}})),h.tabbableGroups=h.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),h.tabbableGroups.length<=0&&!O("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times")},N=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!m.preventScroll}),h.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},k=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},P=function(e){var t=f(e);g(t,e)>=0||(b(m.clickOutsideDeactivates,e)?d.deactivate({returnFocus:m.returnFocusOnDeactivate}):b(m.allowOutsideClick,e)||e.preventDefault())},E=function(e){var t=f(e),n=g(t,e)>=0;n||t instanceof Document?n&&(h.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),N(h.mostRecentlyFocusedNode||F()))},D=function(t){if(!(n=t,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===b(m.escapeDeactivates,t)))return t.preventDefault(),void d.deactivate();var n;(m.isKeyForward(t)||m.isKeyBackward(t))&&function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=f(t);T();var r=null;if(h.tabbableGroups.length>0){var o=g(a,t),u=o>=0?h.containerGroups[o]:void 0;if(o<0)r=n?h.tabbableGroups[h.tabbableGroups.length-1].lastTabbableNode:h.tabbableGroups[0].firstTabbableNode;else if(n){var c=l(h.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(u.container===a||e.isFocusable(a,m.tabbableOptions)&&!e.isTabbable(a,m.tabbableOptions)&&!u.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?h.tabbableGroups.length-1:c-1;r=h.tabbableGroups[s].lastTabbableNode}else i(t)||(r=u.nextTabbableNode(a,!1))}else{var b=l(h.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(u.container===a||e.isFocusable(a,m.tabbableOptions)&&!e.isTabbable(a,m.tabbableOptions)&&!u.nextTabbableNode(a))&&(b=o),b>=0){var v=b===h.tabbableGroups.length-1?0:b+1;r=h.tabbableGroups[v].firstTabbableNode}else i(t)||(r=u.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(i(t)&&t.preventDefault(),N(r))}(t,m.isKeyBackward(t))},G=function(e){var t=f(e);g(t,e)>=0||b(m.clickOutsideDeactivates,e)||b(m.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(h.active)return r(y,d),h.delayInitialFocusTimer=m.delayInitialFocus?s((function(){N(F())})):N(F()),p.addEventListener("focusin",E,!0),p.addEventListener("mousedown",P,{capture:!0,passive:!1}),p.addEventListener("touchstart",P,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",D,{capture:!0,passive:!1}),d},L=function(){if(h.active)return p.removeEventListener("focusin",E,!0),p.removeEventListener("mousedown",P,!0),p.removeEventListener("touchstart",P,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",D,!0),d},x="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}))}))&&N(F())})):void 0,C=function(){x&&(x.disconnect(),h.active&&!h.paused&&h.containers.map((function(e){x.observe(e,{subtree:!0,childList:!0})})))};return(d={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"),a=w(e,"checkCanFocusTrap");a||T(),h.active=!0,h.paused=!1,h.nodeFocusedBeforeActivation=p.activeElement,null==t||t();var r=function(){a&&T(),j(),C(),null==n||n()};return a?(a(h.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!h.active)return this;var t=n({onDeactivate:m.onDeactivate,onPostDeactivate:m.onPostDeactivate,checkCanReturnFocus:m.checkCanReturnFocus},e);clearTimeout(h.delayInitialFocusTimer),h.delayInitialFocusTimer=void 0,L(),h.active=!1,h.paused=!1,C(),o(y,d);var a=w(t,"onDeactivate"),r=w(t,"onPostDeactivate"),i=w(t,"checkCanReturnFocus"),u=w(t,"returnFocus","returnFocusOnDeactivate");null==a||a();var c=function(){s((function(){u&&N(k(h.nodeFocusedBeforeActivation)),null==r||r()}))};return u&&i?(i(k(h.nodeFocusedBeforeActivation)).then(c,c),this):(c(),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(),L(),C(),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(),C(),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(),C(),this}}).updateContainerElements(t),d}; //# sourceMappingURL=focus-trap.min.js.map