@content-blocks/js 0.7.1 → 0.7.3

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