@getflip/swirl-components 0.116.0 → 0.117.0

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 (107) hide show
  1. package/components.json +371 -69
  2. package/dist/cjs/focus-trap.esm-21561e09.js +1145 -0
  3. package/dist/cjs/index-506fe4ea.js +14 -26
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/swirl-app-bar.cjs.entry.js +2 -1
  6. package/dist/cjs/swirl-app-icon.cjs.entry.js +1 -3
  7. package/dist/cjs/swirl-app-layout_6.cjs.entry.js +1 -1
  8. package/dist/cjs/swirl-badge.cjs.entry.js +1 -1
  9. package/dist/cjs/swirl-components.cjs.js +1 -1
  10. package/dist/cjs/swirl-icon-arrow-back_5.cjs.entry.js +87 -0
  11. package/dist/cjs/swirl-icon-dock-left.cjs.entry.js +23 -0
  12. package/dist/cjs/swirl-modal.cjs.entry.js +2 -1143
  13. package/dist/cjs/swirl-shell-layout.cjs.entry.js +87 -75
  14. package/dist/cjs/swirl-shell-navigation-item.cjs.entry.js +1 -1
  15. package/dist/cjs/swirl-visually-hidden.cjs.entry.js +1 -1
  16. package/dist/collection/assets/pdfjs/pdf.worker.min.js +1 -1
  17. package/dist/collection/collection-manifest.json +1 -0
  18. package/dist/collection/components/swirl-app-bar/swirl-app-bar.js +20 -1
  19. package/dist/collection/components/swirl-app-icon/swirl-app-icon.css +3 -22
  20. package/dist/collection/components/swirl-app-icon/swirl-app-icon.js +0 -20
  21. package/dist/collection/components/swirl-app-layout/swirl-app-layout.css +38 -4
  22. package/dist/collection/components/swirl-badge/swirl-badge.css +18 -1
  23. package/dist/collection/components/swirl-badge/swirl-badge.js +1 -1
  24. package/dist/collection/components/swirl-icon/icons/swirl-icon-dock-left.js +52 -0
  25. package/dist/collection/components/swirl-shell-layout/swirl-shell-layout.css +353 -132
  26. package/dist/collection/components/swirl-shell-layout/swirl-shell-layout.js +322 -95
  27. package/dist/collection/components/swirl-shell-layout/swirl-shell-layout.spec.js +8 -58
  28. package/dist/collection/components/swirl-shell-layout/swirl-shell-layout.stories.js +81 -102
  29. package/dist/collection/components/swirl-shell-navigation-item/swirl-shell-navigation-item.css +46 -35
  30. package/dist/collection/components/swirl-visually-hidden/swirl-visually-hidden.js +1 -1
  31. package/dist/collection/components/swirl-visually-hidden/swirl-visually-hidden.spec.js +0 -3
  32. package/dist/components/assets/images/flip-logo.png +0 -0
  33. package/dist/components/assets/pdfjs/pdf.worker.min.js +1 -1
  34. package/dist/components/focus-trap.esm.js +1143 -0
  35. package/dist/components/swirl-app-bar.js +3 -1
  36. package/dist/components/swirl-app-icon.js +1 -4
  37. package/dist/components/swirl-app-layout2.js +1 -1
  38. package/dist/components/swirl-badge2.js +1 -1
  39. package/dist/components/swirl-icon-arrow-back.js +1 -35
  40. package/dist/{esm/swirl-icon-arrow-back.entry.js → components/swirl-icon-arrow-back2.js} +26 -8
  41. package/dist/components/swirl-icon-arrow-forward.js +1 -35
  42. package/dist/{esm/swirl-icon-arrow-forward.entry.js → components/swirl-icon-arrow-forward2.js} +26 -8
  43. package/dist/components/swirl-icon-dock-left.d.ts +11 -0
  44. package/dist/components/swirl-icon-dock-left.js +40 -0
  45. package/dist/components/swirl-icon-double-arrow-left.js +1 -35
  46. package/dist/{esm/swirl-icon-double-arrow-left.entry.js → components/swirl-icon-double-arrow-left2.js} +26 -8
  47. package/dist/components/swirl-icon-double-arrow-right.js +1 -35
  48. package/dist/{esm/swirl-icon-double-arrow-right.entry.js → components/swirl-icon-double-arrow-right2.js} +26 -8
  49. package/dist/components/swirl-icon-menu.js +1 -35
  50. package/dist/{esm/swirl-icon-menu.entry.js → components/swirl-icon-menu2.js} +26 -8
  51. package/dist/components/swirl-modal.js +1 -1142
  52. package/dist/components/swirl-shell-layout.js +150 -89
  53. package/dist/components/swirl-shell-navigation-item.js +1 -1
  54. package/dist/components/swirl-visually-hidden2.js +2 -3
  55. package/dist/esm/focus-trap.esm-37cd2d2b.js +1143 -0
  56. package/dist/esm/index-99d0060d.js +14 -26
  57. package/dist/esm/loader.js +1 -1
  58. package/dist/esm/swirl-app-bar.entry.js +2 -1
  59. package/dist/esm/swirl-app-icon.entry.js +1 -3
  60. package/dist/esm/swirl-app-layout_6.entry.js +1 -1
  61. package/dist/esm/swirl-badge.entry.js +1 -1
  62. package/dist/esm/swirl-components.js +1 -1
  63. package/dist/esm/swirl-icon-arrow-back_5.entry.js +79 -0
  64. package/dist/esm/swirl-icon-dock-left.entry.js +19 -0
  65. package/dist/esm/swirl-modal.entry.js +1 -1142
  66. package/dist/esm/swirl-shell-layout.entry.js +88 -76
  67. package/dist/esm/swirl-shell-navigation-item.entry.js +1 -1
  68. package/dist/esm/swirl-visually-hidden.entry.js +1 -1
  69. package/dist/swirl-components/p-08fd60a5.entry.js +1 -0
  70. package/dist/swirl-components/p-0ac2eb84.entry.js +1 -0
  71. package/dist/swirl-components/p-11c6c9ba.entry.js +1 -0
  72. package/dist/swirl-components/p-25b4973d.entry.js +1 -0
  73. package/dist/swirl-components/p-262771e5.entry.js +1 -0
  74. package/dist/swirl-components/p-3795fbb4.entry.js +1 -0
  75. package/dist/swirl-components/p-40ee5f22.entry.js +1 -0
  76. package/dist/swirl-components/p-4a69e7f3.entry.js +1 -0
  77. package/dist/swirl-components/p-76c36ee9.entry.js +1 -0
  78. package/dist/swirl-components/p-7c4a4b66.entry.js +1 -0
  79. package/dist/swirl-components/p-c2e1dfdb.js +10 -0
  80. package/dist/swirl-components/swirl-components.esm.js +1 -1
  81. package/dist/types/components/swirl-app-bar/swirl-app-bar.d.ts +1 -0
  82. package/dist/types/components/swirl-app-icon/swirl-app-icon.d.ts +0 -1
  83. package/dist/types/components/swirl-badge/swirl-badge.d.ts +1 -1
  84. package/dist/types/components/swirl-icon/icons/swirl-icon-dock-left.d.ts +5 -0
  85. package/dist/types/components/swirl-shell-layout/swirl-shell-layout.d.ts +42 -25
  86. package/dist/types/components.d.ts +50 -11
  87. package/icons.json +1 -1
  88. package/package.json +2 -2
  89. package/vscode-data.json +58 -6
  90. package/dist/cjs/swirl-icon-arrow-back.cjs.entry.js +0 -23
  91. package/dist/cjs/swirl-icon-arrow-forward.cjs.entry.js +0 -23
  92. package/dist/cjs/swirl-icon-double-arrow-left.cjs.entry.js +0 -23
  93. package/dist/cjs/swirl-icon-double-arrow-right.cjs.entry.js +0 -23
  94. package/dist/cjs/swirl-icon-menu.cjs.entry.js +0 -23
  95. package/dist/swirl-components/p-3a2abee9.entry.js +0 -1
  96. package/dist/swirl-components/p-441c8210.entry.js +0 -1
  97. package/dist/swirl-components/p-4a84e63d.entry.js +0 -1
  98. package/dist/swirl-components/p-54e4ff0b.entry.js +0 -1
  99. package/dist/swirl-components/p-5da3a9a8.entry.js +0 -1
  100. package/dist/swirl-components/p-645a878c.entry.js +0 -1
  101. package/dist/swirl-components/p-79be22ea.entry.js +0 -10
  102. package/dist/swirl-components/p-97668c59.entry.js +0 -1
  103. package/dist/swirl-components/p-be2cf7ee.entry.js +0 -1
  104. package/dist/swirl-components/p-c4d4a99d.entry.js +0 -1
  105. package/dist/swirl-components/p-ca78767e.entry.js +0 -1
  106. package/dist/swirl-components/p-d2fc7935.entry.js +0 -1
  107. package/dist/swirl-components/p-f83a0b0f.entry.js +0 -1
@@ -0,0 +1,1143 @@
1
+ /*!
2
+ * tabbable 6.0.1
3
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
4
+ */
5
+ var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]:not(slot)', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', 'details>summary:first-of-type', 'details'];
6
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
7
+ var NoElement = typeof Element === 'undefined';
8
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
9
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
10
+ return element.getRootNode();
11
+ } : function (element) {
12
+ return element.ownerDocument;
13
+ };
14
+
15
+ /**
16
+ * @param {Element} el container to check in
17
+ * @param {boolean} includeContainer add container to check
18
+ * @param {(node: Element) => boolean} filter filter candidates
19
+ * @returns {Element[]}
20
+ */
21
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
22
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
23
+ if (includeContainer && matches.call(el, candidateSelector)) {
24
+ candidates.unshift(el);
25
+ }
26
+ candidates = candidates.filter(filter);
27
+ return candidates;
28
+ };
29
+
30
+ /**
31
+ * @callback GetShadowRoot
32
+ * @param {Element} element to check for shadow root
33
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
34
+ */
35
+
36
+ /**
37
+ * @callback ShadowRootFilter
38
+ * @param {Element} shadowHostNode the element which contains shadow content
39
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
40
+ */
41
+
42
+ /**
43
+ * @typedef {Object} CandidateScope
44
+ * @property {Element} scopeParent contains inner candidates
45
+ * @property {Element[]} candidates list of candidates found in the scope parent
46
+ */
47
+
48
+ /**
49
+ * @typedef {Object} IterativeOptions
50
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
51
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
52
+ * or a boolean stating if it has an undisclosed shadow root
53
+ * @property {(node: Element) => boolean} filter filter candidates
54
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
55
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
56
+ */
57
+
58
+ /**
59
+ * @param {Element[]} elements list of element containers to match candidates from
60
+ * @param {boolean} includeContainer add container list to check
61
+ * @param {IterativeOptions} options
62
+ * @returns {Array.<Element|CandidateScope>}
63
+ */
64
+ var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
65
+ var candidates = [];
66
+ var elementsToCheck = Array.from(elements);
67
+ while (elementsToCheck.length) {
68
+ var element = elementsToCheck.shift();
69
+ if (element.tagName === 'SLOT') {
70
+ // add shadow dom slot scope (slot itself cannot be focusable)
71
+ var assigned = element.assignedElements();
72
+ var content = assigned.length ? assigned : element.children;
73
+ var nestedCandidates = getCandidatesIteratively(content, true, options);
74
+ if (options.flatten) {
75
+ candidates.push.apply(candidates, nestedCandidates);
76
+ } else {
77
+ candidates.push({
78
+ scopeParent: element,
79
+ candidates: nestedCandidates
80
+ });
81
+ }
82
+ } else {
83
+ // check candidate element
84
+ var validCandidate = matches.call(element, candidateSelector);
85
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
86
+ candidates.push(element);
87
+ }
88
+
89
+ // iterate over shadow content if possible
90
+ var shadowRoot = element.shadowRoot ||
91
+ // check for an undisclosed shadow
92
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
93
+ var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element);
94
+ if (shadowRoot && validShadowRoot) {
95
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
96
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
97
+ // child candidates found because they're likely slotted elements (elements that are
98
+ // children of the web component element (which has the shadow), in the light dom, but
99
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
100
+ // _after_ we return from this recursive call
101
+ var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
102
+ if (options.flatten) {
103
+ candidates.push.apply(candidates, _nestedCandidates);
104
+ } else {
105
+ candidates.push({
106
+ scopeParent: element,
107
+ candidates: _nestedCandidates
108
+ });
109
+ }
110
+ } else {
111
+ // there's not shadow so just dig into the element's (light dom) children
112
+ // __without__ giving the element special scope treatment
113
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
114
+ }
115
+ }
116
+ }
117
+ return candidates;
118
+ };
119
+ var getTabindex = function getTabindex(node, isScope) {
120
+ if (node.tabIndex < 0) {
121
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
122
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
123
+ // yet they are still part of the regular tab order; in FF, they get a default
124
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
125
+ // order, consider their tab index to be 0.
126
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
127
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
128
+ //
129
+ // isScope is positive for custom element with shadow root or slot that by default
130
+ // have tabIndex -1, but need to be sorted by document order in order for their
131
+ // content to be inserted in the correct position
132
+ if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute('tabindex'), 10))) {
133
+ return 0;
134
+ }
135
+ }
136
+ return node.tabIndex;
137
+ };
138
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
139
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
140
+ };
141
+ var isInput = function isInput(node) {
142
+ return node.tagName === 'INPUT';
143
+ };
144
+ var isHiddenInput = function isHiddenInput(node) {
145
+ return isInput(node) && node.type === 'hidden';
146
+ };
147
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
148
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
149
+ return child.tagName === 'SUMMARY';
150
+ });
151
+ return r;
152
+ };
153
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
154
+ for (var i = 0; i < nodes.length; i++) {
155
+ if (nodes[i].checked && nodes[i].form === form) {
156
+ return nodes[i];
157
+ }
158
+ }
159
+ };
160
+ var isTabbableRadio = function isTabbableRadio(node) {
161
+ if (!node.name) {
162
+ return true;
163
+ }
164
+ var radioScope = node.form || getRootNode(node);
165
+ var queryRadios = function queryRadios(name) {
166
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
167
+ };
168
+ var radioSet;
169
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
170
+ radioSet = queryRadios(window.CSS.escape(node.name));
171
+ } else {
172
+ try {
173
+ radioSet = queryRadios(node.name);
174
+ } catch (err) {
175
+ // eslint-disable-next-line no-console
176
+ 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);
177
+ return false;
178
+ }
179
+ }
180
+ var checked = getCheckedRadio(radioSet, node.form);
181
+ return !checked || checked === node;
182
+ };
183
+ var isRadio = function isRadio(node) {
184
+ return isInput(node) && node.type === 'radio';
185
+ };
186
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
187
+ return isRadio(node) && !isTabbableRadio(node);
188
+ };
189
+
190
+ // determines if a node is ultimately attached to the window's document
191
+ var isNodeAttached = function isNodeAttached(node) {
192
+ var _nodeRootHost;
193
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
194
+ // (but NOT _the_ document; see second 'If' comment below for more).
195
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
196
+ // is attached, and the one we need to check if it's in the document or not (because the
197
+ // shadow, and all nodes it contains, is never considered in the document since shadows
198
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
199
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
200
+ // visibility, including all the nodes it contains). The host could be any normal node,
201
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
202
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
203
+ // tested).
204
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
205
+ // that is attached (or find none) because the node might be in nested shadows...
206
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
207
+ // document (per the docs) and while it's a Document-type object, that document does not
208
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
209
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
210
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
211
+ // node is actually detached.
212
+ var nodeRootHost = getRootNode(node).host;
213
+ var attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && _nodeRootHost.ownerDocument.contains(nodeRootHost) || node.ownerDocument.contains(node));
214
+ while (!attached && nodeRootHost) {
215
+ var _nodeRootHost2;
216
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
217
+ // which means we need to get the host's host and check if that parent host is contained
218
+ // in (i.e. attached to) the document
219
+ nodeRootHost = getRootNode(nodeRootHost).host;
220
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && _nodeRootHost2.ownerDocument.contains(nodeRootHost));
221
+ }
222
+ return attached;
223
+ };
224
+ var isZeroArea = function isZeroArea(node) {
225
+ var _node$getBoundingClie = node.getBoundingClientRect(),
226
+ width = _node$getBoundingClie.width,
227
+ height = _node$getBoundingClie.height;
228
+ return width === 0 && height === 0;
229
+ };
230
+ var isHidden = function isHidden(node, _ref) {
231
+ var displayCheck = _ref.displayCheck,
232
+ getShadowRoot = _ref.getShadowRoot;
233
+ // NOTE: visibility will be `undefined` if node is detached from the document
234
+ // (see notes about this further down), which means we will consider it visible
235
+ // (this is legacy behavior from a very long way back)
236
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
237
+ // _visibility_ check, not a _display_ check
238
+ if (getComputedStyle(node).visibility === 'hidden') {
239
+ return true;
240
+ }
241
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
242
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
243
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
244
+ return true;
245
+ }
246
+ if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
247
+ if (typeof getShadowRoot === 'function') {
248
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
249
+ // 'non-zero-area' fallback
250
+ var originalNode = node;
251
+ while (node) {
252
+ var parentElement = node.parentElement;
253
+ var rootNode = getRootNode(node);
254
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
255
+ ) {
256
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
257
+ // fall back to a non-zero-area test
258
+ return isZeroArea(node);
259
+ } else if (node.assignedSlot) {
260
+ // iterate up slot
261
+ node = node.assignedSlot;
262
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
263
+ // cross shadow boundary
264
+ node = rootNode.host;
265
+ } else {
266
+ // iterate up normal dom
267
+ node = parentElement;
268
+ }
269
+ }
270
+ node = originalNode;
271
+ }
272
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
273
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
274
+ // it might be a falsy value, which means shadow DOM support is disabled
275
+
276
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
277
+ // now we can just test to see if it would normally be visible or not, provided it's
278
+ // attached to the main document.
279
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
280
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
281
+
282
+ if (isNodeAttached(node)) {
283
+ // this works wherever the node is: if there's at least one client rect, it's
284
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
285
+ // node itself is hidden in place of its contents; and there's no need to search
286
+ // up the hierarchy either
287
+ return !node.getClientRects().length;
288
+ }
289
+
290
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
291
+ // API will __always__ return zero rects (this can happen, for example, if React
292
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
293
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
294
+ //
295
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
296
+ // because styles are only computed for nodes that are in the document.
297
+ //
298
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
299
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
300
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
301
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
302
+ // considering __everything__ to be visible because of the innability to determine styles.
303
+ //
304
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
305
+ // nodes as visible with the 'none' fallback.__
306
+ if (displayCheck !== 'legacy-full') {
307
+ return true; // hidden
308
+ }
309
+ // else, fallback to 'none' mode and consider the node visible
310
+ } else if (displayCheck === 'non-zero-area') {
311
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
312
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
313
+ // client rect, we don't special-case for whether the node is attached or not. In
314
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
315
+ // times, and that includes attached or not.
316
+ return isZeroArea(node);
317
+ }
318
+
319
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
320
+ // it's visible
321
+ return false;
322
+ };
323
+
324
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
325
+ // unless they are in the _first_ <legend> element of the top-most disabled
326
+ // fieldset
327
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
328
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
329
+ var parentNode = node.parentElement;
330
+ // check if `node` is contained in a disabled <fieldset>
331
+ while (parentNode) {
332
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
333
+ // look for the first <legend> among the children of the disabled <fieldset>
334
+ for (var i = 0; i < parentNode.children.length; i++) {
335
+ var child = parentNode.children.item(i);
336
+ // when the first <legend> (in document order) is found
337
+ if (child.tagName === 'LEGEND') {
338
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
339
+ // return whether `node` is a descendant of its first <legend>
340
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
341
+ }
342
+ }
343
+ // the disabled <fieldset> containing `node` has no <legend>
344
+ return true;
345
+ }
346
+ parentNode = parentNode.parentElement;
347
+ }
348
+ }
349
+
350
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
351
+ // enabled/disabled state
352
+ return false;
353
+ };
354
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
355
+ if (node.disabled || isHiddenInput(node) || isHidden(node, options) ||
356
+ // For a details element with a summary, the summary element gets the focus
357
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
358
+ return false;
359
+ }
360
+ return true;
361
+ };
362
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
363
+ if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
364
+ return false;
365
+ }
366
+ return true;
367
+ };
368
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
369
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
370
+ if (isNaN(tabIndex) || tabIndex >= 0) {
371
+ return true;
372
+ }
373
+ // If a custom element has an explicit negative tabindex,
374
+ // browsers will not allow tab targeting said element's children.
375
+ return false;
376
+ };
377
+
378
+ /**
379
+ * @param {Array.<Element|CandidateScope>} candidates
380
+ * @returns Element[]
381
+ */
382
+ var sortByOrder = function sortByOrder(candidates) {
383
+ var regularTabbables = [];
384
+ var orderedTabbables = [];
385
+ candidates.forEach(function (item, i) {
386
+ var isScope = !!item.scopeParent;
387
+ var element = isScope ? item.scopeParent : item;
388
+ var candidateTabindex = getTabindex(element, isScope);
389
+ var elements = isScope ? sortByOrder(item.candidates) : element;
390
+ if (candidateTabindex === 0) {
391
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
392
+ } else {
393
+ orderedTabbables.push({
394
+ documentOrder: i,
395
+ tabIndex: candidateTabindex,
396
+ item: item,
397
+ isScope: isScope,
398
+ content: elements
399
+ });
400
+ }
401
+ });
402
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
403
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
404
+ return acc;
405
+ }, []).concat(regularTabbables);
406
+ };
407
+ var tabbable = function tabbable(el, options) {
408
+ options = options || {};
409
+ var candidates;
410
+ if (options.getShadowRoot) {
411
+ candidates = getCandidatesIteratively([el], options.includeContainer, {
412
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
413
+ flatten: false,
414
+ getShadowRoot: options.getShadowRoot,
415
+ shadowRootFilter: isValidShadowRootTabbable
416
+ });
417
+ } else {
418
+ candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
419
+ }
420
+ return sortByOrder(candidates);
421
+ };
422
+ var focusable = function focusable(el, options) {
423
+ options = options || {};
424
+ var candidates;
425
+ if (options.getShadowRoot) {
426
+ candidates = getCandidatesIteratively([el], options.includeContainer, {
427
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
428
+ flatten: true,
429
+ getShadowRoot: options.getShadowRoot
430
+ });
431
+ } else {
432
+ candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
433
+ }
434
+ return candidates;
435
+ };
436
+ var isTabbable = function isTabbable(node, options) {
437
+ options = options || {};
438
+ if (!node) {
439
+ throw new Error('No node provided');
440
+ }
441
+ if (matches.call(node, candidateSelector) === false) {
442
+ return false;
443
+ }
444
+ return isNodeMatchingSelectorTabbable(options, node);
445
+ };
446
+ var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
447
+ var isFocusable = function isFocusable(node, options) {
448
+ options = options || {};
449
+ if (!node) {
450
+ throw new Error('No node provided');
451
+ }
452
+ if (matches.call(node, focusableCandidateSelector) === false) {
453
+ return false;
454
+ }
455
+ return isNodeMatchingSelectorFocusable(options, node);
456
+ };
457
+
458
+ /*!
459
+ * focus-trap 7.1.0
460
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
461
+ */
462
+
463
+ function ownKeys(object, enumerableOnly) {
464
+ var keys = Object.keys(object);
465
+ if (Object.getOwnPropertySymbols) {
466
+ var symbols = Object.getOwnPropertySymbols(object);
467
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
468
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
469
+ })), keys.push.apply(keys, symbols);
470
+ }
471
+ return keys;
472
+ }
473
+ function _objectSpread2(target) {
474
+ for (var i = 1; i < arguments.length; i++) {
475
+ var source = null != arguments[i] ? arguments[i] : {};
476
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
477
+ _defineProperty(target, key, source[key]);
478
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
479
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
480
+ });
481
+ }
482
+ return target;
483
+ }
484
+ function _defineProperty(obj, key, value) {
485
+ if (key in obj) {
486
+ Object.defineProperty(obj, key, {
487
+ value: value,
488
+ enumerable: true,
489
+ configurable: true,
490
+ writable: true
491
+ });
492
+ } else {
493
+ obj[key] = value;
494
+ }
495
+ return obj;
496
+ }
497
+
498
+ var rooTrapStack = [];
499
+ var activeFocusTraps = {
500
+ activateTrap: function activateTrap(trapStack, trap) {
501
+ if (trapStack.length > 0) {
502
+ var activeTrap = trapStack[trapStack.length - 1];
503
+ if (activeTrap !== trap) {
504
+ activeTrap.pause();
505
+ }
506
+ }
507
+ var trapIndex = trapStack.indexOf(trap);
508
+ if (trapIndex === -1) {
509
+ trapStack.push(trap);
510
+ } else {
511
+ // move this existing trap to the front of the queue
512
+ trapStack.splice(trapIndex, 1);
513
+ trapStack.push(trap);
514
+ }
515
+ },
516
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
517
+ var trapIndex = trapStack.indexOf(trap);
518
+ if (trapIndex !== -1) {
519
+ trapStack.splice(trapIndex, 1);
520
+ }
521
+ if (trapStack.length > 0) {
522
+ trapStack[trapStack.length - 1].unpause();
523
+ }
524
+ }
525
+ };
526
+ var isSelectableInput = function isSelectableInput(node) {
527
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
528
+ };
529
+ var isEscapeEvent = function isEscapeEvent(e) {
530
+ return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;
531
+ };
532
+ var isTabEvent = function isTabEvent(e) {
533
+ return e.key === 'Tab' || e.keyCode === 9;
534
+ };
535
+ var delay = function delay(fn) {
536
+ return setTimeout(fn, 0);
537
+ };
538
+
539
+ // Array.find/findIndex() are not supported on IE; this replicates enough
540
+ // of Array.findIndex() for our needs
541
+ var findIndex = function findIndex(arr, fn) {
542
+ var idx = -1;
543
+ arr.every(function (value, i) {
544
+ if (fn(value)) {
545
+ idx = i;
546
+ return false; // break
547
+ }
548
+
549
+ return true; // next
550
+ });
551
+
552
+ return idx;
553
+ };
554
+
555
+ /**
556
+ * Get an option's value when it could be a plain value, or a handler that provides
557
+ * the value.
558
+ * @param {*} value Option's value to check.
559
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
560
+ * @returns {*} The `value`, or the handler's returned value.
561
+ */
562
+ var valueOrHandler = function valueOrHandler(value) {
563
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
564
+ params[_key - 1] = arguments[_key];
565
+ }
566
+ return typeof value === 'function' ? value.apply(void 0, params) : value;
567
+ };
568
+ var getActualTarget = function getActualTarget(event) {
569
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
570
+ // shadow host. However, event.target.composedPath() will be an array of
571
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
572
+ // outer-most (the host HTML document). If we have access to composedPath(),
573
+ // then use its first element; otherwise, fall back to event.target (and
574
+ // this only works for an _open_ shadow DOM; otherwise,
575
+ // composedPath()[0] === event.target always).
576
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
577
+ };
578
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
579
+ // SSR: a live trap shouldn't be created in this type of environment so this
580
+ // should be safe code to execute if the `document` option isn't specified
581
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
582
+ var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || rooTrapStack;
583
+ var config = _objectSpread2({
584
+ returnFocusOnDeactivate: true,
585
+ escapeDeactivates: true,
586
+ delayInitialFocus: true
587
+ }, userOptions);
588
+ var state = {
589
+ // containers given to createFocusTrap()
590
+ // @type {Array<HTMLElement>}
591
+ containers: [],
592
+ // list of objects identifying tabbable nodes in `containers` in the trap
593
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
594
+ // is active, but the trap should never get to a state where there isn't at least one group
595
+ // with at least one tabbable node in it (that would lead to an error condition that would
596
+ // result in an error being thrown)
597
+ // @type {Array<{
598
+ // container: HTMLElement,
599
+ // tabbableNodes: Array<HTMLElement>, // empty if none
600
+ // focusableNodes: Array<HTMLElement>, // empty if none
601
+ // firstTabbableNode: HTMLElement|null,
602
+ // lastTabbableNode: HTMLElement|null,
603
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
604
+ // }>}
605
+ containerGroups: [],
606
+ // same order/length as `containers` list
607
+
608
+ // references to objects in `containerGroups`, but only those that actually have
609
+ // tabbable nodes in them
610
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
611
+ // the same length
612
+ tabbableGroups: [],
613
+ nodeFocusedBeforeActivation: null,
614
+ mostRecentlyFocusedNode: null,
615
+ active: false,
616
+ paused: false,
617
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
618
+ // has been delayed during activation
619
+ delayInitialFocusTimer: undefined
620
+ };
621
+ 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
622
+
623
+ /**
624
+ * Gets a configuration option value.
625
+ * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
626
+ * value will be taken from this object. Otherwise, value will be taken from base configuration.
627
+ * @param {string} optionName Name of the option whose value is sought.
628
+ * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
629
+ * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
630
+ */
631
+ var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
632
+ return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
633
+ };
634
+
635
+ /**
636
+ * Finds the index of the container that contains the element.
637
+ * @param {HTMLElement} element
638
+ * @returns {number} Index of the container in either `state.containers` or
639
+ * `state.containerGroups` (the order/length of these lists are the same); -1
640
+ * if the element isn't found.
641
+ */
642
+ var findContainerIndex = function findContainerIndex(element) {
643
+ // NOTE: search `containerGroups` because it's possible a group contains no tabbable
644
+ // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
645
+ // and we still need to find the element in there
646
+ return state.containerGroups.findIndex(function (_ref) {
647
+ var container = _ref.container,
648
+ tabbableNodes = _ref.tabbableNodes;
649
+ return container.contains(element) ||
650
+ // fall back to explicit tabbable search which will take into consideration any
651
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
652
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
653
+ // look inside web components even if open)
654
+ tabbableNodes.find(function (node) {
655
+ return node === element;
656
+ });
657
+ });
658
+ };
659
+
660
+ /**
661
+ * Gets the node for the given option, which is expected to be an option that
662
+ * can be either a DOM node, a string that is a selector to get a node, `false`
663
+ * (if a node is explicitly NOT given), or a function that returns any of these
664
+ * values.
665
+ * @param {string} optionName
666
+ * @returns {undefined | false | HTMLElement | SVGElement} Returns
667
+ * `undefined` if the option is not specified; `false` if the option
668
+ * resolved to `false` (node explicitly not given); otherwise, the resolved
669
+ * DOM node.
670
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
671
+ * resolve to a node.
672
+ */
673
+ var getNodeForOption = function getNodeForOption(optionName) {
674
+ var optionValue = config[optionName];
675
+ if (typeof optionValue === 'function') {
676
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
677
+ params[_key2 - 1] = arguments[_key2];
678
+ }
679
+ optionValue = optionValue.apply(void 0, params);
680
+ }
681
+ if (optionValue === true) {
682
+ optionValue = undefined; // use default value
683
+ }
684
+
685
+ if (!optionValue) {
686
+ if (optionValue === undefined || optionValue === false) {
687
+ return optionValue;
688
+ }
689
+ // else, empty string (invalid), null (invalid), 0 (invalid)
690
+
691
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
692
+ }
693
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
694
+
695
+ if (typeof optionValue === 'string') {
696
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
697
+ if (!node) {
698
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
699
+ }
700
+ }
701
+ return node;
702
+ };
703
+ var getInitialFocusNode = function getInitialFocusNode() {
704
+ var node = getNodeForOption('initialFocus');
705
+
706
+ // false explicitly indicates we want no initialFocus at all
707
+ if (node === false) {
708
+ return false;
709
+ }
710
+ if (node === undefined) {
711
+ // option not specified: use fallback options
712
+ if (findContainerIndex(doc.activeElement) >= 0) {
713
+ node = doc.activeElement;
714
+ } else {
715
+ var firstTabbableGroup = state.tabbableGroups[0];
716
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
717
+
718
+ // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
719
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
720
+ }
721
+ }
722
+ if (!node) {
723
+ throw new Error('Your focus-trap needs to have at least one focusable element');
724
+ }
725
+ return node;
726
+ };
727
+ var updateTabbableNodes = function updateTabbableNodes() {
728
+ state.containerGroups = state.containers.map(function (container) {
729
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
730
+
731
+ // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
732
+ // are a superset of tabbable nodes
733
+ var focusableNodes = focusable(container, config.tabbableOptions);
734
+ return {
735
+ container: container,
736
+ tabbableNodes: tabbableNodes,
737
+ focusableNodes: focusableNodes,
738
+ firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null,
739
+ lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null,
740
+ /**
741
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
742
+ * in this container, if any.
743
+ * @param {HTMLElement} node
744
+ * @param {boolean} [forward] True if going in forward tab order; false if going
745
+ * in reverse.
746
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
747
+ */
748
+ nextTabbableNode: function nextTabbableNode(node) {
749
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
750
+ // NOTE: If tabindex is positive (in order to manipulate the tab order separate
751
+ // from the DOM order), this __will not work__ because the list of focusableNodes,
752
+ // while it contains tabbable nodes, does not sort its nodes in any order other
753
+ // than DOM order, because it can't: Where would you place focusable (but not
754
+ // tabbable) nodes in that order? They have no order, because they aren't tabbale...
755
+ // Support for positive tabindex is already broken and hard to manage (possibly
756
+ // not supportable, TBD), so this isn't going to make things worse than they
757
+ // already are, and at least makes things better for the majority of cases where
758
+ // tabindex is either 0/unset or negative.
759
+ // FYI, positive tabindex issue: https://github.com/focus-trap/focus-trap/issues/375
760
+ var nodeIdx = focusableNodes.findIndex(function (n) {
761
+ return n === node;
762
+ });
763
+ if (nodeIdx < 0) {
764
+ return undefined;
765
+ }
766
+ if (forward) {
767
+ return focusableNodes.slice(nodeIdx + 1).find(function (n) {
768
+ return isTabbable(n, config.tabbableOptions);
769
+ });
770
+ }
771
+ return focusableNodes.slice(0, nodeIdx).reverse().find(function (n) {
772
+ return isTabbable(n, config.tabbableOptions);
773
+ });
774
+ }
775
+ };
776
+ });
777
+ state.tabbableGroups = state.containerGroups.filter(function (group) {
778
+ return group.tabbableNodes.length > 0;
779
+ });
780
+
781
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
782
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
783
+ ) {
784
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
785
+ }
786
+ };
787
+ var tryFocus = function tryFocus(node) {
788
+ if (node === false) {
789
+ return;
790
+ }
791
+ if (node === doc.activeElement) {
792
+ return;
793
+ }
794
+ if (!node || !node.focus) {
795
+ tryFocus(getInitialFocusNode());
796
+ return;
797
+ }
798
+ node.focus({
799
+ preventScroll: !!config.preventScroll
800
+ });
801
+ state.mostRecentlyFocusedNode = node;
802
+ if (isSelectableInput(node)) {
803
+ node.select();
804
+ }
805
+ };
806
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
807
+ var node = getNodeForOption('setReturnFocus', previousActiveElement);
808
+ return node ? node : node === false ? false : previousActiveElement;
809
+ };
810
+
811
+ // This needs to be done on mousedown and touchstart instead of click
812
+ // so that it precedes the focus event.
813
+ var checkPointerDown = function checkPointerDown(e) {
814
+ var target = getActualTarget(e);
815
+ if (findContainerIndex(target) >= 0) {
816
+ // allow the click since it ocurred inside the trap
817
+ return;
818
+ }
819
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
820
+ // immediately deactivate the trap
821
+ trap.deactivate({
822
+ // if, on deactivation, we should return focus to the node originally-focused
823
+ // when the trap was activated (or the configured `setReturnFocus` node),
824
+ // then assume it's also OK to return focus to the outside node that was
825
+ // just clicked, causing deactivation, as long as that node is focusable;
826
+ // if it isn't focusable, then return focus to the original node focused
827
+ // on activation (or the configured `setReturnFocus` node)
828
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
829
+ // which will result in the outside click setting focus to the node
830
+ // that was clicked, whether it's focusable or not; by setting
831
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
832
+ // on activation (or the configured `setReturnFocus` node)
833
+ returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions)
834
+ });
835
+ return;
836
+ }
837
+
838
+ // This is needed for mobile devices.
839
+ // (If we'll only let `click` events through,
840
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
841
+ if (valueOrHandler(config.allowOutsideClick, e)) {
842
+ // allow the click outside the trap to take place
843
+ return;
844
+ }
845
+
846
+ // otherwise, prevent the click
847
+ e.preventDefault();
848
+ };
849
+
850
+ // In case focus escapes the trap for some strange reason, pull it back in.
851
+ var checkFocusIn = function checkFocusIn(e) {
852
+ var target = getActualTarget(e);
853
+ var targetContained = findContainerIndex(target) >= 0;
854
+
855
+ // In Firefox when you Tab out of an iframe the Document is briefly focused.
856
+ if (targetContained || target instanceof Document) {
857
+ if (targetContained) {
858
+ state.mostRecentlyFocusedNode = target;
859
+ }
860
+ } else {
861
+ // escaped! pull it back in to where it just left
862
+ e.stopImmediatePropagation();
863
+ tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
864
+ }
865
+ };
866
+
867
+ // Hijack Tab events on the first and last focusable nodes of the trap,
868
+ // in order to prevent focus from escaping. If it escapes for even a
869
+ // moment it can end up scrolling the page and causing confusion so we
870
+ // kind of need to capture the action at the keydown phase.
871
+ var checkTab = function checkTab(e) {
872
+ var target = getActualTarget(e);
873
+ updateTabbableNodes();
874
+ var destinationNode = null;
875
+ if (state.tabbableGroups.length > 0) {
876
+ // make sure the target is actually contained in a group
877
+ // NOTE: the target may also be the container itself if it's focusable
878
+ // with tabIndex='-1' and was given initial focus
879
+ var containerIndex = findContainerIndex(target);
880
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
881
+ if (containerIndex < 0) {
882
+ // target not found in any group: quite possible focus has escaped the trap,
883
+ // so bring it back in to...
884
+ if (e.shiftKey) {
885
+ // ...the last node in the last group
886
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
887
+ } else {
888
+ // ...the first node in the first group
889
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
890
+ }
891
+ } else if (e.shiftKey) {
892
+ // REVERSE
893
+
894
+ // is the target the first tabbable node in a group?
895
+ var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
896
+ var firstTabbableNode = _ref2.firstTabbableNode;
897
+ return target === firstTabbableNode;
898
+ });
899
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
900
+ // an exception case where the target is either the container itself, or
901
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
902
+ // and user clicked on it or node was programmatically given focus)
903
+ // and is not followed by any other tabbable node, in which
904
+ // case, we should handle shift+tab as if focus were on the container's
905
+ // first tabbable node, and go to the last tabbable node of the LAST group
906
+ startOfGroupIndex = containerIndex;
907
+ }
908
+ if (startOfGroupIndex >= 0) {
909
+ // YES: then shift+tab should go to the last tabbable node in the
910
+ // previous group (and wrap around to the last tabbable node of
911
+ // the LAST group if it's the first tabbable node of the FIRST group)
912
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
913
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
914
+ destinationNode = destinationGroup.lastTabbableNode;
915
+ }
916
+ } else {
917
+ // FORWARD
918
+
919
+ // is the target the last tabbable node in a group?
920
+ var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
921
+ var lastTabbableNode = _ref3.lastTabbableNode;
922
+ return target === lastTabbableNode;
923
+ });
924
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
925
+ // an exception case where the target is the container itself, or
926
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
927
+ // and user clicked on it or node was programmatically given focus)
928
+ // and is not followed by any other tabbable node, in which
929
+ // case, we should handle tab as if focus were on the container's
930
+ // last tabbable node, and go to the first tabbable node of the FIRST group
931
+ lastOfGroupIndex = containerIndex;
932
+ }
933
+ if (lastOfGroupIndex >= 0) {
934
+ // YES: then tab should go to the first tabbable node in the next
935
+ // group (and wrap around to the first tabbable node of the FIRST
936
+ // group if it's the last tabbable node of the LAST group)
937
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
938
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
939
+ destinationNode = _destinationGroup.firstTabbableNode;
940
+ }
941
+ }
942
+ } else {
943
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
944
+ destinationNode = getNodeForOption('fallbackFocus');
945
+ }
946
+ if (destinationNode) {
947
+ e.preventDefault();
948
+ tryFocus(destinationNode);
949
+ }
950
+ // else, let the browser take care of [shift+]tab and move the focus
951
+ };
952
+
953
+ var checkKey = function checkKey(e) {
954
+ if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) {
955
+ e.preventDefault();
956
+ trap.deactivate();
957
+ return;
958
+ }
959
+ if (isTabEvent(e)) {
960
+ checkTab(e);
961
+ return;
962
+ }
963
+ };
964
+ var checkClick = function checkClick(e) {
965
+ var target = getActualTarget(e);
966
+ if (findContainerIndex(target) >= 0) {
967
+ return;
968
+ }
969
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
970
+ return;
971
+ }
972
+ if (valueOrHandler(config.allowOutsideClick, e)) {
973
+ return;
974
+ }
975
+ e.preventDefault();
976
+ e.stopImmediatePropagation();
977
+ };
978
+
979
+ //
980
+ // EVENT LISTENERS
981
+ //
982
+
983
+ var addListeners = function addListeners() {
984
+ if (!state.active) {
985
+ return;
986
+ }
987
+
988
+ // There can be only one listening focus trap at a time
989
+ activeFocusTraps.activateTrap(trapStack, trap);
990
+
991
+ // Delay ensures that the focused element doesn't capture the event
992
+ // that caused the focus trap activation.
993
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
994
+ tryFocus(getInitialFocusNode());
995
+ }) : tryFocus(getInitialFocusNode());
996
+ doc.addEventListener('focusin', checkFocusIn, true);
997
+ doc.addEventListener('mousedown', checkPointerDown, {
998
+ capture: true,
999
+ passive: false
1000
+ });
1001
+ doc.addEventListener('touchstart', checkPointerDown, {
1002
+ capture: true,
1003
+ passive: false
1004
+ });
1005
+ doc.addEventListener('click', checkClick, {
1006
+ capture: true,
1007
+ passive: false
1008
+ });
1009
+ doc.addEventListener('keydown', checkKey, {
1010
+ capture: true,
1011
+ passive: false
1012
+ });
1013
+ return trap;
1014
+ };
1015
+ var removeListeners = function removeListeners() {
1016
+ if (!state.active) {
1017
+ return;
1018
+ }
1019
+ doc.removeEventListener('focusin', checkFocusIn, true);
1020
+ doc.removeEventListener('mousedown', checkPointerDown, true);
1021
+ doc.removeEventListener('touchstart', checkPointerDown, true);
1022
+ doc.removeEventListener('click', checkClick, true);
1023
+ doc.removeEventListener('keydown', checkKey, true);
1024
+ return trap;
1025
+ };
1026
+
1027
+ //
1028
+ // TRAP DEFINITION
1029
+ //
1030
+
1031
+ trap = {
1032
+ get active() {
1033
+ return state.active;
1034
+ },
1035
+ get paused() {
1036
+ return state.paused;
1037
+ },
1038
+ activate: function activate(activateOptions) {
1039
+ if (state.active) {
1040
+ return this;
1041
+ }
1042
+ var onActivate = getOption(activateOptions, 'onActivate');
1043
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
1044
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1045
+ if (!checkCanFocusTrap) {
1046
+ updateTabbableNodes();
1047
+ }
1048
+ state.active = true;
1049
+ state.paused = false;
1050
+ state.nodeFocusedBeforeActivation = doc.activeElement;
1051
+ if (onActivate) {
1052
+ onActivate();
1053
+ }
1054
+ var finishActivation = function finishActivation() {
1055
+ if (checkCanFocusTrap) {
1056
+ updateTabbableNodes();
1057
+ }
1058
+ addListeners();
1059
+ if (onPostActivate) {
1060
+ onPostActivate();
1061
+ }
1062
+ };
1063
+ if (checkCanFocusTrap) {
1064
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1065
+ return this;
1066
+ }
1067
+ finishActivation();
1068
+ return this;
1069
+ },
1070
+ deactivate: function deactivate(deactivateOptions) {
1071
+ if (!state.active) {
1072
+ return this;
1073
+ }
1074
+ var options = _objectSpread2({
1075
+ onDeactivate: config.onDeactivate,
1076
+ onPostDeactivate: config.onPostDeactivate,
1077
+ checkCanReturnFocus: config.checkCanReturnFocus
1078
+ }, deactivateOptions);
1079
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1080
+ state.delayInitialFocusTimer = undefined;
1081
+ removeListeners();
1082
+ state.active = false;
1083
+ state.paused = false;
1084
+ activeFocusTraps.deactivateTrap(trapStack, trap);
1085
+ var onDeactivate = getOption(options, 'onDeactivate');
1086
+ var onPostDeactivate = getOption(options, 'onPostDeactivate');
1087
+ var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1088
+ var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1089
+ if (onDeactivate) {
1090
+ onDeactivate();
1091
+ }
1092
+ var finishDeactivation = function finishDeactivation() {
1093
+ delay(function () {
1094
+ if (returnFocus) {
1095
+ tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1096
+ }
1097
+ if (onPostDeactivate) {
1098
+ onPostDeactivate();
1099
+ }
1100
+ });
1101
+ };
1102
+ if (returnFocus && checkCanReturnFocus) {
1103
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1104
+ return this;
1105
+ }
1106
+ finishDeactivation();
1107
+ return this;
1108
+ },
1109
+ pause: function pause() {
1110
+ if (state.paused || !state.active) {
1111
+ return this;
1112
+ }
1113
+ state.paused = true;
1114
+ removeListeners();
1115
+ return this;
1116
+ },
1117
+ unpause: function unpause() {
1118
+ if (!state.paused || !state.active) {
1119
+ return this;
1120
+ }
1121
+ state.paused = false;
1122
+ updateTabbableNodes();
1123
+ addListeners();
1124
+ return this;
1125
+ },
1126
+ updateContainerElements: function updateContainerElements(containerElements) {
1127
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1128
+ state.containers = elementsAsArray.map(function (element) {
1129
+ return typeof element === 'string' ? doc.querySelector(element) : element;
1130
+ });
1131
+ if (state.active) {
1132
+ updateTabbableNodes();
1133
+ }
1134
+ return this;
1135
+ }
1136
+ };
1137
+
1138
+ // initialize container elements
1139
+ trap.updateContainerElements(elements);
1140
+ return trap;
1141
+ };
1142
+
1143
+ export { createFocusTrap as c };