@jobber/components 6.118.2 → 6.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/Autocomplete/index.cjs +11 -10
  2. package/dist/Autocomplete/index.mjs +2 -1
  3. package/dist/Card/index.cjs +3 -1
  4. package/dist/Card/index.mjs +3 -1
  5. package/dist/Chip/index.cjs +2 -1
  6. package/dist/Chip/index.mjs +2 -1
  7. package/dist/Chips/InternalChipDismissible/hooks/index.cjs +2 -1
  8. package/dist/Chips/InternalChipDismissible/hooks/index.mjs +2 -1
  9. package/dist/Chips/InternalChipDismissible/index.cjs +2 -1
  10. package/dist/Chips/InternalChipDismissible/index.mjs +2 -1
  11. package/dist/Chips/index.cjs +2 -1
  12. package/dist/Chips/index.mjs +2 -1
  13. package/dist/Combobox/components/ComboboxActivator/index.cjs +2 -1
  14. package/dist/Combobox/components/ComboboxActivator/index.mjs +2 -1
  15. package/dist/Combobox/components/ComboboxContent/index.cjs +2 -1
  16. package/dist/Combobox/components/ComboboxContent/index.mjs +2 -1
  17. package/dist/Combobox/components/ComboboxTrigger/index.cjs +2 -1
  18. package/dist/Combobox/components/ComboboxTrigger/index.mjs +2 -1
  19. package/dist/Combobox/index.cjs +2 -1
  20. package/dist/Combobox/index.mjs +2 -1
  21. package/dist/ComboboxContent-cjs.js +5 -4
  22. package/dist/ComboboxContent-es.js +2 -1
  23. package/dist/ConfirmationModal/index.cjs +1 -0
  24. package/dist/ConfirmationModal/index.mjs +1 -0
  25. package/dist/Countdown/index.cjs +1 -1
  26. package/dist/Countdown/index.mjs +1 -1
  27. package/dist/Countdown-cjs.js +1 -1
  28. package/dist/Countdown-es.js +1 -1
  29. package/dist/DataDump/index.cjs +3 -1
  30. package/dist/DataDump/index.mjs +3 -1
  31. package/dist/DataList/components/DataListActions/index.cjs +2 -1
  32. package/dist/DataList/components/DataListActions/index.mjs +2 -1
  33. package/dist/DataList/components/DataListBulkActions/index.cjs +2 -1
  34. package/dist/DataList/components/DataListBulkActions/index.mjs +2 -1
  35. package/dist/DataList/components/DataListFilters/components/DataListSort/index.cjs +2 -1
  36. package/dist/DataList/components/DataListFilters/components/DataListSort/index.mjs +2 -1
  37. package/dist/DataList/components/DataListFilters/index.cjs +2 -1
  38. package/dist/DataList/components/DataListFilters/index.mjs +2 -1
  39. package/dist/DataList/components/DataListHeader/index.cjs +2 -1
  40. package/dist/DataList/components/DataListHeader/index.mjs +2 -1
  41. package/dist/DataList/components/DataListItem/index.cjs +2 -1
  42. package/dist/DataList/components/DataListItem/index.mjs +2 -1
  43. package/dist/DataList/components/DataListItemActions/index.cjs +2 -1
  44. package/dist/DataList/components/DataListItemActions/index.mjs +2 -1
  45. package/dist/DataList/components/DataListItemActionsOverflow/index.cjs +2 -1
  46. package/dist/DataList/components/DataListItemActionsOverflow/index.mjs +2 -1
  47. package/dist/DataList/components/DataListItems/index.cjs +2 -1
  48. package/dist/DataList/components/DataListItems/index.mjs +2 -1
  49. package/dist/DataList/components/DataListLayout/index.cjs +2 -1
  50. package/dist/DataList/components/DataListLayout/index.mjs +2 -1
  51. package/dist/DataList/components/DataListLayoutActions/index.cjs +2 -1
  52. package/dist/DataList/components/DataListLayoutActions/index.mjs +2 -1
  53. package/dist/DataList/index.cjs +2 -1
  54. package/dist/DataList/index.mjs +2 -1
  55. package/dist/DatePicker/index.cjs +2 -1
  56. package/dist/DatePicker/index.mjs +2 -1
  57. package/dist/DatePicker-cjs.js +5 -4
  58. package/dist/DatePicker-es.js +2 -1
  59. package/dist/FormatFile/index.cjs +1 -0
  60. package/dist/FormatFile/index.mjs +1 -0
  61. package/dist/Gallery/index.cjs +1 -0
  62. package/dist/Gallery/index.mjs +1 -0
  63. package/dist/InputAvatar/index.cjs +1 -1
  64. package/dist/InputAvatar/index.mjs +1 -1
  65. package/dist/InputDate/index.cjs +2 -1
  66. package/dist/InputDate/index.mjs +2 -1
  67. package/dist/InputFile/index.cjs +1 -1
  68. package/dist/InputFile/index.mjs +1 -1
  69. package/dist/InputFile-cjs.js +1 -1
  70. package/dist/InputFile-es.js +1 -1
  71. package/dist/Menu/index.cjs +3 -1
  72. package/dist/Menu/index.mjs +3 -1
  73. package/dist/Menu-cjs.js +7 -194
  74. package/dist/Menu-es.js +3 -190
  75. package/dist/Modal/index.cjs +1 -0
  76. package/dist/Modal/index.mjs +2 -1
  77. package/dist/Page/index.cjs +2 -0
  78. package/dist/Page/index.mjs +2 -0
  79. package/dist/Popover/index.cjs +2 -1
  80. package/dist/Popover/index.mjs +2 -1
  81. package/dist/Popover-cjs.js +8 -7
  82. package/dist/Popover-es.js +2 -1
  83. package/dist/Tooltip/index.cjs +2 -1
  84. package/dist/Tooltip/index.mjs +2 -1
  85. package/dist/Tooltip-cjs.js +7 -6
  86. package/dist/Tooltip-es.js +2 -1
  87. package/dist/floating-ui.react-cjs.js +218 -3104
  88. package/dist/floating-ui.react-dom-cjs.js +3000 -0
  89. package/dist/floating-ui.react-dom-es.js +2946 -0
  90. package/dist/floating-ui.react-es.js +177 -3054
  91. package/dist/index-cjs.js +166 -1161
  92. package/dist/index-cjs2.js +1189 -0
  93. package/dist/index-es.js +166 -1160
  94. package/dist/index-es2.js +1186 -0
  95. package/dist/index.cjs +4 -2
  96. package/dist/index.mjs +4 -2
  97. package/dist/primitives/index.cjs +2 -0
  98. package/dist/primitives/index.d.ts +7 -0
  99. package/dist/primitives/index.mjs +1 -0
  100. package/dist/unstyledPrimitives/index.cjs +10446 -0
  101. package/dist/unstyledPrimitives/index.d.ts +18 -0
  102. package/dist/unstyledPrimitives/index.mjs +10425 -0
  103. package/dist/useScrollToActive-cjs.js +5 -4
  104. package/dist/useScrollToActive-es.js +2 -1
  105. package/package.json +13 -2
  106. package/primitives.d.ts +1 -0
  107. package/primitives.js +17 -0
  108. package/unstyledPrimitives.d.ts +1 -0
  109. package/unstyledPrimitives.js +17 -0
@@ -0,0 +1,2946 @@
1
+ import * as React from 'react';
2
+ import { useLayoutEffect } from 'react';
3
+ import * as ReactDOM from 'react-dom';
4
+
5
+ function hasWindow() {
6
+ return typeof window !== 'undefined';
7
+ }
8
+ function getNodeName(node) {
9
+ if (isNode(node)) {
10
+ return (node.nodeName || '').toLowerCase();
11
+ }
12
+ // Mocked nodes in testing environments may not be instances of Node. By
13
+ // returning `#document` an infinite loop won't occur.
14
+ // https://github.com/floating-ui/floating-ui/issues/2317
15
+ return '#document';
16
+ }
17
+ function getWindow(node) {
18
+ var _node$ownerDocument;
19
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
20
+ }
21
+ function getDocumentElement(node) {
22
+ var _ref;
23
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
24
+ }
25
+ function isNode(value) {
26
+ if (!hasWindow()) {
27
+ return false;
28
+ }
29
+ return value instanceof Node || value instanceof getWindow(value).Node;
30
+ }
31
+ function isElement(value) {
32
+ if (!hasWindow()) {
33
+ return false;
34
+ }
35
+ return value instanceof Element || value instanceof getWindow(value).Element;
36
+ }
37
+ function isHTMLElement(value) {
38
+ if (!hasWindow()) {
39
+ return false;
40
+ }
41
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
42
+ }
43
+ function isShadowRoot(value) {
44
+ if (!hasWindow() || typeof ShadowRoot === 'undefined') {
45
+ return false;
46
+ }
47
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
48
+ }
49
+ function isOverflowElement(element) {
50
+ const {
51
+ overflow,
52
+ overflowX,
53
+ overflowY,
54
+ display
55
+ } = getComputedStyle$1(element);
56
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== 'inline' && display !== 'contents';
57
+ }
58
+ function isTableElement(element) {
59
+ return /^(table|td|th)$/.test(getNodeName(element));
60
+ }
61
+ function isTopLayer(element) {
62
+ try {
63
+ if (element.matches(':popover-open')) {
64
+ return true;
65
+ }
66
+ } catch (_e) {
67
+ // no-op
68
+ }
69
+ try {
70
+ return element.matches(':modal');
71
+ } catch (_e) {
72
+ return false;
73
+ }
74
+ }
75
+ const willChangeRe = /transform|translate|scale|rotate|perspective|filter/;
76
+ const containRe = /paint|layout|strict|content/;
77
+ const isNotNone = value => !!value && value !== 'none';
78
+ let isWebKitValue;
79
+ function isContainingBlock(elementOrCss) {
80
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
81
+
82
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
83
+ // https://drafts.csswg.org/css-transforms-2/#individual-transforms
84
+ return isNotNone(css.transform) || isNotNone(css.translate) || isNotNone(css.scale) || isNotNone(css.rotate) || isNotNone(css.perspective) || !isWebKit() && (isNotNone(css.backdropFilter) || isNotNone(css.filter)) || willChangeRe.test(css.willChange || '') || containRe.test(css.contain || '');
85
+ }
86
+ function getContainingBlock(element) {
87
+ let currentNode = getParentNode(element);
88
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
89
+ if (isContainingBlock(currentNode)) {
90
+ return currentNode;
91
+ } else if (isTopLayer(currentNode)) {
92
+ return null;
93
+ }
94
+ currentNode = getParentNode(currentNode);
95
+ }
96
+ return null;
97
+ }
98
+ function isWebKit() {
99
+ if (isWebKitValue == null) {
100
+ isWebKitValue = typeof CSS !== 'undefined' && CSS.supports && CSS.supports('-webkit-backdrop-filter', 'none');
101
+ }
102
+ return isWebKitValue;
103
+ }
104
+ function isLastTraversableNode(node) {
105
+ return /^(html|body|#document)$/.test(getNodeName(node));
106
+ }
107
+ function getComputedStyle$1(element) {
108
+ return getWindow(element).getComputedStyle(element);
109
+ }
110
+ function getNodeScroll(element) {
111
+ if (isElement(element)) {
112
+ return {
113
+ scrollLeft: element.scrollLeft,
114
+ scrollTop: element.scrollTop
115
+ };
116
+ }
117
+ return {
118
+ scrollLeft: element.scrollX,
119
+ scrollTop: element.scrollY
120
+ };
121
+ }
122
+ function getParentNode(node) {
123
+ if (getNodeName(node) === 'html') {
124
+ return node;
125
+ }
126
+ const result =
127
+ // Step into the shadow DOM of the parent of a slotted node.
128
+ node.assignedSlot ||
129
+ // DOM Element detected.
130
+ node.parentNode ||
131
+ // ShadowRoot detected.
132
+ isShadowRoot(node) && node.host ||
133
+ // Fallback.
134
+ getDocumentElement(node);
135
+ return isShadowRoot(result) ? result.host : result;
136
+ }
137
+ function getNearestOverflowAncestor(node) {
138
+ const parentNode = getParentNode(node);
139
+ if (isLastTraversableNode(parentNode)) {
140
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
141
+ }
142
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
143
+ return parentNode;
144
+ }
145
+ return getNearestOverflowAncestor(parentNode);
146
+ }
147
+ function getOverflowAncestors(node, list, traverseIframes) {
148
+ var _node$ownerDocument2;
149
+ if (list === void 0) {
150
+ list = [];
151
+ }
152
+ if (traverseIframes === void 0) {
153
+ traverseIframes = true;
154
+ }
155
+ const scrollableAncestor = getNearestOverflowAncestor(node);
156
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
157
+ const win = getWindow(scrollableAncestor);
158
+ if (isBody) {
159
+ const frameElement = getFrameElement(win);
160
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
161
+ } else {
162
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
163
+ }
164
+ }
165
+ function getFrameElement(win) {
166
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
167
+ }
168
+
169
+ /**
170
+ * Custom positioning reference element.
171
+ * @see https://floating-ui.com/docs/virtual-elements
172
+ */
173
+
174
+ const sides = ['top', 'right', 'bottom', 'left'];
175
+ const alignments = ['start', 'end'];
176
+ const placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []);
177
+ const min = Math.min;
178
+ const max = Math.max;
179
+ const round = Math.round;
180
+ const floor = Math.floor;
181
+ const createCoords = v => ({
182
+ x: v,
183
+ y: v
184
+ });
185
+ const oppositeSideMap = {
186
+ left: 'right',
187
+ right: 'left',
188
+ bottom: 'top',
189
+ top: 'bottom'
190
+ };
191
+ function clamp(start, value, end) {
192
+ return max(start, min(value, end));
193
+ }
194
+ function evaluate(value, param) {
195
+ return typeof value === 'function' ? value(param) : value;
196
+ }
197
+ function getSide(placement) {
198
+ return placement.split('-')[0];
199
+ }
200
+ function getAlignment(placement) {
201
+ return placement.split('-')[1];
202
+ }
203
+ function getOppositeAxis(axis) {
204
+ return axis === 'x' ? 'y' : 'x';
205
+ }
206
+ function getAxisLength(axis) {
207
+ return axis === 'y' ? 'height' : 'width';
208
+ }
209
+ function getSideAxis(placement) {
210
+ const firstChar = placement[0];
211
+ return firstChar === 't' || firstChar === 'b' ? 'y' : 'x';
212
+ }
213
+ function getAlignmentAxis(placement) {
214
+ return getOppositeAxis(getSideAxis(placement));
215
+ }
216
+ function getAlignmentSides(placement, rects, rtl) {
217
+ if (rtl === void 0) {
218
+ rtl = false;
219
+ }
220
+ const alignment = getAlignment(placement);
221
+ const alignmentAxis = getAlignmentAxis(placement);
222
+ const length = getAxisLength(alignmentAxis);
223
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
224
+ if (rects.reference[length] > rects.floating[length]) {
225
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
226
+ }
227
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
228
+ }
229
+ function getExpandedPlacements(placement) {
230
+ const oppositePlacement = getOppositePlacement(placement);
231
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
232
+ }
233
+ function getOppositeAlignmentPlacement(placement) {
234
+ return placement.includes('start') ? placement.replace('start', 'end') : placement.replace('end', 'start');
235
+ }
236
+ const lrPlacement = ['left', 'right'];
237
+ const rlPlacement = ['right', 'left'];
238
+ const tbPlacement = ['top', 'bottom'];
239
+ const btPlacement = ['bottom', 'top'];
240
+ function getSideList(side, isStart, rtl) {
241
+ switch (side) {
242
+ case 'top':
243
+ case 'bottom':
244
+ if (rtl) return isStart ? rlPlacement : lrPlacement;
245
+ return isStart ? lrPlacement : rlPlacement;
246
+ case 'left':
247
+ case 'right':
248
+ return isStart ? tbPlacement : btPlacement;
249
+ default:
250
+ return [];
251
+ }
252
+ }
253
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
254
+ const alignment = getAlignment(placement);
255
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
256
+ if (alignment) {
257
+ list = list.map(side => side + "-" + alignment);
258
+ if (flipAlignment) {
259
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
260
+ }
261
+ }
262
+ return list;
263
+ }
264
+ function getOppositePlacement(placement) {
265
+ const side = getSide(placement);
266
+ return oppositeSideMap[side] + placement.slice(side.length);
267
+ }
268
+ function expandPaddingObject(padding) {
269
+ return {
270
+ top: 0,
271
+ right: 0,
272
+ bottom: 0,
273
+ left: 0,
274
+ ...padding
275
+ };
276
+ }
277
+ function getPaddingObject(padding) {
278
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
279
+ top: padding,
280
+ right: padding,
281
+ bottom: padding,
282
+ left: padding
283
+ };
284
+ }
285
+ function rectToClientRect(rect) {
286
+ const {
287
+ x,
288
+ y,
289
+ width,
290
+ height
291
+ } = rect;
292
+ return {
293
+ width,
294
+ height,
295
+ top: y,
296
+ left: x,
297
+ right: x + width,
298
+ bottom: y + height,
299
+ x,
300
+ y
301
+ };
302
+ }
303
+
304
+ /*!
305
+ * tabbable 6.4.0
306
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
307
+ */
308
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
309
+ // `:not([inert], [inert] *)` (Feb 2023)
310
+ var candidateSelectors = ['input:not([inert]):not([inert] *)', 'select:not([inert]):not([inert] *)', 'textarea:not([inert]):not([inert] *)', 'a[href]:not([inert]):not([inert] *)', 'button:not([inert]):not([inert] *)', '[tabindex]:not(slot):not([inert]):not([inert] *)', 'audio[controls]:not([inert]):not([inert] *)', 'video[controls]:not([inert]):not([inert] *)', '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', 'details>summary:first-of-type:not([inert]):not([inert] *)', 'details:not([inert]):not([inert] *)'];
311
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
312
+ var NoElement = typeof Element === 'undefined';
313
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
314
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
315
+ var _element$getRootNode;
316
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
317
+ } : function (element) {
318
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
319
+ };
320
+
321
+ /**
322
+ * Determines if a node is inert or in an inert ancestor.
323
+ * @param {Node} [node]
324
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
325
+ * see if any of them are inert. If false, only `node` itself is considered.
326
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
327
+ * False if `node` is falsy.
328
+ */
329
+ var _isInert = function isInert(node, lookUp) {
330
+ var _node$getAttribute;
331
+ if (lookUp === void 0) {
332
+ lookUp = true;
333
+ }
334
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
335
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
336
+ // if it's `null` (not specified) or 'false', it's an active element
337
+ 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');
338
+ var inert = inertAtt === '' || inertAtt === 'true';
339
+
340
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
341
+ // if it weren't for `matches()` not being a function on shadow roots; the following
342
+ // code works for any kind of node
343
+ var result = inert || lookUp && node && (
344
+ // closest does not exist on shadow roots, so we fall back to a manual
345
+ // lookup upward, in case it is not defined.
346
+ typeof node.closest === 'function' ? node.closest('[inert]') : _isInert(node.parentNode));
347
+ return result;
348
+ };
349
+
350
+ /**
351
+ * Determines if a node's content is editable.
352
+ * @param {Element} [node]
353
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
354
+ */
355
+ var isContentEditable = function isContentEditable(node) {
356
+ var _node$getAttribute2;
357
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
358
+ // to use the attribute directly to check for this, which can either be empty or 'true';
359
+ // if it's `null` (not specified) or 'false', it's a non-editable element
360
+ 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');
361
+ return attValue === '' || attValue === 'true';
362
+ };
363
+
364
+ /**
365
+ * @param {Element} el container to check in
366
+ * @param {boolean} includeContainer add container to check
367
+ * @param {(node: Element) => boolean} filter filter candidates
368
+ * @returns {Element[]}
369
+ */
370
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
371
+ // even if `includeContainer=false`, we still have to check it for inertness because
372
+ // if it's inert (either by itself or via its parent), then all its children are inert
373
+ if (_isInert(el)) {
374
+ return [];
375
+ }
376
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
377
+ if (includeContainer && matches.call(el, candidateSelector)) {
378
+ candidates.unshift(el);
379
+ }
380
+ candidates = candidates.filter(filter);
381
+ return candidates;
382
+ };
383
+
384
+ /**
385
+ * @callback GetShadowRoot
386
+ * @param {Element} element to check for shadow root
387
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
388
+ */
389
+
390
+ /**
391
+ * @callback ShadowRootFilter
392
+ * @param {Element} shadowHostNode the element which contains shadow content
393
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
394
+ */
395
+
396
+ /**
397
+ * @typedef {Object} CandidateScope
398
+ * @property {Element} scopeParent contains inner candidates
399
+ * @property {Element[]} candidates list of candidates found in the scope parent
400
+ */
401
+
402
+ /**
403
+ * @typedef {Object} IterativeOptions
404
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
405
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
406
+ * or a boolean stating if it has an undisclosed shadow root
407
+ * @property {(node: Element) => boolean} filter filter candidates
408
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
409
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
410
+ */
411
+
412
+ /**
413
+ * @param {Element[]} elements list of element containers to match candidates from
414
+ * @param {boolean} includeContainer add container list to check
415
+ * @param {IterativeOptions} options
416
+ * @returns {Array.<Element|CandidateScope>}
417
+ */
418
+ var _getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
419
+ var candidates = [];
420
+ var elementsToCheck = Array.from(elements);
421
+ while (elementsToCheck.length) {
422
+ var element = elementsToCheck.shift();
423
+ if (_isInert(element, false)) {
424
+ // no need to look up since we're drilling down
425
+ // anything inside this container will also be inert
426
+ continue;
427
+ }
428
+ if (element.tagName === 'SLOT') {
429
+ // add shadow dom slot scope (slot itself cannot be focusable)
430
+ var assigned = element.assignedElements();
431
+ var content = assigned.length ? assigned : element.children;
432
+ var nestedCandidates = _getCandidatesIteratively(content, true, options);
433
+ if (options.flatten) {
434
+ candidates.push.apply(candidates, nestedCandidates);
435
+ } else {
436
+ candidates.push({
437
+ scopeParent: element,
438
+ candidates: nestedCandidates
439
+ });
440
+ }
441
+ } else {
442
+ // check candidate element
443
+ var validCandidate = matches.call(element, candidateSelector);
444
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
445
+ candidates.push(element);
446
+ }
447
+
448
+ // iterate over shadow content if possible
449
+ var shadowRoot = element.shadowRoot ||
450
+ // check for an undisclosed shadow
451
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
452
+
453
+ // no inert look up because we're already drilling down and checking for inertness
454
+ // on the way down, so all containers to this root node should have already been
455
+ // vetted as non-inert
456
+ var validShadowRoot = !_isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
457
+ if (shadowRoot && validShadowRoot) {
458
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
459
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
460
+ // child candidates found because they're likely slotted elements (elements that are
461
+ // children of the web component element (which has the shadow), in the light dom, but
462
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
463
+ // _after_ we return from this recursive call
464
+ var _nestedCandidates = _getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
465
+ if (options.flatten) {
466
+ candidates.push.apply(candidates, _nestedCandidates);
467
+ } else {
468
+ candidates.push({
469
+ scopeParent: element,
470
+ candidates: _nestedCandidates
471
+ });
472
+ }
473
+ } else {
474
+ // there's not shadow so just dig into the element's (light dom) children
475
+ // __without__ giving the element special scope treatment
476
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
477
+ }
478
+ }
479
+ }
480
+ return candidates;
481
+ };
482
+
483
+ /**
484
+ * @private
485
+ * Determines if the node has an explicitly specified `tabindex` attribute.
486
+ * @param {HTMLElement} node
487
+ * @returns {boolean} True if so; false if not.
488
+ */
489
+ var hasTabIndex = function hasTabIndex(node) {
490
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
491
+ };
492
+
493
+ /**
494
+ * Determine the tab index of a given node.
495
+ * @param {HTMLElement} node
496
+ * @returns {number} Tab order (negative, 0, or positive number).
497
+ * @throws {Error} If `node` is falsy.
498
+ */
499
+ var getTabIndex = function getTabIndex(node) {
500
+ if (!node) {
501
+ throw new Error('No node provided');
502
+ }
503
+ if (node.tabIndex < 0) {
504
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
505
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
506
+ // yet they are still part of the regular tab order; in FF, they get a default
507
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
508
+ // order, consider their tab index to be 0.
509
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
510
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
511
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
512
+ return 0;
513
+ }
514
+ }
515
+ return node.tabIndex;
516
+ };
517
+
518
+ /**
519
+ * Determine the tab index of a given node __for sort order purposes__.
520
+ * @param {HTMLElement} node
521
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
522
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
523
+ * inserted into the correct sort position.
524
+ * @returns {number} Tab order (negative, 0, or positive number).
525
+ */
526
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
527
+ var tabIndex = getTabIndex(node);
528
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
529
+ return 0;
530
+ }
531
+ return tabIndex;
532
+ };
533
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
534
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
535
+ };
536
+ var isInput = function isInput(node) {
537
+ return node.tagName === 'INPUT';
538
+ };
539
+ var isHiddenInput = function isHiddenInput(node) {
540
+ return isInput(node) && node.type === 'hidden';
541
+ };
542
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
543
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
544
+ return child.tagName === 'SUMMARY';
545
+ });
546
+ return r;
547
+ };
548
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
549
+ for (var i = 0; i < nodes.length; i++) {
550
+ if (nodes[i].checked && nodes[i].form === form) {
551
+ return nodes[i];
552
+ }
553
+ }
554
+ };
555
+ var isTabbableRadio = function isTabbableRadio(node) {
556
+ if (!node.name) {
557
+ return true;
558
+ }
559
+ var radioScope = node.form || getRootNode(node);
560
+ var queryRadios = function queryRadios(name) {
561
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
562
+ };
563
+ var radioSet;
564
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
565
+ radioSet = queryRadios(window.CSS.escape(node.name));
566
+ } else {
567
+ try {
568
+ radioSet = queryRadios(node.name);
569
+ } catch (err) {
570
+ // eslint-disable-next-line no-console
571
+ 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);
572
+ return false;
573
+ }
574
+ }
575
+ var checked = getCheckedRadio(radioSet, node.form);
576
+ return !checked || checked === node;
577
+ };
578
+ var isRadio = function isRadio(node) {
579
+ return isInput(node) && node.type === 'radio';
580
+ };
581
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
582
+ return isRadio(node) && !isTabbableRadio(node);
583
+ };
584
+
585
+ // determines if a node is ultimately attached to the window's document
586
+ var isNodeAttached = function isNodeAttached(node) {
587
+ var _nodeRoot;
588
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
589
+ // (but NOT _the_ document; see second 'If' comment below for more).
590
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
591
+ // is attached, and the one we need to check if it's in the document or not (because the
592
+ // shadow, and all nodes it contains, is never considered in the document since shadows
593
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
594
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
595
+ // visibility, including all the nodes it contains). The host could be any normal node,
596
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
597
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
598
+ // tested).
599
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
600
+ // that is attached (or find none) because the node might be in nested shadows...
601
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
602
+ // document (per the docs) and while it's a Document-type object, that document does not
603
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
604
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
605
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
606
+ // node is actually detached.
607
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
608
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
609
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
610
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
611
+ var nodeRoot = node && getRootNode(node);
612
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
613
+
614
+ // in some cases, a detached node will return itself as the root instead of a document or
615
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
616
+ var attached = false;
617
+ if (nodeRoot && nodeRoot !== node) {
618
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
619
+ 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));
620
+ while (!attached && nodeRootHost) {
621
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
622
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
623
+ // which means we need to get the host's host and check if that parent host is contained
624
+ // in (i.e. attached to) the document
625
+ nodeRoot = getRootNode(nodeRootHost);
626
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
627
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
628
+ }
629
+ }
630
+ return attached;
631
+ };
632
+ var isZeroArea = function isZeroArea(node) {
633
+ var _node$getBoundingClie = node.getBoundingClientRect(),
634
+ width = _node$getBoundingClie.width,
635
+ height = _node$getBoundingClie.height;
636
+ return width === 0 && height === 0;
637
+ };
638
+ var isHidden = function isHidden(node, _ref) {
639
+ var displayCheck = _ref.displayCheck,
640
+ getShadowRoot = _ref.getShadowRoot;
641
+ if (displayCheck === 'full-native') {
642
+ if ('checkVisibility' in node) {
643
+ // Chrome >= 105, Edge >= 105, Firefox >= 106, Safari >= 17.4
644
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility#browser_compatibility
645
+ var visible = node.checkVisibility({
646
+ // Checking opacity might be desirable for some use cases, but natively,
647
+ // opacity zero elements _are_ focusable and tabbable.
648
+ checkOpacity: false,
649
+ opacityProperty: false,
650
+ contentVisibilityAuto: true,
651
+ visibilityProperty: true,
652
+ // This is an alias for `visibilityProperty`. Contemporary browsers
653
+ // support both. However, this alias has wider browser support (Chrome
654
+ // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
655
+ // we include it anyway.
656
+ checkVisibilityCSS: true
657
+ });
658
+ return !visible;
659
+ }
660
+ // Fall through to manual visibility checks
661
+ }
662
+
663
+ // NOTE: visibility will be `undefined` if node is detached from the document
664
+ // (see notes about this further down), which means we will consider it visible
665
+ // (this is legacy behavior from a very long way back)
666
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
667
+ // _visibility_ check, not a _display_ check
668
+ if (getComputedStyle(node).visibility === 'hidden') {
669
+ return true;
670
+ }
671
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
672
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
673
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
674
+ return true;
675
+ }
676
+ if (!displayCheck || displayCheck === 'full' ||
677
+ // full-native can run this branch when it falls through in case
678
+ // Element#checkVisibility is unsupported
679
+ displayCheck === 'full-native' || displayCheck === 'legacy-full') {
680
+ if (typeof getShadowRoot === 'function') {
681
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
682
+ // 'non-zero-area' fallback
683
+ var originalNode = node;
684
+ while (node) {
685
+ var parentElement = node.parentElement;
686
+ var rootNode = getRootNode(node);
687
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
688
+ ) {
689
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
690
+ // fall back to a non-zero-area test
691
+ return isZeroArea(node);
692
+ } else if (node.assignedSlot) {
693
+ // iterate up slot
694
+ node = node.assignedSlot;
695
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
696
+ // cross shadow boundary
697
+ node = rootNode.host;
698
+ } else {
699
+ // iterate up normal dom
700
+ node = parentElement;
701
+ }
702
+ }
703
+ node = originalNode;
704
+ }
705
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
706
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
707
+ // it might be a falsy value, which means shadow DOM support is disabled
708
+
709
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
710
+ // now we can just test to see if it would normally be visible or not, provided it's
711
+ // attached to the main document.
712
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
713
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
714
+
715
+ if (isNodeAttached(node)) {
716
+ // this works wherever the node is: if there's at least one client rect, it's
717
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
718
+ // node itself is hidden in place of its contents; and there's no need to search
719
+ // up the hierarchy either
720
+ return !node.getClientRects().length;
721
+ }
722
+
723
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
724
+ // API will __always__ return zero rects (this can happen, for example, if React
725
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
726
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
727
+ //
728
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
729
+ // because styles are only computed for nodes that are in the document.
730
+ //
731
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
732
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
733
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
734
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
735
+ // considering __everything__ to be visible because of the innability to determine styles.
736
+ //
737
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
738
+ // nodes as visible with the 'none' fallback.__
739
+ if (displayCheck !== 'legacy-full') {
740
+ return true; // hidden
741
+ }
742
+ // else, fallback to 'none' mode and consider the node visible
743
+ } else if (displayCheck === 'non-zero-area') {
744
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
745
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
746
+ // client rect, we don't special-case for whether the node is attached or not. In
747
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
748
+ // times, and that includes attached or not.
749
+ return isZeroArea(node);
750
+ }
751
+
752
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
753
+ // it's visible
754
+ return false;
755
+ };
756
+
757
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
758
+ // unless they are in the _first_ <legend> element of the top-most disabled
759
+ // fieldset
760
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
761
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
762
+ var parentNode = node.parentElement;
763
+ // check if `node` is contained in a disabled <fieldset>
764
+ while (parentNode) {
765
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
766
+ // look for the first <legend> among the children of the disabled <fieldset>
767
+ for (var i = 0; i < parentNode.children.length; i++) {
768
+ var child = parentNode.children.item(i);
769
+ // when the first <legend> (in document order) is found
770
+ if (child.tagName === 'LEGEND') {
771
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
772
+ // return whether `node` is a descendant of its first <legend>
773
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
774
+ }
775
+ }
776
+ // the disabled <fieldset> containing `node` has no <legend>
777
+ return true;
778
+ }
779
+ parentNode = parentNode.parentElement;
780
+ }
781
+ }
782
+
783
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
784
+ // enabled/disabled state
785
+ return false;
786
+ };
787
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
788
+ if (node.disabled || isHiddenInput(node) || isHidden(node, options) ||
789
+ // For a details element with a summary, the summary element gets the focus
790
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
791
+ return false;
792
+ }
793
+ return true;
794
+ };
795
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
796
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
797
+ return false;
798
+ }
799
+ return true;
800
+ };
801
+ var isShadowRootTabbable = function isShadowRootTabbable(shadowHostNode) {
802
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
803
+ if (isNaN(tabIndex) || tabIndex >= 0) {
804
+ return true;
805
+ }
806
+ // If a custom element has an explicit negative tabindex,
807
+ // browsers will not allow tab targeting said element's children.
808
+ return false;
809
+ };
810
+
811
+ /**
812
+ * @param {Array.<Element|CandidateScope>} candidates
813
+ * @returns Element[]
814
+ */
815
+ var _sortByOrder = function sortByOrder(candidates) {
816
+ var regularTabbables = [];
817
+ var orderedTabbables = [];
818
+ candidates.forEach(function (item, i) {
819
+ var isScope = !!item.scopeParent;
820
+ var element = isScope ? item.scopeParent : item;
821
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
822
+ var elements = isScope ? _sortByOrder(item.candidates) : element;
823
+ if (candidateTabindex === 0) {
824
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
825
+ } else {
826
+ orderedTabbables.push({
827
+ documentOrder: i,
828
+ tabIndex: candidateTabindex,
829
+ item: item,
830
+ isScope: isScope,
831
+ content: elements
832
+ });
833
+ }
834
+ });
835
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
836
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
837
+ return acc;
838
+ }, []).concat(regularTabbables);
839
+ };
840
+ var tabbable = function tabbable(container, options) {
841
+ options = options || {};
842
+ var candidates;
843
+ if (options.getShadowRoot) {
844
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
845
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
846
+ flatten: false,
847
+ getShadowRoot: options.getShadowRoot,
848
+ shadowRootFilter: isShadowRootTabbable
849
+ });
850
+ } else {
851
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
852
+ }
853
+ return _sortByOrder(candidates);
854
+ };
855
+ var focusable = function focusable(container, options) {
856
+ options = options || {};
857
+ var candidates;
858
+ if (options.getShadowRoot) {
859
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
860
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
861
+ flatten: true,
862
+ getShadowRoot: options.getShadowRoot
863
+ });
864
+ } else {
865
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
866
+ }
867
+ return candidates;
868
+ };
869
+ var isTabbable = function isTabbable(node, options) {
870
+ options = options || {};
871
+ if (!node) {
872
+ throw new Error('No node provided');
873
+ }
874
+ if (matches.call(node, candidateSelector) === false) {
875
+ return false;
876
+ }
877
+ return isNodeMatchingSelectorTabbable(options, node);
878
+ };
879
+
880
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
881
+ let {
882
+ reference,
883
+ floating
884
+ } = _ref;
885
+ const sideAxis = getSideAxis(placement);
886
+ const alignmentAxis = getAlignmentAxis(placement);
887
+ const alignLength = getAxisLength(alignmentAxis);
888
+ const side = getSide(placement);
889
+ const isVertical = sideAxis === 'y';
890
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
891
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
892
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
893
+ let coords;
894
+ switch (side) {
895
+ case 'top':
896
+ coords = {
897
+ x: commonX,
898
+ y: reference.y - floating.height
899
+ };
900
+ break;
901
+ case 'bottom':
902
+ coords = {
903
+ x: commonX,
904
+ y: reference.y + reference.height
905
+ };
906
+ break;
907
+ case 'right':
908
+ coords = {
909
+ x: reference.x + reference.width,
910
+ y: commonY
911
+ };
912
+ break;
913
+ case 'left':
914
+ coords = {
915
+ x: reference.x - floating.width,
916
+ y: commonY
917
+ };
918
+ break;
919
+ default:
920
+ coords = {
921
+ x: reference.x,
922
+ y: reference.y
923
+ };
924
+ }
925
+ switch (getAlignment(placement)) {
926
+ case 'start':
927
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
928
+ break;
929
+ case 'end':
930
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
931
+ break;
932
+ }
933
+ return coords;
934
+ }
935
+
936
+ /**
937
+ * Resolves with an object of overflow side offsets that determine how much the
938
+ * element is overflowing a given clipping boundary on each side.
939
+ * - positive = overflowing the boundary by that number of pixels
940
+ * - negative = how many pixels left before it will overflow
941
+ * - 0 = lies flush with the boundary
942
+ * @see https://floating-ui.com/docs/detectOverflow
943
+ */
944
+ async function detectOverflow(state, options) {
945
+ var _await$platform$isEle;
946
+ if (options === void 0) {
947
+ options = {};
948
+ }
949
+ const {
950
+ x,
951
+ y,
952
+ platform,
953
+ rects,
954
+ elements,
955
+ strategy
956
+ } = state;
957
+ const {
958
+ boundary = 'clippingAncestors',
959
+ rootBoundary = 'viewport',
960
+ elementContext = 'floating',
961
+ altBoundary = false,
962
+ padding = 0
963
+ } = evaluate(options, state);
964
+ const paddingObject = getPaddingObject(padding);
965
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
966
+ const element = elements[altBoundary ? altContext : elementContext];
967
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
968
+ 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))),
969
+ boundary,
970
+ rootBoundary,
971
+ strategy
972
+ }));
973
+ const rect = elementContext === 'floating' ? {
974
+ x,
975
+ y,
976
+ width: rects.floating.width,
977
+ height: rects.floating.height
978
+ } : rects.reference;
979
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
980
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
981
+ x: 1,
982
+ y: 1
983
+ } : {
984
+ x: 1,
985
+ y: 1
986
+ };
987
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
988
+ elements,
989
+ rect,
990
+ offsetParent,
991
+ strategy
992
+ }) : rect);
993
+ return {
994
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
995
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
996
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
997
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
998
+ };
999
+ }
1000
+
1001
+ // Maximum number of resets that can occur before bailing to avoid infinite reset loops.
1002
+ const MAX_RESET_COUNT = 50;
1003
+
1004
+ /**
1005
+ * Computes the `x` and `y` coordinates that will place the floating element
1006
+ * next to a given reference element.
1007
+ *
1008
+ * This export does not have any `platform` interface logic. You will need to
1009
+ * write one for the platform you are using Floating UI with.
1010
+ */
1011
+ const computePosition$1 = async (reference, floating, config) => {
1012
+ const {
1013
+ placement = 'bottom',
1014
+ strategy = 'absolute',
1015
+ middleware = [],
1016
+ platform
1017
+ } = config;
1018
+ const platformWithDetectOverflow = platform.detectOverflow ? platform : {
1019
+ ...platform,
1020
+ detectOverflow
1021
+ };
1022
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
1023
+ let rects = await platform.getElementRects({
1024
+ reference,
1025
+ floating,
1026
+ strategy
1027
+ });
1028
+ let {
1029
+ x,
1030
+ y
1031
+ } = computeCoordsFromPlacement(rects, placement, rtl);
1032
+ let statefulPlacement = placement;
1033
+ let resetCount = 0;
1034
+ const middlewareData = {};
1035
+ for (let i = 0; i < middleware.length; i++) {
1036
+ const currentMiddleware = middleware[i];
1037
+ if (!currentMiddleware) {
1038
+ continue;
1039
+ }
1040
+ const {
1041
+ name,
1042
+ fn
1043
+ } = currentMiddleware;
1044
+ const {
1045
+ x: nextX,
1046
+ y: nextY,
1047
+ data,
1048
+ reset
1049
+ } = await fn({
1050
+ x,
1051
+ y,
1052
+ initialPlacement: placement,
1053
+ placement: statefulPlacement,
1054
+ strategy,
1055
+ middlewareData,
1056
+ rects,
1057
+ platform: platformWithDetectOverflow,
1058
+ elements: {
1059
+ reference,
1060
+ floating
1061
+ }
1062
+ });
1063
+ x = nextX != null ? nextX : x;
1064
+ y = nextY != null ? nextY : y;
1065
+ middlewareData[name] = {
1066
+ ...middlewareData[name],
1067
+ ...data
1068
+ };
1069
+ if (reset && resetCount < MAX_RESET_COUNT) {
1070
+ resetCount++;
1071
+ if (typeof reset === 'object') {
1072
+ if (reset.placement) {
1073
+ statefulPlacement = reset.placement;
1074
+ }
1075
+ if (reset.rects) {
1076
+ rects = reset.rects === true ? await platform.getElementRects({
1077
+ reference,
1078
+ floating,
1079
+ strategy
1080
+ }) : reset.rects;
1081
+ }
1082
+ ({
1083
+ x,
1084
+ y
1085
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
1086
+ }
1087
+ i = -1;
1088
+ }
1089
+ }
1090
+ return {
1091
+ x,
1092
+ y,
1093
+ placement: statefulPlacement,
1094
+ strategy,
1095
+ middlewareData
1096
+ };
1097
+ };
1098
+
1099
+ /**
1100
+ * Provides data to position an inner element of the floating element so that it
1101
+ * appears centered to the reference element.
1102
+ * @see https://floating-ui.com/docs/arrow
1103
+ */
1104
+ const arrow$3 = options => ({
1105
+ name: 'arrow',
1106
+ options,
1107
+ async fn(state) {
1108
+ const {
1109
+ x,
1110
+ y,
1111
+ placement,
1112
+ rects,
1113
+ platform,
1114
+ elements,
1115
+ middlewareData
1116
+ } = state;
1117
+ // Since `element` is required, we don't Partial<> the type.
1118
+ const {
1119
+ element,
1120
+ padding = 0
1121
+ } = evaluate(options, state) || {};
1122
+ if (element == null) {
1123
+ return {};
1124
+ }
1125
+ const paddingObject = getPaddingObject(padding);
1126
+ const coords = {
1127
+ x,
1128
+ y
1129
+ };
1130
+ const axis = getAlignmentAxis(placement);
1131
+ const length = getAxisLength(axis);
1132
+ const arrowDimensions = await platform.getDimensions(element);
1133
+ const isYAxis = axis === 'y';
1134
+ const minProp = isYAxis ? 'top' : 'left';
1135
+ const maxProp = isYAxis ? 'bottom' : 'right';
1136
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
1137
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
1138
+ const startDiff = coords[axis] - rects.reference[axis];
1139
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
1140
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
1141
+
1142
+ // DOM platform can return `window` as the `offsetParent`.
1143
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
1144
+ clientSize = elements.floating[clientProp] || rects.floating[length];
1145
+ }
1146
+ const centerToReference = endDiff / 2 - startDiff / 2;
1147
+
1148
+ // If the padding is large enough that it causes the arrow to no longer be
1149
+ // centered, modify the padding so that it is centered.
1150
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
1151
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
1152
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
1153
+
1154
+ // Make sure the arrow doesn't overflow the floating element if the center
1155
+ // point is outside the floating element's bounds.
1156
+ const min$1 = minPadding;
1157
+ const max = clientSize - arrowDimensions[length] - maxPadding;
1158
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
1159
+ const offset = clamp(min$1, center, max);
1160
+
1161
+ // If the reference is small enough that the arrow's padding causes it to
1162
+ // to point to nothing for an aligned placement, adjust the offset of the
1163
+ // floating element itself. To ensure `shift()` continues to take action,
1164
+ // a single reset is performed when this is true.
1165
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1166
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
1167
+ return {
1168
+ [axis]: coords[axis] + alignmentOffset,
1169
+ data: {
1170
+ [axis]: offset,
1171
+ centerOffset: center - offset - alignmentOffset,
1172
+ ...(shouldAddOffset && {
1173
+ alignmentOffset
1174
+ })
1175
+ },
1176
+ reset: shouldAddOffset
1177
+ };
1178
+ }
1179
+ });
1180
+
1181
+ function getPlacementList(alignment, autoAlignment, allowedPlacements) {
1182
+ const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);
1183
+ return allowedPlacementsSortedByAlignment.filter(placement => {
1184
+ if (alignment) {
1185
+ return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
1186
+ }
1187
+ return true;
1188
+ });
1189
+ }
1190
+ /**
1191
+ * Optimizes the visibility of the floating element by choosing the placement
1192
+ * that has the most space available automatically, without needing to specify a
1193
+ * preferred placement. Alternative to `flip`.
1194
+ * @see https://floating-ui.com/docs/autoPlacement
1195
+ */
1196
+ const autoPlacement$2 = function (options) {
1197
+ if (options === void 0) {
1198
+ options = {};
1199
+ }
1200
+ return {
1201
+ name: 'autoPlacement',
1202
+ options,
1203
+ async fn(state) {
1204
+ var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
1205
+ const {
1206
+ rects,
1207
+ middlewareData,
1208
+ placement,
1209
+ platform,
1210
+ elements
1211
+ } = state;
1212
+ const {
1213
+ crossAxis = false,
1214
+ alignment,
1215
+ allowedPlacements = placements,
1216
+ autoAlignment = true,
1217
+ ...detectOverflowOptions
1218
+ } = evaluate(options, state);
1219
+ const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
1220
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1221
+ const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
1222
+ const currentPlacement = placements$1[currentIndex];
1223
+ if (currentPlacement == null) {
1224
+ return {};
1225
+ }
1226
+ const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
1227
+
1228
+ // Make `computeCoords` start from the right place.
1229
+ if (placement !== currentPlacement) {
1230
+ return {
1231
+ reset: {
1232
+ placement: placements$1[0]
1233
+ }
1234
+ };
1235
+ }
1236
+ const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
1237
+ const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {
1238
+ placement: currentPlacement,
1239
+ overflows: currentOverflows
1240
+ }];
1241
+ const nextPlacement = placements$1[currentIndex + 1];
1242
+
1243
+ // There are more placements to check.
1244
+ if (nextPlacement) {
1245
+ return {
1246
+ data: {
1247
+ index: currentIndex + 1,
1248
+ overflows: allOverflows
1249
+ },
1250
+ reset: {
1251
+ placement: nextPlacement
1252
+ }
1253
+ };
1254
+ }
1255
+ const placementsSortedByMostSpace = allOverflows.map(d => {
1256
+ const alignment = getAlignment(d.placement);
1257
+ return [d.placement, alignment && crossAxis ?
1258
+ // Check along the mainAxis and main crossAxis side.
1259
+ d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :
1260
+ // Check only the mainAxis.
1261
+ d.overflows[0], d.overflows];
1262
+ }).sort((a, b) => a[1] - b[1]);
1263
+ const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,
1264
+ // Aligned placements should not check their opposite crossAxis
1265
+ // side.
1266
+ getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));
1267
+ const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
1268
+ if (resetPlacement !== placement) {
1269
+ return {
1270
+ data: {
1271
+ index: currentIndex + 1,
1272
+ overflows: allOverflows
1273
+ },
1274
+ reset: {
1275
+ placement: resetPlacement
1276
+ }
1277
+ };
1278
+ }
1279
+ return {};
1280
+ }
1281
+ };
1282
+ };
1283
+
1284
+ /**
1285
+ * Optimizes the visibility of the floating element by flipping the `placement`
1286
+ * in order to keep it in view when the preferred placement(s) will overflow the
1287
+ * clipping boundary. Alternative to `autoPlacement`.
1288
+ * @see https://floating-ui.com/docs/flip
1289
+ */
1290
+ const flip$2 = function (options) {
1291
+ if (options === void 0) {
1292
+ options = {};
1293
+ }
1294
+ return {
1295
+ name: 'flip',
1296
+ options,
1297
+ async fn(state) {
1298
+ var _middlewareData$arrow, _middlewareData$flip;
1299
+ const {
1300
+ placement,
1301
+ middlewareData,
1302
+ rects,
1303
+ initialPlacement,
1304
+ platform,
1305
+ elements
1306
+ } = state;
1307
+ const {
1308
+ mainAxis: checkMainAxis = true,
1309
+ crossAxis: checkCrossAxis = true,
1310
+ fallbackPlacements: specifiedFallbackPlacements,
1311
+ fallbackStrategy = 'bestFit',
1312
+ fallbackAxisSideDirection = 'none',
1313
+ flipAlignment = true,
1314
+ ...detectOverflowOptions
1315
+ } = evaluate(options, state);
1316
+
1317
+ // If a reset by the arrow was caused due to an alignment offset being
1318
+ // added, we should skip any logic now since `flip()` has already done its
1319
+ // work.
1320
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
1321
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1322
+ return {};
1323
+ }
1324
+ const side = getSide(placement);
1325
+ const initialSideAxis = getSideAxis(initialPlacement);
1326
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
1327
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
1328
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
1329
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
1330
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
1331
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
1332
+ }
1333
+ const placements = [initialPlacement, ...fallbackPlacements];
1334
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1335
+ const overflows = [];
1336
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
1337
+ if (checkMainAxis) {
1338
+ overflows.push(overflow[side]);
1339
+ }
1340
+ if (checkCrossAxis) {
1341
+ const sides = getAlignmentSides(placement, rects, rtl);
1342
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
1343
+ }
1344
+ overflowsData = [...overflowsData, {
1345
+ placement,
1346
+ overflows
1347
+ }];
1348
+
1349
+ // One or more sides is overflowing.
1350
+ if (!overflows.every(side => side <= 0)) {
1351
+ var _middlewareData$flip2, _overflowsData$filter;
1352
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
1353
+ const nextPlacement = placements[nextIndex];
1354
+ if (nextPlacement) {
1355
+ const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
1356
+ if (!ignoreCrossAxisOverflow ||
1357
+ // We leave the current main axis only if every placement on that axis
1358
+ // overflows the main axis.
1359
+ overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
1360
+ // Try next placement and re-run the lifecycle.
1361
+ return {
1362
+ data: {
1363
+ index: nextIndex,
1364
+ overflows: overflowsData
1365
+ },
1366
+ reset: {
1367
+ placement: nextPlacement
1368
+ }
1369
+ };
1370
+ }
1371
+ }
1372
+
1373
+ // First, find the candidates that fit on the mainAxis side of overflow,
1374
+ // then find the placement that fits the best on the main crossAxis side.
1375
+ 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;
1376
+
1377
+ // Otherwise fallback.
1378
+ if (!resetPlacement) {
1379
+ switch (fallbackStrategy) {
1380
+ case 'bestFit':
1381
+ {
1382
+ var _overflowsData$filter2;
1383
+ const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
1384
+ if (hasFallbackAxisSideDirection) {
1385
+ const currentSideAxis = getSideAxis(d.placement);
1386
+ return currentSideAxis === initialSideAxis ||
1387
+ // Create a bias to the `y` side axis due to horizontal
1388
+ // reading directions favoring greater width.
1389
+ currentSideAxis === 'y';
1390
+ }
1391
+ return true;
1392
+ }).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];
1393
+ if (placement) {
1394
+ resetPlacement = placement;
1395
+ }
1396
+ break;
1397
+ }
1398
+ case 'initialPlacement':
1399
+ resetPlacement = initialPlacement;
1400
+ break;
1401
+ }
1402
+ }
1403
+ if (placement !== resetPlacement) {
1404
+ return {
1405
+ reset: {
1406
+ placement: resetPlacement
1407
+ }
1408
+ };
1409
+ }
1410
+ }
1411
+ return {};
1412
+ }
1413
+ };
1414
+ };
1415
+
1416
+ function getSideOffsets(overflow, rect) {
1417
+ return {
1418
+ top: overflow.top - rect.height,
1419
+ right: overflow.right - rect.width,
1420
+ bottom: overflow.bottom - rect.height,
1421
+ left: overflow.left - rect.width
1422
+ };
1423
+ }
1424
+ function isAnySideFullyClipped(overflow) {
1425
+ return sides.some(side => overflow[side] >= 0);
1426
+ }
1427
+ /**
1428
+ * Provides data to hide the floating element in applicable situations, such as
1429
+ * when it is not in the same clipping context as the reference element.
1430
+ * @see https://floating-ui.com/docs/hide
1431
+ */
1432
+ const hide$2 = function (options) {
1433
+ if (options === void 0) {
1434
+ options = {};
1435
+ }
1436
+ return {
1437
+ name: 'hide',
1438
+ options,
1439
+ async fn(state) {
1440
+ const {
1441
+ rects,
1442
+ platform
1443
+ } = state;
1444
+ const {
1445
+ strategy = 'referenceHidden',
1446
+ ...detectOverflowOptions
1447
+ } = evaluate(options, state);
1448
+ switch (strategy) {
1449
+ case 'referenceHidden':
1450
+ {
1451
+ const overflow = await platform.detectOverflow(state, {
1452
+ ...detectOverflowOptions,
1453
+ elementContext: 'reference'
1454
+ });
1455
+ const offsets = getSideOffsets(overflow, rects.reference);
1456
+ return {
1457
+ data: {
1458
+ referenceHiddenOffsets: offsets,
1459
+ referenceHidden: isAnySideFullyClipped(offsets)
1460
+ }
1461
+ };
1462
+ }
1463
+ case 'escaped':
1464
+ {
1465
+ const overflow = await platform.detectOverflow(state, {
1466
+ ...detectOverflowOptions,
1467
+ altBoundary: true
1468
+ });
1469
+ const offsets = getSideOffsets(overflow, rects.floating);
1470
+ return {
1471
+ data: {
1472
+ escapedOffsets: offsets,
1473
+ escaped: isAnySideFullyClipped(offsets)
1474
+ }
1475
+ };
1476
+ }
1477
+ default:
1478
+ {
1479
+ return {};
1480
+ }
1481
+ }
1482
+ }
1483
+ };
1484
+ };
1485
+
1486
+ const originSides = /*#__PURE__*/new Set(['left', 'top']);
1487
+
1488
+ // For type backwards-compatibility, the `OffsetOptions` type was also
1489
+ // Derivable.
1490
+
1491
+ async function convertValueToCoords(state, options) {
1492
+ const {
1493
+ placement,
1494
+ platform,
1495
+ elements
1496
+ } = state;
1497
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
1498
+ const side = getSide(placement);
1499
+ const alignment = getAlignment(placement);
1500
+ const isVertical = getSideAxis(placement) === 'y';
1501
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
1502
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
1503
+ const rawValue = evaluate(options, state);
1504
+
1505
+ // eslint-disable-next-line prefer-const
1506
+ let {
1507
+ mainAxis,
1508
+ crossAxis,
1509
+ alignmentAxis
1510
+ } = typeof rawValue === 'number' ? {
1511
+ mainAxis: rawValue,
1512
+ crossAxis: 0,
1513
+ alignmentAxis: null
1514
+ } : {
1515
+ mainAxis: rawValue.mainAxis || 0,
1516
+ crossAxis: rawValue.crossAxis || 0,
1517
+ alignmentAxis: rawValue.alignmentAxis
1518
+ };
1519
+ if (alignment && typeof alignmentAxis === 'number') {
1520
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
1521
+ }
1522
+ return isVertical ? {
1523
+ x: crossAxis * crossAxisMulti,
1524
+ y: mainAxis * mainAxisMulti
1525
+ } : {
1526
+ x: mainAxis * mainAxisMulti,
1527
+ y: crossAxis * crossAxisMulti
1528
+ };
1529
+ }
1530
+
1531
+ /**
1532
+ * Modifies the placement by translating the floating element along the
1533
+ * specified axes.
1534
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
1535
+ * object may be passed.
1536
+ * @see https://floating-ui.com/docs/offset
1537
+ */
1538
+ const offset$2 = function (options) {
1539
+ if (options === void 0) {
1540
+ options = 0;
1541
+ }
1542
+ return {
1543
+ name: 'offset',
1544
+ options,
1545
+ async fn(state) {
1546
+ var _middlewareData$offse, _middlewareData$arrow;
1547
+ const {
1548
+ x,
1549
+ y,
1550
+ placement,
1551
+ middlewareData
1552
+ } = state;
1553
+ const diffCoords = await convertValueToCoords(state, options);
1554
+
1555
+ // If the placement is the same and the arrow caused an alignment offset
1556
+ // then we don't need to change the positioning coordinates.
1557
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1558
+ return {};
1559
+ }
1560
+ return {
1561
+ x: x + diffCoords.x,
1562
+ y: y + diffCoords.y,
1563
+ data: {
1564
+ ...diffCoords,
1565
+ placement
1566
+ }
1567
+ };
1568
+ }
1569
+ };
1570
+ };
1571
+
1572
+ /**
1573
+ * Optimizes the visibility of the floating element by shifting it in order to
1574
+ * keep it in view when it will overflow the clipping boundary.
1575
+ * @see https://floating-ui.com/docs/shift
1576
+ */
1577
+ const shift$2 = function (options) {
1578
+ if (options === void 0) {
1579
+ options = {};
1580
+ }
1581
+ return {
1582
+ name: 'shift',
1583
+ options,
1584
+ async fn(state) {
1585
+ const {
1586
+ x,
1587
+ y,
1588
+ placement,
1589
+ platform
1590
+ } = state;
1591
+ const {
1592
+ mainAxis: checkMainAxis = true,
1593
+ crossAxis: checkCrossAxis = false,
1594
+ limiter = {
1595
+ fn: _ref => {
1596
+ let {
1597
+ x,
1598
+ y
1599
+ } = _ref;
1600
+ return {
1601
+ x,
1602
+ y
1603
+ };
1604
+ }
1605
+ },
1606
+ ...detectOverflowOptions
1607
+ } = evaluate(options, state);
1608
+ const coords = {
1609
+ x,
1610
+ y
1611
+ };
1612
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1613
+ const crossAxis = getSideAxis(getSide(placement));
1614
+ const mainAxis = getOppositeAxis(crossAxis);
1615
+ let mainAxisCoord = coords[mainAxis];
1616
+ let crossAxisCoord = coords[crossAxis];
1617
+ if (checkMainAxis) {
1618
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
1619
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
1620
+ const min = mainAxisCoord + overflow[minSide];
1621
+ const max = mainAxisCoord - overflow[maxSide];
1622
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
1623
+ }
1624
+ if (checkCrossAxis) {
1625
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
1626
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
1627
+ const min = crossAxisCoord + overflow[minSide];
1628
+ const max = crossAxisCoord - overflow[maxSide];
1629
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
1630
+ }
1631
+ const limitedCoords = limiter.fn({
1632
+ ...state,
1633
+ [mainAxis]: mainAxisCoord,
1634
+ [crossAxis]: crossAxisCoord
1635
+ });
1636
+ return {
1637
+ ...limitedCoords,
1638
+ data: {
1639
+ x: limitedCoords.x - x,
1640
+ y: limitedCoords.y - y,
1641
+ enabled: {
1642
+ [mainAxis]: checkMainAxis,
1643
+ [crossAxis]: checkCrossAxis
1644
+ }
1645
+ }
1646
+ };
1647
+ }
1648
+ };
1649
+ };
1650
+ /**
1651
+ * Built-in `limiter` that will stop `shift()` at a certain point.
1652
+ */
1653
+ const limitShift$2 = function (options) {
1654
+ if (options === void 0) {
1655
+ options = {};
1656
+ }
1657
+ return {
1658
+ options,
1659
+ fn(state) {
1660
+ const {
1661
+ x,
1662
+ y,
1663
+ placement,
1664
+ rects,
1665
+ middlewareData
1666
+ } = state;
1667
+ const {
1668
+ offset = 0,
1669
+ mainAxis: checkMainAxis = true,
1670
+ crossAxis: checkCrossAxis = true
1671
+ } = evaluate(options, state);
1672
+ const coords = {
1673
+ x,
1674
+ y
1675
+ };
1676
+ const crossAxis = getSideAxis(placement);
1677
+ const mainAxis = getOppositeAxis(crossAxis);
1678
+ let mainAxisCoord = coords[mainAxis];
1679
+ let crossAxisCoord = coords[crossAxis];
1680
+ const rawOffset = evaluate(offset, state);
1681
+ const computedOffset = typeof rawOffset === 'number' ? {
1682
+ mainAxis: rawOffset,
1683
+ crossAxis: 0
1684
+ } : {
1685
+ mainAxis: 0,
1686
+ crossAxis: 0,
1687
+ ...rawOffset
1688
+ };
1689
+ if (checkMainAxis) {
1690
+ const len = mainAxis === 'y' ? 'height' : 'width';
1691
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
1692
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
1693
+ if (mainAxisCoord < limitMin) {
1694
+ mainAxisCoord = limitMin;
1695
+ } else if (mainAxisCoord > limitMax) {
1696
+ mainAxisCoord = limitMax;
1697
+ }
1698
+ }
1699
+ if (checkCrossAxis) {
1700
+ var _middlewareData$offse, _middlewareData$offse2;
1701
+ const len = mainAxis === 'y' ? 'width' : 'height';
1702
+ const isOriginSide = originSides.has(getSide(placement));
1703
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
1704
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
1705
+ if (crossAxisCoord < limitMin) {
1706
+ crossAxisCoord = limitMin;
1707
+ } else if (crossAxisCoord > limitMax) {
1708
+ crossAxisCoord = limitMax;
1709
+ }
1710
+ }
1711
+ return {
1712
+ [mainAxis]: mainAxisCoord,
1713
+ [crossAxis]: crossAxisCoord
1714
+ };
1715
+ }
1716
+ };
1717
+ };
1718
+
1719
+ /**
1720
+ * Provides data that allows you to change the size of the floating element —
1721
+ * for instance, prevent it from overflowing the clipping boundary or match the
1722
+ * width of the reference element.
1723
+ * @see https://floating-ui.com/docs/size
1724
+ */
1725
+ const size$2 = function (options) {
1726
+ if (options === void 0) {
1727
+ options = {};
1728
+ }
1729
+ return {
1730
+ name: 'size',
1731
+ options,
1732
+ async fn(state) {
1733
+ var _state$middlewareData, _state$middlewareData2;
1734
+ const {
1735
+ placement,
1736
+ rects,
1737
+ platform,
1738
+ elements
1739
+ } = state;
1740
+ const {
1741
+ apply = () => {},
1742
+ ...detectOverflowOptions
1743
+ } = evaluate(options, state);
1744
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1745
+ const side = getSide(placement);
1746
+ const alignment = getAlignment(placement);
1747
+ const isYAxis = getSideAxis(placement) === 'y';
1748
+ const {
1749
+ width,
1750
+ height
1751
+ } = rects.floating;
1752
+ let heightSide;
1753
+ let widthSide;
1754
+ if (side === 'top' || side === 'bottom') {
1755
+ heightSide = side;
1756
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
1757
+ } else {
1758
+ widthSide = side;
1759
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
1760
+ }
1761
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
1762
+ const maximumClippingWidth = width - overflow.left - overflow.right;
1763
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
1764
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
1765
+ const noShift = !state.middlewareData.shift;
1766
+ let availableHeight = overflowAvailableHeight;
1767
+ let availableWidth = overflowAvailableWidth;
1768
+ if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
1769
+ availableWidth = maximumClippingWidth;
1770
+ }
1771
+ if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
1772
+ availableHeight = maximumClippingHeight;
1773
+ }
1774
+ if (noShift && !alignment) {
1775
+ const xMin = max(overflow.left, 0);
1776
+ const xMax = max(overflow.right, 0);
1777
+ const yMin = max(overflow.top, 0);
1778
+ const yMax = max(overflow.bottom, 0);
1779
+ if (isYAxis) {
1780
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
1781
+ } else {
1782
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
1783
+ }
1784
+ }
1785
+ await apply({
1786
+ ...state,
1787
+ availableWidth,
1788
+ availableHeight
1789
+ });
1790
+ const nextDimensions = await platform.getDimensions(elements.floating);
1791
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
1792
+ return {
1793
+ reset: {
1794
+ rects: true
1795
+ }
1796
+ };
1797
+ }
1798
+ return {};
1799
+ }
1800
+ };
1801
+ };
1802
+
1803
+ function getCssDimensions(element) {
1804
+ const css = getComputedStyle$1(element);
1805
+ // In testing environments, the `width` and `height` properties are empty
1806
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
1807
+ let width = parseFloat(css.width) || 0;
1808
+ let height = parseFloat(css.height) || 0;
1809
+ const hasOffset = isHTMLElement(element);
1810
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
1811
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
1812
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1813
+ if (shouldFallback) {
1814
+ width = offsetWidth;
1815
+ height = offsetHeight;
1816
+ }
1817
+ return {
1818
+ width,
1819
+ height,
1820
+ $: shouldFallback
1821
+ };
1822
+ }
1823
+
1824
+ function unwrapElement(element) {
1825
+ return !isElement(element) ? element.contextElement : element;
1826
+ }
1827
+
1828
+ function getScale(element) {
1829
+ const domElement = unwrapElement(element);
1830
+ if (!isHTMLElement(domElement)) {
1831
+ return createCoords(1);
1832
+ }
1833
+ const rect = domElement.getBoundingClientRect();
1834
+ const {
1835
+ width,
1836
+ height,
1837
+ $
1838
+ } = getCssDimensions(domElement);
1839
+ let x = ($ ? round(rect.width) : rect.width) / width;
1840
+ let y = ($ ? round(rect.height) : rect.height) / height;
1841
+
1842
+ // 0, NaN, or Infinity should always fallback to 1.
1843
+
1844
+ if (!x || !Number.isFinite(x)) {
1845
+ x = 1;
1846
+ }
1847
+ if (!y || !Number.isFinite(y)) {
1848
+ y = 1;
1849
+ }
1850
+ return {
1851
+ x,
1852
+ y
1853
+ };
1854
+ }
1855
+
1856
+ const noOffsets = /*#__PURE__*/createCoords(0);
1857
+ function getVisualOffsets(element) {
1858
+ const win = getWindow(element);
1859
+ if (!isWebKit() || !win.visualViewport) {
1860
+ return noOffsets;
1861
+ }
1862
+ return {
1863
+ x: win.visualViewport.offsetLeft,
1864
+ y: win.visualViewport.offsetTop
1865
+ };
1866
+ }
1867
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1868
+ if (isFixed === void 0) {
1869
+ isFixed = false;
1870
+ }
1871
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1872
+ return false;
1873
+ }
1874
+ return isFixed;
1875
+ }
1876
+
1877
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1878
+ if (includeScale === void 0) {
1879
+ includeScale = false;
1880
+ }
1881
+ if (isFixedStrategy === void 0) {
1882
+ isFixedStrategy = false;
1883
+ }
1884
+ const clientRect = element.getBoundingClientRect();
1885
+ const domElement = unwrapElement(element);
1886
+ let scale = createCoords(1);
1887
+ if (includeScale) {
1888
+ if (offsetParent) {
1889
+ if (isElement(offsetParent)) {
1890
+ scale = getScale(offsetParent);
1891
+ }
1892
+ } else {
1893
+ scale = getScale(element);
1894
+ }
1895
+ }
1896
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1897
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
1898
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
1899
+ let width = clientRect.width / scale.x;
1900
+ let height = clientRect.height / scale.y;
1901
+ if (domElement) {
1902
+ const win = getWindow(domElement);
1903
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1904
+ let currentWin = win;
1905
+ let currentIFrame = getFrameElement(currentWin);
1906
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
1907
+ const iframeScale = getScale(currentIFrame);
1908
+ const iframeRect = currentIFrame.getBoundingClientRect();
1909
+ const css = getComputedStyle$1(currentIFrame);
1910
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1911
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1912
+ x *= iframeScale.x;
1913
+ y *= iframeScale.y;
1914
+ width *= iframeScale.x;
1915
+ height *= iframeScale.y;
1916
+ x += left;
1917
+ y += top;
1918
+ currentWin = getWindow(currentIFrame);
1919
+ currentIFrame = getFrameElement(currentWin);
1920
+ }
1921
+ }
1922
+ return rectToClientRect({
1923
+ width,
1924
+ height,
1925
+ x,
1926
+ y
1927
+ });
1928
+ }
1929
+
1930
+ // If <html> has a CSS width greater than the viewport, then this will be
1931
+ // incorrect for RTL.
1932
+ function getWindowScrollBarX(element, rect) {
1933
+ const leftScroll = getNodeScroll(element).scrollLeft;
1934
+ if (!rect) {
1935
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
1936
+ }
1937
+ return rect.left + leftScroll;
1938
+ }
1939
+
1940
+ function getHTMLOffset(documentElement, scroll) {
1941
+ const htmlRect = documentElement.getBoundingClientRect();
1942
+ const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
1943
+ const y = htmlRect.top + scroll.scrollTop;
1944
+ return {
1945
+ x,
1946
+ y
1947
+ };
1948
+ }
1949
+
1950
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1951
+ let {
1952
+ elements,
1953
+ rect,
1954
+ offsetParent,
1955
+ strategy
1956
+ } = _ref;
1957
+ const isFixed = strategy === 'fixed';
1958
+ const documentElement = getDocumentElement(offsetParent);
1959
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
1960
+ if (offsetParent === documentElement || topLayer && isFixed) {
1961
+ return rect;
1962
+ }
1963
+ let scroll = {
1964
+ scrollLeft: 0,
1965
+ scrollTop: 0
1966
+ };
1967
+ let scale = createCoords(1);
1968
+ const offsets = createCoords(0);
1969
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1970
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1971
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1972
+ scroll = getNodeScroll(offsetParent);
1973
+ }
1974
+ if (isOffsetParentAnElement) {
1975
+ const offsetRect = getBoundingClientRect(offsetParent);
1976
+ scale = getScale(offsetParent);
1977
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1978
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1979
+ }
1980
+ }
1981
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1982
+ return {
1983
+ width: rect.width * scale.x,
1984
+ height: rect.height * scale.y,
1985
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
1986
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
1987
+ };
1988
+ }
1989
+
1990
+ function getClientRects(element) {
1991
+ return Array.from(element.getClientRects());
1992
+ }
1993
+
1994
+ // Gets the entire size of the scrollable document area, even extending outside
1995
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
1996
+ function getDocumentRect(element) {
1997
+ const html = getDocumentElement(element);
1998
+ const scroll = getNodeScroll(element);
1999
+ const body = element.ownerDocument.body;
2000
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
2001
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
2002
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
2003
+ const y = -scroll.scrollTop;
2004
+ if (getComputedStyle$1(body).direction === 'rtl') {
2005
+ x += max(html.clientWidth, body.clientWidth) - width;
2006
+ }
2007
+ return {
2008
+ width,
2009
+ height,
2010
+ x,
2011
+ y
2012
+ };
2013
+ }
2014
+
2015
+ // Safety check: ensure the scrollbar space is reasonable in case this
2016
+ // calculation is affected by unusual styles.
2017
+ // Most scrollbars leave 15-18px of space.
2018
+ const SCROLLBAR_MAX = 25;
2019
+ function getViewportRect(element, strategy) {
2020
+ const win = getWindow(element);
2021
+ const html = getDocumentElement(element);
2022
+ const visualViewport = win.visualViewport;
2023
+ let width = html.clientWidth;
2024
+ let height = html.clientHeight;
2025
+ let x = 0;
2026
+ let y = 0;
2027
+ if (visualViewport) {
2028
+ width = visualViewport.width;
2029
+ height = visualViewport.height;
2030
+ const visualViewportBased = isWebKit();
2031
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
2032
+ x = visualViewport.offsetLeft;
2033
+ y = visualViewport.offsetTop;
2034
+ }
2035
+ }
2036
+ const windowScrollbarX = getWindowScrollBarX(html);
2037
+ // <html> `overflow: hidden` + `scrollbar-gutter: stable` reduces the
2038
+ // visual width of the <html> but this is not considered in the size
2039
+ // of `html.clientWidth`.
2040
+ if (windowScrollbarX <= 0) {
2041
+ const doc = html.ownerDocument;
2042
+ const body = doc.body;
2043
+ const bodyStyles = getComputedStyle(body);
2044
+ const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
2045
+ const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
2046
+ if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
2047
+ width -= clippingStableScrollbarWidth;
2048
+ }
2049
+ } else if (windowScrollbarX <= SCROLLBAR_MAX) {
2050
+ // If the <body> scrollbar is on the left, the width needs to be extended
2051
+ // by the scrollbar amount so there isn't extra space on the right.
2052
+ width += windowScrollbarX;
2053
+ }
2054
+ return {
2055
+ width,
2056
+ height,
2057
+ x,
2058
+ y
2059
+ };
2060
+ }
2061
+
2062
+ // Returns the inner client rect, subtracting scrollbars if present.
2063
+ function getInnerBoundingClientRect(element, strategy) {
2064
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
2065
+ const top = clientRect.top + element.clientTop;
2066
+ const left = clientRect.left + element.clientLeft;
2067
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2068
+ const width = element.clientWidth * scale.x;
2069
+ const height = element.clientHeight * scale.y;
2070
+ const x = left * scale.x;
2071
+ const y = top * scale.y;
2072
+ return {
2073
+ width,
2074
+ height,
2075
+ x,
2076
+ y
2077
+ };
2078
+ }
2079
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2080
+ let rect;
2081
+ if (clippingAncestor === 'viewport') {
2082
+ rect = getViewportRect(element, strategy);
2083
+ } else if (clippingAncestor === 'document') {
2084
+ rect = getDocumentRect(getDocumentElement(element));
2085
+ } else if (isElement(clippingAncestor)) {
2086
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
2087
+ } else {
2088
+ const visualOffsets = getVisualOffsets(element);
2089
+ rect = {
2090
+ x: clippingAncestor.x - visualOffsets.x,
2091
+ y: clippingAncestor.y - visualOffsets.y,
2092
+ width: clippingAncestor.width,
2093
+ height: clippingAncestor.height
2094
+ };
2095
+ }
2096
+ return rectToClientRect(rect);
2097
+ }
2098
+ function hasFixedPositionAncestor(element, stopNode) {
2099
+ const parentNode = getParentNode(element);
2100
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2101
+ return false;
2102
+ }
2103
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
2104
+ }
2105
+
2106
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
2107
+ // clipping (or hiding) child elements. This returns all clipping ancestors
2108
+ // of the given element up the tree.
2109
+ function getClippingElementAncestors(element, cache) {
2110
+ const cachedResult = cache.get(element);
2111
+ if (cachedResult) {
2112
+ return cachedResult;
2113
+ }
2114
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
2115
+ let currentContainingBlockComputedStyle = null;
2116
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
2117
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
2118
+
2119
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
2120
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2121
+ const computedStyle = getComputedStyle$1(currentNode);
2122
+ const currentNodeIsContaining = isContainingBlock(currentNode);
2123
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
2124
+ currentContainingBlockComputedStyle = null;
2125
+ }
2126
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === 'absolute' || currentContainingBlockComputedStyle.position === 'fixed') || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2127
+ if (shouldDropCurrentNode) {
2128
+ // Drop non-containing blocks.
2129
+ result = result.filter(ancestor => ancestor !== currentNode);
2130
+ } else {
2131
+ // Record last containing block for next iteration.
2132
+ currentContainingBlockComputedStyle = computedStyle;
2133
+ }
2134
+ currentNode = getParentNode(currentNode);
2135
+ }
2136
+ cache.set(element, result);
2137
+ return result;
2138
+ }
2139
+
2140
+ // Gets the maximum area that the element is visible in due to any number of
2141
+ // clipping ancestors.
2142
+ function getClippingRect(_ref) {
2143
+ let {
2144
+ element,
2145
+ boundary,
2146
+ rootBoundary,
2147
+ strategy
2148
+ } = _ref;
2149
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
2150
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
2151
+ const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
2152
+ let top = firstRect.top;
2153
+ let right = firstRect.right;
2154
+ let bottom = firstRect.bottom;
2155
+ let left = firstRect.left;
2156
+ for (let i = 1; i < clippingAncestors.length; i++) {
2157
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
2158
+ top = max(rect.top, top);
2159
+ right = min(rect.right, right);
2160
+ bottom = min(rect.bottom, bottom);
2161
+ left = max(rect.left, left);
2162
+ }
2163
+ return {
2164
+ width: right - left,
2165
+ height: bottom - top,
2166
+ x: left,
2167
+ y: top
2168
+ };
2169
+ }
2170
+
2171
+ function getDimensions(element) {
2172
+ const {
2173
+ width,
2174
+ height
2175
+ } = getCssDimensions(element);
2176
+ return {
2177
+ width,
2178
+ height
2179
+ };
2180
+ }
2181
+
2182
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2183
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2184
+ const documentElement = getDocumentElement(offsetParent);
2185
+ const isFixed = strategy === 'fixed';
2186
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
2187
+ let scroll = {
2188
+ scrollLeft: 0,
2189
+ scrollTop: 0
2190
+ };
2191
+ const offsets = createCoords(0);
2192
+
2193
+ // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
2194
+ // Firefox with layout.scrollbar.side = 3 in about:config to test this.
2195
+ function setLeftRTLScrollbarOffset() {
2196
+ offsets.x = getWindowScrollBarX(documentElement);
2197
+ }
2198
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2199
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
2200
+ scroll = getNodeScroll(offsetParent);
2201
+ }
2202
+ if (isOffsetParentAnElement) {
2203
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2204
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2205
+ offsets.y = offsetRect.y + offsetParent.clientTop;
2206
+ } else if (documentElement) {
2207
+ setLeftRTLScrollbarOffset();
2208
+ }
2209
+ }
2210
+ if (isFixed && !isOffsetParentAnElement && documentElement) {
2211
+ setLeftRTLScrollbarOffset();
2212
+ }
2213
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
2214
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
2215
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
2216
+ return {
2217
+ x,
2218
+ y,
2219
+ width: rect.width,
2220
+ height: rect.height
2221
+ };
2222
+ }
2223
+
2224
+ function isStaticPositioned(element) {
2225
+ return getComputedStyle$1(element).position === 'static';
2226
+ }
2227
+
2228
+ function getTrueOffsetParent(element, polyfill) {
2229
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
2230
+ return null;
2231
+ }
2232
+ if (polyfill) {
2233
+ return polyfill(element);
2234
+ }
2235
+ let rawOffsetParent = element.offsetParent;
2236
+
2237
+ // Firefox returns the <html> element as the offsetParent if it's non-static,
2238
+ // while Chrome and Safari return the <body> element. The <body> element must
2239
+ // be used to perform the correct calculations even if the <html> element is
2240
+ // non-static.
2241
+ if (getDocumentElement(element) === rawOffsetParent) {
2242
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
2243
+ }
2244
+ return rawOffsetParent;
2245
+ }
2246
+
2247
+ // Gets the closest ancestor positioned element. Handles some edge cases,
2248
+ // such as table ancestors and cross browser bugs.
2249
+ function getOffsetParent(element, polyfill) {
2250
+ const win = getWindow(element);
2251
+ if (isTopLayer(element)) {
2252
+ return win;
2253
+ }
2254
+ if (!isHTMLElement(element)) {
2255
+ let svgOffsetParent = getParentNode(element);
2256
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
2257
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
2258
+ return svgOffsetParent;
2259
+ }
2260
+ svgOffsetParent = getParentNode(svgOffsetParent);
2261
+ }
2262
+ return win;
2263
+ }
2264
+ let offsetParent = getTrueOffsetParent(element, polyfill);
2265
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
2266
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
2267
+ }
2268
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
2269
+ return win;
2270
+ }
2271
+ return offsetParent || getContainingBlock(element) || win;
2272
+ }
2273
+
2274
+ const getElementRects = async function (data) {
2275
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
2276
+ const getDimensionsFn = this.getDimensions;
2277
+ const floatingDimensions = await getDimensionsFn(data.floating);
2278
+ return {
2279
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
2280
+ floating: {
2281
+ x: 0,
2282
+ y: 0,
2283
+ width: floatingDimensions.width,
2284
+ height: floatingDimensions.height
2285
+ }
2286
+ };
2287
+ };
2288
+
2289
+ function isRTL(element) {
2290
+ return getComputedStyle$1(element).direction === 'rtl';
2291
+ }
2292
+
2293
+ const platform = {
2294
+ convertOffsetParentRelativeRectToViewportRelativeRect,
2295
+ getDocumentElement,
2296
+ getClippingRect,
2297
+ getOffsetParent,
2298
+ getElementRects,
2299
+ getClientRects,
2300
+ getDimensions,
2301
+ getScale,
2302
+ isElement,
2303
+ isRTL
2304
+ };
2305
+
2306
+ function rectsAreEqual(a, b) {
2307
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
2308
+ }
2309
+
2310
+ // https://samthor.au/2021/observing-dom/
2311
+ function observeMove(element, onMove) {
2312
+ let io = null;
2313
+ let timeoutId;
2314
+ const root = getDocumentElement(element);
2315
+ function cleanup() {
2316
+ var _io;
2317
+ clearTimeout(timeoutId);
2318
+ (_io = io) == null || _io.disconnect();
2319
+ io = null;
2320
+ }
2321
+ function refresh(skip, threshold) {
2322
+ if (skip === void 0) {
2323
+ skip = false;
2324
+ }
2325
+ if (threshold === void 0) {
2326
+ threshold = 1;
2327
+ }
2328
+ cleanup();
2329
+ const elementRectForRootMargin = element.getBoundingClientRect();
2330
+ const {
2331
+ left,
2332
+ top,
2333
+ width,
2334
+ height
2335
+ } = elementRectForRootMargin;
2336
+ if (!skip) {
2337
+ onMove();
2338
+ }
2339
+ if (!width || !height) {
2340
+ return;
2341
+ }
2342
+ const insetTop = floor(top);
2343
+ const insetRight = floor(root.clientWidth - (left + width));
2344
+ const insetBottom = floor(root.clientHeight - (top + height));
2345
+ const insetLeft = floor(left);
2346
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
2347
+ const options = {
2348
+ rootMargin,
2349
+ threshold: max(0, min(1, threshold)) || 1
2350
+ };
2351
+ let isFirstUpdate = true;
2352
+ function handleObserve(entries) {
2353
+ const ratio = entries[0].intersectionRatio;
2354
+ if (ratio !== threshold) {
2355
+ if (!isFirstUpdate) {
2356
+ return refresh();
2357
+ }
2358
+ if (!ratio) {
2359
+ // If the reference is clipped, the ratio is 0. Throttle the refresh
2360
+ // to prevent an infinite loop of updates.
2361
+ timeoutId = setTimeout(() => {
2362
+ refresh(false, 1e-7);
2363
+ }, 1000);
2364
+ } else {
2365
+ refresh(false, ratio);
2366
+ }
2367
+ }
2368
+ if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
2369
+ // It's possible that even though the ratio is reported as 1, the
2370
+ // element is not actually fully within the IntersectionObserver's root
2371
+ // area anymore. This can happen under performance constraints. This may
2372
+ // be a bug in the browser's IntersectionObserver implementation. To
2373
+ // work around this, we compare the element's bounding rect now with
2374
+ // what it was at the time we created the IntersectionObserver. If they
2375
+ // are not equal then the element moved, so we refresh.
2376
+ refresh();
2377
+ }
2378
+ isFirstUpdate = false;
2379
+ }
2380
+
2381
+ // Older browsers don't support a `document` as the root and will throw an
2382
+ // error.
2383
+ try {
2384
+ io = new IntersectionObserver(handleObserve, {
2385
+ ...options,
2386
+ // Handle <iframe>s
2387
+ root: root.ownerDocument
2388
+ });
2389
+ } catch (_e) {
2390
+ io = new IntersectionObserver(handleObserve, options);
2391
+ }
2392
+ io.observe(element);
2393
+ }
2394
+ refresh(true);
2395
+ return cleanup;
2396
+ }
2397
+
2398
+ /**
2399
+ * Automatically updates the position of the floating element when necessary.
2400
+ * Should only be called when the floating element is mounted on the DOM or
2401
+ * visible on the screen.
2402
+ * @returns cleanup function that should be invoked when the floating element is
2403
+ * removed from the DOM or hidden from the screen.
2404
+ * @see https://floating-ui.com/docs/autoUpdate
2405
+ */
2406
+ function autoUpdate(reference, floating, update, options) {
2407
+ if (options === void 0) {
2408
+ options = {};
2409
+ }
2410
+ const {
2411
+ ancestorScroll = true,
2412
+ ancestorResize = true,
2413
+ elementResize = typeof ResizeObserver === 'function',
2414
+ layoutShift = typeof IntersectionObserver === 'function',
2415
+ animationFrame = false
2416
+ } = options;
2417
+ const referenceEl = unwrapElement(reference);
2418
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...(floating ? getOverflowAncestors(floating) : [])] : [];
2419
+ ancestors.forEach(ancestor => {
2420
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
2421
+ passive: true
2422
+ });
2423
+ ancestorResize && ancestor.addEventListener('resize', update);
2424
+ });
2425
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2426
+ let reobserveFrame = -1;
2427
+ let resizeObserver = null;
2428
+ if (elementResize) {
2429
+ resizeObserver = new ResizeObserver(_ref => {
2430
+ let [firstEntry] = _ref;
2431
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
2432
+ // Prevent update loops when using the `size` middleware.
2433
+ // https://github.com/floating-ui/floating-ui/issues/1740
2434
+ resizeObserver.unobserve(floating);
2435
+ cancelAnimationFrame(reobserveFrame);
2436
+ reobserveFrame = requestAnimationFrame(() => {
2437
+ var _resizeObserver;
2438
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
2439
+ });
2440
+ }
2441
+ update();
2442
+ });
2443
+ if (referenceEl && !animationFrame) {
2444
+ resizeObserver.observe(referenceEl);
2445
+ }
2446
+ if (floating) {
2447
+ resizeObserver.observe(floating);
2448
+ }
2449
+ }
2450
+ let frameId;
2451
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
2452
+ if (animationFrame) {
2453
+ frameLoop();
2454
+ }
2455
+ function frameLoop() {
2456
+ const nextRefRect = getBoundingClientRect(reference);
2457
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
2458
+ update();
2459
+ }
2460
+ prevRefRect = nextRefRect;
2461
+ frameId = requestAnimationFrame(frameLoop);
2462
+ }
2463
+ update();
2464
+ return () => {
2465
+ var _resizeObserver2;
2466
+ ancestors.forEach(ancestor => {
2467
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
2468
+ ancestorResize && ancestor.removeEventListener('resize', update);
2469
+ });
2470
+ cleanupIo == null || cleanupIo();
2471
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
2472
+ resizeObserver = null;
2473
+ if (animationFrame) {
2474
+ cancelAnimationFrame(frameId);
2475
+ }
2476
+ };
2477
+ }
2478
+
2479
+ /**
2480
+ * Modifies the placement by translating the floating element along the
2481
+ * specified axes.
2482
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
2483
+ * object may be passed.
2484
+ * @see https://floating-ui.com/docs/offset
2485
+ */
2486
+ const offset$1 = offset$2;
2487
+
2488
+ /**
2489
+ * Optimizes the visibility of the floating element by choosing the placement
2490
+ * that has the most space available automatically, without needing to specify a
2491
+ * preferred placement. Alternative to `flip`.
2492
+ * @see https://floating-ui.com/docs/autoPlacement
2493
+ */
2494
+ const autoPlacement$1 = autoPlacement$2;
2495
+
2496
+ /**
2497
+ * Optimizes the visibility of the floating element by shifting it in order to
2498
+ * keep it in view when it will overflow the clipping boundary.
2499
+ * @see https://floating-ui.com/docs/shift
2500
+ */
2501
+ const shift$1 = shift$2;
2502
+
2503
+ /**
2504
+ * Optimizes the visibility of the floating element by flipping the `placement`
2505
+ * in order to keep it in view when the preferred placement(s) will overflow the
2506
+ * clipping boundary. Alternative to `autoPlacement`.
2507
+ * @see https://floating-ui.com/docs/flip
2508
+ */
2509
+ const flip$1 = flip$2;
2510
+
2511
+ /**
2512
+ * Provides data that allows you to change the size of the floating element —
2513
+ * for instance, prevent it from overflowing the clipping boundary or match the
2514
+ * width of the reference element.
2515
+ * @see https://floating-ui.com/docs/size
2516
+ */
2517
+ const size$1 = size$2;
2518
+
2519
+ /**
2520
+ * Provides data to hide the floating element in applicable situations, such as
2521
+ * when it is not in the same clipping context as the reference element.
2522
+ * @see https://floating-ui.com/docs/hide
2523
+ */
2524
+ const hide$1 = hide$2;
2525
+
2526
+ /**
2527
+ * Provides data to position an inner element of the floating element so that it
2528
+ * appears centered to the reference element.
2529
+ * @see https://floating-ui.com/docs/arrow
2530
+ */
2531
+ const arrow$2 = arrow$3;
2532
+
2533
+ /**
2534
+ * Built-in `limiter` that will stop `shift()` at a certain point.
2535
+ */
2536
+ const limitShift$1 = limitShift$2;
2537
+
2538
+ /**
2539
+ * Computes the `x` and `y` coordinates that will place the floating element
2540
+ * next to a given reference element.
2541
+ */
2542
+ const computePosition = (reference, floating, options) => {
2543
+ // This caches the expensive `getClippingElementAncestors` function so that
2544
+ // multiple lifecycle resets re-use the same result. It only lives for a
2545
+ // single call. If other functions become expensive, we can add them as well.
2546
+ const cache = new Map();
2547
+ const mergedOptions = {
2548
+ platform,
2549
+ ...options
2550
+ };
2551
+ const platformWithCache = {
2552
+ ...mergedOptions.platform,
2553
+ _c: cache
2554
+ };
2555
+ return computePosition$1(reference, floating, {
2556
+ ...mergedOptions,
2557
+ platform: platformWithCache
2558
+ });
2559
+ };
2560
+
2561
+ var isClient = typeof document !== 'undefined';
2562
+
2563
+ var noop = function noop() {};
2564
+ var index = isClient ? useLayoutEffect : noop;
2565
+
2566
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
2567
+ // functions
2568
+ function deepEqual(a, b) {
2569
+ if (a === b) {
2570
+ return true;
2571
+ }
2572
+ if (typeof a !== typeof b) {
2573
+ return false;
2574
+ }
2575
+ if (typeof a === 'function' && a.toString() === b.toString()) {
2576
+ return true;
2577
+ }
2578
+ let length;
2579
+ let i;
2580
+ let keys;
2581
+ if (a && b && typeof a === 'object') {
2582
+ if (Array.isArray(a)) {
2583
+ length = a.length;
2584
+ if (length !== b.length) return false;
2585
+ for (i = length; i-- !== 0;) {
2586
+ if (!deepEqual(a[i], b[i])) {
2587
+ return false;
2588
+ }
2589
+ }
2590
+ return true;
2591
+ }
2592
+ keys = Object.keys(a);
2593
+ length = keys.length;
2594
+ if (length !== Object.keys(b).length) {
2595
+ return false;
2596
+ }
2597
+ for (i = length; i-- !== 0;) {
2598
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
2599
+ return false;
2600
+ }
2601
+ }
2602
+ for (i = length; i-- !== 0;) {
2603
+ const key = keys[i];
2604
+ if (key === '_owner' && a.$$typeof) {
2605
+ continue;
2606
+ }
2607
+ if (!deepEqual(a[key], b[key])) {
2608
+ return false;
2609
+ }
2610
+ }
2611
+ return true;
2612
+ }
2613
+ return a !== a && b !== b;
2614
+ }
2615
+
2616
+ function getDPR(element) {
2617
+ if (typeof window === 'undefined') {
2618
+ return 1;
2619
+ }
2620
+ const win = element.ownerDocument.defaultView || window;
2621
+ return win.devicePixelRatio || 1;
2622
+ }
2623
+
2624
+ function roundByDPR(element, value) {
2625
+ const dpr = getDPR(element);
2626
+ return Math.round(value * dpr) / dpr;
2627
+ }
2628
+
2629
+ function useLatestRef(value) {
2630
+ const ref = React.useRef(value);
2631
+ index(() => {
2632
+ ref.current = value;
2633
+ });
2634
+ return ref;
2635
+ }
2636
+
2637
+ /**
2638
+ * Provides data to position a floating element.
2639
+ * @see https://floating-ui.com/docs/useFloating
2640
+ */
2641
+ function useFloating(options) {
2642
+ if (options === void 0) {
2643
+ options = {};
2644
+ }
2645
+ const {
2646
+ placement = 'bottom',
2647
+ strategy = 'absolute',
2648
+ middleware = [],
2649
+ platform,
2650
+ elements: {
2651
+ reference: externalReference,
2652
+ floating: externalFloating
2653
+ } = {},
2654
+ transform = true,
2655
+ whileElementsMounted,
2656
+ open
2657
+ } = options;
2658
+ const [data, setData] = React.useState({
2659
+ x: 0,
2660
+ y: 0,
2661
+ strategy,
2662
+ placement,
2663
+ middlewareData: {},
2664
+ isPositioned: false
2665
+ });
2666
+ const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
2667
+ if (!deepEqual(latestMiddleware, middleware)) {
2668
+ setLatestMiddleware(middleware);
2669
+ }
2670
+ const [_reference, _setReference] = React.useState(null);
2671
+ const [_floating, _setFloating] = React.useState(null);
2672
+ const setReference = React.useCallback(node => {
2673
+ if (node !== referenceRef.current) {
2674
+ referenceRef.current = node;
2675
+ _setReference(node);
2676
+ }
2677
+ }, []);
2678
+ const setFloating = React.useCallback(node => {
2679
+ if (node !== floatingRef.current) {
2680
+ floatingRef.current = node;
2681
+ _setFloating(node);
2682
+ }
2683
+ }, []);
2684
+ const referenceEl = externalReference || _reference;
2685
+ const floatingEl = externalFloating || _floating;
2686
+ const referenceRef = React.useRef(null);
2687
+ const floatingRef = React.useRef(null);
2688
+ const dataRef = React.useRef(data);
2689
+ const hasWhileElementsMounted = whileElementsMounted != null;
2690
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
2691
+ const platformRef = useLatestRef(platform);
2692
+ const openRef = useLatestRef(open);
2693
+ const update = React.useCallback(() => {
2694
+ if (!referenceRef.current || !floatingRef.current) {
2695
+ return;
2696
+ }
2697
+ const config = {
2698
+ placement,
2699
+ strategy,
2700
+ middleware: latestMiddleware
2701
+ };
2702
+ if (platformRef.current) {
2703
+ config.platform = platformRef.current;
2704
+ }
2705
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
2706
+ const fullData = {
2707
+ ...data,
2708
+ // The floating element's position may be recomputed while it's closed
2709
+ // but still mounted (such as when transitioning out). To ensure
2710
+ // `isPositioned` will be `false` initially on the next open, avoid
2711
+ // setting it to `true` when `open === false` (must be specified).
2712
+ isPositioned: openRef.current !== false
2713
+ };
2714
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
2715
+ dataRef.current = fullData;
2716
+ ReactDOM.flushSync(() => {
2717
+ setData(fullData);
2718
+ });
2719
+ }
2720
+ });
2721
+ }, [latestMiddleware, placement, strategy, platformRef, openRef]);
2722
+ index(() => {
2723
+ if (open === false && dataRef.current.isPositioned) {
2724
+ dataRef.current.isPositioned = false;
2725
+ setData(data => ({
2726
+ ...data,
2727
+ isPositioned: false
2728
+ }));
2729
+ }
2730
+ }, [open]);
2731
+ const isMountedRef = React.useRef(false);
2732
+ index(() => {
2733
+ isMountedRef.current = true;
2734
+ return () => {
2735
+ isMountedRef.current = false;
2736
+ };
2737
+ }, []);
2738
+ index(() => {
2739
+ if (referenceEl) referenceRef.current = referenceEl;
2740
+ if (floatingEl) floatingRef.current = floatingEl;
2741
+ if (referenceEl && floatingEl) {
2742
+ if (whileElementsMountedRef.current) {
2743
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
2744
+ }
2745
+ update();
2746
+ }
2747
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
2748
+ const refs = React.useMemo(() => ({
2749
+ reference: referenceRef,
2750
+ floating: floatingRef,
2751
+ setReference,
2752
+ setFloating
2753
+ }), [setReference, setFloating]);
2754
+ const elements = React.useMemo(() => ({
2755
+ reference: referenceEl,
2756
+ floating: floatingEl
2757
+ }), [referenceEl, floatingEl]);
2758
+ const floatingStyles = React.useMemo(() => {
2759
+ const initialStyles = {
2760
+ position: strategy,
2761
+ left: 0,
2762
+ top: 0
2763
+ };
2764
+ if (!elements.floating) {
2765
+ return initialStyles;
2766
+ }
2767
+ const x = roundByDPR(elements.floating, data.x);
2768
+ const y = roundByDPR(elements.floating, data.y);
2769
+ if (transform) {
2770
+ return {
2771
+ ...initialStyles,
2772
+ transform: "translate(" + x + "px, " + y + "px)",
2773
+ ...(getDPR(elements.floating) >= 1.5 && {
2774
+ willChange: 'transform'
2775
+ })
2776
+ };
2777
+ }
2778
+ return {
2779
+ position: strategy,
2780
+ left: x,
2781
+ top: y
2782
+ };
2783
+ }, [strategy, transform, elements.floating, data.x, data.y]);
2784
+ return React.useMemo(() => ({
2785
+ ...data,
2786
+ update,
2787
+ refs,
2788
+ elements,
2789
+ floatingStyles
2790
+ }), [data, update, refs, elements, floatingStyles]);
2791
+ }
2792
+
2793
+ /**
2794
+ * Provides data to position an inner element of the floating element so that it
2795
+ * appears centered to the reference element.
2796
+ * This wraps the core `arrow` middleware to allow React refs as the element.
2797
+ * @see https://floating-ui.com/docs/arrow
2798
+ */
2799
+ const arrow$1 = options => {
2800
+ function isRef(value) {
2801
+ return {}.hasOwnProperty.call(value, 'current');
2802
+ }
2803
+ return {
2804
+ name: 'arrow',
2805
+ options,
2806
+ fn(state) {
2807
+ const {
2808
+ element,
2809
+ padding
2810
+ } = typeof options === 'function' ? options(state) : options;
2811
+ if (element && isRef(element)) {
2812
+ if (element.current != null) {
2813
+ return arrow$2({
2814
+ element: element.current,
2815
+ padding
2816
+ }).fn(state);
2817
+ }
2818
+ return {};
2819
+ }
2820
+ if (element) {
2821
+ return arrow$2({
2822
+ element,
2823
+ padding
2824
+ }).fn(state);
2825
+ }
2826
+ return {};
2827
+ }
2828
+ };
2829
+ };
2830
+
2831
+ /**
2832
+ * Modifies the placement by translating the floating element along the
2833
+ * specified axes.
2834
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
2835
+ * object may be passed.
2836
+ * @see https://floating-ui.com/docs/offset
2837
+ */
2838
+ const offset = (options, deps) => {
2839
+ const result = offset$1(options);
2840
+ return {
2841
+ name: result.name,
2842
+ fn: result.fn,
2843
+ options: [options, deps]
2844
+ };
2845
+ };
2846
+
2847
+ /**
2848
+ * Optimizes the visibility of the floating element by shifting it in order to
2849
+ * keep it in view when it will overflow the clipping boundary.
2850
+ * @see https://floating-ui.com/docs/shift
2851
+ */
2852
+ const shift = (options, deps) => {
2853
+ const result = shift$1(options);
2854
+ return {
2855
+ name: result.name,
2856
+ fn: result.fn,
2857
+ options: [options, deps]
2858
+ };
2859
+ };
2860
+
2861
+ /**
2862
+ * Built-in `limiter` that will stop `shift()` at a certain point.
2863
+ */
2864
+ const limitShift = (options, deps) => {
2865
+ const result = limitShift$1(options);
2866
+ return {
2867
+ fn: result.fn,
2868
+ options: [options, deps]
2869
+ };
2870
+ };
2871
+
2872
+ /**
2873
+ * Optimizes the visibility of the floating element by flipping the `placement`
2874
+ * in order to keep it in view when the preferred placement(s) will overflow the
2875
+ * clipping boundary. Alternative to `autoPlacement`.
2876
+ * @see https://floating-ui.com/docs/flip
2877
+ */
2878
+ const flip = (options, deps) => {
2879
+ const result = flip$1(options);
2880
+ return {
2881
+ name: result.name,
2882
+ fn: result.fn,
2883
+ options: [options, deps]
2884
+ };
2885
+ };
2886
+
2887
+ /**
2888
+ * Provides data that allows you to change the size of the floating element —
2889
+ * for instance, prevent it from overflowing the clipping boundary or match the
2890
+ * width of the reference element.
2891
+ * @see https://floating-ui.com/docs/size
2892
+ */
2893
+ const size = (options, deps) => {
2894
+ const result = size$1(options);
2895
+ return {
2896
+ name: result.name,
2897
+ fn: result.fn,
2898
+ options: [options, deps]
2899
+ };
2900
+ };
2901
+
2902
+ /**
2903
+ * Optimizes the visibility of the floating element by choosing the placement
2904
+ * that has the most space available automatically, without needing to specify a
2905
+ * preferred placement. Alternative to `flip`.
2906
+ * @see https://floating-ui.com/docs/autoPlacement
2907
+ */
2908
+ const autoPlacement = (options, deps) => {
2909
+ const result = autoPlacement$1(options);
2910
+ return {
2911
+ name: result.name,
2912
+ fn: result.fn,
2913
+ options: [options, deps]
2914
+ };
2915
+ };
2916
+
2917
+ /**
2918
+ * Provides data to hide the floating element in applicable situations, such as
2919
+ * when it is not in the same clipping context as the reference element.
2920
+ * @see https://floating-ui.com/docs/hide
2921
+ */
2922
+ const hide = (options, deps) => {
2923
+ const result = hide$1(options);
2924
+ return {
2925
+ name: result.name,
2926
+ fn: result.fn,
2927
+ options: [options, deps]
2928
+ };
2929
+ };
2930
+
2931
+ /**
2932
+ * Provides data to position an inner element of the floating element so that it
2933
+ * appears centered to the reference element.
2934
+ * This wraps the core `arrow` middleware to allow React refs as the element.
2935
+ * @see https://floating-ui.com/docs/arrow
2936
+ */
2937
+ const arrow = (options, deps) => {
2938
+ const result = arrow$1(options);
2939
+ return {
2940
+ name: result.name,
2941
+ fn: result.fn,
2942
+ options: [options, deps]
2943
+ };
2944
+ };
2945
+
2946
+ export { evaluate as A, getPaddingObject as B, getAlignmentAxis as C, getAlignment as D, getAxisLength as E, clamp as F, getSide as G, getSideAxis as H, isHTMLElement as a, isElement as b, isNode as c, getNodeName as d, isTabbable as e, floor as f, getOverflowAncestors as g, focusable as h, isShadowRoot as i, isLastTraversableNode as j, getParentNode as k, getComputedStyle$1 as l, isWebKit as m, flip as n, arrow as o, hide as p, autoUpdate as q, limitShift as r, shift as s, tabbable as t, useFloating as u, offset as v, autoPlacement as w, size as x, getWindow as y, isOverflowElement as z };