@odx/foundation 1.0.0-alpha.6 → 1.0.0-alpha.7

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 (248) hide show
  1. package/README.md +7 -7
  2. package/dist/cdk.js +345 -0
  3. package/dist/components/accordion/accordion-header.component.d.ts +1 -1
  4. package/dist/components/button/base-button.d.ts +1 -1
  5. package/dist/components/button/button.component.d.ts +1 -1
  6. package/dist/components/button-group/button-group.component.d.ts +1 -1
  7. package/dist/components/card/card.component.d.ts +1 -1
  8. package/dist/components/chip/chip.component.d.ts +1 -1
  9. package/dist/components/dropdown/dropdown.component.d.ts +2 -2
  10. package/dist/components/format/format-date.component.d.ts +1 -1
  11. package/dist/components/format/format-number.component.d.ts +1 -1
  12. package/dist/components/format/format.component.d.ts +2 -2
  13. package/dist/components/format/relative-time.component.d.ts +1 -1
  14. package/dist/components/input/input.component.d.ts +1 -1
  15. package/dist/components/link/base-link.d.ts +1 -1
  16. package/dist/components/loading-overlay/loading-overlay.component.d.ts +1 -1
  17. package/dist/components/menu/menu.component.d.ts +2 -2
  18. package/dist/components/slider/slider-handle.component.d.ts +2 -2
  19. package/dist/components/slider/slider.component.d.ts +1 -1
  20. package/dist/components/spinbox/spinbox.component.d.ts +1 -1
  21. package/dist/components/tooltip/tooltip.element.d.ts +2 -2
  22. package/dist/components.js +4284 -0
  23. package/dist/i18n/lib/translate.d.ts +5 -1
  24. package/dist/i18n.js +140 -0
  25. package/dist/main.js +1448 -0
  26. package/dist/vendor.js +3660 -0
  27. package/package.json +13 -22
  28. package/dist/cdk/drag-drop/drag.controller.js +0 -90
  29. package/dist/cdk/drag-drop/is-draggable.js +0 -42
  30. package/dist/cdk/main.js +0 -5
  31. package/dist/cdk/popover/popover-host.mixin.css.js +0 -3
  32. package/dist/cdk/popover/popover-host.mixin.js +0 -115
  33. package/dist/cdk/popover/popover.component.css.js +0 -3
  34. package/dist/cdk/popover/popover.component.js +0 -38
  35. package/dist/cdk/popover/popover.models.js +0 -32
  36. package/dist/cdk/popover/popover.utils.js +0 -48
  37. package/dist/components/accordion/accordion-header.component.css.js +0 -3
  38. package/dist/components/accordion/accordion-header.component.js +0 -69
  39. package/dist/components/accordion/accordion-panel.component.css.js +0 -3
  40. package/dist/components/accordion/accordion-panel.component.js +0 -29
  41. package/dist/components/accordion/accordion.component.css.js +0 -3
  42. package/dist/components/accordion/accordion.component.js +0 -83
  43. package/dist/components/area-header/area-header.component.css.js +0 -3
  44. package/dist/components/area-header/area-header.component.js +0 -37
  45. package/dist/components/area-header/area-header.models.js +0 -11
  46. package/dist/components/avatar/avatar.component.css.js +0 -3
  47. package/dist/components/avatar/avatar.component.js +0 -31
  48. package/dist/components/avatar/avatar.models.js +0 -12
  49. package/dist/components/avatar-group/avatar-group.component.css.js +0 -3
  50. package/dist/components/avatar-group/avatar-group.component.js +0 -31
  51. package/dist/components/badge/badge.component.css.js +0 -3
  52. package/dist/components/badge/badge.component.js +0 -32
  53. package/dist/components/badge/badge.models.js +0 -10
  54. package/dist/components/breadcrumbs/breadcrumbs-item.component.css.js +0 -3
  55. package/dist/components/breadcrumbs/breadcrumbs-item.component.js +0 -56
  56. package/dist/components/breadcrumbs/breadcrumbs.component.css.js +0 -3
  57. package/dist/components/breadcrumbs/breadcrumbs.component.js +0 -88
  58. package/dist/components/button/base-button.css.js +0 -3
  59. package/dist/components/button/base-button.js +0 -72
  60. package/dist/components/button/button.component.css.js +0 -3
  61. package/dist/components/button/button.component.js +0 -66
  62. package/dist/components/button/button.models.js +0 -16
  63. package/dist/components/button-group/button-group.component.css.js +0 -3
  64. package/dist/components/button-group/button-group.component.js +0 -47
  65. package/dist/components/card/card.component.css.js +0 -3
  66. package/dist/components/card/card.component.js +0 -30
  67. package/dist/components/checkbox/checkbox.component.css.js +0 -3
  68. package/dist/components/checkbox/checkbox.component.js +0 -57
  69. package/dist/components/checkbox-group/checkbox-group.component.css.js +0 -3
  70. package/dist/components/checkbox-group/checkbox-group.component.js +0 -54
  71. package/dist/components/checkbox-group/checkbox-group.models.js +0 -5
  72. package/dist/components/chip/chip.component.css.js +0 -3
  73. package/dist/components/chip/chip.component.js +0 -94
  74. package/dist/components/chip/chip.models.js +0 -10
  75. package/dist/components/circular-progress-bar/circular-progress-bar.component.css.js +0 -3
  76. package/dist/components/circular-progress-bar/circular-progress-bar.component.js +0 -123
  77. package/dist/components/circular-progress-bar/circular-progress-bar.models.js +0 -7
  78. package/dist/components/content-box/content-box.component.css.js +0 -3
  79. package/dist/components/content-box/content-box.component.js +0 -26
  80. package/dist/components/dropdown/dropdown.component.css.js +0 -3
  81. package/dist/components/dropdown/dropdown.component.js +0 -121
  82. package/dist/components/dropdown/dropdown.models.js +0 -8
  83. package/dist/components/form-field/form-field.element.css.js +0 -3
  84. package/dist/components/form-field/form-field.element.js +0 -62
  85. package/dist/components/format/format-bytes.component.js +0 -46
  86. package/dist/components/format/format-date.component.js +0 -36
  87. package/dist/components/format/format-number.component.js +0 -59
  88. package/dist/components/format/format.component.js +0 -34
  89. package/dist/components/format/relative-time.component.js +0 -80
  90. package/dist/components/header/header-actions.component.css.js +0 -3
  91. package/dist/components/header/header-actions.component.js +0 -22
  92. package/dist/components/header/header.component.css.js +0 -3
  93. package/dist/components/header/header.component.js +0 -58
  94. package/dist/components/headline/headline.component.css.js +0 -3
  95. package/dist/components/headline/headline.component.js +0 -31
  96. package/dist/components/headline/headline.models.js +0 -8
  97. package/dist/components/icon-button/icon-button.component.js +0 -34
  98. package/dist/components/inline-message/inline-message.component.css.js +0 -3
  99. package/dist/components/inline-message/inline-message.component.js +0 -39
  100. package/dist/components/inline-message/inline-message.models.js +0 -9
  101. package/dist/components/input/input.component.css.js +0 -3
  102. package/dist/components/input/input.component.js +0 -72
  103. package/dist/components/input/input.models.js +0 -7
  104. package/dist/components/line-clamp/line-clamp.component.css.js +0 -3
  105. package/dist/components/line-clamp/line-clamp.component.js +0 -37
  106. package/dist/components/link/base-link.js +0 -70
  107. package/dist/components/link/link.component.css.js +0 -3
  108. package/dist/components/link/link.component.js +0 -33
  109. package/dist/components/list/list-item.component.css.js +0 -3
  110. package/dist/components/list/list-item.component.js +0 -33
  111. package/dist/components/list/list.component.css.js +0 -3
  112. package/dist/components/list/list.component.js +0 -25
  113. package/dist/components/loading-overlay/loading-overlay.component.css.js +0 -3
  114. package/dist/components/loading-overlay/loading-overlay.component.js +0 -78
  115. package/dist/components/loading-spinner/loading-spinner.component.css.js +0 -3
  116. package/dist/components/loading-spinner/loading-spinner.component.js +0 -58
  117. package/dist/components/logo/logo.component.css.js +0 -3
  118. package/dist/components/logo/logo.component.js +0 -38
  119. package/dist/components/logo/logo.models.js +0 -9
  120. package/dist/components/main-menu/main-menu-button.component.js +0 -38
  121. package/dist/components/main-menu/main-menu-link.component.css.js +0 -3
  122. package/dist/components/main-menu/main-menu-link.component.js +0 -20
  123. package/dist/components/main-menu/main-menu-subtitle.component.js +0 -29
  124. package/dist/components/main-menu/main-menu-title.component.js +0 -29
  125. package/dist/components/main-menu/main-menu.component.css.js +0 -3
  126. package/dist/components/main-menu/main-menu.component.js +0 -82
  127. package/dist/components/main.js +0 -102
  128. package/dist/components/menu/menu-label.component.css.js +0 -3
  129. package/dist/components/menu/menu-label.component.js +0 -18
  130. package/dist/components/menu/menu.component.css.js +0 -3
  131. package/dist/components/menu/menu.component.js +0 -111
  132. package/dist/components/menu-item/menu-item.component.css.js +0 -3
  133. package/dist/components/menu-item/menu-item.component.js +0 -45
  134. package/dist/components/navigation-item/navigation-item.component.css.js +0 -3
  135. package/dist/components/navigation-item/navigation-item.component.js +0 -43
  136. package/dist/components/navigation-item/navigation-item.models.js +0 -6
  137. package/dist/components/option/option.component.css.js +0 -3
  138. package/dist/components/option/option.component.js +0 -37
  139. package/dist/components/page/page.component.css.js +0 -3
  140. package/dist/components/page/page.component.js +0 -53
  141. package/dist/components/page/page.models.js +0 -9
  142. package/dist/components/page-layout/page-layout.component.css.js +0 -3
  143. package/dist/components/page-layout/page-layout.component.js +0 -28
  144. package/dist/components/progress-bar/progress-bar.component.css.js +0 -3
  145. package/dist/components/progress-bar/progress-bar.component.js +0 -89
  146. package/dist/components/progress-bar/progress-bar.models.js +0 -7
  147. package/dist/components/radio-button/radio-button.component.css.js +0 -3
  148. package/dist/components/radio-button/radio-button.component.js +0 -39
  149. package/dist/components/radio-group/radio-group.component.css.js +0 -3
  150. package/dist/components/radio-group/radio-group.component.js +0 -24
  151. package/dist/components/radio-group/radio-group.models.js +0 -5
  152. package/dist/components/rail-navigation/rail-navigation.component.css.js +0 -3
  153. package/dist/components/rail-navigation/rail-navigation.component.js +0 -65
  154. package/dist/components/search-bar/search-bar.component.css.js +0 -3
  155. package/dist/components/search-bar/search-bar.component.js +0 -100
  156. package/dist/components/search-bar/search-bar.events.js +0 -7
  157. package/dist/components/search-bar/search-bar.models.js +0 -6
  158. package/dist/components/select/select.component.css.js +0 -3
  159. package/dist/components/select/select.component.js +0 -101
  160. package/dist/components/separator/separator.component.css.js +0 -3
  161. package/dist/components/separator/separator.component.js +0 -49
  162. package/dist/components/skeleton/skeleton.component.css.js +0 -3
  163. package/dist/components/skeleton/skeleton.component.js +0 -32
  164. package/dist/components/slider/slider-handle.component.css.js +0 -3
  165. package/dist/components/slider/slider-handle.component.js +0 -168
  166. package/dist/components/slider/slider-marks.component.css.js +0 -3
  167. package/dist/components/slider/slider-marks.component.js +0 -61
  168. package/dist/components/slider/slider.component.css.js +0 -3
  169. package/dist/components/slider/slider.component.js +0 -119
  170. package/dist/components/slider/slider.models.js +0 -17
  171. package/dist/components/spacer/spacer.component.css.js +0 -3
  172. package/dist/components/spacer/spacer.component.js +0 -39
  173. package/dist/components/spinbox/spinbox.component.css.js +0 -3
  174. package/dist/components/spinbox/spinbox.component.js +0 -94
  175. package/dist/components/stack/stack.component.css.js +0 -3
  176. package/dist/components/stack/stack.component.js +0 -45
  177. package/dist/components/stack/stack.models.js +0 -23
  178. package/dist/components/switch/switch.component.css.js +0 -3
  179. package/dist/components/switch/switch.component.js +0 -36
  180. package/dist/components/table/table-body.element.css.js +0 -3
  181. package/dist/components/table/table-body.element.js +0 -26
  182. package/dist/components/table/table-cell.element.css.js +0 -3
  183. package/dist/components/table/table-cell.element.js +0 -26
  184. package/dist/components/table/table-checkbox-cell.element.css.js +0 -3
  185. package/dist/components/table/table-checkbox-cell.element.js +0 -66
  186. package/dist/components/table/table-header-cell.element.css.js +0 -3
  187. package/dist/components/table/table-header-cell.element.js +0 -40
  188. package/dist/components/table/table-header.element.css.js +0 -3
  189. package/dist/components/table/table-header.element.js +0 -52
  190. package/dist/components/table/table-row.element.css.js +0 -3
  191. package/dist/components/table/table-row.element.js +0 -111
  192. package/dist/components/table/table.element.css.js +0 -3
  193. package/dist/components/table/table.element.js +0 -97
  194. package/dist/components/text/text.component.css.js +0 -3
  195. package/dist/components/text/text.component.js +0 -34
  196. package/dist/components/text/text.models.js +0 -13
  197. package/dist/components/title/title.component.css.js +0 -3
  198. package/dist/components/title/title.component.js +0 -31
  199. package/dist/components/title/title.models.js +0 -10
  200. package/dist/components/toast/toast.element.css.js +0 -3
  201. package/dist/components/toast/toast.element.js +0 -31
  202. package/dist/components/toast/toast.models.js +0 -5
  203. package/dist/components/toggle-button/toggle-button.component.css.js +0 -3
  204. package/dist/components/toggle-button/toggle-button.component.js +0 -52
  205. package/dist/components/tooltip/tooltip.element.css.js +0 -3
  206. package/dist/components/tooltip/tooltip.element.js +0 -120
  207. package/dist/components/tooltip/tooltip.models.js +0 -10
  208. package/dist/components/visually-hidden/visually-hidden.component.css.js +0 -3
  209. package/dist/components/visually-hidden/visually-hidden.component.js +0 -22
  210. package/dist/i18n/lib/config.js +0 -16
  211. package/dist/i18n/lib/format.js +0 -55
  212. package/dist/i18n/lib/is-localized.mixin.js +0 -41
  213. package/dist/i18n/lib/localization.js +0 -28
  214. package/dist/i18n/lib/translate.js +0 -18
  215. package/dist/i18n/main.js +0 -5
  216. package/dist/lib/controllers/focus-trap.controller.js +0 -55
  217. package/dist/lib/custom-element.css.js +0 -3
  218. package/dist/lib/custom-element.js +0 -27
  219. package/dist/lib/decorators/request-update-on-aria-change.js +0 -15
  220. package/dist/lib/directives/aria-boolean-attr.js +0 -9
  221. package/dist/lib/directives/optional-attr.js +0 -8
  222. package/dist/lib/directives/optional-slot.js +0 -14
  223. package/dist/lib/directives/slot-fallback.js +0 -16
  224. package/dist/lib/external/roving-tabindex.js +0 -386
  225. package/dist/lib/facade/checkbox-form-control.js +0 -78
  226. package/dist/lib/facade/checkbox-group-form-control.js +0 -109
  227. package/dist/lib/facade/option-control.js +0 -49
  228. package/dist/lib/facade/radio-group-form-control.js +0 -87
  229. package/dist/lib/facade/select-form-control.js +0 -108
  230. package/dist/lib/main.js +0 -30
  231. package/dist/lib/mixins/can-be-disabled.js +0 -60
  232. package/dist/lib/mixins/can-be-readonly.js +0 -33
  233. package/dist/lib/mixins/can-be-required.js +0 -33
  234. package/dist/lib/mixins/can-be-validated.js +0 -32
  235. package/dist/lib/mixins/dedupe-mixin.js +0 -23
  236. package/dist/lib/mixins/form-control.js +0 -61
  237. package/dist/lib/mixins/number-control.js +0 -63
  238. package/dist/lib/mixins/with-aria-controls.js +0 -43
  239. package/dist/lib/mixins/with-loading-state.js +0 -33
  240. package/dist/lib/utils/date.js +0 -10
  241. package/dist/lib/utils/dom.js +0 -48
  242. package/dist/lib/utils/get-unique-id.js +0 -15
  243. package/dist/lib/utils/keyboard-events.js +0 -42
  244. package/dist/lib/utils/object.js +0 -7
  245. package/dist/lib/utils/shared-intersection-observer.js +0 -37
  246. package/dist/lib/utils/shared-resize-observer.js +0 -38
  247. package/dist/lib/utils/string.js +0 -7
  248. /package/dist/{lib/main.css → styles.css} +0 -0
package/dist/vendor.js ADDED
@@ -0,0 +1,3660 @@
1
+ /*!
2
+ * tabbable 6.2.0
3
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
4
+ */
5
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
6
+ // `:not([inert], [inert] *)` (Feb 2023)
7
+ // CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
8
+ // the entire query to fail, resulting in no nodes found, which will break a lot
9
+ // of things... so we have to rely on JS to identify nodes inside an inert container
10
+ var candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable="false"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];
11
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
12
+ var NoElement = typeof Element === 'undefined';
13
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
14
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
15
+ var _element$getRootNode;
16
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
17
+ } : function (element) {
18
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
19
+ };
20
+
21
+ /**
22
+ * Determines if a node is inert or in an inert ancestor.
23
+ * @param {Element} [node]
24
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
25
+ * see if any of them are inert. If false, only `node` itself is considered.
26
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
27
+ * False if `node` is falsy.
28
+ */
29
+ var isInert = function isInert(node, lookUp) {
30
+ var _node$getAttribute;
31
+ if (lookUp === void 0) {
32
+ lookUp = true;
33
+ }
34
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
35
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
36
+ // if it's `null` (not specified) or 'false', it's an active element
37
+ var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
38
+ var inert = inertAtt === '' || inertAtt === 'true';
39
+
40
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
41
+ // if it weren't for `matches()` not being a function on shadow roots; the following
42
+ // code works for any kind of node
43
+ // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
44
+ // so it likely would not support `:is([inert] *)` either...
45
+ var result = inert || lookUp && node && isInert(node.parentNode); // recursive
46
+
47
+ return result;
48
+ };
49
+
50
+ /**
51
+ * Determines if a node's content is editable.
52
+ * @param {Element} [node]
53
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
54
+ */
55
+ var isContentEditable = function isContentEditable(node) {
56
+ var _node$getAttribute2;
57
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
58
+ // to use the attribute directly to check for this, which can either be empty or 'true';
59
+ // if it's `null` (not specified) or 'false', it's a non-editable element
60
+ var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
61
+ return attValue === '' || attValue === 'true';
62
+ };
63
+
64
+ /**
65
+ * @param {Element} el container to check in
66
+ * @param {boolean} includeContainer add container to check
67
+ * @param {(node: Element) => boolean} filter filter candidates
68
+ * @returns {Element[]}
69
+ */
70
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
71
+ // even if `includeContainer=false`, we still have to check it for inertness because
72
+ // if it's inert, all its children are inert
73
+ if (isInert(el)) {
74
+ return [];
75
+ }
76
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
77
+ if (includeContainer && matches.call(el, candidateSelector)) {
78
+ candidates.unshift(el);
79
+ }
80
+ candidates = candidates.filter(filter);
81
+ return candidates;
82
+ };
83
+
84
+ /**
85
+ * @callback GetShadowRoot
86
+ * @param {Element} element to check for shadow root
87
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
88
+ */
89
+
90
+ /**
91
+ * @callback ShadowRootFilter
92
+ * @param {Element} shadowHostNode the element which contains shadow content
93
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
94
+ */
95
+
96
+ /**
97
+ * @typedef {Object} CandidateScope
98
+ * @property {Element} scopeParent contains inner candidates
99
+ * @property {Element[]} candidates list of candidates found in the scope parent
100
+ */
101
+
102
+ /**
103
+ * @typedef {Object} IterativeOptions
104
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
105
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
106
+ * or a boolean stating if it has an undisclosed shadow root
107
+ * @property {(node: Element) => boolean} filter filter candidates
108
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
109
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
110
+ */
111
+
112
+ /**
113
+ * @param {Element[]} elements list of element containers to match candidates from
114
+ * @param {boolean} includeContainer add container list to check
115
+ * @param {IterativeOptions} options
116
+ * @returns {Array.<Element|CandidateScope>}
117
+ */
118
+ var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
119
+ var candidates = [];
120
+ var elementsToCheck = Array.from(elements);
121
+ while (elementsToCheck.length) {
122
+ var element = elementsToCheck.shift();
123
+ if (isInert(element, false)) {
124
+ // no need to look up since we're drilling down
125
+ // anything inside this container will also be inert
126
+ continue;
127
+ }
128
+ if (element.tagName === 'SLOT') {
129
+ // add shadow dom slot scope (slot itself cannot be focusable)
130
+ var assigned = element.assignedElements();
131
+ var content = assigned.length ? assigned : element.children;
132
+ var nestedCandidates = getCandidatesIteratively(content, true, options);
133
+ if (options.flatten) {
134
+ candidates.push.apply(candidates, nestedCandidates);
135
+ } else {
136
+ candidates.push({
137
+ scopeParent: element,
138
+ candidates: nestedCandidates
139
+ });
140
+ }
141
+ } else {
142
+ // check candidate element
143
+ var validCandidate = matches.call(element, candidateSelector);
144
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
145
+ candidates.push(element);
146
+ }
147
+
148
+ // iterate over shadow content if possible
149
+ var shadowRoot = element.shadowRoot ||
150
+ // check for an undisclosed shadow
151
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
152
+
153
+ // no inert look up because we're already drilling down and checking for inertness
154
+ // on the way down, so all containers to this root node should have already been
155
+ // vetted as non-inert
156
+ var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
157
+ if (shadowRoot && validShadowRoot) {
158
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
159
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
160
+ // child candidates found because they're likely slotted elements (elements that are
161
+ // children of the web component element (which has the shadow), in the light dom, but
162
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
163
+ // _after_ we return from this recursive call
164
+ var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
165
+ if (options.flatten) {
166
+ candidates.push.apply(candidates, _nestedCandidates);
167
+ } else {
168
+ candidates.push({
169
+ scopeParent: element,
170
+ candidates: _nestedCandidates
171
+ });
172
+ }
173
+ } else {
174
+ // there's not shadow so just dig into the element's (light dom) children
175
+ // __without__ giving the element special scope treatment
176
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
177
+ }
178
+ }
179
+ }
180
+ return candidates;
181
+ };
182
+
183
+ /**
184
+ * @private
185
+ * Determines if the node has an explicitly specified `tabindex` attribute.
186
+ * @param {HTMLElement} node
187
+ * @returns {boolean} True if so; false if not.
188
+ */
189
+ var hasTabIndex = function hasTabIndex(node) {
190
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
191
+ };
192
+
193
+ /**
194
+ * Determine the tab index of a given node.
195
+ * @param {HTMLElement} node
196
+ * @returns {number} Tab order (negative, 0, or positive number).
197
+ * @throws {Error} If `node` is falsy.
198
+ */
199
+ var getTabIndex = function getTabIndex(node) {
200
+ if (!node) {
201
+ throw new Error('No node provided');
202
+ }
203
+ if (node.tabIndex < 0) {
204
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
205
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
206
+ // yet they are still part of the regular tab order; in FF, they get a default
207
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
208
+ // order, consider their tab index to be 0.
209
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
210
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
211
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
212
+ return 0;
213
+ }
214
+ }
215
+ return node.tabIndex;
216
+ };
217
+
218
+ /**
219
+ * Determine the tab index of a given node __for sort order purposes__.
220
+ * @param {HTMLElement} node
221
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
222
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
223
+ * inserted into the correct sort position.
224
+ * @returns {number} Tab order (negative, 0, or positive number).
225
+ */
226
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
227
+ var tabIndex = getTabIndex(node);
228
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
229
+ return 0;
230
+ }
231
+ return tabIndex;
232
+ };
233
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
234
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
235
+ };
236
+ var isInput = function isInput(node) {
237
+ return node.tagName === 'INPUT';
238
+ };
239
+ var isHiddenInput = function isHiddenInput(node) {
240
+ return isInput(node) && node.type === 'hidden';
241
+ };
242
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
243
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
244
+ return child.tagName === 'SUMMARY';
245
+ });
246
+ return r;
247
+ };
248
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
249
+ for (var i = 0; i < nodes.length; i++) {
250
+ if (nodes[i].checked && nodes[i].form === form) {
251
+ return nodes[i];
252
+ }
253
+ }
254
+ };
255
+ var isTabbableRadio = function isTabbableRadio(node) {
256
+ if (!node.name) {
257
+ return true;
258
+ }
259
+ var radioScope = node.form || getRootNode(node);
260
+ var queryRadios = function queryRadios(name) {
261
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
262
+ };
263
+ var radioSet;
264
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
265
+ radioSet = queryRadios(window.CSS.escape(node.name));
266
+ } else {
267
+ try {
268
+ radioSet = queryRadios(node.name);
269
+ } catch (err) {
270
+ // eslint-disable-next-line no-console
271
+ console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
272
+ return false;
273
+ }
274
+ }
275
+ var checked = getCheckedRadio(radioSet, node.form);
276
+ return !checked || checked === node;
277
+ };
278
+ var isRadio = function isRadio(node) {
279
+ return isInput(node) && node.type === 'radio';
280
+ };
281
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
282
+ return isRadio(node) && !isTabbableRadio(node);
283
+ };
284
+
285
+ // determines if a node is ultimately attached to the window's document
286
+ var isNodeAttached = function isNodeAttached(node) {
287
+ var _nodeRoot;
288
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
289
+ // (but NOT _the_ document; see second 'If' comment below for more).
290
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
291
+ // is attached, and the one we need to check if it's in the document or not (because the
292
+ // shadow, and all nodes it contains, is never considered in the document since shadows
293
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
294
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
295
+ // visibility, including all the nodes it contains). The host could be any normal node,
296
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
297
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
298
+ // tested).
299
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
300
+ // that is attached (or find none) because the node might be in nested shadows...
301
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
302
+ // document (per the docs) and while it's a Document-type object, that document does not
303
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
304
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
305
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
306
+ // node is actually detached.
307
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
308
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
309
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
310
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
311
+ var nodeRoot = node && getRootNode(node);
312
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
313
+
314
+ // in some cases, a detached node will return itself as the root instead of a document or
315
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
316
+ var attached = false;
317
+ if (nodeRoot && nodeRoot !== node) {
318
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
319
+ attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
320
+ while (!attached && nodeRootHost) {
321
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
322
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
323
+ // which means we need to get the host's host and check if that parent host is contained
324
+ // in (i.e. attached to) the document
325
+ nodeRoot = getRootNode(nodeRootHost);
326
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
327
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
328
+ }
329
+ }
330
+ return attached;
331
+ };
332
+ var isZeroArea = function isZeroArea(node) {
333
+ var _node$getBoundingClie = node.getBoundingClientRect(),
334
+ width = _node$getBoundingClie.width,
335
+ height = _node$getBoundingClie.height;
336
+ return width === 0 && height === 0;
337
+ };
338
+ var isHidden = function isHidden(node, _ref) {
339
+ var displayCheck = _ref.displayCheck,
340
+ getShadowRoot = _ref.getShadowRoot;
341
+ // NOTE: visibility will be `undefined` if node is detached from the document
342
+ // (see notes about this further down), which means we will consider it visible
343
+ // (this is legacy behavior from a very long way back)
344
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
345
+ // _visibility_ check, not a _display_ check
346
+ if (getComputedStyle(node).visibility === 'hidden') {
347
+ return true;
348
+ }
349
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
350
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
351
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
352
+ return true;
353
+ }
354
+ if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
355
+ if (typeof getShadowRoot === 'function') {
356
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
357
+ // 'non-zero-area' fallback
358
+ var originalNode = node;
359
+ while (node) {
360
+ var parentElement = node.parentElement;
361
+ var rootNode = getRootNode(node);
362
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
363
+ ) {
364
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
365
+ // fall back to a non-zero-area test
366
+ return isZeroArea(node);
367
+ } else if (node.assignedSlot) {
368
+ // iterate up slot
369
+ node = node.assignedSlot;
370
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
371
+ // cross shadow boundary
372
+ node = rootNode.host;
373
+ } else {
374
+ // iterate up normal dom
375
+ node = parentElement;
376
+ }
377
+ }
378
+ node = originalNode;
379
+ }
380
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
381
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
382
+ // it might be a falsy value, which means shadow DOM support is disabled
383
+
384
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
385
+ // now we can just test to see if it would normally be visible or not, provided it's
386
+ // attached to the main document.
387
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
388
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
389
+
390
+ if (isNodeAttached(node)) {
391
+ // this works wherever the node is: if there's at least one client rect, it's
392
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
393
+ // node itself is hidden in place of its contents; and there's no need to search
394
+ // up the hierarchy either
395
+ return !node.getClientRects().length;
396
+ }
397
+
398
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
399
+ // API will __always__ return zero rects (this can happen, for example, if React
400
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
401
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
402
+ //
403
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
404
+ // because styles are only computed for nodes that are in the document.
405
+ //
406
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
407
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
408
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
409
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
410
+ // considering __everything__ to be visible because of the innability to determine styles.
411
+ //
412
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
413
+ // nodes as visible with the 'none' fallback.__
414
+ if (displayCheck !== 'legacy-full') {
415
+ return true; // hidden
416
+ }
417
+ // else, fallback to 'none' mode and consider the node visible
418
+ } else if (displayCheck === 'non-zero-area') {
419
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
420
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
421
+ // client rect, we don't special-case for whether the node is attached or not. In
422
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
423
+ // times, and that includes attached or not.
424
+ return isZeroArea(node);
425
+ }
426
+
427
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
428
+ // it's visible
429
+ return false;
430
+ };
431
+
432
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
433
+ // unless they are in the _first_ <legend> element of the top-most disabled
434
+ // fieldset
435
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
436
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
437
+ var parentNode = node.parentElement;
438
+ // check if `node` is contained in a disabled <fieldset>
439
+ while (parentNode) {
440
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
441
+ // look for the first <legend> among the children of the disabled <fieldset>
442
+ for (var i = 0; i < parentNode.children.length; i++) {
443
+ var child = parentNode.children.item(i);
444
+ // when the first <legend> (in document order) is found
445
+ if (child.tagName === 'LEGEND') {
446
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
447
+ // return whether `node` is a descendant of its first <legend>
448
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
449
+ }
450
+ }
451
+ // the disabled <fieldset> containing `node` has no <legend>
452
+ return true;
453
+ }
454
+ parentNode = parentNode.parentElement;
455
+ }
456
+ }
457
+
458
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
459
+ // enabled/disabled state
460
+ return false;
461
+ };
462
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
463
+ if (node.disabled ||
464
+ // we must do an inert look up to filter out any elements inside an inert ancestor
465
+ // because we're limited in the type of selectors we can use in JSDom (see related
466
+ // note related to `candidateSelectors`)
467
+ isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
468
+ // For a details element with a summary, the summary element gets the focus
469
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
470
+ return false;
471
+ }
472
+ return true;
473
+ };
474
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
475
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
476
+ return false;
477
+ }
478
+ return true;
479
+ };
480
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
481
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
482
+ if (isNaN(tabIndex) || tabIndex >= 0) {
483
+ return true;
484
+ }
485
+ // If a custom element has an explicit negative tabindex,
486
+ // browsers will not allow tab targeting said element's children.
487
+ return false;
488
+ };
489
+
490
+ /**
491
+ * @param {Array.<Element|CandidateScope>} candidates
492
+ * @returns Element[]
493
+ */
494
+ var sortByOrder = function sortByOrder(candidates) {
495
+ var regularTabbables = [];
496
+ var orderedTabbables = [];
497
+ candidates.forEach(function (item, i) {
498
+ var isScope = !!item.scopeParent;
499
+ var element = isScope ? item.scopeParent : item;
500
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
501
+ var elements = isScope ? sortByOrder(item.candidates) : element;
502
+ if (candidateTabindex === 0) {
503
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
504
+ } else {
505
+ orderedTabbables.push({
506
+ documentOrder: i,
507
+ tabIndex: candidateTabindex,
508
+ item: item,
509
+ isScope: isScope,
510
+ content: elements
511
+ });
512
+ }
513
+ });
514
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
515
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
516
+ return acc;
517
+ }, []).concat(regularTabbables);
518
+ };
519
+ var tabbable = function tabbable(container, options) {
520
+ options = options || {};
521
+ var candidates;
522
+ if (options.getShadowRoot) {
523
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
524
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
525
+ flatten: false,
526
+ getShadowRoot: options.getShadowRoot,
527
+ shadowRootFilter: isValidShadowRootTabbable
528
+ });
529
+ } else {
530
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
531
+ }
532
+ return sortByOrder(candidates);
533
+ };
534
+ var focusable = function focusable(container, options) {
535
+ options = options || {};
536
+ var candidates;
537
+ if (options.getShadowRoot) {
538
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
539
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
540
+ flatten: true,
541
+ getShadowRoot: options.getShadowRoot
542
+ });
543
+ } else {
544
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
545
+ }
546
+ return candidates;
547
+ };
548
+ var isTabbable = function isTabbable(node, options) {
549
+ options = options || {};
550
+ if (!node) {
551
+ throw new Error('No node provided');
552
+ }
553
+ if (matches.call(node, candidateSelector) === false) {
554
+ return false;
555
+ }
556
+ return isNodeMatchingSelectorTabbable(options, node);
557
+ };
558
+ var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
559
+ var isFocusable = function isFocusable(node, options) {
560
+ options = options || {};
561
+ if (!node) {
562
+ throw new Error('No node provided');
563
+ }
564
+ if (matches.call(node, focusableCandidateSelector) === false) {
565
+ return false;
566
+ }
567
+ return isNodeMatchingSelectorFocusable(options, node);
568
+ };
569
+
570
+ /*!
571
+ * focus-trap 7.6.4
572
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
573
+ */
574
+
575
+ function _arrayLikeToArray(r, a) {
576
+ (null == a || a > r.length) && (a = r.length);
577
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
578
+ return n;
579
+ }
580
+ function _arrayWithoutHoles(r) {
581
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
582
+ }
583
+ function _defineProperty(e, r, t) {
584
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
585
+ value: t,
586
+ enumerable: true,
587
+ configurable: true,
588
+ writable: true
589
+ }) : e[r] = t, e;
590
+ }
591
+ function _iterableToArray(r) {
592
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
593
+ }
594
+ function _nonIterableSpread() {
595
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
596
+ }
597
+ function ownKeys(e, r) {
598
+ var t = Object.keys(e);
599
+ if (Object.getOwnPropertySymbols) {
600
+ var o = Object.getOwnPropertySymbols(e);
601
+ r && (o = o.filter(function (r) {
602
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
603
+ })), t.push.apply(t, o);
604
+ }
605
+ return t;
606
+ }
607
+ function _objectSpread2(e) {
608
+ for (var r = 1; r < arguments.length; r++) {
609
+ var t = null != arguments[r] ? arguments[r] : {};
610
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
611
+ _defineProperty(e, r, t[r]);
612
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
613
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
614
+ });
615
+ }
616
+ return e;
617
+ }
618
+ function _toConsumableArray(r) {
619
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
620
+ }
621
+ function _toPrimitive(t, r) {
622
+ if ("object" != typeof t || !t) return t;
623
+ var e = t[Symbol.toPrimitive];
624
+ if (undefined !== e) {
625
+ var i = e.call(t, r);
626
+ if ("object" != typeof i) return i;
627
+ throw new TypeError("@@toPrimitive must return a primitive value.");
628
+ }
629
+ return (String )(t);
630
+ }
631
+ function _toPropertyKey(t) {
632
+ var i = _toPrimitive(t, "string");
633
+ return "symbol" == typeof i ? i : i + "";
634
+ }
635
+ function _unsupportedIterableToArray(r, a) {
636
+ if (r) {
637
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
638
+ var t = {}.toString.call(r).slice(8, -1);
639
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : undefined;
640
+ }
641
+ }
642
+
643
+ var activeFocusTraps = {
644
+ activateTrap: function activateTrap(trapStack, trap) {
645
+ if (trapStack.length > 0) {
646
+ var activeTrap = trapStack[trapStack.length - 1];
647
+ if (activeTrap !== trap) {
648
+ activeTrap._setPausedState(true);
649
+ }
650
+ }
651
+ var trapIndex = trapStack.indexOf(trap);
652
+ if (trapIndex === -1) {
653
+ trapStack.push(trap);
654
+ } else {
655
+ // move this existing trap to the front of the queue
656
+ trapStack.splice(trapIndex, 1);
657
+ trapStack.push(trap);
658
+ }
659
+ },
660
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
661
+ var trapIndex = trapStack.indexOf(trap);
662
+ if (trapIndex !== -1) {
663
+ trapStack.splice(trapIndex, 1);
664
+ }
665
+ if (trapStack.length > 0 && !trapStack[trapStack.length - 1]._isManuallyPaused()) {
666
+ trapStack[trapStack.length - 1]._setPausedState(false);
667
+ }
668
+ }
669
+ };
670
+ var isSelectableInput = function isSelectableInput(node) {
671
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
672
+ };
673
+ var isEscapeEvent = function isEscapeEvent(e) {
674
+ return (e === null || e === undefined ? undefined : e.key) === 'Escape' || (e === null || e === undefined ? undefined : e.key) === 'Esc' || (e === null || e === undefined ? undefined : e.keyCode) === 27;
675
+ };
676
+ var isTabEvent = function isTabEvent(e) {
677
+ return (e === null || e === undefined ? undefined : e.key) === 'Tab' || (e === null || e === undefined ? undefined : e.keyCode) === 9;
678
+ };
679
+
680
+ // checks for TAB by default
681
+ var isKeyForward = function isKeyForward(e) {
682
+ return isTabEvent(e) && !e.shiftKey;
683
+ };
684
+
685
+ // checks for SHIFT+TAB by default
686
+ var isKeyBackward = function isKeyBackward(e) {
687
+ return isTabEvent(e) && e.shiftKey;
688
+ };
689
+ var delay = function delay(fn) {
690
+ return setTimeout(fn, 0);
691
+ };
692
+
693
+ /**
694
+ * Get an option's value when it could be a plain value, or a handler that provides
695
+ * the value.
696
+ * @param {*} value Option's value to check.
697
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
698
+ * @returns {*} The `value`, or the handler's returned value.
699
+ */
700
+ var valueOrHandler = function valueOrHandler(value) {
701
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
702
+ params[_key - 1] = arguments[_key];
703
+ }
704
+ return typeof value === 'function' ? value.apply(undefined, params) : value;
705
+ };
706
+ var getActualTarget = function getActualTarget(event) {
707
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
708
+ // shadow host. However, event.target.composedPath() will be an array of
709
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
710
+ // outer-most (the host HTML document). If we have access to composedPath(),
711
+ // then use its first element; otherwise, fall back to event.target (and
712
+ // this only works for an _open_ shadow DOM; otherwise,
713
+ // composedPath()[0] === event.target always).
714
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
715
+ };
716
+
717
+ // NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this
718
+ // current instance use the same stack if `userOptions.trapStack` isn't specified
719
+ var internalTrapStack = [];
720
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
721
+ // SSR: a live trap shouldn't be created in this type of environment so this
722
+ // should be safe code to execute if the `document` option isn't specified
723
+ var doc = (userOptions === null || userOptions === undefined ? undefined : userOptions.document) || document;
724
+ var trapStack = (userOptions === null || userOptions === undefined ? undefined : userOptions.trapStack) || internalTrapStack;
725
+ var config = _objectSpread2({
726
+ returnFocusOnDeactivate: true,
727
+ escapeDeactivates: true,
728
+ delayInitialFocus: true,
729
+ isKeyForward: isKeyForward,
730
+ isKeyBackward: isKeyBackward
731
+ }, userOptions);
732
+ var state = {
733
+ // containers given to createFocusTrap()
734
+ // @type {Array<HTMLElement>}
735
+ containers: [],
736
+ // list of objects identifying tabbable nodes in `containers` in the trap
737
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
738
+ // is active, but the trap should never get to a state where there isn't at least one group
739
+ // with at least one tabbable node in it (that would lead to an error condition that would
740
+ // result in an error being thrown)
741
+ // @type {Array<{
742
+ // container: HTMLElement,
743
+ // tabbableNodes: Array<HTMLElement>, // empty if none
744
+ // focusableNodes: Array<HTMLElement>, // empty if none
745
+ // posTabIndexesFound: boolean,
746
+ // firstTabbableNode: HTMLElement|undefined,
747
+ // lastTabbableNode: HTMLElement|undefined,
748
+ // firstDomTabbableNode: HTMLElement|undefined,
749
+ // lastDomTabbableNode: HTMLElement|undefined,
750
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
751
+ // }>}
752
+ containerGroups: [],
753
+ // same order/length as `containers` list
754
+
755
+ // references to objects in `containerGroups`, but only those that actually have
756
+ // tabbable nodes in them
757
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
758
+ // the same length
759
+ tabbableGroups: [],
760
+ nodeFocusedBeforeActivation: null,
761
+ mostRecentlyFocusedNode: null,
762
+ active: false,
763
+ paused: false,
764
+ manuallyPaused: 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 === undefined ? undefined : 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 === undefined ? undefined : 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
+ * @param {Object} options
820
+ * @param {boolean} [options.hasFallback] True if the option could be a selector string
821
+ * and the option allows for a fallback scenario in the case where the selector is
822
+ * valid but does not match a node (i.e. the queried node doesn't exist in the DOM).
823
+ * @param {Array} [options.params] Params to pass to the option if it's a function.
824
+ * @returns {undefined | null | false | HTMLElement | SVGElement} Returns
825
+ * `undefined` if the option is not specified; `null` if the option didn't resolve
826
+ * to a node but `options.hasFallback=true`, `false` if the option resolved to `false`
827
+ * (node explicitly not given); otherwise, the resolved DOM node.
828
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
829
+ * resolve to a node, unless the option is a selector string and `options.hasFallback=true`.
830
+ */
831
+ var getNodeForOption = function getNodeForOption(optionName) {
832
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
833
+ _ref2$hasFallback = _ref2.hasFallback,
834
+ hasFallback = _ref2$hasFallback === undefined ? false : _ref2$hasFallback,
835
+ _ref2$params = _ref2.params,
836
+ params = _ref2$params === undefined ? [] : _ref2$params;
837
+ var optionValue = config[optionName];
838
+ if (typeof optionValue === 'function') {
839
+ optionValue = optionValue.apply(undefined, _toConsumableArray(params));
840
+ }
841
+ if (optionValue === true) {
842
+ optionValue = undefined; // use default value
843
+ }
844
+ if (!optionValue) {
845
+ if (optionValue === undefined || optionValue === false) {
846
+ return optionValue;
847
+ }
848
+ // else, empty string (invalid), null (invalid), 0 (invalid)
849
+
850
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
851
+ }
852
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
853
+
854
+ if (typeof optionValue === 'string') {
855
+ try {
856
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
857
+ } catch (err) {
858
+ throw new Error("`".concat(optionName, "` appears to be an invalid selector; error=\"").concat(err.message, "\""));
859
+ }
860
+ if (!node) {
861
+ if (!hasFallback) {
862
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
863
+ }
864
+ // else, `node` MUST be `null` because that's what `Document.querySelector()` returns
865
+ // if the selector is valid but doesn't match anything
866
+ }
867
+ }
868
+ return node;
869
+ };
870
+ var getInitialFocusNode = function getInitialFocusNode() {
871
+ var node = getNodeForOption('initialFocus', {
872
+ hasFallback: true
873
+ });
874
+
875
+ // false explicitly indicates we want no initialFocus at all
876
+ if (node === false) {
877
+ return false;
878
+ }
879
+ if (node === undefined || node && !isFocusable(node, config.tabbableOptions)) {
880
+ // option not specified nor focusable: use fallback options
881
+ if (findContainerIndex(doc.activeElement) >= 0) {
882
+ node = doc.activeElement;
883
+ } else {
884
+ var firstTabbableGroup = state.tabbableGroups[0];
885
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
886
+
887
+ // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
888
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
889
+ }
890
+ } else if (node === null) {
891
+ // option is a VALID selector string that doesn't yield a node: use the `fallbackFocus`
892
+ // option instead of the default behavior when the option isn't specified at all
893
+ node = getNodeForOption('fallbackFocus');
894
+ }
895
+ if (!node) {
896
+ throw new Error('Your focus-trap needs to have at least one focusable element');
897
+ }
898
+ return node;
899
+ };
900
+ var updateTabbableNodes = function updateTabbableNodes() {
901
+ state.containerGroups = state.containers.map(function (container) {
902
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
903
+
904
+ // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
905
+ // are a superset of tabbable nodes since nodes with negative `tabindex` attributes
906
+ // are focusable but not tabbable
907
+ var focusableNodes = focusable(container, config.tabbableOptions);
908
+ var firstTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;
909
+ var lastTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : undefined;
910
+ var firstDomTabbableNode = focusableNodes.find(function (node) {
911
+ return isTabbable(node);
912
+ });
913
+ var lastDomTabbableNode = focusableNodes.slice().reverse().find(function (node) {
914
+ return isTabbable(node);
915
+ });
916
+ var posTabIndexesFound = !!tabbableNodes.find(function (node) {
917
+ return getTabIndex(node) > 0;
918
+ });
919
+ return {
920
+ container: container,
921
+ tabbableNodes: tabbableNodes,
922
+ focusableNodes: focusableNodes,
923
+ /** True if at least one node with positive `tabindex` was found in this container. */
924
+ posTabIndexesFound: posTabIndexesFound,
925
+ /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
926
+ firstTabbableNode: firstTabbableNode,
927
+ /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
928
+ lastTabbableNode: lastTabbableNode,
929
+ // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
930
+ // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
931
+ // because that API doesn't work with Shadow DOM as well as it should (@see
932
+ // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
933
+ // to address an edge case related to positive tabindex support, this seems like a much easier,
934
+ // "close enough most of the time" alternative for positive tabindexes which should generally
935
+ // be avoided anyway...
936
+ /** First tabbable node in container, __DOM__ order; `undefined` if none. */
937
+ firstDomTabbableNode: firstDomTabbableNode,
938
+ /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
939
+ lastDomTabbableNode: lastDomTabbableNode,
940
+ /**
941
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
942
+ * in this container, if any.
943
+ * @param {HTMLElement} node
944
+ * @param {boolean} [forward] True if going in forward tab order; false if going
945
+ * in reverse.
946
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
947
+ */
948
+ nextTabbableNode: function nextTabbableNode(node) {
949
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
950
+ var nodeIdx = tabbableNodes.indexOf(node);
951
+ if (nodeIdx < 0) {
952
+ // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):
953
+ // since `node` should at least have been focusable, we assume that's the case and mimic
954
+ // what browsers do, which is set focus to the next node in __document position order__,
955
+ // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE
956
+ // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to
957
+ // basic DOM order
958
+ if (forward) {
959
+ return focusableNodes.slice(focusableNodes.indexOf(node) + 1).find(function (el) {
960
+ return isTabbable(el);
961
+ });
962
+ }
963
+ return focusableNodes.slice(0, focusableNodes.indexOf(node)).reverse().find(function (el) {
964
+ return isTabbable(el);
965
+ });
966
+ }
967
+ return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
968
+ }
969
+ };
970
+ });
971
+ state.tabbableGroups = state.containerGroups.filter(function (group) {
972
+ return group.tabbableNodes.length > 0;
973
+ });
974
+
975
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
976
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
977
+ ) {
978
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
979
+ }
980
+
981
+ // NOTE: Positive tabindexes are only properly supported in single-container traps because
982
+ // doing it across multiple containers where tabindexes could be all over the place
983
+ // would require Tabbable to support multiple containers, would require additional
984
+ // specialized Shadow DOM support, and would require Tabbable's multi-container support
985
+ // to look at those containers in document position order rather than user-provided
986
+ // order (as they are treated in Focus-trap, for legacy reasons). See discussion on
987
+ // https://github.com/focus-trap/focus-trap/issues/375 for more details.
988
+ if (state.containerGroups.find(function (g) {
989
+ return g.posTabIndexesFound;
990
+ }) && state.containerGroups.length > 1) {
991
+ 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.");
992
+ }
993
+ };
994
+
995
+ /**
996
+ * Gets the current activeElement. If it's a web-component and has open shadow-root
997
+ * it will recursively search inside shadow roots for the "true" activeElement.
998
+ *
999
+ * @param {Document | ShadowRoot} el
1000
+ *
1001
+ * @returns {HTMLElement} The element that currently has the focus
1002
+ **/
1003
+ var _getActiveElement = function getActiveElement(el) {
1004
+ var activeElement = el.activeElement;
1005
+ if (!activeElement) {
1006
+ return;
1007
+ }
1008
+ if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
1009
+ return _getActiveElement(activeElement.shadowRoot);
1010
+ }
1011
+ return activeElement;
1012
+ };
1013
+ var _tryFocus = function tryFocus(node) {
1014
+ if (node === false) {
1015
+ return;
1016
+ }
1017
+ if (node === _getActiveElement(document)) {
1018
+ return;
1019
+ }
1020
+ if (!node || !node.focus) {
1021
+ _tryFocus(getInitialFocusNode());
1022
+ return;
1023
+ }
1024
+ node.focus({
1025
+ preventScroll: !!config.preventScroll
1026
+ });
1027
+ // NOTE: focus() API does not trigger focusIn event so set MRU node manually
1028
+ state.mostRecentlyFocusedNode = node;
1029
+ if (isSelectableInput(node)) {
1030
+ node.select();
1031
+ }
1032
+ };
1033
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
1034
+ var node = getNodeForOption('setReturnFocus', {
1035
+ params: [previousActiveElement]
1036
+ });
1037
+ return node ? node : node === false ? false : previousActiveElement;
1038
+ };
1039
+
1040
+ /**
1041
+ * Finds the next node (in either direction) where focus should move according to a
1042
+ * keyboard focus-in event.
1043
+ * @param {Object} params
1044
+ * @param {Node} [params.target] Known target __from which__ to navigate, if any.
1045
+ * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event
1046
+ * will be used to determine the `target`). Ignored if `target` is specified.
1047
+ * @param {boolean} [params.isBackward] True if focus should move backward.
1048
+ * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be
1049
+ * determined given the current state of the trap.
1050
+ */
1051
+ var findNextNavNode = function findNextNavNode(_ref3) {
1052
+ var target = _ref3.target,
1053
+ event = _ref3.event,
1054
+ _ref3$isBackward = _ref3.isBackward,
1055
+ isBackward = _ref3$isBackward === undefined ? false : _ref3$isBackward;
1056
+ target = target || getActualTarget(event);
1057
+ updateTabbableNodes();
1058
+ var destinationNode = null;
1059
+ if (state.tabbableGroups.length > 0) {
1060
+ // make sure the target is actually contained in a group
1061
+ // NOTE: the target may also be the container itself if it's focusable
1062
+ // with tabIndex='-1' and was given initial focus
1063
+ var containerIndex = findContainerIndex(target, event);
1064
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
1065
+ if (containerIndex < 0) {
1066
+ // target not found in any group: quite possible focus has escaped the trap,
1067
+ // so bring it back into...
1068
+ if (isBackward) {
1069
+ // ...the last node in the last group
1070
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
1071
+ } else {
1072
+ // ...the first node in the first group
1073
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
1074
+ }
1075
+ } else if (isBackward) {
1076
+ // REVERSE
1077
+
1078
+ // is the target the first tabbable node in a group?
1079
+ var startOfGroupIndex = state.tabbableGroups.findIndex(function (_ref4) {
1080
+ var firstTabbableNode = _ref4.firstTabbableNode;
1081
+ return target === firstTabbableNode;
1082
+ });
1083
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
1084
+ // an exception case where the target is either the container itself, or
1085
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1086
+ // and user clicked on it or node was programmatically given focus)
1087
+ // and is not followed by any other tabbable node, in which
1088
+ // case, we should handle shift+tab as if focus were on the container's
1089
+ // first tabbable node, and go to the last tabbable node of the LAST group
1090
+ startOfGroupIndex = containerIndex;
1091
+ }
1092
+ if (startOfGroupIndex >= 0) {
1093
+ // YES: then shift+tab should go to the last tabbable node in the
1094
+ // previous group (and wrap around to the last tabbable node of
1095
+ // the LAST group if it's the first tabbable node of the FIRST group)
1096
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
1097
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
1098
+ destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
1099
+ } else if (!isTabEvent(event)) {
1100
+ // user must have customized the nav keys so we have to move focus manually _within_
1101
+ // the active group: do this based on the order determined by tabbable()
1102
+ destinationNode = containerGroup.nextTabbableNode(target, false);
1103
+ }
1104
+ } else {
1105
+ // FORWARD
1106
+
1107
+ // is the target the last tabbable node in a group?
1108
+ var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref5) {
1109
+ var lastTabbableNode = _ref5.lastTabbableNode;
1110
+ return target === lastTabbableNode;
1111
+ });
1112
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
1113
+ // an exception case where the target is the container itself, or
1114
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1115
+ // and user clicked on it or node was programmatically given focus)
1116
+ // and is not followed by any other tabbable node, in which
1117
+ // case, we should handle tab as if focus were on the container's
1118
+ // last tabbable node, and go to the first tabbable node of the FIRST group
1119
+ lastOfGroupIndex = containerIndex;
1120
+ }
1121
+ if (lastOfGroupIndex >= 0) {
1122
+ // YES: then tab should go to the first tabbable node in the next
1123
+ // group (and wrap around to the first tabbable node of the FIRST
1124
+ // group if it's the last tabbable node of the LAST group)
1125
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
1126
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
1127
+ destinationNode = getTabIndex(target) >= 0 ? _destinationGroup.firstTabbableNode : _destinationGroup.firstDomTabbableNode;
1128
+ } else if (!isTabEvent(event)) {
1129
+ // user must have customized the nav keys so we have to move focus manually _within_
1130
+ // the active group: do this based on the order determined by tabbable()
1131
+ destinationNode = containerGroup.nextTabbableNode(target);
1132
+ }
1133
+ }
1134
+ } else {
1135
+ // no groups available
1136
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
1137
+ destinationNode = getNodeForOption('fallbackFocus');
1138
+ }
1139
+ return destinationNode;
1140
+ };
1141
+
1142
+ // This needs to be done on mousedown and touchstart instead of click
1143
+ // so that it precedes the focus event.
1144
+ var checkPointerDown = function checkPointerDown(e) {
1145
+ var target = getActualTarget(e);
1146
+ if (findContainerIndex(target, e) >= 0) {
1147
+ // allow the click since it ocurred inside the trap
1148
+ return;
1149
+ }
1150
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1151
+ // immediately deactivate the trap
1152
+ trap.deactivate({
1153
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
1154
+ // which will result in the outside click setting focus to the node
1155
+ // that was clicked (and if not focusable, to "nothing"); by setting
1156
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
1157
+ // on activation (or the configured `setReturnFocus` node), whether the
1158
+ // outside click was on a focusable node or not
1159
+ returnFocus: config.returnFocusOnDeactivate
1160
+ });
1161
+ return;
1162
+ }
1163
+
1164
+ // This is needed for mobile devices.
1165
+ // (If we'll only let `click` events through,
1166
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
1167
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1168
+ // allow the click outside the trap to take place
1169
+ return;
1170
+ }
1171
+
1172
+ // otherwise, prevent the click
1173
+ e.preventDefault();
1174
+ };
1175
+
1176
+ // In case focus escapes the trap for some strange reason, pull it back in.
1177
+ // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected
1178
+ // scrolling if the node that got focused was out of view; there's nothing we can do to
1179
+ // prevent that from happening by the time we discover that focus escaped
1180
+ var checkFocusIn = function checkFocusIn(event) {
1181
+ var target = getActualTarget(event);
1182
+ var targetContained = findContainerIndex(target, event) >= 0;
1183
+
1184
+ // In Firefox when you Tab out of an iframe the Document is briefly focused.
1185
+ if (targetContained || target instanceof Document) {
1186
+ if (targetContained) {
1187
+ state.mostRecentlyFocusedNode = target;
1188
+ }
1189
+ } else {
1190
+ // escaped! pull it back in to where it just left
1191
+ event.stopImmediatePropagation();
1192
+
1193
+ // focus will escape if the MRU node had a positive tab index and user tried to nav forward;
1194
+ // it will also escape if the MRU node had a 0 tab index and user tried to nav backward
1195
+ // toward a node with a positive tab index
1196
+ var nextNode; // next node to focus, if we find one
1197
+ var navAcrossContainers = true;
1198
+ if (state.mostRecentlyFocusedNode) {
1199
+ if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
1200
+ // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...
1201
+ var mruContainerIdx = findContainerIndex(state.mostRecentlyFocusedNode);
1202
+ // there MAY not be any tabbable nodes in the container if there are at least 2 containers
1203
+ // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container
1204
+ // with at least one tabbable node in order to function, so this could be the other container
1205
+ // with nothing tabbable in it)
1206
+ var tabbableNodes = state.containerGroups[mruContainerIdx].tabbableNodes;
1207
+ if (tabbableNodes.length > 0) {
1208
+ // MRU tab index MAY not be found if the MRU node is focusable but not tabbable
1209
+ var mruTabIdx = tabbableNodes.findIndex(function (node) {
1210
+ return node === state.mostRecentlyFocusedNode;
1211
+ });
1212
+ if (mruTabIdx >= 0) {
1213
+ if (config.isKeyForward(state.recentNavEvent)) {
1214
+ if (mruTabIdx + 1 < tabbableNodes.length) {
1215
+ nextNode = tabbableNodes[mruTabIdx + 1];
1216
+ navAcrossContainers = false;
1217
+ }
1218
+ // else, don't wrap within the container as focus should move to next/previous
1219
+ // container
1220
+ } else {
1221
+ if (mruTabIdx - 1 >= 0) {
1222
+ nextNode = tabbableNodes[mruTabIdx - 1];
1223
+ navAcrossContainers = false;
1224
+ }
1225
+ // else, don't wrap within the container as focus should move to next/previous
1226
+ // container
1227
+ }
1228
+ // else, don't find in container order without considering direction too
1229
+ }
1230
+ }
1231
+ // else, no tabbable nodes in that container (which means we must have at least one other
1232
+ // container with at least one tabbable node in it, otherwise focus-trap would've thrown
1233
+ // an error the last time updateTabbableNodes() was run): find next node among all known
1234
+ // containers
1235
+ } else {
1236
+ // check to see if there's at least one tabbable node with a positive tab index inside
1237
+ // the trap because focus seems to escape when navigating backward from a tabbable node
1238
+ // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with
1239
+ // the greatest positive tab index like it should)
1240
+ if (!state.containerGroups.some(function (g) {
1241
+ return g.tabbableNodes.some(function (n) {
1242
+ return getTabIndex(n) > 0;
1243
+ });
1244
+ })) {
1245
+ // no containers with tabbable nodes with positive tab indexes which means the focus
1246
+ // escaped for some other reason and we should just execute the fallback to the
1247
+ // MRU node or initial focus node, if any
1248
+ navAcrossContainers = false;
1249
+ }
1250
+ }
1251
+ } else {
1252
+ // no MRU node means we're likely in some initial condition when the trap has just
1253
+ // been activated and initial focus hasn't been given yet, in which case we should
1254
+ // fall through to trying to focus the initial focus node, which is what should
1255
+ // happen below at this point in the logic
1256
+ navAcrossContainers = false;
1257
+ }
1258
+ if (navAcrossContainers) {
1259
+ nextNode = findNextNavNode({
1260
+ // move FROM the MRU node, not event-related node (which will be the node that is
1261
+ // outside the trap causing the focus escape we're trying to fix)
1262
+ target: state.mostRecentlyFocusedNode,
1263
+ isBackward: config.isKeyBackward(state.recentNavEvent)
1264
+ });
1265
+ }
1266
+ if (nextNode) {
1267
+ _tryFocus(nextNode);
1268
+ } else {
1269
+ _tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
1270
+ }
1271
+ }
1272
+ state.recentNavEvent = undefined; // clear
1273
+ };
1274
+
1275
+ // Hijack key nav events on the first and last focusable nodes of the trap,
1276
+ // in order to prevent focus from escaping. If it escapes for even a
1277
+ // moment it can end up scrolling the page and causing confusion so we
1278
+ // kind of need to capture the action at the keydown phase.
1279
+ var checkKeyNav = function checkKeyNav(event) {
1280
+ var isBackward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1281
+ state.recentNavEvent = event;
1282
+ var destinationNode = findNextNavNode({
1283
+ event: event,
1284
+ isBackward: isBackward
1285
+ });
1286
+ if (destinationNode) {
1287
+ if (isTabEvent(event)) {
1288
+ // since tab natively moves focus, we wouldn't have a destination node unless we
1289
+ // were on the edge of a container and had to move to the next/previous edge, in
1290
+ // which case we want to prevent default to keep the browser from moving focus
1291
+ // to where it normally would
1292
+ event.preventDefault();
1293
+ }
1294
+ _tryFocus(destinationNode);
1295
+ }
1296
+ // else, let the browser take care of [shift+]tab and move the focus
1297
+ };
1298
+ var checkTabKey = function checkTabKey(event) {
1299
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
1300
+ checkKeyNav(event, config.isKeyBackward(event));
1301
+ }
1302
+ };
1303
+
1304
+ // we use a different event phase for the Escape key to allow canceling the event and checking for this in escapeDeactivates
1305
+ var checkEscapeKey = function checkEscapeKey(event) {
1306
+ if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
1307
+ event.preventDefault();
1308
+ trap.deactivate();
1309
+ }
1310
+ };
1311
+ var checkClick = function checkClick(e) {
1312
+ var target = getActualTarget(e);
1313
+ if (findContainerIndex(target, e) >= 0) {
1314
+ return;
1315
+ }
1316
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1317
+ return;
1318
+ }
1319
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1320
+ return;
1321
+ }
1322
+ e.preventDefault();
1323
+ e.stopImmediatePropagation();
1324
+ };
1325
+
1326
+ //
1327
+ // EVENT LISTENERS
1328
+ //
1329
+
1330
+ var addListeners = function addListeners() {
1331
+ if (!state.active) {
1332
+ return;
1333
+ }
1334
+
1335
+ // There can be only one listening focus trap at a time
1336
+ activeFocusTraps.activateTrap(trapStack, trap);
1337
+
1338
+ // Delay ensures that the focused element doesn't capture the event
1339
+ // that caused the focus trap activation.
1340
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
1341
+ _tryFocus(getInitialFocusNode());
1342
+ }) : _tryFocus(getInitialFocusNode());
1343
+ doc.addEventListener('focusin', checkFocusIn, true);
1344
+ doc.addEventListener('mousedown', checkPointerDown, {
1345
+ capture: true,
1346
+ passive: false
1347
+ });
1348
+ doc.addEventListener('touchstart', checkPointerDown, {
1349
+ capture: true,
1350
+ passive: false
1351
+ });
1352
+ doc.addEventListener('click', checkClick, {
1353
+ capture: true,
1354
+ passive: false
1355
+ });
1356
+ doc.addEventListener('keydown', checkTabKey, {
1357
+ capture: true,
1358
+ passive: false
1359
+ });
1360
+ doc.addEventListener('keydown', checkEscapeKey);
1361
+ return trap;
1362
+ };
1363
+ var removeListeners = function removeListeners() {
1364
+ if (!state.active) {
1365
+ return;
1366
+ }
1367
+ doc.removeEventListener('focusin', checkFocusIn, true);
1368
+ doc.removeEventListener('mousedown', checkPointerDown, true);
1369
+ doc.removeEventListener('touchstart', checkPointerDown, true);
1370
+ doc.removeEventListener('click', checkClick, true);
1371
+ doc.removeEventListener('keydown', checkTabKey, true);
1372
+ doc.removeEventListener('keydown', checkEscapeKey);
1373
+ return trap;
1374
+ };
1375
+
1376
+ //
1377
+ // MUTATION OBSERVER
1378
+ //
1379
+
1380
+ var checkDomRemoval = function checkDomRemoval(mutations) {
1381
+ var isFocusedNodeRemoved = mutations.some(function (mutation) {
1382
+ var removedNodes = Array.from(mutation.removedNodes);
1383
+ return removedNodes.some(function (node) {
1384
+ return node === state.mostRecentlyFocusedNode;
1385
+ });
1386
+ });
1387
+
1388
+ // If the currently focused is removed then browsers will move focus to the
1389
+ // <body> element. If this happens, try to move focus back into the trap.
1390
+ if (isFocusedNodeRemoved) {
1391
+ _tryFocus(getInitialFocusNode());
1392
+ }
1393
+ };
1394
+
1395
+ // Use MutationObserver - if supported - to detect if focused node is removed
1396
+ // from the DOM.
1397
+ var mutationObserver = typeof window !== 'undefined' && 'MutationObserver' in window ? new MutationObserver(checkDomRemoval) : undefined;
1398
+ var updateObservedNodes = function updateObservedNodes() {
1399
+ if (!mutationObserver) {
1400
+ return;
1401
+ }
1402
+ mutationObserver.disconnect();
1403
+ if (state.active && !state.paused) {
1404
+ state.containers.map(function (container) {
1405
+ mutationObserver.observe(container, {
1406
+ subtree: true,
1407
+ childList: true
1408
+ });
1409
+ });
1410
+ }
1411
+ };
1412
+
1413
+ //
1414
+ // TRAP DEFINITION
1415
+ //
1416
+
1417
+ trap = {
1418
+ get active() {
1419
+ return state.active;
1420
+ },
1421
+ get paused() {
1422
+ return state.paused;
1423
+ },
1424
+ activate: function activate(activateOptions) {
1425
+ if (state.active) {
1426
+ return this;
1427
+ }
1428
+ var onActivate = getOption(activateOptions, 'onActivate');
1429
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
1430
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1431
+ if (!checkCanFocusTrap) {
1432
+ updateTabbableNodes();
1433
+ }
1434
+ state.active = true;
1435
+ state.paused = false;
1436
+ state.nodeFocusedBeforeActivation = doc.activeElement;
1437
+ onActivate === null || onActivate === undefined || onActivate();
1438
+ var finishActivation = function finishActivation() {
1439
+ if (checkCanFocusTrap) {
1440
+ updateTabbableNodes();
1441
+ }
1442
+ addListeners();
1443
+ updateObservedNodes();
1444
+ onPostActivate === null || onPostActivate === undefined || onPostActivate();
1445
+ };
1446
+ if (checkCanFocusTrap) {
1447
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1448
+ return this;
1449
+ }
1450
+ finishActivation();
1451
+ return this;
1452
+ },
1453
+ deactivate: function deactivate(deactivateOptions) {
1454
+ if (!state.active) {
1455
+ return this;
1456
+ }
1457
+ var options = _objectSpread2({
1458
+ onDeactivate: config.onDeactivate,
1459
+ onPostDeactivate: config.onPostDeactivate,
1460
+ checkCanReturnFocus: config.checkCanReturnFocus
1461
+ }, deactivateOptions);
1462
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1463
+ state.delayInitialFocusTimer = undefined;
1464
+ removeListeners();
1465
+ state.active = false;
1466
+ state.paused = false;
1467
+ updateObservedNodes();
1468
+ activeFocusTraps.deactivateTrap(trapStack, trap);
1469
+ var onDeactivate = getOption(options, 'onDeactivate');
1470
+ var onPostDeactivate = getOption(options, 'onPostDeactivate');
1471
+ var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1472
+ var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1473
+ onDeactivate === null || onDeactivate === undefined || onDeactivate();
1474
+ var finishDeactivation = function finishDeactivation() {
1475
+ delay(function () {
1476
+ if (returnFocus) {
1477
+ _tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1478
+ }
1479
+ onPostDeactivate === null || onPostDeactivate === undefined || onPostDeactivate();
1480
+ });
1481
+ };
1482
+ if (returnFocus && checkCanReturnFocus) {
1483
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1484
+ return this;
1485
+ }
1486
+ finishDeactivation();
1487
+ return this;
1488
+ },
1489
+ pause: function pause(pauseOptions) {
1490
+ if (!state.active) {
1491
+ return this;
1492
+ }
1493
+ state.manuallyPaused = true;
1494
+ return this._setPausedState(true, pauseOptions);
1495
+ },
1496
+ unpause: function unpause(unpauseOptions) {
1497
+ if (!state.active) {
1498
+ return this;
1499
+ }
1500
+ state.manuallyPaused = false;
1501
+ if (trapStack[trapStack.length - 1] !== this) {
1502
+ return this;
1503
+ }
1504
+ return this._setPausedState(false, unpauseOptions);
1505
+ },
1506
+ updateContainerElements: function updateContainerElements(containerElements) {
1507
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1508
+ state.containers = elementsAsArray.map(function (element) {
1509
+ return typeof element === 'string' ? doc.querySelector(element) : element;
1510
+ });
1511
+ if (state.active) {
1512
+ updateTabbableNodes();
1513
+ }
1514
+ updateObservedNodes();
1515
+ return this;
1516
+ }
1517
+ };
1518
+ Object.defineProperties(trap, {
1519
+ _isManuallyPaused: {
1520
+ value: function value() {
1521
+ return state.manuallyPaused;
1522
+ }
1523
+ },
1524
+ _setPausedState: {
1525
+ value: function value(paused, options) {
1526
+ if (state.paused === paused) {
1527
+ return this;
1528
+ }
1529
+ state.paused = paused;
1530
+ if (paused) {
1531
+ var onPause = getOption(options, 'onPause');
1532
+ var onPostPause = getOption(options, 'onPostPause');
1533
+ onPause === null || onPause === undefined || onPause();
1534
+ removeListeners();
1535
+ updateObservedNodes();
1536
+ onPostPause === null || onPostPause === undefined || onPostPause();
1537
+ } else {
1538
+ var onUnpause = getOption(options, 'onUnpause');
1539
+ var onPostUnpause = getOption(options, 'onPostUnpause');
1540
+ onUnpause === null || onUnpause === undefined || onUnpause();
1541
+ updateTabbableNodes();
1542
+ addListeners();
1543
+ updateObservedNodes();
1544
+ onPostUnpause === null || onPostUnpause === undefined || onPostUnpause();
1545
+ }
1546
+ return this;
1547
+ }
1548
+ }
1549
+ });
1550
+
1551
+ // initialize container elements
1552
+ trap.updateContainerElements(elements);
1553
+ return trap;
1554
+ };
1555
+
1556
+ function clamp$1(value, bound1, bound2) {
1557
+ if (bound2 == null) {
1558
+ return Math.min(value, bound1);
1559
+ }
1560
+ return Math.min(Math.max(value, bound1), bound2);
1561
+ }
1562
+
1563
+ function round$1(value, precision = 0) {
1564
+ if (!Number.isInteger(precision)) {
1565
+ throw new Error('Precision must be an integer.');
1566
+ }
1567
+ const multiplier = Math.pow(10, precision);
1568
+ return Math.round(value * multiplier) / multiplier;
1569
+ }
1570
+
1571
+ function isPrimitive(value) {
1572
+ return value == null || (typeof value !== 'object' && typeof value !== 'function');
1573
+ }
1574
+
1575
+ function isTypedArray(x) {
1576
+ return ArrayBuffer.isView(x) && !(x instanceof DataView);
1577
+ }
1578
+
1579
+ function getSymbols(object) {
1580
+ return Object.getOwnPropertySymbols(object).filter(symbol => Object.prototype.propertyIsEnumerable.call(object, symbol));
1581
+ }
1582
+
1583
+ function getTag(value) {
1584
+ if (value == null) {
1585
+ return value === undefined ? '[object Undefined]' : '[object Null]';
1586
+ }
1587
+ return Object.prototype.toString.call(value);
1588
+ }
1589
+
1590
+ const regexpTag = '[object RegExp]';
1591
+ const stringTag = '[object String]';
1592
+ const numberTag = '[object Number]';
1593
+ const booleanTag = '[object Boolean]';
1594
+ const argumentsTag = '[object Arguments]';
1595
+ const symbolTag = '[object Symbol]';
1596
+ const dateTag = '[object Date]';
1597
+ const mapTag = '[object Map]';
1598
+ const setTag = '[object Set]';
1599
+ const arrayTag = '[object Array]';
1600
+ const arrayBufferTag = '[object ArrayBuffer]';
1601
+ const objectTag = '[object Object]';
1602
+ const dataViewTag = '[object DataView]';
1603
+ const uint8ArrayTag = '[object Uint8Array]';
1604
+ const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
1605
+ const uint16ArrayTag = '[object Uint16Array]';
1606
+ const uint32ArrayTag = '[object Uint32Array]';
1607
+ const int8ArrayTag = '[object Int8Array]';
1608
+ const int16ArrayTag = '[object Int16Array]';
1609
+ const int32ArrayTag = '[object Int32Array]';
1610
+ const float32ArrayTag = '[object Float32Array]';
1611
+ const float64ArrayTag = '[object Float64Array]';
1612
+
1613
+ function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = new Map(), cloneValue = undefined) {
1614
+ const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
1615
+ if (cloned != null) {
1616
+ return cloned;
1617
+ }
1618
+ if (isPrimitive(valueToClone)) {
1619
+ return valueToClone;
1620
+ }
1621
+ if (stack.has(valueToClone)) {
1622
+ return stack.get(valueToClone);
1623
+ }
1624
+ if (Array.isArray(valueToClone)) {
1625
+ const result = new Array(valueToClone.length);
1626
+ stack.set(valueToClone, result);
1627
+ for (let i = 0; i < valueToClone.length; i++) {
1628
+ result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
1629
+ }
1630
+ if (Object.hasOwn(valueToClone, 'index')) {
1631
+ result.index = valueToClone.index;
1632
+ }
1633
+ if (Object.hasOwn(valueToClone, 'input')) {
1634
+ result.input = valueToClone.input;
1635
+ }
1636
+ return result;
1637
+ }
1638
+ if (valueToClone instanceof Date) {
1639
+ return new Date(valueToClone.getTime());
1640
+ }
1641
+ if (valueToClone instanceof RegExp) {
1642
+ const result = new RegExp(valueToClone.source, valueToClone.flags);
1643
+ result.lastIndex = valueToClone.lastIndex;
1644
+ return result;
1645
+ }
1646
+ if (valueToClone instanceof Map) {
1647
+ const result = new Map();
1648
+ stack.set(valueToClone, result);
1649
+ for (const [key, value] of valueToClone) {
1650
+ result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
1651
+ }
1652
+ return result;
1653
+ }
1654
+ if (valueToClone instanceof Set) {
1655
+ const result = new Set();
1656
+ stack.set(valueToClone, result);
1657
+ for (const value of valueToClone) {
1658
+ result.add(cloneDeepWithImpl(value, undefined, objectToClone, stack, cloneValue));
1659
+ }
1660
+ return result;
1661
+ }
1662
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer(valueToClone)) {
1663
+ return valueToClone.subarray();
1664
+ }
1665
+ if (isTypedArray(valueToClone)) {
1666
+ const result = new (Object.getPrototypeOf(valueToClone).constructor)(valueToClone.length);
1667
+ stack.set(valueToClone, result);
1668
+ for (let i = 0; i < valueToClone.length; i++) {
1669
+ result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
1670
+ }
1671
+ return result;
1672
+ }
1673
+ if (valueToClone instanceof ArrayBuffer ||
1674
+ (typeof SharedArrayBuffer !== 'undefined' && valueToClone instanceof SharedArrayBuffer)) {
1675
+ return valueToClone.slice(0);
1676
+ }
1677
+ if (valueToClone instanceof DataView) {
1678
+ const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
1679
+ stack.set(valueToClone, result);
1680
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
1681
+ return result;
1682
+ }
1683
+ if (typeof File !== 'undefined' && valueToClone instanceof File) {
1684
+ const result = new File([valueToClone], valueToClone.name, {
1685
+ type: valueToClone.type,
1686
+ });
1687
+ stack.set(valueToClone, result);
1688
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
1689
+ return result;
1690
+ }
1691
+ if (valueToClone instanceof Blob) {
1692
+ const result = new Blob([valueToClone], { type: valueToClone.type });
1693
+ stack.set(valueToClone, result);
1694
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
1695
+ return result;
1696
+ }
1697
+ if (valueToClone instanceof Error) {
1698
+ const result = new valueToClone.constructor();
1699
+ stack.set(valueToClone, result);
1700
+ result.message = valueToClone.message;
1701
+ result.name = valueToClone.name;
1702
+ result.stack = valueToClone.stack;
1703
+ result.cause = valueToClone.cause;
1704
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
1705
+ return result;
1706
+ }
1707
+ if (typeof valueToClone === 'object' && isCloneableObject(valueToClone)) {
1708
+ const result = Object.create(Object.getPrototypeOf(valueToClone));
1709
+ stack.set(valueToClone, result);
1710
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
1711
+ return result;
1712
+ }
1713
+ return valueToClone;
1714
+ }
1715
+ function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
1716
+ const keys = [...Object.keys(source), ...getSymbols(source)];
1717
+ for (let i = 0; i < keys.length; i++) {
1718
+ const key = keys[i];
1719
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
1720
+ if (descriptor == null || descriptor.writable) {
1721
+ target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
1722
+ }
1723
+ }
1724
+ }
1725
+ function isCloneableObject(object) {
1726
+ switch (getTag(object)) {
1727
+ case argumentsTag:
1728
+ case arrayTag:
1729
+ case arrayBufferTag:
1730
+ case dataViewTag:
1731
+ case booleanTag:
1732
+ case dateTag:
1733
+ case float32ArrayTag:
1734
+ case float64ArrayTag:
1735
+ case int8ArrayTag:
1736
+ case int16ArrayTag:
1737
+ case int32ArrayTag:
1738
+ case mapTag:
1739
+ case numberTag:
1740
+ case objectTag:
1741
+ case regexpTag:
1742
+ case setTag:
1743
+ case stringTag:
1744
+ case symbolTag:
1745
+ case uint8ArrayTag:
1746
+ case uint8ClampedArrayTag:
1747
+ case uint16ArrayTag:
1748
+ case uint32ArrayTag: {
1749
+ return true;
1750
+ }
1751
+ default: {
1752
+ return false;
1753
+ }
1754
+ }
1755
+ }
1756
+
1757
+ function cloneDeep(obj) {
1758
+ return cloneDeepWithImpl(obj, undefined, obj, new Map(), undefined);
1759
+ }
1760
+
1761
+ function isPlainObject(value) {
1762
+ if (!value || typeof value !== 'object') {
1763
+ return false;
1764
+ }
1765
+ const proto = Object.getPrototypeOf(value);
1766
+ const hasObjectPrototype = proto === null ||
1767
+ proto === Object.prototype ||
1768
+ Object.getPrototypeOf(proto) === null;
1769
+ if (!hasObjectPrototype) {
1770
+ return false;
1771
+ }
1772
+ return Object.prototype.toString.call(value) === '[object Object]';
1773
+ }
1774
+
1775
+ function flattenObject(object, { delimiter = '.' } = {}) {
1776
+ return flattenObjectImpl(object, '', delimiter);
1777
+ }
1778
+ function flattenObjectImpl(object, prefix = '', delimiter = '.') {
1779
+ const result = {};
1780
+ const keys = Object.keys(object);
1781
+ for (let i = 0; i < keys.length; i++) {
1782
+ const key = keys[i];
1783
+ const value = object[key];
1784
+ const prefixedKey = prefix ? `${prefix}${delimiter}${key}` : key;
1785
+ if (isPlainObject(value) && Object.keys(value).length > 0) {
1786
+ Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
1787
+ continue;
1788
+ }
1789
+ if (Array.isArray(value)) {
1790
+ Object.assign(result, flattenObjectImpl(value, prefixedKey, delimiter));
1791
+ continue;
1792
+ }
1793
+ result[prefixedKey] = value;
1794
+ }
1795
+ return result;
1796
+ }
1797
+
1798
+ function merge(target, source) {
1799
+ const sourceKeys = Object.keys(source);
1800
+ for (let i = 0; i < sourceKeys.length; i++) {
1801
+ const key = sourceKeys[i];
1802
+ const sourceValue = source[key];
1803
+ const targetValue = target[key];
1804
+ if (Array.isArray(sourceValue)) {
1805
+ if (Array.isArray(targetValue)) {
1806
+ target[key] = merge(targetValue, sourceValue);
1807
+ }
1808
+ else {
1809
+ target[key] = merge([], sourceValue);
1810
+ }
1811
+ }
1812
+ else if (isPlainObject(sourceValue)) {
1813
+ if (isPlainObject(targetValue)) {
1814
+ target[key] = merge(targetValue, sourceValue);
1815
+ }
1816
+ else {
1817
+ target[key] = merge({}, sourceValue);
1818
+ }
1819
+ }
1820
+ else if (targetValue === undefined || sourceValue !== undefined) {
1821
+ target[key] = sourceValue;
1822
+ }
1823
+ }
1824
+ return target;
1825
+ }
1826
+
1827
+ function toMerged(target, source) {
1828
+ return merge(cloneDeep(target), source);
1829
+ }
1830
+
1831
+ function maxBy(items, getValue) {
1832
+ let maxElement = items[0];
1833
+ let max = -Infinity;
1834
+ for (let i = 0; i < items.length; i++) {
1835
+ const element = items[i];
1836
+ const value = getValue(element);
1837
+ if (value > max) {
1838
+ max = value;
1839
+ maxElement = element;
1840
+ }
1841
+ }
1842
+ return maxElement;
1843
+ }
1844
+
1845
+ function minBy(items, getValue) {
1846
+ let minElement = items[0];
1847
+ let min = Infinity;
1848
+ for (let i = 0; i < items.length; i++) {
1849
+ const element = items[i];
1850
+ const value = getValue(element);
1851
+ if (value < min) {
1852
+ min = value;
1853
+ minElement = element;
1854
+ }
1855
+ }
1856
+ return minElement;
1857
+ }
1858
+
1859
+ /**
1860
+ * Custom positioning reference element.
1861
+ * @see https://floating-ui.com/docs/virtual-elements
1862
+ */
1863
+
1864
+ const sides = ['top', 'right', 'bottom', 'left'];
1865
+ const min = Math.min;
1866
+ const max = Math.max;
1867
+ const round = Math.round;
1868
+ const floor = Math.floor;
1869
+ const createCoords = v => ({
1870
+ x: v,
1871
+ y: v
1872
+ });
1873
+ const oppositeSideMap = {
1874
+ left: 'right',
1875
+ right: 'left',
1876
+ bottom: 'top',
1877
+ top: 'bottom'
1878
+ };
1879
+ const oppositeAlignmentMap = {
1880
+ start: 'end',
1881
+ end: 'start'
1882
+ };
1883
+ function clamp(start, value, end) {
1884
+ return max(start, min(value, end));
1885
+ }
1886
+ function evaluate(value, param) {
1887
+ return typeof value === 'function' ? value(param) : value;
1888
+ }
1889
+ function getSide(placement) {
1890
+ return placement.split('-')[0];
1891
+ }
1892
+ function getAlignment(placement) {
1893
+ return placement.split('-')[1];
1894
+ }
1895
+ function getOppositeAxis(axis) {
1896
+ return axis === 'x' ? 'y' : 'x';
1897
+ }
1898
+ function getAxisLength(axis) {
1899
+ return axis === 'y' ? 'height' : 'width';
1900
+ }
1901
+ function getSideAxis(placement) {
1902
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
1903
+ }
1904
+ function getAlignmentAxis(placement) {
1905
+ return getOppositeAxis(getSideAxis(placement));
1906
+ }
1907
+ function getAlignmentSides(placement, rects, rtl) {
1908
+ if (rtl === void 0) {
1909
+ rtl = false;
1910
+ }
1911
+ const alignment = getAlignment(placement);
1912
+ const alignmentAxis = getAlignmentAxis(placement);
1913
+ const length = getAxisLength(alignmentAxis);
1914
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
1915
+ if (rects.reference[length] > rects.floating[length]) {
1916
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
1917
+ }
1918
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
1919
+ }
1920
+ function getExpandedPlacements(placement) {
1921
+ const oppositePlacement = getOppositePlacement(placement);
1922
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
1923
+ }
1924
+ function getOppositeAlignmentPlacement(placement) {
1925
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
1926
+ }
1927
+ function getSideList(side, isStart, rtl) {
1928
+ const lr = ['left', 'right'];
1929
+ const rl = ['right', 'left'];
1930
+ const tb = ['top', 'bottom'];
1931
+ const bt = ['bottom', 'top'];
1932
+ switch (side) {
1933
+ case 'top':
1934
+ case 'bottom':
1935
+ if (rtl) return isStart ? rl : lr;
1936
+ return isStart ? lr : rl;
1937
+ case 'left':
1938
+ case 'right':
1939
+ return isStart ? tb : bt;
1940
+ default:
1941
+ return [];
1942
+ }
1943
+ }
1944
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
1945
+ const alignment = getAlignment(placement);
1946
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
1947
+ if (alignment) {
1948
+ list = list.map(side => side + "-" + alignment);
1949
+ if (flipAlignment) {
1950
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
1951
+ }
1952
+ }
1953
+ return list;
1954
+ }
1955
+ function getOppositePlacement(placement) {
1956
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
1957
+ }
1958
+ function expandPaddingObject(padding) {
1959
+ return {
1960
+ top: 0,
1961
+ right: 0,
1962
+ bottom: 0,
1963
+ left: 0,
1964
+ ...padding
1965
+ };
1966
+ }
1967
+ function getPaddingObject(padding) {
1968
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
1969
+ top: padding,
1970
+ right: padding,
1971
+ bottom: padding,
1972
+ left: padding
1973
+ };
1974
+ }
1975
+ function rectToClientRect(rect) {
1976
+ const {
1977
+ x,
1978
+ y,
1979
+ width,
1980
+ height
1981
+ } = rect;
1982
+ return {
1983
+ width,
1984
+ height,
1985
+ top: y,
1986
+ left: x,
1987
+ right: x + width,
1988
+ bottom: y + height,
1989
+ x,
1990
+ y
1991
+ };
1992
+ }
1993
+
1994
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
1995
+ let {
1996
+ reference,
1997
+ floating
1998
+ } = _ref;
1999
+ const sideAxis = getSideAxis(placement);
2000
+ const alignmentAxis = getAlignmentAxis(placement);
2001
+ const alignLength = getAxisLength(alignmentAxis);
2002
+ const side = getSide(placement);
2003
+ const isVertical = sideAxis === 'y';
2004
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
2005
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
2006
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
2007
+ let coords;
2008
+ switch (side) {
2009
+ case 'top':
2010
+ coords = {
2011
+ x: commonX,
2012
+ y: reference.y - floating.height
2013
+ };
2014
+ break;
2015
+ case 'bottom':
2016
+ coords = {
2017
+ x: commonX,
2018
+ y: reference.y + reference.height
2019
+ };
2020
+ break;
2021
+ case 'right':
2022
+ coords = {
2023
+ x: reference.x + reference.width,
2024
+ y: commonY
2025
+ };
2026
+ break;
2027
+ case 'left':
2028
+ coords = {
2029
+ x: reference.x - floating.width,
2030
+ y: commonY
2031
+ };
2032
+ break;
2033
+ default:
2034
+ coords = {
2035
+ x: reference.x,
2036
+ y: reference.y
2037
+ };
2038
+ }
2039
+ switch (getAlignment(placement)) {
2040
+ case 'start':
2041
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
2042
+ break;
2043
+ case 'end':
2044
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
2045
+ break;
2046
+ }
2047
+ return coords;
2048
+ }
2049
+
2050
+ /**
2051
+ * Computes the `x` and `y` coordinates that will place the floating element
2052
+ * next to a given reference element.
2053
+ *
2054
+ * This export does not have any `platform` interface logic. You will need to
2055
+ * write one for the platform you are using Floating UI with.
2056
+ */
2057
+ const computePosition$1 = async (reference, floating, config) => {
2058
+ const {
2059
+ placement = 'bottom',
2060
+ strategy = 'absolute',
2061
+ middleware = [],
2062
+ platform
2063
+ } = config;
2064
+ const validMiddleware = middleware.filter(Boolean);
2065
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
2066
+ let rects = await platform.getElementRects({
2067
+ reference,
2068
+ floating,
2069
+ strategy
2070
+ });
2071
+ let {
2072
+ x,
2073
+ y
2074
+ } = computeCoordsFromPlacement(rects, placement, rtl);
2075
+ let statefulPlacement = placement;
2076
+ let middlewareData = {};
2077
+ let resetCount = 0;
2078
+ for (let i = 0; i < validMiddleware.length; i++) {
2079
+ const {
2080
+ name,
2081
+ fn
2082
+ } = validMiddleware[i];
2083
+ const {
2084
+ x: nextX,
2085
+ y: nextY,
2086
+ data,
2087
+ reset
2088
+ } = await fn({
2089
+ x,
2090
+ y,
2091
+ initialPlacement: placement,
2092
+ placement: statefulPlacement,
2093
+ strategy,
2094
+ middlewareData,
2095
+ rects,
2096
+ platform,
2097
+ elements: {
2098
+ reference,
2099
+ floating
2100
+ }
2101
+ });
2102
+ x = nextX != null ? nextX : x;
2103
+ y = nextY != null ? nextY : y;
2104
+ middlewareData = {
2105
+ ...middlewareData,
2106
+ [name]: {
2107
+ ...middlewareData[name],
2108
+ ...data
2109
+ }
2110
+ };
2111
+ if (reset && resetCount <= 50) {
2112
+ resetCount++;
2113
+ if (typeof reset === 'object') {
2114
+ if (reset.placement) {
2115
+ statefulPlacement = reset.placement;
2116
+ }
2117
+ if (reset.rects) {
2118
+ rects = reset.rects === true ? await platform.getElementRects({
2119
+ reference,
2120
+ floating,
2121
+ strategy
2122
+ }) : reset.rects;
2123
+ }
2124
+ ({
2125
+ x,
2126
+ y
2127
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
2128
+ }
2129
+ i = -1;
2130
+ }
2131
+ }
2132
+ return {
2133
+ x,
2134
+ y,
2135
+ placement: statefulPlacement,
2136
+ strategy,
2137
+ middlewareData
2138
+ };
2139
+ };
2140
+
2141
+ /**
2142
+ * Resolves with an object of overflow side offsets that determine how much the
2143
+ * element is overflowing a given clipping boundary on each side.
2144
+ * - positive = overflowing the boundary by that number of pixels
2145
+ * - negative = how many pixels left before it will overflow
2146
+ * - 0 = lies flush with the boundary
2147
+ * @see https://floating-ui.com/docs/detectOverflow
2148
+ */
2149
+ async function detectOverflow(state, options) {
2150
+ var _await$platform$isEle;
2151
+ if (options === void 0) {
2152
+ options = {};
2153
+ }
2154
+ const {
2155
+ x,
2156
+ y,
2157
+ platform,
2158
+ rects,
2159
+ elements,
2160
+ strategy
2161
+ } = state;
2162
+ const {
2163
+ boundary = 'clippingAncestors',
2164
+ rootBoundary = 'viewport',
2165
+ elementContext = 'floating',
2166
+ altBoundary = false,
2167
+ padding = 0
2168
+ } = evaluate(options, state);
2169
+ const paddingObject = getPaddingObject(padding);
2170
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
2171
+ const element = elements[altBoundary ? altContext : elementContext];
2172
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
2173
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
2174
+ boundary,
2175
+ rootBoundary,
2176
+ strategy
2177
+ }));
2178
+ const rect = elementContext === 'floating' ? {
2179
+ x,
2180
+ y,
2181
+ width: rects.floating.width,
2182
+ height: rects.floating.height
2183
+ } : rects.reference;
2184
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
2185
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
2186
+ x: 1,
2187
+ y: 1
2188
+ } : {
2189
+ x: 1,
2190
+ y: 1
2191
+ };
2192
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
2193
+ elements,
2194
+ rect,
2195
+ offsetParent,
2196
+ strategy
2197
+ }) : rect);
2198
+ return {
2199
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
2200
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
2201
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
2202
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
2203
+ };
2204
+ }
2205
+
2206
+ /**
2207
+ * Provides data to position an inner element of the floating element so that it
2208
+ * appears centered to the reference element.
2209
+ * @see https://floating-ui.com/docs/arrow
2210
+ */
2211
+ const arrow$1 = options => ({
2212
+ name: 'arrow',
2213
+ options,
2214
+ async fn(state) {
2215
+ const {
2216
+ x,
2217
+ y,
2218
+ placement,
2219
+ rects,
2220
+ platform,
2221
+ elements,
2222
+ middlewareData
2223
+ } = state;
2224
+ // Since `element` is required, we don't Partial<> the type.
2225
+ const {
2226
+ element,
2227
+ padding = 0
2228
+ } = evaluate(options, state) || {};
2229
+ if (element == null) {
2230
+ return {};
2231
+ }
2232
+ const paddingObject = getPaddingObject(padding);
2233
+ const coords = {
2234
+ x,
2235
+ y
2236
+ };
2237
+ const axis = getAlignmentAxis(placement);
2238
+ const length = getAxisLength(axis);
2239
+ const arrowDimensions = await platform.getDimensions(element);
2240
+ const isYAxis = axis === 'y';
2241
+ const minProp = isYAxis ? 'top' : 'left';
2242
+ const maxProp = isYAxis ? 'bottom' : 'right';
2243
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
2244
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
2245
+ const startDiff = coords[axis] - rects.reference[axis];
2246
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
2247
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
2248
+
2249
+ // DOM platform can return `window` as the `offsetParent`.
2250
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
2251
+ clientSize = elements.floating[clientProp] || rects.floating[length];
2252
+ }
2253
+ const centerToReference = endDiff / 2 - startDiff / 2;
2254
+
2255
+ // If the padding is large enough that it causes the arrow to no longer be
2256
+ // centered, modify the padding so that it is centered.
2257
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
2258
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
2259
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
2260
+
2261
+ // Make sure the arrow doesn't overflow the floating element if the center
2262
+ // point is outside the floating element's bounds.
2263
+ const min$1 = minPadding;
2264
+ const max = clientSize - arrowDimensions[length] - maxPadding;
2265
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
2266
+ const offset = clamp(min$1, center, max);
2267
+
2268
+ // If the reference is small enough that the arrow's padding causes it to
2269
+ // to point to nothing for an aligned placement, adjust the offset of the
2270
+ // floating element itself. To ensure `shift()` continues to take action,
2271
+ // a single reset is performed when this is true.
2272
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
2273
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
2274
+ return {
2275
+ [axis]: coords[axis] + alignmentOffset,
2276
+ data: {
2277
+ [axis]: offset,
2278
+ centerOffset: center - offset - alignmentOffset,
2279
+ ...(shouldAddOffset && {
2280
+ alignmentOffset
2281
+ })
2282
+ },
2283
+ reset: shouldAddOffset
2284
+ };
2285
+ }
2286
+ });
2287
+
2288
+ /**
2289
+ * Optimizes the visibility of the floating element by flipping the `placement`
2290
+ * in order to keep it in view when the preferred placement(s) will overflow the
2291
+ * clipping boundary. Alternative to `autoPlacement`.
2292
+ * @see https://floating-ui.com/docs/flip
2293
+ */
2294
+ const flip$1 = function (options) {
2295
+ if (options === void 0) {
2296
+ options = {};
2297
+ }
2298
+ return {
2299
+ name: 'flip',
2300
+ options,
2301
+ async fn(state) {
2302
+ var _middlewareData$arrow, _middlewareData$flip;
2303
+ const {
2304
+ placement,
2305
+ middlewareData,
2306
+ rects,
2307
+ initialPlacement,
2308
+ platform,
2309
+ elements
2310
+ } = state;
2311
+ const {
2312
+ mainAxis: checkMainAxis = true,
2313
+ crossAxis: checkCrossAxis = true,
2314
+ fallbackPlacements: specifiedFallbackPlacements,
2315
+ fallbackStrategy = 'bestFit',
2316
+ fallbackAxisSideDirection = 'none',
2317
+ flipAlignment = true,
2318
+ ...detectOverflowOptions
2319
+ } = evaluate(options, state);
2320
+
2321
+ // If a reset by the arrow was caused due to an alignment offset being
2322
+ // added, we should skip any logic now since `flip()` has already done its
2323
+ // work.
2324
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
2325
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2326
+ return {};
2327
+ }
2328
+ const side = getSide(placement);
2329
+ const initialSideAxis = getSideAxis(initialPlacement);
2330
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
2331
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
2332
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
2333
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
2334
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
2335
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
2336
+ }
2337
+ const placements = [initialPlacement, ...fallbackPlacements];
2338
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2339
+ const overflows = [];
2340
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
2341
+ if (checkMainAxis) {
2342
+ overflows.push(overflow[side]);
2343
+ }
2344
+ if (checkCrossAxis) {
2345
+ const sides = getAlignmentSides(placement, rects, rtl);
2346
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
2347
+ }
2348
+ overflowsData = [...overflowsData, {
2349
+ placement,
2350
+ overflows
2351
+ }];
2352
+
2353
+ // One or more sides is overflowing.
2354
+ if (!overflows.every(side => side <= 0)) {
2355
+ var _middlewareData$flip2, _overflowsData$filter;
2356
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
2357
+ const nextPlacement = placements[nextIndex];
2358
+ if (nextPlacement) {
2359
+ // Try next placement and re-run the lifecycle.
2360
+ return {
2361
+ data: {
2362
+ index: nextIndex,
2363
+ overflows: overflowsData
2364
+ },
2365
+ reset: {
2366
+ placement: nextPlacement
2367
+ }
2368
+ };
2369
+ }
2370
+
2371
+ // First, find the candidates that fit on the mainAxis side of overflow,
2372
+ // then find the placement that fits the best on the main crossAxis side.
2373
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
2374
+
2375
+ // Otherwise fallback.
2376
+ if (!resetPlacement) {
2377
+ switch (fallbackStrategy) {
2378
+ case 'bestFit':
2379
+ {
2380
+ var _overflowsData$filter2;
2381
+ const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
2382
+ if (hasFallbackAxisSideDirection) {
2383
+ const currentSideAxis = getSideAxis(d.placement);
2384
+ return currentSideAxis === initialSideAxis ||
2385
+ // Create a bias to the `y` side axis due to horizontal
2386
+ // reading directions favoring greater width.
2387
+ currentSideAxis === 'y';
2388
+ }
2389
+ return true;
2390
+ }).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
2391
+ if (placement) {
2392
+ resetPlacement = placement;
2393
+ }
2394
+ break;
2395
+ }
2396
+ case 'initialPlacement':
2397
+ resetPlacement = initialPlacement;
2398
+ break;
2399
+ }
2400
+ }
2401
+ if (placement !== resetPlacement) {
2402
+ return {
2403
+ reset: {
2404
+ placement: resetPlacement
2405
+ }
2406
+ };
2407
+ }
2408
+ }
2409
+ return {};
2410
+ }
2411
+ };
2412
+ };
2413
+
2414
+ function getSideOffsets(overflow, rect) {
2415
+ return {
2416
+ top: overflow.top - rect.height,
2417
+ right: overflow.right - rect.width,
2418
+ bottom: overflow.bottom - rect.height,
2419
+ left: overflow.left - rect.width
2420
+ };
2421
+ }
2422
+ function isAnySideFullyClipped(overflow) {
2423
+ return sides.some(side => overflow[side] >= 0);
2424
+ }
2425
+ /**
2426
+ * Provides data to hide the floating element in applicable situations, such as
2427
+ * when it is not in the same clipping context as the reference element.
2428
+ * @see https://floating-ui.com/docs/hide
2429
+ */
2430
+ const hide$1 = function (options) {
2431
+ if (options === void 0) {
2432
+ options = {};
2433
+ }
2434
+ return {
2435
+ name: 'hide',
2436
+ options,
2437
+ async fn(state) {
2438
+ const {
2439
+ rects
2440
+ } = state;
2441
+ const {
2442
+ strategy = 'referenceHidden',
2443
+ ...detectOverflowOptions
2444
+ } = evaluate(options, state);
2445
+ switch (strategy) {
2446
+ case 'referenceHidden':
2447
+ {
2448
+ const overflow = await detectOverflow(state, {
2449
+ ...detectOverflowOptions,
2450
+ elementContext: 'reference'
2451
+ });
2452
+ const offsets = getSideOffsets(overflow, rects.reference);
2453
+ return {
2454
+ data: {
2455
+ referenceHiddenOffsets: offsets,
2456
+ referenceHidden: isAnySideFullyClipped(offsets)
2457
+ }
2458
+ };
2459
+ }
2460
+ case 'escaped':
2461
+ {
2462
+ const overflow = await detectOverflow(state, {
2463
+ ...detectOverflowOptions,
2464
+ altBoundary: true
2465
+ });
2466
+ const offsets = getSideOffsets(overflow, rects.floating);
2467
+ return {
2468
+ data: {
2469
+ escapedOffsets: offsets,
2470
+ escaped: isAnySideFullyClipped(offsets)
2471
+ }
2472
+ };
2473
+ }
2474
+ default:
2475
+ {
2476
+ return {};
2477
+ }
2478
+ }
2479
+ }
2480
+ };
2481
+ };
2482
+
2483
+ // For type backwards-compatibility, the `OffsetOptions` type was also
2484
+ // Derivable.
2485
+
2486
+ async function convertValueToCoords(state, options) {
2487
+ const {
2488
+ placement,
2489
+ platform,
2490
+ elements
2491
+ } = state;
2492
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
2493
+ const side = getSide(placement);
2494
+ const alignment = getAlignment(placement);
2495
+ const isVertical = getSideAxis(placement) === 'y';
2496
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
2497
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
2498
+ const rawValue = evaluate(options, state);
2499
+
2500
+ // eslint-disable-next-line prefer-const
2501
+ let {
2502
+ mainAxis,
2503
+ crossAxis,
2504
+ alignmentAxis
2505
+ } = typeof rawValue === 'number' ? {
2506
+ mainAxis: rawValue,
2507
+ crossAxis: 0,
2508
+ alignmentAxis: null
2509
+ } : {
2510
+ mainAxis: rawValue.mainAxis || 0,
2511
+ crossAxis: rawValue.crossAxis || 0,
2512
+ alignmentAxis: rawValue.alignmentAxis
2513
+ };
2514
+ if (alignment && typeof alignmentAxis === 'number') {
2515
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
2516
+ }
2517
+ return isVertical ? {
2518
+ x: crossAxis * crossAxisMulti,
2519
+ y: mainAxis * mainAxisMulti
2520
+ } : {
2521
+ x: mainAxis * mainAxisMulti,
2522
+ y: crossAxis * crossAxisMulti
2523
+ };
2524
+ }
2525
+
2526
+ /**
2527
+ * Modifies the placement by translating the floating element along the
2528
+ * specified axes.
2529
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
2530
+ * object may be passed.
2531
+ * @see https://floating-ui.com/docs/offset
2532
+ */
2533
+ const offset$1 = function (options) {
2534
+ if (options === void 0) {
2535
+ options = 0;
2536
+ }
2537
+ return {
2538
+ name: 'offset',
2539
+ options,
2540
+ async fn(state) {
2541
+ var _middlewareData$offse, _middlewareData$arrow;
2542
+ const {
2543
+ x,
2544
+ y,
2545
+ placement,
2546
+ middlewareData
2547
+ } = state;
2548
+ const diffCoords = await convertValueToCoords(state, options);
2549
+
2550
+ // If the placement is the same and the arrow caused an alignment offset
2551
+ // then we don't need to change the positioning coordinates.
2552
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2553
+ return {};
2554
+ }
2555
+ return {
2556
+ x: x + diffCoords.x,
2557
+ y: y + diffCoords.y,
2558
+ data: {
2559
+ ...diffCoords,
2560
+ placement
2561
+ }
2562
+ };
2563
+ }
2564
+ };
2565
+ };
2566
+
2567
+ /**
2568
+ * Optimizes the visibility of the floating element by shifting it in order to
2569
+ * keep it in view when it will overflow the clipping boundary.
2570
+ * @see https://floating-ui.com/docs/shift
2571
+ */
2572
+ const shift$1 = function (options) {
2573
+ if (options === void 0) {
2574
+ options = {};
2575
+ }
2576
+ return {
2577
+ name: 'shift',
2578
+ options,
2579
+ async fn(state) {
2580
+ const {
2581
+ x,
2582
+ y,
2583
+ placement
2584
+ } = state;
2585
+ const {
2586
+ mainAxis: checkMainAxis = true,
2587
+ crossAxis: checkCrossAxis = false,
2588
+ limiter = {
2589
+ fn: _ref => {
2590
+ let {
2591
+ x,
2592
+ y
2593
+ } = _ref;
2594
+ return {
2595
+ x,
2596
+ y
2597
+ };
2598
+ }
2599
+ },
2600
+ ...detectOverflowOptions
2601
+ } = evaluate(options, state);
2602
+ const coords = {
2603
+ x,
2604
+ y
2605
+ };
2606
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2607
+ const crossAxis = getSideAxis(getSide(placement));
2608
+ const mainAxis = getOppositeAxis(crossAxis);
2609
+ let mainAxisCoord = coords[mainAxis];
2610
+ let crossAxisCoord = coords[crossAxis];
2611
+ if (checkMainAxis) {
2612
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
2613
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
2614
+ const min = mainAxisCoord + overflow[minSide];
2615
+ const max = mainAxisCoord - overflow[maxSide];
2616
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
2617
+ }
2618
+ if (checkCrossAxis) {
2619
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
2620
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
2621
+ const min = crossAxisCoord + overflow[minSide];
2622
+ const max = crossAxisCoord - overflow[maxSide];
2623
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
2624
+ }
2625
+ const limitedCoords = limiter.fn({
2626
+ ...state,
2627
+ [mainAxis]: mainAxisCoord,
2628
+ [crossAxis]: crossAxisCoord
2629
+ });
2630
+ return {
2631
+ ...limitedCoords,
2632
+ data: {
2633
+ x: limitedCoords.x - x,
2634
+ y: limitedCoords.y - y,
2635
+ enabled: {
2636
+ [mainAxis]: checkMainAxis,
2637
+ [crossAxis]: checkCrossAxis
2638
+ }
2639
+ }
2640
+ };
2641
+ }
2642
+ };
2643
+ };
2644
+
2645
+ /**
2646
+ * Provides data that allows you to change the size of the floating element —
2647
+ * for instance, prevent it from overflowing the clipping boundary or match the
2648
+ * width of the reference element.
2649
+ * @see https://floating-ui.com/docs/size
2650
+ */
2651
+ const size$1 = function (options) {
2652
+ if (options === void 0) {
2653
+ options = {};
2654
+ }
2655
+ return {
2656
+ name: 'size',
2657
+ options,
2658
+ async fn(state) {
2659
+ var _state$middlewareData, _state$middlewareData2;
2660
+ const {
2661
+ placement,
2662
+ rects,
2663
+ platform,
2664
+ elements
2665
+ } = state;
2666
+ const {
2667
+ apply = () => {},
2668
+ ...detectOverflowOptions
2669
+ } = evaluate(options, state);
2670
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2671
+ const side = getSide(placement);
2672
+ const alignment = getAlignment(placement);
2673
+ const isYAxis = getSideAxis(placement) === 'y';
2674
+ const {
2675
+ width,
2676
+ height
2677
+ } = rects.floating;
2678
+ let heightSide;
2679
+ let widthSide;
2680
+ if (side === 'top' || side === 'bottom') {
2681
+ heightSide = side;
2682
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
2683
+ } else {
2684
+ widthSide = side;
2685
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
2686
+ }
2687
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
2688
+ const maximumClippingWidth = width - overflow.left - overflow.right;
2689
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
2690
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
2691
+ const noShift = !state.middlewareData.shift;
2692
+ let availableHeight = overflowAvailableHeight;
2693
+ let availableWidth = overflowAvailableWidth;
2694
+ if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
2695
+ availableWidth = maximumClippingWidth;
2696
+ }
2697
+ if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
2698
+ availableHeight = maximumClippingHeight;
2699
+ }
2700
+ if (noShift && !alignment) {
2701
+ const xMin = max(overflow.left, 0);
2702
+ const xMax = max(overflow.right, 0);
2703
+ const yMin = max(overflow.top, 0);
2704
+ const yMax = max(overflow.bottom, 0);
2705
+ if (isYAxis) {
2706
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
2707
+ } else {
2708
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
2709
+ }
2710
+ }
2711
+ await apply({
2712
+ ...state,
2713
+ availableWidth,
2714
+ availableHeight
2715
+ });
2716
+ const nextDimensions = await platform.getDimensions(elements.floating);
2717
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
2718
+ return {
2719
+ reset: {
2720
+ rects: true
2721
+ }
2722
+ };
2723
+ }
2724
+ return {};
2725
+ }
2726
+ };
2727
+ };
2728
+
2729
+ function hasWindow() {
2730
+ return typeof window !== 'undefined';
2731
+ }
2732
+ function getNodeName(node) {
2733
+ if (isNode(node)) {
2734
+ return (node.nodeName || '').toLowerCase();
2735
+ }
2736
+ // Mocked nodes in testing environments may not be instances of Node. By
2737
+ // returning `#document` an infinite loop won't occur.
2738
+ // https://github.com/floating-ui/floating-ui/issues/2317
2739
+ return '#document';
2740
+ }
2741
+ function getWindow(node) {
2742
+ var _node$ownerDocument;
2743
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
2744
+ }
2745
+ function getDocumentElement(node) {
2746
+ var _ref;
2747
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2748
+ }
2749
+ function isNode(value) {
2750
+ if (!hasWindow()) {
2751
+ return false;
2752
+ }
2753
+ return value instanceof Node || value instanceof getWindow(value).Node;
2754
+ }
2755
+ function isElement(value) {
2756
+ if (!hasWindow()) {
2757
+ return false;
2758
+ }
2759
+ return value instanceof Element || value instanceof getWindow(value).Element;
2760
+ }
2761
+ function isHTMLElement(value) {
2762
+ if (!hasWindow()) {
2763
+ return false;
2764
+ }
2765
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
2766
+ }
2767
+ function isShadowRoot(value) {
2768
+ if (!hasWindow() || typeof ShadowRoot === 'undefined') {
2769
+ return false;
2770
+ }
2771
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
2772
+ }
2773
+ function isOverflowElement(element) {
2774
+ const {
2775
+ overflow,
2776
+ overflowX,
2777
+ overflowY,
2778
+ display
2779
+ } = getComputedStyle$1(element);
2780
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
2781
+ }
2782
+ function isTableElement(element) {
2783
+ return ['table', 'td', 'th'].includes(getNodeName(element));
2784
+ }
2785
+ function isTopLayer(element) {
2786
+ return [':popover-open', ':modal'].some(selector => {
2787
+ try {
2788
+ return element.matches(selector);
2789
+ } catch (e) {
2790
+ return false;
2791
+ }
2792
+ });
2793
+ }
2794
+ function isContainingBlock(elementOrCss) {
2795
+ const webkit = isWebKit();
2796
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
2797
+
2798
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
2799
+ // https://drafts.csswg.org/css-transforms-2/#individual-transforms
2800
+ return ['transform', 'translate', 'scale', 'rotate', 'perspective'].some(value => css[value] ? css[value] !== 'none' : false) || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
2801
+ }
2802
+ function getContainingBlock(element) {
2803
+ let currentNode = getParentNode(element);
2804
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
2805
+ if (isContainingBlock(currentNode)) {
2806
+ return currentNode;
2807
+ } else if (isTopLayer(currentNode)) {
2808
+ return null;
2809
+ }
2810
+ currentNode = getParentNode(currentNode);
2811
+ }
2812
+ return null;
2813
+ }
2814
+ function isWebKit() {
2815
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
2816
+ return CSS.supports('-webkit-backdrop-filter', 'none');
2817
+ }
2818
+ function isLastTraversableNode(node) {
2819
+ return ['html', 'body', '#document'].includes(getNodeName(node));
2820
+ }
2821
+ function getComputedStyle$1(element) {
2822
+ return getWindow(element).getComputedStyle(element);
2823
+ }
2824
+ function getNodeScroll(element) {
2825
+ if (isElement(element)) {
2826
+ return {
2827
+ scrollLeft: element.scrollLeft,
2828
+ scrollTop: element.scrollTop
2829
+ };
2830
+ }
2831
+ return {
2832
+ scrollLeft: element.scrollX,
2833
+ scrollTop: element.scrollY
2834
+ };
2835
+ }
2836
+ function getParentNode(node) {
2837
+ if (getNodeName(node) === 'html') {
2838
+ return node;
2839
+ }
2840
+ const result =
2841
+ // Step into the shadow DOM of the parent of a slotted node.
2842
+ node.assignedSlot ||
2843
+ // DOM Element detected.
2844
+ node.parentNode ||
2845
+ // ShadowRoot detected.
2846
+ isShadowRoot(node) && node.host ||
2847
+ // Fallback.
2848
+ getDocumentElement(node);
2849
+ return isShadowRoot(result) ? result.host : result;
2850
+ }
2851
+ function getNearestOverflowAncestor(node) {
2852
+ const parentNode = getParentNode(node);
2853
+ if (isLastTraversableNode(parentNode)) {
2854
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
2855
+ }
2856
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2857
+ return parentNode;
2858
+ }
2859
+ return getNearestOverflowAncestor(parentNode);
2860
+ }
2861
+ function getOverflowAncestors(node, list, traverseIframes) {
2862
+ var _node$ownerDocument2;
2863
+ if (list === void 0) {
2864
+ list = [];
2865
+ }
2866
+ if (traverseIframes === void 0) {
2867
+ traverseIframes = true;
2868
+ }
2869
+ const scrollableAncestor = getNearestOverflowAncestor(node);
2870
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
2871
+ const win = getWindow(scrollableAncestor);
2872
+ if (isBody) {
2873
+ const frameElement = getFrameElement(win);
2874
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
2875
+ }
2876
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
2877
+ }
2878
+ function getFrameElement(win) {
2879
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
2880
+ }
2881
+
2882
+ function getCssDimensions(element) {
2883
+ const css = getComputedStyle$1(element);
2884
+ // In testing environments, the `width` and `height` properties are empty
2885
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
2886
+ let width = parseFloat(css.width) || 0;
2887
+ let height = parseFloat(css.height) || 0;
2888
+ const hasOffset = isHTMLElement(element);
2889
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
2890
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
2891
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
2892
+ if (shouldFallback) {
2893
+ width = offsetWidth;
2894
+ height = offsetHeight;
2895
+ }
2896
+ return {
2897
+ width,
2898
+ height,
2899
+ $: shouldFallback
2900
+ };
2901
+ }
2902
+
2903
+ function unwrapElement(element) {
2904
+ return !isElement(element) ? element.contextElement : element;
2905
+ }
2906
+
2907
+ function getScale(element) {
2908
+ const domElement = unwrapElement(element);
2909
+ if (!isHTMLElement(domElement)) {
2910
+ return createCoords(1);
2911
+ }
2912
+ const rect = domElement.getBoundingClientRect();
2913
+ const {
2914
+ width,
2915
+ height,
2916
+ $
2917
+ } = getCssDimensions(domElement);
2918
+ let x = ($ ? round(rect.width) : rect.width) / width;
2919
+ let y = ($ ? round(rect.height) : rect.height) / height;
2920
+
2921
+ // 0, NaN, or Infinity should always fallback to 1.
2922
+
2923
+ if (!x || !Number.isFinite(x)) {
2924
+ x = 1;
2925
+ }
2926
+ if (!y || !Number.isFinite(y)) {
2927
+ y = 1;
2928
+ }
2929
+ return {
2930
+ x,
2931
+ y
2932
+ };
2933
+ }
2934
+
2935
+ const noOffsets = /*#__PURE__*/createCoords(0);
2936
+ function getVisualOffsets(element) {
2937
+ const win = getWindow(element);
2938
+ if (!isWebKit() || !win.visualViewport) {
2939
+ return noOffsets;
2940
+ }
2941
+ return {
2942
+ x: win.visualViewport.offsetLeft,
2943
+ y: win.visualViewport.offsetTop
2944
+ };
2945
+ }
2946
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
2947
+ if (isFixed === void 0) {
2948
+ isFixed = false;
2949
+ }
2950
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
2951
+ return false;
2952
+ }
2953
+ return isFixed;
2954
+ }
2955
+
2956
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
2957
+ if (includeScale === void 0) {
2958
+ includeScale = false;
2959
+ }
2960
+ if (isFixedStrategy === void 0) {
2961
+ isFixedStrategy = false;
2962
+ }
2963
+ const clientRect = element.getBoundingClientRect();
2964
+ const domElement = unwrapElement(element);
2965
+ let scale = createCoords(1);
2966
+ if (includeScale) {
2967
+ if (offsetParent) {
2968
+ if (isElement(offsetParent)) {
2969
+ scale = getScale(offsetParent);
2970
+ }
2971
+ } else {
2972
+ scale = getScale(element);
2973
+ }
2974
+ }
2975
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
2976
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
2977
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
2978
+ let width = clientRect.width / scale.x;
2979
+ let height = clientRect.height / scale.y;
2980
+ if (domElement) {
2981
+ const win = getWindow(domElement);
2982
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2983
+ let currentWin = win;
2984
+ let currentIFrame = getFrameElement(currentWin);
2985
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
2986
+ const iframeScale = getScale(currentIFrame);
2987
+ const iframeRect = currentIFrame.getBoundingClientRect();
2988
+ const css = getComputedStyle$1(currentIFrame);
2989
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
2990
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
2991
+ x *= iframeScale.x;
2992
+ y *= iframeScale.y;
2993
+ width *= iframeScale.x;
2994
+ height *= iframeScale.y;
2995
+ x += left;
2996
+ y += top;
2997
+ currentWin = getWindow(currentIFrame);
2998
+ currentIFrame = getFrameElement(currentWin);
2999
+ }
3000
+ }
3001
+ return rectToClientRect({
3002
+ width,
3003
+ height,
3004
+ x,
3005
+ y
3006
+ });
3007
+ }
3008
+
3009
+ // If <html> has a CSS width greater than the viewport, then this will be
3010
+ // incorrect for RTL.
3011
+ function getWindowScrollBarX(element, rect) {
3012
+ const leftScroll = getNodeScroll(element).scrollLeft;
3013
+ if (!rect) {
3014
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
3015
+ }
3016
+ return rect.left + leftScroll;
3017
+ }
3018
+
3019
+ function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
3020
+ if (ignoreScrollbarX === void 0) {
3021
+ ignoreScrollbarX = false;
3022
+ }
3023
+ const htmlRect = documentElement.getBoundingClientRect();
3024
+ const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 :
3025
+ // RTL <body> scrollbar.
3026
+ getWindowScrollBarX(documentElement, htmlRect));
3027
+ const y = htmlRect.top + scroll.scrollTop;
3028
+ return {
3029
+ x,
3030
+ y
3031
+ };
3032
+ }
3033
+
3034
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
3035
+ let {
3036
+ elements,
3037
+ rect,
3038
+ offsetParent,
3039
+ strategy
3040
+ } = _ref;
3041
+ const isFixed = strategy === 'fixed';
3042
+ const documentElement = getDocumentElement(offsetParent);
3043
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
3044
+ if (offsetParent === documentElement || topLayer && isFixed) {
3045
+ return rect;
3046
+ }
3047
+ let scroll = {
3048
+ scrollLeft: 0,
3049
+ scrollTop: 0
3050
+ };
3051
+ let scale = createCoords(1);
3052
+ const offsets = createCoords(0);
3053
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
3054
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3055
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
3056
+ scroll = getNodeScroll(offsetParent);
3057
+ }
3058
+ if (isHTMLElement(offsetParent)) {
3059
+ const offsetRect = getBoundingClientRect(offsetParent);
3060
+ scale = getScale(offsetParent);
3061
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
3062
+ offsets.y = offsetRect.y + offsetParent.clientTop;
3063
+ }
3064
+ }
3065
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
3066
+ return {
3067
+ width: rect.width * scale.x,
3068
+ height: rect.height * scale.y,
3069
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
3070
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
3071
+ };
3072
+ }
3073
+
3074
+ function getClientRects(element) {
3075
+ return Array.from(element.getClientRects());
3076
+ }
3077
+
3078
+ // Gets the entire size of the scrollable document area, even extending outside
3079
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
3080
+ function getDocumentRect(element) {
3081
+ const html = getDocumentElement(element);
3082
+ const scroll = getNodeScroll(element);
3083
+ const body = element.ownerDocument.body;
3084
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
3085
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
3086
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
3087
+ const y = -scroll.scrollTop;
3088
+ if (getComputedStyle$1(body).direction === 'rtl') {
3089
+ x += max(html.clientWidth, body.clientWidth) - width;
3090
+ }
3091
+ return {
3092
+ width,
3093
+ height,
3094
+ x,
3095
+ y
3096
+ };
3097
+ }
3098
+
3099
+ function getViewportRect(element, strategy) {
3100
+ const win = getWindow(element);
3101
+ const html = getDocumentElement(element);
3102
+ const visualViewport = win.visualViewport;
3103
+ let width = html.clientWidth;
3104
+ let height = html.clientHeight;
3105
+ let x = 0;
3106
+ let y = 0;
3107
+ if (visualViewport) {
3108
+ width = visualViewport.width;
3109
+ height = visualViewport.height;
3110
+ const visualViewportBased = isWebKit();
3111
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
3112
+ x = visualViewport.offsetLeft;
3113
+ y = visualViewport.offsetTop;
3114
+ }
3115
+ }
3116
+ return {
3117
+ width,
3118
+ height,
3119
+ x,
3120
+ y
3121
+ };
3122
+ }
3123
+
3124
+ // Returns the inner client rect, subtracting scrollbars if present.
3125
+ function getInnerBoundingClientRect(element, strategy) {
3126
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
3127
+ const top = clientRect.top + element.clientTop;
3128
+ const left = clientRect.left + element.clientLeft;
3129
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
3130
+ const width = element.clientWidth * scale.x;
3131
+ const height = element.clientHeight * scale.y;
3132
+ const x = left * scale.x;
3133
+ const y = top * scale.y;
3134
+ return {
3135
+ width,
3136
+ height,
3137
+ x,
3138
+ y
3139
+ };
3140
+ }
3141
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
3142
+ let rect;
3143
+ if (clippingAncestor === 'viewport') {
3144
+ rect = getViewportRect(element, strategy);
3145
+ } else if (clippingAncestor === 'document') {
3146
+ rect = getDocumentRect(getDocumentElement(element));
3147
+ } else if (isElement(clippingAncestor)) {
3148
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
3149
+ } else {
3150
+ const visualOffsets = getVisualOffsets(element);
3151
+ rect = {
3152
+ x: clippingAncestor.x - visualOffsets.x,
3153
+ y: clippingAncestor.y - visualOffsets.y,
3154
+ width: clippingAncestor.width,
3155
+ height: clippingAncestor.height
3156
+ };
3157
+ }
3158
+ return rectToClientRect(rect);
3159
+ }
3160
+ function hasFixedPositionAncestor(element, stopNode) {
3161
+ const parentNode = getParentNode(element);
3162
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
3163
+ return false;
3164
+ }
3165
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
3166
+ }
3167
+
3168
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
3169
+ // clipping (or hiding) child elements. This returns all clipping ancestors
3170
+ // of the given element up the tree.
3171
+ function getClippingElementAncestors(element, cache) {
3172
+ const cachedResult = cache.get(element);
3173
+ if (cachedResult) {
3174
+ return cachedResult;
3175
+ }
3176
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
3177
+ let currentContainingBlockComputedStyle = null;
3178
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
3179
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
3180
+
3181
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
3182
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
3183
+ const computedStyle = getComputedStyle$1(currentNode);
3184
+ const currentNodeIsContaining = isContainingBlock(currentNode);
3185
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
3186
+ currentContainingBlockComputedStyle = null;
3187
+ }
3188
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
3189
+ if (shouldDropCurrentNode) {
3190
+ // Drop non-containing blocks.
3191
+ result = result.filter(ancestor => ancestor !== currentNode);
3192
+ } else {
3193
+ // Record last containing block for next iteration.
3194
+ currentContainingBlockComputedStyle = computedStyle;
3195
+ }
3196
+ currentNode = getParentNode(currentNode);
3197
+ }
3198
+ cache.set(element, result);
3199
+ return result;
3200
+ }
3201
+
3202
+ // Gets the maximum area that the element is visible in due to any number of
3203
+ // clipping ancestors.
3204
+ function getClippingRect(_ref) {
3205
+ let {
3206
+ element,
3207
+ boundary,
3208
+ rootBoundary,
3209
+ strategy
3210
+ } = _ref;
3211
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
3212
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
3213
+ const firstClippingAncestor = clippingAncestors[0];
3214
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
3215
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
3216
+ accRect.top = max(rect.top, accRect.top);
3217
+ accRect.right = min(rect.right, accRect.right);
3218
+ accRect.bottom = min(rect.bottom, accRect.bottom);
3219
+ accRect.left = max(rect.left, accRect.left);
3220
+ return accRect;
3221
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
3222
+ return {
3223
+ width: clippingRect.right - clippingRect.left,
3224
+ height: clippingRect.bottom - clippingRect.top,
3225
+ x: clippingRect.left,
3226
+ y: clippingRect.top
3227
+ };
3228
+ }
3229
+
3230
+ function getDimensions(element) {
3231
+ const {
3232
+ width,
3233
+ height
3234
+ } = getCssDimensions(element);
3235
+ return {
3236
+ width,
3237
+ height
3238
+ };
3239
+ }
3240
+
3241
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
3242
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
3243
+ const documentElement = getDocumentElement(offsetParent);
3244
+ const isFixed = strategy === 'fixed';
3245
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
3246
+ let scroll = {
3247
+ scrollLeft: 0,
3248
+ scrollTop: 0
3249
+ };
3250
+ const offsets = createCoords(0);
3251
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3252
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
3253
+ scroll = getNodeScroll(offsetParent);
3254
+ }
3255
+ if (isOffsetParentAnElement) {
3256
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
3257
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
3258
+ offsets.y = offsetRect.y + offsetParent.clientTop;
3259
+ } else if (documentElement) {
3260
+ // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
3261
+ // Firefox with layout.scrollbar.side = 3 in about:config to test this.
3262
+ offsets.x = getWindowScrollBarX(documentElement);
3263
+ }
3264
+ }
3265
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
3266
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
3267
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
3268
+ return {
3269
+ x,
3270
+ y,
3271
+ width: rect.width,
3272
+ height: rect.height
3273
+ };
3274
+ }
3275
+
3276
+ function isStaticPositioned(element) {
3277
+ return getComputedStyle$1(element).position === 'static';
3278
+ }
3279
+
3280
+ function getTrueOffsetParent(element, polyfill) {
3281
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
3282
+ return null;
3283
+ }
3284
+ if (polyfill) {
3285
+ return polyfill(element);
3286
+ }
3287
+ let rawOffsetParent = element.offsetParent;
3288
+
3289
+ // Firefox returns the <html> element as the offsetParent if it's non-static,
3290
+ // while Chrome and Safari return the <body> element. The <body> element must
3291
+ // be used to perform the correct calculations even if the <html> element is
3292
+ // non-static.
3293
+ if (getDocumentElement(element) === rawOffsetParent) {
3294
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
3295
+ }
3296
+ return rawOffsetParent;
3297
+ }
3298
+
3299
+ // Gets the closest ancestor positioned element. Handles some edge cases,
3300
+ // such as table ancestors and cross browser bugs.
3301
+ function getOffsetParent(element, polyfill) {
3302
+ const win = getWindow(element);
3303
+ if (isTopLayer(element)) {
3304
+ return win;
3305
+ }
3306
+ if (!isHTMLElement(element)) {
3307
+ let svgOffsetParent = getParentNode(element);
3308
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
3309
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
3310
+ return svgOffsetParent;
3311
+ }
3312
+ svgOffsetParent = getParentNode(svgOffsetParent);
3313
+ }
3314
+ return win;
3315
+ }
3316
+ let offsetParent = getTrueOffsetParent(element, polyfill);
3317
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
3318
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
3319
+ }
3320
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
3321
+ return win;
3322
+ }
3323
+ return offsetParent || getContainingBlock(element) || win;
3324
+ }
3325
+
3326
+ const getElementRects = async function (data) {
3327
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
3328
+ const getDimensionsFn = this.getDimensions;
3329
+ const floatingDimensions = await getDimensionsFn(data.floating);
3330
+ return {
3331
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
3332
+ floating: {
3333
+ x: 0,
3334
+ y: 0,
3335
+ width: floatingDimensions.width,
3336
+ height: floatingDimensions.height
3337
+ }
3338
+ };
3339
+ };
3340
+
3341
+ function isRTL(element) {
3342
+ return getComputedStyle$1(element).direction === 'rtl';
3343
+ }
3344
+
3345
+ const platform = {
3346
+ convertOffsetParentRelativeRectToViewportRelativeRect,
3347
+ getDocumentElement,
3348
+ getClippingRect,
3349
+ getOffsetParent,
3350
+ getElementRects,
3351
+ getClientRects,
3352
+ getDimensions,
3353
+ getScale,
3354
+ isElement,
3355
+ isRTL
3356
+ };
3357
+
3358
+ function rectsAreEqual(a, b) {
3359
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
3360
+ }
3361
+
3362
+ // https://samthor.au/2021/observing-dom/
3363
+ function observeMove(element, onMove) {
3364
+ let io = null;
3365
+ let timeoutId;
3366
+ const root = getDocumentElement(element);
3367
+ function cleanup() {
3368
+ var _io;
3369
+ clearTimeout(timeoutId);
3370
+ (_io = io) == null || _io.disconnect();
3371
+ io = null;
3372
+ }
3373
+ function refresh(skip, threshold) {
3374
+ if (skip === void 0) {
3375
+ skip = false;
3376
+ }
3377
+ if (threshold === void 0) {
3378
+ threshold = 1;
3379
+ }
3380
+ cleanup();
3381
+ const elementRectForRootMargin = element.getBoundingClientRect();
3382
+ const {
3383
+ left,
3384
+ top,
3385
+ width,
3386
+ height
3387
+ } = elementRectForRootMargin;
3388
+ if (!skip) {
3389
+ onMove();
3390
+ }
3391
+ if (!width || !height) {
3392
+ return;
3393
+ }
3394
+ const insetTop = floor(top);
3395
+ const insetRight = floor(root.clientWidth - (left + width));
3396
+ const insetBottom = floor(root.clientHeight - (top + height));
3397
+ const insetLeft = floor(left);
3398
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
3399
+ const options = {
3400
+ rootMargin,
3401
+ threshold: max(0, min(1, threshold)) || 1
3402
+ };
3403
+ let isFirstUpdate = true;
3404
+ function handleObserve(entries) {
3405
+ const ratio = entries[0].intersectionRatio;
3406
+ if (ratio !== threshold) {
3407
+ if (!isFirstUpdate) {
3408
+ return refresh();
3409
+ }
3410
+ if (!ratio) {
3411
+ // If the reference is clipped, the ratio is 0. Throttle the refresh
3412
+ // to prevent an infinite loop of updates.
3413
+ timeoutId = setTimeout(() => {
3414
+ refresh(false, 1e-7);
3415
+ }, 1000);
3416
+ } else {
3417
+ refresh(false, ratio);
3418
+ }
3419
+ }
3420
+ if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
3421
+ // It's possible that even though the ratio is reported as 1, the
3422
+ // element is not actually fully within the IntersectionObserver's root
3423
+ // area anymore. This can happen under performance constraints. This may
3424
+ // be a bug in the browser's IntersectionObserver implementation. To
3425
+ // work around this, we compare the element's bounding rect now with
3426
+ // what it was at the time we created the IntersectionObserver. If they
3427
+ // are not equal then the element moved, so we refresh.
3428
+ refresh();
3429
+ }
3430
+ isFirstUpdate = false;
3431
+ }
3432
+
3433
+ // Older browsers don't support a `document` as the root and will throw an
3434
+ // error.
3435
+ try {
3436
+ io = new IntersectionObserver(handleObserve, {
3437
+ ...options,
3438
+ // Handle <iframe>s
3439
+ root: root.ownerDocument
3440
+ });
3441
+ } catch (e) {
3442
+ io = new IntersectionObserver(handleObserve, options);
3443
+ }
3444
+ io.observe(element);
3445
+ }
3446
+ refresh(true);
3447
+ return cleanup;
3448
+ }
3449
+
3450
+ /**
3451
+ * Automatically updates the position of the floating element when necessary.
3452
+ * Should only be called when the floating element is mounted on the DOM or
3453
+ * visible on the screen.
3454
+ * @returns cleanup function that should be invoked when the floating element is
3455
+ * removed from the DOM or hidden from the screen.
3456
+ * @see https://floating-ui.com/docs/autoUpdate
3457
+ */
3458
+ function autoUpdate(reference, floating, update, options) {
3459
+ if (options === void 0) {
3460
+ options = {};
3461
+ }
3462
+ const {
3463
+ ancestorScroll = true,
3464
+ ancestorResize = true,
3465
+ elementResize = typeof ResizeObserver === 'function',
3466
+ layoutShift = typeof IntersectionObserver === 'function',
3467
+ animationFrame = false
3468
+ } = options;
3469
+ const referenceEl = unwrapElement(reference);
3470
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
3471
+ ancestors.forEach(ancestor => {
3472
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
3473
+ passive: true
3474
+ });
3475
+ ancestorResize && ancestor.addEventListener('resize', update);
3476
+ });
3477
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
3478
+ let reobserveFrame = -1;
3479
+ let resizeObserver = null;
3480
+ if (elementResize) {
3481
+ resizeObserver = new ResizeObserver(_ref => {
3482
+ let [firstEntry] = _ref;
3483
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
3484
+ // Prevent update loops when using the `size` middleware.
3485
+ // https://github.com/floating-ui/floating-ui/issues/1740
3486
+ resizeObserver.unobserve(floating);
3487
+ cancelAnimationFrame(reobserveFrame);
3488
+ reobserveFrame = requestAnimationFrame(() => {
3489
+ var _resizeObserver;
3490
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
3491
+ });
3492
+ }
3493
+ update();
3494
+ });
3495
+ if (referenceEl && !animationFrame) {
3496
+ resizeObserver.observe(referenceEl);
3497
+ }
3498
+ resizeObserver.observe(floating);
3499
+ }
3500
+ let frameId;
3501
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
3502
+ if (animationFrame) {
3503
+ frameLoop();
3504
+ }
3505
+ function frameLoop() {
3506
+ const nextRefRect = getBoundingClientRect(reference);
3507
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
3508
+ update();
3509
+ }
3510
+ prevRefRect = nextRefRect;
3511
+ frameId = requestAnimationFrame(frameLoop);
3512
+ }
3513
+ update();
3514
+ return () => {
3515
+ var _resizeObserver2;
3516
+ ancestors.forEach(ancestor => {
3517
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
3518
+ ancestorResize && ancestor.removeEventListener('resize', update);
3519
+ });
3520
+ cleanupIo == null || cleanupIo();
3521
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
3522
+ resizeObserver = null;
3523
+ if (animationFrame) {
3524
+ cancelAnimationFrame(frameId);
3525
+ }
3526
+ };
3527
+ }
3528
+
3529
+ /**
3530
+ * Modifies the placement by translating the floating element along the
3531
+ * specified axes.
3532
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
3533
+ * object may be passed.
3534
+ * @see https://floating-ui.com/docs/offset
3535
+ */
3536
+ const offset = offset$1;
3537
+
3538
+ /**
3539
+ * Optimizes the visibility of the floating element by shifting it in order to
3540
+ * keep it in view when it will overflow the clipping boundary.
3541
+ * @see https://floating-ui.com/docs/shift
3542
+ */
3543
+ const shift = shift$1;
3544
+
3545
+ /**
3546
+ * Optimizes the visibility of the floating element by flipping the `placement`
3547
+ * in order to keep it in view when the preferred placement(s) will overflow the
3548
+ * clipping boundary. Alternative to `autoPlacement`.
3549
+ * @see https://floating-ui.com/docs/flip
3550
+ */
3551
+ const flip = flip$1;
3552
+
3553
+ /**
3554
+ * Provides data that allows you to change the size of the floating element —
3555
+ * for instance, prevent it from overflowing the clipping boundary or match the
3556
+ * width of the reference element.
3557
+ * @see https://floating-ui.com/docs/size
3558
+ */
3559
+ const size = size$1;
3560
+
3561
+ /**
3562
+ * Provides data to hide the floating element in applicable situations, such as
3563
+ * when it is not in the same clipping context as the reference element.
3564
+ * @see https://floating-ui.com/docs/hide
3565
+ */
3566
+ const hide = hide$1;
3567
+
3568
+ /**
3569
+ * Provides data to position an inner element of the floating element so that it
3570
+ * appears centered to the reference element.
3571
+ * @see https://floating-ui.com/docs/arrow
3572
+ */
3573
+ const arrow = arrow$1;
3574
+
3575
+ /**
3576
+ * Computes the `x` and `y` coordinates that will place the floating element
3577
+ * next to a given reference element.
3578
+ */
3579
+ const computePosition = (reference, floating, options) => {
3580
+ // This caches the expensive `getClippingElementAncestors` function so that
3581
+ // multiple lifecycle resets re-use the same result. It only lives for a
3582
+ // single call. If other functions become expensive, we can add them as well.
3583
+ const cache = new Map();
3584
+ const mergedOptions = {
3585
+ platform,
3586
+ ...options
3587
+ };
3588
+ const platformWithCache = {
3589
+ ...mergedOptions.platform,
3590
+ _c: cache
3591
+ };
3592
+ return computePosition$1(reference, floating, {
3593
+ ...mergedOptions,
3594
+ platform: platformWithCache
3595
+ });
3596
+ };
3597
+
3598
+ function debounce(func, debounceMs, { signal, edges } = {}) {
3599
+ let pendingThis = undefined;
3600
+ let pendingArgs = null;
3601
+ const leading = edges != null && edges.includes('leading');
3602
+ const trailing = edges == null || edges.includes('trailing');
3603
+ const invoke = () => {
3604
+ if (pendingArgs !== null) {
3605
+ func.apply(pendingThis, pendingArgs);
3606
+ pendingThis = undefined;
3607
+ pendingArgs = null;
3608
+ }
3609
+ };
3610
+ const onTimerEnd = () => {
3611
+ if (trailing) {
3612
+ invoke();
3613
+ }
3614
+ cancel();
3615
+ };
3616
+ let timeoutId = null;
3617
+ const schedule = () => {
3618
+ if (timeoutId != null) {
3619
+ clearTimeout(timeoutId);
3620
+ }
3621
+ timeoutId = setTimeout(() => {
3622
+ timeoutId = null;
3623
+ onTimerEnd();
3624
+ }, debounceMs);
3625
+ };
3626
+ const cancelTimer = () => {
3627
+ if (timeoutId !== null) {
3628
+ clearTimeout(timeoutId);
3629
+ timeoutId = null;
3630
+ }
3631
+ };
3632
+ const cancel = () => {
3633
+ cancelTimer();
3634
+ pendingThis = undefined;
3635
+ pendingArgs = null;
3636
+ };
3637
+ const flush = () => {
3638
+ cancelTimer();
3639
+ invoke();
3640
+ };
3641
+ const debounced = function (...args) {
3642
+ if (signal?.aborted) {
3643
+ return;
3644
+ }
3645
+ pendingThis = this;
3646
+ pendingArgs = args;
3647
+ const isFirstCall = timeoutId == null;
3648
+ schedule();
3649
+ if (leading && isFirstCall) {
3650
+ invoke();
3651
+ }
3652
+ };
3653
+ debounced.schedule = schedule;
3654
+ debounced.cancel = cancel;
3655
+ debounced.flush = flush;
3656
+ signal?.addEventListener('abort', cancel, { once: true });
3657
+ return debounced;
3658
+ }
3659
+
3660
+ export { computePosition as a, size as b, createFocusTrap as c, arrow as d, autoUpdate as e, flip as f, clamp$1 as g, hide as h, debounce as i, maxBy as j, flattenObject as k, minBy as m, offset as o, round$1 as r, shift as s, toMerged as t };