@geneui/components 3.0.0-next-9230252-17092024 → 3.0.0-next-1b7eefe-17092024

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 (132) hide show
  1. package/ActionableList/index.js +7 -8
  2. package/AdvancedSearch/index.js +5 -6
  3. package/Alert/index.js +3 -3
  4. package/Avatar/index.js +1 -1
  5. package/Badge/index.js +1 -1
  6. package/Breadcrumb/index.js +4 -5
  7. package/BusyLoader/index.js +2 -2
  8. package/Button/index.js +2 -2
  9. package/CHANGELOG.md +23 -0
  10. package/Card/index.js +4 -5
  11. package/CardList/index.js +11 -12
  12. package/{CellMeasurerCache-a1dbe54e.js → CellMeasurerCache-f0690f3b.js} +2 -2
  13. package/Charts/index.js +19 -19
  14. package/Checkbox/index.js +4 -4
  15. package/CheckboxGroup/index.js +4 -4
  16. package/CheckboxGroupWithSearch/index.js +5 -6
  17. package/Collapse/index.js +2 -2
  18. package/ColorPicker/index.js +2 -2
  19. package/ComboBox/index.js +6 -6
  20. package/Copy/index.js +5 -5
  21. package/Counter/index.js +4 -5
  22. package/DateFilter/index.js +5 -6
  23. package/DatePicker/index.js +2 -2
  24. package/DatePickerInput/index.js +6 -7
  25. package/Divider/index.js +1 -1
  26. package/Drawer/index.js +5 -5
  27. package/Dropdown/index.js +8 -9
  28. package/Editor/index.js +7 -14
  29. package/Empty/index.js +1 -1
  30. package/ExtendedInput/index.js +5 -5
  31. package/Form/index.js +8 -9
  32. package/FormContainer/index.js +2 -2
  33. package/FormableCheckbox/index.js +5 -5
  34. package/FormableDatePicker/index.js +6 -7
  35. package/FormableDropdown/index.js +8 -9
  36. package/FormableEditor/index.js +3 -3
  37. package/{FormableHOC-70f027f8.js → FormableHOC-300e2dd7.js} +2 -2
  38. package/FormableMultiSelectDropdown/index.js +8 -9
  39. package/FormableNumberInput/index.js +5 -5
  40. package/FormableRadio/index.js +3 -3
  41. package/FormableSwitcher/index.js +3 -3
  42. package/FormableTextInput/index.js +5 -5
  43. package/FormableUploader/index.js +4 -5
  44. package/GeneUIProvider/index.js +2 -1
  45. package/Grid/index.js +3 -3
  46. package/HelperText/index.js +4 -5
  47. package/Holder/index.js +4 -5
  48. package/Icon/index.js +2 -2
  49. package/Image/index.js +6 -7
  50. package/ImagePreview/index.js +4 -5
  51. package/InteractiveWidget/index.js +4 -5
  52. package/KeyValue/index.js +2 -2
  53. package/Label/index.js +1 -1
  54. package/LinkButton/index.js +2 -2
  55. package/Menu/index.js +5 -5
  56. package/MobileNavigation/index.js +2 -2
  57. package/MobilePopup/index.js +5 -5
  58. package/Modal/index.js +3 -3
  59. package/ModuleTitle/index.js +5 -5
  60. package/NavigationMenu/index.js +6 -6
  61. package/Notification/index.js +3 -3
  62. package/Option/index.js +5 -5
  63. package/Overlay/index.js +4 -5
  64. package/Overspread/index.js +9 -10
  65. package/Pagination/index.js +4 -5
  66. package/Paper/index.js +2 -2
  67. package/Popover/index.js +411 -6
  68. package/PopoverV2/index.js +3 -3
  69. package/Products/index.js +3 -3
  70. package/Profile/index.js +4 -5
  71. package/Progress/index.js +2 -2
  72. package/Radio/index.js +2 -2
  73. package/RadioGroup/index.js +2 -2
  74. package/Range/index.js +3 -3
  75. package/Rating/index.js +4 -4
  76. package/RichEditor/index.js +1 -1
  77. package/{RichEditor-a3f1150e.js → RichEditor-3ad651c7.js} +1 -1
  78. package/Scrollbar/index.js +3 -3
  79. package/Search/index.js +4 -4
  80. package/SearchWithDropdown/index.js +9 -10
  81. package/Section/index.js +3 -3
  82. package/SkeletonLoader/index.js +2 -2
  83. package/Slider/index.js +5 -5
  84. package/Status/index.js +6 -6
  85. package/Steps/index.js +6 -6
  86. package/SuggestionList/index.js +3 -3
  87. package/Switcher/index.js +3 -3
  88. package/Table/index.js +16 -17
  89. package/TableCompositions/index.js +14 -15
  90. package/Tabs/index.js +2 -2
  91. package/Tag/index.js +3 -3
  92. package/Textarea/index.js +4 -4
  93. package/Time/index.js +2 -2
  94. package/TimePicker/index.js +57 -39
  95. package/Timeline/index.js +3 -3
  96. package/Title/index.js +3 -3
  97. package/Toaster/index.js +3 -3
  98. package/Tooltip/index.js +10 -153
  99. package/TransferList/index.js +9 -10
  100. package/Uploader/index.js +7 -8
  101. package/ValidatableCheckbox/index.js +4 -4
  102. package/ValidatableDatePicker/index.js +5 -6
  103. package/ValidatableDropdown/index.js +7 -8
  104. package/ValidatableElements/index.js +7 -8
  105. package/ValidatableMultiSelectDropdown/index.js +7 -8
  106. package/ValidatableNumberInput/index.js +4 -4
  107. package/ValidatableRadio/index.js +2 -2
  108. package/ValidatableSwitcher/index.js +2 -2
  109. package/ValidatableTextInput/index.js +4 -4
  110. package/ValidatableTimeInput/index.js +4 -4
  111. package/ValidatableUploader/index.js +3 -4
  112. package/Widget/index.js +4 -5
  113. package/_rollupPluginBabelHelpers-e8fb2e5c.js +16 -0
  114. package/{configs-0ed1e326.js → configs-34847b77.js} +1 -1
  115. package/hooks/useDeviceType.js +1 -1
  116. package/index-006d8b06.js +3080 -0
  117. package/{index-34914e4c.js → index-263b0f0b.js} +1 -1
  118. package/{index-b139bff9.js → index-558ac559.js} +87 -64
  119. package/{index-79316a14.js → index-761141c1.js} +11 -10
  120. package/{index-b4ec7815.js → index-ac5c45f7.js} +3 -3
  121. package/index.js +14 -15
  122. package/lib/atoms/Button/Button.d.ts +1 -1
  123. package/lib/molecules/Tooltip/Tooltip.d.ts +58 -0
  124. package/lib/molecules/Tooltip/index.d.ts +1 -0
  125. package/objectWithoutPropertiesLoose-d8a4a68c.js +78 -0
  126. package/package.json +2 -1
  127. package/{rangeAndSlider-693a3d41.js → rangeAndSlider-63c5d423.js} +8 -16
  128. package/{react-beautiful-dnd.esm-ec039212.js → react-beautiful-dnd.esm-0ce25a0e.js} +7 -4
  129. package/{index-b7c1fe38.js → redux-b3e598ca.js} +2 -273
  130. package/Popover-f4d1cac0.js +0 -411
  131. package/_rollupPluginBabelHelpers-a83240e1.js +0 -11
  132. package/objectWithoutPropertiesLoose-e1596bdb.js +0 -62
@@ -0,0 +1,3080 @@
1
+ import { _ as __rest } from './tslib.es6-f211516f.js';
2
+ import * as React from 'react';
3
+ import React__default, { useLayoutEffect, useEffect, useContext, useState, Children, Fragment, cloneElement } from 'react';
4
+ import * as ReactDOM from 'react-dom';
5
+ import { n as noop } from './index-a0e4e333.js';
6
+ import useDeviceType from './hooks/useDeviceType.js';
7
+ import { GeneUIDesignSystemContext } from './GeneUIProvider/index.js';
8
+ import { s as styleInject } from './style-inject.es-746bb8ed.js';
9
+
10
+ /**
11
+ * Custom positioning reference element.
12
+ * @see https://floating-ui.com/docs/virtual-elements
13
+ */
14
+
15
+ const min = Math.min;
16
+ const max = Math.max;
17
+ const round = Math.round;
18
+ const floor = Math.floor;
19
+ const createCoords = v => ({
20
+ x: v,
21
+ y: v
22
+ });
23
+ const oppositeSideMap = {
24
+ left: 'right',
25
+ right: 'left',
26
+ bottom: 'top',
27
+ top: 'bottom'
28
+ };
29
+ const oppositeAlignmentMap = {
30
+ start: 'end',
31
+ end: 'start'
32
+ };
33
+ function clamp(start, value, end) {
34
+ return max(start, min(value, end));
35
+ }
36
+ function evaluate(value, param) {
37
+ return typeof value === 'function' ? value(param) : value;
38
+ }
39
+ function getSide(placement) {
40
+ return placement.split('-')[0];
41
+ }
42
+ function getAlignment(placement) {
43
+ return placement.split('-')[1];
44
+ }
45
+ function getOppositeAxis(axis) {
46
+ return axis === 'x' ? 'y' : 'x';
47
+ }
48
+ function getAxisLength(axis) {
49
+ return axis === 'y' ? 'height' : 'width';
50
+ }
51
+ function getSideAxis(placement) {
52
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
53
+ }
54
+ function getAlignmentAxis(placement) {
55
+ return getOppositeAxis(getSideAxis(placement));
56
+ }
57
+ function getAlignmentSides(placement, rects, rtl) {
58
+ if (rtl === void 0) {
59
+ rtl = false;
60
+ }
61
+ const alignment = getAlignment(placement);
62
+ const alignmentAxis = getAlignmentAxis(placement);
63
+ const length = getAxisLength(alignmentAxis);
64
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
65
+ if (rects.reference[length] > rects.floating[length]) {
66
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
67
+ }
68
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
69
+ }
70
+ function getExpandedPlacements(placement) {
71
+ const oppositePlacement = getOppositePlacement(placement);
72
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
73
+ }
74
+ function getOppositeAlignmentPlacement(placement) {
75
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
76
+ }
77
+ function getSideList(side, isStart, rtl) {
78
+ const lr = ['left', 'right'];
79
+ const rl = ['right', 'left'];
80
+ const tb = ['top', 'bottom'];
81
+ const bt = ['bottom', 'top'];
82
+ switch (side) {
83
+ case 'top':
84
+ case 'bottom':
85
+ if (rtl) return isStart ? rl : lr;
86
+ return isStart ? lr : rl;
87
+ case 'left':
88
+ case 'right':
89
+ return isStart ? tb : bt;
90
+ default:
91
+ return [];
92
+ }
93
+ }
94
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
95
+ const alignment = getAlignment(placement);
96
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
97
+ if (alignment) {
98
+ list = list.map(side => side + "-" + alignment);
99
+ if (flipAlignment) {
100
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
101
+ }
102
+ }
103
+ return list;
104
+ }
105
+ function getOppositePlacement(placement) {
106
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
107
+ }
108
+ function expandPaddingObject(padding) {
109
+ return {
110
+ top: 0,
111
+ right: 0,
112
+ bottom: 0,
113
+ left: 0,
114
+ ...padding
115
+ };
116
+ }
117
+ function getPaddingObject(padding) {
118
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
119
+ top: padding,
120
+ right: padding,
121
+ bottom: padding,
122
+ left: padding
123
+ };
124
+ }
125
+ function rectToClientRect(rect) {
126
+ const {
127
+ x,
128
+ y,
129
+ width,
130
+ height
131
+ } = rect;
132
+ return {
133
+ width,
134
+ height,
135
+ top: y,
136
+ left: x,
137
+ right: x + width,
138
+ bottom: y + height,
139
+ x,
140
+ y
141
+ };
142
+ }
143
+
144
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
145
+ let {
146
+ reference,
147
+ floating
148
+ } = _ref;
149
+ const sideAxis = getSideAxis(placement);
150
+ const alignmentAxis = getAlignmentAxis(placement);
151
+ const alignLength = getAxisLength(alignmentAxis);
152
+ const side = getSide(placement);
153
+ const isVertical = sideAxis === 'y';
154
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
155
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
156
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
157
+ let coords;
158
+ switch (side) {
159
+ case 'top':
160
+ coords = {
161
+ x: commonX,
162
+ y: reference.y - floating.height
163
+ };
164
+ break;
165
+ case 'bottom':
166
+ coords = {
167
+ x: commonX,
168
+ y: reference.y + reference.height
169
+ };
170
+ break;
171
+ case 'right':
172
+ coords = {
173
+ x: reference.x + reference.width,
174
+ y: commonY
175
+ };
176
+ break;
177
+ case 'left':
178
+ coords = {
179
+ x: reference.x - floating.width,
180
+ y: commonY
181
+ };
182
+ break;
183
+ default:
184
+ coords = {
185
+ x: reference.x,
186
+ y: reference.y
187
+ };
188
+ }
189
+ switch (getAlignment(placement)) {
190
+ case 'start':
191
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
192
+ break;
193
+ case 'end':
194
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
195
+ break;
196
+ }
197
+ return coords;
198
+ }
199
+
200
+ /**
201
+ * Computes the `x` and `y` coordinates that will place the floating element
202
+ * next to a given reference element.
203
+ *
204
+ * This export does not have any `platform` interface logic. You will need to
205
+ * write one for the platform you are using Floating UI with.
206
+ */
207
+ const computePosition$1 = async (reference, floating, config) => {
208
+ const {
209
+ placement = 'bottom',
210
+ strategy = 'absolute',
211
+ middleware = [],
212
+ platform
213
+ } = config;
214
+ const validMiddleware = middleware.filter(Boolean);
215
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
216
+ let rects = await platform.getElementRects({
217
+ reference,
218
+ floating,
219
+ strategy
220
+ });
221
+ let {
222
+ x,
223
+ y
224
+ } = computeCoordsFromPlacement(rects, placement, rtl);
225
+ let statefulPlacement = placement;
226
+ let middlewareData = {};
227
+ let resetCount = 0;
228
+ for (let i = 0; i < validMiddleware.length; i++) {
229
+ const {
230
+ name,
231
+ fn
232
+ } = validMiddleware[i];
233
+ const {
234
+ x: nextX,
235
+ y: nextY,
236
+ data,
237
+ reset
238
+ } = await fn({
239
+ x,
240
+ y,
241
+ initialPlacement: placement,
242
+ placement: statefulPlacement,
243
+ strategy,
244
+ middlewareData,
245
+ rects,
246
+ platform,
247
+ elements: {
248
+ reference,
249
+ floating
250
+ }
251
+ });
252
+ x = nextX != null ? nextX : x;
253
+ y = nextY != null ? nextY : y;
254
+ middlewareData = {
255
+ ...middlewareData,
256
+ [name]: {
257
+ ...middlewareData[name],
258
+ ...data
259
+ }
260
+ };
261
+ if (reset && resetCount <= 50) {
262
+ resetCount++;
263
+ if (typeof reset === 'object') {
264
+ if (reset.placement) {
265
+ statefulPlacement = reset.placement;
266
+ }
267
+ if (reset.rects) {
268
+ rects = reset.rects === true ? await platform.getElementRects({
269
+ reference,
270
+ floating,
271
+ strategy
272
+ }) : reset.rects;
273
+ }
274
+ ({
275
+ x,
276
+ y
277
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
278
+ }
279
+ i = -1;
280
+ }
281
+ }
282
+ return {
283
+ x,
284
+ y,
285
+ placement: statefulPlacement,
286
+ strategy,
287
+ middlewareData
288
+ };
289
+ };
290
+
291
+ /**
292
+ * Resolves with an object of overflow side offsets that determine how much the
293
+ * element is overflowing a given clipping boundary on each side.
294
+ * - positive = overflowing the boundary by that number of pixels
295
+ * - negative = how many pixels left before it will overflow
296
+ * - 0 = lies flush with the boundary
297
+ * @see https://floating-ui.com/docs/detectOverflow
298
+ */
299
+ async function detectOverflow(state, options) {
300
+ var _await$platform$isEle;
301
+ if (options === void 0) {
302
+ options = {};
303
+ }
304
+ const {
305
+ x,
306
+ y,
307
+ platform,
308
+ rects,
309
+ elements,
310
+ strategy
311
+ } = state;
312
+ const {
313
+ boundary = 'clippingAncestors',
314
+ rootBoundary = 'viewport',
315
+ elementContext = 'floating',
316
+ altBoundary = false,
317
+ padding = 0
318
+ } = evaluate(options, state);
319
+ const paddingObject = getPaddingObject(padding);
320
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
321
+ const element = elements[altBoundary ? altContext : elementContext];
322
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
323
+ 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))),
324
+ boundary,
325
+ rootBoundary,
326
+ strategy
327
+ }));
328
+ const rect = elementContext === 'floating' ? {
329
+ ...rects.floating,
330
+ x,
331
+ y
332
+ } : rects.reference;
333
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
334
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
335
+ x: 1,
336
+ y: 1
337
+ } : {
338
+ x: 1,
339
+ y: 1
340
+ };
341
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
342
+ elements,
343
+ rect,
344
+ offsetParent,
345
+ strategy
346
+ }) : rect);
347
+ return {
348
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
349
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
350
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
351
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
352
+ };
353
+ }
354
+
355
+ /**
356
+ * Optimizes the visibility of the floating element by flipping the `placement`
357
+ * in order to keep it in view when the preferred placement(s) will overflow the
358
+ * clipping boundary. Alternative to `autoPlacement`.
359
+ * @see https://floating-ui.com/docs/flip
360
+ */
361
+ const flip = function (options) {
362
+ if (options === void 0) {
363
+ options = {};
364
+ }
365
+ return {
366
+ name: 'flip',
367
+ options,
368
+ async fn(state) {
369
+ var _middlewareData$arrow, _middlewareData$flip;
370
+ const {
371
+ placement,
372
+ middlewareData,
373
+ rects,
374
+ initialPlacement,
375
+ platform,
376
+ elements
377
+ } = state;
378
+ const {
379
+ mainAxis: checkMainAxis = true,
380
+ crossAxis: checkCrossAxis = true,
381
+ fallbackPlacements: specifiedFallbackPlacements,
382
+ fallbackStrategy = 'bestFit',
383
+ fallbackAxisSideDirection = 'none',
384
+ flipAlignment = true,
385
+ ...detectOverflowOptions
386
+ } = evaluate(options, state);
387
+
388
+ // If a reset by the arrow was caused due to an alignment offset being
389
+ // added, we should skip any logic now since `flip()` has already done its
390
+ // work.
391
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
392
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
393
+ return {};
394
+ }
395
+ const side = getSide(placement);
396
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
397
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
398
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
399
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
400
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
401
+ }
402
+ const placements = [initialPlacement, ...fallbackPlacements];
403
+ const overflow = await detectOverflow(state, detectOverflowOptions);
404
+ const overflows = [];
405
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
406
+ if (checkMainAxis) {
407
+ overflows.push(overflow[side]);
408
+ }
409
+ if (checkCrossAxis) {
410
+ const sides = getAlignmentSides(placement, rects, rtl);
411
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
412
+ }
413
+ overflowsData = [...overflowsData, {
414
+ placement,
415
+ overflows
416
+ }];
417
+
418
+ // One or more sides is overflowing.
419
+ if (!overflows.every(side => side <= 0)) {
420
+ var _middlewareData$flip2, _overflowsData$filter;
421
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
422
+ const nextPlacement = placements[nextIndex];
423
+ if (nextPlacement) {
424
+ // Try next placement and re-run the lifecycle.
425
+ return {
426
+ data: {
427
+ index: nextIndex,
428
+ overflows: overflowsData
429
+ },
430
+ reset: {
431
+ placement: nextPlacement
432
+ }
433
+ };
434
+ }
435
+
436
+ // First, find the candidates that fit on the mainAxis side of overflow,
437
+ // then find the placement that fits the best on the main crossAxis side.
438
+ 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;
439
+
440
+ // Otherwise fallback.
441
+ if (!resetPlacement) {
442
+ switch (fallbackStrategy) {
443
+ case 'bestFit':
444
+ {
445
+ var _overflowsData$map$so;
446
+ const placement = (_overflowsData$map$so = overflowsData.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$map$so[0];
447
+ if (placement) {
448
+ resetPlacement = placement;
449
+ }
450
+ break;
451
+ }
452
+ case 'initialPlacement':
453
+ resetPlacement = initialPlacement;
454
+ break;
455
+ }
456
+ }
457
+ if (placement !== resetPlacement) {
458
+ return {
459
+ reset: {
460
+ placement: resetPlacement
461
+ }
462
+ };
463
+ }
464
+ }
465
+ return {};
466
+ }
467
+ };
468
+ };
469
+
470
+ // For type backwards-compatibility, the `OffsetOptions` type was also
471
+ // Derivable.
472
+
473
+ async function convertValueToCoords(state, options) {
474
+ const {
475
+ placement,
476
+ platform,
477
+ elements
478
+ } = state;
479
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
480
+ const side = getSide(placement);
481
+ const alignment = getAlignment(placement);
482
+ const isVertical = getSideAxis(placement) === 'y';
483
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
484
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
485
+ const rawValue = evaluate(options, state);
486
+ let {
487
+ mainAxis,
488
+ crossAxis,
489
+ alignmentAxis
490
+ } = typeof rawValue === 'number' ? {
491
+ mainAxis: rawValue,
492
+ crossAxis: 0,
493
+ alignmentAxis: null
494
+ } : {
495
+ mainAxis: 0,
496
+ crossAxis: 0,
497
+ alignmentAxis: null,
498
+ ...rawValue
499
+ };
500
+ if (alignment && typeof alignmentAxis === 'number') {
501
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
502
+ }
503
+ return isVertical ? {
504
+ x: crossAxis * crossAxisMulti,
505
+ y: mainAxis * mainAxisMulti
506
+ } : {
507
+ x: mainAxis * mainAxisMulti,
508
+ y: crossAxis * crossAxisMulti
509
+ };
510
+ }
511
+
512
+ /**
513
+ * Modifies the placement by translating the floating element along the
514
+ * specified axes.
515
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
516
+ * object may be passed.
517
+ * @see https://floating-ui.com/docs/offset
518
+ */
519
+ const offset = function (options) {
520
+ if (options === void 0) {
521
+ options = 0;
522
+ }
523
+ return {
524
+ name: 'offset',
525
+ options,
526
+ async fn(state) {
527
+ var _middlewareData$offse, _middlewareData$arrow;
528
+ const {
529
+ x,
530
+ y,
531
+ placement,
532
+ middlewareData
533
+ } = state;
534
+ const diffCoords = await convertValueToCoords(state, options);
535
+
536
+ // If the placement is the same and the arrow caused an alignment offset
537
+ // then we don't need to change the positioning coordinates.
538
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
539
+ return {};
540
+ }
541
+ return {
542
+ x: x + diffCoords.x,
543
+ y: y + diffCoords.y,
544
+ data: {
545
+ ...diffCoords,
546
+ placement
547
+ }
548
+ };
549
+ }
550
+ };
551
+ };
552
+
553
+ /**
554
+ * Optimizes the visibility of the floating element by shifting it in order to
555
+ * keep it in view when it will overflow the clipping boundary.
556
+ * @see https://floating-ui.com/docs/shift
557
+ */
558
+ const shift = function (options) {
559
+ if (options === void 0) {
560
+ options = {};
561
+ }
562
+ return {
563
+ name: 'shift',
564
+ options,
565
+ async fn(state) {
566
+ const {
567
+ x,
568
+ y,
569
+ placement
570
+ } = state;
571
+ const {
572
+ mainAxis: checkMainAxis = true,
573
+ crossAxis: checkCrossAxis = false,
574
+ limiter = {
575
+ fn: _ref => {
576
+ let {
577
+ x,
578
+ y
579
+ } = _ref;
580
+ return {
581
+ x,
582
+ y
583
+ };
584
+ }
585
+ },
586
+ ...detectOverflowOptions
587
+ } = evaluate(options, state);
588
+ const coords = {
589
+ x,
590
+ y
591
+ };
592
+ const overflow = await detectOverflow(state, detectOverflowOptions);
593
+ const crossAxis = getSideAxis(getSide(placement));
594
+ const mainAxis = getOppositeAxis(crossAxis);
595
+ let mainAxisCoord = coords[mainAxis];
596
+ let crossAxisCoord = coords[crossAxis];
597
+ if (checkMainAxis) {
598
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
599
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
600
+ const min = mainAxisCoord + overflow[minSide];
601
+ const max = mainAxisCoord - overflow[maxSide];
602
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
603
+ }
604
+ if (checkCrossAxis) {
605
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
606
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
607
+ const min = crossAxisCoord + overflow[minSide];
608
+ const max = crossAxisCoord - overflow[maxSide];
609
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
610
+ }
611
+ const limitedCoords = limiter.fn({
612
+ ...state,
613
+ [mainAxis]: mainAxisCoord,
614
+ [crossAxis]: crossAxisCoord
615
+ });
616
+ return {
617
+ ...limitedCoords,
618
+ data: {
619
+ x: limitedCoords.x - x,
620
+ y: limitedCoords.y - y
621
+ }
622
+ };
623
+ }
624
+ };
625
+ };
626
+
627
+ function hasWindow() {
628
+ return typeof window !== 'undefined';
629
+ }
630
+ function getNodeName(node) {
631
+ if (isNode(node)) {
632
+ return (node.nodeName || '').toLowerCase();
633
+ }
634
+ // Mocked nodes in testing environments may not be instances of Node. By
635
+ // returning `#document` an infinite loop won't occur.
636
+ // https://github.com/floating-ui/floating-ui/issues/2317
637
+ return '#document';
638
+ }
639
+ function getWindow(node) {
640
+ var _node$ownerDocument;
641
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
642
+ }
643
+ function getDocumentElement(node) {
644
+ var _ref;
645
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
646
+ }
647
+ function isNode(value) {
648
+ if (!hasWindow()) {
649
+ return false;
650
+ }
651
+ return value instanceof Node || value instanceof getWindow(value).Node;
652
+ }
653
+ function isElement(value) {
654
+ if (!hasWindow()) {
655
+ return false;
656
+ }
657
+ return value instanceof Element || value instanceof getWindow(value).Element;
658
+ }
659
+ function isHTMLElement(value) {
660
+ if (!hasWindow()) {
661
+ return false;
662
+ }
663
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
664
+ }
665
+ function isShadowRoot(value) {
666
+ if (!hasWindow() || typeof ShadowRoot === 'undefined') {
667
+ return false;
668
+ }
669
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
670
+ }
671
+ function isOverflowElement(element) {
672
+ const {
673
+ overflow,
674
+ overflowX,
675
+ overflowY,
676
+ display
677
+ } = getComputedStyle$1(element);
678
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
679
+ }
680
+ function isTableElement(element) {
681
+ return ['table', 'td', 'th'].includes(getNodeName(element));
682
+ }
683
+ function isTopLayer$1(element) {
684
+ return [':popover-open', ':modal'].some(selector => {
685
+ try {
686
+ return element.matches(selector);
687
+ } catch (e) {
688
+ return false;
689
+ }
690
+ });
691
+ }
692
+ function isContainingBlock(elementOrCss) {
693
+ const webkit = isWebKit();
694
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
695
+
696
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
697
+ return css.transform !== 'none' || css.perspective !== 'none' || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
698
+ }
699
+ function getContainingBlock(element) {
700
+ let currentNode = getParentNode(element);
701
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
702
+ if (isContainingBlock(currentNode)) {
703
+ return currentNode;
704
+ } else if (isTopLayer$1(currentNode)) {
705
+ return null;
706
+ }
707
+ currentNode = getParentNode(currentNode);
708
+ }
709
+ return null;
710
+ }
711
+ function isWebKit() {
712
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
713
+ return CSS.supports('-webkit-backdrop-filter', 'none');
714
+ }
715
+ function isLastTraversableNode(node) {
716
+ return ['html', 'body', '#document'].includes(getNodeName(node));
717
+ }
718
+ function getComputedStyle$1(element) {
719
+ return getWindow(element).getComputedStyle(element);
720
+ }
721
+ function getNodeScroll(element) {
722
+ if (isElement(element)) {
723
+ return {
724
+ scrollLeft: element.scrollLeft,
725
+ scrollTop: element.scrollTop
726
+ };
727
+ }
728
+ return {
729
+ scrollLeft: element.scrollX,
730
+ scrollTop: element.scrollY
731
+ };
732
+ }
733
+ function getParentNode(node) {
734
+ if (getNodeName(node) === 'html') {
735
+ return node;
736
+ }
737
+ const result =
738
+ // Step into the shadow DOM of the parent of a slotted node.
739
+ node.assignedSlot ||
740
+ // DOM Element detected.
741
+ node.parentNode ||
742
+ // ShadowRoot detected.
743
+ isShadowRoot(node) && node.host ||
744
+ // Fallback.
745
+ getDocumentElement(node);
746
+ return isShadowRoot(result) ? result.host : result;
747
+ }
748
+ function getNearestOverflowAncestor(node) {
749
+ const parentNode = getParentNode(node);
750
+ if (isLastTraversableNode(parentNode)) {
751
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
752
+ }
753
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
754
+ return parentNode;
755
+ }
756
+ return getNearestOverflowAncestor(parentNode);
757
+ }
758
+ function getOverflowAncestors(node, list, traverseIframes) {
759
+ var _node$ownerDocument2;
760
+ if (list === void 0) {
761
+ list = [];
762
+ }
763
+ if (traverseIframes === void 0) {
764
+ traverseIframes = true;
765
+ }
766
+ const scrollableAncestor = getNearestOverflowAncestor(node);
767
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
768
+ const win = getWindow(scrollableAncestor);
769
+ if (isBody) {
770
+ const frameElement = getFrameElement(win);
771
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
772
+ }
773
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
774
+ }
775
+ function getFrameElement(win) {
776
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
777
+ }
778
+
779
+ function activeElement(doc) {
780
+ let activeElement = doc.activeElement;
781
+ while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
782
+ var _activeElement;
783
+ activeElement = activeElement.shadowRoot.activeElement;
784
+ }
785
+ return activeElement;
786
+ }
787
+ function contains(parent, child) {
788
+ if (!parent || !child) {
789
+ return false;
790
+ }
791
+ const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
792
+
793
+ // First, attempt with faster native method
794
+ if (parent.contains(child)) {
795
+ return true;
796
+ }
797
+
798
+ // then fallback to custom implementation with Shadow DOM support
799
+ if (rootNode && isShadowRoot(rootNode)) {
800
+ let next = child;
801
+ while (next) {
802
+ if (parent === next) {
803
+ return true;
804
+ }
805
+ // @ts-ignore
806
+ next = next.parentNode || next.host;
807
+ }
808
+ }
809
+
810
+ // Give up, the result is false
811
+ return false;
812
+ }
813
+ function isSafari() {
814
+ // Chrome DevTools does not complain about navigator.vendor
815
+ return /apple/i.test(navigator.vendor);
816
+ }
817
+ function getDocument(node) {
818
+ return (node == null ? void 0 : node.ownerDocument) || document;
819
+ }
820
+
821
+ /*!
822
+ * tabbable 6.2.0
823
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
824
+ */
825
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
826
+ // `:not([inert], [inert] *)` (Feb 2023)
827
+ // CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
828
+ // the entire query to fail, resulting in no nodes found, which will break a lot
829
+ // of things... so we have to rely on JS to identify nodes inside an inert container
830
+ var candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable="false"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];
831
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
832
+ var NoElement = typeof Element === 'undefined';
833
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
834
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
835
+ var _element$getRootNode;
836
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
837
+ } : function (element) {
838
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
839
+ };
840
+
841
+ /**
842
+ * Determines if a node is inert or in an inert ancestor.
843
+ * @param {Element} [node]
844
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
845
+ * see if any of them are inert. If false, only `node` itself is considered.
846
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
847
+ * False if `node` is falsy.
848
+ */
849
+ var isInert = function isInert(node, lookUp) {
850
+ var _node$getAttribute;
851
+ if (lookUp === void 0) {
852
+ lookUp = true;
853
+ }
854
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
855
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
856
+ // if it's `null` (not specified) or 'false', it's an active element
857
+ 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');
858
+ var inert = inertAtt === '' || inertAtt === 'true';
859
+
860
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
861
+ // if it weren't for `matches()` not being a function on shadow roots; the following
862
+ // code works for any kind of node
863
+ // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
864
+ // so it likely would not support `:is([inert] *)` either...
865
+ var result = inert || lookUp && node && isInert(node.parentNode); // recursive
866
+
867
+ return result;
868
+ };
869
+
870
+ /**
871
+ * Determines if a node's content is editable.
872
+ * @param {Element} [node]
873
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
874
+ */
875
+ var isContentEditable = function isContentEditable(node) {
876
+ var _node$getAttribute2;
877
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
878
+ // to use the attribute directly to check for this, which can either be empty or 'true';
879
+ // if it's `null` (not specified) or 'false', it's a non-editable element
880
+ 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');
881
+ return attValue === '' || attValue === 'true';
882
+ };
883
+
884
+ /**
885
+ * @param {Element} el container to check in
886
+ * @param {boolean} includeContainer add container to check
887
+ * @param {(node: Element) => boolean} filter filter candidates
888
+ * @returns {Element[]}
889
+ */
890
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
891
+ // even if `includeContainer=false`, we still have to check it for inertness because
892
+ // if it's inert, all its children are inert
893
+ if (isInert(el)) {
894
+ return [];
895
+ }
896
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
897
+ if (includeContainer && matches.call(el, candidateSelector)) {
898
+ candidates.unshift(el);
899
+ }
900
+ candidates = candidates.filter(filter);
901
+ return candidates;
902
+ };
903
+
904
+ /**
905
+ * @callback GetShadowRoot
906
+ * @param {Element} element to check for shadow root
907
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
908
+ */
909
+
910
+ /**
911
+ * @callback ShadowRootFilter
912
+ * @param {Element} shadowHostNode the element which contains shadow content
913
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
914
+ */
915
+
916
+ /**
917
+ * @typedef {Object} CandidateScope
918
+ * @property {Element} scopeParent contains inner candidates
919
+ * @property {Element[]} candidates list of candidates found in the scope parent
920
+ */
921
+
922
+ /**
923
+ * @typedef {Object} IterativeOptions
924
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
925
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
926
+ * or a boolean stating if it has an undisclosed shadow root
927
+ * @property {(node: Element) => boolean} filter filter candidates
928
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
929
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
930
+ */
931
+
932
+ /**
933
+ * @param {Element[]} elements list of element containers to match candidates from
934
+ * @param {boolean} includeContainer add container list to check
935
+ * @param {IterativeOptions} options
936
+ * @returns {Array.<Element|CandidateScope>}
937
+ */
938
+ var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
939
+ var candidates = [];
940
+ var elementsToCheck = Array.from(elements);
941
+ while (elementsToCheck.length) {
942
+ var element = elementsToCheck.shift();
943
+ if (isInert(element, false)) {
944
+ // no need to look up since we're drilling down
945
+ // anything inside this container will also be inert
946
+ continue;
947
+ }
948
+ if (element.tagName === 'SLOT') {
949
+ // add shadow dom slot scope (slot itself cannot be focusable)
950
+ var assigned = element.assignedElements();
951
+ var content = assigned.length ? assigned : element.children;
952
+ var nestedCandidates = getCandidatesIteratively(content, true, options);
953
+ if (options.flatten) {
954
+ candidates.push.apply(candidates, nestedCandidates);
955
+ } else {
956
+ candidates.push({
957
+ scopeParent: element,
958
+ candidates: nestedCandidates
959
+ });
960
+ }
961
+ } else {
962
+ // check candidate element
963
+ var validCandidate = matches.call(element, candidateSelector);
964
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
965
+ candidates.push(element);
966
+ }
967
+
968
+ // iterate over shadow content if possible
969
+ var shadowRoot = element.shadowRoot ||
970
+ // check for an undisclosed shadow
971
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
972
+
973
+ // no inert look up because we're already drilling down and checking for inertness
974
+ // on the way down, so all containers to this root node should have already been
975
+ // vetted as non-inert
976
+ var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
977
+ if (shadowRoot && validShadowRoot) {
978
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
979
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
980
+ // child candidates found because they're likely slotted elements (elements that are
981
+ // children of the web component element (which has the shadow), in the light dom, but
982
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
983
+ // _after_ we return from this recursive call
984
+ var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
985
+ if (options.flatten) {
986
+ candidates.push.apply(candidates, _nestedCandidates);
987
+ } else {
988
+ candidates.push({
989
+ scopeParent: element,
990
+ candidates: _nestedCandidates
991
+ });
992
+ }
993
+ } else {
994
+ // there's not shadow so just dig into the element's (light dom) children
995
+ // __without__ giving the element special scope treatment
996
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
997
+ }
998
+ }
999
+ }
1000
+ return candidates;
1001
+ };
1002
+
1003
+ /**
1004
+ * @private
1005
+ * Determines if the node has an explicitly specified `tabindex` attribute.
1006
+ * @param {HTMLElement} node
1007
+ * @returns {boolean} True if so; false if not.
1008
+ */
1009
+ var hasTabIndex = function hasTabIndex(node) {
1010
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
1011
+ };
1012
+
1013
+ /**
1014
+ * Determine the tab index of a given node.
1015
+ * @param {HTMLElement} node
1016
+ * @returns {number} Tab order (negative, 0, or positive number).
1017
+ * @throws {Error} If `node` is falsy.
1018
+ */
1019
+ var getTabIndex = function getTabIndex(node) {
1020
+ if (!node) {
1021
+ throw new Error('No node provided');
1022
+ }
1023
+ if (node.tabIndex < 0) {
1024
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
1025
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
1026
+ // yet they are still part of the regular tab order; in FF, they get a default
1027
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
1028
+ // order, consider their tab index to be 0.
1029
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
1030
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
1031
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
1032
+ return 0;
1033
+ }
1034
+ }
1035
+ return node.tabIndex;
1036
+ };
1037
+
1038
+ /**
1039
+ * Determine the tab index of a given node __for sort order purposes__.
1040
+ * @param {HTMLElement} node
1041
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
1042
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
1043
+ * inserted into the correct sort position.
1044
+ * @returns {number} Tab order (negative, 0, or positive number).
1045
+ */
1046
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
1047
+ var tabIndex = getTabIndex(node);
1048
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
1049
+ return 0;
1050
+ }
1051
+ return tabIndex;
1052
+ };
1053
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
1054
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
1055
+ };
1056
+ var isInput = function isInput(node) {
1057
+ return node.tagName === 'INPUT';
1058
+ };
1059
+ var isHiddenInput = function isHiddenInput(node) {
1060
+ return isInput(node) && node.type === 'hidden';
1061
+ };
1062
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
1063
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
1064
+ return child.tagName === 'SUMMARY';
1065
+ });
1066
+ return r;
1067
+ };
1068
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
1069
+ for (var i = 0; i < nodes.length; i++) {
1070
+ if (nodes[i].checked && nodes[i].form === form) {
1071
+ return nodes[i];
1072
+ }
1073
+ }
1074
+ };
1075
+ var isTabbableRadio = function isTabbableRadio(node) {
1076
+ if (!node.name) {
1077
+ return true;
1078
+ }
1079
+ var radioScope = node.form || getRootNode(node);
1080
+ var queryRadios = function queryRadios(name) {
1081
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
1082
+ };
1083
+ var radioSet;
1084
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
1085
+ radioSet = queryRadios(window.CSS.escape(node.name));
1086
+ } else {
1087
+ try {
1088
+ radioSet = queryRadios(node.name);
1089
+ } catch (err) {
1090
+ // eslint-disable-next-line no-console
1091
+ 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);
1092
+ return false;
1093
+ }
1094
+ }
1095
+ var checked = getCheckedRadio(radioSet, node.form);
1096
+ return !checked || checked === node;
1097
+ };
1098
+ var isRadio = function isRadio(node) {
1099
+ return isInput(node) && node.type === 'radio';
1100
+ };
1101
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
1102
+ return isRadio(node) && !isTabbableRadio(node);
1103
+ };
1104
+
1105
+ // determines if a node is ultimately attached to the window's document
1106
+ var isNodeAttached = function isNodeAttached(node) {
1107
+ var _nodeRoot;
1108
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
1109
+ // (but NOT _the_ document; see second 'If' comment below for more).
1110
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
1111
+ // is attached, and the one we need to check if it's in the document or not (because the
1112
+ // shadow, and all nodes it contains, is never considered in the document since shadows
1113
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
1114
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
1115
+ // visibility, including all the nodes it contains). The host could be any normal node,
1116
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
1117
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
1118
+ // tested).
1119
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
1120
+ // that is attached (or find none) because the node might be in nested shadows...
1121
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
1122
+ // document (per the docs) and while it's a Document-type object, that document does not
1123
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
1124
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
1125
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
1126
+ // node is actually detached.
1127
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
1128
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
1129
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
1130
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
1131
+ var nodeRoot = node && getRootNode(node);
1132
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
1133
+
1134
+ // in some cases, a detached node will return itself as the root instead of a document or
1135
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
1136
+ var attached = false;
1137
+ if (nodeRoot && nodeRoot !== node) {
1138
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
1139
+ 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));
1140
+ while (!attached && nodeRootHost) {
1141
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
1142
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
1143
+ // which means we need to get the host's host and check if that parent host is contained
1144
+ // in (i.e. attached to) the document
1145
+ nodeRoot = getRootNode(nodeRootHost);
1146
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
1147
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
1148
+ }
1149
+ }
1150
+ return attached;
1151
+ };
1152
+ var isZeroArea = function isZeroArea(node) {
1153
+ var _node$getBoundingClie = node.getBoundingClientRect(),
1154
+ width = _node$getBoundingClie.width,
1155
+ height = _node$getBoundingClie.height;
1156
+ return width === 0 && height === 0;
1157
+ };
1158
+ var isHidden = function isHidden(node, _ref) {
1159
+ var displayCheck = _ref.displayCheck,
1160
+ getShadowRoot = _ref.getShadowRoot;
1161
+ // NOTE: visibility will be `undefined` if node is detached from the document
1162
+ // (see notes about this further down), which means we will consider it visible
1163
+ // (this is legacy behavior from a very long way back)
1164
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
1165
+ // _visibility_ check, not a _display_ check
1166
+ if (getComputedStyle(node).visibility === 'hidden') {
1167
+ return true;
1168
+ }
1169
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
1170
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
1171
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
1172
+ return true;
1173
+ }
1174
+ if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
1175
+ if (typeof getShadowRoot === 'function') {
1176
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
1177
+ // 'non-zero-area' fallback
1178
+ var originalNode = node;
1179
+ while (node) {
1180
+ var parentElement = node.parentElement;
1181
+ var rootNode = getRootNode(node);
1182
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
1183
+ ) {
1184
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
1185
+ // fall back to a non-zero-area test
1186
+ return isZeroArea(node);
1187
+ } else if (node.assignedSlot) {
1188
+ // iterate up slot
1189
+ node = node.assignedSlot;
1190
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
1191
+ // cross shadow boundary
1192
+ node = rootNode.host;
1193
+ } else {
1194
+ // iterate up normal dom
1195
+ node = parentElement;
1196
+ }
1197
+ }
1198
+ node = originalNode;
1199
+ }
1200
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
1201
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
1202
+ // it might be a falsy value, which means shadow DOM support is disabled
1203
+
1204
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
1205
+ // now we can just test to see if it would normally be visible or not, provided it's
1206
+ // attached to the main document.
1207
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
1208
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
1209
+
1210
+ if (isNodeAttached(node)) {
1211
+ // this works wherever the node is: if there's at least one client rect, it's
1212
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
1213
+ // node itself is hidden in place of its contents; and there's no need to search
1214
+ // up the hierarchy either
1215
+ return !node.getClientRects().length;
1216
+ }
1217
+
1218
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
1219
+ // API will __always__ return zero rects (this can happen, for example, if React
1220
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
1221
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
1222
+ //
1223
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
1224
+ // because styles are only computed for nodes that are in the document.
1225
+ //
1226
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
1227
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
1228
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
1229
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
1230
+ // considering __everything__ to be visible because of the innability to determine styles.
1231
+ //
1232
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
1233
+ // nodes as visible with the 'none' fallback.__
1234
+ if (displayCheck !== 'legacy-full') {
1235
+ return true; // hidden
1236
+ }
1237
+ // else, fallback to 'none' mode and consider the node visible
1238
+ } else if (displayCheck === 'non-zero-area') {
1239
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
1240
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
1241
+ // client rect, we don't special-case for whether the node is attached or not. In
1242
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
1243
+ // times, and that includes attached or not.
1244
+ return isZeroArea(node);
1245
+ }
1246
+
1247
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
1248
+ // it's visible
1249
+ return false;
1250
+ };
1251
+
1252
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
1253
+ // unless they are in the _first_ <legend> element of the top-most disabled
1254
+ // fieldset
1255
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
1256
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
1257
+ var parentNode = node.parentElement;
1258
+ // check if `node` is contained in a disabled <fieldset>
1259
+ while (parentNode) {
1260
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
1261
+ // look for the first <legend> among the children of the disabled <fieldset>
1262
+ for (var i = 0; i < parentNode.children.length; i++) {
1263
+ var child = parentNode.children.item(i);
1264
+ // when the first <legend> (in document order) is found
1265
+ if (child.tagName === 'LEGEND') {
1266
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
1267
+ // return whether `node` is a descendant of its first <legend>
1268
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
1269
+ }
1270
+ }
1271
+ // the disabled <fieldset> containing `node` has no <legend>
1272
+ return true;
1273
+ }
1274
+ parentNode = parentNode.parentElement;
1275
+ }
1276
+ }
1277
+
1278
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
1279
+ // enabled/disabled state
1280
+ return false;
1281
+ };
1282
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
1283
+ if (node.disabled ||
1284
+ // we must do an inert look up to filter out any elements inside an inert ancestor
1285
+ // because we're limited in the type of selectors we can use in JSDom (see related
1286
+ // note related to `candidateSelectors`)
1287
+ isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
1288
+ // For a details element with a summary, the summary element gets the focus
1289
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
1290
+ return false;
1291
+ }
1292
+ return true;
1293
+ };
1294
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
1295
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
1296
+ return false;
1297
+ }
1298
+ return true;
1299
+ };
1300
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
1301
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
1302
+ if (isNaN(tabIndex) || tabIndex >= 0) {
1303
+ return true;
1304
+ }
1305
+ // If a custom element has an explicit negative tabindex,
1306
+ // browsers will not allow tab targeting said element's children.
1307
+ return false;
1308
+ };
1309
+
1310
+ /**
1311
+ * @param {Array.<Element|CandidateScope>} candidates
1312
+ * @returns Element[]
1313
+ */
1314
+ var sortByOrder = function sortByOrder(candidates) {
1315
+ var regularTabbables = [];
1316
+ var orderedTabbables = [];
1317
+ candidates.forEach(function (item, i) {
1318
+ var isScope = !!item.scopeParent;
1319
+ var element = isScope ? item.scopeParent : item;
1320
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
1321
+ var elements = isScope ? sortByOrder(item.candidates) : element;
1322
+ if (candidateTabindex === 0) {
1323
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
1324
+ } else {
1325
+ orderedTabbables.push({
1326
+ documentOrder: i,
1327
+ tabIndex: candidateTabindex,
1328
+ item: item,
1329
+ isScope: isScope,
1330
+ content: elements
1331
+ });
1332
+ }
1333
+ });
1334
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
1335
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
1336
+ return acc;
1337
+ }, []).concat(regularTabbables);
1338
+ };
1339
+ var tabbable = function tabbable(container, options) {
1340
+ options = options || {};
1341
+ var candidates;
1342
+ if (options.getShadowRoot) {
1343
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
1344
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
1345
+ flatten: false,
1346
+ getShadowRoot: options.getShadowRoot,
1347
+ shadowRootFilter: isValidShadowRootTabbable
1348
+ });
1349
+ } else {
1350
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
1351
+ }
1352
+ return sortByOrder(candidates);
1353
+ };
1354
+
1355
+ function getCssDimensions(element) {
1356
+ const css = getComputedStyle$1(element);
1357
+ // In testing environments, the `width` and `height` properties are empty
1358
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
1359
+ let width = parseFloat(css.width) || 0;
1360
+ let height = parseFloat(css.height) || 0;
1361
+ const hasOffset = isHTMLElement(element);
1362
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
1363
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
1364
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1365
+ if (shouldFallback) {
1366
+ width = offsetWidth;
1367
+ height = offsetHeight;
1368
+ }
1369
+ return {
1370
+ width,
1371
+ height,
1372
+ $: shouldFallback
1373
+ };
1374
+ }
1375
+
1376
+ function unwrapElement(element) {
1377
+ return !isElement(element) ? element.contextElement : element;
1378
+ }
1379
+
1380
+ function getScale(element) {
1381
+ const domElement = unwrapElement(element);
1382
+ if (!isHTMLElement(domElement)) {
1383
+ return createCoords(1);
1384
+ }
1385
+ const rect = domElement.getBoundingClientRect();
1386
+ const {
1387
+ width,
1388
+ height,
1389
+ $
1390
+ } = getCssDimensions(domElement);
1391
+ let x = ($ ? round(rect.width) : rect.width) / width;
1392
+ let y = ($ ? round(rect.height) : rect.height) / height;
1393
+
1394
+ // 0, NaN, or Infinity should always fallback to 1.
1395
+
1396
+ if (!x || !Number.isFinite(x)) {
1397
+ x = 1;
1398
+ }
1399
+ if (!y || !Number.isFinite(y)) {
1400
+ y = 1;
1401
+ }
1402
+ return {
1403
+ x,
1404
+ y
1405
+ };
1406
+ }
1407
+
1408
+ const noOffsets = /*#__PURE__*/createCoords(0);
1409
+ function getVisualOffsets(element) {
1410
+ const win = getWindow(element);
1411
+ if (!isWebKit() || !win.visualViewport) {
1412
+ return noOffsets;
1413
+ }
1414
+ return {
1415
+ x: win.visualViewport.offsetLeft,
1416
+ y: win.visualViewport.offsetTop
1417
+ };
1418
+ }
1419
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1420
+ if (isFixed === void 0) {
1421
+ isFixed = false;
1422
+ }
1423
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1424
+ return false;
1425
+ }
1426
+ return isFixed;
1427
+ }
1428
+
1429
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1430
+ if (includeScale === void 0) {
1431
+ includeScale = false;
1432
+ }
1433
+ if (isFixedStrategy === void 0) {
1434
+ isFixedStrategy = false;
1435
+ }
1436
+ const clientRect = element.getBoundingClientRect();
1437
+ const domElement = unwrapElement(element);
1438
+ let scale = createCoords(1);
1439
+ if (includeScale) {
1440
+ if (offsetParent) {
1441
+ if (isElement(offsetParent)) {
1442
+ scale = getScale(offsetParent);
1443
+ }
1444
+ } else {
1445
+ scale = getScale(element);
1446
+ }
1447
+ }
1448
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1449
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
1450
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
1451
+ let width = clientRect.width / scale.x;
1452
+ let height = clientRect.height / scale.y;
1453
+ if (domElement) {
1454
+ const win = getWindow(domElement);
1455
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1456
+ let currentWin = win;
1457
+ let currentIFrame = currentWin.frameElement;
1458
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
1459
+ const iframeScale = getScale(currentIFrame);
1460
+ const iframeRect = currentIFrame.getBoundingClientRect();
1461
+ const css = getComputedStyle$1(currentIFrame);
1462
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1463
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1464
+ x *= iframeScale.x;
1465
+ y *= iframeScale.y;
1466
+ width *= iframeScale.x;
1467
+ height *= iframeScale.y;
1468
+ x += left;
1469
+ y += top;
1470
+ currentWin = getWindow(currentIFrame);
1471
+ currentIFrame = currentWin.frameElement;
1472
+ }
1473
+ }
1474
+ return rectToClientRect({
1475
+ width,
1476
+ height,
1477
+ x,
1478
+ y
1479
+ });
1480
+ }
1481
+
1482
+ const topLayerSelectors = [':popover-open', ':modal'];
1483
+ function isTopLayer(floating) {
1484
+ return topLayerSelectors.some(selector => {
1485
+ try {
1486
+ return floating.matches(selector);
1487
+ } catch (e) {
1488
+ return false;
1489
+ }
1490
+ });
1491
+ }
1492
+
1493
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1494
+ let {
1495
+ elements,
1496
+ rect,
1497
+ offsetParent,
1498
+ strategy
1499
+ } = _ref;
1500
+ const isFixed = strategy === 'fixed';
1501
+ const documentElement = getDocumentElement(offsetParent);
1502
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
1503
+ if (offsetParent === documentElement || topLayer && isFixed) {
1504
+ return rect;
1505
+ }
1506
+ let scroll = {
1507
+ scrollLeft: 0,
1508
+ scrollTop: 0
1509
+ };
1510
+ let scale = createCoords(1);
1511
+ const offsets = createCoords(0);
1512
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1513
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1514
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1515
+ scroll = getNodeScroll(offsetParent);
1516
+ }
1517
+ if (isHTMLElement(offsetParent)) {
1518
+ const offsetRect = getBoundingClientRect(offsetParent);
1519
+ scale = getScale(offsetParent);
1520
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1521
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1522
+ }
1523
+ }
1524
+ return {
1525
+ width: rect.width * scale.x,
1526
+ height: rect.height * scale.y,
1527
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
1528
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
1529
+ };
1530
+ }
1531
+
1532
+ function getClientRects(element) {
1533
+ return Array.from(element.getClientRects());
1534
+ }
1535
+
1536
+ function getWindowScrollBarX(element) {
1537
+ // If <html> has a CSS width greater than the viewport, then this will be
1538
+ // incorrect for RTL.
1539
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
1540
+ }
1541
+
1542
+ // Gets the entire size of the scrollable document area, even extending outside
1543
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
1544
+ function getDocumentRect(element) {
1545
+ const html = getDocumentElement(element);
1546
+ const scroll = getNodeScroll(element);
1547
+ const body = element.ownerDocument.body;
1548
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1549
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1550
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1551
+ const y = -scroll.scrollTop;
1552
+ if (getComputedStyle$1(body).direction === 'rtl') {
1553
+ x += max(html.clientWidth, body.clientWidth) - width;
1554
+ }
1555
+ return {
1556
+ width,
1557
+ height,
1558
+ x,
1559
+ y
1560
+ };
1561
+ }
1562
+
1563
+ function getViewportRect(element, strategy) {
1564
+ const win = getWindow(element);
1565
+ const html = getDocumentElement(element);
1566
+ const visualViewport = win.visualViewport;
1567
+ let width = html.clientWidth;
1568
+ let height = html.clientHeight;
1569
+ let x = 0;
1570
+ let y = 0;
1571
+ if (visualViewport) {
1572
+ width = visualViewport.width;
1573
+ height = visualViewport.height;
1574
+ const visualViewportBased = isWebKit();
1575
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
1576
+ x = visualViewport.offsetLeft;
1577
+ y = visualViewport.offsetTop;
1578
+ }
1579
+ }
1580
+ return {
1581
+ width,
1582
+ height,
1583
+ x,
1584
+ y
1585
+ };
1586
+ }
1587
+
1588
+ // Returns the inner client rect, subtracting scrollbars if present.
1589
+ function getInnerBoundingClientRect(element, strategy) {
1590
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
1591
+ const top = clientRect.top + element.clientTop;
1592
+ const left = clientRect.left + element.clientLeft;
1593
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1594
+ const width = element.clientWidth * scale.x;
1595
+ const height = element.clientHeight * scale.y;
1596
+ const x = left * scale.x;
1597
+ const y = top * scale.y;
1598
+ return {
1599
+ width,
1600
+ height,
1601
+ x,
1602
+ y
1603
+ };
1604
+ }
1605
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1606
+ let rect;
1607
+ if (clippingAncestor === 'viewport') {
1608
+ rect = getViewportRect(element, strategy);
1609
+ } else if (clippingAncestor === 'document') {
1610
+ rect = getDocumentRect(getDocumentElement(element));
1611
+ } else if (isElement(clippingAncestor)) {
1612
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1613
+ } else {
1614
+ const visualOffsets = getVisualOffsets(element);
1615
+ rect = {
1616
+ ...clippingAncestor,
1617
+ x: clippingAncestor.x - visualOffsets.x,
1618
+ y: clippingAncestor.y - visualOffsets.y
1619
+ };
1620
+ }
1621
+ return rectToClientRect(rect);
1622
+ }
1623
+ function hasFixedPositionAncestor(element, stopNode) {
1624
+ const parentNode = getParentNode(element);
1625
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1626
+ return false;
1627
+ }
1628
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
1629
+ }
1630
+
1631
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
1632
+ // clipping (or hiding) child elements. This returns all clipping ancestors
1633
+ // of the given element up the tree.
1634
+ function getClippingElementAncestors(element, cache) {
1635
+ const cachedResult = cache.get(element);
1636
+ if (cachedResult) {
1637
+ return cachedResult;
1638
+ }
1639
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
1640
+ let currentContainingBlockComputedStyle = null;
1641
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
1642
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1643
+
1644
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1645
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1646
+ const computedStyle = getComputedStyle$1(currentNode);
1647
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1648
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
1649
+ currentContainingBlockComputedStyle = null;
1650
+ }
1651
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1652
+ if (shouldDropCurrentNode) {
1653
+ // Drop non-containing blocks.
1654
+ result = result.filter(ancestor => ancestor !== currentNode);
1655
+ } else {
1656
+ // Record last containing block for next iteration.
1657
+ currentContainingBlockComputedStyle = computedStyle;
1658
+ }
1659
+ currentNode = getParentNode(currentNode);
1660
+ }
1661
+ cache.set(element, result);
1662
+ return result;
1663
+ }
1664
+
1665
+ // Gets the maximum area that the element is visible in due to any number of
1666
+ // clipping ancestors.
1667
+ function getClippingRect(_ref) {
1668
+ let {
1669
+ element,
1670
+ boundary,
1671
+ rootBoundary,
1672
+ strategy
1673
+ } = _ref;
1674
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
1675
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1676
+ const firstClippingAncestor = clippingAncestors[0];
1677
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
1678
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1679
+ accRect.top = max(rect.top, accRect.top);
1680
+ accRect.right = min(rect.right, accRect.right);
1681
+ accRect.bottom = min(rect.bottom, accRect.bottom);
1682
+ accRect.left = max(rect.left, accRect.left);
1683
+ return accRect;
1684
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1685
+ return {
1686
+ width: clippingRect.right - clippingRect.left,
1687
+ height: clippingRect.bottom - clippingRect.top,
1688
+ x: clippingRect.left,
1689
+ y: clippingRect.top
1690
+ };
1691
+ }
1692
+
1693
+ function getDimensions(element) {
1694
+ const {
1695
+ width,
1696
+ height
1697
+ } = getCssDimensions(element);
1698
+ return {
1699
+ width,
1700
+ height
1701
+ };
1702
+ }
1703
+
1704
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1705
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1706
+ const documentElement = getDocumentElement(offsetParent);
1707
+ const isFixed = strategy === 'fixed';
1708
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1709
+ let scroll = {
1710
+ scrollLeft: 0,
1711
+ scrollTop: 0
1712
+ };
1713
+ const offsets = createCoords(0);
1714
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1715
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1716
+ scroll = getNodeScroll(offsetParent);
1717
+ }
1718
+ if (isOffsetParentAnElement) {
1719
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1720
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1721
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1722
+ } else if (documentElement) {
1723
+ offsets.x = getWindowScrollBarX(documentElement);
1724
+ }
1725
+ }
1726
+ const x = rect.left + scroll.scrollLeft - offsets.x;
1727
+ const y = rect.top + scroll.scrollTop - offsets.y;
1728
+ return {
1729
+ x,
1730
+ y,
1731
+ width: rect.width,
1732
+ height: rect.height
1733
+ };
1734
+ }
1735
+
1736
+ function getTrueOffsetParent(element, polyfill) {
1737
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
1738
+ return null;
1739
+ }
1740
+ if (polyfill) {
1741
+ return polyfill(element);
1742
+ }
1743
+ return element.offsetParent;
1744
+ }
1745
+
1746
+ // Gets the closest ancestor positioned element. Handles some edge cases,
1747
+ // such as table ancestors and cross browser bugs.
1748
+ function getOffsetParent(element, polyfill) {
1749
+ const window = getWindow(element);
1750
+ if (!isHTMLElement(element) || isTopLayer(element)) {
1751
+ return window;
1752
+ }
1753
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1754
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
1755
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1756
+ }
1757
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
1758
+ return window;
1759
+ }
1760
+ return offsetParent || getContainingBlock(element) || window;
1761
+ }
1762
+
1763
+ const getElementRects = async function (data) {
1764
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1765
+ const getDimensionsFn = this.getDimensions;
1766
+ return {
1767
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
1768
+ floating: {
1769
+ x: 0,
1770
+ y: 0,
1771
+ ...(await getDimensionsFn(data.floating))
1772
+ }
1773
+ };
1774
+ };
1775
+
1776
+ function isRTL(element) {
1777
+ return getComputedStyle$1(element).direction === 'rtl';
1778
+ }
1779
+
1780
+ const platform = {
1781
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1782
+ getDocumentElement,
1783
+ getClippingRect,
1784
+ getOffsetParent,
1785
+ getElementRects,
1786
+ getClientRects,
1787
+ getDimensions,
1788
+ getScale,
1789
+ isElement,
1790
+ isRTL
1791
+ };
1792
+
1793
+ // https://samthor.au/2021/observing-dom/
1794
+ function observeMove(element, onMove) {
1795
+ let io = null;
1796
+ let timeoutId;
1797
+ const root = getDocumentElement(element);
1798
+ function cleanup() {
1799
+ var _io;
1800
+ clearTimeout(timeoutId);
1801
+ (_io = io) == null || _io.disconnect();
1802
+ io = null;
1803
+ }
1804
+ function refresh(skip, threshold) {
1805
+ if (skip === void 0) {
1806
+ skip = false;
1807
+ }
1808
+ if (threshold === void 0) {
1809
+ threshold = 1;
1810
+ }
1811
+ cleanup();
1812
+ const {
1813
+ left,
1814
+ top,
1815
+ width,
1816
+ height
1817
+ } = element.getBoundingClientRect();
1818
+ if (!skip) {
1819
+ onMove();
1820
+ }
1821
+ if (!width || !height) {
1822
+ return;
1823
+ }
1824
+ const insetTop = floor(top);
1825
+ const insetRight = floor(root.clientWidth - (left + width));
1826
+ const insetBottom = floor(root.clientHeight - (top + height));
1827
+ const insetLeft = floor(left);
1828
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1829
+ const options = {
1830
+ rootMargin,
1831
+ threshold: max(0, min(1, threshold)) || 1
1832
+ };
1833
+ let isFirstUpdate = true;
1834
+ function handleObserve(entries) {
1835
+ const ratio = entries[0].intersectionRatio;
1836
+ if (ratio !== threshold) {
1837
+ if (!isFirstUpdate) {
1838
+ return refresh();
1839
+ }
1840
+ if (!ratio) {
1841
+ timeoutId = setTimeout(() => {
1842
+ refresh(false, 1e-7);
1843
+ }, 100);
1844
+ } else {
1845
+ refresh(false, ratio);
1846
+ }
1847
+ }
1848
+ isFirstUpdate = false;
1849
+ }
1850
+
1851
+ // Older browsers don't support a `document` as the root and will throw an
1852
+ // error.
1853
+ try {
1854
+ io = new IntersectionObserver(handleObserve, {
1855
+ ...options,
1856
+ // Handle <iframe>s
1857
+ root: root.ownerDocument
1858
+ });
1859
+ } catch (e) {
1860
+ io = new IntersectionObserver(handleObserve, options);
1861
+ }
1862
+ io.observe(element);
1863
+ }
1864
+ refresh(true);
1865
+ return cleanup;
1866
+ }
1867
+
1868
+ /**
1869
+ * Automatically updates the position of the floating element when necessary.
1870
+ * Should only be called when the floating element is mounted on the DOM or
1871
+ * visible on the screen.
1872
+ * @returns cleanup function that should be invoked when the floating element is
1873
+ * removed from the DOM or hidden from the screen.
1874
+ * @see https://floating-ui.com/docs/autoUpdate
1875
+ */
1876
+ function autoUpdate(reference, floating, update, options) {
1877
+ if (options === void 0) {
1878
+ options = {};
1879
+ }
1880
+ const {
1881
+ ancestorScroll = true,
1882
+ ancestorResize = true,
1883
+ elementResize = typeof ResizeObserver === 'function',
1884
+ layoutShift = typeof IntersectionObserver === 'function',
1885
+ animationFrame = false
1886
+ } = options;
1887
+ const referenceEl = unwrapElement(reference);
1888
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
1889
+ ancestors.forEach(ancestor => {
1890
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
1891
+ passive: true
1892
+ });
1893
+ ancestorResize && ancestor.addEventListener('resize', update);
1894
+ });
1895
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
1896
+ let reobserveFrame = -1;
1897
+ let resizeObserver = null;
1898
+ if (elementResize) {
1899
+ resizeObserver = new ResizeObserver(_ref => {
1900
+ let [firstEntry] = _ref;
1901
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
1902
+ // Prevent update loops when using the `size` middleware.
1903
+ // https://github.com/floating-ui/floating-ui/issues/1740
1904
+ resizeObserver.unobserve(floating);
1905
+ cancelAnimationFrame(reobserveFrame);
1906
+ reobserveFrame = requestAnimationFrame(() => {
1907
+ var _resizeObserver;
1908
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
1909
+ });
1910
+ }
1911
+ update();
1912
+ });
1913
+ if (referenceEl && !animationFrame) {
1914
+ resizeObserver.observe(referenceEl);
1915
+ }
1916
+ resizeObserver.observe(floating);
1917
+ }
1918
+ let frameId;
1919
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1920
+ if (animationFrame) {
1921
+ frameLoop();
1922
+ }
1923
+ function frameLoop() {
1924
+ const nextRefRect = getBoundingClientRect(reference);
1925
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
1926
+ update();
1927
+ }
1928
+ prevRefRect = nextRefRect;
1929
+ frameId = requestAnimationFrame(frameLoop);
1930
+ }
1931
+ update();
1932
+ return () => {
1933
+ var _resizeObserver2;
1934
+ ancestors.forEach(ancestor => {
1935
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
1936
+ ancestorResize && ancestor.removeEventListener('resize', update);
1937
+ });
1938
+ cleanupIo == null || cleanupIo();
1939
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
1940
+ resizeObserver = null;
1941
+ if (animationFrame) {
1942
+ cancelAnimationFrame(frameId);
1943
+ }
1944
+ };
1945
+ }
1946
+
1947
+ /**
1948
+ * Computes the `x` and `y` coordinates that will place the floating element
1949
+ * next to a given reference element.
1950
+ */
1951
+ const computePosition = (reference, floating, options) => {
1952
+ // This caches the expensive `getClippingElementAncestors` function so that
1953
+ // multiple lifecycle resets re-use the same result. It only lives for a
1954
+ // single call. If other functions become expensive, we can add them as well.
1955
+ const cache = new Map();
1956
+ const mergedOptions = {
1957
+ platform,
1958
+ ...options
1959
+ };
1960
+ const platformWithCache = {
1961
+ ...mergedOptions.platform,
1962
+ _c: cache
1963
+ };
1964
+ return computePosition$1(reference, floating, {
1965
+ ...mergedOptions,
1966
+ platform: platformWithCache
1967
+ });
1968
+ };
1969
+
1970
+ var index$1 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1971
+
1972
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1973
+ // functions
1974
+ function deepEqual(a, b) {
1975
+ if (a === b) {
1976
+ return true;
1977
+ }
1978
+ if (typeof a !== typeof b) {
1979
+ return false;
1980
+ }
1981
+ if (typeof a === 'function' && a.toString() === b.toString()) {
1982
+ return true;
1983
+ }
1984
+ let length;
1985
+ let i;
1986
+ let keys;
1987
+ if (a && b && typeof a === 'object') {
1988
+ if (Array.isArray(a)) {
1989
+ length = a.length;
1990
+ if (length !== b.length) return false;
1991
+ for (i = length; i-- !== 0;) {
1992
+ if (!deepEqual(a[i], b[i])) {
1993
+ return false;
1994
+ }
1995
+ }
1996
+ return true;
1997
+ }
1998
+ keys = Object.keys(a);
1999
+ length = keys.length;
2000
+ if (length !== Object.keys(b).length) {
2001
+ return false;
2002
+ }
2003
+ for (i = length; i-- !== 0;) {
2004
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
2005
+ return false;
2006
+ }
2007
+ }
2008
+ for (i = length; i-- !== 0;) {
2009
+ const key = keys[i];
2010
+ if (key === '_owner' && a.$$typeof) {
2011
+ continue;
2012
+ }
2013
+ if (!deepEqual(a[key], b[key])) {
2014
+ return false;
2015
+ }
2016
+ }
2017
+ return true;
2018
+ }
2019
+ return a !== a && b !== b;
2020
+ }
2021
+
2022
+ function getDPR(element) {
2023
+ if (typeof window === 'undefined') {
2024
+ return 1;
2025
+ }
2026
+ const win = element.ownerDocument.defaultView || window;
2027
+ return win.devicePixelRatio || 1;
2028
+ }
2029
+
2030
+ function roundByDPR(element, value) {
2031
+ const dpr = getDPR(element);
2032
+ return Math.round(value * dpr) / dpr;
2033
+ }
2034
+
2035
+ function useLatestRef(value) {
2036
+ const ref = React.useRef(value);
2037
+ index$1(() => {
2038
+ ref.current = value;
2039
+ });
2040
+ return ref;
2041
+ }
2042
+
2043
+ /**
2044
+ * Provides data to position a floating element.
2045
+ * @see https://floating-ui.com/docs/useFloating
2046
+ */
2047
+ function useFloating$1(options) {
2048
+ if (options === void 0) {
2049
+ options = {};
2050
+ }
2051
+ const {
2052
+ placement = 'bottom',
2053
+ strategy = 'absolute',
2054
+ middleware = [],
2055
+ platform,
2056
+ elements: {
2057
+ reference: externalReference,
2058
+ floating: externalFloating
2059
+ } = {},
2060
+ transform = true,
2061
+ whileElementsMounted,
2062
+ open
2063
+ } = options;
2064
+ const [data, setData] = React.useState({
2065
+ x: 0,
2066
+ y: 0,
2067
+ strategy,
2068
+ placement,
2069
+ middlewareData: {},
2070
+ isPositioned: false
2071
+ });
2072
+ const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
2073
+ if (!deepEqual(latestMiddleware, middleware)) {
2074
+ setLatestMiddleware(middleware);
2075
+ }
2076
+ const [_reference, _setReference] = React.useState(null);
2077
+ const [_floating, _setFloating] = React.useState(null);
2078
+ const setReference = React.useCallback(node => {
2079
+ if (node !== referenceRef.current) {
2080
+ referenceRef.current = node;
2081
+ _setReference(node);
2082
+ }
2083
+ }, []);
2084
+ const setFloating = React.useCallback(node => {
2085
+ if (node !== floatingRef.current) {
2086
+ floatingRef.current = node;
2087
+ _setFloating(node);
2088
+ }
2089
+ }, []);
2090
+ const referenceEl = externalReference || _reference;
2091
+ const floatingEl = externalFloating || _floating;
2092
+ const referenceRef = React.useRef(null);
2093
+ const floatingRef = React.useRef(null);
2094
+ const dataRef = React.useRef(data);
2095
+ const hasWhileElementsMounted = whileElementsMounted != null;
2096
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
2097
+ const platformRef = useLatestRef(platform);
2098
+ const openRef = useLatestRef(open);
2099
+ const update = React.useCallback(() => {
2100
+ if (!referenceRef.current || !floatingRef.current) {
2101
+ return;
2102
+ }
2103
+ const config = {
2104
+ placement,
2105
+ strategy,
2106
+ middleware: latestMiddleware
2107
+ };
2108
+ if (platformRef.current) {
2109
+ config.platform = platformRef.current;
2110
+ }
2111
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
2112
+ const fullData = {
2113
+ ...data,
2114
+ // The floating element's position may be recomputed while it's closed
2115
+ // but still mounted (such as when transitioning out). To ensure
2116
+ // `isPositioned` will be `false` initially on the next open, avoid
2117
+ // setting it to `true` when `open === false` (must be specified).
2118
+ isPositioned: openRef.current !== false
2119
+ };
2120
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
2121
+ dataRef.current = fullData;
2122
+ ReactDOM.flushSync(() => {
2123
+ setData(fullData);
2124
+ });
2125
+ }
2126
+ });
2127
+ }, [latestMiddleware, placement, strategy, platformRef, openRef]);
2128
+ index$1(() => {
2129
+ if (open === false && dataRef.current.isPositioned) {
2130
+ dataRef.current.isPositioned = false;
2131
+ setData(data => ({
2132
+ ...data,
2133
+ isPositioned: false
2134
+ }));
2135
+ }
2136
+ }, [open]);
2137
+ const isMountedRef = React.useRef(false);
2138
+ index$1(() => {
2139
+ isMountedRef.current = true;
2140
+ return () => {
2141
+ isMountedRef.current = false;
2142
+ };
2143
+ }, []);
2144
+ index$1(() => {
2145
+ if (referenceEl) referenceRef.current = referenceEl;
2146
+ if (floatingEl) floatingRef.current = floatingEl;
2147
+ if (referenceEl && floatingEl) {
2148
+ if (whileElementsMountedRef.current) {
2149
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
2150
+ }
2151
+ update();
2152
+ }
2153
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
2154
+ const refs = React.useMemo(() => ({
2155
+ reference: referenceRef,
2156
+ floating: floatingRef,
2157
+ setReference,
2158
+ setFloating
2159
+ }), [setReference, setFloating]);
2160
+ const elements = React.useMemo(() => ({
2161
+ reference: referenceEl,
2162
+ floating: floatingEl
2163
+ }), [referenceEl, floatingEl]);
2164
+ const floatingStyles = React.useMemo(() => {
2165
+ const initialStyles = {
2166
+ position: strategy,
2167
+ left: 0,
2168
+ top: 0
2169
+ };
2170
+ if (!elements.floating) {
2171
+ return initialStyles;
2172
+ }
2173
+ const x = roundByDPR(elements.floating, data.x);
2174
+ const y = roundByDPR(elements.floating, data.y);
2175
+ if (transform) {
2176
+ return {
2177
+ ...initialStyles,
2178
+ transform: "translate(" + x + "px, " + y + "px)",
2179
+ ...(getDPR(elements.floating) >= 1.5 && {
2180
+ willChange: 'transform'
2181
+ })
2182
+ };
2183
+ }
2184
+ return {
2185
+ position: strategy,
2186
+ left: x,
2187
+ top: y
2188
+ };
2189
+ }, [strategy, transform, elements.floating, data.x, data.y]);
2190
+ return React.useMemo(() => ({
2191
+ ...data,
2192
+ update,
2193
+ refs,
2194
+ elements,
2195
+ floatingStyles
2196
+ }), [data, update, refs, elements, floatingStyles]);
2197
+ }
2198
+
2199
+ // https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
2200
+ const SafeReact = {
2201
+ ...React
2202
+ };
2203
+
2204
+ const useInsertionEffect = SafeReact.useInsertionEffect;
2205
+ const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
2206
+ function useEffectEvent(callback) {
2207
+ const ref = React.useRef(() => {
2208
+ if (process.env.NODE_ENV !== "production") {
2209
+ throw new Error('Cannot call an event handler while rendering.');
2210
+ }
2211
+ });
2212
+ useSafeInsertionEffect(() => {
2213
+ ref.current = callback;
2214
+ });
2215
+ return React.useCallback(function () {
2216
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2217
+ args[_key] = arguments[_key];
2218
+ }
2219
+ return ref.current == null ? void 0 : ref.current(...args);
2220
+ }, []);
2221
+ }
2222
+
2223
+ var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
2224
+
2225
+ function _extends() {
2226
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2227
+ for (var i = 1; i < arguments.length; i++) {
2228
+ var source = arguments[i];
2229
+ for (var key in source) {
2230
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2231
+ target[key] = source[key];
2232
+ }
2233
+ }
2234
+ }
2235
+ return target;
2236
+ };
2237
+ return _extends.apply(this, arguments);
2238
+ }
2239
+
2240
+ let serverHandoffComplete = false;
2241
+ let count = 0;
2242
+ const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
2243
+ // on <React 18
2244
+ "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
2245
+ function useFloatingId() {
2246
+ const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
2247
+ index(() => {
2248
+ if (id == null) {
2249
+ setId(genId());
2250
+ }
2251
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2252
+ }, []);
2253
+ React.useEffect(() => {
2254
+ serverHandoffComplete = true;
2255
+ }, []);
2256
+ return id;
2257
+ }
2258
+ const useReactId = SafeReact.useId;
2259
+
2260
+ /**
2261
+ * Uses React 18's built-in `useId()` when available, or falls back to a
2262
+ * slightly less performant (requiring a double render) implementation for
2263
+ * earlier React versions.
2264
+ * @see https://floating-ui.com/docs/react-utils#useid
2265
+ */
2266
+ const useId = useReactId || useFloatingId;
2267
+
2268
+ let devMessageSet;
2269
+ if (process.env.NODE_ENV !== "production") {
2270
+ devMessageSet = /*#__PURE__*/new Set();
2271
+ }
2272
+ function error() {
2273
+ var _devMessageSet3;
2274
+ for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2275
+ messages[_key2] = arguments[_key2];
2276
+ }
2277
+ const message = "Floating UI: " + messages.join(' ');
2278
+ if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
2279
+ var _devMessageSet4;
2280
+ (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
2281
+ console.error(message);
2282
+ }
2283
+ }
2284
+
2285
+ function createPubSub() {
2286
+ const map = new Map();
2287
+ return {
2288
+ emit(event, data) {
2289
+ var _map$get;
2290
+ (_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
2291
+ },
2292
+ on(event, listener) {
2293
+ map.set(event, [...(map.get(event) || []), listener]);
2294
+ },
2295
+ off(event, listener) {
2296
+ var _map$get2;
2297
+ map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
2298
+ }
2299
+ };
2300
+ }
2301
+
2302
+ const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
2303
+ const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
2304
+
2305
+ /**
2306
+ * Returns the parent node id for nested floating elements, if available.
2307
+ * Returns `null` for top-level floating elements.
2308
+ */
2309
+ const useFloatingParentNodeId = () => {
2310
+ var _React$useContext;
2311
+ return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
2312
+ };
2313
+
2314
+ /**
2315
+ * Returns the nearest floating tree context, if available.
2316
+ */
2317
+ const useFloatingTree = () => React.useContext(FloatingTreeContext);
2318
+
2319
+ function createAttribute(name) {
2320
+ return "data-floating-ui-" + name;
2321
+ }
2322
+
2323
+ const getTabbableOptions = () => ({
2324
+ getShadowRoot: true,
2325
+ displayCheck:
2326
+ // JSDOM does not support the `tabbable` library. To solve this we can
2327
+ // check if `ResizeObserver` is a real function (not polyfilled), which
2328
+ // determines if the current environment is JSDOM-like.
2329
+ typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
2330
+ });
2331
+ function getTabbableIn(container, direction) {
2332
+ const allTabbable = tabbable(container, getTabbableOptions());
2333
+ if (direction === 'prev') {
2334
+ allTabbable.reverse();
2335
+ }
2336
+ const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
2337
+ const nextTabbableElements = allTabbable.slice(activeIndex + 1);
2338
+ return nextTabbableElements[0];
2339
+ }
2340
+ function getNextTabbable() {
2341
+ return getTabbableIn(document.body, 'next');
2342
+ }
2343
+ function getPreviousTabbable() {
2344
+ return getTabbableIn(document.body, 'prev');
2345
+ }
2346
+ function isOutsideEvent(event, container) {
2347
+ const containerElement = container || event.currentTarget;
2348
+ const relatedTarget = event.relatedTarget;
2349
+ return !relatedTarget || !contains(containerElement, relatedTarget);
2350
+ }
2351
+ function disableFocusInside(container) {
2352
+ const tabbableElements = tabbable(container, getTabbableOptions());
2353
+ tabbableElements.forEach(element => {
2354
+ element.dataset.tabindex = element.getAttribute('tabindex') || '';
2355
+ element.setAttribute('tabindex', '-1');
2356
+ });
2357
+ }
2358
+ function enableFocusInside(container) {
2359
+ const elements = container.querySelectorAll('[data-tabindex]');
2360
+ elements.forEach(element => {
2361
+ const tabindex = element.dataset.tabindex;
2362
+ delete element.dataset.tabindex;
2363
+ if (tabindex) {
2364
+ element.setAttribute('tabindex', tabindex);
2365
+ } else {
2366
+ element.removeAttribute('tabindex');
2367
+ }
2368
+ });
2369
+ }
2370
+
2371
+ // See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
2372
+ // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
2373
+
2374
+ const HIDDEN_STYLES = {
2375
+ border: 0,
2376
+ clip: 'rect(0 0 0 0)',
2377
+ height: '1px',
2378
+ margin: '-1px',
2379
+ overflow: 'hidden',
2380
+ padding: 0,
2381
+ position: 'fixed',
2382
+ whiteSpace: 'nowrap',
2383
+ width: '1px',
2384
+ top: 0,
2385
+ left: 0
2386
+ };
2387
+ let timeoutId;
2388
+ function setActiveElementOnTab(event) {
2389
+ if (event.key === 'Tab') {
2390
+ event.target;
2391
+ clearTimeout(timeoutId);
2392
+ }
2393
+ }
2394
+ const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
2395
+ const [role, setRole] = React.useState();
2396
+ index(() => {
2397
+ if (isSafari()) {
2398
+ // Unlike other screen readers such as NVDA and JAWS, the virtual cursor
2399
+ // on VoiceOver does trigger the onFocus event, so we can use the focus
2400
+ // trap element. On Safari, only buttons trigger the onFocus event.
2401
+ // NB: "group" role in the Sandbox no longer appears to work, must be a
2402
+ // button role.
2403
+ setRole('button');
2404
+ }
2405
+ document.addEventListener('keydown', setActiveElementOnTab);
2406
+ return () => {
2407
+ document.removeEventListener('keydown', setActiveElementOnTab);
2408
+ };
2409
+ }, []);
2410
+ const restProps = {
2411
+ ref,
2412
+ tabIndex: 0,
2413
+ // Role is only for VoiceOver
2414
+ role,
2415
+ 'aria-hidden': role ? undefined : true,
2416
+ [createAttribute('focus-guard')]: '',
2417
+ style: HIDDEN_STYLES
2418
+ };
2419
+ return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
2420
+ });
2421
+
2422
+ const PortalContext = /*#__PURE__*/React.createContext(null);
2423
+ const attr = /*#__PURE__*/createAttribute('portal');
2424
+ /**
2425
+ * @see https://floating-ui.com/docs/FloatingPortal#usefloatingportalnode
2426
+ */
2427
+ function useFloatingPortalNode(props) {
2428
+ if (props === void 0) {
2429
+ props = {};
2430
+ }
2431
+ const {
2432
+ id,
2433
+ root
2434
+ } = props;
2435
+ const uniqueId = useId();
2436
+ const portalContext = usePortalContext();
2437
+ const [portalNode, setPortalNode] = React.useState(null);
2438
+ const portalNodeRef = React.useRef(null);
2439
+ index(() => {
2440
+ return () => {
2441
+ portalNode == null || portalNode.remove();
2442
+ // Allow the subsequent layout effects to create a new node on updates.
2443
+ // The portal node will still be cleaned up on unmount.
2444
+ // https://github.com/floating-ui/floating-ui/issues/2454
2445
+ queueMicrotask(() => {
2446
+ portalNodeRef.current = null;
2447
+ });
2448
+ };
2449
+ }, [portalNode]);
2450
+ index(() => {
2451
+ // Wait for the uniqueId to be generated before creating the portal node in
2452
+ // React <18 (using `useFloatingId` instead of the native `useId`).
2453
+ // https://github.com/floating-ui/floating-ui/issues/2778
2454
+ if (!uniqueId) return;
2455
+ if (portalNodeRef.current) return;
2456
+ const existingIdRoot = id ? document.getElementById(id) : null;
2457
+ if (!existingIdRoot) return;
2458
+ const subRoot = document.createElement('div');
2459
+ subRoot.id = uniqueId;
2460
+ subRoot.setAttribute(attr, '');
2461
+ existingIdRoot.appendChild(subRoot);
2462
+ portalNodeRef.current = subRoot;
2463
+ setPortalNode(subRoot);
2464
+ }, [id, uniqueId]);
2465
+ index(() => {
2466
+ if (!uniqueId) return;
2467
+ if (portalNodeRef.current) return;
2468
+ let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
2469
+ if (container && !isElement(container)) container = container.current;
2470
+ container = container || document.body;
2471
+ let idWrapper = null;
2472
+ if (id) {
2473
+ idWrapper = document.createElement('div');
2474
+ idWrapper.id = id;
2475
+ container.appendChild(idWrapper);
2476
+ }
2477
+ const subRoot = document.createElement('div');
2478
+ subRoot.id = uniqueId;
2479
+ subRoot.setAttribute(attr, '');
2480
+ container = idWrapper || container;
2481
+ container.appendChild(subRoot);
2482
+ portalNodeRef.current = subRoot;
2483
+ setPortalNode(subRoot);
2484
+ }, [id, root, uniqueId, portalContext]);
2485
+ return portalNode;
2486
+ }
2487
+ /**
2488
+ * Portals the floating element into a given container element — by default,
2489
+ * outside of the app root and into the body.
2490
+ * This is necessary to ensure the floating element can appear outside any
2491
+ * potential parent containers that cause clipping (such as `overflow: hidden`),
2492
+ * while retaining its location in the React tree.
2493
+ * @see https://floating-ui.com/docs/FloatingPortal
2494
+ */
2495
+ function FloatingPortal(props) {
2496
+ const {
2497
+ children,
2498
+ id,
2499
+ root = null,
2500
+ preserveTabOrder = true
2501
+ } = props;
2502
+ const portalNode = useFloatingPortalNode({
2503
+ id,
2504
+ root
2505
+ });
2506
+ const [focusManagerState, setFocusManagerState] = React.useState(null);
2507
+ const beforeOutsideRef = React.useRef(null);
2508
+ const afterOutsideRef = React.useRef(null);
2509
+ const beforeInsideRef = React.useRef(null);
2510
+ const afterInsideRef = React.useRef(null);
2511
+ const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
2512
+ const open = focusManagerState == null ? void 0 : focusManagerState.open;
2513
+ const shouldRenderGuards =
2514
+ // The FocusManager and therefore floating element are currently open/
2515
+ // rendered.
2516
+ !!focusManagerState &&
2517
+ // Guards are only for non-modal focus management.
2518
+ !focusManagerState.modal &&
2519
+ // Don't render if unmount is transitioning.
2520
+ focusManagerState.open && preserveTabOrder && !!(root || portalNode);
2521
+
2522
+ // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
2523
+ React.useEffect(() => {
2524
+ if (!portalNode || !preserveTabOrder || modal) {
2525
+ return;
2526
+ }
2527
+
2528
+ // Make sure elements inside the portal element are tabbable only when the
2529
+ // portal has already been focused, either by tabbing into a focus trap
2530
+ // element outside or using the mouse.
2531
+ function onFocus(event) {
2532
+ if (portalNode && isOutsideEvent(event)) {
2533
+ const focusing = event.type === 'focusin';
2534
+ const manageFocus = focusing ? enableFocusInside : disableFocusInside;
2535
+ manageFocus(portalNode);
2536
+ }
2537
+ }
2538
+ // Listen to the event on the capture phase so they run before the focus
2539
+ // trap elements onFocus prop is called.
2540
+ portalNode.addEventListener('focusin', onFocus, true);
2541
+ portalNode.addEventListener('focusout', onFocus, true);
2542
+ return () => {
2543
+ portalNode.removeEventListener('focusin', onFocus, true);
2544
+ portalNode.removeEventListener('focusout', onFocus, true);
2545
+ };
2546
+ }, [portalNode, preserveTabOrder, modal]);
2547
+ React.useEffect(() => {
2548
+ if (!portalNode) return;
2549
+ if (open) return;
2550
+ enableFocusInside(portalNode);
2551
+ }, [open, portalNode]);
2552
+ return /*#__PURE__*/React.createElement(PortalContext.Provider, {
2553
+ value: React.useMemo(() => ({
2554
+ preserveTabOrder,
2555
+ beforeOutsideRef,
2556
+ afterOutsideRef,
2557
+ beforeInsideRef,
2558
+ afterInsideRef,
2559
+ portalNode,
2560
+ setFocusManagerState
2561
+ }), [preserveTabOrder, portalNode])
2562
+ }, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
2563
+ "data-type": "outside",
2564
+ ref: beforeOutsideRef,
2565
+ onFocus: event => {
2566
+ if (isOutsideEvent(event, portalNode)) {
2567
+ var _beforeInsideRef$curr;
2568
+ (_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
2569
+ } else {
2570
+ const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
2571
+ prevTabbable == null || prevTabbable.focus();
2572
+ }
2573
+ }
2574
+ }), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement("span", {
2575
+ "aria-owns": portalNode.id,
2576
+ style: HIDDEN_STYLES
2577
+ }), portalNode && /*#__PURE__*/ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
2578
+ "data-type": "outside",
2579
+ ref: afterOutsideRef,
2580
+ onFocus: event => {
2581
+ if (isOutsideEvent(event, portalNode)) {
2582
+ var _afterInsideRef$curre;
2583
+ (_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
2584
+ } else {
2585
+ const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
2586
+ nextTabbable == null || nextTabbable.focus();
2587
+ (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, 'focus-out'));
2588
+ }
2589
+ }
2590
+ }));
2591
+ }
2592
+ const usePortalContext = () => React.useContext(PortalContext);
2593
+
2594
+ function useFloatingRootContext(options) {
2595
+ const {
2596
+ open = false,
2597
+ onOpenChange: onOpenChangeProp,
2598
+ elements: elementsProp
2599
+ } = options;
2600
+ const floatingId = useId();
2601
+ const dataRef = React.useRef({});
2602
+ const [events] = React.useState(() => createPubSub());
2603
+ const nested = useFloatingParentNodeId() != null;
2604
+ if (process.env.NODE_ENV !== "production") {
2605
+ const optionDomReference = elementsProp.reference;
2606
+ if (optionDomReference && !isElement(optionDomReference)) {
2607
+ error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
2608
+ }
2609
+ }
2610
+ const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
2611
+ const onOpenChange = useEffectEvent((open, event, reason) => {
2612
+ dataRef.current.openEvent = open ? event : undefined;
2613
+ events.emit('openchange', {
2614
+ open,
2615
+ event,
2616
+ reason,
2617
+ nested
2618
+ });
2619
+ onOpenChangeProp == null || onOpenChangeProp(open, event, reason);
2620
+ });
2621
+ const refs = React.useMemo(() => ({
2622
+ setPositionReference
2623
+ }), []);
2624
+ const elements = React.useMemo(() => ({
2625
+ reference: positionReference || elementsProp.reference || null,
2626
+ floating: elementsProp.floating || null,
2627
+ domReference: elementsProp.reference
2628
+ }), [positionReference, elementsProp.reference, elementsProp.floating]);
2629
+ return React.useMemo(() => ({
2630
+ dataRef,
2631
+ open,
2632
+ onOpenChange,
2633
+ elements,
2634
+ events,
2635
+ floatingId,
2636
+ refs
2637
+ }), [open, onOpenChange, elements, events, floatingId, refs]);
2638
+ }
2639
+
2640
+ /**
2641
+ * Provides data to position a floating element and context to add interactions.
2642
+ * @see https://floating-ui.com/docs/useFloating
2643
+ */
2644
+ function useFloating(options) {
2645
+ if (options === void 0) {
2646
+ options = {};
2647
+ }
2648
+ const {
2649
+ nodeId
2650
+ } = options;
2651
+ const internalRootContext = useFloatingRootContext({
2652
+ ...options,
2653
+ elements: {
2654
+ reference: null,
2655
+ floating: null,
2656
+ ...options.elements
2657
+ }
2658
+ });
2659
+ const rootContext = options.rootContext || internalRootContext;
2660
+ const computedElements = rootContext.elements;
2661
+ const [_domReference, setDomReference] = React.useState(null);
2662
+ const [positionReference, _setPositionReference] = React.useState(null);
2663
+ const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
2664
+ const domReference = optionDomReference || _domReference;
2665
+ const domReferenceRef = React.useRef(null);
2666
+ const tree = useFloatingTree();
2667
+ index(() => {
2668
+ if (domReference) {
2669
+ domReferenceRef.current = domReference;
2670
+ }
2671
+ }, [domReference]);
2672
+ const position = useFloating$1({
2673
+ ...options,
2674
+ elements: {
2675
+ ...computedElements,
2676
+ ...(positionReference && {
2677
+ reference: positionReference
2678
+ })
2679
+ }
2680
+ });
2681
+ const setPositionReference = React.useCallback(node => {
2682
+ const computedPositionReference = isElement(node) ? {
2683
+ getBoundingClientRect: () => node.getBoundingClientRect(),
2684
+ contextElement: node
2685
+ } : node;
2686
+ // Store the positionReference in state if the DOM reference is specified externally via the
2687
+ // `elements.reference` option. This ensures that it won't be overridden on future renders.
2688
+ _setPositionReference(computedPositionReference);
2689
+ position.refs.setReference(computedPositionReference);
2690
+ }, [position.refs]);
2691
+ const setReference = React.useCallback(node => {
2692
+ if (isElement(node) || node === null) {
2693
+ domReferenceRef.current = node;
2694
+ setDomReference(node);
2695
+ }
2696
+
2697
+ // Backwards-compatibility for passing a virtual element to `reference`
2698
+ // after it has set the DOM reference.
2699
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
2700
+ // Don't allow setting virtual elements using the old technique back to
2701
+ // `null` to support `positionReference` + an unstable `reference`
2702
+ // callback ref.
2703
+ node !== null && !isElement(node)) {
2704
+ position.refs.setReference(node);
2705
+ }
2706
+ }, [position.refs]);
2707
+ const refs = React.useMemo(() => ({
2708
+ ...position.refs,
2709
+ setReference,
2710
+ setPositionReference,
2711
+ domReference: domReferenceRef
2712
+ }), [position.refs, setReference, setPositionReference]);
2713
+ const elements = React.useMemo(() => ({
2714
+ ...position.elements,
2715
+ domReference: domReference
2716
+ }), [position.elements, domReference]);
2717
+ const context = React.useMemo(() => ({
2718
+ ...position,
2719
+ ...rootContext,
2720
+ refs,
2721
+ elements,
2722
+ nodeId
2723
+ }), [position, refs, elements, nodeId, rootContext]);
2724
+ index(() => {
2725
+ rootContext.dataRef.current.floatingContext = context;
2726
+ const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
2727
+ if (node) {
2728
+ node.context = context;
2729
+ }
2730
+ });
2731
+ return React.useMemo(() => ({
2732
+ ...position,
2733
+ context,
2734
+ refs,
2735
+ elements
2736
+ }), [position, refs, elements, context]);
2737
+ }
2738
+
2739
+ var reactIsExports = {};
2740
+ var reactIs = {
2741
+ get exports(){ return reactIsExports; },
2742
+ set exports(v){ reactIsExports = v; },
2743
+ };
2744
+
2745
+ var reactIs_production_min = {};
2746
+
2747
+ /** @license React v17.0.2
2748
+ * react-is.production.min.js
2749
+ *
2750
+ * Copyright (c) Facebook, Inc. and its affiliates.
2751
+ *
2752
+ * This source code is licensed under the MIT license found in the
2753
+ * LICENSE file in the root directory of this source tree.
2754
+ */
2755
+
2756
+ var hasRequiredReactIs_production_min;
2757
+
2758
+ function requireReactIs_production_min () {
2759
+ if (hasRequiredReactIs_production_min) return reactIs_production_min;
2760
+ hasRequiredReactIs_production_min = 1;
2761
+ var b=60103,c=60106,d=60107,e=60108,f=60114,g=60109,h=60110,k=60112,l=60113,m=60120,n=60115,p=60116,q=60121,r=60122,u=60117,v=60129,w=60131;
2762
+ if("function"===typeof Symbol&&Symbol.for){var x=Symbol.for;b=x("react.element");c=x("react.portal");d=x("react.fragment");e=x("react.strict_mode");f=x("react.profiler");g=x("react.provider");h=x("react.context");k=x("react.forward_ref");l=x("react.suspense");m=x("react.suspense_list");n=x("react.memo");p=x("react.lazy");q=x("react.block");r=x("react.server.block");u=x("react.fundamental");v=x("react.debug_trace_mode");w=x("react.legacy_hidden");}
2763
+ function y(a){if("object"===typeof a&&null!==a){var t=a.$$typeof;switch(t){case b:switch(a=a.type,a){case d:case f:case e:case l:case m:return a;default:switch(a=a&&a.$$typeof,a){case h:case k:case p:case n:case g:return a;default:return t}}case c:return t}}}var z=g,A=b,B=k,C=d,D=p,E=n,F=c,G=f,H=e,I=l;reactIs_production_min.ContextConsumer=h;reactIs_production_min.ContextProvider=z;reactIs_production_min.Element=A;reactIs_production_min.ForwardRef=B;reactIs_production_min.Fragment=C;reactIs_production_min.Lazy=D;reactIs_production_min.Memo=E;reactIs_production_min.Portal=F;reactIs_production_min.Profiler=G;reactIs_production_min.StrictMode=H;
2764
+ reactIs_production_min.Suspense=I;reactIs_production_min.isAsyncMode=function(){return !1};reactIs_production_min.isConcurrentMode=function(){return !1};reactIs_production_min.isContextConsumer=function(a){return y(a)===h};reactIs_production_min.isContextProvider=function(a){return y(a)===g};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===b};reactIs_production_min.isForwardRef=function(a){return y(a)===k};reactIs_production_min.isFragment=function(a){return y(a)===d};reactIs_production_min.isLazy=function(a){return y(a)===p};reactIs_production_min.isMemo=function(a){return y(a)===n};
2765
+ reactIs_production_min.isPortal=function(a){return y(a)===c};reactIs_production_min.isProfiler=function(a){return y(a)===f};reactIs_production_min.isStrictMode=function(a){return y(a)===e};reactIs_production_min.isSuspense=function(a){return y(a)===l};reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===d||a===f||a===v||a===e||a===l||a===m||a===w||"object"===typeof a&&null!==a&&(a.$$typeof===p||a.$$typeof===n||a.$$typeof===g||a.$$typeof===h||a.$$typeof===k||a.$$typeof===u||a.$$typeof===q||a[0]===r)?!0:!1};
2766
+ reactIs_production_min.typeOf=y;
2767
+ return reactIs_production_min;
2768
+ }
2769
+
2770
+ var reactIs_development = {};
2771
+
2772
+ /** @license React v17.0.2
2773
+ * react-is.development.js
2774
+ *
2775
+ * Copyright (c) Facebook, Inc. and its affiliates.
2776
+ *
2777
+ * This source code is licensed under the MIT license found in the
2778
+ * LICENSE file in the root directory of this source tree.
2779
+ */
2780
+
2781
+ var hasRequiredReactIs_development;
2782
+
2783
+ function requireReactIs_development () {
2784
+ if (hasRequiredReactIs_development) return reactIs_development;
2785
+ hasRequiredReactIs_development = 1;
2786
+
2787
+ if (process.env.NODE_ENV !== "production") {
2788
+ (function() {
2789
+
2790
+ // ATTENTION
2791
+ // When adding new symbols to this file,
2792
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
2793
+ // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
2794
+ // nor polyfill, then a plain number is used for performance.
2795
+ var REACT_ELEMENT_TYPE = 0xeac7;
2796
+ var REACT_PORTAL_TYPE = 0xeaca;
2797
+ var REACT_FRAGMENT_TYPE = 0xeacb;
2798
+ var REACT_STRICT_MODE_TYPE = 0xeacc;
2799
+ var REACT_PROFILER_TYPE = 0xead2;
2800
+ var REACT_PROVIDER_TYPE = 0xeacd;
2801
+ var REACT_CONTEXT_TYPE = 0xeace;
2802
+ var REACT_FORWARD_REF_TYPE = 0xead0;
2803
+ var REACT_SUSPENSE_TYPE = 0xead1;
2804
+ var REACT_SUSPENSE_LIST_TYPE = 0xead8;
2805
+ var REACT_MEMO_TYPE = 0xead3;
2806
+ var REACT_LAZY_TYPE = 0xead4;
2807
+ var REACT_BLOCK_TYPE = 0xead9;
2808
+ var REACT_SERVER_BLOCK_TYPE = 0xeada;
2809
+ var REACT_FUNDAMENTAL_TYPE = 0xead5;
2810
+ var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
2811
+ var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
2812
+
2813
+ if (typeof Symbol === 'function' && Symbol.for) {
2814
+ var symbolFor = Symbol.for;
2815
+ REACT_ELEMENT_TYPE = symbolFor('react.element');
2816
+ REACT_PORTAL_TYPE = symbolFor('react.portal');
2817
+ REACT_FRAGMENT_TYPE = symbolFor('react.fragment');
2818
+ REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
2819
+ REACT_PROFILER_TYPE = symbolFor('react.profiler');
2820
+ REACT_PROVIDER_TYPE = symbolFor('react.provider');
2821
+ REACT_CONTEXT_TYPE = symbolFor('react.context');
2822
+ REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
2823
+ REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
2824
+ REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
2825
+ REACT_MEMO_TYPE = symbolFor('react.memo');
2826
+ REACT_LAZY_TYPE = symbolFor('react.lazy');
2827
+ REACT_BLOCK_TYPE = symbolFor('react.block');
2828
+ REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
2829
+ REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
2830
+ symbolFor('react.scope');
2831
+ symbolFor('react.opaque.id');
2832
+ REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
2833
+ symbolFor('react.offscreen');
2834
+ REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
2835
+ }
2836
+
2837
+ // Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
2838
+
2839
+ var enableScopeAPI = false; // Experimental Create Event Handle API.
2840
+
2841
+ function isValidElementType(type) {
2842
+ if (typeof type === 'string' || typeof type === 'function') {
2843
+ return true;
2844
+ } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
2845
+
2846
+
2847
+ if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_DEBUG_TRACING_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI ) {
2848
+ return true;
2849
+ }
2850
+
2851
+ if (typeof type === 'object' && type !== null) {
2852
+ if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) {
2853
+ return true;
2854
+ }
2855
+ }
2856
+
2857
+ return false;
2858
+ }
2859
+
2860
+ function typeOf(object) {
2861
+ if (typeof object === 'object' && object !== null) {
2862
+ var $$typeof = object.$$typeof;
2863
+
2864
+ switch ($$typeof) {
2865
+ case REACT_ELEMENT_TYPE:
2866
+ var type = object.type;
2867
+
2868
+ switch (type) {
2869
+ case REACT_FRAGMENT_TYPE:
2870
+ case REACT_PROFILER_TYPE:
2871
+ case REACT_STRICT_MODE_TYPE:
2872
+ case REACT_SUSPENSE_TYPE:
2873
+ case REACT_SUSPENSE_LIST_TYPE:
2874
+ return type;
2875
+
2876
+ default:
2877
+ var $$typeofType = type && type.$$typeof;
2878
+
2879
+ switch ($$typeofType) {
2880
+ case REACT_CONTEXT_TYPE:
2881
+ case REACT_FORWARD_REF_TYPE:
2882
+ case REACT_LAZY_TYPE:
2883
+ case REACT_MEMO_TYPE:
2884
+ case REACT_PROVIDER_TYPE:
2885
+ return $$typeofType;
2886
+
2887
+ default:
2888
+ return $$typeof;
2889
+ }
2890
+
2891
+ }
2892
+
2893
+ case REACT_PORTAL_TYPE:
2894
+ return $$typeof;
2895
+ }
2896
+ }
2897
+
2898
+ return undefined;
2899
+ }
2900
+ var ContextConsumer = REACT_CONTEXT_TYPE;
2901
+ var ContextProvider = REACT_PROVIDER_TYPE;
2902
+ var Element = REACT_ELEMENT_TYPE;
2903
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
2904
+ var Fragment = REACT_FRAGMENT_TYPE;
2905
+ var Lazy = REACT_LAZY_TYPE;
2906
+ var Memo = REACT_MEMO_TYPE;
2907
+ var Portal = REACT_PORTAL_TYPE;
2908
+ var Profiler = REACT_PROFILER_TYPE;
2909
+ var StrictMode = REACT_STRICT_MODE_TYPE;
2910
+ var Suspense = REACT_SUSPENSE_TYPE;
2911
+ var hasWarnedAboutDeprecatedIsAsyncMode = false;
2912
+ var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
2913
+
2914
+ function isAsyncMode(object) {
2915
+ {
2916
+ if (!hasWarnedAboutDeprecatedIsAsyncMode) {
2917
+ hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
2918
+
2919
+ console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
2920
+ }
2921
+ }
2922
+
2923
+ return false;
2924
+ }
2925
+ function isConcurrentMode(object) {
2926
+ {
2927
+ if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
2928
+ hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
2929
+
2930
+ console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
2931
+ }
2932
+ }
2933
+
2934
+ return false;
2935
+ }
2936
+ function isContextConsumer(object) {
2937
+ return typeOf(object) === REACT_CONTEXT_TYPE;
2938
+ }
2939
+ function isContextProvider(object) {
2940
+ return typeOf(object) === REACT_PROVIDER_TYPE;
2941
+ }
2942
+ function isElement(object) {
2943
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
2944
+ }
2945
+ function isForwardRef(object) {
2946
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
2947
+ }
2948
+ function isFragment(object) {
2949
+ return typeOf(object) === REACT_FRAGMENT_TYPE;
2950
+ }
2951
+ function isLazy(object) {
2952
+ return typeOf(object) === REACT_LAZY_TYPE;
2953
+ }
2954
+ function isMemo(object) {
2955
+ return typeOf(object) === REACT_MEMO_TYPE;
2956
+ }
2957
+ function isPortal(object) {
2958
+ return typeOf(object) === REACT_PORTAL_TYPE;
2959
+ }
2960
+ function isProfiler(object) {
2961
+ return typeOf(object) === REACT_PROFILER_TYPE;
2962
+ }
2963
+ function isStrictMode(object) {
2964
+ return typeOf(object) === REACT_STRICT_MODE_TYPE;
2965
+ }
2966
+ function isSuspense(object) {
2967
+ return typeOf(object) === REACT_SUSPENSE_TYPE;
2968
+ }
2969
+
2970
+ reactIs_development.ContextConsumer = ContextConsumer;
2971
+ reactIs_development.ContextProvider = ContextProvider;
2972
+ reactIs_development.Element = Element;
2973
+ reactIs_development.ForwardRef = ForwardRef;
2974
+ reactIs_development.Fragment = Fragment;
2975
+ reactIs_development.Lazy = Lazy;
2976
+ reactIs_development.Memo = Memo;
2977
+ reactIs_development.Portal = Portal;
2978
+ reactIs_development.Profiler = Profiler;
2979
+ reactIs_development.StrictMode = StrictMode;
2980
+ reactIs_development.Suspense = Suspense;
2981
+ reactIs_development.isAsyncMode = isAsyncMode;
2982
+ reactIs_development.isConcurrentMode = isConcurrentMode;
2983
+ reactIs_development.isContextConsumer = isContextConsumer;
2984
+ reactIs_development.isContextProvider = isContextProvider;
2985
+ reactIs_development.isElement = isElement;
2986
+ reactIs_development.isForwardRef = isForwardRef;
2987
+ reactIs_development.isFragment = isFragment;
2988
+ reactIs_development.isLazy = isLazy;
2989
+ reactIs_development.isMemo = isMemo;
2990
+ reactIs_development.isPortal = isPortal;
2991
+ reactIs_development.isProfiler = isProfiler;
2992
+ reactIs_development.isStrictMode = isStrictMode;
2993
+ reactIs_development.isSuspense = isSuspense;
2994
+ reactIs_development.isValidElementType = isValidElementType;
2995
+ reactIs_development.typeOf = typeOf;
2996
+ })();
2997
+ }
2998
+ return reactIs_development;
2999
+ }
3000
+
3001
+ (function (module) {
3002
+
3003
+ if (process.env.NODE_ENV === 'production') {
3004
+ module.exports = requireReactIs_production_min();
3005
+ } else {
3006
+ module.exports = requireReactIs_development();
3007
+ }
3008
+ } (reactIs));
3009
+
3010
+ var css_248z = "[data-gene-ui-version=\"2.16.0\"] .tooltip-c-p{pointer-events:none;z-index:10}[data-gene-ui-version=\"2.16.0\"] .s-small .tooltip-c-p{padding:1.5rem}[data-gene-ui-version=\"2.16.0\"] .tooltip-wrapper{max-width:inherit}[data-gene-ui-version=\"2.16.0\"] .tooltip-content{background:rgba(var(--background-sc-rgb),.6);border-radius:.4rem;color:rgba(var(--background-rgb),.7);font:600 1.2rem/1.6rem var(--font-family);max-width:20rem;padding:.6rem 1rem;word-break:break-word}[data-gene-ui-version=\"2.16.0\"] .tooltip-content>*+*{margin:.2rem 0 0}[data-gene-ui-version=\"2.16.0\"] .s-small .tooltip-content{font:600 1rem/1.4rem var(--font-family);padding:.6rem .8rem}[data-gene-ui-version=\"2.16.0\"] .tooltip-title{color:var(--background)}";
3011
+ styleInject(css_248z);
3012
+
3013
+ const positions = ['top', 'right', 'bottom', 'left'];
3014
+ const FindAndMergeRef = (children, childProps, componentRef) => Children.map(children, (el, i) => {
3015
+ const newProps = Object.assign(Object.assign({}, childProps), { onClick: (e) => childProps === null || childProps === void 0 ? void 0 : childProps.onClick(e, el), ref: i === 0 ? componentRef : {} });
3016
+ if ((el === null || el === void 0 ? void 0 : el.type) === Fragment && el.props.children) {
3017
+ return FindAndMergeRef(el.props.children, childProps, componentRef);
3018
+ }
3019
+ if (reactIsExports.isForwardRef(el)) {
3020
+ return FindAndMergeRef(el.type.render(el.props), newProps, componentRef);
3021
+ }
3022
+ if (typeof (el === null || el === void 0 ? void 0 : el.type) === 'string') {
3023
+ return cloneElement(el, newProps);
3024
+ }
3025
+ if (typeof (el === null || el === void 0 ? void 0 : el.type) === 'function') {
3026
+ return FindAndMergeRef(el.type(el.props), newProps, componentRef);
3027
+ }
3028
+ return el && cloneElement(el, newProps);
3029
+ });
3030
+ const Tooltip = (_a) => {
3031
+ var { children, position = 'top', size = 'default', style, text, title, customPosition, alwaysShow, onClick = noop, padding = 5, screenType = 'desktop', isVisible = true } = _a, props = __rest(_a, ["children", "position", "size", "style", "text", "title", "customPosition", "alwaysShow", "onClick", "padding", "screenType", "isVisible"]);
3032
+ // @ts-ignore
3033
+ const { geneUIProviderRef } = useContext(GeneUIDesignSystemContext);
3034
+ const { isMobile } = useDeviceType(screenType);
3035
+ const [isPopoverOpen, setIsPopoverState] = useState(false);
3036
+ const mouseEnterHandler = () => !alwaysShow && setIsPopoverState(true);
3037
+ const mouseLeaveHandler = () => {
3038
+ !alwaysShow && setIsPopoverState(false);
3039
+ };
3040
+ const { refs, floatingStyles, context } = useFloating({
3041
+ open: alwaysShow || isPopoverOpen,
3042
+ placement: position,
3043
+ middleware: [
3044
+ offset(padding),
3045
+ flip({
3046
+ fallbackAxisSideDirection: 'none',
3047
+ fallbackPlacements: positions,
3048
+ mainAxis: true
3049
+ }),
3050
+ shift(),
3051
+ {
3052
+ name: 'getCustomPosition',
3053
+ fn: () => customPosition
3054
+ ? {
3055
+ x: customPosition === null || customPosition === void 0 ? void 0 : customPosition.left,
3056
+ y: customPosition === null || customPosition === void 0 ? void 0 : customPosition.top
3057
+ }
3058
+ : {}
3059
+ }
3060
+ ],
3061
+ whileElementsMounted: autoUpdate
3062
+ });
3063
+ const checkNudged = ({ nudgedLeft, nudgedTop }) => (isMobile ? !(nudgedTop || nudgedLeft) : true);
3064
+ const childProps = {
3065
+ onMouseEnter: mouseEnterHandler,
3066
+ onMouseLeave: mouseLeaveHandler,
3067
+ onClick: (e, el) => {
3068
+ const { onClick: onClickHandler } = el === null || el === void 0 ? void 0 : el.props;
3069
+ typeof onClickHandler === 'function' && onClickHandler(e);
3070
+ onClick(e);
3071
+ }
3072
+ };
3073
+ return (React__default.createElement(React__default.Fragment, null,
3074
+ FindAndMergeRef(children, childProps, refs.setReference),
3075
+ isVisible && (alwaysShow || isPopoverOpen) && (React__default.createElement(FloatingPortal, { root: geneUIProviderRef.current }, checkNudged({ nudgedLeft: context.x, nudgedTop: context.y }) && (React__default.createElement("div", Object.assign({ className: `tooltip-c-p s-${size} ${position}`, ref: refs.setFloating, style: Object.assign(Object.assign({}, style), floatingStyles) }, props), (title || text) && (React__default.createElement("div", { className: "tooltip-content" },
3076
+ title && React__default.createElement("div", { className: "tooltip-title" }, title),
3077
+ text && React__default.createElement("div", { className: "tooltip-text" }, text)))))))));
3078
+ };
3079
+
3080
+ export { Tooltip as T, reactIsExports as r };