Files
JiboViteDocs/node_modules/focus-trap/dist/focus-trap.esm.min.js
Your Name 38652eb9b5 Initalize
2026-05-03 12:12:57 -04:00

9 lines
17 KiB
JavaScript

/*!
* focus-trap 8.1.0
* @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,getTabIndex as o}from"tabbable";function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function i(e,t,n,r,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,o)}function u(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function u(e){i(a,r,o,u,c,"next",e)}function c(e){i(a,r,o,u,c,"throw",e)}u(void 0)}))}}function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=p(e))||t){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){u=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(u)throw a}}}}function s(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);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:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(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 d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function a(n,r,o,a){var c=r&&r.prototype instanceof u?r:u,s=Object.create(c.prototype);return v(s,"_invoke",function(n,r,o){var a,u,c,s=0,l=o||[],d=!1,f={p:0,n:0,v:e,a:v,f:v.bind(e,4),d:function(t,n){return a=t,u=0,c=e,f.n=n,i}};function v(n,r){for(u=n,c=r,t=0;!d&&s&&!o&&t<l.length;t++){var o,a=l[t],v=f.p,b=a[2];n>3?(o=b===r)&&(c=a[(u=a[4])?5:(u=3,3)],a[4]=a[5]=e):a[0]<=v&&((o=n<2&&v<a[1])?(u=0,f.v=r,f.n=a[1]):v<b&&(o=n<3||a[0]>r||r>b)&&(a[4]=n,a[5]=r,f.n=b,u=0))}if(o||n>1)return i;throw d=!0,r}return function(o,l,b){if(s>1)throw TypeError("Generator is already running");for(d&&1===l&&v(l,b),u=l,c=b;(t=u<2?e:c)||!d;){a||(u?u<3?(u>1&&(f.n=-1),v(u,c)):f.n=c:f.v=c);try{if(s=2,a){if(u||(o="next"),t=a[o]){if(!(t=t.call(a,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=a.return)&&t.call(a),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);a=e}else if((t=(d=f.n<0)?c:n.call(r,f))!==i)break}catch(t){a=e,u=1,c=t}finally{s=1}}return{value:t,done:d}}}(n,o,a),!0),s}var i={};function u(){}function c(){}function s(){}t=Object.getPrototypeOf;var l=[][r]?t(t([][r]())):(v(t={},r,(function(){return this})),t),d=s.prototype=u.prototype=Object.create(l);function b(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,v(e,o,"GeneratorFunction")),e.prototype=Object.create(d),e}return c.prototype=s,v(d,"constructor",s),v(s,"constructor",c),c.displayName="GeneratorFunction",v(s,o,"GeneratorFunction"),v(d),v(d,o,"Generator"),v(d,r,(function(){return this})),v(d,"toString",(function(){return"[object Generator]"})),(f=function(){return{w:a,m:b}})()}function v(e,t,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}v=function(e,t,n,r){function a(t,n){v(e,t,(function(e){return this._invoke(t,n,e)}))}t?o?o(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(a("next",0),a("throw",1),a("return",2))},v(e,t,n,r)}function b(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){if(e){if("string"==typeof e)return a(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,t):void 0}}var y={getActiveTrap:function(e){return(null==e?void 0:e.length)>0?e[e.length-1]:null},activateTrap:function(e,t){t!==y.getActiveTrap(e)&&y.pauseTrap(e);var n=e.indexOf(t);-1===n||e.splice(n,1),e.push(t)},deactivateTrap:function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),y.unpauseTrap(e)},pauseTrap:function(e){var t=y.getActiveTrap(e);null==t||t._setPausedState(!0)},unpauseTrap:function(e){var t=y.getActiveTrap(e);t&&!t._isManuallyPaused()&&t._setPausedState(!1)}},h=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},m=function(e){return h(e)&&!e.shiftKey},w=function(e){return h(e)&&e.shiftKey},g=function(e){return setTimeout(e,0)},S=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},O=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},T=[],N=function(a,i){var s,l=(null==i?void 0:i.document)||document,v=(null==i?void 0:i.trapStack)||T,p=d({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isolateSubtrees:!1,isKeyForward:m,isKeyBackward:w},i),N={containers:[],containerGroups:[],tabbableGroups:[],adjacentElements:new Set,alreadySilent:new Set,nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,manuallyPaused:!1,delayInitialFocusTimer:void 0,recentNavEvent:void 0},P=function(e,t,n){return e&&void 0!==e[t]?e[t]:p[n||t]},E=function(e,t){var n="function"==typeof(null==t?void 0:t.composedPath)?t.composedPath():void 0;return N.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}))}))},F=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.hasFallback,r=void 0!==n&&n,o=t.params,a=void 0===o?[]:o,i=p[e];if("function"==typeof i&&(i=i.apply(void 0,b(a))),!0===i&&(i=void 0),!i){if(void 0===i||!1===i)return i;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var u=i;if("string"==typeof i){try{u=l.querySelector(i)}catch(t){throw new Error("`".concat(e,'` appears to be an invalid selector; error="').concat(t.message,'"'))}if(!u&&!r)throw new Error("`".concat(e,"` as selector refers to no known node"))}return u},k=function(){var t=F("initialFocus",{hasFallback:!0});if(!1===t)return!1;if(void 0===t||t&&!e(t,p.tabbableOptions))if(E(l.activeElement)>=0)t=l.activeElement;else{var n=N.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},j=function(){if(N.containerGroups=N.containers.map((function(e){var a=t(e,p.tabbableOptions),i=n(e,p.tabbableOptions),u=a.length>0?a[0]:void 0,c=a.length>0?a[a.length-1]:void 0,s=i.find((function(e){return r(e)})),l=i.slice().reverse().find((function(e){return r(e)})),d=!!a.find((function(e){return o(e)>0}));return{container:e,tabbableNodes:a,focusableNodes:i,posTabIndexesFound:d,firstTabbableNode:u,lastTabbableNode:c,firstDomTabbableNode:s,lastDomTabbableNode:l,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=a.indexOf(e);return n<0?t?i.slice(i.indexOf(e)+1).find((function(e){return r(e)})):i.slice(0,i.indexOf(e)).reverse().find((function(e){return r(e)})):a[n+(t?1:-1)]}}})),N.tabbableGroups=N.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),N.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(N.containerGroups.find((function(e){return e.posTabIndexesFound}))&&N.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.")},A=function(e){var t=e.activeElement;if(t)return t.shadowRoot&&null!==t.shadowRoot.activeElement?A(t.shadowRoot):t},G=function(e){!1!==e&&e!==A(document)&&(e&&e.focus?(e.focus({preventScroll:!!p.preventScroll}),N.mostRecentlyFocusedNode=e,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(e)&&e.select()):G(k()))},I=function(e){var t=F("setReturnFocus",{params:[e]});return t||!1!==t&&e},D=function(t){var n=t.target,a=t.event,i=t.isBackward,u=void 0!==i&&i;n=n||O(a),j();var c=null;if(N.tabbableGroups.length>0){var s=E(n,a),l=s>=0?N.containerGroups[s]:void 0;if(s<0)c=u?N.tabbableGroups[N.tabbableGroups.length-1].lastTabbableNode:N.tabbableGroups[0].firstTabbableNode;else if(u){var d=N.tabbableGroups.findIndex((function(e){var t=e.firstTabbableNode;return n===t}));if(d<0&&(l.container===n||e(n,p.tabbableOptions)&&!r(n,p.tabbableOptions)&&!l.nextTabbableNode(n,!1))&&(d=s),d>=0){var f=0===d?N.tabbableGroups.length-1:d-1,v=N.tabbableGroups[f];c=o(n)>=0?v.lastTabbableNode:v.lastDomTabbableNode}else h(a)||(c=l.nextTabbableNode(n,!1))}else{var b=N.tabbableGroups.findIndex((function(e){var t=e.lastTabbableNode;return n===t}));if(b<0&&(l.container===n||e(n,p.tabbableOptions)&&!r(n,p.tabbableOptions)&&!l.nextTabbableNode(n))&&(b=s),b>=0){var y=b===N.tabbableGroups.length-1?0:b+1,m=N.tabbableGroups[y];c=o(n)>=0?m.firstTabbableNode:m.firstDomTabbableNode}else h(a)||(c=l.nextTabbableNode(n))}}else c=F("fallbackFocus");return c},R=function(e){var t=O(e);E(t,e)>=0||(S(p.clickOutsideDeactivates,e)?s.deactivate({returnFocus:p.returnFocusOnDeactivate}):S(p.allowOutsideClick,e)||e.preventDefault())},x=function(e){var t=O(e),n=E(t,e)>=0;if(n||t instanceof Document)n&&(N.mostRecentlyFocusedNode=t);else{var r;e.stopImmediatePropagation();var a=!0;if(N.mostRecentlyFocusedNode)if(o(N.mostRecentlyFocusedNode)>0){var i=E(N.mostRecentlyFocusedNode),u=N.containerGroups[i].tabbableNodes;if(u.length>0){var c=u.findIndex((function(e){return e===N.mostRecentlyFocusedNode}));c>=0&&(p.isKeyForward(N.recentNavEvent)?c+1<u.length&&(r=u[c+1],a=!1):c-1>=0&&(r=u[c-1],a=!1))}}else N.containerGroups.some((function(e){return e.tabbableNodes.some((function(e){return o(e)>0}))}))||(a=!1);else a=!1;a&&(r=D({target:N.mostRecentlyFocusedNode,isBackward:p.isKeyBackward(N.recentNavEvent)})),G(r||(N.mostRecentlyFocusedNode||k()))}N.recentNavEvent=void 0},_=function(e){(p.isKeyForward(e)||p.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];N.recentNavEvent=e;var n=D({event:e,isBackward:t});n&&(h(e)&&e.preventDefault(),G(n))}(e,p.isKeyBackward(e))},L=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===S(p.escapeDeactivates,e)||(e.preventDefault(),s.deactivate())},C=function(e){var t=O(e);E(t,e)>=0||S(p.clickOutsideDeactivates,e)||S(p.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},B=function(){return N.active?(y.activateTrap(v,s),p.delayInitialFocus?e=new Promise((function(e){N.delayInitialFocusTimer=g((function(){G(k()),e()}))})):(e=Promise.resolve(),G(k())),l.addEventListener("focusin",x,!0),l.addEventListener("mousedown",R,{capture:!0,passive:!1}),l.addEventListener("touchstart",R,{capture:!0,passive:!1}),l.addEventListener("click",C,{capture:!0,passive:!1}),l.addEventListener("keydown",_,{capture:!0,passive:!1}),l.addEventListener("keydown",L),e):Promise.resolve();var e},K=function(){if(N.active)return l.removeEventListener("focusin",x,!0),l.removeEventListener("mousedown",R,!0),l.removeEventListener("touchstart",R,!0),l.removeEventListener("click",C,!0),l.removeEventListener("keydown",_,!0),l.removeEventListener("keydown",L),s},M="undefined"!=typeof window&&"MutationObserver"in window?new MutationObserver((function(e){e.some((function(e){return Array.from(e.removedNodes).some((function(e){return e===N.mostRecentlyFocusedNode}))}))&&G(k())})):void 0,U=function(){M&&(M.disconnect(),N.active&&!N.paused&&N.containers.map((function(e){M.observe(e,{subtree:!0,childList:!0})})))};return s={get active(){return N.active},get paused(){return N.paused},activate:function(e){if(N.active)return this;var t,n=P(e,"onActivate"),r=P(e,"onPostActivate"),o=P(e,"checkCanFocusTrap"),a=y.getActiveTrap(v),i=!1;a&&!a.paused&&(null===(t=a._setSubtreeIsolation)||void 0===t||t.call(a,!1),i=!0);try{o||j(),N.active=!0,N.paused=!1,N.nodeFocusedBeforeActivation=A(l),null==n||n({trap:s});var c=function(){var e=u(f().m((function e(){return f().w((function(e){for(;;)switch(e.n){case 0:return o&&j(),e.n=1,B();case 1:s._setSubtreeIsolation(!0),U(),null==r||r({trap:s});case 2:return e.a(2)}}),e)})));return function(){return e.apply(this,arguments)}}();if(o)return o(N.containers.concat()).then(c,c),this;c()}catch(e){var d;if(a===y.getActiveTrap(v)&&i)null===(d=a._setSubtreeIsolation)||void 0===d||d.call(a,!0);throw e}return this},deactivate:function(e){if(!N.active)return this;var t=d({onDeactivate:p.onDeactivate,onPostDeactivate:p.onPostDeactivate,checkCanReturnFocus:p.checkCanReturnFocus},e);clearTimeout(N.delayInitialFocusTimer),N.delayInitialFocusTimer=void 0,N.paused||s._setSubtreeIsolation(!1),N.alreadySilent.clear(),K(),N.active=!1,N.paused=!1,U(),y.deactivateTrap(v,s);var n=P(t,"onDeactivate"),r=P(t,"onPostDeactivate"),o=P(t,"checkCanReturnFocus"),a=P(t,"returnFocus","returnFocusOnDeactivate");null==n||n({trap:s});var i=function(){g((function(){a&&G(I(N.nodeFocusedBeforeActivation)),null==r||r({trap:s})}))};return a&&o?(o(I(N.nodeFocusedBeforeActivation)).then(i,i),this):(i(),this)},pause:function(e){return N.active?(N.manuallyPaused=!0,this._setPausedState(!0,e)):this},unpause:function(e){return N.active?(N.manuallyPaused=!1,v[v.length-1]!==this?this:this._setPausedState(!1,e)):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return N.containers=t.map((function(e){return"string"==typeof e?l.querySelector(e):e})),p.isolateSubtrees&&function(e){N.active&&!N.paused&&s._setSubtreeIsolation(!1),N.adjacentElements.clear(),N.alreadySilent.clear();var t,n=new Set,r=new Set,o=c(e);try{for(o.s();!(t=o.n()).done;){var a=t.value;n.add(a);for(var i="undefined"!=typeof ShadowRoot&&a.getRootNode()instanceof ShadowRoot,u=a;u;){n.add(u);var l=u.parentElement,d=[];l?d=l.children:!l&&i&&(d=u.getRootNode().children,l=u.getRootNode().host,i="undefined"!=typeof ShadowRoot&&l.getRootNode()instanceof ShadowRoot);var f,v=c(d);try{for(v.s();!(f=v.n()).done;){var b=f.value;r.add(b)}}catch(e){v.e(e)}finally{v.f()}u=l}}}catch(e){o.e(e)}finally{o.f()}n.forEach((function(e){r.delete(e)})),N.adjacentElements=r}(N.containers),N.active&&(j(),N.paused||s._setSubtreeIsolation(!0)),U(),this}},Object.defineProperties(s,{_isManuallyPaused:{value:function(){return N.manuallyPaused}},_setPausedState:{value:function(e,t){if(N.paused===e)return this;if(N.paused=e,e){var n=P(t,"onPause"),r=P(t,"onPostPause");null==n||n({trap:s}),K(),s._setSubtreeIsolation(!1),U(),null==r||r({trap:s})}else{var o=P(t,"onUnpause"),a=P(t,"onPostUnpause");null==o||o({trap:s});var i=function(){var e=u(f().m((function e(){return f().w((function(e){for(;;)switch(e.n){case 0:return j(),e.n=1,B();case 1:s._setSubtreeIsolation(!0),U(),null==a||a({trap:s});case 2:return e.a(2)}}),e)})));return function(){return e.apply(this,arguments)}}();i()}return this}},_setSubtreeIsolation:{value:function(e){p.isolateSubtrees&&N.adjacentElements.forEach((function(t){var n;if(e)if("aria-hidden"===p.isolateSubtrees)"true"!==t.ariaHidden&&"true"!==(null===(n=t.getAttribute("aria-hidden"))||void 0===n?void 0:n.toLowerCase())||N.alreadySilent.add(t),t.setAttribute("aria-hidden","true");else(t.inert||t.hasAttribute("inert"))&&N.alreadySilent.add(t),t.setAttribute("inert",!0);else if(N.alreadySilent.has(t));else if("aria-hidden"===p.isolateSubtrees)t.removeAttribute("aria-hidden");else t.removeAttribute("inert")}))}}}),s.updateContainerElements(a),s};export{N as createFocusTrap};
//# sourceMappingURL=focus-trap.esm.min.js.map