@content-blocks/js 0.7.1 → 0.7.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.
Files changed (113) hide show
  1. package/dist/cjs/content-accordion_11.cjs.entry.js +45 -1545
  2. package/dist/cjs/content-accordion_11.cjs.entry.js.map +1 -1
  3. package/dist/cjs/content-blocks.cjs.js +1 -1
  4. package/dist/cjs/content-carousel.cjs.entry.js +6 -5
  5. package/dist/cjs/content-carousel.cjs.entry.js.map +1 -1
  6. package/dist/cjs/content-navigation-block.cjs.entry.js +41 -24
  7. package/dist/cjs/content-navigation-block.cjs.entry.js.map +1 -1
  8. package/dist/cjs/focus-trap.esm-a1e3774c.js +1509 -0
  9. package/dist/cjs/focus-trap.esm-a1e3774c.js.map +1 -0
  10. package/dist/cjs/index-f38d389e.js +5224 -0
  11. package/dist/cjs/index-f38d389e.js.map +1 -0
  12. package/dist/cjs/loader.cjs.js +1 -1
  13. package/dist/cjs/{swiper-4fade542.js → swiper-e5a68ae2.js} +68 -469
  14. package/dist/cjs/swiper-e5a68ae2.js.map +1 -0
  15. package/dist/cjs/utils-c04e978e.js +457 -0
  16. package/dist/cjs/utils-c04e978e.js.map +1 -0
  17. package/dist/cjs/window-resize-service-ac5c2012.js.map +1 -1
  18. package/dist/collection/components/content-carousel/content-carousel.js +5 -4
  19. package/dist/collection/components/content-carousel/content-carousel.js.map +1 -1
  20. package/dist/collection/components/content-navigation-block/content-navigation-block.css +55 -13
  21. package/dist/collection/components/content-navigation-block/content-navigation-block.js +51 -24
  22. package/dist/collection/components/content-navigation-block/content-navigation-block.js.map +1 -1
  23. package/dist/collection/components/content-overlay/content-overlay.css +11 -6
  24. package/dist/collection/components/content-overlay/content-overlay.js +69 -34
  25. package/dist/collection/components/content-overlay/content-overlay.js.map +1 -1
  26. package/dist/collection/elements/content-image/content-image.js +4 -4
  27. package/dist/collection/elements/content-image/content-image.js.map +1 -1
  28. package/dist/collection/formatters/content-grid-formatter/content-grid-formatter.css +4 -3
  29. package/dist/collection/formatters/content-grid-formatter/content-grid-formatter.js +37 -0
  30. package/dist/collection/formatters/content-grid-formatter/content-grid-formatter.js.map +1 -1
  31. package/dist/collection/formatters/content-spacer/content-spacer.css +3 -4
  32. package/dist/collection/formatters/content-spacer/content-spacer.js +13 -5
  33. package/dist/collection/formatters/content-spacer/content-spacer.js.map +1 -1
  34. package/dist/collection/services/window-resize-service.js.map +1 -1
  35. package/dist/collection/stories/ContentNavigationBlock.stories.js +1 -1
  36. package/dist/collection/stories/ContentNavigationBlock.stories.js.map +1 -1
  37. package/dist/collection/stories/ContentTextBlock.stories.js +5 -5
  38. package/dist/collection/stories/ContentTextBlock.stories.js.map +1 -1
  39. package/dist/collection/stories/FullPageExample.stories.js +164 -214
  40. package/dist/collection/stories/FullPageExample.stories.js.map +1 -1
  41. package/dist/components/content-carousel.js +5 -4
  42. package/dist/components/content-carousel.js.map +1 -1
  43. package/dist/components/content-grid-formatter2.js +9 -1
  44. package/dist/components/content-grid-formatter2.js.map +1 -1
  45. package/dist/components/content-image.js +4 -4
  46. package/dist/components/content-image.js.map +1 -1
  47. package/dist/components/content-navigation-block.js +48 -25
  48. package/dist/components/content-navigation-block.js.map +1 -1
  49. package/dist/components/content-overlay.js +32 -1538
  50. package/dist/components/content-overlay.js.map +1 -1
  51. package/dist/components/content-spacer.js +3 -3
  52. package/dist/components/content-spacer.js.map +1 -1
  53. package/dist/components/focus-trap.esm.js +1507 -0
  54. package/dist/components/focus-trap.esm.js.map +1 -0
  55. package/dist/components/index2.js +5200 -0
  56. package/dist/components/index2.js.map +1 -0
  57. package/dist/components/swiper.js +1 -402
  58. package/dist/components/swiper.js.map +1 -1
  59. package/dist/components/utils2.js +433 -0
  60. package/dist/components/utils2.js.map +1 -0
  61. package/dist/components/window-resize-service.js.map +1 -1
  62. package/dist/content-blocks/content-blocks.esm.js +1 -1
  63. package/dist/content-blocks/content-blocks.esm.js.map +1 -1
  64. package/dist/content-blocks/p-75ac85e9.js +2 -0
  65. package/dist/content-blocks/p-75ac85e9.js.map +1 -0
  66. package/dist/content-blocks/p-7ff352fe.entry.js +2 -0
  67. package/dist/content-blocks/p-7ff352fe.entry.js.map +1 -0
  68. package/dist/content-blocks/p-878dc806.js +10 -0
  69. package/dist/content-blocks/p-878dc806.js.map +1 -0
  70. package/dist/content-blocks/p-97c4ca9d.js +2 -0
  71. package/dist/content-blocks/p-97c4ca9d.js.map +1 -0
  72. package/dist/content-blocks/{p-271fb304.entry.js → p-cbc1dd73.entry.js} +2 -2
  73. package/dist/content-blocks/p-cbc1dd73.entry.js.map +1 -0
  74. package/dist/content-blocks/p-cfb4593f.js.map +1 -1
  75. package/dist/content-blocks/p-e2907508.js +2 -0
  76. package/dist/content-blocks/p-e2907508.js.map +1 -0
  77. package/dist/content-blocks/p-ef45f146.entry.js +2 -0
  78. package/dist/content-blocks/p-ef45f146.entry.js.map +1 -0
  79. package/dist/esm/content-accordion_11.entry.js +45 -1545
  80. package/dist/esm/content-accordion_11.entry.js.map +1 -1
  81. package/dist/esm/content-blocks.js +1 -1
  82. package/dist/esm/content-carousel.entry.js +6 -5
  83. package/dist/esm/content-carousel.entry.js.map +1 -1
  84. package/dist/esm/content-navigation-block.entry.js +41 -24
  85. package/dist/esm/content-navigation-block.entry.js.map +1 -1
  86. package/dist/esm/focus-trap.esm-49c9613c.js +1507 -0
  87. package/dist/esm/focus-trap.esm-49c9613c.js.map +1 -0
  88. package/dist/esm/index-d9f353de.js +5200 -0
  89. package/dist/esm/index-d9f353de.js.map +1 -0
  90. package/dist/esm/loader.js +1 -1
  91. package/dist/esm/{swiper-3e7be625.js → swiper-3394f7fd.js} +2 -403
  92. package/dist/esm/swiper-3394f7fd.js.map +1 -0
  93. package/dist/esm/utils-075121ec.js +433 -0
  94. package/dist/esm/utils-075121ec.js.map +1 -0
  95. package/dist/esm/window-resize-service-f40ec51c.js.map +1 -1
  96. package/dist/types/components/content-carousel/content-carousel.d.ts +3 -3
  97. package/dist/types/components/content-navigation-block/content-navigation-block.d.ts +11 -0
  98. package/dist/types/components/content-overlay/content-overlay.d.ts +9 -0
  99. package/dist/types/components.d.ts +34 -2
  100. package/dist/types/formatters/content-grid-formatter/content-grid-formatter.d.ts +8 -1
  101. package/dist/types/formatters/content-spacer/content-spacer.d.ts +2 -1
  102. package/dist/types/stories/ContentNavigationBlock.stories.d.ts +1 -3
  103. package/dist/types/stories/ContentTextBlock.stories.d.ts +1 -7
  104. package/package.json +2 -2
  105. package/dist/cjs/swiper-4fade542.js.map +0 -1
  106. package/dist/content-blocks/p-10819bfa.js +0 -2
  107. package/dist/content-blocks/p-10819bfa.js.map +0 -1
  108. package/dist/content-blocks/p-24657e66.entry.js +0 -10
  109. package/dist/content-blocks/p-24657e66.entry.js.map +0 -1
  110. package/dist/content-blocks/p-271fb304.entry.js.map +0 -1
  111. package/dist/content-blocks/p-6a177aef.entry.js +0 -2
  112. package/dist/content-blocks/p-6a177aef.entry.js.map +0 -1
  113. package/dist/esm/swiper-3e7be625.js.map +0 -1
@@ -0,0 +1,1507 @@
1
+ /*!
2
+ * tabbable 6.2.0
3
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
4
+ */
5
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
6
+ // `:not([inert], [inert] *)` (Feb 2023)
7
+ // CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
8
+ // the entire query to fail, resulting in no nodes found, which will break a lot
9
+ // of things... so we have to rely on JS to identify nodes inside an inert container
10
+ var candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable="false"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];
11
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
12
+ var NoElement = typeof Element === 'undefined';
13
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
14
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
15
+ var _element$getRootNode;
16
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
17
+ } : function (element) {
18
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
19
+ };
20
+
21
+ /**
22
+ * Determines if a node is inert or in an inert ancestor.
23
+ * @param {Element} [node]
24
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
25
+ * see if any of them are inert. If false, only `node` itself is considered.
26
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
27
+ * False if `node` is falsy.
28
+ */
29
+ var isInert = function isInert(node, lookUp) {
30
+ var _node$getAttribute;
31
+ if (lookUp === void 0) {
32
+ lookUp = true;
33
+ }
34
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
35
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
36
+ // if it's `null` (not specified) or 'false', it's an active element
37
+ var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
38
+ var inert = inertAtt === '' || inertAtt === 'true';
39
+
40
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
41
+ // if it weren't for `matches()` not being a function on shadow roots; the following
42
+ // code works for any kind of node
43
+ // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
44
+ // so it likely would not support `:is([inert] *)` either...
45
+ var result = inert || lookUp && node && isInert(node.parentNode); // recursive
46
+
47
+ return result;
48
+ };
49
+
50
+ /**
51
+ * Determines if a node's content is editable.
52
+ * @param {Element} [node]
53
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
54
+ */
55
+ var isContentEditable = function isContentEditable(node) {
56
+ var _node$getAttribute2;
57
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
58
+ // to use the attribute directly to check for this, which can either be empty or 'true';
59
+ // if it's `null` (not specified) or 'false', it's a non-editable element
60
+ var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
61
+ return attValue === '' || attValue === 'true';
62
+ };
63
+
64
+ /**
65
+ * @param {Element} el container to check in
66
+ * @param {boolean} includeContainer add container to check
67
+ * @param {(node: Element) => boolean} filter filter candidates
68
+ * @returns {Element[]}
69
+ */
70
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
71
+ // even if `includeContainer=false`, we still have to check it for inertness because
72
+ // if it's inert, all its children are inert
73
+ if (isInert(el)) {
74
+ return [];
75
+ }
76
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
77
+ if (includeContainer && matches.call(el, candidateSelector)) {
78
+ candidates.unshift(el);
79
+ }
80
+ candidates = candidates.filter(filter);
81
+ return candidates;
82
+ };
83
+
84
+ /**
85
+ * @callback GetShadowRoot
86
+ * @param {Element} element to check for shadow root
87
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
88
+ */
89
+
90
+ /**
91
+ * @callback ShadowRootFilter
92
+ * @param {Element} shadowHostNode the element which contains shadow content
93
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
94
+ */
95
+
96
+ /**
97
+ * @typedef {Object} CandidateScope
98
+ * @property {Element} scopeParent contains inner candidates
99
+ * @property {Element[]} candidates list of candidates found in the scope parent
100
+ */
101
+
102
+ /**
103
+ * @typedef {Object} IterativeOptions
104
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
105
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
106
+ * or a boolean stating if it has an undisclosed shadow root
107
+ * @property {(node: Element) => boolean} filter filter candidates
108
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
109
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
110
+ */
111
+
112
+ /**
113
+ * @param {Element[]} elements list of element containers to match candidates from
114
+ * @param {boolean} includeContainer add container list to check
115
+ * @param {IterativeOptions} options
116
+ * @returns {Array.<Element|CandidateScope>}
117
+ */
118
+ var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
119
+ var candidates = [];
120
+ var elementsToCheck = Array.from(elements);
121
+ while (elementsToCheck.length) {
122
+ var element = elementsToCheck.shift();
123
+ if (isInert(element, false)) {
124
+ // no need to look up since we're drilling down
125
+ // anything inside this container will also be inert
126
+ continue;
127
+ }
128
+ if (element.tagName === 'SLOT') {
129
+ // add shadow dom slot scope (slot itself cannot be focusable)
130
+ var assigned = element.assignedElements();
131
+ var content = assigned.length ? assigned : element.children;
132
+ var nestedCandidates = getCandidatesIteratively(content, true, options);
133
+ if (options.flatten) {
134
+ candidates.push.apply(candidates, nestedCandidates);
135
+ } else {
136
+ candidates.push({
137
+ scopeParent: element,
138
+ candidates: nestedCandidates
139
+ });
140
+ }
141
+ } else {
142
+ // check candidate element
143
+ var validCandidate = matches.call(element, candidateSelector);
144
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
145
+ candidates.push(element);
146
+ }
147
+
148
+ // iterate over shadow content if possible
149
+ var shadowRoot = element.shadowRoot ||
150
+ // check for an undisclosed shadow
151
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
152
+
153
+ // no inert look up because we're already drilling down and checking for inertness
154
+ // on the way down, so all containers to this root node should have already been
155
+ // vetted as non-inert
156
+ var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
157
+ if (shadowRoot && validShadowRoot) {
158
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
159
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
160
+ // child candidates found because they're likely slotted elements (elements that are
161
+ // children of the web component element (which has the shadow), in the light dom, but
162
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
163
+ // _after_ we return from this recursive call
164
+ var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
165
+ if (options.flatten) {
166
+ candidates.push.apply(candidates, _nestedCandidates);
167
+ } else {
168
+ candidates.push({
169
+ scopeParent: element,
170
+ candidates: _nestedCandidates
171
+ });
172
+ }
173
+ } else {
174
+ // there's not shadow so just dig into the element's (light dom) children
175
+ // __without__ giving the element special scope treatment
176
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
177
+ }
178
+ }
179
+ }
180
+ return candidates;
181
+ };
182
+
183
+ /**
184
+ * @private
185
+ * Determines if the node has an explicitly specified `tabindex` attribute.
186
+ * @param {HTMLElement} node
187
+ * @returns {boolean} True if so; false if not.
188
+ */
189
+ var hasTabIndex = function hasTabIndex(node) {
190
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
191
+ };
192
+
193
+ /**
194
+ * Determine the tab index of a given node.
195
+ * @param {HTMLElement} node
196
+ * @returns {number} Tab order (negative, 0, or positive number).
197
+ * @throws {Error} If `node` is falsy.
198
+ */
199
+ var getTabIndex = function getTabIndex(node) {
200
+ if (!node) {
201
+ throw new Error('No node provided');
202
+ }
203
+ if (node.tabIndex < 0) {
204
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
205
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
206
+ // yet they are still part of the regular tab order; in FF, they get a default
207
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
208
+ // order, consider their tab index to be 0.
209
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
210
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
211
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
212
+ return 0;
213
+ }
214
+ }
215
+ return node.tabIndex;
216
+ };
217
+
218
+ /**
219
+ * Determine the tab index of a given node __for sort order purposes__.
220
+ * @param {HTMLElement} node
221
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
222
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
223
+ * inserted into the correct sort position.
224
+ * @returns {number} Tab order (negative, 0, or positive number).
225
+ */
226
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
227
+ var tabIndex = getTabIndex(node);
228
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
229
+ return 0;
230
+ }
231
+ return tabIndex;
232
+ };
233
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
234
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
235
+ };
236
+ var isInput = function isInput(node) {
237
+ return node.tagName === 'INPUT';
238
+ };
239
+ var isHiddenInput = function isHiddenInput(node) {
240
+ return isInput(node) && node.type === 'hidden';
241
+ };
242
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
243
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
244
+ return child.tagName === 'SUMMARY';
245
+ });
246
+ return r;
247
+ };
248
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
249
+ for (var i = 0; i < nodes.length; i++) {
250
+ if (nodes[i].checked && nodes[i].form === form) {
251
+ return nodes[i];
252
+ }
253
+ }
254
+ };
255
+ var isTabbableRadio = function isTabbableRadio(node) {
256
+ if (!node.name) {
257
+ return true;
258
+ }
259
+ var radioScope = node.form || getRootNode(node);
260
+ var queryRadios = function queryRadios(name) {
261
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
262
+ };
263
+ var radioSet;
264
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
265
+ radioSet = queryRadios(window.CSS.escape(node.name));
266
+ } else {
267
+ try {
268
+ radioSet = queryRadios(node.name);
269
+ } catch (err) {
270
+ // eslint-disable-next-line no-console
271
+ console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
272
+ return false;
273
+ }
274
+ }
275
+ var checked = getCheckedRadio(radioSet, node.form);
276
+ return !checked || checked === node;
277
+ };
278
+ var isRadio = function isRadio(node) {
279
+ return isInput(node) && node.type === 'radio';
280
+ };
281
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
282
+ return isRadio(node) && !isTabbableRadio(node);
283
+ };
284
+
285
+ // determines if a node is ultimately attached to the window's document
286
+ var isNodeAttached = function isNodeAttached(node) {
287
+ var _nodeRoot;
288
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
289
+ // (but NOT _the_ document; see second 'If' comment below for more).
290
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
291
+ // is attached, and the one we need to check if it's in the document or not (because the
292
+ // shadow, and all nodes it contains, is never considered in the document since shadows
293
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
294
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
295
+ // visibility, including all the nodes it contains). The host could be any normal node,
296
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
297
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
298
+ // tested).
299
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
300
+ // that is attached (or find none) because the node might be in nested shadows...
301
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
302
+ // document (per the docs) and while it's a Document-type object, that document does not
303
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
304
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
305
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
306
+ // node is actually detached.
307
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
308
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
309
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
310
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
311
+ var nodeRoot = node && getRootNode(node);
312
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
313
+
314
+ // in some cases, a detached node will return itself as the root instead of a document or
315
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
316
+ var attached = false;
317
+ if (nodeRoot && nodeRoot !== node) {
318
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
319
+ attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
320
+ while (!attached && nodeRootHost) {
321
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
322
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
323
+ // which means we need to get the host's host and check if that parent host is contained
324
+ // in (i.e. attached to) the document
325
+ nodeRoot = getRootNode(nodeRootHost);
326
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
327
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
328
+ }
329
+ }
330
+ return attached;
331
+ };
332
+ var isZeroArea = function isZeroArea(node) {
333
+ var _node$getBoundingClie = node.getBoundingClientRect(),
334
+ width = _node$getBoundingClie.width,
335
+ height = _node$getBoundingClie.height;
336
+ return width === 0 && height === 0;
337
+ };
338
+ var isHidden = function isHidden(node, _ref) {
339
+ var displayCheck = _ref.displayCheck,
340
+ getShadowRoot = _ref.getShadowRoot;
341
+ // NOTE: visibility will be `undefined` if node is detached from the document
342
+ // (see notes about this further down), which means we will consider it visible
343
+ // (this is legacy behavior from a very long way back)
344
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
345
+ // _visibility_ check, not a _display_ check
346
+ if (getComputedStyle(node).visibility === 'hidden') {
347
+ return true;
348
+ }
349
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
350
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
351
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
352
+ return true;
353
+ }
354
+ if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
355
+ if (typeof getShadowRoot === 'function') {
356
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
357
+ // 'non-zero-area' fallback
358
+ var originalNode = node;
359
+ while (node) {
360
+ var parentElement = node.parentElement;
361
+ var rootNode = getRootNode(node);
362
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
363
+ ) {
364
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
365
+ // fall back to a non-zero-area test
366
+ return isZeroArea(node);
367
+ } else if (node.assignedSlot) {
368
+ // iterate up slot
369
+ node = node.assignedSlot;
370
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
371
+ // cross shadow boundary
372
+ node = rootNode.host;
373
+ } else {
374
+ // iterate up normal dom
375
+ node = parentElement;
376
+ }
377
+ }
378
+ node = originalNode;
379
+ }
380
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
381
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
382
+ // it might be a falsy value, which means shadow DOM support is disabled
383
+
384
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
385
+ // now we can just test to see if it would normally be visible or not, provided it's
386
+ // attached to the main document.
387
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
388
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
389
+
390
+ if (isNodeAttached(node)) {
391
+ // this works wherever the node is: if there's at least one client rect, it's
392
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
393
+ // node itself is hidden in place of its contents; and there's no need to search
394
+ // up the hierarchy either
395
+ return !node.getClientRects().length;
396
+ }
397
+
398
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
399
+ // API will __always__ return zero rects (this can happen, for example, if React
400
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
401
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
402
+ //
403
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
404
+ // because styles are only computed for nodes that are in the document.
405
+ //
406
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
407
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
408
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
409
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
410
+ // considering __everything__ to be visible because of the innability to determine styles.
411
+ //
412
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
413
+ // nodes as visible with the 'none' fallback.__
414
+ if (displayCheck !== 'legacy-full') {
415
+ return true; // hidden
416
+ }
417
+ // else, fallback to 'none' mode and consider the node visible
418
+ } else if (displayCheck === 'non-zero-area') {
419
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
420
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
421
+ // client rect, we don't special-case for whether the node is attached or not. In
422
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
423
+ // times, and that includes attached or not.
424
+ return isZeroArea(node);
425
+ }
426
+
427
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
428
+ // it's visible
429
+ return false;
430
+ };
431
+
432
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
433
+ // unless they are in the _first_ <legend> element of the top-most disabled
434
+ // fieldset
435
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
436
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
437
+ var parentNode = node.parentElement;
438
+ // check if `node` is contained in a disabled <fieldset>
439
+ while (parentNode) {
440
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
441
+ // look for the first <legend> among the children of the disabled <fieldset>
442
+ for (var i = 0; i < parentNode.children.length; i++) {
443
+ var child = parentNode.children.item(i);
444
+ // when the first <legend> (in document order) is found
445
+ if (child.tagName === 'LEGEND') {
446
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
447
+ // return whether `node` is a descendant of its first <legend>
448
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
449
+ }
450
+ }
451
+ // the disabled <fieldset> containing `node` has no <legend>
452
+ return true;
453
+ }
454
+ parentNode = parentNode.parentElement;
455
+ }
456
+ }
457
+
458
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
459
+ // enabled/disabled state
460
+ return false;
461
+ };
462
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
463
+ if (node.disabled ||
464
+ // we must do an inert look up to filter out any elements inside an inert ancestor
465
+ // because we're limited in the type of selectors we can use in JSDom (see related
466
+ // note related to `candidateSelectors`)
467
+ isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
468
+ // For a details element with a summary, the summary element gets the focus
469
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
470
+ return false;
471
+ }
472
+ return true;
473
+ };
474
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
475
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
476
+ return false;
477
+ }
478
+ return true;
479
+ };
480
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
481
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
482
+ if (isNaN(tabIndex) || tabIndex >= 0) {
483
+ return true;
484
+ }
485
+ // If a custom element has an explicit negative tabindex,
486
+ // browsers will not allow tab targeting said element's children.
487
+ return false;
488
+ };
489
+
490
+ /**
491
+ * @param {Array.<Element|CandidateScope>} candidates
492
+ * @returns Element[]
493
+ */
494
+ var sortByOrder = function sortByOrder(candidates) {
495
+ var regularTabbables = [];
496
+ var orderedTabbables = [];
497
+ candidates.forEach(function (item, i) {
498
+ var isScope = !!item.scopeParent;
499
+ var element = isScope ? item.scopeParent : item;
500
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
501
+ var elements = isScope ? sortByOrder(item.candidates) : element;
502
+ if (candidateTabindex === 0) {
503
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
504
+ } else {
505
+ orderedTabbables.push({
506
+ documentOrder: i,
507
+ tabIndex: candidateTabindex,
508
+ item: item,
509
+ isScope: isScope,
510
+ content: elements
511
+ });
512
+ }
513
+ });
514
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
515
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
516
+ return acc;
517
+ }, []).concat(regularTabbables);
518
+ };
519
+ var tabbable = function tabbable(container, options) {
520
+ options = options || {};
521
+ var candidates;
522
+ if (options.getShadowRoot) {
523
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
524
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
525
+ flatten: false,
526
+ getShadowRoot: options.getShadowRoot,
527
+ shadowRootFilter: isValidShadowRootTabbable
528
+ });
529
+ } else {
530
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
531
+ }
532
+ return sortByOrder(candidates);
533
+ };
534
+ var focusable = function focusable(container, options) {
535
+ options = options || {};
536
+ var candidates;
537
+ if (options.getShadowRoot) {
538
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
539
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
540
+ flatten: true,
541
+ getShadowRoot: options.getShadowRoot
542
+ });
543
+ } else {
544
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
545
+ }
546
+ return candidates;
547
+ };
548
+ var isTabbable = function isTabbable(node, options) {
549
+ options = options || {};
550
+ if (!node) {
551
+ throw new Error('No node provided');
552
+ }
553
+ if (matches.call(node, candidateSelector) === false) {
554
+ return false;
555
+ }
556
+ return isNodeMatchingSelectorTabbable(options, node);
557
+ };
558
+ var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
559
+ var isFocusable = function isFocusable(node, options) {
560
+ options = options || {};
561
+ if (!node) {
562
+ throw new Error('No node provided');
563
+ }
564
+ if (matches.call(node, focusableCandidateSelector) === false) {
565
+ return false;
566
+ }
567
+ return isNodeMatchingSelectorFocusable(options, node);
568
+ };
569
+
570
+ /*!
571
+ * focus-trap 7.5.4
572
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
573
+ */
574
+
575
+ function ownKeys(e, r) {
576
+ var t = Object.keys(e);
577
+ if (Object.getOwnPropertySymbols) {
578
+ var o = Object.getOwnPropertySymbols(e);
579
+ r && (o = o.filter(function (r) {
580
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
581
+ })), t.push.apply(t, o);
582
+ }
583
+ return t;
584
+ }
585
+ function _objectSpread2(e) {
586
+ for (var r = 1; r < arguments.length; r++) {
587
+ var t = null != arguments[r] ? arguments[r] : {};
588
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
589
+ _defineProperty(e, r, t[r]);
590
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
591
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
592
+ });
593
+ }
594
+ return e;
595
+ }
596
+ function _defineProperty(obj, key, value) {
597
+ key = _toPropertyKey(key);
598
+ if (key in obj) {
599
+ Object.defineProperty(obj, key, {
600
+ value: value,
601
+ enumerable: true,
602
+ configurable: true,
603
+ writable: true
604
+ });
605
+ } else {
606
+ obj[key] = value;
607
+ }
608
+ return obj;
609
+ }
610
+ function _toPrimitive(input, hint) {
611
+ if (typeof input !== "object" || input === null) return input;
612
+ var prim = input[Symbol.toPrimitive];
613
+ if (prim !== undefined) {
614
+ var res = prim.call(input, hint || "default");
615
+ if (typeof res !== "object") return res;
616
+ throw new TypeError("@@toPrimitive must return a primitive value.");
617
+ }
618
+ return (hint === "string" ? String : Number)(input);
619
+ }
620
+ function _toPropertyKey(arg) {
621
+ var key = _toPrimitive(arg, "string");
622
+ return typeof key === "symbol" ? key : String(key);
623
+ }
624
+
625
+ var activeFocusTraps = {
626
+ activateTrap: function activateTrap(trapStack, trap) {
627
+ if (trapStack.length > 0) {
628
+ var activeTrap = trapStack[trapStack.length - 1];
629
+ if (activeTrap !== trap) {
630
+ activeTrap.pause();
631
+ }
632
+ }
633
+ var trapIndex = trapStack.indexOf(trap);
634
+ if (trapIndex === -1) {
635
+ trapStack.push(trap);
636
+ } else {
637
+ // move this existing trap to the front of the queue
638
+ trapStack.splice(trapIndex, 1);
639
+ trapStack.push(trap);
640
+ }
641
+ },
642
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
643
+ var trapIndex = trapStack.indexOf(trap);
644
+ if (trapIndex !== -1) {
645
+ trapStack.splice(trapIndex, 1);
646
+ }
647
+ if (trapStack.length > 0) {
648
+ trapStack[trapStack.length - 1].unpause();
649
+ }
650
+ }
651
+ };
652
+ var isSelectableInput = function isSelectableInput(node) {
653
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
654
+ };
655
+ var isEscapeEvent = function isEscapeEvent(e) {
656
+ return (e === null || e === void 0 ? void 0 : e.key) === 'Escape' || (e === null || e === void 0 ? void 0 : e.key) === 'Esc' || (e === null || e === void 0 ? void 0 : e.keyCode) === 27;
657
+ };
658
+ var isTabEvent = function isTabEvent(e) {
659
+ return (e === null || e === void 0 ? void 0 : e.key) === 'Tab' || (e === null || e === void 0 ? void 0 : e.keyCode) === 9;
660
+ };
661
+
662
+ // checks for TAB by default
663
+ var isKeyForward = function isKeyForward(e) {
664
+ return isTabEvent(e) && !e.shiftKey;
665
+ };
666
+
667
+ // checks for SHIFT+TAB by default
668
+ var isKeyBackward = function isKeyBackward(e) {
669
+ return isTabEvent(e) && e.shiftKey;
670
+ };
671
+ var delay = function delay(fn) {
672
+ return setTimeout(fn, 0);
673
+ };
674
+
675
+ // Array.find/findIndex() are not supported on IE; this replicates enough
676
+ // of Array.findIndex() for our needs
677
+ var findIndex = function findIndex(arr, fn) {
678
+ var idx = -1;
679
+ arr.every(function (value, i) {
680
+ if (fn(value)) {
681
+ idx = i;
682
+ return false; // break
683
+ }
684
+
685
+ return true; // next
686
+ });
687
+
688
+ return idx;
689
+ };
690
+
691
+ /**
692
+ * Get an option's value when it could be a plain value, or a handler that provides
693
+ * the value.
694
+ * @param {*} value Option's value to check.
695
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
696
+ * @returns {*} The `value`, or the handler's returned value.
697
+ */
698
+ var valueOrHandler = function valueOrHandler(value) {
699
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
700
+ params[_key - 1] = arguments[_key];
701
+ }
702
+ return typeof value === 'function' ? value.apply(void 0, params) : value;
703
+ };
704
+ var getActualTarget = function getActualTarget(event) {
705
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
706
+ // shadow host. However, event.target.composedPath() will be an array of
707
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
708
+ // outer-most (the host HTML document). If we have access to composedPath(),
709
+ // then use its first element; otherwise, fall back to event.target (and
710
+ // this only works for an _open_ shadow DOM; otherwise,
711
+ // composedPath()[0] === event.target always).
712
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
713
+ };
714
+
715
+ // NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this
716
+ // current instance use the same stack if `userOptions.trapStack` isn't specified
717
+ var internalTrapStack = [];
718
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
719
+ // SSR: a live trap shouldn't be created in this type of environment so this
720
+ // should be safe code to execute if the `document` option isn't specified
721
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
722
+ var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || internalTrapStack;
723
+ var config = _objectSpread2({
724
+ returnFocusOnDeactivate: true,
725
+ escapeDeactivates: true,
726
+ delayInitialFocus: true,
727
+ isKeyForward: isKeyForward,
728
+ isKeyBackward: isKeyBackward
729
+ }, userOptions);
730
+ var state = {
731
+ // containers given to createFocusTrap()
732
+ // @type {Array<HTMLElement>}
733
+ containers: [],
734
+ // list of objects identifying tabbable nodes in `containers` in the trap
735
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
736
+ // is active, but the trap should never get to a state where there isn't at least one group
737
+ // with at least one tabbable node in it (that would lead to an error condition that would
738
+ // result in an error being thrown)
739
+ // @type {Array<{
740
+ // container: HTMLElement,
741
+ // tabbableNodes: Array<HTMLElement>, // empty if none
742
+ // focusableNodes: Array<HTMLElement>, // empty if none
743
+ // posTabIndexesFound: boolean,
744
+ // firstTabbableNode: HTMLElement|undefined,
745
+ // lastTabbableNode: HTMLElement|undefined,
746
+ // firstDomTabbableNode: HTMLElement|undefined,
747
+ // lastDomTabbableNode: HTMLElement|undefined,
748
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
749
+ // }>}
750
+ containerGroups: [],
751
+ // same order/length as `containers` list
752
+
753
+ // references to objects in `containerGroups`, but only those that actually have
754
+ // tabbable nodes in them
755
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
756
+ // the same length
757
+ tabbableGroups: [],
758
+ nodeFocusedBeforeActivation: null,
759
+ mostRecentlyFocusedNode: null,
760
+ active: false,
761
+ paused: false,
762
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
763
+ // has been delayed during activation
764
+ delayInitialFocusTimer: undefined,
765
+ // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
766
+ recentNavEvent: undefined
767
+ };
768
+ var trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later
769
+
770
+ /**
771
+ * Gets a configuration option value.
772
+ * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
773
+ * value will be taken from this object. Otherwise, value will be taken from base configuration.
774
+ * @param {string} optionName Name of the option whose value is sought.
775
+ * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
776
+ * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
777
+ */
778
+ var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
779
+ return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
780
+ };
781
+
782
+ /**
783
+ * Finds the index of the container that contains the element.
784
+ * @param {HTMLElement} element
785
+ * @param {Event} [event] If available, and `element` isn't directly found in any container,
786
+ * the event's composed path is used to see if includes any known trap containers in the
787
+ * case where the element is inside a Shadow DOM.
788
+ * @returns {number} Index of the container in either `state.containers` or
789
+ * `state.containerGroups` (the order/length of these lists are the same); -1
790
+ * if the element isn't found.
791
+ */
792
+ var findContainerIndex = function findContainerIndex(element, event) {
793
+ var composedPath = typeof (event === null || event === void 0 ? void 0 : event.composedPath) === 'function' ? event.composedPath() : undefined;
794
+ // NOTE: search `containerGroups` because it's possible a group contains no tabbable
795
+ // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
796
+ // and we still need to find the element in there
797
+ return state.containerGroups.findIndex(function (_ref) {
798
+ var container = _ref.container,
799
+ tabbableNodes = _ref.tabbableNodes;
800
+ return container.contains(element) || ( // fall back to explicit tabbable search which will take into consideration any
801
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
802
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
803
+ // look inside web components even if open)
804
+ composedPath === null || composedPath === void 0 ? void 0 : composedPath.includes(container)) || tabbableNodes.find(function (node) {
805
+ return node === element;
806
+ });
807
+ });
808
+ };
809
+
810
+ /**
811
+ * Gets the node for the given option, which is expected to be an option that
812
+ * can be either a DOM node, a string that is a selector to get a node, `false`
813
+ * (if a node is explicitly NOT given), or a function that returns any of these
814
+ * values.
815
+ * @param {string} optionName
816
+ * @returns {undefined | false | HTMLElement | SVGElement} Returns
817
+ * `undefined` if the option is not specified; `false` if the option
818
+ * resolved to `false` (node explicitly not given); otherwise, the resolved
819
+ * DOM node.
820
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
821
+ * resolve to a node.
822
+ */
823
+ var getNodeForOption = function getNodeForOption(optionName) {
824
+ var optionValue = config[optionName];
825
+ if (typeof optionValue === 'function') {
826
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
827
+ params[_key2 - 1] = arguments[_key2];
828
+ }
829
+ optionValue = optionValue.apply(void 0, params);
830
+ }
831
+ if (optionValue === true) {
832
+ optionValue = undefined; // use default value
833
+ }
834
+
835
+ if (!optionValue) {
836
+ if (optionValue === undefined || optionValue === false) {
837
+ return optionValue;
838
+ }
839
+ // else, empty string (invalid), null (invalid), 0 (invalid)
840
+
841
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
842
+ }
843
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
844
+
845
+ if (typeof optionValue === 'string') {
846
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
847
+ if (!node) {
848
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
849
+ }
850
+ }
851
+ return node;
852
+ };
853
+ var getInitialFocusNode = function getInitialFocusNode() {
854
+ var node = getNodeForOption('initialFocus');
855
+
856
+ // false explicitly indicates we want no initialFocus at all
857
+ if (node === false) {
858
+ return false;
859
+ }
860
+ if (node === undefined || !isFocusable(node, config.tabbableOptions)) {
861
+ // option not specified nor focusable: use fallback options
862
+ if (findContainerIndex(doc.activeElement) >= 0) {
863
+ node = doc.activeElement;
864
+ } else {
865
+ var firstTabbableGroup = state.tabbableGroups[0];
866
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
867
+
868
+ // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
869
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
870
+ }
871
+ }
872
+ if (!node) {
873
+ throw new Error('Your focus-trap needs to have at least one focusable element');
874
+ }
875
+ return node;
876
+ };
877
+ var updateTabbableNodes = function updateTabbableNodes() {
878
+ state.containerGroups = state.containers.map(function (container) {
879
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
880
+
881
+ // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
882
+ // are a superset of tabbable nodes since nodes with negative `tabindex` attributes
883
+ // are focusable but not tabbable
884
+ var focusableNodes = focusable(container, config.tabbableOptions);
885
+ var firstTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;
886
+ var lastTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : undefined;
887
+ var firstDomTabbableNode = focusableNodes.find(function (node) {
888
+ return isTabbable(node);
889
+ });
890
+ var lastDomTabbableNode = focusableNodes.slice().reverse().find(function (node) {
891
+ return isTabbable(node);
892
+ });
893
+ var posTabIndexesFound = !!tabbableNodes.find(function (node) {
894
+ return getTabIndex(node) > 0;
895
+ });
896
+ return {
897
+ container: container,
898
+ tabbableNodes: tabbableNodes,
899
+ focusableNodes: focusableNodes,
900
+ /** True if at least one node with positive `tabindex` was found in this container. */
901
+ posTabIndexesFound: posTabIndexesFound,
902
+ /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
903
+ firstTabbableNode: firstTabbableNode,
904
+ /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
905
+ lastTabbableNode: lastTabbableNode,
906
+ // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
907
+ // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
908
+ // because that API doesn't work with Shadow DOM as well as it should (@see
909
+ // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
910
+ // to address an edge case related to positive tabindex support, this seems like a much easier,
911
+ // "close enough most of the time" alternative for positive tabindexes which should generally
912
+ // be avoided anyway...
913
+ /** First tabbable node in container, __DOM__ order; `undefined` if none. */
914
+ firstDomTabbableNode: firstDomTabbableNode,
915
+ /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
916
+ lastDomTabbableNode: lastDomTabbableNode,
917
+ /**
918
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
919
+ * in this container, if any.
920
+ * @param {HTMLElement} node
921
+ * @param {boolean} [forward] True if going in forward tab order; false if going
922
+ * in reverse.
923
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
924
+ */
925
+ nextTabbableNode: function nextTabbableNode(node) {
926
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
927
+ var nodeIdx = tabbableNodes.indexOf(node);
928
+ if (nodeIdx < 0) {
929
+ // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):
930
+ // since `node` should at least have been focusable, we assume that's the case and mimic
931
+ // what browsers do, which is set focus to the next node in __document position order__,
932
+ // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE
933
+ // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to
934
+ // basic DOM order
935
+ if (forward) {
936
+ return focusableNodes.slice(focusableNodes.indexOf(node) + 1).find(function (el) {
937
+ return isTabbable(el);
938
+ });
939
+ }
940
+ return focusableNodes.slice(0, focusableNodes.indexOf(node)).reverse().find(function (el) {
941
+ return isTabbable(el);
942
+ });
943
+ }
944
+ return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
945
+ }
946
+ };
947
+ });
948
+ state.tabbableGroups = state.containerGroups.filter(function (group) {
949
+ return group.tabbableNodes.length > 0;
950
+ });
951
+
952
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
953
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
954
+ ) {
955
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
956
+ }
957
+
958
+ // NOTE: Positive tabindexes are only properly supported in single-container traps because
959
+ // doing it across multiple containers where tabindexes could be all over the place
960
+ // would require Tabbable to support multiple containers, would require additional
961
+ // specialized Shadow DOM support, and would require Tabbable's multi-container support
962
+ // to look at those containers in document position order rather than user-provided
963
+ // order (as they are treated in Focus-trap, for legacy reasons). See discussion on
964
+ // https://github.com/focus-trap/focus-trap/issues/375 for more details.
965
+ if (state.containerGroups.find(function (g) {
966
+ return g.posTabIndexesFound;
967
+ }) && state.containerGroups.length > 1) {
968
+ 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.");
969
+ }
970
+ };
971
+
972
+ /**
973
+ * Gets the current activeElement. If it's a web-component and has open shadow-root
974
+ * it will recursively search inside shadow roots for the "true" activeElement.
975
+ *
976
+ * @param {Document | ShadowRoot} el
977
+ *
978
+ * @returns {HTMLElement} The element that currently has the focus
979
+ **/
980
+ var getActiveElement = function getActiveElement(el) {
981
+ var activeElement = el.activeElement;
982
+ if (!activeElement) {
983
+ return;
984
+ }
985
+ if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
986
+ return getActiveElement(activeElement.shadowRoot);
987
+ }
988
+ return activeElement;
989
+ };
990
+ var tryFocus = function tryFocus(node) {
991
+ if (node === false) {
992
+ return;
993
+ }
994
+ if (node === getActiveElement(document)) {
995
+ return;
996
+ }
997
+ if (!node || !node.focus) {
998
+ tryFocus(getInitialFocusNode());
999
+ return;
1000
+ }
1001
+ node.focus({
1002
+ preventScroll: !!config.preventScroll
1003
+ });
1004
+ // NOTE: focus() API does not trigger focusIn event so set MRU node manually
1005
+ state.mostRecentlyFocusedNode = node;
1006
+ if (isSelectableInput(node)) {
1007
+ node.select();
1008
+ }
1009
+ };
1010
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
1011
+ var node = getNodeForOption('setReturnFocus', previousActiveElement);
1012
+ return node ? node : node === false ? false : previousActiveElement;
1013
+ };
1014
+
1015
+ /**
1016
+ * Finds the next node (in either direction) where focus should move according to a
1017
+ * keyboard focus-in event.
1018
+ * @param {Object} params
1019
+ * @param {Node} [params.target] Known target __from which__ to navigate, if any.
1020
+ * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event
1021
+ * will be used to determine the `target`). Ignored if `target` is specified.
1022
+ * @param {boolean} [params.isBackward] True if focus should move backward.
1023
+ * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be
1024
+ * determined given the current state of the trap.
1025
+ */
1026
+ var findNextNavNode = function findNextNavNode(_ref2) {
1027
+ var target = _ref2.target,
1028
+ event = _ref2.event,
1029
+ _ref2$isBackward = _ref2.isBackward,
1030
+ isBackward = _ref2$isBackward === void 0 ? false : _ref2$isBackward;
1031
+ target = target || getActualTarget(event);
1032
+ updateTabbableNodes();
1033
+ var destinationNode = null;
1034
+ if (state.tabbableGroups.length > 0) {
1035
+ // make sure the target is actually contained in a group
1036
+ // NOTE: the target may also be the container itself if it's focusable
1037
+ // with tabIndex='-1' and was given initial focus
1038
+ var containerIndex = findContainerIndex(target, event);
1039
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
1040
+ if (containerIndex < 0) {
1041
+ // target not found in any group: quite possible focus has escaped the trap,
1042
+ // so bring it back into...
1043
+ if (isBackward) {
1044
+ // ...the last node in the last group
1045
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
1046
+ } else {
1047
+ // ...the first node in the first group
1048
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
1049
+ }
1050
+ } else if (isBackward) {
1051
+ // REVERSE
1052
+
1053
+ // is the target the first tabbable node in a group?
1054
+ var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
1055
+ var firstTabbableNode = _ref3.firstTabbableNode;
1056
+ return target === firstTabbableNode;
1057
+ });
1058
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
1059
+ // an exception case where the target is either the container itself, or
1060
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1061
+ // and user clicked on it or node was programmatically given focus)
1062
+ // and is not followed by any other tabbable node, in which
1063
+ // case, we should handle shift+tab as if focus were on the container's
1064
+ // first tabbable node, and go to the last tabbable node of the LAST group
1065
+ startOfGroupIndex = containerIndex;
1066
+ }
1067
+ if (startOfGroupIndex >= 0) {
1068
+ // YES: then shift+tab should go to the last tabbable node in the
1069
+ // previous group (and wrap around to the last tabbable node of
1070
+ // the LAST group if it's the first tabbable node of the FIRST group)
1071
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
1072
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
1073
+ destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
1074
+ } else if (!isTabEvent(event)) {
1075
+ // user must have customized the nav keys so we have to move focus manually _within_
1076
+ // the active group: do this based on the order determined by tabbable()
1077
+ destinationNode = containerGroup.nextTabbableNode(target, false);
1078
+ }
1079
+ } else {
1080
+ // FORWARD
1081
+
1082
+ // is the target the last tabbable node in a group?
1083
+ var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref4) {
1084
+ var lastTabbableNode = _ref4.lastTabbableNode;
1085
+ return target === lastTabbableNode;
1086
+ });
1087
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
1088
+ // an exception case where the target is the container itself, or
1089
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1090
+ // and user clicked on it or node was programmatically given focus)
1091
+ // and is not followed by any other tabbable node, in which
1092
+ // case, we should handle tab as if focus were on the container's
1093
+ // last tabbable node, and go to the first tabbable node of the FIRST group
1094
+ lastOfGroupIndex = containerIndex;
1095
+ }
1096
+ if (lastOfGroupIndex >= 0) {
1097
+ // YES: then tab should go to the first tabbable node in the next
1098
+ // group (and wrap around to the first tabbable node of the FIRST
1099
+ // group if it's the last tabbable node of the LAST group)
1100
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
1101
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
1102
+ destinationNode = getTabIndex(target) >= 0 ? _destinationGroup.firstTabbableNode : _destinationGroup.firstDomTabbableNode;
1103
+ } else if (!isTabEvent(event)) {
1104
+ // user must have customized the nav keys so we have to move focus manually _within_
1105
+ // the active group: do this based on the order determined by tabbable()
1106
+ destinationNode = containerGroup.nextTabbableNode(target);
1107
+ }
1108
+ }
1109
+ } else {
1110
+ // no groups available
1111
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
1112
+ destinationNode = getNodeForOption('fallbackFocus');
1113
+ }
1114
+ return destinationNode;
1115
+ };
1116
+
1117
+ // This needs to be done on mousedown and touchstart instead of click
1118
+ // so that it precedes the focus event.
1119
+ var checkPointerDown = function checkPointerDown(e) {
1120
+ var target = getActualTarget(e);
1121
+ if (findContainerIndex(target, e) >= 0) {
1122
+ // allow the click since it ocurred inside the trap
1123
+ return;
1124
+ }
1125
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1126
+ // immediately deactivate the trap
1127
+ trap.deactivate({
1128
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
1129
+ // which will result in the outside click setting focus to the node
1130
+ // that was clicked (and if not focusable, to "nothing"); by setting
1131
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
1132
+ // on activation (or the configured `setReturnFocus` node), whether the
1133
+ // outside click was on a focusable node or not
1134
+ returnFocus: config.returnFocusOnDeactivate
1135
+ });
1136
+ return;
1137
+ }
1138
+
1139
+ // This is needed for mobile devices.
1140
+ // (If we'll only let `click` events through,
1141
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
1142
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1143
+ // allow the click outside the trap to take place
1144
+ return;
1145
+ }
1146
+
1147
+ // otherwise, prevent the click
1148
+ e.preventDefault();
1149
+ };
1150
+
1151
+ // In case focus escapes the trap for some strange reason, pull it back in.
1152
+ // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected
1153
+ // scrolling if the node that got focused was out of view; there's nothing we can do to
1154
+ // prevent that from happening by the time we discover that focus escaped
1155
+ var checkFocusIn = function checkFocusIn(event) {
1156
+ var target = getActualTarget(event);
1157
+ var targetContained = findContainerIndex(target, event) >= 0;
1158
+
1159
+ // In Firefox when you Tab out of an iframe the Document is briefly focused.
1160
+ if (targetContained || target instanceof Document) {
1161
+ if (targetContained) {
1162
+ state.mostRecentlyFocusedNode = target;
1163
+ }
1164
+ } else {
1165
+ // escaped! pull it back in to where it just left
1166
+ event.stopImmediatePropagation();
1167
+
1168
+ // focus will escape if the MRU node had a positive tab index and user tried to nav forward;
1169
+ // it will also escape if the MRU node had a 0 tab index and user tried to nav backward
1170
+ // toward a node with a positive tab index
1171
+ var nextNode; // next node to focus, if we find one
1172
+ var navAcrossContainers = true;
1173
+ if (state.mostRecentlyFocusedNode) {
1174
+ if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
1175
+ // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...
1176
+ var mruContainerIdx = findContainerIndex(state.mostRecentlyFocusedNode);
1177
+ // there MAY not be any tabbable nodes in the container if there are at least 2 containers
1178
+ // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container
1179
+ // with at least one tabbable node in order to function, so this could be the other container
1180
+ // with nothing tabbable in it)
1181
+ var tabbableNodes = state.containerGroups[mruContainerIdx].tabbableNodes;
1182
+ if (tabbableNodes.length > 0) {
1183
+ // MRU tab index MAY not be found if the MRU node is focusable but not tabbable
1184
+ var mruTabIdx = tabbableNodes.findIndex(function (node) {
1185
+ return node === state.mostRecentlyFocusedNode;
1186
+ });
1187
+ if (mruTabIdx >= 0) {
1188
+ if (config.isKeyForward(state.recentNavEvent)) {
1189
+ if (mruTabIdx + 1 < tabbableNodes.length) {
1190
+ nextNode = tabbableNodes[mruTabIdx + 1];
1191
+ navAcrossContainers = false;
1192
+ }
1193
+ // else, don't wrap within the container as focus should move to next/previous
1194
+ // container
1195
+ } else {
1196
+ if (mruTabIdx - 1 >= 0) {
1197
+ nextNode = tabbableNodes[mruTabIdx - 1];
1198
+ navAcrossContainers = false;
1199
+ }
1200
+ // else, don't wrap within the container as focus should move to next/previous
1201
+ // container
1202
+ }
1203
+ // else, don't find in container order without considering direction too
1204
+ }
1205
+ }
1206
+ // else, no tabbable nodes in that container (which means we must have at least one other
1207
+ // container with at least one tabbable node in it, otherwise focus-trap would've thrown
1208
+ // an error the last time updateTabbableNodes() was run): find next node among all known
1209
+ // containers
1210
+ } else {
1211
+ // check to see if there's at least one tabbable node with a positive tab index inside
1212
+ // the trap because focus seems to escape when navigating backward from a tabbable node
1213
+ // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with
1214
+ // the greatest positive tab index like it should)
1215
+ if (!state.containerGroups.some(function (g) {
1216
+ return g.tabbableNodes.some(function (n) {
1217
+ return getTabIndex(n) > 0;
1218
+ });
1219
+ })) {
1220
+ // no containers with tabbable nodes with positive tab indexes which means the focus
1221
+ // escaped for some other reason and we should just execute the fallback to the
1222
+ // MRU node or initial focus node, if any
1223
+ navAcrossContainers = false;
1224
+ }
1225
+ }
1226
+ } else {
1227
+ // no MRU node means we're likely in some initial condition when the trap has just
1228
+ // been activated and initial focus hasn't been given yet, in which case we should
1229
+ // fall through to trying to focus the initial focus node, which is what should
1230
+ // happen below at this point in the logic
1231
+ navAcrossContainers = false;
1232
+ }
1233
+ if (navAcrossContainers) {
1234
+ nextNode = findNextNavNode({
1235
+ // move FROM the MRU node, not event-related node (which will be the node that is
1236
+ // outside the trap causing the focus escape we're trying to fix)
1237
+ target: state.mostRecentlyFocusedNode,
1238
+ isBackward: config.isKeyBackward(state.recentNavEvent)
1239
+ });
1240
+ }
1241
+ if (nextNode) {
1242
+ tryFocus(nextNode);
1243
+ } else {
1244
+ tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
1245
+ }
1246
+ }
1247
+ state.recentNavEvent = undefined; // clear
1248
+ };
1249
+
1250
+ // Hijack key nav events on the first and last focusable nodes of the trap,
1251
+ // in order to prevent focus from escaping. If it escapes for even a
1252
+ // moment it can end up scrolling the page and causing confusion so we
1253
+ // kind of need to capture the action at the keydown phase.
1254
+ var checkKeyNav = function checkKeyNav(event) {
1255
+ var isBackward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1256
+ state.recentNavEvent = event;
1257
+ var destinationNode = findNextNavNode({
1258
+ event: event,
1259
+ isBackward: isBackward
1260
+ });
1261
+ if (destinationNode) {
1262
+ if (isTabEvent(event)) {
1263
+ // since tab natively moves focus, we wouldn't have a destination node unless we
1264
+ // were on the edge of a container and had to move to the next/previous edge, in
1265
+ // which case we want to prevent default to keep the browser from moving focus
1266
+ // to where it normally would
1267
+ event.preventDefault();
1268
+ }
1269
+ tryFocus(destinationNode);
1270
+ }
1271
+ // else, let the browser take care of [shift+]tab and move the focus
1272
+ };
1273
+
1274
+ var checkKey = function checkKey(event) {
1275
+ if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
1276
+ event.preventDefault();
1277
+ trap.deactivate();
1278
+ return;
1279
+ }
1280
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
1281
+ checkKeyNav(event, config.isKeyBackward(event));
1282
+ }
1283
+ };
1284
+ var checkClick = function checkClick(e) {
1285
+ var target = getActualTarget(e);
1286
+ if (findContainerIndex(target, e) >= 0) {
1287
+ return;
1288
+ }
1289
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1290
+ return;
1291
+ }
1292
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1293
+ return;
1294
+ }
1295
+ e.preventDefault();
1296
+ e.stopImmediatePropagation();
1297
+ };
1298
+
1299
+ //
1300
+ // EVENT LISTENERS
1301
+ //
1302
+
1303
+ var addListeners = function addListeners() {
1304
+ if (!state.active) {
1305
+ return;
1306
+ }
1307
+
1308
+ // There can be only one listening focus trap at a time
1309
+ activeFocusTraps.activateTrap(trapStack, trap);
1310
+
1311
+ // Delay ensures that the focused element doesn't capture the event
1312
+ // that caused the focus trap activation.
1313
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
1314
+ tryFocus(getInitialFocusNode());
1315
+ }) : tryFocus(getInitialFocusNode());
1316
+ doc.addEventListener('focusin', checkFocusIn, true);
1317
+ doc.addEventListener('mousedown', checkPointerDown, {
1318
+ capture: true,
1319
+ passive: false
1320
+ });
1321
+ doc.addEventListener('touchstart', checkPointerDown, {
1322
+ capture: true,
1323
+ passive: false
1324
+ });
1325
+ doc.addEventListener('click', checkClick, {
1326
+ capture: true,
1327
+ passive: false
1328
+ });
1329
+ doc.addEventListener('keydown', checkKey, {
1330
+ capture: true,
1331
+ passive: false
1332
+ });
1333
+ return trap;
1334
+ };
1335
+ var removeListeners = function removeListeners() {
1336
+ if (!state.active) {
1337
+ return;
1338
+ }
1339
+ doc.removeEventListener('focusin', checkFocusIn, true);
1340
+ doc.removeEventListener('mousedown', checkPointerDown, true);
1341
+ doc.removeEventListener('touchstart', checkPointerDown, true);
1342
+ doc.removeEventListener('click', checkClick, true);
1343
+ doc.removeEventListener('keydown', checkKey, true);
1344
+ return trap;
1345
+ };
1346
+
1347
+ //
1348
+ // MUTATION OBSERVER
1349
+ //
1350
+
1351
+ var checkDomRemoval = function checkDomRemoval(mutations) {
1352
+ var isFocusedNodeRemoved = mutations.some(function (mutation) {
1353
+ var removedNodes = Array.from(mutation.removedNodes);
1354
+ return removedNodes.some(function (node) {
1355
+ return node === state.mostRecentlyFocusedNode;
1356
+ });
1357
+ });
1358
+
1359
+ // If the currently focused is removed then browsers will move focus to the
1360
+ // <body> element. If this happens, try to move focus back into the trap.
1361
+ if (isFocusedNodeRemoved) {
1362
+ tryFocus(getInitialFocusNode());
1363
+ }
1364
+ };
1365
+
1366
+ // Use MutationObserver - if supported - to detect if focused node is removed
1367
+ // from the DOM.
1368
+ var mutationObserver = typeof window !== 'undefined' && 'MutationObserver' in window ? new MutationObserver(checkDomRemoval) : undefined;
1369
+ var updateObservedNodes = function updateObservedNodes() {
1370
+ if (!mutationObserver) {
1371
+ return;
1372
+ }
1373
+ mutationObserver.disconnect();
1374
+ if (state.active && !state.paused) {
1375
+ state.containers.map(function (container) {
1376
+ mutationObserver.observe(container, {
1377
+ subtree: true,
1378
+ childList: true
1379
+ });
1380
+ });
1381
+ }
1382
+ };
1383
+
1384
+ //
1385
+ // TRAP DEFINITION
1386
+ //
1387
+
1388
+ trap = {
1389
+ get active() {
1390
+ return state.active;
1391
+ },
1392
+ get paused() {
1393
+ return state.paused;
1394
+ },
1395
+ activate: function activate(activateOptions) {
1396
+ if (state.active) {
1397
+ return this;
1398
+ }
1399
+ var onActivate = getOption(activateOptions, 'onActivate');
1400
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
1401
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1402
+ if (!checkCanFocusTrap) {
1403
+ updateTabbableNodes();
1404
+ }
1405
+ state.active = true;
1406
+ state.paused = false;
1407
+ state.nodeFocusedBeforeActivation = doc.activeElement;
1408
+ onActivate === null || onActivate === void 0 || onActivate();
1409
+ var finishActivation = function finishActivation() {
1410
+ if (checkCanFocusTrap) {
1411
+ updateTabbableNodes();
1412
+ }
1413
+ addListeners();
1414
+ updateObservedNodes();
1415
+ onPostActivate === null || onPostActivate === void 0 || onPostActivate();
1416
+ };
1417
+ if (checkCanFocusTrap) {
1418
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1419
+ return this;
1420
+ }
1421
+ finishActivation();
1422
+ return this;
1423
+ },
1424
+ deactivate: function deactivate(deactivateOptions) {
1425
+ if (!state.active) {
1426
+ return this;
1427
+ }
1428
+ var options = _objectSpread2({
1429
+ onDeactivate: config.onDeactivate,
1430
+ onPostDeactivate: config.onPostDeactivate,
1431
+ checkCanReturnFocus: config.checkCanReturnFocus
1432
+ }, deactivateOptions);
1433
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1434
+ state.delayInitialFocusTimer = undefined;
1435
+ removeListeners();
1436
+ state.active = false;
1437
+ state.paused = false;
1438
+ updateObservedNodes();
1439
+ activeFocusTraps.deactivateTrap(trapStack, trap);
1440
+ var onDeactivate = getOption(options, 'onDeactivate');
1441
+ var onPostDeactivate = getOption(options, 'onPostDeactivate');
1442
+ var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1443
+ var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1444
+ onDeactivate === null || onDeactivate === void 0 || onDeactivate();
1445
+ var finishDeactivation = function finishDeactivation() {
1446
+ delay(function () {
1447
+ if (returnFocus) {
1448
+ tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1449
+ }
1450
+ onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
1451
+ });
1452
+ };
1453
+ if (returnFocus && checkCanReturnFocus) {
1454
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1455
+ return this;
1456
+ }
1457
+ finishDeactivation();
1458
+ return this;
1459
+ },
1460
+ pause: function pause(pauseOptions) {
1461
+ if (state.paused || !state.active) {
1462
+ return this;
1463
+ }
1464
+ var onPause = getOption(pauseOptions, 'onPause');
1465
+ var onPostPause = getOption(pauseOptions, 'onPostPause');
1466
+ state.paused = true;
1467
+ onPause === null || onPause === void 0 || onPause();
1468
+ removeListeners();
1469
+ updateObservedNodes();
1470
+ onPostPause === null || onPostPause === void 0 || onPostPause();
1471
+ return this;
1472
+ },
1473
+ unpause: function unpause(unpauseOptions) {
1474
+ if (!state.paused || !state.active) {
1475
+ return this;
1476
+ }
1477
+ var onUnpause = getOption(unpauseOptions, 'onUnpause');
1478
+ var onPostUnpause = getOption(unpauseOptions, 'onPostUnpause');
1479
+ state.paused = false;
1480
+ onUnpause === null || onUnpause === void 0 || onUnpause();
1481
+ updateTabbableNodes();
1482
+ addListeners();
1483
+ updateObservedNodes();
1484
+ onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause();
1485
+ return this;
1486
+ },
1487
+ updateContainerElements: function updateContainerElements(containerElements) {
1488
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1489
+ state.containers = elementsAsArray.map(function (element) {
1490
+ return typeof element === 'string' ? doc.querySelector(element) : element;
1491
+ });
1492
+ if (state.active) {
1493
+ updateTabbableNodes();
1494
+ }
1495
+ updateObservedNodes();
1496
+ return this;
1497
+ }
1498
+ };
1499
+
1500
+ // initialize container elements
1501
+ trap.updateContainerElements(elements);
1502
+ return trap;
1503
+ };
1504
+
1505
+ export { createFocusTrap as c };
1506
+
1507
+ //# sourceMappingURL=focus-trap.esm-49c9613c.js.map