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