7 lines
8.5 KiB
JavaScript
7 lines
8.5 KiB
JavaScript
|
/*!
|
||
|
* focus-trap 7.4.3
|
||
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
||
|
*/
|
||
|
import{isFocusable as e,tabbable as t,focusable as n,isTabbable as r}from"tabbable";function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var u=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var r=e.indexOf(t);-1===r||e.splice(r,1),e.push(t)},c=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},s=function(e){return"Tab"===e.key||9===e.keyCode},l=function(e){return s(e)&&!e.shiftKey},b=function(e){return s(e)&&e.shiftKey},f=function(e){return setTimeout(e,0)},v=function(e,t){var n=-1;return e.every((function(e,r){return!t(e)||(n=r,!1)})),n},d=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return"function"==typeof e?e.apply(void 0,n):e},p=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},m=[],y=function(o,i){var y,h=(null==i?void 0:i.document)||document,w=(null==i?void 0:i.trapStack)||m,g=a({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:l,isKeyBackward:b},i),O={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},F=function(e,t,n){return e&&void 0!==e[t]?e[t]:g[n||t]},N=function(e,t){var n="function"==typeof(null==t?void 0:t.composedPath)?t.composedPath():void 0;return O.containerGroups.findIndex((function(t){var r=t.container,o=t.tabbableNodes;return r.contains(e)||(null==n?void 0:n.includes(r))||o.find((function(t){return t===e}))}))},k=function(e){var t=g[e];if("function"==typeof t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];t=t.apply(void 0,r)}if(!0===t&&(t=void 0),!t){if(void 0===t||!1===t)return t;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var a=t;if("string"==typeof t&&!(a=h.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return a},E=function(){var t=k("initialFocus");if(!1===t)return!1;if(void 0===t||!e(t,g.tabbableOptions))if(N(h.activeElement)>=0)t=h.activeElement;else{var n=O.tabbableGroups[0];t=n&&n.firstTabbableNode||k("fallbackFocus")}if(!t)throw new Error("Your focus-trap needs to have at least one focusable element");return t},P=function(){if(O.containerGroups=O.containers.map((function(e){var o=t(e,g.tabbableOptions),a=n(e,g.tabbableOptions);return{container:e,tabbableNodes:o,focusableNodes:a,firstTabbableNode:o.length>0?o[0]:null,lastTabbableNode:o.length>0?o[o.length-1]:null,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=a.findIndex((function(t){return t===e}));if(!(n<0))return t?a.slice(n+1).find((function(e){return r(e,g.tabbableOptions)})):a.slice(0,n).reverse().find((function(e){return r(e,g.tabbableOptions)}))}}})),O.tabbableGroups=O.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),O.tabbableGroups.length<=0&&!k("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all ti
|
||
|
//# sourceMappingURL=focus-trap.esm.min.js.map
|