@ai-ecoverse/slicc-spectrum 0.0.0 → 1.1.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 (87) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +173 -5
  3. package/dist/chunk-24WRGUXG.js +168 -0
  4. package/dist/chunk-24WRGUXG.js.map +7 -0
  5. package/dist/chunk-364Y2XOJ.js +28 -0
  6. package/dist/chunk-364Y2XOJ.js.map +7 -0
  7. package/dist/chunk-4RGMMAR4.js +18 -0
  8. package/dist/chunk-4RGMMAR4.js.map +7 -0
  9. package/dist/chunk-5OVGH7HO.js +28 -0
  10. package/dist/chunk-5OVGH7HO.js.map +7 -0
  11. package/dist/chunk-6A6NIESE.js +9 -0
  12. package/dist/chunk-6A6NIESE.js.map +7 -0
  13. package/dist/chunk-EN3XGF2M.js +26 -0
  14. package/dist/chunk-EN3XGF2M.js.map +7 -0
  15. package/dist/chunk-ER3HU7OE.js +22 -0
  16. package/dist/chunk-ER3HU7OE.js.map +7 -0
  17. package/dist/chunk-FN3Y2AYJ.js +17 -0
  18. package/dist/chunk-FN3Y2AYJ.js.map +7 -0
  19. package/dist/chunk-H5WU2XYY.js +8 -0
  20. package/dist/chunk-H5WU2XYY.js.map +7 -0
  21. package/dist/chunk-HBUX7E54.js +234 -0
  22. package/dist/chunk-HBUX7E54.js.map +7 -0
  23. package/dist/chunk-IBQ4O4NO.js +13 -0
  24. package/dist/chunk-IBQ4O4NO.js.map +7 -0
  25. package/dist/chunk-J45KH7MF.js +180 -0
  26. package/dist/chunk-J45KH7MF.js.map +7 -0
  27. package/dist/chunk-JASEW37G.js +411 -0
  28. package/dist/chunk-JASEW37G.js.map +7 -0
  29. package/dist/chunk-MR7SU4GJ.js +59 -0
  30. package/dist/chunk-MR7SU4GJ.js.map +7 -0
  31. package/dist/chunk-MTF6JFSL.js +1093 -0
  32. package/dist/chunk-MTF6JFSL.js.map +7 -0
  33. package/dist/chunk-Q4AC2O6Z.js +13 -0
  34. package/dist/chunk-Q4AC2O6Z.js.map +7 -0
  35. package/dist/chunk-SZ33GAVH.js +2638 -0
  36. package/dist/chunk-SZ33GAVH.js.map +7 -0
  37. package/dist/chunk-T5NHW4KC.js +23 -0
  38. package/dist/chunk-T5NHW4KC.js.map +7 -0
  39. package/dist/chunk-T5QFSUYQ.js +8 -0
  40. package/dist/chunk-T5QFSUYQ.js.map +7 -0
  41. package/dist/chunk-TS7SL372.js +687 -0
  42. package/dist/chunk-TS7SL372.js.map +7 -0
  43. package/dist/chunk-Y4Z7K443.js +64 -0
  44. package/dist/chunk-Y4Z7K443.js.map +7 -0
  45. package/dist/chunk-ZMBN6APP.js +11 -0
  46. package/dist/chunk-ZMBN6APP.js.map +7 -0
  47. package/dist/chunk-ZTPYBVZL.js +181 -0
  48. package/dist/chunk-ZTPYBVZL.js.map +7 -0
  49. package/dist/fonts/source-code-pro-latin-400-normal.woff2 +0 -0
  50. package/dist/fonts/source-code-pro-latin-600-normal.woff2 +0 -0
  51. package/dist/slicc-dummy.js +1393 -0
  52. package/dist/slicc-dummy.js.map +7 -0
  53. package/dist/slicc-terminal.js +5377 -0
  54. package/dist/slicc-terminal.js.map +7 -0
  55. package/dist/slicc-ui.js +22441 -0
  56. package/dist/slicc-ui.js.map +7 -0
  57. package/dist/types/app/agents.d.ts +11 -0
  58. package/dist/types/app/app.d.ts +40 -0
  59. package/dist/types/app/base.d.ts +27 -0
  60. package/dist/types/app/chat.d.ts +23 -0
  61. package/dist/types/app/fonts.d.ts +3 -0
  62. package/dist/types/app/markdown.d.ts +24 -0
  63. package/dist/types/app/panels.d.ts +31 -0
  64. package/dist/types/app/spectrum.d.ts +19 -0
  65. package/dist/types/backend.d.ts +19 -0
  66. package/dist/types/components/dock.d.ts +24 -0
  67. package/dist/types/components/sheets.d.ts +1 -0
  68. package/dist/types/dummy/agent.d.ts +14 -0
  69. package/dist/types/dummy/browser.d.ts +15 -0
  70. package/dist/types/dummy/clock.d.ts +5 -0
  71. package/dist/types/dummy/files.d.ts +14 -0
  72. package/dist/types/dummy/fixtures.d.ts +11 -0
  73. package/dist/types/dummy/index.d.ts +6 -0
  74. package/dist/types/dummy/script.d.ts +23 -0
  75. package/dist/types/dummy/settings.d.ts +13 -0
  76. package/dist/types/dummy/shell.d.ts +16 -0
  77. package/dist/types/dummy/terminals.d.ts +15 -0
  78. package/dist/types/dummy.d.ts +2 -0
  79. package/dist/types/index.d.ts +4 -0
  80. package/dist/types/kernel-backend.d.ts +24 -0
  81. package/dist/types/model/emitter.d.ts +9 -0
  82. package/dist/types/model/types.d.ts +183 -0
  83. package/dist/types/slicc-terminal.d.ts +23 -0
  84. package/dist/types/styles.d.ts +1 -0
  85. package/dist/types/ui.d.ts +15 -0
  86. package/dist/wterm.wasm +0 -0
  87. package/package.json +78 -2
@@ -0,0 +1,1093 @@
1
+ import "./chunk-Q4AC2O6Z.js";
2
+
3
+ // node_modules/tabbable/dist/index.esm.js
4
+ var candidateSelectors = ["input:not([inert]):not([inert] *)", "select:not([inert]):not([inert] *)", "textarea:not([inert]):not([inert] *)", "a[href]:not([inert]):not([inert] *)", "area[href]:not([inert]):not([inert] *)", "button:not([inert]):not([inert] *)", "[tabindex]:not(slot):not([inert]):not([inert] *)", "audio[controls]:not([inert]):not([inert] *)", "video[controls]:not([inert]):not([inert] *)", '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', "details>summary:first-of-type:not([inert]):not([inert] *)", "details:not([inert]):not([inert] *)"];
5
+ var candidateSelector = /* @__PURE__ */ candidateSelectors.join(",");
6
+ var NoElement = typeof Element === "undefined";
7
+ var matches = NoElement ? function() {
8
+ } : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
9
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function(element) {
10
+ var _element$getRootNode;
11
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
12
+ } : function(element) {
13
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
14
+ };
15
+ var _isInert = function isInert(node, lookUp) {
16
+ var _node$getAttribute;
17
+ if (lookUp === void 0) {
18
+ lookUp = true;
19
+ }
20
+ 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");
21
+ var inert = inertAtt === "" || inertAtt === "true";
22
+ var result = inert || lookUp && node && // closest does not exist on shadow roots, so we fall back to a manual
23
+ // lookup upward, in case it is not defined.
24
+ (typeof node.closest === "function" ? node.closest("[inert]") : _isInert(node.parentNode));
25
+ return result;
26
+ };
27
+ var isContentEditable = function isContentEditable2(node) {
28
+ var _node$getAttribute2;
29
+ 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");
30
+ return attValue === "" || attValue === "true";
31
+ };
32
+ var getCandidates = function getCandidates2(el, includeContainer, filter) {
33
+ if (_isInert(el)) {
34
+ return [];
35
+ }
36
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
37
+ if (includeContainer && matches.call(el, candidateSelector)) {
38
+ candidates.unshift(el);
39
+ }
40
+ candidates = candidates.filter(filter);
41
+ return candidates;
42
+ };
43
+ var _getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
44
+ var candidates = [];
45
+ var elementsToCheck = Array.from(elements);
46
+ while (elementsToCheck.length) {
47
+ var element = elementsToCheck.shift();
48
+ if (_isInert(element, false)) {
49
+ continue;
50
+ }
51
+ if (element.tagName === "SLOT") {
52
+ var assigned = element.assignedElements();
53
+ var content = assigned.length ? assigned : element.children;
54
+ var nestedCandidates = _getCandidatesIteratively(content, true, options);
55
+ if (options.flatten) {
56
+ candidates.push.apply(candidates, nestedCandidates);
57
+ } else {
58
+ candidates.push({
59
+ scopeParent: element,
60
+ candidates: nestedCandidates
61
+ });
62
+ }
63
+ } else {
64
+ var validCandidate = matches.call(element, candidateSelector);
65
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
66
+ candidates.push(element);
67
+ }
68
+ var shadowRoot = element.shadowRoot || // check for an undisclosed shadow
69
+ typeof options.getShadowRoot === "function" && options.getShadowRoot(element);
70
+ var validShadowRoot = !_isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
71
+ if (shadowRoot && validShadowRoot) {
72
+ var _nestedCandidates = _getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
73
+ if (options.flatten) {
74
+ candidates.push.apply(candidates, _nestedCandidates);
75
+ } else {
76
+ candidates.push({
77
+ scopeParent: element,
78
+ candidates: _nestedCandidates
79
+ });
80
+ }
81
+ } else {
82
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
83
+ }
84
+ }
85
+ }
86
+ return candidates;
87
+ };
88
+ var hasTabIndex = function hasTabIndex2(node) {
89
+ return !isNaN(parseInt(node.getAttribute("tabindex"), 10));
90
+ };
91
+ var getTabIndex = function getTabIndex2(node) {
92
+ if (!node) {
93
+ throw new Error("No node provided");
94
+ }
95
+ if (node.tabIndex < 0) {
96
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
97
+ return 0;
98
+ }
99
+ }
100
+ return node.tabIndex;
101
+ };
102
+ var getSortOrderTabIndex = function getSortOrderTabIndex2(node, isScope) {
103
+ var tabIndex = getTabIndex(node);
104
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
105
+ return 0;
106
+ }
107
+ return tabIndex;
108
+ };
109
+ var sortOrderedTabbables = function sortOrderedTabbables2(a, b) {
110
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
111
+ };
112
+ var isInput = function isInput2(node) {
113
+ return node.tagName === "INPUT";
114
+ };
115
+ var isHiddenInput = function isHiddenInput2(node) {
116
+ return isInput(node) && node.type === "hidden";
117
+ };
118
+ var isDetailsWithSummary = function isDetailsWithSummary2(node) {
119
+ var r = node.tagName === "DETAILS" && Array.prototype.slice.apply(node.children).some(function(child) {
120
+ return child.tagName === "SUMMARY";
121
+ });
122
+ return r;
123
+ };
124
+ var getCheckedRadio = function getCheckedRadio2(nodes, form) {
125
+ for (var i = 0; i < nodes.length; i++) {
126
+ if (nodes[i].checked && nodes[i].form === form) {
127
+ return nodes[i];
128
+ }
129
+ }
130
+ };
131
+ var isTabbableRadio = function isTabbableRadio2(node) {
132
+ if (!node.name) {
133
+ return true;
134
+ }
135
+ var radioScope = node.form || getRootNode(node);
136
+ var queryRadios = function queryRadios2(name) {
137
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
138
+ };
139
+ var radioSet;
140
+ if (typeof window !== "undefined" && typeof window.CSS !== "undefined" && typeof window.CSS.escape === "function") {
141
+ radioSet = queryRadios(window.CSS.escape(node.name));
142
+ } else {
143
+ try {
144
+ radioSet = queryRadios(node.name);
145
+ } catch (err) {
146
+ 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);
147
+ return false;
148
+ }
149
+ }
150
+ var checked = getCheckedRadio(radioSet, node.form);
151
+ return !checked || checked === node;
152
+ };
153
+ var isRadio = function isRadio2(node) {
154
+ return isInput(node) && node.type === "radio";
155
+ };
156
+ var isNonTabbableRadio = function isNonTabbableRadio2(node) {
157
+ return isRadio(node) && !isTabbableRadio(node);
158
+ };
159
+ var isNodeAttached = function isNodeAttached2(node) {
160
+ var _nodeRoot;
161
+ var nodeRoot = node && getRootNode(node);
162
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
163
+ var attached = false;
164
+ if (nodeRoot && nodeRoot !== node) {
165
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
166
+ 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));
167
+ while (!attached && nodeRootHost) {
168
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
169
+ nodeRoot = getRootNode(nodeRootHost);
170
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
171
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
172
+ }
173
+ }
174
+ return attached;
175
+ };
176
+ var isZeroArea = function isZeroArea2(node) {
177
+ var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height;
178
+ return width === 0 && height === 0;
179
+ };
180
+ var isHidden = function isHidden2(node, _ref) {
181
+ var displayCheck = _ref.displayCheck, getShadowRoot = _ref.getShadowRoot;
182
+ if (displayCheck === "full-native") {
183
+ if ("checkVisibility" in node) {
184
+ var visible = node.checkVisibility({
185
+ // Checking opacity might be desirable for some use cases, but natively,
186
+ // opacity zero elements _are_ focusable and tabbable.
187
+ checkOpacity: false,
188
+ opacityProperty: false,
189
+ contentVisibilityAuto: true,
190
+ visibilityProperty: true,
191
+ // This is an alias for `visibilityProperty`. Contemporary browsers
192
+ // support both. However, this alias has wider browser support (Chrome
193
+ // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
194
+ // we include it anyway.
195
+ checkVisibilityCSS: true
196
+ });
197
+ return !visible;
198
+ }
199
+ }
200
+ var _getComputedStyle = getComputedStyle(node), visibility = _getComputedStyle.visibility;
201
+ if (visibility === "hidden" || visibility === "collapse") {
202
+ return true;
203
+ }
204
+ var isDirectSummary = matches.call(node, "details>summary:first-of-type");
205
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
206
+ if (matches.call(nodeUnderDetails, "details:not([open]) *")) {
207
+ return true;
208
+ }
209
+ if (!displayCheck || displayCheck === "full" || // full-native can run this branch when it falls through in case
210
+ // Element#checkVisibility is unsupported
211
+ displayCheck === "full-native" || displayCheck === "legacy-full") {
212
+ if (typeof getShadowRoot === "function") {
213
+ var originalNode = node;
214
+ while (node) {
215
+ var parentElement = node.parentElement;
216
+ var rootNode = getRootNode(node);
217
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true) {
218
+ return isZeroArea(node);
219
+ } else if (node.assignedSlot) {
220
+ node = node.assignedSlot;
221
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
222
+ node = rootNode.host;
223
+ } else {
224
+ node = parentElement;
225
+ }
226
+ }
227
+ node = originalNode;
228
+ }
229
+ if (isNodeAttached(node)) {
230
+ return !node.getClientRects().length;
231
+ }
232
+ if (displayCheck !== "legacy-full") {
233
+ return true;
234
+ }
235
+ } else if (displayCheck === "non-zero-area") {
236
+ return isZeroArea(node);
237
+ }
238
+ return false;
239
+ };
240
+ var isDisabledFromFieldset = function isDisabledFromFieldset2(node) {
241
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
242
+ var parentNode = node.parentElement;
243
+ while (parentNode) {
244
+ if (parentNode.tagName === "FIELDSET" && parentNode.disabled) {
245
+ for (var i = 0; i < parentNode.children.length; i++) {
246
+ var child = parentNode.children.item(i);
247
+ if (child.tagName === "LEGEND") {
248
+ return matches.call(parentNode, "fieldset[disabled] *") ? true : !child.contains(node);
249
+ }
250
+ }
251
+ return true;
252
+ }
253
+ parentNode = parentNode.parentElement;
254
+ }
255
+ }
256
+ return false;
257
+ };
258
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) {
259
+ if (node.disabled || isHiddenInput(node) || isHidden(node, options) || // For a details element with a summary, the summary element gets the focus
260
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
261
+ return false;
262
+ }
263
+ return true;
264
+ };
265
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) {
266
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
267
+ return false;
268
+ }
269
+ return true;
270
+ };
271
+ var isShadowRootTabbable = function isShadowRootTabbable2(shadowHostNode) {
272
+ var tabIndex = parseInt(shadowHostNode.getAttribute("tabindex"), 10);
273
+ if (isNaN(tabIndex) || tabIndex >= 0) {
274
+ return true;
275
+ }
276
+ return false;
277
+ };
278
+ var _sortByOrder = function sortByOrder(candidates) {
279
+ var regularTabbables = [];
280
+ var orderedTabbables = [];
281
+ candidates.forEach(function(item, i) {
282
+ var isScope = !!item.scopeParent;
283
+ var element = isScope ? item.scopeParent : item;
284
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
285
+ var elements = isScope ? _sortByOrder(item.candidates) : element;
286
+ if (candidateTabindex === 0) {
287
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
288
+ } else {
289
+ orderedTabbables.push({
290
+ documentOrder: i,
291
+ tabIndex: candidateTabindex,
292
+ item,
293
+ isScope,
294
+ content: elements
295
+ });
296
+ }
297
+ });
298
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function(acc, sortable) {
299
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
300
+ return acc;
301
+ }, []).concat(regularTabbables);
302
+ };
303
+ var tabbable = function tabbable2(container, options) {
304
+ options = options || {};
305
+ var candidates;
306
+ if (options.getShadowRoot) {
307
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
308
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
309
+ flatten: false,
310
+ getShadowRoot: options.getShadowRoot,
311
+ shadowRootFilter: isShadowRootTabbable
312
+ });
313
+ } else {
314
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
315
+ }
316
+ return _sortByOrder(candidates);
317
+ };
318
+ var focusable = function focusable2(container, options) {
319
+ options = options || {};
320
+ var candidates;
321
+ if (options.getShadowRoot) {
322
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
323
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
324
+ flatten: true,
325
+ getShadowRoot: options.getShadowRoot
326
+ });
327
+ } else {
328
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
329
+ }
330
+ return candidates;
331
+ };
332
+ var isTabbable = function isTabbable2(node, options) {
333
+ options = options || {};
334
+ if (!node) {
335
+ throw new Error("No node provided");
336
+ }
337
+ if (matches.call(node, candidateSelector) === false) {
338
+ return false;
339
+ }
340
+ return isNodeMatchingSelectorTabbable(options, node);
341
+ };
342
+ var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe:not([inert]):not([inert] *)").join(",");
343
+ var isFocusable = function isFocusable2(node, options) {
344
+ options = options || {};
345
+ if (!node) {
346
+ throw new Error("No node provided");
347
+ }
348
+ if (matches.call(node, focusableCandidateSelector) === false) {
349
+ return false;
350
+ }
351
+ return isNodeMatchingSelectorFocusable(options, node);
352
+ };
353
+
354
+ // node_modules/focus-trap/dist/focus-trap.esm.js
355
+ function _arrayLikeToArray(r, a) {
356
+ (null == a || a > r.length) && (a = r.length);
357
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
358
+ return n;
359
+ }
360
+ function _arrayWithoutHoles(r) {
361
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
362
+ }
363
+ function _defineProperty(e, r, t) {
364
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
365
+ value: t,
366
+ enumerable: true,
367
+ configurable: true,
368
+ writable: true
369
+ }) : e[r] = t, e;
370
+ }
371
+ function _iterableToArray(r) {
372
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
373
+ }
374
+ function _nonIterableSpread() {
375
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
376
+ }
377
+ function ownKeys(e, r) {
378
+ var t = Object.keys(e);
379
+ if (Object.getOwnPropertySymbols) {
380
+ var o = Object.getOwnPropertySymbols(e);
381
+ r && (o = o.filter(function(r2) {
382
+ return Object.getOwnPropertyDescriptor(e, r2).enumerable;
383
+ })), t.push.apply(t, o);
384
+ }
385
+ return t;
386
+ }
387
+ function _objectSpread2(e) {
388
+ for (var r = 1; r < arguments.length; r++) {
389
+ var t = null != arguments[r] ? arguments[r] : {};
390
+ r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
391
+ _defineProperty(e, r2, t[r2]);
392
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
393
+ Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
394
+ });
395
+ }
396
+ return e;
397
+ }
398
+ function _toConsumableArray(r) {
399
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
400
+ }
401
+ function _toPrimitive(t, r) {
402
+ if ("object" != typeof t || !t) return t;
403
+ var e = t[Symbol.toPrimitive];
404
+ if (void 0 !== e) {
405
+ var i = e.call(t, r);
406
+ if ("object" != typeof i) return i;
407
+ throw new TypeError("@@toPrimitive must return a primitive value.");
408
+ }
409
+ return ("string" === r ? String : Number)(t);
410
+ }
411
+ function _toPropertyKey(t) {
412
+ var i = _toPrimitive(t, "string");
413
+ return "symbol" == typeof i ? i : i + "";
414
+ }
415
+ function _unsupportedIterableToArray(r, a) {
416
+ if (r) {
417
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
418
+ var t = {}.toString.call(r).slice(8, -1);
419
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
420
+ }
421
+ }
422
+ var activeFocusTraps = {
423
+ activateTrap: function activateTrap(trapStack, trap) {
424
+ if (trapStack.length > 0) {
425
+ var activeTrap = trapStack[trapStack.length - 1];
426
+ if (activeTrap !== trap) {
427
+ activeTrap._setPausedState(true);
428
+ }
429
+ }
430
+ var trapIndex = trapStack.indexOf(trap);
431
+ if (trapIndex === -1) {
432
+ trapStack.push(trap);
433
+ } else {
434
+ trapStack.splice(trapIndex, 1);
435
+ trapStack.push(trap);
436
+ }
437
+ },
438
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
439
+ var trapIndex = trapStack.indexOf(trap);
440
+ if (trapIndex !== -1) {
441
+ trapStack.splice(trapIndex, 1);
442
+ }
443
+ if (trapStack.length > 0 && !trapStack[trapStack.length - 1]._isManuallyPaused()) {
444
+ trapStack[trapStack.length - 1]._setPausedState(false);
445
+ }
446
+ }
447
+ };
448
+ var isSelectableInput = function isSelectableInput2(node) {
449
+ return node.tagName && node.tagName.toLowerCase() === "input" && typeof node.select === "function";
450
+ };
451
+ var isEscapeEvent = function isEscapeEvent2(e) {
452
+ 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;
453
+ };
454
+ var isTabEvent = function isTabEvent2(e) {
455
+ return (e === null || e === void 0 ? void 0 : e.key) === "Tab" || (e === null || e === void 0 ? void 0 : e.keyCode) === 9;
456
+ };
457
+ var isKeyForward = function isKeyForward2(e) {
458
+ return isTabEvent(e) && !e.shiftKey;
459
+ };
460
+ var isKeyBackward = function isKeyBackward2(e) {
461
+ return isTabEvent(e) && e.shiftKey;
462
+ };
463
+ var delay = function delay2(fn) {
464
+ return setTimeout(fn, 0);
465
+ };
466
+ var valueOrHandler = function valueOrHandler2(value) {
467
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
468
+ params[_key - 1] = arguments[_key];
469
+ }
470
+ return typeof value === "function" ? value.apply(void 0, params) : value;
471
+ };
472
+ var getActualTarget = function getActualTarget2(event) {
473
+ return event.target.shadowRoot && typeof event.composedPath === "function" ? event.composedPath()[0] : event.target;
474
+ };
475
+ var internalTrapStack = [];
476
+ var createFocusTrap = function createFocusTrap2(elements, userOptions) {
477
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
478
+ var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || internalTrapStack;
479
+ var config = _objectSpread2({
480
+ returnFocusOnDeactivate: true,
481
+ escapeDeactivates: true,
482
+ delayInitialFocus: true,
483
+ isKeyForward,
484
+ isKeyBackward
485
+ }, userOptions);
486
+ var state = {
487
+ // containers given to createFocusTrap()
488
+ // @type {Array<HTMLElement>}
489
+ containers: [],
490
+ // list of objects identifying tabbable nodes in `containers` in the trap
491
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
492
+ // is active, but the trap should never get to a state where there isn't at least one group
493
+ // with at least one tabbable node in it (that would lead to an error condition that would
494
+ // result in an error being thrown)
495
+ // @type {Array<{
496
+ // container: HTMLElement,
497
+ // tabbableNodes: Array<HTMLElement>, // empty if none
498
+ // focusableNodes: Array<HTMLElement>, // empty if none
499
+ // posTabIndexesFound: boolean,
500
+ // firstTabbableNode: HTMLElement|undefined,
501
+ // lastTabbableNode: HTMLElement|undefined,
502
+ // firstDomTabbableNode: HTMLElement|undefined,
503
+ // lastDomTabbableNode: HTMLElement|undefined,
504
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
505
+ // }>}
506
+ containerGroups: [],
507
+ // same order/length as `containers` list
508
+ // references to objects in `containerGroups`, but only those that actually have
509
+ // tabbable nodes in them
510
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
511
+ // the same length
512
+ tabbableGroups: [],
513
+ nodeFocusedBeforeActivation: null,
514
+ mostRecentlyFocusedNode: null,
515
+ active: false,
516
+ paused: false,
517
+ manuallyPaused: false,
518
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
519
+ // has been delayed during activation
520
+ delayInitialFocusTimer: void 0,
521
+ // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
522
+ recentNavEvent: void 0
523
+ };
524
+ var trap;
525
+ var getOption = function getOption2(configOverrideOptions, optionName, configOptionName) {
526
+ return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : config[configOptionName || optionName];
527
+ };
528
+ var findContainerIndex = function findContainerIndex2(element, event) {
529
+ var composedPath = typeof (event === null || event === void 0 ? void 0 : event.composedPath) === "function" ? event.composedPath() : void 0;
530
+ return state.containerGroups.findIndex(function(_ref) {
531
+ var container = _ref.container, tabbableNodes = _ref.tabbableNodes;
532
+ return container.contains(element) || // fall back to explicit tabbable search which will take into consideration any
533
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
534
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
535
+ // look inside web components even if open)
536
+ (composedPath === null || composedPath === void 0 ? void 0 : composedPath.includes(container)) || tabbableNodes.find(function(node) {
537
+ return node === element;
538
+ });
539
+ });
540
+ };
541
+ var getNodeForOption = function getNodeForOption2(optionName) {
542
+ var _ref2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref2$hasFallback = _ref2.hasFallback, hasFallback = _ref2$hasFallback === void 0 ? false : _ref2$hasFallback, _ref2$params = _ref2.params, params = _ref2$params === void 0 ? [] : _ref2$params;
543
+ var optionValue = config[optionName];
544
+ if (typeof optionValue === "function") {
545
+ optionValue = optionValue.apply(void 0, _toConsumableArray(params));
546
+ }
547
+ if (optionValue === true) {
548
+ optionValue = void 0;
549
+ }
550
+ if (!optionValue) {
551
+ if (optionValue === void 0 || optionValue === false) {
552
+ return optionValue;
553
+ }
554
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
555
+ }
556
+ var node = optionValue;
557
+ if (typeof optionValue === "string") {
558
+ try {
559
+ node = doc.querySelector(optionValue);
560
+ } catch (err) {
561
+ throw new Error("`".concat(optionName, '` appears to be an invalid selector; error="').concat(err.message, '"'));
562
+ }
563
+ if (!node) {
564
+ if (!hasFallback) {
565
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
566
+ }
567
+ }
568
+ }
569
+ return node;
570
+ };
571
+ var getInitialFocusNode = function getInitialFocusNode2() {
572
+ var node = getNodeForOption("initialFocus", {
573
+ hasFallback: true
574
+ });
575
+ if (node === false) {
576
+ return false;
577
+ }
578
+ if (node === void 0 || node && !isFocusable(node, config.tabbableOptions)) {
579
+ if (findContainerIndex(doc.activeElement) >= 0) {
580
+ node = doc.activeElement;
581
+ } else {
582
+ var firstTabbableGroup = state.tabbableGroups[0];
583
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
584
+ node = firstTabbableNode || getNodeForOption("fallbackFocus");
585
+ }
586
+ } else if (node === null) {
587
+ node = getNodeForOption("fallbackFocus");
588
+ }
589
+ if (!node) {
590
+ throw new Error("Your focus-trap needs to have at least one focusable element");
591
+ }
592
+ return node;
593
+ };
594
+ var updateTabbableNodes = function updateTabbableNodes2() {
595
+ state.containerGroups = state.containers.map(function(container) {
596
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
597
+ var focusableNodes = focusable(container, config.tabbableOptions);
598
+ var firstTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[0] : void 0;
599
+ var lastTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : void 0;
600
+ var firstDomTabbableNode = focusableNodes.find(function(node) {
601
+ return isTabbable(node);
602
+ });
603
+ var lastDomTabbableNode = focusableNodes.slice().reverse().find(function(node) {
604
+ return isTabbable(node);
605
+ });
606
+ var posTabIndexesFound = !!tabbableNodes.find(function(node) {
607
+ return getTabIndex(node) > 0;
608
+ });
609
+ return {
610
+ container,
611
+ tabbableNodes,
612
+ focusableNodes,
613
+ /** True if at least one node with positive `tabindex` was found in this container. */
614
+ posTabIndexesFound,
615
+ /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
616
+ firstTabbableNode,
617
+ /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
618
+ lastTabbableNode,
619
+ // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
620
+ // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
621
+ // because that API doesn't work with Shadow DOM as well as it should (@see
622
+ // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
623
+ // to address an edge case related to positive tabindex support, this seems like a much easier,
624
+ // "close enough most of the time" alternative for positive tabindexes which should generally
625
+ // be avoided anyway...
626
+ /** First tabbable node in container, __DOM__ order; `undefined` if none. */
627
+ firstDomTabbableNode,
628
+ /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
629
+ lastDomTabbableNode,
630
+ /**
631
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
632
+ * in this container, if any.
633
+ * @param {HTMLElement} node
634
+ * @param {boolean} [forward] True if going in forward tab order; false if going
635
+ * in reverse.
636
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
637
+ */
638
+ nextTabbableNode: function nextTabbableNode(node) {
639
+ var forward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
640
+ var nodeIdx = tabbableNodes.indexOf(node);
641
+ if (nodeIdx < 0) {
642
+ if (forward) {
643
+ return focusableNodes.slice(focusableNodes.indexOf(node) + 1).find(function(el) {
644
+ return isTabbable(el);
645
+ });
646
+ }
647
+ return focusableNodes.slice(0, focusableNodes.indexOf(node)).reverse().find(function(el) {
648
+ return isTabbable(el);
649
+ });
650
+ }
651
+ return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
652
+ }
653
+ };
654
+ });
655
+ state.tabbableGroups = state.containerGroups.filter(function(group) {
656
+ return group.tabbableNodes.length > 0;
657
+ });
658
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption("fallbackFocus")) {
659
+ throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");
660
+ }
661
+ if (state.containerGroups.find(function(g) {
662
+ return g.posTabIndexesFound;
663
+ }) && state.containerGroups.length > 1) {
664
+ 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.");
665
+ }
666
+ };
667
+ var _getActiveElement = function getActiveElement(el) {
668
+ var activeElement = el.activeElement;
669
+ if (!activeElement) {
670
+ return;
671
+ }
672
+ if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
673
+ return _getActiveElement(activeElement.shadowRoot);
674
+ }
675
+ return activeElement;
676
+ };
677
+ var _tryFocus = function tryFocus(node) {
678
+ if (node === false) {
679
+ return;
680
+ }
681
+ if (node === _getActiveElement(document)) {
682
+ return;
683
+ }
684
+ if (!node || !node.focus) {
685
+ _tryFocus(getInitialFocusNode());
686
+ return;
687
+ }
688
+ node.focus({
689
+ preventScroll: !!config.preventScroll
690
+ });
691
+ state.mostRecentlyFocusedNode = node;
692
+ if (isSelectableInput(node)) {
693
+ node.select();
694
+ }
695
+ };
696
+ var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) {
697
+ var node = getNodeForOption("setReturnFocus", {
698
+ params: [previousActiveElement]
699
+ });
700
+ return node ? node : node === false ? false : previousActiveElement;
701
+ };
702
+ var findNextNavNode = function findNextNavNode2(_ref3) {
703
+ var target = _ref3.target, event = _ref3.event, _ref3$isBackward = _ref3.isBackward, isBackward = _ref3$isBackward === void 0 ? false : _ref3$isBackward;
704
+ target = target || getActualTarget(event);
705
+ updateTabbableNodes();
706
+ var destinationNode = null;
707
+ if (state.tabbableGroups.length > 0) {
708
+ var containerIndex = findContainerIndex(target, event);
709
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0;
710
+ if (containerIndex < 0) {
711
+ if (isBackward) {
712
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
713
+ } else {
714
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
715
+ }
716
+ } else if (isBackward) {
717
+ var startOfGroupIndex = state.tabbableGroups.findIndex(function(_ref4) {
718
+ var firstTabbableNode = _ref4.firstTabbableNode;
719
+ return target === firstTabbableNode;
720
+ });
721
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
722
+ startOfGroupIndex = containerIndex;
723
+ }
724
+ if (startOfGroupIndex >= 0) {
725
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
726
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
727
+ destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
728
+ } else if (!isTabEvent(event)) {
729
+ destinationNode = containerGroup.nextTabbableNode(target, false);
730
+ }
731
+ } else {
732
+ var lastOfGroupIndex = state.tabbableGroups.findIndex(function(_ref5) {
733
+ var lastTabbableNode = _ref5.lastTabbableNode;
734
+ return target === lastTabbableNode;
735
+ });
736
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
737
+ lastOfGroupIndex = containerIndex;
738
+ }
739
+ if (lastOfGroupIndex >= 0) {
740
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
741
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
742
+ destinationNode = getTabIndex(target) >= 0 ? _destinationGroup.firstTabbableNode : _destinationGroup.firstDomTabbableNode;
743
+ } else if (!isTabEvent(event)) {
744
+ destinationNode = containerGroup.nextTabbableNode(target);
745
+ }
746
+ }
747
+ } else {
748
+ destinationNode = getNodeForOption("fallbackFocus");
749
+ }
750
+ return destinationNode;
751
+ };
752
+ var checkPointerDown = function checkPointerDown2(e) {
753
+ var target = getActualTarget(e);
754
+ if (findContainerIndex(target, e) >= 0) {
755
+ return;
756
+ }
757
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
758
+ trap.deactivate({
759
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
760
+ // which will result in the outside click setting focus to the node
761
+ // that was clicked (and if not focusable, to "nothing"); by setting
762
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
763
+ // on activation (or the configured `setReturnFocus` node), whether the
764
+ // outside click was on a focusable node or not
765
+ returnFocus: config.returnFocusOnDeactivate
766
+ });
767
+ return;
768
+ }
769
+ if (valueOrHandler(config.allowOutsideClick, e)) {
770
+ return;
771
+ }
772
+ e.preventDefault();
773
+ };
774
+ var checkFocusIn = function checkFocusIn2(event) {
775
+ var target = getActualTarget(event);
776
+ var targetContained = findContainerIndex(target, event) >= 0;
777
+ if (targetContained || target instanceof Document) {
778
+ if (targetContained) {
779
+ state.mostRecentlyFocusedNode = target;
780
+ }
781
+ } else {
782
+ event.stopImmediatePropagation();
783
+ var nextNode;
784
+ var navAcrossContainers = true;
785
+ if (state.mostRecentlyFocusedNode) {
786
+ if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
787
+ var mruContainerIdx = findContainerIndex(state.mostRecentlyFocusedNode);
788
+ var tabbableNodes = state.containerGroups[mruContainerIdx].tabbableNodes;
789
+ if (tabbableNodes.length > 0) {
790
+ var mruTabIdx = tabbableNodes.findIndex(function(node) {
791
+ return node === state.mostRecentlyFocusedNode;
792
+ });
793
+ if (mruTabIdx >= 0) {
794
+ if (config.isKeyForward(state.recentNavEvent)) {
795
+ if (mruTabIdx + 1 < tabbableNodes.length) {
796
+ nextNode = tabbableNodes[mruTabIdx + 1];
797
+ navAcrossContainers = false;
798
+ }
799
+ } else {
800
+ if (mruTabIdx - 1 >= 0) {
801
+ nextNode = tabbableNodes[mruTabIdx - 1];
802
+ navAcrossContainers = false;
803
+ }
804
+ }
805
+ }
806
+ }
807
+ } else {
808
+ if (!state.containerGroups.some(function(g) {
809
+ return g.tabbableNodes.some(function(n) {
810
+ return getTabIndex(n) > 0;
811
+ });
812
+ })) {
813
+ navAcrossContainers = false;
814
+ }
815
+ }
816
+ } else {
817
+ navAcrossContainers = false;
818
+ }
819
+ if (navAcrossContainers) {
820
+ nextNode = findNextNavNode({
821
+ // move FROM the MRU node, not event-related node (which will be the node that is
822
+ // outside the trap causing the focus escape we're trying to fix)
823
+ target: state.mostRecentlyFocusedNode,
824
+ isBackward: config.isKeyBackward(state.recentNavEvent)
825
+ });
826
+ }
827
+ if (nextNode) {
828
+ _tryFocus(nextNode);
829
+ } else {
830
+ _tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
831
+ }
832
+ }
833
+ state.recentNavEvent = void 0;
834
+ };
835
+ var checkKeyNav = function checkKeyNav2(event) {
836
+ var isBackward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
837
+ state.recentNavEvent = event;
838
+ var destinationNode = findNextNavNode({
839
+ event,
840
+ isBackward
841
+ });
842
+ if (destinationNode) {
843
+ if (isTabEvent(event)) {
844
+ event.preventDefault();
845
+ }
846
+ _tryFocus(destinationNode);
847
+ }
848
+ };
849
+ var checkTabKey = function checkTabKey2(event) {
850
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
851
+ checkKeyNav(event, config.isKeyBackward(event));
852
+ }
853
+ };
854
+ var checkEscapeKey = function checkEscapeKey2(event) {
855
+ if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
856
+ event.preventDefault();
857
+ trap.deactivate();
858
+ }
859
+ };
860
+ var checkClick = function checkClick2(e) {
861
+ var target = getActualTarget(e);
862
+ if (findContainerIndex(target, e) >= 0) {
863
+ return;
864
+ }
865
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
866
+ return;
867
+ }
868
+ if (valueOrHandler(config.allowOutsideClick, e)) {
869
+ return;
870
+ }
871
+ e.preventDefault();
872
+ e.stopImmediatePropagation();
873
+ };
874
+ var addListeners = function addListeners2() {
875
+ if (!state.active) {
876
+ return;
877
+ }
878
+ activeFocusTraps.activateTrap(trapStack, trap);
879
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function() {
880
+ _tryFocus(getInitialFocusNode());
881
+ }) : _tryFocus(getInitialFocusNode());
882
+ doc.addEventListener("focusin", checkFocusIn, true);
883
+ doc.addEventListener("mousedown", checkPointerDown, {
884
+ capture: true,
885
+ passive: false
886
+ });
887
+ doc.addEventListener("touchstart", checkPointerDown, {
888
+ capture: true,
889
+ passive: false
890
+ });
891
+ doc.addEventListener("click", checkClick, {
892
+ capture: true,
893
+ passive: false
894
+ });
895
+ doc.addEventListener("keydown", checkTabKey, {
896
+ capture: true,
897
+ passive: false
898
+ });
899
+ doc.addEventListener("keydown", checkEscapeKey);
900
+ return trap;
901
+ };
902
+ var removeListeners = function removeListeners2() {
903
+ if (!state.active) {
904
+ return;
905
+ }
906
+ doc.removeEventListener("focusin", checkFocusIn, true);
907
+ doc.removeEventListener("mousedown", checkPointerDown, true);
908
+ doc.removeEventListener("touchstart", checkPointerDown, true);
909
+ doc.removeEventListener("click", checkClick, true);
910
+ doc.removeEventListener("keydown", checkTabKey, true);
911
+ doc.removeEventListener("keydown", checkEscapeKey);
912
+ return trap;
913
+ };
914
+ var checkDomRemoval = function checkDomRemoval2(mutations) {
915
+ var isFocusedNodeRemoved = mutations.some(function(mutation) {
916
+ var removedNodes = Array.from(mutation.removedNodes);
917
+ return removedNodes.some(function(node) {
918
+ return node === state.mostRecentlyFocusedNode;
919
+ });
920
+ });
921
+ if (isFocusedNodeRemoved) {
922
+ _tryFocus(getInitialFocusNode());
923
+ }
924
+ };
925
+ var mutationObserver = typeof window !== "undefined" && "MutationObserver" in window ? new MutationObserver(checkDomRemoval) : void 0;
926
+ var updateObservedNodes = function updateObservedNodes2() {
927
+ if (!mutationObserver) {
928
+ return;
929
+ }
930
+ mutationObserver.disconnect();
931
+ if (state.active && !state.paused) {
932
+ state.containers.map(function(container) {
933
+ mutationObserver.observe(container, {
934
+ subtree: true,
935
+ childList: true
936
+ });
937
+ });
938
+ }
939
+ };
940
+ trap = {
941
+ get active() {
942
+ return state.active;
943
+ },
944
+ get paused() {
945
+ return state.paused;
946
+ },
947
+ activate: function activate(activateOptions) {
948
+ if (state.active) {
949
+ return this;
950
+ }
951
+ var onActivate = getOption(activateOptions, "onActivate");
952
+ var onPostActivate = getOption(activateOptions, "onPostActivate");
953
+ var checkCanFocusTrap = getOption(activateOptions, "checkCanFocusTrap");
954
+ if (!checkCanFocusTrap) {
955
+ updateTabbableNodes();
956
+ }
957
+ state.active = true;
958
+ state.paused = false;
959
+ state.nodeFocusedBeforeActivation = _getActiveElement(doc);
960
+ onActivate === null || onActivate === void 0 || onActivate();
961
+ var finishActivation = function finishActivation2() {
962
+ if (checkCanFocusTrap) {
963
+ updateTabbableNodes();
964
+ }
965
+ addListeners();
966
+ updateObservedNodes();
967
+ onPostActivate === null || onPostActivate === void 0 || onPostActivate();
968
+ };
969
+ if (checkCanFocusTrap) {
970
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
971
+ return this;
972
+ }
973
+ finishActivation();
974
+ return this;
975
+ },
976
+ deactivate: function deactivate(deactivateOptions) {
977
+ if (!state.active) {
978
+ return this;
979
+ }
980
+ var options = _objectSpread2({
981
+ onDeactivate: config.onDeactivate,
982
+ onPostDeactivate: config.onPostDeactivate,
983
+ checkCanReturnFocus: config.checkCanReturnFocus
984
+ }, deactivateOptions);
985
+ clearTimeout(state.delayInitialFocusTimer);
986
+ state.delayInitialFocusTimer = void 0;
987
+ removeListeners();
988
+ state.active = false;
989
+ state.paused = false;
990
+ updateObservedNodes();
991
+ activeFocusTraps.deactivateTrap(trapStack, trap);
992
+ var onDeactivate = getOption(options, "onDeactivate");
993
+ var onPostDeactivate = getOption(options, "onPostDeactivate");
994
+ var checkCanReturnFocus = getOption(options, "checkCanReturnFocus");
995
+ var returnFocus = getOption(options, "returnFocus", "returnFocusOnDeactivate");
996
+ onDeactivate === null || onDeactivate === void 0 || onDeactivate();
997
+ var finishDeactivation = function finishDeactivation2() {
998
+ delay(function() {
999
+ if (returnFocus) {
1000
+ _tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1001
+ }
1002
+ onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
1003
+ });
1004
+ };
1005
+ if (returnFocus && checkCanReturnFocus) {
1006
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1007
+ return this;
1008
+ }
1009
+ finishDeactivation();
1010
+ return this;
1011
+ },
1012
+ pause: function pause(pauseOptions) {
1013
+ if (!state.active) {
1014
+ return this;
1015
+ }
1016
+ state.manuallyPaused = true;
1017
+ return this._setPausedState(true, pauseOptions);
1018
+ },
1019
+ unpause: function unpause(unpauseOptions) {
1020
+ if (!state.active) {
1021
+ return this;
1022
+ }
1023
+ state.manuallyPaused = false;
1024
+ if (trapStack[trapStack.length - 1] !== this) {
1025
+ return this;
1026
+ }
1027
+ return this._setPausedState(false, unpauseOptions);
1028
+ },
1029
+ updateContainerElements: function updateContainerElements(containerElements) {
1030
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1031
+ state.containers = elementsAsArray.map(function(element) {
1032
+ return typeof element === "string" ? doc.querySelector(element) : element;
1033
+ });
1034
+ if (state.active) {
1035
+ updateTabbableNodes();
1036
+ }
1037
+ updateObservedNodes();
1038
+ return this;
1039
+ }
1040
+ };
1041
+ Object.defineProperties(trap, {
1042
+ _isManuallyPaused: {
1043
+ value: function value() {
1044
+ return state.manuallyPaused;
1045
+ }
1046
+ },
1047
+ _setPausedState: {
1048
+ value: function value(paused, options) {
1049
+ if (state.paused === paused) {
1050
+ return this;
1051
+ }
1052
+ state.paused = paused;
1053
+ if (paused) {
1054
+ var onPause = getOption(options, "onPause");
1055
+ var onPostPause = getOption(options, "onPostPause");
1056
+ onPause === null || onPause === void 0 || onPause();
1057
+ removeListeners();
1058
+ updateObservedNodes();
1059
+ onPostPause === null || onPostPause === void 0 || onPostPause();
1060
+ } else {
1061
+ var onUnpause = getOption(options, "onUnpause");
1062
+ var onPostUnpause = getOption(options, "onPostUnpause");
1063
+ onUnpause === null || onUnpause === void 0 || onUnpause();
1064
+ updateTabbableNodes();
1065
+ addListeners();
1066
+ updateObservedNodes();
1067
+ onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause();
1068
+ }
1069
+ return this;
1070
+ }
1071
+ }
1072
+ });
1073
+ trap.updateContainerElements(elements);
1074
+ return trap;
1075
+ };
1076
+ export {
1077
+ createFocusTrap
1078
+ };
1079
+ /*! Bundled license information:
1080
+
1081
+ tabbable/dist/index.esm.js:
1082
+ (*!
1083
+ * tabbable 6.5.0
1084
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
1085
+ *)
1086
+
1087
+ focus-trap/dist/focus-trap.esm.js:
1088
+ (*!
1089
+ * focus-trap 7.6.5
1090
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
1091
+ *)
1092
+ */
1093
+ //# sourceMappingURL=chunk-MTF6JFSL.js.map