@dso-toolkit/core 34.1.0 → 35.0.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 (116) hide show
  1. package/dist/cjs/dso-autosuggest.cjs.entry.js +5 -1
  2. package/dist/cjs/dso-header.cjs.entry.js +1 -1
  3. package/dist/cjs/dso-image-overlay.cjs.entry.js +62 -0
  4. package/dist/cjs/dso-info_2.cjs.entry.js +4 -1
  5. package/dist/cjs/dso-map-base-layers.cjs.entry.js +14 -1
  6. package/dist/cjs/dso-map-overlays.cjs.entry.js +14 -1
  7. package/dist/cjs/dso-ozon-content.cjs.entry.js +281 -423
  8. package/dist/cjs/dso-toolkit.cjs.js +1 -1
  9. package/dist/cjs/dso-viewer-grid.cjs.entry.js +57 -726
  10. package/dist/cjs/focus-trap.esm-8d3e3fb6.js +712 -0
  11. package/dist/cjs/loader.cjs.js +1 -1
  12. package/dist/collection/collection-manifest.json +3 -2
  13. package/dist/collection/components/autosuggest/autosuggest.js +6 -2
  14. package/dist/collection/components/header/header.css +21 -13
  15. package/dist/collection/components/highlight-box/highlight-box.template.js +4 -1
  16. package/dist/collection/components/image-overlay/image-overlay.css +263 -0
  17. package/dist/collection/components/image-overlay/image-overlay.js +72 -0
  18. package/dist/collection/components/image-overlay/image-overlay.template.js +7 -0
  19. package/dist/collection/components/info/info.css +20 -0
  20. package/dist/collection/components/map-base-layers/map-base-layers.js +16 -1
  21. package/dist/collection/components/map-overlays/map-overlays.js +16 -1
  22. package/dist/collection/components/ozon-content/nodes/al.node.js +13 -0
  23. package/dist/collection/components/ozon-content/nodes/document.node.js +9 -0
  24. package/dist/collection/components/ozon-content/nodes/ext-ref.node.js +15 -0
  25. package/dist/collection/components/ozon-content/nodes/fallback.node.js +10 -0
  26. package/dist/collection/components/ozon-content/nodes/illustratie.node.js +13 -0
  27. package/dist/collection/components/ozon-content/nodes/inhoud.node.js +14 -0
  28. package/dist/collection/components/ozon-content/nodes/inline.nodes.js +21 -0
  29. package/dist/collection/components/ozon-content/nodes/int-ref.node.js +26 -0
  30. package/dist/collection/components/ozon-content/nodes/noot.node.js +27 -0
  31. package/dist/collection/components/ozon-content/nodes/table.node/colspec/colspec-mapper.js +39 -0
  32. package/dist/collection/components/ozon-content/nodes/table.node/colspec/colspec.interface.js +2 -0
  33. package/dist/collection/components/ozon-content/nodes/table.node/index.js +1 -0
  34. package/dist/collection/components/ozon-content/nodes/table.node/table-cell.js +25 -0
  35. package/dist/collection/components/ozon-content/nodes/table.node/table-colgroup.js +4 -0
  36. package/dist/collection/components/ozon-content/nodes/table.node/table-rows.js +5 -0
  37. package/dist/collection/components/ozon-content/nodes/table.node/table.node.js +32 -0
  38. package/dist/collection/components/ozon-content/nodes/text.node.js +9 -0
  39. package/dist/collection/components/ozon-content/ozon-content-context.interface.js +1 -0
  40. package/dist/collection/components/ozon-content/ozon-content-mapper.js +76 -0
  41. package/dist/collection/components/ozon-content/ozon-content-node-context.interface.js +1 -0
  42. package/dist/collection/components/ozon-content/ozon-content-node-state.interface.js +1 -0
  43. package/dist/collection/components/ozon-content/ozon-content-node.interface.js +1 -0
  44. package/dist/collection/components/ozon-content/ozon-content.css +15 -7
  45. package/dist/collection/components/ozon-content/ozon-content.js +21 -33
  46. package/dist/collection/components/selectable/selectable.js +25 -1
  47. package/dist/collection/components/viewer-grid/viewer-grid-filterpanel-buttons.js +7 -0
  48. package/dist/collection/components/viewer-grid/viewer-grid.css +351 -3
  49. package/dist/collection/components/viewer-grid/viewer-grid.js +109 -19
  50. package/dist/collection/components/viewer-grid/viewer-grid.template.js +7 -3
  51. package/dist/custom-elements/index.d.ts +6 -0
  52. package/dist/custom-elements/index.js +3088 -3103
  53. package/dist/dso-toolkit/dso-toolkit.css +1 -1
  54. package/dist/dso-toolkit/dso-toolkit.esm.js +1 -1
  55. package/dist/dso-toolkit/p-225bbb28.entry.js +1 -0
  56. package/dist/dso-toolkit/p-3c4dbd89.entry.js +1 -0
  57. package/dist/dso-toolkit/p-44905fb1.js +5 -0
  58. package/dist/dso-toolkit/p-50b63cf4.entry.js +1 -0
  59. package/dist/dso-toolkit/p-8b6e3abc.entry.js +1 -0
  60. package/dist/dso-toolkit/p-ad540748.entry.js +1 -0
  61. package/dist/dso-toolkit/p-c6f467b3.entry.js +1 -0
  62. package/dist/dso-toolkit/p-f193c258.entry.js +1 -0
  63. package/dist/esm/dso-autosuggest.entry.js +5 -1
  64. package/dist/esm/dso-header.entry.js +1 -1
  65. package/dist/esm/dso-image-overlay.entry.js +58 -0
  66. package/dist/esm/dso-info_2.entry.js +4 -1
  67. package/dist/esm/dso-map-base-layers.entry.js +14 -1
  68. package/dist/esm/dso-map-overlays.entry.js +14 -1
  69. package/dist/esm/dso-ozon-content.entry.js +282 -424
  70. package/dist/esm/dso-toolkit.js +1 -1
  71. package/dist/esm/dso-viewer-grid.entry.js +58 -727
  72. package/dist/esm/focus-trap.esm-299989f2.js +710 -0
  73. package/dist/esm/loader.js +1 -1
  74. package/dist/types/components/autosuggest/autosuggest.d.ts +15 -1
  75. package/dist/types/components/image-overlay/image-overlay.d.ts +15 -0
  76. package/dist/types/components/image-overlay/image-overlay.template.d.ts +2 -0
  77. package/dist/types/components/map-base-layers/map-base-layers.d.ts +7 -2
  78. package/dist/types/components/map-overlays/map-overlays.d.ts +7 -2
  79. package/dist/types/components/ozon-content/nodes/al.node.d.ts +6 -0
  80. package/dist/types/components/ozon-content/nodes/document.node.d.ts +6 -0
  81. package/dist/types/components/ozon-content/nodes/ext-ref.node.d.ts +6 -0
  82. package/dist/types/components/ozon-content/nodes/fallback.node.d.ts +6 -0
  83. package/dist/types/components/ozon-content/nodes/illustratie.node.d.ts +5 -0
  84. package/dist/types/components/ozon-content/nodes/inhoud.node.d.ts +6 -0
  85. package/dist/types/components/ozon-content/nodes/inline.nodes.d.ts +6 -0
  86. package/dist/types/components/ozon-content/nodes/int-ref.node.d.ts +6 -0
  87. package/dist/types/components/ozon-content/nodes/noot.node.d.ts +8 -0
  88. package/dist/types/components/ozon-content/nodes/table.node/colspec/colspec-mapper.d.ts +2 -0
  89. package/dist/types/components/ozon-content/nodes/table.node/colspec/colspec.interface.d.ts +10 -0
  90. package/dist/types/components/ozon-content/nodes/table.node/index.d.ts +1 -0
  91. package/dist/types/components/ozon-content/nodes/table.node/table-cell.d.ts +8 -0
  92. package/dist/types/components/ozon-content/nodes/table.node/table-colgroup.d.ts +5 -0
  93. package/dist/types/components/ozon-content/nodes/table.node/table-rows.d.ts +8 -0
  94. package/dist/types/components/ozon-content/nodes/table.node/table.node.d.ts +7 -0
  95. package/dist/types/components/ozon-content/nodes/text.node.d.ts +5 -0
  96. package/dist/types/components/ozon-content/ozon-content-context.interface.d.ts +8 -0
  97. package/dist/types/components/ozon-content/ozon-content-mapper.d.ts +12 -0
  98. package/dist/types/components/ozon-content/ozon-content-node-context.interface.d.ts +8 -0
  99. package/dist/types/components/ozon-content/ozon-content-node-state.interface.d.ts +3 -0
  100. package/dist/types/components/ozon-content/ozon-content-node.interface.d.ts +8 -0
  101. package/dist/types/components/ozon-content/ozon-content.d.ts +8 -10
  102. package/dist/types/components/ozon-content/ozon-content.interfaces.d.ts +2 -2
  103. package/dist/types/components/selectable/selectable.d.ts +1 -0
  104. package/dist/types/components/viewer-grid/viewer-grid-filterpanel-buttons.d.ts +6 -0
  105. package/dist/types/components/viewer-grid/viewer-grid.d.ts +14 -3
  106. package/dist/types/components/viewer-grid/viewer-grid.template.d.ts +1 -1
  107. package/dist/types/components.d.ts +25 -6
  108. package/package.json +2 -2
  109. package/dist/collection/components/ozon-content/ozon-content.transformer.js +0 -105
  110. package/dist/dso-toolkit/p-06de0fa1.entry.js +0 -1
  111. package/dist/dso-toolkit/p-17f073d1.entry.js +0 -1
  112. package/dist/dso-toolkit/p-20856f91.entry.js +0 -1
  113. package/dist/dso-toolkit/p-7b006b11.entry.js +0 -1
  114. package/dist/dso-toolkit/p-aadc4f8e.entry.js +0 -1
  115. package/dist/dso-toolkit/p-b69134ed.entry.js +0 -5
  116. package/dist/types/components/ozon-content/ozon-content.transformer.d.ts +0 -15
@@ -0,0 +1,712 @@
1
+ 'use strict';
2
+
3
+ const index_esm = require('./index.esm-2ac7081c.js');
4
+
5
+ /*!
6
+ * focus-trap 6.7.3
7
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
8
+ */
9
+
10
+ function ownKeys(object, enumerableOnly) {
11
+ var keys = Object.keys(object);
12
+
13
+ if (Object.getOwnPropertySymbols) {
14
+ var symbols = Object.getOwnPropertySymbols(object);
15
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
16
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
17
+ })), keys.push.apply(keys, symbols);
18
+ }
19
+
20
+ return keys;
21
+ }
22
+
23
+ function _objectSpread2(target) {
24
+ for (var i = 1; i < arguments.length; i++) {
25
+ var source = null != arguments[i] ? arguments[i] : {};
26
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
27
+ _defineProperty(target, key, source[key]);
28
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
29
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
30
+ });
31
+ }
32
+
33
+ return target;
34
+ }
35
+
36
+ function _defineProperty(obj, key, value) {
37
+ if (key in obj) {
38
+ Object.defineProperty(obj, key, {
39
+ value: value,
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true
43
+ });
44
+ } else {
45
+ obj[key] = value;
46
+ }
47
+
48
+ return obj;
49
+ }
50
+
51
+ var activeFocusTraps = function () {
52
+ var trapQueue = [];
53
+ return {
54
+ activateTrap: function activateTrap(trap) {
55
+ if (trapQueue.length > 0) {
56
+ var activeTrap = trapQueue[trapQueue.length - 1];
57
+
58
+ if (activeTrap !== trap) {
59
+ activeTrap.pause();
60
+ }
61
+ }
62
+
63
+ var trapIndex = trapQueue.indexOf(trap);
64
+
65
+ if (trapIndex === -1) {
66
+ trapQueue.push(trap);
67
+ } else {
68
+ // move this existing trap to the front of the queue
69
+ trapQueue.splice(trapIndex, 1);
70
+ trapQueue.push(trap);
71
+ }
72
+ },
73
+ deactivateTrap: function deactivateTrap(trap) {
74
+ var trapIndex = trapQueue.indexOf(trap);
75
+
76
+ if (trapIndex !== -1) {
77
+ trapQueue.splice(trapIndex, 1);
78
+ }
79
+
80
+ if (trapQueue.length > 0) {
81
+ trapQueue[trapQueue.length - 1].unpause();
82
+ }
83
+ }
84
+ };
85
+ }();
86
+
87
+ var isSelectableInput = function isSelectableInput(node) {
88
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
89
+ };
90
+
91
+ var isEscapeEvent = function isEscapeEvent(e) {
92
+ return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;
93
+ };
94
+
95
+ var isTabEvent = function isTabEvent(e) {
96
+ return e.key === 'Tab' || e.keyCode === 9;
97
+ };
98
+
99
+ var delay = function delay(fn) {
100
+ return setTimeout(fn, 0);
101
+ }; // Array.find/findIndex() are not supported on IE; this replicates enough
102
+ // of Array.findIndex() for our needs
103
+
104
+
105
+ var findIndex = function findIndex(arr, fn) {
106
+ var idx = -1;
107
+ arr.every(function (value, i) {
108
+ if (fn(value)) {
109
+ idx = i;
110
+ return false; // break
111
+ }
112
+
113
+ return true; // next
114
+ });
115
+ return idx;
116
+ };
117
+ /**
118
+ * Get an option's value when it could be a plain value, or a handler that provides
119
+ * the value.
120
+ * @param {*} value Option's value to check.
121
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
122
+ * @returns {*} The `value`, or the handler's returned value.
123
+ */
124
+
125
+
126
+ var valueOrHandler = function valueOrHandler(value) {
127
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
128
+ params[_key - 1] = arguments[_key];
129
+ }
130
+
131
+ return typeof value === 'function' ? value.apply(void 0, params) : value;
132
+ };
133
+
134
+ var getActualTarget = function getActualTarget(event) {
135
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
136
+ // shadow host. However, event.target.composedPath() will be an array of
137
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
138
+ // outer-most (the host HTML document). If we have access to composedPath(),
139
+ // then use its first element; otherwise, fall back to event.target (and
140
+ // this only works for an _open_ shadow DOM; otherwise,
141
+ // composedPath()[0] === event.target always).
142
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
143
+ };
144
+
145
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
146
+ // SSR: a live trap shouldn't be created in this type of environment so this
147
+ // should be safe code to execute if the `document` option isn't specified
148
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
149
+
150
+ var config = _objectSpread2({
151
+ returnFocusOnDeactivate: true,
152
+ escapeDeactivates: true,
153
+ delayInitialFocus: true
154
+ }, userOptions);
155
+
156
+ var state = {
157
+ // @type {Array<HTMLElement>}
158
+ containers: [],
159
+ // list of objects identifying the first and last tabbable nodes in all containers/groups in
160
+ // the trap
161
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
162
+ // is active, but the trap should never get to a state where there isn't at least one group
163
+ // with at least one tabbable node in it (that would lead to an error condition that would
164
+ // result in an error being thrown)
165
+ // @type {Array<{
166
+ // container: HTMLElement,
167
+ // firstTabbableNode: HTMLElement|null,
168
+ // lastTabbableNode: HTMLElement|null,
169
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
170
+ // }>}
171
+ tabbableGroups: [],
172
+ nodeFocusedBeforeActivation: null,
173
+ mostRecentlyFocusedNode: null,
174
+ active: false,
175
+ paused: false,
176
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
177
+ // has been delayed during activation
178
+ delayInitialFocusTimer: undefined
179
+ };
180
+ 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
181
+
182
+ var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
183
+ return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
184
+ };
185
+
186
+ var containersContain = function containersContain(element) {
187
+ return !!(element && state.containers.some(function (container) {
188
+ return container.contains(element);
189
+ }));
190
+ };
191
+ /**
192
+ * Gets the node for the given option, which is expected to be an option that
193
+ * can be either a DOM node, a string that is a selector to get a node, `false`
194
+ * (if a node is explicitly NOT given), or a function that returns any of these
195
+ * values.
196
+ * @param {string} optionName
197
+ * @returns {undefined | false | HTMLElement | SVGElement} Returns
198
+ * `undefined` if the option is not specified; `false` if the option
199
+ * resolved to `false` (node explicitly not given); otherwise, the resolved
200
+ * DOM node.
201
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
202
+ * resolve to a node.
203
+ */
204
+
205
+
206
+ var getNodeForOption = function getNodeForOption(optionName) {
207
+ var optionValue = config[optionName];
208
+
209
+ if (typeof optionValue === 'function') {
210
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
211
+ params[_key2 - 1] = arguments[_key2];
212
+ }
213
+
214
+ optionValue = optionValue.apply(void 0, params);
215
+ }
216
+
217
+ if (!optionValue) {
218
+ if (optionValue === undefined || optionValue === false) {
219
+ return optionValue;
220
+ } // else, empty string (invalid), null (invalid), 0 (invalid)
221
+
222
+
223
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
224
+ }
225
+
226
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
227
+
228
+ if (typeof optionValue === 'string') {
229
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
230
+
231
+ if (!node) {
232
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
233
+ }
234
+ }
235
+
236
+ return node;
237
+ };
238
+
239
+ var getInitialFocusNode = function getInitialFocusNode() {
240
+ var node = getNodeForOption('initialFocus'); // false explicitly indicates we want no initialFocus at all
241
+
242
+ if (node === false) {
243
+ return false;
244
+ }
245
+
246
+ if (node === undefined) {
247
+ // option not specified: use fallback options
248
+ if (containersContain(doc.activeElement)) {
249
+ node = doc.activeElement;
250
+ } else {
251
+ var firstTabbableGroup = state.tabbableGroups[0];
252
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
253
+
254
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
255
+ }
256
+ }
257
+
258
+ if (!node) {
259
+ throw new Error('Your focus-trap needs to have at least one focusable element');
260
+ }
261
+
262
+ return node;
263
+ };
264
+
265
+ var updateTabbableNodes = function updateTabbableNodes() {
266
+ state.tabbableGroups = state.containers.map(function (container) {
267
+ var tabbableNodes = index_esm.tabbable(container); // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
268
+ // are a superset of tabbable nodes
269
+
270
+ var focusableNodes = index_esm.focusable(container);
271
+
272
+ if (tabbableNodes.length > 0) {
273
+ return {
274
+ container: container,
275
+ firstTabbableNode: tabbableNodes[0],
276
+ lastTabbableNode: tabbableNodes[tabbableNodes.length - 1],
277
+
278
+ /**
279
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
280
+ * in this container, if any.
281
+ * @param {HTMLElement} node
282
+ * @param {boolean} [forward] True if going in forward tab order; false if going
283
+ * in reverse.
284
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
285
+ */
286
+ nextTabbableNode: function nextTabbableNode(node) {
287
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
288
+ // NOTE: If tabindex is positive (in order to manipulate the tab order separate
289
+ // from the DOM order), this __will not work__ because the list of focusableNodes,
290
+ // while it contains tabbable nodes, does not sort its nodes in any order other
291
+ // than DOM order, because it can't: Where would you place focusable (but not
292
+ // tabbable) nodes in that order? They have no order, because they aren't tabbale...
293
+ // Support for positive tabindex is already broken and hard to manage (possibly
294
+ // not supportable, TBD), so this isn't going to make things worse than they
295
+ // already are, and at least makes things better for the majority of cases where
296
+ // tabindex is either 0/unset or negative.
297
+ // FYI, positive tabindex issue: https://github.com/focus-trap/focus-trap/issues/375
298
+ var nodeIdx = focusableNodes.findIndex(function (n) {
299
+ return n === node;
300
+ });
301
+
302
+ if (forward) {
303
+ return focusableNodes.slice(nodeIdx + 1).find(function (n) {
304
+ return index_esm.isTabbable(n);
305
+ });
306
+ }
307
+
308
+ return focusableNodes.slice(0, nodeIdx).reverse().find(function (n) {
309
+ return index_esm.isTabbable(n);
310
+ });
311
+ }
312
+ };
313
+ }
314
+
315
+ return undefined;
316
+ }).filter(function (group) {
317
+ return !!group;
318
+ }); // remove groups with no tabbable nodes
319
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
320
+
321
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
322
+ ) {
323
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
324
+ }
325
+ };
326
+
327
+ var tryFocus = function tryFocus(node) {
328
+ if (node === false) {
329
+ return;
330
+ }
331
+
332
+ if (node === doc.activeElement) {
333
+ return;
334
+ }
335
+
336
+ if (!node || !node.focus) {
337
+ tryFocus(getInitialFocusNode());
338
+ return;
339
+ }
340
+
341
+ node.focus({
342
+ preventScroll: !!config.preventScroll
343
+ });
344
+ state.mostRecentlyFocusedNode = node;
345
+
346
+ if (isSelectableInput(node)) {
347
+ node.select();
348
+ }
349
+ };
350
+
351
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
352
+ var node = getNodeForOption('setReturnFocus', previousActiveElement);
353
+ return node ? node : node === false ? false : previousActiveElement;
354
+ }; // This needs to be done on mousedown and touchstart instead of click
355
+ // so that it precedes the focus event.
356
+
357
+
358
+ var checkPointerDown = function checkPointerDown(e) {
359
+ var target = getActualTarget(e);
360
+
361
+ if (containersContain(target)) {
362
+ // allow the click since it ocurred inside the trap
363
+ return;
364
+ }
365
+
366
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
367
+ // immediately deactivate the trap
368
+ trap.deactivate({
369
+ // if, on deactivation, we should return focus to the node originally-focused
370
+ // when the trap was activated (or the configured `setReturnFocus` node),
371
+ // then assume it's also OK to return focus to the outside node that was
372
+ // just clicked, causing deactivation, as long as that node is focusable;
373
+ // if it isn't focusable, then return focus to the original node focused
374
+ // on activation (or the configured `setReturnFocus` node)
375
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
376
+ // which will result in the outside click setting focus to the node
377
+ // that was clicked, whether it's focusable or not; by setting
378
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
379
+ // on activation (or the configured `setReturnFocus` node)
380
+ returnFocus: config.returnFocusOnDeactivate && !index_esm.isFocusable(target)
381
+ });
382
+ return;
383
+ } // This is needed for mobile devices.
384
+ // (If we'll only let `click` events through,
385
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
386
+
387
+
388
+ if (valueOrHandler(config.allowOutsideClick, e)) {
389
+ // allow the click outside the trap to take place
390
+ return;
391
+ } // otherwise, prevent the click
392
+
393
+
394
+ e.preventDefault();
395
+ }; // In case focus escapes the trap for some strange reason, pull it back in.
396
+
397
+
398
+ var checkFocusIn = function checkFocusIn(e) {
399
+ var target = getActualTarget(e);
400
+ var targetContained = containersContain(target); // In Firefox when you Tab out of an iframe the Document is briefly focused.
401
+
402
+ if (targetContained || target instanceof Document) {
403
+ if (targetContained) {
404
+ state.mostRecentlyFocusedNode = target;
405
+ }
406
+ } else {
407
+ // escaped! pull it back in to where it just left
408
+ e.stopImmediatePropagation();
409
+ tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
410
+ }
411
+ }; // Hijack Tab events on the first and last focusable nodes of the trap,
412
+ // in order to prevent focus from escaping. If it escapes for even a
413
+ // moment it can end up scrolling the page and causing confusion so we
414
+ // kind of need to capture the action at the keydown phase.
415
+
416
+
417
+ var checkTab = function checkTab(e) {
418
+ var target = getActualTarget(e);
419
+ updateTabbableNodes();
420
+ var destinationNode = null;
421
+
422
+ if (state.tabbableGroups.length > 0) {
423
+ // make sure the target is actually contained in a group
424
+ // NOTE: the target may also be the container itself if it's focusable
425
+ // with tabIndex='-1' and was given initial focus
426
+ var containerIndex = findIndex(state.tabbableGroups, function (_ref) {
427
+ var container = _ref.container;
428
+ return container.contains(target);
429
+ });
430
+ var containerGroup = containerIndex >= 0 ? state.tabbableGroups[containerIndex] : undefined;
431
+
432
+ if (containerIndex < 0) {
433
+ // target not found in any group: quite possible focus has escaped the trap,
434
+ // so bring it back in to...
435
+ if (e.shiftKey) {
436
+ // ...the last node in the last group
437
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
438
+ } else {
439
+ // ...the first node in the first group
440
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
441
+ }
442
+ } else if (e.shiftKey) {
443
+ // REVERSE
444
+ // is the target the first tabbable node in a group?
445
+ var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
446
+ var firstTabbableNode = _ref2.firstTabbableNode;
447
+ return target === firstTabbableNode;
448
+ });
449
+
450
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || index_esm.isFocusable(target) && !index_esm.isTabbable(target) && !containerGroup.nextTabbableNode(target, false))) {
451
+ // an exception case where the target is either the container itself, or
452
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
453
+ // and user clicked on it or node was programmatically given focus)
454
+ // and is not followed by any other tabbable node, in which
455
+ // case, we should handle shift+tab as if focus were on the container's
456
+ // first tabbable node, and go to the last tabbable node of the LAST group
457
+ startOfGroupIndex = containerIndex;
458
+ }
459
+
460
+ if (startOfGroupIndex >= 0) {
461
+ // YES: then shift+tab should go to the last tabbable node in the
462
+ // previous group (and wrap around to the last tabbable node of
463
+ // the LAST group if it's the first tabbable node of the FIRST group)
464
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
465
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
466
+ destinationNode = destinationGroup.lastTabbableNode;
467
+ }
468
+ } else {
469
+ // FORWARD
470
+ // is the target the last tabbable node in a group?
471
+ var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
472
+ var lastTabbableNode = _ref3.lastTabbableNode;
473
+ return target === lastTabbableNode;
474
+ });
475
+
476
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || index_esm.isFocusable(target) && !index_esm.isTabbable(target) && !containerGroup.nextTabbableNode(target))) {
477
+ // an exception case where the target is the container itself, or
478
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
479
+ // and user clicked on it or node was programmatically given focus)
480
+ // and is not followed by any other tabbable node, in which
481
+ // case, we should handle tab as if focus were on the container's
482
+ // last tabbable node, and go to the first tabbable node of the FIRST group
483
+ lastOfGroupIndex = containerIndex;
484
+ }
485
+
486
+ if (lastOfGroupIndex >= 0) {
487
+ // YES: then tab should go to the first tabbable node in the next
488
+ // group (and wrap around to the first tabbable node of the FIRST
489
+ // group if it's the last tabbable node of the LAST group)
490
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
491
+
492
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
493
+ destinationNode = _destinationGroup.firstTabbableNode;
494
+ }
495
+ }
496
+ } else {
497
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
498
+ destinationNode = getNodeForOption('fallbackFocus');
499
+ }
500
+
501
+ if (destinationNode) {
502
+ e.preventDefault();
503
+ tryFocus(destinationNode);
504
+ } // else, let the browser take care of [shift+]tab and move the focus
505
+
506
+ };
507
+
508
+ var checkKey = function checkKey(e) {
509
+ if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) {
510
+ e.preventDefault();
511
+ trap.deactivate();
512
+ return;
513
+ }
514
+
515
+ if (isTabEvent(e)) {
516
+ checkTab(e);
517
+ return;
518
+ }
519
+ };
520
+
521
+ var checkClick = function checkClick(e) {
522
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
523
+ return;
524
+ }
525
+
526
+ var target = getActualTarget(e);
527
+
528
+ if (containersContain(target)) {
529
+ return;
530
+ }
531
+
532
+ if (valueOrHandler(config.allowOutsideClick, e)) {
533
+ return;
534
+ }
535
+
536
+ e.preventDefault();
537
+ e.stopImmediatePropagation();
538
+ }; //
539
+ // EVENT LISTENERS
540
+ //
541
+
542
+
543
+ var addListeners = function addListeners() {
544
+ if (!state.active) {
545
+ return;
546
+ } // There can be only one listening focus trap at a time
547
+
548
+
549
+ activeFocusTraps.activateTrap(trap); // Delay ensures that the focused element doesn't capture the event
550
+ // that caused the focus trap activation.
551
+
552
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
553
+ tryFocus(getInitialFocusNode());
554
+ }) : tryFocus(getInitialFocusNode());
555
+ doc.addEventListener('focusin', checkFocusIn, true);
556
+ doc.addEventListener('mousedown', checkPointerDown, {
557
+ capture: true,
558
+ passive: false
559
+ });
560
+ doc.addEventListener('touchstart', checkPointerDown, {
561
+ capture: true,
562
+ passive: false
563
+ });
564
+ doc.addEventListener('click', checkClick, {
565
+ capture: true,
566
+ passive: false
567
+ });
568
+ doc.addEventListener('keydown', checkKey, {
569
+ capture: true,
570
+ passive: false
571
+ });
572
+ return trap;
573
+ };
574
+
575
+ var removeListeners = function removeListeners() {
576
+ if (!state.active) {
577
+ return;
578
+ }
579
+
580
+ doc.removeEventListener('focusin', checkFocusIn, true);
581
+ doc.removeEventListener('mousedown', checkPointerDown, true);
582
+ doc.removeEventListener('touchstart', checkPointerDown, true);
583
+ doc.removeEventListener('click', checkClick, true);
584
+ doc.removeEventListener('keydown', checkKey, true);
585
+ return trap;
586
+ }; //
587
+ // TRAP DEFINITION
588
+ //
589
+
590
+
591
+ trap = {
592
+ activate: function activate(activateOptions) {
593
+ if (state.active) {
594
+ return this;
595
+ }
596
+
597
+ var onActivate = getOption(activateOptions, 'onActivate');
598
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
599
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
600
+
601
+ if (!checkCanFocusTrap) {
602
+ updateTabbableNodes();
603
+ }
604
+
605
+ state.active = true;
606
+ state.paused = false;
607
+ state.nodeFocusedBeforeActivation = doc.activeElement;
608
+
609
+ if (onActivate) {
610
+ onActivate();
611
+ }
612
+
613
+ var finishActivation = function finishActivation() {
614
+ if (checkCanFocusTrap) {
615
+ updateTabbableNodes();
616
+ }
617
+
618
+ addListeners();
619
+
620
+ if (onPostActivate) {
621
+ onPostActivate();
622
+ }
623
+ };
624
+
625
+ if (checkCanFocusTrap) {
626
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
627
+ return this;
628
+ }
629
+
630
+ finishActivation();
631
+ return this;
632
+ },
633
+ deactivate: function deactivate(deactivateOptions) {
634
+ if (!state.active) {
635
+ return this;
636
+ }
637
+
638
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
639
+
640
+ state.delayInitialFocusTimer = undefined;
641
+ removeListeners();
642
+ state.active = false;
643
+ state.paused = false;
644
+ activeFocusTraps.deactivateTrap(trap);
645
+ var onDeactivate = getOption(deactivateOptions, 'onDeactivate');
646
+ var onPostDeactivate = getOption(deactivateOptions, 'onPostDeactivate');
647
+ var checkCanReturnFocus = getOption(deactivateOptions, 'checkCanReturnFocus');
648
+
649
+ if (onDeactivate) {
650
+ onDeactivate();
651
+ }
652
+
653
+ var returnFocus = getOption(deactivateOptions, 'returnFocus', 'returnFocusOnDeactivate');
654
+
655
+ var finishDeactivation = function finishDeactivation() {
656
+ delay(function () {
657
+ if (returnFocus) {
658
+ tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
659
+ }
660
+
661
+ if (onPostDeactivate) {
662
+ onPostDeactivate();
663
+ }
664
+ });
665
+ };
666
+
667
+ if (returnFocus && checkCanReturnFocus) {
668
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
669
+ return this;
670
+ }
671
+
672
+ finishDeactivation();
673
+ return this;
674
+ },
675
+ pause: function pause() {
676
+ if (state.paused || !state.active) {
677
+ return this;
678
+ }
679
+
680
+ state.paused = true;
681
+ removeListeners();
682
+ return this;
683
+ },
684
+ unpause: function unpause() {
685
+ if (!state.paused || !state.active) {
686
+ return this;
687
+ }
688
+
689
+ state.paused = false;
690
+ updateTabbableNodes();
691
+ addListeners();
692
+ return this;
693
+ },
694
+ updateContainerElements: function updateContainerElements(containerElements) {
695
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
696
+ state.containers = elementsAsArray.map(function (element) {
697
+ return typeof element === 'string' ? doc.querySelector(element) : element;
698
+ });
699
+
700
+ if (state.active) {
701
+ updateTabbableNodes();
702
+ }
703
+
704
+ return this;
705
+ }
706
+ }; // initialize container elements
707
+
708
+ trap.updateContainerElements(elements);
709
+ return trap;
710
+ };
711
+
712
+ exports.createFocusTrap = createFocusTrap;