focus-trap 7.3.0 → 7.3.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - a00cfa5: Bump tabbable to v6.1.1 for JSDom fixes
8
+
3
9
  ## 7.3.0
4
10
 
5
11
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
3
3
  * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
4
4
  */
5
5
  import { tabbable, focusable, isTabbable, isFocusable } from 'tabbable';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
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,isFocusable as r}from"tabbable";function a(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 o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(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 c=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)},u=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},y=[],h=function(a,i){var h,m=(null==i?void 0:i.document)||document,g=(null==i?void 0:i.trapStack)||y,w=o({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]:w[n||t]},k=function(e){return O.containerGroups.findIndex((function(t){var n=t.container,r=t.tabbableNodes;return n.contains(e)||r.find((function(t){return t===e}))}))},E=function(e){var t=w[e];if("function"==typeof t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];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 o=t;if("string"==typeof t&&!(o=m.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},N=function(){var e=E("initialFocus");if(!1===e)return!1;if(void 0===e)if(k(m.activeElement)>=0)e=m.activeElement;else{var t=O.tabbableGroups[0];e=t&&t.firstTabbableNode||E("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(O.containerGroups=O.containers.map((function(r){var a=e(r,w.tabbableOptions),o=t(r,w.tabbableOptions);return{container:r,tabbableNodes:a,focusableNodes:o,firstTabbableNode:a.length>0?a[0]:null,lastTabbableNode:a.length>0?a[a.length-1]:null,nextTabbableNode:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=o.findIndex((function(t){return t===e}));if(!(r<0))return t?o.slice(r+1).find((function(e){return n(e,w.tabbableOptions)})):o.slice(0,r).reverse().find((function(e){return n(e,w.tabbableOptions)}))}}})),O.tabbableGroups=O.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),O.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")},D=function e(t){!1!==t&&t!==m.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!w.preventScroll}),O.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(N()))},G=function(e){var t=E("setReturnFocus",e);return t||!1!==t&&e},P=function(e){var t=p(e);k(t)>=0||(d(w.clickOutsideDeactivates,e)?h.deactivate({returnFocus:w.returnFocusOnDeactivate}):d(w.allowOutsideClick,e)||e.preventDefault())},j=function(e){var t=p(e),n=k(t)>=0;n||t instanceof Document?n&&(O.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),D(O.mostRecentlyFocusedNode||N()))},C=function(e){if(!(t=e,"Escape"!==t.key&&"Esc"!==t.key&&27!==t.keyCode||!1===d(w.escapeDeactivates,e)))return e.preventDefault(),void h.deactivate();var t;(w.isKeyForward(e)||w.isKeyBackward(e))&&function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=p(e);T();var o=null;if(O.tabbableGroups.length>0){var i=k(a),c=i>=0?O.containerGroups[i]:void 0;if(i<0)o=t?O.tabbableGroups[O.tabbableGroups.length-1].lastTabbableNode:O.tabbableGroups[0].firstTabbableNode;else if(t){var u=v(O.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(u<0&&(c.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!c.nextTabbableNode(a,!1))&&(u=i),u>=0){var l=0===u?O.tabbableGroups.length-1:u-1;o=O.tabbableGroups[l].lastTabbableNode}else s(e)||(o=c.nextTabbableNode(a,!1))}else{var b=v(O.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(c.container===a||r(a,w.tabbableOptions)&&!n(a,w.tabbableOptions)&&!c.nextTabbableNode(a))&&(b=i),b>=0){var f=b===O.tabbableGroups.length-1?0:b+1;o=O.tabbableGroups[f].firstTabbableNode}else s(e)||(o=c.nextTabbableNode(a))}}else o=E("fallbackFocus");o&&(s(e)&&e.preventDefault(),D(o))}(e,w.isKeyBackward(e))},L=function(e){var t=p(e);k(t)>=0||d(w.clickOutsideDeactivates,e)||d(w.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},x=function(){if(O.active)return c(g,h),O.delayInitialFocusTimer=w.delayInitialFocus?f((function(){D(N())})):D(N()),m.addEventListener("focusin",j,!0),m.addEventListener("mousedown",P,{capture:!0,passive:!1}),m.addEventListener("touchstart",P,{capture:!0,passive:!1}),m.addEventListener("click",L,{capture:!0,passive:!1}),m.addEventListener("keydown",C,{capture:!0,passive:!1}),h},I=function(){if(O.active)return m.removeEventListener("focusin",j,!0),m.removeEventListener("mousedown",P,!0),m.removeEventListener("touchstart",P,!0),m.removeEventListener("click",L,!0),m.removeEventListener("keydown",C,!0),h};return(h={get active(){return O.active},get paused(){return O.paused},activate:function(e){if(O.active)return this;var t=F(e,"onActivate"),n=F(e,"onPostActivate"),r=F(e,"checkCanFocusTrap");r||T(),O.active=!0,O.paused=!1,O.nodeFocusedBeforeActivation=m.activeElement,t&&t();var a=function(){r&&T(),x(),n&&n()};return r?(r(O.containers.concat()).then(a,a),this):(a(),this)},deactivate:function(e){if(!O.active)return this;var t=o({onDeactivate:w.onDeactivate,onPostDeactivate:w.onPostDeactivate,checkCanReturnFocus:w.checkCanReturnFocus},e);clearTimeout(O.delayInitialFocusTimer),O.delayInitialFocusTimer=void 0,I(),O.active=!1,O.paused=!1,u(g,h);var n=F(t,"onDeactivate"),r=F(t,"onPostDeactivate"),a=F(t,"checkCanReturnFocus"),i=F(t,"returnFocus","returnFocusOnDeactivate");n&&n();var c=function(){f((function(){i&&D(G(O.nodeFocusedBeforeActivation)),r&&r()}))};return i&&a?(a(G(O.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return O.paused||!O.active||(O.paused=!0,I()),this},unpause:function(){return O.paused&&O.active?(O.paused=!1,T(),x(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return O.containers=t.map((function(e){return"string"==typeof e?m.querySelector(e):e})),O.active&&T(),this}}).updateContainerElements(a),h};export{h as createFocusTrap};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
3
3
  * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
4
4
  */
5
5
  'use strict';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
3
3
  * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
4
4
  */
5
5
  "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;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?t(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(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 a=n.call(e,t||"default");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:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r=function(e,t){if(e.length>0){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;a<t;a++)n[a-1]=arguments[a];return"function"==typeof e?e.apply(void 0,n):e},f=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},v=[];exports.createFocusTrap=function(t,a){var d,p=(null==a?void 0:a.document)||document,y=(null==a?void 0:a.trapStack)||v,h=n({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:u,isKeyBackward:c},a),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}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 o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(t){var n=e.tabbable(t,h.tabbableOptions),a=e.focusable(t,h.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,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(t){return e.isTabbable(t,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.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")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=f(e);w(t)>=0||(b(h.clickOutsideDeactivates,e)?d.deactivate({returnFocus:h.returnFocusOnDeactivate}):b(h.allowOutsideClick,e)||e.preventDefault())},D=function(e){var t=f(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},P=function(t){if(!(n=t,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===b(h.escapeDeactivates,t)))return t.preventDefault(),void d.deactivate();var n;(h.isKeyForward(t)||h.isKeyBackward(t))&&function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=f(t);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),u=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=l(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else i(t)||(r=u.nextTabbableNode(a,!1))}else{var b=l(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(b<0&&(u.container===a||e.isFocusable(a,h.tabbableOptions)&&!e.isTabbable(a,h.tabbableOptions)&&!u.nextTabbableNode(a))&&(b=o),b>=0){var v=b===m.tabbableGroups.length-1?0:b+1;r=m.tabbableGroups[v].firstTabbableNode}else i(t)||(r=u.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(i(t)&&t.preventDefault(),k(r))}(t,h.isKeyBackward(t))},G=function(e){var t=f(e);w(t)>=0||b(h.clickOutsideDeactivates,e)||b(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return r(y,d),m.delayInitialFocusTimer=h.delayInitialFocus?s((function(){k(F())})):k(F()),p.addEventListener("focusin",D,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",P,{capture:!0,passive:!1}),d},x=function(){if(m.active)return p.removeEventListener("focusin",D,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",P,!0),d};return(d={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,t&&t();var r=function(){a&&T(),j(),n&&n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=n({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,o(y,d);var a=g(t,"onDeactivate"),r=g(t,"onPostDeactivate"),i=g(t,"checkCanReturnFocus"),u=g(t,"returnFocus","returnFocusOnDeactivate");a&&a();var c=function(){s((function(){u&&k(E(m.nodeFocusedBeforeActivation)),r&&r()}))};return u&&i?(i(E(m.nodeFocusedBeforeActivation)).then(c,c),this):(c(),this)},pause:function(){return m.paused||!m.active||(m.paused=!0,x()),this},unpause:function(){return m.paused&&m.active?(m.paused=!1,T(),j(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(t),d};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
3
3
  * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
4
4
  */
5
5
  (function (global, factory) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * focus-trap 7.3.0
2
+ * focus-trap 7.3.1
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){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 a(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function r(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 a=n.call(e,t||"default");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:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(e,t){if(e.length>0){var n=e[e.length-1];n!==t&&n.pause()}var a=e.indexOf(t);-1===a||e.splice(a,1),e.push(t)},i=function(e,t){var n=e.indexOf(t);-1!==n&&e.splice(n,1),e.length>0&&e[e.length-1].unpause()},u=function(e){return"Tab"===e.key||9===e.keyCode},c=function(e){return u(e)&&!e.shiftKey},s=function(e){return u(e)&&e.shiftKey},l=function(e){return setTimeout(e,0)},b=function(e,t){var n=-1;return e.every((function(e,a){return!t(e)||(n=a,!1)})),n},f=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},d=function(e){return e.target.shadowRoot&&"function"==typeof e.composedPath?e.composedPath()[0]:e.target},v=[];e.createFocusTrap=function(e,n){var r,p=(null==n?void 0:n.document)||document,y=(null==n?void 0:n.trapStack)||v,h=a({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:c,isKeyBackward:s},n),m={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,delayInitialFocusTimer:void 0},g=function(e,t,n){return e&&void 0!==e[t]?e[t]:h[n||t]},w=function(e){return m.containerGroups.findIndex((function(t){var n=t.container,a=t.tabbableNodes;return n.contains(e)||a.find((function(t){return t===e}))}))},O=function(e){var t=h[e];if("function"==typeof t){for(var n=arguments.length,a=new Array(n>1?n-1:0),r=1;r<n;r++)a[r-1]=arguments[r];t=t.apply(void 0,a)}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 o=t;if("string"==typeof t&&!(o=p.querySelector(t)))throw new Error("`".concat(e,"` as selector refers to no known node"));return o},F=function(){var e=O("initialFocus");if(!1===e)return!1;if(void 0===e)if(w(p.activeElement)>=0)e=p.activeElement;else{var t=m.tabbableGroups[0];e=t&&t.firstTabbableNode||O("fallbackFocus")}if(!e)throw new Error("Your focus-trap needs to have at least one focusable element");return e},T=function(){if(m.containerGroups=m.containers.map((function(e){var n=t.tabbable(e,h.tabbableOptions),a=t.focusable(e,h.tabbableOptions);return{container:e,tabbableNodes:n,focusableNodes:a,firstTabbableNode:n.length>0?n[0]:null,lastTabbableNode:n.length>0?n[n.length-1]:null,nextTabbableNode:function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=a.findIndex((function(t){return t===e}));if(!(r<0))return n?a.slice(r+1).find((function(e){return t.isTabbable(e,h.tabbableOptions)})):a.slice(0,r).reverse().find((function(e){return t.isTabbable(e,h.tabbableOptions)}))}}})),m.tabbableGroups=m.containerGroups.filter((function(e){return e.tabbableNodes.length>0})),m.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")},k=function e(t){!1!==t&&t!==p.activeElement&&(t&&t.focus?(t.focus({preventScroll:!!h.preventScroll}),m.mostRecentlyFocusedNode=t,function(e){return e.tagName&&"input"===e.tagName.toLowerCase()&&"function"==typeof e.select}(t)&&t.select()):e(F()))},E=function(e){var t=O("setReturnFocus",e);return t||!1!==t&&e},N=function(e){var t=d(e);w(t)>=0||(f(h.clickOutsideDeactivates,e)?r.deactivate({returnFocus:h.returnFocusOnDeactivate}):f(h.allowOutsideClick,e)||e.preventDefault())},D=function(e){var t=d(e),n=w(t)>=0;n||t instanceof Document?n&&(m.mostRecentlyFocusedNode=t):(e.stopImmediatePropagation(),k(m.mostRecentlyFocusedNode||F()))},P=function(e){if(!(n=e,"Escape"!==n.key&&"Esc"!==n.key&&27!==n.keyCode||!1===f(h.escapeDeactivates,e)))return e.preventDefault(),void r.deactivate();var n;(h.isKeyForward(e)||h.isKeyBackward(e))&&function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=d(e);T();var r=null;if(m.tabbableGroups.length>0){var o=w(a),i=o>=0?m.containerGroups[o]:void 0;if(o<0)r=n?m.tabbableGroups[m.tabbableGroups.length-1].lastTabbableNode:m.tabbableGroups[0].firstTabbableNode;else if(n){var c=b(m.tabbableGroups,(function(e){var t=e.firstTabbableNode;return a===t}));if(c<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a,!1))&&(c=o),c>=0){var s=0===c?m.tabbableGroups.length-1:c-1;r=m.tabbableGroups[s].lastTabbableNode}else u(e)||(r=i.nextTabbableNode(a,!1))}else{var l=b(m.tabbableGroups,(function(e){var t=e.lastTabbableNode;return a===t}));if(l<0&&(i.container===a||t.isFocusable(a,h.tabbableOptions)&&!t.isTabbable(a,h.tabbableOptions)&&!i.nextTabbableNode(a))&&(l=o),l>=0){var f=l===m.tabbableGroups.length-1?0:l+1;r=m.tabbableGroups[f].firstTabbableNode}else u(e)||(r=i.nextTabbableNode(a))}}else r=O("fallbackFocus");r&&(u(e)&&e.preventDefault(),k(r))}(e,h.isKeyBackward(e))},G=function(e){var t=d(e);w(t)>=0||f(h.clickOutsideDeactivates,e)||f(h.allowOutsideClick,e)||(e.preventDefault(),e.stopImmediatePropagation())},j=function(){if(m.active)return o(y,r),m.delayInitialFocusTimer=h.delayInitialFocus?l((function(){k(F())})):k(F()),p.addEventListener("focusin",D,!0),p.addEventListener("mousedown",N,{capture:!0,passive:!1}),p.addEventListener("touchstart",N,{capture:!0,passive:!1}),p.addEventListener("click",G,{capture:!0,passive:!1}),p.addEventListener("keydown",P,{capture:!0,passive:!1}),r},x=function(){if(m.active)return p.removeEventListener("focusin",D,!0),p.removeEventListener("mousedown",N,!0),p.removeEventListener("touchstart",N,!0),p.removeEventListener("click",G,!0),p.removeEventListener("keydown",P,!0),r};return(r={get active(){return m.active},get paused(){return m.paused},activate:function(e){if(m.active)return this;var t=g(e,"onActivate"),n=g(e,"onPostActivate"),a=g(e,"checkCanFocusTrap");a||T(),m.active=!0,m.paused=!1,m.nodeFocusedBeforeActivation=p.activeElement,t&&t();var r=function(){a&&T(),j(),n&&n()};return a?(a(m.containers.concat()).then(r,r),this):(r(),this)},deactivate:function(e){if(!m.active)return this;var t=a({onDeactivate:h.onDeactivate,onPostDeactivate:h.onPostDeactivate,checkCanReturnFocus:h.checkCanReturnFocus},e);clearTimeout(m.delayInitialFocusTimer),m.delayInitialFocusTimer=void 0,x(),m.active=!1,m.paused=!1,i(y,r);var n=g(t,"onDeactivate"),o=g(t,"onPostDeactivate"),u=g(t,"checkCanReturnFocus"),c=g(t,"returnFocus","returnFocusOnDeactivate");n&&n();var s=function(){l((function(){c&&k(E(m.nodeFocusedBeforeActivation)),o&&o()}))};return c&&u?(u(E(m.nodeFocusedBeforeActivation)).then(s,s),this):(s(),this)},pause:function(){return m.paused||!m.active||(m.paused=!0,x()),this},unpause:function(){return m.paused&&m.active?(m.paused=!1,T(),j(),this):this},updateContainerElements:function(e){var t=[].concat(e).filter(Boolean);return m.containers=t.map((function(e){return"string"==typeof e?p.querySelector(e):e})),m.active&&T(),this}}).updateContainerElements(e),r},Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "focus-trap",
3
- "version": "7.3.0",
3
+ "version": "7.3.1",
4
4
  "description": "Trap focus within a DOM node.",
5
5
  "main": "dist/focus-trap.js",
6
6
  "module": "dist/focus-trap.esm.js",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "homepage": "https://github.com/focus-trap/focus-trap#readme",
65
65
  "dependencies": {
66
- "tabbable": "^6.1.0"
66
+ "tabbable": "^6.1.1"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@babel/cli": "^7.20.7",