focus-trap 8.2.1 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/focus-trap.esm.js +1 -1
- package/dist/focus-trap.esm.min.js +1 -1
- package/dist/focus-trap.js +1 -1
- package/dist/focus-trap.min.js +1 -1
- package/dist/focus-trap.umd.js +1 -1
- package/dist/focus-trap.umd.min.js +1 -1
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
package/dist/focus-trap.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 8.2.
|
|
2
|
+
* focus-trap 8.2.2
|
|
3
3
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
import{tabbable as e,focusable as t,isTabbable as n,getTabIndex as a,isFocusable as r}from"tabbable";function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function i(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 a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}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 u(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 a=n.call(e,t);if("object"!=typeof a)return a;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 s(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 c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e){return function(e){if(Array.isArray(e))return o(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,t){if(e){if("string"==typeof e)return o(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)?o(e,t):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)}},v=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},b=function(e){return v(e)&&!e.shiftKey},p=function(e){return v(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),a=1;a<t;a++)n[a-1]=arguments[a];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=[],g=function(o,u){var s,d=(null==u?void 0:u.document)||document,g=(null==u?void 0:u.trapStack)||w,S=c({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,delayReturnFocus:!0,isolateSubtrees:!1,isKeyForward:b,isKeyBackward:p},u),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},T=function(e,t,n){return e&&void 0!==e[t]?e[t]:S[n||t]},F=function(e,t){var n="function"==typeof(null==t?void 0:t.composedPath)?t.composedPath():void 0;return N.containerGroups.findIndex((function(t){var a=t.container,r=t.tabbableNodes;return a.contains(e)||(null==n?void 0:n.includes(a))||r.find((function(t){return t===e}))}))},E=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.hasFallback,a=void 0!==n&&n,r=t.params,o=void 0===r?[]:r,i=S[e];if("function"==typeof i&&(i=i.apply(void 0,l(o))),!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=d.querySelector(i)}catch(t){throw new Error("`".concat(e,'` appears to be an invalid selector; error="').concat(t.message,'"'))}if(!u&&!a)throw new Error("`".concat(e,"` as selector refers to no known node"))}return u},O=function(e){var t=e.activeElement;return t?t.shadowRoot&&null!==t.shadowRoot.activeElement?O(t.shadowRoot):t:null},P=function(){var e=E("initialFocus",{hasFallback:!0});if(!1===e)return!1;if(void 0===e||e&&!r(e,S.tabbableOptions)){var t=O(d);if(F(t)>=0)e=t;else{var n=N.tabbableGroups[0];e=n&&n.firstTabbableNode||E("fallbackFocus")}}else null===e&&(e=E("fallbackFocus"));if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},k=function(){if(N.containerGroups=N.containers.map((function(r){var o=e(r,S.tabbableOptions),i=t(r,S.tabbableOptions),u=o.length>0?o[0]:void 0,s=o.length>0?o[o.length-1]:void 0,c=i.find((function(e){return n(e)})),l=i.slice().reverse().find((function(e){return n(e)})),d=!!o.find((function(e){return a(e)>0}));return{container:r,tabbableNodes:o,focusableNodes:i,posTabIndexesFound:d,firstTabbableNode:u,lastTabbableNode:s,firstDomTabbableNode:c,lastDomTabbableNode:l,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=o.indexOf(e);return a<0?t?i.slice(i.indexOf(e)+1).find((function(e){return n(e)})):i.slice(0,i.indexOf(e)).reverse().find((function(e){return n(e)})):o[a+(t?1:-1)]}}})),N.tabbableGroups=N.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),N.tabbableGroups.length<=0&&!E("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){!1!==e&&e!==O(document)&&(e&&e.focus?(e.focus({preventScroll:!!S.preventScroll}),N.mostRecentlyFocusedNode=e,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(e)&&e.select()):A(P()))},I=function(e){var t=E("setReturnFocus",{params:[e]});return t||!1!==t&&e},R=function(e){var t=e.target,o=e.event,i=e.isBackward,u=void 0!==i&&i;t=t||m(o),k();var s=null;if(N.tabbableGroups.length>0){var c=F(t,o),l=c>=0?N.containerGroups[c]:void 0;if(c<0)s=u?N.tabbableGroups[N.tabbableGroups.length-1].lastTabbableNode:N.tabbableGroups[0].firstTabbableNode;else if(u){var d=N.tabbableGroups.findIndex((function(e){var n=e.firstTabbableNode;return t===n}));if(d<0&&(l.container===t||r(t,S.tabbableOptions)&&!n(t,S.tabbableOptions)&&!l.nextTabbableNode(t,!1))&&(d=c),d>=0){var f=0===d?N.tabbableGroups.length-1:d-1,b=N.tabbableGroups[f];s=a(t)>=0?b.lastTabbableNode:b.lastDomTabbableNode}else v(o)||(s=l.nextTabbableNode(t,!1))}else{var p=N.tabbableGroups.findIndex((function(e){var n=e.lastTabbableNode;return t===n}));if(p<0&&(l.container===t||r(t,S.tabbableOptions)&&!n(t,S.tabbableOptions)&&!l.nextTabbableNode(t))&&(p=c),p>=0){var y=p===N.tabbableGroups.length-1?0:p+1,h=N.tabbableGroups[y];s=a(t)>=0?h.firstTabbableNode:h.firstDomTabbableNode}else v(o)||(s=l.nextTabbableNode(t))}}else s=E("fallbackFocus");return s},D=function(e){var t=m(e);F(t,e)>=0||(h(S.clickOutsideDeactivates,e)?s.deactivate({returnFocus:S.returnFocusOnDeactivate}):h(S.allowOutsideClick,e)||e.preventDefault())},G=function(e){var t=m(e),n=F(t,e)>=0;if(n||t instanceof Document)n&&(N.mostRecentlyFocusedNode=t);else{var r;e.stopImmediatePropagation();var o=!0;if(N.mostRecentlyFocusedNode)if(a(N.mostRecentlyFocusedNode)>0){var i=F(N.mostRecentlyFocusedNode),u=N.containerGroups[i].tabbableNodes;if(u.length>0){var s=u.findIndex((function(e){return e===N.mostRecentlyFocusedNode}));s>=0&&(S.isKeyForward(N.recentNavEvent)?s+1<u.length&&(r=u[s+1],o=!1):s-1>=0&&(r=u[s-1],o=!1))}}else N.containerGroups.some((function(e){return e.tabbableNodes.some((function(e){return a(e)>0}))}))||(o=!1);else o=!1;o&&(r=R({target:N.mostRecentlyFocusedNode,isBackward:S.isKeyBackward(N.recentNavEvent)})),A(r||(N.mostRecentlyFocusedNode||P()))}N.recentNavEvent=void 0},j=function(e){(S.isKeyForward(e)||S.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];N.recentNavEvent=e;var n=R({event:e,isBackward:t});n&&(v(e)&&e.preventDefault(),A(n))}(e,S.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(S.escapeDeactivates,e)||(e.preventDefault(),s.deactivate())},_=function(e){var t=m(e);F(t,e)>=0||h(S.clickOutsideDeactivates,e)||h(S.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},L=function(){var e;if(N.active)return f.activateTrap(g,s),S.delayInitialFocus?e=new Promise((function(e){N.delayInitialFocusTimer=y((function(){A(P()),e()}))})):A(P()),d.addEventListener("focusin",G,!0),d.addEventListener("mousedown",D,{capture:!0,passive:!1}),d.addEventListener("touchstart",D,{capture:!0,passive:!1}),d.addEventListener("click",_,{capture:!0,passive:!1}),d.addEventListener("keydown",j,{capture:!0,passive:!1}),d.addEventListener("keydown",x),e},C=function(){if(N.active)return d.removeEventListener("focusin",G,!0),d.removeEventListener("mousedown",D,!0),d.removeEventListener("touchstart",D,!0),d.removeEventListener("click",_,!0),d.removeEventListener("keydown",j,!0),d.removeEventListener("keydown",x),s},B="undefined"!=typeof window&&"MutationObserver"in window?new MutationObserver((function(e){var t=N.mostRecentlyFocusedNode;if(t&&(e.some((function(e){return Array.from(e.removedNodes).some((function(e){return e===t||"function"==typeof e.contains&&e.contains(t)}))}))&&N.containers.some((function(e){return null==e?void 0:e.isConnected})))){k();var n=P();A(n)}})):void 0,K=function(){B&&(B.disconnect(),N.active&&!N.paused&&N.containers.map((function(e){B.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=T(e,"onActivate"),a=T(e,"onPostActivate"),r=T(e,"checkCanFocusTrap"),o=f.getActiveTrap(g),i=!1;o&&!o.paused&&(null===(t=o._setSubtreeIsolation)||void 0===t||t.call(o,!1),i=!0);try{r||k(),N.active=!0,N.paused=!1,N.nodeFocusedBeforeActivation=O(d),null==n||n({trap:s});var u=function(){r&&k();var e=function(){s._setSubtreeIsolation(!0),K(),null==a||a({trap:s})},t=L();t?t.then(e):e()};if(r)return r(N.containers.concat()).then(u,u),this;u()}catch(e){var c;if(o===f.getActiveTrap(g)&&i)null===(c=o._setSubtreeIsolation)||void 0===c||c.call(o,!0);throw e}return this},deactivate:function(e){if(!N.active)return this;var t=c({onDeactivate:S.onDeactivate,onPostDeactivate:S.onPostDeactivate,checkCanReturnFocus:S.checkCanReturnFocus},e);clearTimeout(N.delayInitialFocusTimer),N.delayInitialFocusTimer=void 0,N.paused||s._setSubtreeIsolation(!1),N.alreadySilent.clear(),C(),N.active=!1,N.paused=!1,K(),f.deactivateTrap(g,s);var n=T(t,"onDeactivate"),a=T(t,"onPostDeactivate"),r=T(t,"checkCanReturnFocus"),o=T(t,"delayReturnFocus"),i=T(t,"returnFocus","returnFocusOnDeactivate");null==n||n({trap:s});var u=function(){i&&A(I(N.nodeFocusedBeforeActivation)),null==a||a({trap:s})},l=function(){o&&i?y(u):u()};return i&&r?(r(I(N.nodeFocusedBeforeActivation)).then(l,l),this):(l(),this)},pause:function(e){return N.active?(N.manuallyPaused=!0,this._setPausedState(!0,e)):this},unpause:function(e){return N.active?(N.manuallyPaused=!1,g[g.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?d.querySelector(e):e})),S.isolateSubtrees&&function(e){N.active&&!N.paused&&s._setSubtreeIsolation(!1),N.adjacentElements.clear(),N.alreadySilent.clear();var t,n=new Set,a=new Set,r=i(e);try{for(r.s();!(t=r.n()).done;){var o=t.value;n.add(o);for(var u="undefined"!=typeof ShadowRoot&&o.getRootNode()instanceof ShadowRoot,c=o;c;){n.add(c);var l=c.parentElement,d=[];l?d=l.children:!l&&u&&(d=c.getRootNode().children,l=c.getRootNode().host,u="undefined"!=typeof ShadowRoot&&l.getRootNode()instanceof ShadowRoot);var f,v=i(d);try{for(v.s();!(f=v.n()).done;){var b=f.value;a.add(b)}}catch(e){v.e(e)}finally{v.f()}c=l}}}catch(e){r.e(e)}finally{r.f()}n.forEach((function(e){a.delete(e)})),N.adjacentElements=a}(N.containers),N.active&&(k(),N.paused||s._setSubtreeIsolation(!0)),K(),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=T(t,"onPause"),a=T(t,"onPostPause");null==n||n({trap:s}),C(),s._setSubtreeIsolation(!1),K(),null==a||a({trap:s})}else{var r=T(t,"onUnpause"),o=T(t,"onPostUnpause");null==r||r({trap:s});!function(){k();var e=function(){s._setSubtreeIsolation(!0),K(),null==o||o({trap:s})},t=L();t?t.then(e):e()}()}return this}},_setSubtreeIsolation:{value:function(e){S.isolateSubtrees&&N.adjacentElements.forEach((function(t){var n;if(e)if("aria-hidden"===S.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"===S.isolateSubtrees)t.removeAttribute("aria-hidden");else t.removeAttribute("inert")}))}}}),s.updateContainerElements(o),s};export{g as createFocusTrap};
|
package/dist/focus-trap.js
CHANGED
package/dist/focus-trap.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 8.2.
|
|
2
|
+
* focus-trap 8.2.2
|
|
3
3
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
"use strict";var e=require("tabbable");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=u(e))||t){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}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,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}function a(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 a=n.call(e,t);if("object"!=typeof a)return a;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 r(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 o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(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)||u(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 u(e,n){if(e){if("string"==typeof e)return t(e,n);var a={}.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?t(e,n):void 0}}var s={getActiveTrap:function(e){return(null==e?void 0:e.length)>0?e[e.length-1]:null},activateTrap:function(e,t){t!==s.getActiveTrap(e)&&s.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),s.unpauseTrap(e)},pauseTrap:function(e){var t=s.getActiveTrap(e);null==t||t._setPausedState(!0)},unpauseTrap:function(e){var t=s.getActiveTrap(e);t&&!t._isManuallyPaused()&&t._setPausedState(!1)}},c=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},l=function(e){return c(e)&&!e.shiftKey},d=function(e){return c(e)&&e.shiftKey},f=function(e){return setTimeout(e,0)},b=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},v=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},p=[];exports.createFocusTrap=function(t,a){var r,u=(null==a?void 0:a.document)||document,y=(null==a?void 0:a.trapStack)||p,h=o({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,delayReturnFocus:!0,isolateSubtrees:!1,isKeyForward:l,isKeyBackward:d},a),m={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},w=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},g=function(e,t){var n="function"==typeof(null==t?void 0:t.composedPath)?t.composedPath():void 0;return m.containerGroups.findIndex((function(t){var a=t.container,r=t.tabbableNodes;return a.contains(e)||(null==n?void 0:n.includes(a))||r.find((function(t){return t===e}))}))},T=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.hasFallback,a=void 0!==n&&n,r=t.params,o=void 0===r?[]:r,s=h[e];if("function"==typeof s&&(s=s.apply(void 0,i(o))),!0===s&&(s=void 0),!s){if(void 0===s||!1===s)return s;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var c=s;if("string"==typeof s){try{c=u.querySelector(s)}catch(t){throw new Error("`".concat(e,'` appears to be an invalid selector; error="').concat(t.message,'"'))}if(!c&&!a)throw new Error("`".concat(e,"` as selector refers to no known node"))}return c},S=function(e){var t=e.activeElement;return t?t.shadowRoot&&null!==t.shadowRoot.activeElement?S(t.shadowRoot):t:null},F=function(){var t=T("initialFocus",{hasFallback:!0});if(!1===t)return!1;if(void 0===t||t&&!e.isFocusable(t,h.tabbableOptions)){var n=S(u);if(g(n)>=0)t=n;else{var a=m.tabbableGroups[0];t=a&&a.firstTabbableNode||T("fallbackFocus")}}else null===t&&(t=T("fallbackFocus"));if(!t)throw new Error("Your focus-trap needs to have at least one focusable element");return t},N=function(){if(m.containerGroups=m.containers.map((function(t){var n=e.tabbable(t,h.tabbableOptions),a=e.focusable(t,h.tabbableOptions),r=n.length>0?n[0]:void 0,o=n.length>0?n[n.length-1]:void 0,i=a.find((function(t){return e.isTabbable(t)})),u=a.slice().reverse().find((function(t){return e.isTabbable(t)})),s=!!n.find((function(t){return e.getTabIndex(t)>0}));return{container:t,tabbableNodes:n,focusableNodes:a,posTabIndexesFound:s,firstTabbableNode:r,lastTabbableNode:o,firstDomTabbableNode:i,lastDomTabbableNode:u,nextTabbableNode:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=n.indexOf(t);return o<0?r?a.slice(a.indexOf(t)+1).find((function(t){return e.isTabbable(t)})):a.slice(0,a.indexOf(t)).reverse().find((function(t){return e.isTabbable(t)})):n[o+(r?1:-1)]}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!T("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(m.containerGroups.find((function(e){return e.posTabIndexesFound}))&&m.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.")},E=function(e){!1!==e&&e!==S(document)&&(e&&e.focus?(e.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=e,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(e)&&e.select()):E(F()))},O=function(e){var t=T("setReturnFocus",{params:[e]});return t||!1!==t&&e},P=function(t){var n=t.target,a=t.event,r=t.isBackward,o=void 0!==r&&r;n=n||v(a),N();var i=null;if(m.tabbableGroups.length>0){var u=g(n,a),s=u>=0?m.containerGroups[u]:void 0;if(u<0)i=o?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(o){var l=m.tabbableGroups.findIndex((function(e){var t=e.firstTabbableNode;return n===t}));if(l<0&&(s.container===n||e.isFocusable(n,h.tabbableOptions)&&!e.isTabbable(n,h.tabbableOptions)&&!s.nextTabbableNode(n,!1))&&(l=u),l>=0){var d=0===l?m.tabbableGroups.length-1:l-1,f=m.tabbableGroups[d];i=e.getTabIndex(n)>=0?f.lastTabbableNode:f.lastDomTabbableNode}else c(a)||(i=s.nextTabbableNode(n,!1))}else{var b=m.tabbableGroups.findIndex((function(e){var t=e.lastTabbableNode;return n===t}));if(b<0&&(s.container===n||e.isFocusable(n,h.tabbableOptions)&&!e.isTabbable(n,h.tabbableOptions)&&!s.nextTabbableNode(n))&&(b=u),b>=0){var p=b===m.tabbableGroups.length-1?0:b+1,y=m.tabbableGroups[p];i=e.getTabIndex(n)>=0?y.firstTabbableNode:y.firstDomTabbableNode}else c(a)||(i=s.nextTabbableNode(n))}}else i=T("fallbackFocus");return i},k=function(e){var t=v(e);g(t,e)>=0||(b(h.clickOutsideDeactivates,e)?r.deactivate({returnFocus:h.returnFocusOnDeactivate}):b(h.allowOutsideClick,e)||e.preventDefault())},I=function(t){var n=v(t),a=g(n,t)>=0;if(a||n instanceof Document)a&&(m.mostRecentlyFocusedNode=n);else{var r;t.stopImmediatePropagation();var o=!0;if(m.mostRecentlyFocusedNode)if(e.getTabIndex(m.mostRecentlyFocusedNode)>0){var i=g(m.mostRecentlyFocusedNode),u=m.containerGroups[i].tabbableNodes;if(u.length>0){var s=u.findIndex((function(e){return e===m.mostRecentlyFocusedNode}));s>=0&&(h.isKeyForward(m.recentNavEvent)?s+1<u.length&&(r=u[s+1],o=!1):s-1>=0&&(r=u[s-1],o=!1))}}else m.containerGroups.some((function(t){return t.tabbableNodes.some((function(t){return e.getTabIndex(t)>0}))}))||(o=!1);else o=!1;o&&(r=P({target:m.mostRecentlyFocusedNode,isBackward:h.isKeyBackward(m.recentNavEvent)})),E(r||(m.mostRecentlyFocusedNode||F()))}m.recentNavEvent=void 0},A=function(e){(h.isKeyForward(e)||h.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];m.recentNavEvent=e;var n=P({event:e,isBackward:t});n&&(c(e)&&e.preventDefault(),E(n))}(e,h.isKeyBackward(e))},R=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===b(h.escapeDeactivates,e)||(e.preventDefault(),r.deactivate())},D=function(e){var t=v(e);g(t,e)>=0||b(h.clickOutsideDeactivates,e)||b(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},x=function(){var e;if(m.active)return s.activateTrap(y,r),h.delayInitialFocus?e=new Promise((function(e){m.delayInitialFocusTimer=f((function(){E(F()),e()}))})):E(F()),u.addEventListener("focusin",I,!0),u.addEventListener("mousedown",k,{capture:!0,passive:!1}),u.addEventListener("touchstart",k,{capture:!0,passive:!1}),u.addEventListener("click",D,{capture:!0,passive:!1}),u.addEventListener("keydown",A,{capture:!0,passive:!1}),u.addEventListener("keydown",R),e},G=function(){if(m.active)return u.removeEventListener("focusin",I,!0),u.removeEventListener("mousedown",k,!0),u.removeEventListener("touchstart",k,!0),u.removeEventListener("click",D,!0),u.removeEventListener("keydown",A,!0),u.removeEventListener("keydown",R),r},j="undefined"!=typeof window&&"MutationObserver"in window?new MutationObserver((function(e){var t=m.mostRecentlyFocusedNode;if(t&&(e.some((function(e){return Array.from(e.removedNodes).some((function(e){return e===t||"function"==typeof e.contains&&e.contains(t)}))}))&&m.containers.some((function(e){return null==e?void 0:e.isConnected})))){N();var n=F();E(n)}})):void 0,_=function(){j&&(j.disconnect(),m.active&&!m.paused&&m.containers.map((function(e){j.observe(e,{subtree:!0,childList:!0})})))};return r={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t,n=w(e,"onActivate"),a=w(e,"onPostActivate"),o=w(e,"checkCanFocusTrap"),i=s.getActiveTrap(y),c=!1;i&&!i.paused&&(null===(t=i._setSubtreeIsolation)||void 0===t||t.call(i,!1),c=!0);try{o||N(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=S(u),null==n||n({trap:r});var l=function(){o&&N();var e=function(){r._setSubtreeIsolation(!0),_(),null==a||a({trap:r})},t=x();t?t.then(e):e()};if(o)return o(m.containers.concat()).then(l,l),this;l()}catch(e){var d;if(i===s.getActiveTrap(y)&&c)null===(d=i._setSubtreeIsolation)||void 0===d||d.call(i,!0);throw e}return this},deactivate:function(e){if(!m.active)return this;var t=o({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,m.paused||r._setSubtreeIsolation(!1),m.alreadySilent.clear(),G(),m.active=!1,m.paused=!1,_(),s.deactivateTrap(y,r);var n=w(t,"onDeactivate"),a=w(t,"onPostDeactivate"),i=w(t,"checkCanReturnFocus"),u=w(t,"delayReturnFocus"),c=w(t,"returnFocus","returnFocusOnDeactivate");null==n||n({trap:r});var l=function(){c&&E(O(m.nodeFocusedBeforeActivation)),null==a||a({trap:r})},d=function(){u&&c?f(l):l()};return c&&i?(i(O(m.nodeFocusedBeforeActivation)).then(d,d),this):(d(),this)},pause:function(e){return m.active?(m.manuallyPaused=!0,this._setPausedState(!0,e)):this},unpause:function(e){return m.active?(m.manuallyPaused=!1,y[y.length-1]!==this?this:this._setPausedState(!1,e)):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?u.querySelector(e):e})),h.isolateSubtrees&&function(e){m.active&&!m.paused&&r._setSubtreeIsolation(!1),m.adjacentElements.clear(),m.alreadySilent.clear();var t,a=new Set,o=new Set,i=n(e);try{for(i.s();!(t=i.n()).done;){var u=t.value;a.add(u);for(var s="undefined"!=typeof ShadowRoot&&u.getRootNode()instanceof ShadowRoot,c=u;c;){a.add(c);var l=c.parentElement,d=[];l?d=l.children:!l&&s&&(d=c.getRootNode().children,l=c.getRootNode().host,s="undefined"!=typeof ShadowRoot&&l.getRootNode()instanceof ShadowRoot);var f,b=n(d);try{for(b.s();!(f=b.n()).done;){var v=f.value;o.add(v)}}catch(e){b.e(e)}finally{b.f()}c=l}}}catch(e){i.e(e)}finally{i.f()}a.forEach((function(e){o.delete(e)})),m.adjacentElements=o}(m.containers),m.active&&(N(),m.paused||r._setSubtreeIsolation(!0)),_(),this}},Object.defineProperties(r,{_isManuallyPaused:{value:function(){return m.manuallyPaused}},_setPausedState:{value:function(e,t){if(m.paused===e)return this;if(m.paused=e,e){var n=w(t,"onPause"),a=w(t,"onPostPause");null==n||n({trap:r}),G(),r._setSubtreeIsolation(!1),_(),null==a||a({trap:r})}else{var o=w(t,"onUnpause"),i=w(t,"onPostUnpause");null==o||o({trap:r});!function(){N();var e=function(){r._setSubtreeIsolation(!0),_(),null==i||i({trap:r})},t=x();t?t.then(e):e()}()}return this}},_setSubtreeIsolation:{value:function(e){h.isolateSubtrees&&m.adjacentElements.forEach((function(t){var n;if(e)if("aria-hidden"===h.isolateSubtrees)"true"!==t.ariaHidden&&"true"!==(null===(n=t.getAttribute("aria-hidden"))||void 0===n?void 0:n.toLowerCase())||m.alreadySilent.add(t),t.setAttribute("aria-hidden","true");else(t.inert||t.hasAttribute("inert"))&&m.alreadySilent.add(t),t.setAttribute("inert",!0);else if(m.alreadySilent.has(t));else if("aria-hidden"===h.isolateSubtrees)t.removeAttribute("aria-hidden");else t.removeAttribute("inert")}))}}}),r.updateContainerElements(t),r};
|
package/dist/focus-trap.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* focus-trap 8.2.
|
|
2
|
+
* focus-trap 8.2.2
|
|
3
3
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
4
4
|
*/
|
|
5
5
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tabbable")):"function"==typeof define&&define.amd?define(["exports","tabbable"],t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.focusTrap,a=e.focusTrap={};t(a,e.tabbable),a.noConflict=function(){return e.focusTrap=n,a}}())}(this,(function(e,t){"use strict";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=s(e))||t){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}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 r(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 a=n.call(e,t);if("object"!=typeof a)return a;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 o(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 i(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){r(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 u(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||s(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 s(e,t){if(e){if("string"==typeof e)return n(e,t);var a={}.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?n(e,t):void 0}}var c={getActiveTrap:function(e){return(null==e?void 0:e.length)>0?e[e.length-1]:null},activateTrap:function(e,t){t!==c.getActiveTrap(e)&&c.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),c.unpauseTrap(e)},pauseTrap:function(e){var t=c.getActiveTrap(e);null==t||t._setPausedState(!0)},unpauseTrap:function(e){var t=c.getActiveTrap(e);t&&!t._isManuallyPaused()&&t._setPausedState(!1)}},l=function(e){return"Tab"===(null==e?void 0:e.key)||9===(null==e?void 0:e.keyCode)},d=function(e){return l(e)&&!e.shiftKey},f=function(e){return l(e)&&e.shiftKey},b=function(e){return setTimeout(e,0)},v=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];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},y=[];e.createFocusTrap=function(e,n){var r,o=(null==n?void 0:n.document)||document,s=(null==n?void 0:n.trapStack)||y,h=i({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,delayReturnFocus:!0,isolateSubtrees:!1,isKeyForward:d,isKeyBackward:f},n),m={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},w=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},g=function(e,t){var n="function"==typeof(null==t?void 0:t.composedPath)?t.composedPath():void 0;return m.containerGroups.findIndex((function(t){var a=t.container,r=t.tabbableNodes;return a.contains(e)||(null==n?void 0:n.includes(a))||r.find((function(t){return t===e}))}))},T=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.hasFallback,a=void 0!==n&&n,r=t.params,i=void 0===r?[]:r,s=h[e];if("function"==typeof s&&(s=s.apply(void 0,u(i))),!0===s&&(s=void 0),!s){if(void 0===s||!1===s)return s;throw new Error("`".concat(e,"` was specified but was not a node, or did not return a node"))}var c=s;if("string"==typeof s){try{c=o.querySelector(s)}catch(t){throw new Error("`".concat(e,'` appears to be an invalid selector; error="').concat(t.message,'"'))}if(!c&&!a)throw new Error("`".concat(e,"` as selector refers to no known node"))}return c},S=function(e){var t=e.activeElement;return t?t.shadowRoot&&null!==t.shadowRoot.activeElement?S(t.shadowRoot):t:null},F=function(){var e=T("initialFocus",{hasFallback:!0});if(!1===e)return!1;if(void 0===e||e&&!t.isFocusable(e,h.tabbableOptions)){var n=S(o);if(g(n)>=0)e=n;else{var a=m.tabbableGroups[0];e=a&&a.firstTabbableNode||T("fallbackFocus")}}else null===e&&(e=T("fallbackFocus"));if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},N=function(){if(m.containerGroups=m.containers.map((function(e){var n=t.tabbable(e,h.tabbableOptions),a=t.focusable(e,h.tabbableOptions),r=n.length>0?n[0]:void 0,o=n.length>0?n[n.length-1]:void 0,i=a.find((function(e){return t.isTabbable(e)})),u=a.slice().reverse().find((function(e){return t.isTabbable(e)})),s=!!n.find((function(e){return t.getTabIndex(e)>0}));return{container:e,tabbableNodes:n,focusableNodes:a,posTabIndexesFound:s,firstTabbableNode:r,lastTabbableNode:o,firstDomTabbableNode:i,lastDomTabbableNode:u,nextTabbableNode:function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=n.indexOf(e);return o<0?r?a.slice(a.indexOf(e)+1).find((function(e){return t.isTabbable(e)})):a.slice(0,a.indexOf(e)).reverse().find((function(e){return t.isTabbable(e)})):n[o+(r?1:-1)]}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.tabbableGroups.length<=0&&!T("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(m.containerGroups.find((function(e){return e.posTabIndexesFound}))&&m.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.")},E=function(e){!1!==e&&e!==S(document)&&(e&&e.focus?(e.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=e,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(e)&&e.select()):E(F()))},O=function(e){var t=T("setReturnFocus",{params:[e]});return t||!1!==t&&e},P=function(e){var n=e.target,a=e.event,r=e.isBackward,o=void 0!==r&&r;n=n||p(a),N();var i=null;if(m.tabbableGroups.length>0){var u=g(n,a),s=u>=0?m.containerGroups[u]:void 0;if(u<0)i=o?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(o){var c=m.tabbableGroups.findIndex((function(e){var t=e.firstTabbableNode;return n===t}));if(c<0&&(s.container===n||t.isFocusable(n,h.tabbableOptions)&&!t.isTabbable(n,h.tabbableOptions)&&!s.nextTabbableNode(n,!1))&&(c=u),c>=0){var d=0===c?m.tabbableGroups.length-1:c-1,f=m.tabbableGroups[d];i=t.getTabIndex(n)>=0?f.lastTabbableNode:f.lastDomTabbableNode}else l(a)||(i=s.nextTabbableNode(n,!1))}else{var b=m.tabbableGroups.findIndex((function(e){var t=e.lastTabbableNode;return n===t}));if(b<0&&(s.container===n||t.isFocusable(n,h.tabbableOptions)&&!t.isTabbable(n,h.tabbableOptions)&&!s.nextTabbableNode(n))&&(b=u),b>=0){var v=b===m.tabbableGroups.length-1?0:b+1,y=m.tabbableGroups[v];i=t.getTabIndex(n)>=0?y.firstTabbableNode:y.firstDomTabbableNode}else l(a)||(i=s.nextTabbableNode(n))}}else i=T("fallbackFocus");return i},k=function(e){var t=p(e);g(t,e)>=0||(v(h.clickOutsideDeactivates,e)?r.deactivate({returnFocus:h.returnFocusOnDeactivate}):v(h.allowOutsideClick,e)||e.preventDefault())},I=function(e){var n=p(e),a=g(n,e)>=0;if(a||n instanceof Document)a&&(m.mostRecentlyFocusedNode=n);else{var r;e.stopImmediatePropagation();var o=!0;if(m.mostRecentlyFocusedNode)if(t.getTabIndex(m.mostRecentlyFocusedNode)>0){var i=g(m.mostRecentlyFocusedNode),u=m.containerGroups[i].tabbableNodes;if(u.length>0){var s=u.findIndex((function(e){return e===m.mostRecentlyFocusedNode}));s>=0&&(h.isKeyForward(m.recentNavEvent)?s+1<u.length&&(r=u[s+1],o=!1):s-1>=0&&(r=u[s-1],o=!1))}}else m.containerGroups.some((function(e){return e.tabbableNodes.some((function(e){return t.getTabIndex(e)>0}))}))||(o=!1);else o=!1;o&&(r=P({target:m.mostRecentlyFocusedNode,isBackward:h.isKeyBackward(m.recentNavEvent)})),E(r||(m.mostRecentlyFocusedNode||F()))}m.recentNavEvent=void 0},A=function(e){(h.isKeyForward(e)||h.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];m.recentNavEvent=e;var n=P({event:e,isBackward:t});n&&(l(e)&&e.preventDefault(),E(n))}(e,h.isKeyBackward(e))},R=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===v(h.escapeDeactivates,e)||(e.preventDefault(),r.deactivate())},x=function(e){var t=p(e);g(t,e)>=0||v(h.clickOutsideDeactivates,e)||v(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},D=function(){var e;if(m.active)return c.activateTrap(s,r),h.delayInitialFocus?e=new Promise((function(e){m.delayInitialFocusTimer=b((function(){E(F()),e()}))})):E(F()),o.addEventListener("focusin",I,!0),o.addEventListener("mousedown",k,{capture:!0,passive:!1}),o.addEventListener("touchstart",k,{capture:!0,passive:!1}),o.addEventListener("click",x,{capture:!0,passive:!1}),o.addEventListener("keydown",A,{capture:!0,passive:!1}),o.addEventListener("keydown",R),e},j=function(){if(m.active)return o.removeEventListener("focusin",I,!0),o.removeEventListener("mousedown",k,!0),o.removeEventListener("touchstart",k,!0),o.removeEventListener("click",x,!0),o.removeEventListener("keydown",A,!0),o.removeEventListener("keydown",R),r},G="undefined"!=typeof window&&"MutationObserver"in window?new MutationObserver((function(e){var t=m.mostRecentlyFocusedNode;if(t&&(e.some((function(e){return Array.from(e.removedNodes).some((function(e){return e===t||"function"==typeof e.contains&&e.contains(t)}))}))&&m.containers.some((function(e){return null==e?void 0:e.isConnected})))){N();var n=F();E(n)}})):void 0,_=function(){G&&(G.disconnect(),m.active&&!m.paused&&m.containers.map((function(e){G.observe(e,{subtree:!0,childList:!0})})))};return r={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t,n=w(e,"onActivate"),a=w(e,"onPostActivate"),i=w(e,"checkCanFocusTrap"),u=c.getActiveTrap(s),l=!1;u&&!u.paused&&(null===(t=u._setSubtreeIsolation)||void 0===t||t.call(u,!1),l=!0);try{i||N(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=S(o),null==n||n({trap:r});var d=function(){i&&N();var e=function(){r._setSubtreeIsolation(!0),_(),null==a||a({trap:r})},t=D();t?t.then(e):e()};if(i)return i(m.containers.concat()).then(d,d),this;d()}catch(e){var f;if(u===c.getActiveTrap(s)&&l)null===(f=u._setSubtreeIsolation)||void 0===f||f.call(u,!0);throw e}return this},deactivate:function(e){if(!m.active)return this;var t=i({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,m.paused||r._setSubtreeIsolation(!1),m.alreadySilent.clear(),j(),m.active=!1,m.paused=!1,_(),c.deactivateTrap(s,r);var n=w(t,"onDeactivate"),a=w(t,"onPostDeactivate"),o=w(t,"checkCanReturnFocus"),u=w(t,"delayReturnFocus"),l=w(t,"returnFocus","returnFocusOnDeactivate");null==n||n({trap:r});var d=function(){l&&E(O(m.nodeFocusedBeforeActivation)),null==a||a({trap:r})},f=function(){u&&l?b(d):d()};return l&&o?(o(O(m.nodeFocusedBeforeActivation)).then(f,f),this):(f(),this)},pause:function(e){return m.active?(m.manuallyPaused=!0,this._setPausedState(!0,e)):this},unpause:function(e){return m.active?(m.manuallyPaused=!1,s[s.length-1]!==this?this:this._setPausedState(!1,e)):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?o.querySelector(e):e})),h.isolateSubtrees&&function(e){m.active&&!m.paused&&r._setSubtreeIsolation(!1),m.adjacentElements.clear(),m.alreadySilent.clear();var t,n=new Set,o=new Set,i=a(e);try{for(i.s();!(t=i.n()).done;){var u=t.value;n.add(u);for(var s="undefined"!=typeof ShadowRoot&&u.getRootNode()instanceof ShadowRoot,c=u;c;){n.add(c);var l=c.parentElement,d=[];l?d=l.children:!l&&s&&(d=c.getRootNode().children,l=c.getRootNode().host,s="undefined"!=typeof ShadowRoot&&l.getRootNode()instanceof ShadowRoot);var f,b=a(d);try{for(b.s();!(f=b.n()).done;){var v=f.value;o.add(v)}}catch(e){b.e(e)}finally{b.f()}c=l}}}catch(e){i.e(e)}finally{i.f()}n.forEach((function(e){o.delete(e)})),m.adjacentElements=o}(m.containers),m.active&&(N(),m.paused||r._setSubtreeIsolation(!0)),_(),this}},Object.defineProperties(r,{_isManuallyPaused:{value:function(){return m.manuallyPaused}},_setPausedState:{value:function(e,t){if(m.paused===e)return this;if(m.paused=e,e){var n=w(t,"onPause"),a=w(t,"onPostPause");null==n||n({trap:r}),j(),r._setSubtreeIsolation(!1),_(),null==a||a({trap:r})}else{var o=w(t,"onUnpause"),i=w(t,"onPostUnpause");null==o||o({trap:r});!function(){N();var e=function(){r._setSubtreeIsolation(!0),_(),null==i||i({trap:r})},t=D();t?t.then(e):e()}()}return this}},_setSubtreeIsolation:{value:function(e){h.isolateSubtrees&&m.adjacentElements.forEach((function(t){var n;if(e)if("aria-hidden"===h.isolateSubtrees)"true"!==t.ariaHidden&&"true"!==(null===(n=t.getAttribute("aria-hidden"))||void 0===n?void 0:n.toLowerCase())||m.alreadySilent.add(t),t.setAttribute("aria-hidden","true");else(t.inert||t.hasAttribute("inert"))&&m.alreadySilent.add(t),t.setAttribute("inert",!0);else if(m.alreadySilent.has(t));else if("aria-hidden"===h.isolateSubtrees)t.removeAttribute("aria-hidden");else t.removeAttribute("inert")}))}}}),r.updateContainerElements(e),r}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "focus-trap",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.2",
|
|
4
4
|
"description": "Trap focus within a DOM node.",
|
|
5
5
|
"main": "dist/focus-trap.js",
|
|
6
6
|
"module": "dist/focus-trap.esm.js",
|
|
@@ -65,18 +65,18 @@
|
|
|
65
65
|
},
|
|
66
66
|
"homepage": "https://github.com/focus-trap/focus-trap#readme",
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"tabbable": "^6.
|
|
68
|
+
"tabbable": "^6.5.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@babel/cli": "^7.
|
|
72
|
-
"@babel/core": "^7.29.
|
|
73
|
-
"@babel/eslint-parser": "^7.
|
|
74
|
-
"@babel/eslint-plugin": "^7.
|
|
75
|
-
"@babel/preset-env": "^7.29.
|
|
71
|
+
"@babel/cli": "^7.29.7",
|
|
72
|
+
"@babel/core": "^7.29.7",
|
|
73
|
+
"@babel/eslint-parser": "^7.29.7",
|
|
74
|
+
"@babel/eslint-plugin": "^7.29.7",
|
|
75
|
+
"@babel/preset-env": "^7.29.7",
|
|
76
76
|
"@changesets/cli": "^2.31.0",
|
|
77
77
|
"@eslint/js": "^9.39.2",
|
|
78
|
-
"@rollup/plugin-babel": "^7.
|
|
79
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
78
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
79
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
80
80
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
81
81
|
"@rollup/plugin-replace": "^6.0.3",
|
|
82
82
|
"@rollup/plugin-terser": "^1.0.0",
|
|
@@ -85,20 +85,20 @@
|
|
|
85
85
|
"@testing-library/jest-dom": "^6.9.1",
|
|
86
86
|
"@testing-library/user-event": "^14.6.1",
|
|
87
87
|
"@types/jest": "^30.0.0",
|
|
88
|
-
"@types/jquery": "^4.0.
|
|
89
|
-
"@types/node": "^25.
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
91
|
-
"@typescript-eslint/parser": "^8.
|
|
88
|
+
"@types/jquery": "^4.0.1",
|
|
89
|
+
"@types/node": "^25.9.3",
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
91
|
+
"@typescript-eslint/parser": "^8.61.0",
|
|
92
92
|
"all-contributors-cli": "^6.26.1",
|
|
93
93
|
"babel-jest": "^30.4.1",
|
|
94
94
|
"babel-loader": "^10.1.1",
|
|
95
95
|
"cross-env": "^10.1.0",
|
|
96
|
-
"cypress": "^15.
|
|
96
|
+
"cypress": "^15.17.0",
|
|
97
97
|
"cypress-plugin-tab": "^1.0.5",
|
|
98
98
|
"eslint": "^9.39.2",
|
|
99
99
|
"eslint-config-prettier": "^10.1.8",
|
|
100
|
-
"eslint-import-resolver-node": "^0.
|
|
101
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
100
|
+
"eslint-import-resolver-node": "^0.4.0",
|
|
101
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
102
102
|
"eslint-plugin-cypress": "^6.4.1",
|
|
103
103
|
"eslint-plugin-import": "^2.32.0",
|
|
104
104
|
"eslint-plugin-jest": "^29.15.2",
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"jest-environment-jsdom": "^30.4.1",
|
|
110
110
|
"jest-watch-typeahead": "^3.0.1",
|
|
111
111
|
"onchange": "^7.1.0",
|
|
112
|
-
"prettier": "^3.8.
|
|
113
|
-
"rollup": "^4.
|
|
112
|
+
"prettier": "^3.8.4",
|
|
113
|
+
"rollup": "^4.62.0",
|
|
114
114
|
"rollup-plugin-livereload": "^2.0.5",
|
|
115
115
|
"rollup-plugin-serve": "^3.0.0",
|
|
116
|
-
"start-server-and-test": "^3.0.
|
|
116
|
+
"start-server-and-test": "^3.0.9",
|
|
117
117
|
"typescript": "^6.0.3"
|
|
118
118
|
}
|
|
119
119
|
}
|