@radui/ui 0.0.2 → 0.0.4

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 (58) hide show
  1. package/dist/components/Accordion.js +26 -0
  2. package/dist/components/Avatar.js +67 -0
  3. package/dist/components/Badge.js +51 -0
  4. package/dist/components/BlockQuote.js +47 -0
  5. package/dist/components/Button.js +40 -0
  6. package/dist/components/Callout.js +66 -0
  7. package/dist/components/Code.js +13 -0
  8. package/dist/components/Dropdown.js +1751 -0
  9. package/dist/components/Em.js +47 -0
  10. package/dist/components/Heading.js +76 -0
  11. package/dist/components/Kbd.js +46 -0
  12. package/dist/components/Link.js +51 -0
  13. package/dist/components/Quote.js +47 -0
  14. package/dist/components/Separator.js +32 -0
  15. package/dist/components/Strong.js +9 -0
  16. package/dist/components/Tabs.js +146 -0
  17. package/dist/components/Text.js +51 -0
  18. package/dist/components/TextArea.js +8 -0
  19. package/dist/components/Tooltip.js +2716 -0
  20. package/package.json +5 -3
  21. package/dist/ui/Accordion.es.js +0 -1
  22. package/dist/ui/Accordion.js +0 -1
  23. package/dist/ui/Avatar.es.js +0 -1
  24. package/dist/ui/Avatar.js +0 -1
  25. package/dist/ui/Badge.es.js +0 -1
  26. package/dist/ui/Badge.js +0 -1
  27. package/dist/ui/BlockQuote.es.js +0 -1
  28. package/dist/ui/BlockQuote.js +0 -1
  29. package/dist/ui/Button.es.js +0 -1
  30. package/dist/ui/Button.js +0 -1
  31. package/dist/ui/Callout.es.js +0 -1
  32. package/dist/ui/Callout.js +0 -1
  33. package/dist/ui/Code.es.js +0 -1
  34. package/dist/ui/Code.js +0 -1
  35. package/dist/ui/Dropdown.es.js +0 -1
  36. package/dist/ui/Dropdown.js +0 -1
  37. package/dist/ui/Em.es.js +0 -1
  38. package/dist/ui/Em.js +0 -1
  39. package/dist/ui/Heading.es.js +0 -1
  40. package/dist/ui/Heading.js +0 -1
  41. package/dist/ui/Kbd.es.js +0 -1
  42. package/dist/ui/Kbd.js +0 -1
  43. package/dist/ui/Link.es.js +0 -1
  44. package/dist/ui/Link.js +0 -1
  45. package/dist/ui/Quote.es.js +0 -1
  46. package/dist/ui/Quote.js +0 -1
  47. package/dist/ui/Separator.es.js +0 -1
  48. package/dist/ui/Separator.js +0 -1
  49. package/dist/ui/Strong.es.js +0 -1
  50. package/dist/ui/Strong.js +0 -1
  51. package/dist/ui/Tabs.es.js +0 -1
  52. package/dist/ui/Tabs.js +0 -1
  53. package/dist/ui/Text.es.js +0 -1
  54. package/dist/ui/Text.js +0 -1
  55. package/dist/ui/TextArea.es.js +0 -1
  56. package/dist/ui/TextArea.js +0 -1
  57. package/dist/ui/Tooltip.es.js +0 -1
  58. package/dist/ui/Tooltip.js +0 -1
@@ -0,0 +1,2716 @@
1
+ 'use client';
2
+ import * as React$1 from 'react';
3
+ import { useLayoutEffect, useEffect, useRef, useState } from 'react';
4
+ import * as ReactDOM from 'react-dom';
5
+
6
+ function _extends$1() {
7
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
8
+ for (var i = 1; i < arguments.length; i++) {
9
+ var source = arguments[i];
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
15
+ }
16
+ return target;
17
+ };
18
+ return _extends$1.apply(this, arguments);
19
+ }
20
+
21
+ const RAD_UI_CLASS_PREFIX = 'rad-ui';
22
+ const customClassSwitcher = function (customRootClass) {
23
+ let componentName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
24
+ // applies a custom root class the user provides, else applies the default rad-ui classes to the component
25
+ // rad ui's classes are based on this logic
26
+
27
+ // add dashes between capitalized words
28
+ const componentClassName = componentName.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
29
+ if (customRootClass) return customRootClass;
30
+ if (componentName) return `${RAD_UI_CLASS_PREFIX}-${componentClassName}`;
31
+ return '';
32
+ };
33
+
34
+ function getNodeName(node) {
35
+ if (isNode(node)) {
36
+ return (node.nodeName || '').toLowerCase();
37
+ }
38
+ // Mocked nodes in testing environments may not be instances of Node. By
39
+ // returning `#document` an infinite loop won't occur.
40
+ // https://github.com/floating-ui/floating-ui/issues/2317
41
+ return '#document';
42
+ }
43
+ function getWindow(node) {
44
+ var _node$ownerDocument;
45
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
46
+ }
47
+ function getDocumentElement(node) {
48
+ var _ref;
49
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
50
+ }
51
+ function isNode(value) {
52
+ return value instanceof Node || value instanceof getWindow(value).Node;
53
+ }
54
+ function isElement(value) {
55
+ return value instanceof Element || value instanceof getWindow(value).Element;
56
+ }
57
+ function isHTMLElement(value) {
58
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
59
+ }
60
+ function isShadowRoot(value) {
61
+ // Browsers without `ShadowRoot` support.
62
+ if (typeof ShadowRoot === 'undefined') {
63
+ return false;
64
+ }
65
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
66
+ }
67
+ function isOverflowElement(element) {
68
+ const {
69
+ overflow,
70
+ overflowX,
71
+ overflowY,
72
+ display
73
+ } = getComputedStyle(element);
74
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
75
+ }
76
+ function isTableElement(element) {
77
+ return ['table', 'td', 'th'].includes(getNodeName(element));
78
+ }
79
+ function isContainingBlock(element) {
80
+ const webkit = isWebKit();
81
+ const css = getComputedStyle(element);
82
+
83
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
84
+ 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));
85
+ }
86
+ function getContainingBlock(element) {
87
+ let currentNode = getParentNode(element);
88
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
89
+ if (isContainingBlock(currentNode)) {
90
+ return currentNode;
91
+ } else {
92
+ currentNode = getParentNode(currentNode);
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+ function isWebKit() {
98
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
99
+ return CSS.supports('-webkit-backdrop-filter', 'none');
100
+ }
101
+ function isLastTraversableNode(node) {
102
+ return ['html', 'body', '#document'].includes(getNodeName(node));
103
+ }
104
+ function getComputedStyle(element) {
105
+ return getWindow(element).getComputedStyle(element);
106
+ }
107
+ function getNodeScroll(element) {
108
+ if (isElement(element)) {
109
+ return {
110
+ scrollLeft: element.scrollLeft,
111
+ scrollTop: element.scrollTop
112
+ };
113
+ }
114
+ return {
115
+ scrollLeft: element.pageXOffset,
116
+ scrollTop: element.pageYOffset
117
+ };
118
+ }
119
+ function getParentNode(node) {
120
+ if (getNodeName(node) === 'html') {
121
+ return node;
122
+ }
123
+ const result =
124
+ // Step into the shadow DOM of the parent of a slotted node.
125
+ node.assignedSlot ||
126
+ // DOM Element detected.
127
+ node.parentNode ||
128
+ // ShadowRoot detected.
129
+ isShadowRoot(node) && node.host ||
130
+ // Fallback.
131
+ getDocumentElement(node);
132
+ return isShadowRoot(result) ? result.host : result;
133
+ }
134
+ function getNearestOverflowAncestor(node) {
135
+ const parentNode = getParentNode(node);
136
+ if (isLastTraversableNode(parentNode)) {
137
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
138
+ }
139
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
140
+ return parentNode;
141
+ }
142
+ return getNearestOverflowAncestor(parentNode);
143
+ }
144
+ function getOverflowAncestors(node, list, traverseIframes) {
145
+ var _node$ownerDocument2;
146
+ if (list === void 0) {
147
+ list = [];
148
+ }
149
+ if (traverseIframes === void 0) {
150
+ traverseIframes = true;
151
+ }
152
+ const scrollableAncestor = getNearestOverflowAncestor(node);
153
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
154
+ const win = getWindow(scrollableAncestor);
155
+ if (isBody) {
156
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
157
+ }
158
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
159
+ }
160
+
161
+ function contains(parent, child) {
162
+ if (!parent || !child) {
163
+ return false;
164
+ }
165
+ const rootNode = child.getRootNode && child.getRootNode();
166
+
167
+ // First, attempt with faster native method
168
+ if (parent.contains(child)) {
169
+ return true;
170
+ }
171
+
172
+ // then fallback to custom implementation with Shadow DOM support
173
+ if (rootNode && isShadowRoot(rootNode)) {
174
+ let next = child;
175
+ while (next) {
176
+ if (parent === next) {
177
+ return true;
178
+ }
179
+ // @ts-ignore
180
+ next = next.parentNode || next.host;
181
+ }
182
+ }
183
+
184
+ // Give up, the result is false
185
+ return false;
186
+ }
187
+ function isMouseLikePointerType(pointerType, strict) {
188
+ // On some Linux machines with Chromium, mouse inputs return a `pointerType`
189
+ // of "pen": https://github.com/floating-ui/floating-ui/issues/2015
190
+ const values = ['mouse', 'pen'];
191
+ if (!strict) {
192
+ values.push('', undefined);
193
+ }
194
+ return values.includes(pointerType);
195
+ }
196
+ function isReactEvent(event) {
197
+ return 'nativeEvent' in event;
198
+ }
199
+ function isRootElement(element) {
200
+ return element.matches('html,body');
201
+ }
202
+ function getDocument(node) {
203
+ return (node == null ? void 0 : node.ownerDocument) || document;
204
+ }
205
+ function isEventTargetWithin(event, node) {
206
+ if (node == null) {
207
+ return false;
208
+ }
209
+ if ('composedPath' in event) {
210
+ return event.composedPath().includes(node);
211
+ }
212
+
213
+ // TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
214
+ const e = event;
215
+ return e.target != null && node.contains(e.target);
216
+ }
217
+ function getTarget(event) {
218
+ if ('composedPath' in event) {
219
+ return event.composedPath()[0];
220
+ }
221
+
222
+ // TS thinks `event` is of type never as it assumes all browsers support
223
+ // `composedPath()`, but browsers without shadow DOM don't.
224
+ return event.target;
225
+ }
226
+
227
+ const min = Math.min;
228
+ const max = Math.max;
229
+ const round = Math.round;
230
+ const createCoords = v => ({
231
+ x: v,
232
+ y: v
233
+ });
234
+ const oppositeSideMap = {
235
+ left: 'right',
236
+ right: 'left',
237
+ bottom: 'top',
238
+ top: 'bottom'
239
+ };
240
+ const oppositeAlignmentMap = {
241
+ start: 'end',
242
+ end: 'start'
243
+ };
244
+ function clamp(start, value, end) {
245
+ return max(start, min(value, end));
246
+ }
247
+ function evaluate(value, param) {
248
+ return typeof value === 'function' ? value(param) : value;
249
+ }
250
+ function getSide(placement) {
251
+ return placement.split('-')[0];
252
+ }
253
+ function getAlignment(placement) {
254
+ return placement.split('-')[1];
255
+ }
256
+ function getOppositeAxis(axis) {
257
+ return axis === 'x' ? 'y' : 'x';
258
+ }
259
+ function getAxisLength(axis) {
260
+ return axis === 'y' ? 'height' : 'width';
261
+ }
262
+ function getSideAxis(placement) {
263
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
264
+ }
265
+ function getAlignmentAxis(placement) {
266
+ return getOppositeAxis(getSideAxis(placement));
267
+ }
268
+ function getAlignmentSides(placement, rects, rtl) {
269
+ if (rtl === void 0) {
270
+ rtl = false;
271
+ }
272
+ const alignment = getAlignment(placement);
273
+ const alignmentAxis = getAlignmentAxis(placement);
274
+ const length = getAxisLength(alignmentAxis);
275
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
276
+ if (rects.reference[length] > rects.floating[length]) {
277
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
278
+ }
279
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
280
+ }
281
+ function getExpandedPlacements(placement) {
282
+ const oppositePlacement = getOppositePlacement(placement);
283
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
284
+ }
285
+ function getOppositeAlignmentPlacement(placement) {
286
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
287
+ }
288
+ function getSideList(side, isStart, rtl) {
289
+ const lr = ['left', 'right'];
290
+ const rl = ['right', 'left'];
291
+ const tb = ['top', 'bottom'];
292
+ const bt = ['bottom', 'top'];
293
+ switch (side) {
294
+ case 'top':
295
+ case 'bottom':
296
+ if (rtl) return isStart ? rl : lr;
297
+ return isStart ? lr : rl;
298
+ case 'left':
299
+ case 'right':
300
+ return isStart ? tb : bt;
301
+ default:
302
+ return [];
303
+ }
304
+ }
305
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
306
+ const alignment = getAlignment(placement);
307
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
308
+ if (alignment) {
309
+ list = list.map(side => side + "-" + alignment);
310
+ if (flipAlignment) {
311
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
312
+ }
313
+ }
314
+ return list;
315
+ }
316
+ function getOppositePlacement(placement) {
317
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
318
+ }
319
+ function expandPaddingObject(padding) {
320
+ return {
321
+ top: 0,
322
+ right: 0,
323
+ bottom: 0,
324
+ left: 0,
325
+ ...padding
326
+ };
327
+ }
328
+ function getPaddingObject(padding) {
329
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
330
+ top: padding,
331
+ right: padding,
332
+ bottom: padding,
333
+ left: padding
334
+ };
335
+ }
336
+ function rectToClientRect(rect) {
337
+ return {
338
+ ...rect,
339
+ top: rect.y,
340
+ left: rect.x,
341
+ right: rect.x + rect.width,
342
+ bottom: rect.y + rect.height
343
+ };
344
+ }
345
+
346
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
347
+ let {
348
+ reference,
349
+ floating
350
+ } = _ref;
351
+ const sideAxis = getSideAxis(placement);
352
+ const alignmentAxis = getAlignmentAxis(placement);
353
+ const alignLength = getAxisLength(alignmentAxis);
354
+ const side = getSide(placement);
355
+ const isVertical = sideAxis === 'y';
356
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
357
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
358
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
359
+ let coords;
360
+ switch (side) {
361
+ case 'top':
362
+ coords = {
363
+ x: commonX,
364
+ y: reference.y - floating.height
365
+ };
366
+ break;
367
+ case 'bottom':
368
+ coords = {
369
+ x: commonX,
370
+ y: reference.y + reference.height
371
+ };
372
+ break;
373
+ case 'right':
374
+ coords = {
375
+ x: reference.x + reference.width,
376
+ y: commonY
377
+ };
378
+ break;
379
+ case 'left':
380
+ coords = {
381
+ x: reference.x - floating.width,
382
+ y: commonY
383
+ };
384
+ break;
385
+ default:
386
+ coords = {
387
+ x: reference.x,
388
+ y: reference.y
389
+ };
390
+ }
391
+ switch (getAlignment(placement)) {
392
+ case 'start':
393
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
394
+ break;
395
+ case 'end':
396
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
397
+ break;
398
+ }
399
+ return coords;
400
+ }
401
+
402
+ /**
403
+ * Computes the `x` and `y` coordinates that will place the floating element
404
+ * next to a reference element when it is given a certain positioning strategy.
405
+ *
406
+ * This export does not have any `platform` interface logic. You will need to
407
+ * write one for the platform you are using Floating UI with.
408
+ */
409
+ const computePosition$1 = async (reference, floating, config) => {
410
+ const {
411
+ placement = 'bottom',
412
+ strategy = 'absolute',
413
+ middleware = [],
414
+ platform
415
+ } = config;
416
+ const validMiddleware = middleware.filter(Boolean);
417
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
418
+ let rects = await platform.getElementRects({
419
+ reference,
420
+ floating,
421
+ strategy
422
+ });
423
+ let {
424
+ x,
425
+ y
426
+ } = computeCoordsFromPlacement(rects, placement, rtl);
427
+ let statefulPlacement = placement;
428
+ let middlewareData = {};
429
+ let resetCount = 0;
430
+ for (let i = 0; i < validMiddleware.length; i++) {
431
+ const {
432
+ name,
433
+ fn
434
+ } = validMiddleware[i];
435
+ const {
436
+ x: nextX,
437
+ y: nextY,
438
+ data,
439
+ reset
440
+ } = await fn({
441
+ x,
442
+ y,
443
+ initialPlacement: placement,
444
+ placement: statefulPlacement,
445
+ strategy,
446
+ middlewareData,
447
+ rects,
448
+ platform,
449
+ elements: {
450
+ reference,
451
+ floating
452
+ }
453
+ });
454
+ x = nextX != null ? nextX : x;
455
+ y = nextY != null ? nextY : y;
456
+ middlewareData = {
457
+ ...middlewareData,
458
+ [name]: {
459
+ ...middlewareData[name],
460
+ ...data
461
+ }
462
+ };
463
+ if (reset && resetCount <= 50) {
464
+ resetCount++;
465
+ if (typeof reset === 'object') {
466
+ if (reset.placement) {
467
+ statefulPlacement = reset.placement;
468
+ }
469
+ if (reset.rects) {
470
+ rects = reset.rects === true ? await platform.getElementRects({
471
+ reference,
472
+ floating,
473
+ strategy
474
+ }) : reset.rects;
475
+ }
476
+ ({
477
+ x,
478
+ y
479
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
480
+ }
481
+ i = -1;
482
+ continue;
483
+ }
484
+ }
485
+ return {
486
+ x,
487
+ y,
488
+ placement: statefulPlacement,
489
+ strategy,
490
+ middlewareData
491
+ };
492
+ };
493
+
494
+ /**
495
+ * Resolves with an object of overflow side offsets that determine how much the
496
+ * element is overflowing a given clipping boundary on each side.
497
+ * - positive = overflowing the boundary by that number of pixels
498
+ * - negative = how many pixels left before it will overflow
499
+ * - 0 = lies flush with the boundary
500
+ * @see https://floating-ui.com/docs/detectOverflow
501
+ */
502
+ async function detectOverflow(state, options) {
503
+ var _await$platform$isEle;
504
+ if (options === void 0) {
505
+ options = {};
506
+ }
507
+ const {
508
+ x,
509
+ y,
510
+ platform,
511
+ rects,
512
+ elements,
513
+ strategy
514
+ } = state;
515
+ const {
516
+ boundary = 'clippingAncestors',
517
+ rootBoundary = 'viewport',
518
+ elementContext = 'floating',
519
+ altBoundary = false,
520
+ padding = 0
521
+ } = evaluate(options, state);
522
+ const paddingObject = getPaddingObject(padding);
523
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
524
+ const element = elements[altBoundary ? altContext : elementContext];
525
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
526
+ 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))),
527
+ boundary,
528
+ rootBoundary,
529
+ strategy
530
+ }));
531
+ const rect = elementContext === 'floating' ? {
532
+ ...rects.floating,
533
+ x,
534
+ y
535
+ } : rects.reference;
536
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
537
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
538
+ x: 1,
539
+ y: 1
540
+ } : {
541
+ x: 1,
542
+ y: 1
543
+ };
544
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
545
+ rect,
546
+ offsetParent,
547
+ strategy
548
+ }) : rect);
549
+ return {
550
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
551
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
552
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
553
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
554
+ };
555
+ }
556
+
557
+ /**
558
+ * Provides data to position an inner element of the floating element so that it
559
+ * appears centered to the reference element.
560
+ * @see https://floating-ui.com/docs/arrow
561
+ */
562
+ const arrow$1 = options => ({
563
+ name: 'arrow',
564
+ options,
565
+ async fn(state) {
566
+ const {
567
+ x,
568
+ y,
569
+ placement,
570
+ rects,
571
+ platform,
572
+ elements,
573
+ middlewareData
574
+ } = state;
575
+ // Since `element` is required, we don't Partial<> the type.
576
+ const {
577
+ element,
578
+ padding = 0
579
+ } = evaluate(options, state) || {};
580
+ if (element == null) {
581
+ return {};
582
+ }
583
+ const paddingObject = getPaddingObject(padding);
584
+ const coords = {
585
+ x,
586
+ y
587
+ };
588
+ const axis = getAlignmentAxis(placement);
589
+ const length = getAxisLength(axis);
590
+ const arrowDimensions = await platform.getDimensions(element);
591
+ const isYAxis = axis === 'y';
592
+ const minProp = isYAxis ? 'top' : 'left';
593
+ const maxProp = isYAxis ? 'bottom' : 'right';
594
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
595
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
596
+ const startDiff = coords[axis] - rects.reference[axis];
597
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
598
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
599
+
600
+ // DOM platform can return `window` as the `offsetParent`.
601
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
602
+ clientSize = elements.floating[clientProp] || rects.floating[length];
603
+ }
604
+ const centerToReference = endDiff / 2 - startDiff / 2;
605
+
606
+ // If the padding is large enough that it causes the arrow to no longer be
607
+ // centered, modify the padding so that it is centered.
608
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
609
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
610
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
611
+
612
+ // Make sure the arrow doesn't overflow the floating element if the center
613
+ // point is outside the floating element's bounds.
614
+ const min$1 = minPadding;
615
+ const max = clientSize - arrowDimensions[length] - maxPadding;
616
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
617
+ const offset = clamp(min$1, center, max);
618
+
619
+ // If the reference is small enough that the arrow's padding causes it to
620
+ // to point to nothing for an aligned placement, adjust the offset of the
621
+ // floating element itself. To ensure `shift()` continues to take action,
622
+ // a single reset is performed when this is true.
623
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
624
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
625
+ return {
626
+ [axis]: coords[axis] + alignmentOffset,
627
+ data: {
628
+ [axis]: offset,
629
+ centerOffset: center - offset - alignmentOffset,
630
+ ...(shouldAddOffset && {
631
+ alignmentOffset
632
+ })
633
+ },
634
+ reset: shouldAddOffset
635
+ };
636
+ }
637
+ });
638
+
639
+ /**
640
+ * Optimizes the visibility of the floating element by flipping the `placement`
641
+ * in order to keep it in view when the preferred placement(s) will overflow the
642
+ * clipping boundary. Alternative to `autoPlacement`.
643
+ * @see https://floating-ui.com/docs/flip
644
+ */
645
+ const flip = function (options) {
646
+ if (options === void 0) {
647
+ options = {};
648
+ }
649
+ return {
650
+ name: 'flip',
651
+ options,
652
+ async fn(state) {
653
+ var _middlewareData$arrow, _middlewareData$flip;
654
+ const {
655
+ placement,
656
+ middlewareData,
657
+ rects,
658
+ initialPlacement,
659
+ platform,
660
+ elements
661
+ } = state;
662
+ const {
663
+ mainAxis: checkMainAxis = true,
664
+ crossAxis: checkCrossAxis = true,
665
+ fallbackPlacements: specifiedFallbackPlacements,
666
+ fallbackStrategy = 'bestFit',
667
+ fallbackAxisSideDirection = 'none',
668
+ flipAlignment = true,
669
+ ...detectOverflowOptions
670
+ } = evaluate(options, state);
671
+
672
+ // If a reset by the arrow was caused due to an alignment offset being
673
+ // added, we should skip any logic now since `flip()` has already done its
674
+ // work.
675
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
676
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
677
+ return {};
678
+ }
679
+ const side = getSide(placement);
680
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
681
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
682
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
683
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
684
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
685
+ }
686
+ const placements = [initialPlacement, ...fallbackPlacements];
687
+ const overflow = await detectOverflow(state, detectOverflowOptions);
688
+ const overflows = [];
689
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
690
+ if (checkMainAxis) {
691
+ overflows.push(overflow[side]);
692
+ }
693
+ if (checkCrossAxis) {
694
+ const sides = getAlignmentSides(placement, rects, rtl);
695
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
696
+ }
697
+ overflowsData = [...overflowsData, {
698
+ placement,
699
+ overflows
700
+ }];
701
+
702
+ // One or more sides is overflowing.
703
+ if (!overflows.every(side => side <= 0)) {
704
+ var _middlewareData$flip2, _overflowsData$filter;
705
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
706
+ const nextPlacement = placements[nextIndex];
707
+ if (nextPlacement) {
708
+ // Try next placement and re-run the lifecycle.
709
+ return {
710
+ data: {
711
+ index: nextIndex,
712
+ overflows: overflowsData
713
+ },
714
+ reset: {
715
+ placement: nextPlacement
716
+ }
717
+ };
718
+ }
719
+
720
+ // First, find the candidates that fit on the mainAxis side of overflow,
721
+ // then find the placement that fits the best on the main crossAxis side.
722
+ 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;
723
+
724
+ // Otherwise fallback.
725
+ if (!resetPlacement) {
726
+ switch (fallbackStrategy) {
727
+ case 'bestFit':
728
+ {
729
+ var _overflowsData$map$so;
730
+ 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];
731
+ if (placement) {
732
+ resetPlacement = placement;
733
+ }
734
+ break;
735
+ }
736
+ case 'initialPlacement':
737
+ resetPlacement = initialPlacement;
738
+ break;
739
+ }
740
+ }
741
+ if (placement !== resetPlacement) {
742
+ return {
743
+ reset: {
744
+ placement: resetPlacement
745
+ }
746
+ };
747
+ }
748
+ }
749
+ return {};
750
+ }
751
+ };
752
+ };
753
+
754
+ // For type backwards-compatibility, the `OffsetOptions` type was also
755
+ // Derivable.
756
+ async function convertValueToCoords(state, options) {
757
+ const {
758
+ placement,
759
+ platform,
760
+ elements
761
+ } = state;
762
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
763
+ const side = getSide(placement);
764
+ const alignment = getAlignment(placement);
765
+ const isVertical = getSideAxis(placement) === 'y';
766
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
767
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
768
+ const rawValue = evaluate(options, state);
769
+
770
+ // eslint-disable-next-line prefer-const
771
+ let {
772
+ mainAxis,
773
+ crossAxis,
774
+ alignmentAxis
775
+ } = typeof rawValue === 'number' ? {
776
+ mainAxis: rawValue,
777
+ crossAxis: 0,
778
+ alignmentAxis: null
779
+ } : {
780
+ mainAxis: 0,
781
+ crossAxis: 0,
782
+ alignmentAxis: null,
783
+ ...rawValue
784
+ };
785
+ if (alignment && typeof alignmentAxis === 'number') {
786
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
787
+ }
788
+ return isVertical ? {
789
+ x: crossAxis * crossAxisMulti,
790
+ y: mainAxis * mainAxisMulti
791
+ } : {
792
+ x: mainAxis * mainAxisMulti,
793
+ y: crossAxis * crossAxisMulti
794
+ };
795
+ }
796
+
797
+ /**
798
+ * Modifies the placement by translating the floating element along the
799
+ * specified axes.
800
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
801
+ * object may be passed.
802
+ * @see https://floating-ui.com/docs/offset
803
+ */
804
+ const offset = function (options) {
805
+ if (options === void 0) {
806
+ options = 0;
807
+ }
808
+ return {
809
+ name: 'offset',
810
+ options,
811
+ async fn(state) {
812
+ var _middlewareData$offse, _middlewareData$arrow;
813
+ const {
814
+ x,
815
+ y,
816
+ placement,
817
+ middlewareData
818
+ } = state;
819
+ const diffCoords = await convertValueToCoords(state, options);
820
+
821
+ // If the placement is the same and the arrow caused an alignment offset
822
+ // then we don't need to change the positioning coordinates.
823
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
824
+ return {};
825
+ }
826
+ return {
827
+ x: x + diffCoords.x,
828
+ y: y + diffCoords.y,
829
+ data: {
830
+ ...diffCoords,
831
+ placement
832
+ }
833
+ };
834
+ }
835
+ };
836
+ };
837
+
838
+ function getCssDimensions(element) {
839
+ const css = getComputedStyle(element);
840
+ // In testing environments, the `width` and `height` properties are empty
841
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
842
+ let width = parseFloat(css.width) || 0;
843
+ let height = parseFloat(css.height) || 0;
844
+ const hasOffset = isHTMLElement(element);
845
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
846
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
847
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
848
+ if (shouldFallback) {
849
+ width = offsetWidth;
850
+ height = offsetHeight;
851
+ }
852
+ return {
853
+ width,
854
+ height,
855
+ $: shouldFallback
856
+ };
857
+ }
858
+
859
+ function unwrapElement(element) {
860
+ return !isElement(element) ? element.contextElement : element;
861
+ }
862
+
863
+ function getScale(element) {
864
+ const domElement = unwrapElement(element);
865
+ if (!isHTMLElement(domElement)) {
866
+ return createCoords(1);
867
+ }
868
+ const rect = domElement.getBoundingClientRect();
869
+ const {
870
+ width,
871
+ height,
872
+ $
873
+ } = getCssDimensions(domElement);
874
+ let x = ($ ? round(rect.width) : rect.width) / width;
875
+ let y = ($ ? round(rect.height) : rect.height) / height;
876
+
877
+ // 0, NaN, or Infinity should always fallback to 1.
878
+
879
+ if (!x || !Number.isFinite(x)) {
880
+ x = 1;
881
+ }
882
+ if (!y || !Number.isFinite(y)) {
883
+ y = 1;
884
+ }
885
+ return {
886
+ x,
887
+ y
888
+ };
889
+ }
890
+
891
+ const noOffsets = /*#__PURE__*/createCoords(0);
892
+ function getVisualOffsets(element) {
893
+ const win = getWindow(element);
894
+ if (!isWebKit() || !win.visualViewport) {
895
+ return noOffsets;
896
+ }
897
+ return {
898
+ x: win.visualViewport.offsetLeft,
899
+ y: win.visualViewport.offsetTop
900
+ };
901
+ }
902
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
903
+ if (isFixed === void 0) {
904
+ isFixed = false;
905
+ }
906
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
907
+ return false;
908
+ }
909
+ return isFixed;
910
+ }
911
+
912
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
913
+ if (includeScale === void 0) {
914
+ includeScale = false;
915
+ }
916
+ if (isFixedStrategy === void 0) {
917
+ isFixedStrategy = false;
918
+ }
919
+ const clientRect = element.getBoundingClientRect();
920
+ const domElement = unwrapElement(element);
921
+ let scale = createCoords(1);
922
+ if (includeScale) {
923
+ if (offsetParent) {
924
+ if (isElement(offsetParent)) {
925
+ scale = getScale(offsetParent);
926
+ }
927
+ } else {
928
+ scale = getScale(element);
929
+ }
930
+ }
931
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
932
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
933
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
934
+ let width = clientRect.width / scale.x;
935
+ let height = clientRect.height / scale.y;
936
+ if (domElement) {
937
+ const win = getWindow(domElement);
938
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
939
+ let currentIFrame = win.frameElement;
940
+ while (currentIFrame && offsetParent && offsetWin !== win) {
941
+ const iframeScale = getScale(currentIFrame);
942
+ const iframeRect = currentIFrame.getBoundingClientRect();
943
+ const css = getComputedStyle(currentIFrame);
944
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
945
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
946
+ x *= iframeScale.x;
947
+ y *= iframeScale.y;
948
+ width *= iframeScale.x;
949
+ height *= iframeScale.y;
950
+ x += left;
951
+ y += top;
952
+ currentIFrame = getWindow(currentIFrame).frameElement;
953
+ }
954
+ }
955
+ return rectToClientRect({
956
+ width,
957
+ height,
958
+ x,
959
+ y
960
+ });
961
+ }
962
+
963
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
964
+ let {
965
+ rect,
966
+ offsetParent,
967
+ strategy
968
+ } = _ref;
969
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
970
+ const documentElement = getDocumentElement(offsetParent);
971
+ if (offsetParent === documentElement) {
972
+ return rect;
973
+ }
974
+ let scroll = {
975
+ scrollLeft: 0,
976
+ scrollTop: 0
977
+ };
978
+ let scale = createCoords(1);
979
+ const offsets = createCoords(0);
980
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
981
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
982
+ scroll = getNodeScroll(offsetParent);
983
+ }
984
+ if (isHTMLElement(offsetParent)) {
985
+ const offsetRect = getBoundingClientRect(offsetParent);
986
+ scale = getScale(offsetParent);
987
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
988
+ offsets.y = offsetRect.y + offsetParent.clientTop;
989
+ }
990
+ }
991
+ return {
992
+ width: rect.width * scale.x,
993
+ height: rect.height * scale.y,
994
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
995
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
996
+ };
997
+ }
998
+
999
+ function getClientRects(element) {
1000
+ return Array.from(element.getClientRects());
1001
+ }
1002
+
1003
+ function getWindowScrollBarX(element) {
1004
+ // If <html> has a CSS width greater than the viewport, then this will be
1005
+ // incorrect for RTL.
1006
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
1007
+ }
1008
+
1009
+ // Gets the entire size of the scrollable document area, even extending outside
1010
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
1011
+ function getDocumentRect(element) {
1012
+ const html = getDocumentElement(element);
1013
+ const scroll = getNodeScroll(element);
1014
+ const body = element.ownerDocument.body;
1015
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1016
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1017
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1018
+ const y = -scroll.scrollTop;
1019
+ if (getComputedStyle(body).direction === 'rtl') {
1020
+ x += max(html.clientWidth, body.clientWidth) - width;
1021
+ }
1022
+ return {
1023
+ width,
1024
+ height,
1025
+ x,
1026
+ y
1027
+ };
1028
+ }
1029
+
1030
+ function getViewportRect(element, strategy) {
1031
+ const win = getWindow(element);
1032
+ const html = getDocumentElement(element);
1033
+ const visualViewport = win.visualViewport;
1034
+ let width = html.clientWidth;
1035
+ let height = html.clientHeight;
1036
+ let x = 0;
1037
+ let y = 0;
1038
+ if (visualViewport) {
1039
+ width = visualViewport.width;
1040
+ height = visualViewport.height;
1041
+ const visualViewportBased = isWebKit();
1042
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
1043
+ x = visualViewport.offsetLeft;
1044
+ y = visualViewport.offsetTop;
1045
+ }
1046
+ }
1047
+ return {
1048
+ width,
1049
+ height,
1050
+ x,
1051
+ y
1052
+ };
1053
+ }
1054
+
1055
+ // Returns the inner client rect, subtracting scrollbars if present.
1056
+ function getInnerBoundingClientRect(element, strategy) {
1057
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
1058
+ const top = clientRect.top + element.clientTop;
1059
+ const left = clientRect.left + element.clientLeft;
1060
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1061
+ const width = element.clientWidth * scale.x;
1062
+ const height = element.clientHeight * scale.y;
1063
+ const x = left * scale.x;
1064
+ const y = top * scale.y;
1065
+ return {
1066
+ width,
1067
+ height,
1068
+ x,
1069
+ y
1070
+ };
1071
+ }
1072
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1073
+ let rect;
1074
+ if (clippingAncestor === 'viewport') {
1075
+ rect = getViewportRect(element, strategy);
1076
+ } else if (clippingAncestor === 'document') {
1077
+ rect = getDocumentRect(getDocumentElement(element));
1078
+ } else if (isElement(clippingAncestor)) {
1079
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1080
+ } else {
1081
+ const visualOffsets = getVisualOffsets(element);
1082
+ rect = {
1083
+ ...clippingAncestor,
1084
+ x: clippingAncestor.x - visualOffsets.x,
1085
+ y: clippingAncestor.y - visualOffsets.y
1086
+ };
1087
+ }
1088
+ return rectToClientRect(rect);
1089
+ }
1090
+ function hasFixedPositionAncestor(element, stopNode) {
1091
+ const parentNode = getParentNode(element);
1092
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1093
+ return false;
1094
+ }
1095
+ return getComputedStyle(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
1096
+ }
1097
+
1098
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
1099
+ // clipping (or hiding) child elements. This returns all clipping ancestors
1100
+ // of the given element up the tree.
1101
+ function getClippingElementAncestors(element, cache) {
1102
+ const cachedResult = cache.get(element);
1103
+ if (cachedResult) {
1104
+ return cachedResult;
1105
+ }
1106
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
1107
+ let currentContainingBlockComputedStyle = null;
1108
+ const elementIsFixed = getComputedStyle(element).position === 'fixed';
1109
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1110
+
1111
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1112
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1113
+ const computedStyle = getComputedStyle(currentNode);
1114
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1115
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
1116
+ currentContainingBlockComputedStyle = null;
1117
+ }
1118
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1119
+ if (shouldDropCurrentNode) {
1120
+ // Drop non-containing blocks.
1121
+ result = result.filter(ancestor => ancestor !== currentNode);
1122
+ } else {
1123
+ // Record last containing block for next iteration.
1124
+ currentContainingBlockComputedStyle = computedStyle;
1125
+ }
1126
+ currentNode = getParentNode(currentNode);
1127
+ }
1128
+ cache.set(element, result);
1129
+ return result;
1130
+ }
1131
+
1132
+ // Gets the maximum area that the element is visible in due to any number of
1133
+ // clipping ancestors.
1134
+ function getClippingRect(_ref) {
1135
+ let {
1136
+ element,
1137
+ boundary,
1138
+ rootBoundary,
1139
+ strategy
1140
+ } = _ref;
1141
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
1142
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1143
+ const firstClippingAncestor = clippingAncestors[0];
1144
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
1145
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1146
+ accRect.top = max(rect.top, accRect.top);
1147
+ accRect.right = min(rect.right, accRect.right);
1148
+ accRect.bottom = min(rect.bottom, accRect.bottom);
1149
+ accRect.left = max(rect.left, accRect.left);
1150
+ return accRect;
1151
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1152
+ return {
1153
+ width: clippingRect.right - clippingRect.left,
1154
+ height: clippingRect.bottom - clippingRect.top,
1155
+ x: clippingRect.left,
1156
+ y: clippingRect.top
1157
+ };
1158
+ }
1159
+
1160
+ function getDimensions(element) {
1161
+ return getCssDimensions(element);
1162
+ }
1163
+
1164
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1165
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1166
+ const documentElement = getDocumentElement(offsetParent);
1167
+ const isFixed = strategy === 'fixed';
1168
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1169
+ let scroll = {
1170
+ scrollLeft: 0,
1171
+ scrollTop: 0
1172
+ };
1173
+ const offsets = createCoords(0);
1174
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1175
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1176
+ scroll = getNodeScroll(offsetParent);
1177
+ }
1178
+ if (isOffsetParentAnElement) {
1179
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1180
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1181
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1182
+ } else if (documentElement) {
1183
+ offsets.x = getWindowScrollBarX(documentElement);
1184
+ }
1185
+ }
1186
+ return {
1187
+ x: rect.left + scroll.scrollLeft - offsets.x,
1188
+ y: rect.top + scroll.scrollTop - offsets.y,
1189
+ width: rect.width,
1190
+ height: rect.height
1191
+ };
1192
+ }
1193
+
1194
+ function getTrueOffsetParent(element, polyfill) {
1195
+ if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {
1196
+ return null;
1197
+ }
1198
+ if (polyfill) {
1199
+ return polyfill(element);
1200
+ }
1201
+ return element.offsetParent;
1202
+ }
1203
+
1204
+ // Gets the closest ancestor positioned element. Handles some edge cases,
1205
+ // such as table ancestors and cross browser bugs.
1206
+ function getOffsetParent(element, polyfill) {
1207
+ const window = getWindow(element);
1208
+ if (!isHTMLElement(element)) {
1209
+ return window;
1210
+ }
1211
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1212
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
1213
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1214
+ }
1215
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
1216
+ return window;
1217
+ }
1218
+ return offsetParent || getContainingBlock(element) || window;
1219
+ }
1220
+
1221
+ const getElementRects = async function (_ref) {
1222
+ let {
1223
+ reference,
1224
+ floating,
1225
+ strategy
1226
+ } = _ref;
1227
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1228
+ const getDimensionsFn = this.getDimensions;
1229
+ return {
1230
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
1231
+ floating: {
1232
+ x: 0,
1233
+ y: 0,
1234
+ ...(await getDimensionsFn(floating))
1235
+ }
1236
+ };
1237
+ };
1238
+
1239
+ function isRTL(element) {
1240
+ return getComputedStyle(element).direction === 'rtl';
1241
+ }
1242
+
1243
+ const platform = {
1244
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1245
+ getDocumentElement,
1246
+ getClippingRect,
1247
+ getOffsetParent,
1248
+ getElementRects,
1249
+ getClientRects,
1250
+ getDimensions,
1251
+ getScale,
1252
+ isElement,
1253
+ isRTL
1254
+ };
1255
+
1256
+ /**
1257
+ * Computes the `x` and `y` coordinates that will place the floating element
1258
+ * next to a reference element when it is given a certain CSS positioning
1259
+ * strategy.
1260
+ */
1261
+ const computePosition = (reference, floating, options) => {
1262
+ // This caches the expensive `getClippingElementAncestors` function so that
1263
+ // multiple lifecycle resets re-use the same result. It only lives for a
1264
+ // single call. If other functions become expensive, we can add them as well.
1265
+ const cache = new Map();
1266
+ const mergedOptions = {
1267
+ platform,
1268
+ ...options
1269
+ };
1270
+ const platformWithCache = {
1271
+ ...mergedOptions.platform,
1272
+ _c: cache
1273
+ };
1274
+ return computePosition$1(reference, floating, {
1275
+ ...mergedOptions,
1276
+ platform: platformWithCache
1277
+ });
1278
+ };
1279
+
1280
+ /**
1281
+ * Provides data to position an inner element of the floating element so that it
1282
+ * appears centered to the reference element.
1283
+ * This wraps the core `arrow` middleware to allow React refs as the element.
1284
+ * @see https://floating-ui.com/docs/arrow
1285
+ */
1286
+ const arrow = options => {
1287
+ function isRef(value) {
1288
+ return {}.hasOwnProperty.call(value, 'current');
1289
+ }
1290
+ return {
1291
+ name: 'arrow',
1292
+ options,
1293
+ fn(state) {
1294
+ const {
1295
+ element,
1296
+ padding
1297
+ } = typeof options === 'function' ? options(state) : options;
1298
+ if (element && isRef(element)) {
1299
+ if (element.current != null) {
1300
+ return arrow$1({
1301
+ element: element.current,
1302
+ padding
1303
+ }).fn(state);
1304
+ }
1305
+ return {};
1306
+ } else if (element) {
1307
+ return arrow$1({
1308
+ element,
1309
+ padding
1310
+ }).fn(state);
1311
+ }
1312
+ return {};
1313
+ }
1314
+ };
1315
+ };
1316
+
1317
+ var index$1 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1318
+
1319
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1320
+ // functions
1321
+ function deepEqual(a, b) {
1322
+ if (a === b) {
1323
+ return true;
1324
+ }
1325
+ if (typeof a !== typeof b) {
1326
+ return false;
1327
+ }
1328
+ if (typeof a === 'function' && a.toString() === b.toString()) {
1329
+ return true;
1330
+ }
1331
+ let length, i, keys;
1332
+ if (a && b && typeof a == 'object') {
1333
+ if (Array.isArray(a)) {
1334
+ length = a.length;
1335
+ if (length != b.length) return false;
1336
+ for (i = length; i-- !== 0;) {
1337
+ if (!deepEqual(a[i], b[i])) {
1338
+ return false;
1339
+ }
1340
+ }
1341
+ return true;
1342
+ }
1343
+ keys = Object.keys(a);
1344
+ length = keys.length;
1345
+ if (length !== Object.keys(b).length) {
1346
+ return false;
1347
+ }
1348
+ for (i = length; i-- !== 0;) {
1349
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
1350
+ return false;
1351
+ }
1352
+ }
1353
+ for (i = length; i-- !== 0;) {
1354
+ const key = keys[i];
1355
+ if (key === '_owner' && a.$$typeof) {
1356
+ continue;
1357
+ }
1358
+ if (!deepEqual(a[key], b[key])) {
1359
+ return false;
1360
+ }
1361
+ }
1362
+ return true;
1363
+ }
1364
+ return a !== a && b !== b;
1365
+ }
1366
+
1367
+ function getDPR(element) {
1368
+ if (typeof window === 'undefined') {
1369
+ return 1;
1370
+ }
1371
+ const win = element.ownerDocument.defaultView || window;
1372
+ return win.devicePixelRatio || 1;
1373
+ }
1374
+
1375
+ function roundByDPR(element, value) {
1376
+ const dpr = getDPR(element);
1377
+ return Math.round(value * dpr) / dpr;
1378
+ }
1379
+
1380
+ function useLatestRef$1(value) {
1381
+ const ref = React$1.useRef(value);
1382
+ index$1(() => {
1383
+ ref.current = value;
1384
+ });
1385
+ return ref;
1386
+ }
1387
+
1388
+ /**
1389
+ * Provides data to position a floating element.
1390
+ * @see https://floating-ui.com/docs/useFloating
1391
+ */
1392
+ function useFloating$1(options) {
1393
+ if (options === void 0) {
1394
+ options = {};
1395
+ }
1396
+ const {
1397
+ placement = 'bottom',
1398
+ strategy = 'absolute',
1399
+ middleware = [],
1400
+ platform,
1401
+ elements: {
1402
+ reference: externalReference,
1403
+ floating: externalFloating
1404
+ } = {},
1405
+ transform = true,
1406
+ whileElementsMounted,
1407
+ open
1408
+ } = options;
1409
+ const [data, setData] = React$1.useState({
1410
+ x: 0,
1411
+ y: 0,
1412
+ strategy,
1413
+ placement,
1414
+ middlewareData: {},
1415
+ isPositioned: false
1416
+ });
1417
+ const [latestMiddleware, setLatestMiddleware] = React$1.useState(middleware);
1418
+ if (!deepEqual(latestMiddleware, middleware)) {
1419
+ setLatestMiddleware(middleware);
1420
+ }
1421
+ const [_reference, _setReference] = React$1.useState(null);
1422
+ const [_floating, _setFloating] = React$1.useState(null);
1423
+ const setReference = React$1.useCallback(node => {
1424
+ if (node != referenceRef.current) {
1425
+ referenceRef.current = node;
1426
+ _setReference(node);
1427
+ }
1428
+ }, [_setReference]);
1429
+ const setFloating = React$1.useCallback(node => {
1430
+ if (node !== floatingRef.current) {
1431
+ floatingRef.current = node;
1432
+ _setFloating(node);
1433
+ }
1434
+ }, [_setFloating]);
1435
+ const referenceEl = externalReference || _reference;
1436
+ const floatingEl = externalFloating || _floating;
1437
+ const referenceRef = React$1.useRef(null);
1438
+ const floatingRef = React$1.useRef(null);
1439
+ const dataRef = React$1.useRef(data);
1440
+ const whileElementsMountedRef = useLatestRef$1(whileElementsMounted);
1441
+ const platformRef = useLatestRef$1(platform);
1442
+ const update = React$1.useCallback(() => {
1443
+ if (!referenceRef.current || !floatingRef.current) {
1444
+ return;
1445
+ }
1446
+ const config = {
1447
+ placement,
1448
+ strategy,
1449
+ middleware: latestMiddleware
1450
+ };
1451
+ if (platformRef.current) {
1452
+ config.platform = platformRef.current;
1453
+ }
1454
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
1455
+ const fullData = {
1456
+ ...data,
1457
+ isPositioned: true
1458
+ };
1459
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
1460
+ dataRef.current = fullData;
1461
+ ReactDOM.flushSync(() => {
1462
+ setData(fullData);
1463
+ });
1464
+ }
1465
+ });
1466
+ }, [latestMiddleware, placement, strategy, platformRef]);
1467
+ index$1(() => {
1468
+ if (open === false && dataRef.current.isPositioned) {
1469
+ dataRef.current.isPositioned = false;
1470
+ setData(data => ({
1471
+ ...data,
1472
+ isPositioned: false
1473
+ }));
1474
+ }
1475
+ }, [open]);
1476
+ const isMountedRef = React$1.useRef(false);
1477
+ index$1(() => {
1478
+ isMountedRef.current = true;
1479
+ return () => {
1480
+ isMountedRef.current = false;
1481
+ };
1482
+ }, []);
1483
+ index$1(() => {
1484
+ if (referenceEl) referenceRef.current = referenceEl;
1485
+ if (floatingEl) floatingRef.current = floatingEl;
1486
+ if (referenceEl && floatingEl) {
1487
+ if (whileElementsMountedRef.current) {
1488
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
1489
+ } else {
1490
+ update();
1491
+ }
1492
+ }
1493
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef]);
1494
+ const refs = React$1.useMemo(() => ({
1495
+ reference: referenceRef,
1496
+ floating: floatingRef,
1497
+ setReference,
1498
+ setFloating
1499
+ }), [setReference, setFloating]);
1500
+ const elements = React$1.useMemo(() => ({
1501
+ reference: referenceEl,
1502
+ floating: floatingEl
1503
+ }), [referenceEl, floatingEl]);
1504
+ const floatingStyles = React$1.useMemo(() => {
1505
+ const initialStyles = {
1506
+ position: strategy,
1507
+ left: 0,
1508
+ top: 0
1509
+ };
1510
+ if (!elements.floating) {
1511
+ return initialStyles;
1512
+ }
1513
+ const x = roundByDPR(elements.floating, data.x);
1514
+ const y = roundByDPR(elements.floating, data.y);
1515
+ if (transform) {
1516
+ return {
1517
+ ...initialStyles,
1518
+ transform: "translate(" + x + "px, " + y + "px)",
1519
+ ...(getDPR(elements.floating) >= 1.5 && {
1520
+ willChange: 'transform'
1521
+ })
1522
+ };
1523
+ }
1524
+ return {
1525
+ position: strategy,
1526
+ left: x,
1527
+ top: y
1528
+ };
1529
+ }, [strategy, transform, elements.floating, data.x, data.y]);
1530
+ return React$1.useMemo(() => ({
1531
+ ...data,
1532
+ update,
1533
+ refs,
1534
+ elements,
1535
+ floatingStyles
1536
+ }), [data, update, refs, elements, floatingStyles]);
1537
+ }
1538
+
1539
+ // `toString()` prevents bundlers from trying to `import { useInsertionEffect } from 'react'`
1540
+ const useInsertionEffect = React$1[/*#__PURE__*/'useInsertionEffect'.toString()];
1541
+ const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
1542
+ function useEffectEvent(callback) {
1543
+ const ref = React$1.useRef(() => {
1544
+ if (process.env.NODE_ENV !== "production") {
1545
+ throw new Error('Cannot call an event handler while rendering.');
1546
+ }
1547
+ });
1548
+ useSafeInsertionEffect(() => {
1549
+ ref.current = callback;
1550
+ });
1551
+ return React$1.useCallback(function () {
1552
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1553
+ args[_key] = arguments[_key];
1554
+ }
1555
+ return ref.current == null ? void 0 : ref.current(...args);
1556
+ }, []);
1557
+ }
1558
+
1559
+ var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1560
+
1561
+ function _extends() {
1562
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
1563
+ for (var i = 1; i < arguments.length; i++) {
1564
+ var source = arguments[i];
1565
+ for (var key in source) {
1566
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1567
+ target[key] = source[key];
1568
+ }
1569
+ }
1570
+ }
1571
+ return target;
1572
+ };
1573
+ return _extends.apply(this, arguments);
1574
+ }
1575
+
1576
+ let serverHandoffComplete = false;
1577
+ let count = 0;
1578
+ const genId = () => "floating-ui-" + count++;
1579
+ function useFloatingId() {
1580
+ const [id, setId] = React$1.useState(() => serverHandoffComplete ? genId() : undefined);
1581
+ index(() => {
1582
+ if (id == null) {
1583
+ setId(genId());
1584
+ }
1585
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1586
+ }, []);
1587
+ React$1.useEffect(() => {
1588
+ if (!serverHandoffComplete) {
1589
+ serverHandoffComplete = true;
1590
+ }
1591
+ }, []);
1592
+ return id;
1593
+ }
1594
+
1595
+ // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
1596
+ const useReactId = React$1[/*#__PURE__*/'useId'.toString()];
1597
+
1598
+ /**
1599
+ * Uses React 18's built-in `useId()` when available, or falls back to a
1600
+ * slightly less performant (requiring a double render) implementation for
1601
+ * earlier React versions.
1602
+ * @see https://floating-ui.com/docs/useId
1603
+ */
1604
+ const useId = useReactId || useFloatingId;
1605
+
1606
+ /**
1607
+ * Renders a pointing arrow triangle.
1608
+ * @see https://floating-ui.com/docs/FloatingArrow
1609
+ */
1610
+ const FloatingArrow = /*#__PURE__*/React$1.forwardRef(function FloatingArrow(_ref, ref) {
1611
+ let {
1612
+ context: {
1613
+ placement,
1614
+ elements: {
1615
+ floating
1616
+ },
1617
+ middlewareData: {
1618
+ arrow
1619
+ }
1620
+ },
1621
+ width = 14,
1622
+ height = 7,
1623
+ tipRadius = 0,
1624
+ strokeWidth = 0,
1625
+ staticOffset,
1626
+ stroke,
1627
+ d,
1628
+ style: {
1629
+ transform,
1630
+ ...restStyle
1631
+ } = {},
1632
+ ...rest
1633
+ } = _ref;
1634
+ if (process.env.NODE_ENV !== "production") {
1635
+ if (!ref) {
1636
+ console.warn('Floating UI: The `ref` prop is required for the `FloatingArrow`', 'component.');
1637
+ }
1638
+ }
1639
+ const clipPathId = useId();
1640
+ if (!floating) {
1641
+ return null;
1642
+ }
1643
+
1644
+ // Strokes must be double the border width, this ensures the stroke's width
1645
+ // works as you'd expect.
1646
+ strokeWidth *= 2;
1647
+ const halfStrokeWidth = strokeWidth / 2;
1648
+ const svgX = width / 2 * (tipRadius / -8 + 1);
1649
+ const svgY = height / 2 * tipRadius / 4;
1650
+ const [side, alignment] = placement.split('-');
1651
+ const isRTL = platform.isRTL(floating);
1652
+ const isCustomShape = !!d;
1653
+ const isVerticalSide = side === 'top' || side === 'bottom';
1654
+ const yOffsetProp = staticOffset && alignment === 'end' ? 'bottom' : 'top';
1655
+ let xOffsetProp = staticOffset && alignment === 'end' ? 'right' : 'left';
1656
+ if (staticOffset && isRTL) {
1657
+ xOffsetProp = alignment === 'end' ? 'left' : 'right';
1658
+ }
1659
+ const arrowX = (arrow == null ? void 0 : arrow.x) != null ? staticOffset || arrow.x : '';
1660
+ const arrowY = (arrow == null ? void 0 : arrow.y) != null ? staticOffset || arrow.y : '';
1661
+ const dValue = d || 'M0,0' + (" H" + width) + (" L" + (width - svgX) + "," + (height - svgY)) + (" Q" + width / 2 + "," + height + " " + svgX + "," + (height - svgY)) + ' Z';
1662
+ const rotation = {
1663
+ top: isCustomShape ? 'rotate(180deg)' : '',
1664
+ left: isCustomShape ? 'rotate(90deg)' : 'rotate(-90deg)',
1665
+ bottom: isCustomShape ? '' : 'rotate(180deg)',
1666
+ right: isCustomShape ? 'rotate(-90deg)' : 'rotate(90deg)'
1667
+ }[side];
1668
+ return /*#__PURE__*/React$1.createElement("svg", _extends({}, rest, {
1669
+ "aria-hidden": true,
1670
+ ref: ref,
1671
+ width: isCustomShape ? width : width + strokeWidth,
1672
+ height: width,
1673
+ viewBox: "0 0 " + width + " " + (height > width ? height : width),
1674
+ style: {
1675
+ position: 'absolute',
1676
+ pointerEvents: 'none',
1677
+ [xOffsetProp]: arrowX,
1678
+ [yOffsetProp]: arrowY,
1679
+ [side]: isVerticalSide || isCustomShape ? '100%' : "calc(100% - " + strokeWidth / 2 + "px)",
1680
+ transform: "" + rotation + (transform != null ? transform : ''),
1681
+ ...restStyle
1682
+ }
1683
+ }), strokeWidth > 0 && /*#__PURE__*/React$1.createElement("path", {
1684
+ clipPath: "url(#" + clipPathId + ")",
1685
+ fill: "none",
1686
+ stroke: stroke
1687
+ // Account for the stroke on the fill path rendered below.
1688
+ ,
1689
+ strokeWidth: strokeWidth + (d ? 0 : 1),
1690
+ d: dValue
1691
+ }), /*#__PURE__*/React$1.createElement("path", {
1692
+ stroke: strokeWidth && !d ? rest.fill : 'none',
1693
+ d: dValue
1694
+ }), /*#__PURE__*/React$1.createElement("clipPath", {
1695
+ id: clipPathId
1696
+ }, /*#__PURE__*/React$1.createElement("rect", {
1697
+ x: -halfStrokeWidth,
1698
+ y: halfStrokeWidth * (isCustomShape ? -1 : 1),
1699
+ width: width + strokeWidth,
1700
+ height: width
1701
+ })));
1702
+ });
1703
+
1704
+ function createPubSub() {
1705
+ const map = new Map();
1706
+ return {
1707
+ emit(event, data) {
1708
+ var _map$get;
1709
+ (_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
1710
+ },
1711
+ on(event, listener) {
1712
+ map.set(event, [...(map.get(event) || []), listener]);
1713
+ },
1714
+ off(event, listener) {
1715
+ var _map$get2;
1716
+ map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
1717
+ }
1718
+ };
1719
+ }
1720
+
1721
+ const FloatingNodeContext = /*#__PURE__*/React$1.createContext(null);
1722
+ const FloatingTreeContext = /*#__PURE__*/React$1.createContext(null);
1723
+ const useFloatingParentNodeId = () => {
1724
+ var _React$useContext;
1725
+ return ((_React$useContext = React$1.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
1726
+ };
1727
+ const useFloatingTree = () => React$1.useContext(FloatingTreeContext);
1728
+
1729
+ function createAttribute(name) {
1730
+ return "data-floating-ui-" + name;
1731
+ }
1732
+
1733
+ function useLatestRef(value) {
1734
+ const ref = useRef(value);
1735
+ index(() => {
1736
+ ref.current = value;
1737
+ });
1738
+ return ref;
1739
+ }
1740
+
1741
+ const safePolygonIdentifier = /*#__PURE__*/createAttribute('safe-polygon');
1742
+ function getDelay(value, prop, pointerType) {
1743
+ if (pointerType && !isMouseLikePointerType(pointerType)) {
1744
+ return 0;
1745
+ }
1746
+ if (typeof value === 'number') {
1747
+ return value;
1748
+ }
1749
+ return value == null ? void 0 : value[prop];
1750
+ }
1751
+ /**
1752
+ * Opens the floating element while hovering over the reference element, like
1753
+ * CSS `:hover`.
1754
+ * @see https://floating-ui.com/docs/useHover
1755
+ */
1756
+ function useHover(context, props) {
1757
+ if (props === void 0) {
1758
+ props = {};
1759
+ }
1760
+ const {
1761
+ open,
1762
+ onOpenChange,
1763
+ dataRef,
1764
+ events,
1765
+ elements: {
1766
+ domReference,
1767
+ floating
1768
+ },
1769
+ refs
1770
+ } = context;
1771
+ const {
1772
+ enabled = true,
1773
+ delay = 0,
1774
+ handleClose = null,
1775
+ mouseOnly = false,
1776
+ restMs = 0,
1777
+ move = true
1778
+ } = props;
1779
+ const tree = useFloatingTree();
1780
+ const parentId = useFloatingParentNodeId();
1781
+ const handleCloseRef = useLatestRef(handleClose);
1782
+ const delayRef = useLatestRef(delay);
1783
+ const pointerTypeRef = React$1.useRef();
1784
+ const timeoutRef = React$1.useRef();
1785
+ const handlerRef = React$1.useRef();
1786
+ const restTimeoutRef = React$1.useRef();
1787
+ const blockMouseMoveRef = React$1.useRef(true);
1788
+ const performedPointerEventsMutationRef = React$1.useRef(false);
1789
+ const unbindMouseMoveRef = React$1.useRef(() => {});
1790
+ const isHoverOpen = React$1.useCallback(() => {
1791
+ var _dataRef$current$open;
1792
+ const type = (_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type;
1793
+ return (type == null ? void 0 : type.includes('mouse')) && type !== 'mousedown';
1794
+ }, [dataRef]);
1795
+
1796
+ // When closing before opening, clear the delay timeouts to cancel it
1797
+ // from showing.
1798
+ React$1.useEffect(() => {
1799
+ if (!enabled) {
1800
+ return;
1801
+ }
1802
+ function onOpenChange(_ref) {
1803
+ let {
1804
+ open
1805
+ } = _ref;
1806
+ if (!open) {
1807
+ clearTimeout(timeoutRef.current);
1808
+ clearTimeout(restTimeoutRef.current);
1809
+ blockMouseMoveRef.current = true;
1810
+ }
1811
+ }
1812
+ events.on('openchange', onOpenChange);
1813
+ return () => {
1814
+ events.off('openchange', onOpenChange);
1815
+ };
1816
+ }, [enabled, events]);
1817
+ React$1.useEffect(() => {
1818
+ if (!enabled || !handleCloseRef.current || !open) {
1819
+ return;
1820
+ }
1821
+ function onLeave(event) {
1822
+ if (isHoverOpen()) {
1823
+ onOpenChange(false, event, 'hover');
1824
+ }
1825
+ }
1826
+ const html = getDocument(floating).documentElement;
1827
+ html.addEventListener('mouseleave', onLeave);
1828
+ return () => {
1829
+ html.removeEventListener('mouseleave', onLeave);
1830
+ };
1831
+ }, [floating, open, onOpenChange, enabled, handleCloseRef, dataRef, isHoverOpen]);
1832
+ const closeWithDelay = React$1.useCallback(function (event, runElseBranch, reason) {
1833
+ if (runElseBranch === void 0) {
1834
+ runElseBranch = true;
1835
+ }
1836
+ if (reason === void 0) {
1837
+ reason = 'hover';
1838
+ }
1839
+ const closeDelay = getDelay(delayRef.current, 'close', pointerTypeRef.current);
1840
+ if (closeDelay && !handlerRef.current) {
1841
+ clearTimeout(timeoutRef.current);
1842
+ timeoutRef.current = setTimeout(() => onOpenChange(false, event, reason), closeDelay);
1843
+ } else if (runElseBranch) {
1844
+ clearTimeout(timeoutRef.current);
1845
+ onOpenChange(false, event, reason);
1846
+ }
1847
+ }, [delayRef, onOpenChange]);
1848
+ const cleanupMouseMoveHandler = React$1.useCallback(() => {
1849
+ unbindMouseMoveRef.current();
1850
+ handlerRef.current = undefined;
1851
+ }, []);
1852
+ const clearPointerEvents = React$1.useCallback(() => {
1853
+ if (performedPointerEventsMutationRef.current) {
1854
+ const body = getDocument(refs.floating.current).body;
1855
+ body.style.pointerEvents = '';
1856
+ body.removeAttribute(safePolygonIdentifier);
1857
+ performedPointerEventsMutationRef.current = false;
1858
+ }
1859
+ }, [refs]);
1860
+
1861
+ // Registering the mouse events on the reference directly to bypass React's
1862
+ // delegation system. If the cursor was on a disabled element and then entered
1863
+ // the reference (no gap), `mouseenter` doesn't fire in the delegation system.
1864
+ React$1.useEffect(() => {
1865
+ if (!enabled) {
1866
+ return;
1867
+ }
1868
+ function isClickLikeOpenEvent() {
1869
+ return dataRef.current.openEvent ? ['click', 'mousedown'].includes(dataRef.current.openEvent.type) : false;
1870
+ }
1871
+ function onMouseEnter(event) {
1872
+ clearTimeout(timeoutRef.current);
1873
+ blockMouseMoveRef.current = false;
1874
+ if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || restMs > 0 && getDelay(delayRef.current, 'open') === 0) {
1875
+ return;
1876
+ }
1877
+ const openDelay = getDelay(delayRef.current, 'open', pointerTypeRef.current);
1878
+ if (openDelay) {
1879
+ timeoutRef.current = setTimeout(() => {
1880
+ onOpenChange(true, event, 'hover');
1881
+ }, openDelay);
1882
+ } else {
1883
+ onOpenChange(true, event, 'hover');
1884
+ }
1885
+ }
1886
+ function onMouseLeave(event) {
1887
+ if (isClickLikeOpenEvent()) {
1888
+ return;
1889
+ }
1890
+ unbindMouseMoveRef.current();
1891
+ const doc = getDocument(floating);
1892
+ clearTimeout(restTimeoutRef.current);
1893
+ if (handleCloseRef.current) {
1894
+ // Prevent clearing `onScrollMouseLeave` timeout.
1895
+ if (!open) {
1896
+ clearTimeout(timeoutRef.current);
1897
+ }
1898
+ handlerRef.current = handleCloseRef.current({
1899
+ ...context,
1900
+ tree,
1901
+ x: event.clientX,
1902
+ y: event.clientY,
1903
+ onClose() {
1904
+ clearPointerEvents();
1905
+ cleanupMouseMoveHandler();
1906
+ closeWithDelay(event, true, 'safe-polygon');
1907
+ }
1908
+ });
1909
+ const handler = handlerRef.current;
1910
+ doc.addEventListener('mousemove', handler);
1911
+ unbindMouseMoveRef.current = () => {
1912
+ doc.removeEventListener('mousemove', handler);
1913
+ };
1914
+ return;
1915
+ }
1916
+
1917
+ // Allow interactivity without `safePolygon` on touch devices. With a
1918
+ // pointer, a short close delay is an alternative, so it should work
1919
+ // consistently.
1920
+ const shouldClose = pointerTypeRef.current === 'touch' ? !contains(floating, event.relatedTarget) : true;
1921
+ if (shouldClose) {
1922
+ closeWithDelay(event);
1923
+ }
1924
+ }
1925
+
1926
+ // Ensure the floating element closes after scrolling even if the pointer
1927
+ // did not move.
1928
+ // https://github.com/floating-ui/floating-ui/discussions/1692
1929
+ function onScrollMouseLeave(event) {
1930
+ if (isClickLikeOpenEvent()) {
1931
+ return;
1932
+ }
1933
+ handleCloseRef.current == null || handleCloseRef.current({
1934
+ ...context,
1935
+ tree,
1936
+ x: event.clientX,
1937
+ y: event.clientY,
1938
+ onClose() {
1939
+ clearPointerEvents();
1940
+ cleanupMouseMoveHandler();
1941
+ closeWithDelay(event);
1942
+ }
1943
+ })(event);
1944
+ }
1945
+ if (isElement(domReference)) {
1946
+ const ref = domReference;
1947
+ open && ref.addEventListener('mouseleave', onScrollMouseLeave);
1948
+ floating == null || floating.addEventListener('mouseleave', onScrollMouseLeave);
1949
+ move && ref.addEventListener('mousemove', onMouseEnter, {
1950
+ once: true
1951
+ });
1952
+ ref.addEventListener('mouseenter', onMouseEnter);
1953
+ ref.addEventListener('mouseleave', onMouseLeave);
1954
+ return () => {
1955
+ open && ref.removeEventListener('mouseleave', onScrollMouseLeave);
1956
+ floating == null || floating.removeEventListener('mouseleave', onScrollMouseLeave);
1957
+ move && ref.removeEventListener('mousemove', onMouseEnter);
1958
+ ref.removeEventListener('mouseenter', onMouseEnter);
1959
+ ref.removeEventListener('mouseleave', onMouseLeave);
1960
+ };
1961
+ }
1962
+ }, [domReference, floating, enabled, context, mouseOnly, restMs, move, closeWithDelay, cleanupMouseMoveHandler, clearPointerEvents, onOpenChange, open, tree, delayRef, handleCloseRef, dataRef]);
1963
+
1964
+ // Block pointer-events of every element other than the reference and floating
1965
+ // while the floating element is open and has a `handleClose` handler. Also
1966
+ // handles nested floating elements.
1967
+ // https://github.com/floating-ui/floating-ui/issues/1722
1968
+ index(() => {
1969
+ var _handleCloseRef$curre;
1970
+ if (!enabled) {
1971
+ return;
1972
+ }
1973
+ if (open && (_handleCloseRef$curre = handleCloseRef.current) != null && _handleCloseRef$curre.__options.blockPointerEvents && isHoverOpen()) {
1974
+ const body = getDocument(floating).body;
1975
+ body.setAttribute(safePolygonIdentifier, '');
1976
+ body.style.pointerEvents = 'none';
1977
+ performedPointerEventsMutationRef.current = true;
1978
+ if (isElement(domReference) && floating) {
1979
+ var _tree$nodesRef$curren;
1980
+ const ref = domReference;
1981
+ const parentFloating = tree == null || (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren.elements.floating;
1982
+ if (parentFloating) {
1983
+ parentFloating.style.pointerEvents = '';
1984
+ }
1985
+ ref.style.pointerEvents = 'auto';
1986
+ floating.style.pointerEvents = 'auto';
1987
+ return () => {
1988
+ ref.style.pointerEvents = '';
1989
+ floating.style.pointerEvents = '';
1990
+ };
1991
+ }
1992
+ }
1993
+ }, [enabled, open, parentId, floating, domReference, tree, handleCloseRef, dataRef, isHoverOpen]);
1994
+ index(() => {
1995
+ if (!open) {
1996
+ pointerTypeRef.current = undefined;
1997
+ cleanupMouseMoveHandler();
1998
+ clearPointerEvents();
1999
+ }
2000
+ }, [open, cleanupMouseMoveHandler, clearPointerEvents]);
2001
+ React$1.useEffect(() => {
2002
+ return () => {
2003
+ cleanupMouseMoveHandler();
2004
+ clearTimeout(timeoutRef.current);
2005
+ clearTimeout(restTimeoutRef.current);
2006
+ clearPointerEvents();
2007
+ };
2008
+ }, [enabled, domReference, cleanupMouseMoveHandler, clearPointerEvents]);
2009
+ return React$1.useMemo(() => {
2010
+ if (!enabled) {
2011
+ return {};
2012
+ }
2013
+ function setPointerRef(event) {
2014
+ pointerTypeRef.current = event.pointerType;
2015
+ }
2016
+ return {
2017
+ reference: {
2018
+ onPointerDown: setPointerRef,
2019
+ onPointerEnter: setPointerRef,
2020
+ onMouseMove(event) {
2021
+ if (open || restMs === 0) {
2022
+ return;
2023
+ }
2024
+ clearTimeout(restTimeoutRef.current);
2025
+ restTimeoutRef.current = setTimeout(() => {
2026
+ if (!blockMouseMoveRef.current) {
2027
+ onOpenChange(true, event.nativeEvent, 'hover');
2028
+ }
2029
+ }, restMs);
2030
+ }
2031
+ },
2032
+ floating: {
2033
+ onMouseEnter() {
2034
+ clearTimeout(timeoutRef.current);
2035
+ },
2036
+ onMouseLeave(event) {
2037
+ closeWithDelay(event.nativeEvent, false);
2038
+ }
2039
+ }
2040
+ };
2041
+ }, [enabled, restMs, open, onOpenChange, closeWithDelay]);
2042
+ }
2043
+
2044
+ function getChildren(nodes, id) {
2045
+ let allChildren = nodes.filter(node => {
2046
+ var _node$context;
2047
+ return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
2048
+ });
2049
+ let currentChildren = allChildren;
2050
+ while (currentChildren.length) {
2051
+ currentChildren = nodes.filter(node => {
2052
+ var _currentChildren;
2053
+ return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some(n => {
2054
+ var _node$context2;
2055
+ return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
2056
+ });
2057
+ });
2058
+ allChildren = allChildren.concat(currentChildren);
2059
+ }
2060
+ return allChildren;
2061
+ }
2062
+
2063
+ const bubbleHandlerKeys = {
2064
+ pointerdown: 'onPointerDown',
2065
+ mousedown: 'onMouseDown',
2066
+ click: 'onClick'
2067
+ };
2068
+ const captureHandlerKeys = {
2069
+ pointerdown: 'onPointerDownCapture',
2070
+ mousedown: 'onMouseDownCapture',
2071
+ click: 'onClickCapture'
2072
+ };
2073
+ const normalizeProp = normalizable => {
2074
+ var _normalizable$escapeK, _normalizable$outside;
2075
+ return {
2076
+ escapeKey: typeof normalizable === 'boolean' ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
2077
+ outsidePress: typeof normalizable === 'boolean' ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
2078
+ };
2079
+ };
2080
+ /**
2081
+ * Closes the floating element when a dismissal is requested — by default, when
2082
+ * the user presses the `escape` key or outside of the floating element.
2083
+ * @see https://floating-ui.com/docs/useDismiss
2084
+ */
2085
+ function useDismiss(context, props) {
2086
+ if (props === void 0) {
2087
+ props = {};
2088
+ }
2089
+ const {
2090
+ open,
2091
+ onOpenChange,
2092
+ nodeId,
2093
+ elements: {
2094
+ reference,
2095
+ domReference,
2096
+ floating
2097
+ },
2098
+ dataRef
2099
+ } = context;
2100
+ const {
2101
+ enabled = true,
2102
+ escapeKey = true,
2103
+ outsidePress: unstable_outsidePress = true,
2104
+ outsidePressEvent = 'pointerdown',
2105
+ referencePress = false,
2106
+ referencePressEvent = 'pointerdown',
2107
+ ancestorScroll = false,
2108
+ bubbles,
2109
+ capture
2110
+ } = props;
2111
+ const tree = useFloatingTree();
2112
+ const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
2113
+ const outsidePress = typeof unstable_outsidePress === 'function' ? outsidePressFn : unstable_outsidePress;
2114
+ const insideReactTreeRef = React$1.useRef(false);
2115
+ const endedOrStartedInsideRef = React$1.useRef(false);
2116
+ const {
2117
+ escapeKey: escapeKeyBubbles,
2118
+ outsidePress: outsidePressBubbles
2119
+ } = normalizeProp(bubbles);
2120
+ const {
2121
+ escapeKey: escapeKeyCapture,
2122
+ outsidePress: outsidePressCapture
2123
+ } = normalizeProp(capture);
2124
+ const closeOnEscapeKeyDown = useEffectEvent(event => {
2125
+ if (!open || !enabled || !escapeKey || event.key !== 'Escape') {
2126
+ return;
2127
+ }
2128
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
2129
+ if (!escapeKeyBubbles) {
2130
+ event.stopPropagation();
2131
+ if (children.length > 0) {
2132
+ let shouldDismiss = true;
2133
+ children.forEach(child => {
2134
+ var _child$context;
2135
+ if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
2136
+ shouldDismiss = false;
2137
+ return;
2138
+ }
2139
+ });
2140
+ if (!shouldDismiss) {
2141
+ return;
2142
+ }
2143
+ }
2144
+ }
2145
+ onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, 'escape-key');
2146
+ });
2147
+ const closeOnEscapeKeyDownCapture = useEffectEvent(event => {
2148
+ var _getTarget2;
2149
+ const callback = () => {
2150
+ var _getTarget;
2151
+ closeOnEscapeKeyDown(event);
2152
+ (_getTarget = getTarget(event)) == null || _getTarget.removeEventListener('keydown', callback);
2153
+ };
2154
+ (_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener('keydown', callback);
2155
+ });
2156
+ const closeOnPressOutside = useEffectEvent(event => {
2157
+ // Given developers can stop the propagation of the synthetic event,
2158
+ // we can only be confident with a positive value.
2159
+ const insideReactTree = insideReactTreeRef.current;
2160
+ insideReactTreeRef.current = false;
2161
+
2162
+ // When click outside is lazy (`click` event), handle dragging.
2163
+ // Don't close if:
2164
+ // - The click started inside the floating element.
2165
+ // - The click ended inside the floating element.
2166
+ const endedOrStartedInside = endedOrStartedInsideRef.current;
2167
+ endedOrStartedInsideRef.current = false;
2168
+ if (outsidePressEvent === 'click' && endedOrStartedInside) {
2169
+ return;
2170
+ }
2171
+ if (insideReactTree) {
2172
+ return;
2173
+ }
2174
+ if (typeof outsidePress === 'function' && !outsidePress(event)) {
2175
+ return;
2176
+ }
2177
+ const target = getTarget(event);
2178
+ const inertSelector = "[" + createAttribute('inert') + "]";
2179
+ const markers = getDocument(floating).querySelectorAll(inertSelector);
2180
+ let targetRootAncestor = isElement(target) ? target : null;
2181
+ while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
2182
+ const nextParent = getParentNode(targetRootAncestor);
2183
+ if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
2184
+ break;
2185
+ } else {
2186
+ targetRootAncestor = nextParent;
2187
+ }
2188
+ }
2189
+
2190
+ // Check if the click occurred on a third-party element injected after the
2191
+ // floating element rendered.
2192
+ if (markers.length && isElement(target) && !isRootElement(target) &&
2193
+ // Clicked on a direct ancestor (e.g. FloatingOverlay).
2194
+ !contains(target, floating) &&
2195
+ // If the target root element contains none of the markers, then the
2196
+ // element was injected after the floating element rendered.
2197
+ Array.from(markers).every(marker => !contains(targetRootAncestor, marker))) {
2198
+ return;
2199
+ }
2200
+
2201
+ // Check if the click occurred on the scrollbar
2202
+ if (isHTMLElement(target) && floating) {
2203
+ // In Firefox, `target.scrollWidth > target.clientWidth` for inline
2204
+ // elements.
2205
+ const canScrollX = target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
2206
+ const canScrollY = target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
2207
+ let xCond = canScrollY && event.offsetX > target.clientWidth;
2208
+
2209
+ // In some browsers it is possible to change the <body> (or window)
2210
+ // scrollbar to the left side, but is very rare and is difficult to
2211
+ // check for. Plus, for modal dialogs with backdrops, it is more
2212
+ // important that the backdrop is checked but not so much the window.
2213
+ if (canScrollY) {
2214
+ const isRTL = getComputedStyle(target).direction === 'rtl';
2215
+ if (isRTL) {
2216
+ xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
2217
+ }
2218
+ }
2219
+ if (xCond || canScrollX && event.offsetY > target.clientHeight) {
2220
+ return;
2221
+ }
2222
+ }
2223
+ const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some(node => {
2224
+ var _node$context;
2225
+ return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
2226
+ });
2227
+ if (isEventTargetWithin(event, floating) || isEventTargetWithin(event, domReference) || targetIsInsideChildren) {
2228
+ return;
2229
+ }
2230
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
2231
+ if (children.length > 0) {
2232
+ let shouldDismiss = true;
2233
+ children.forEach(child => {
2234
+ var _child$context2;
2235
+ if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
2236
+ shouldDismiss = false;
2237
+ return;
2238
+ }
2239
+ });
2240
+ if (!shouldDismiss) {
2241
+ return;
2242
+ }
2243
+ }
2244
+ onOpenChange(false, event, 'outside-press');
2245
+ });
2246
+ const closeOnPressOutsideCapture = useEffectEvent(event => {
2247
+ var _getTarget4;
2248
+ const callback = () => {
2249
+ var _getTarget3;
2250
+ closeOnPressOutside(event);
2251
+ (_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
2252
+ };
2253
+ (_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
2254
+ });
2255
+ React$1.useEffect(() => {
2256
+ if (!open || !enabled) {
2257
+ return;
2258
+ }
2259
+ dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
2260
+ dataRef.current.__outsidePressBubbles = outsidePressBubbles;
2261
+ function onScroll(event) {
2262
+ onOpenChange(false, event, 'ancestor-scroll');
2263
+ }
2264
+ const doc = getDocument(floating);
2265
+ escapeKey && doc.addEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
2266
+ outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
2267
+ let ancestors = [];
2268
+ if (ancestorScroll) {
2269
+ if (isElement(domReference)) {
2270
+ ancestors = getOverflowAncestors(domReference);
2271
+ }
2272
+ if (isElement(floating)) {
2273
+ ancestors = ancestors.concat(getOverflowAncestors(floating));
2274
+ }
2275
+ if (!isElement(reference) && reference && reference.contextElement) {
2276
+ ancestors = ancestors.concat(getOverflowAncestors(reference.contextElement));
2277
+ }
2278
+ }
2279
+
2280
+ // Ignore the visual viewport for scrolling dismissal (allow pinch-zoom)
2281
+ ancestors = ancestors.filter(ancestor => {
2282
+ var _doc$defaultView;
2283
+ return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
2284
+ });
2285
+ ancestors.forEach(ancestor => {
2286
+ ancestor.addEventListener('scroll', onScroll, {
2287
+ passive: true
2288
+ });
2289
+ });
2290
+ return () => {
2291
+ escapeKey && doc.removeEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
2292
+ outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
2293
+ ancestors.forEach(ancestor => {
2294
+ ancestor.removeEventListener('scroll', onScroll);
2295
+ });
2296
+ };
2297
+ }, [dataRef, floating, domReference, reference, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
2298
+ React$1.useEffect(() => {
2299
+ insideReactTreeRef.current = false;
2300
+ }, [outsidePress, outsidePressEvent]);
2301
+ return React$1.useMemo(() => {
2302
+ if (!enabled) {
2303
+ return {};
2304
+ }
2305
+ return {
2306
+ reference: {
2307
+ onKeyDown: closeOnEscapeKeyDown,
2308
+ [bubbleHandlerKeys[referencePressEvent]]: event => {
2309
+ if (referencePress) {
2310
+ onOpenChange(false, event.nativeEvent, 'reference-press');
2311
+ }
2312
+ }
2313
+ },
2314
+ floating: {
2315
+ onKeyDown: closeOnEscapeKeyDown,
2316
+ onMouseDown() {
2317
+ endedOrStartedInsideRef.current = true;
2318
+ },
2319
+ onMouseUp() {
2320
+ endedOrStartedInsideRef.current = true;
2321
+ },
2322
+ [captureHandlerKeys[outsidePressEvent]]: () => {
2323
+ insideReactTreeRef.current = true;
2324
+ }
2325
+ }
2326
+ };
2327
+ }, [enabled, referencePress, outsidePressEvent, referencePressEvent, onOpenChange, closeOnEscapeKeyDown]);
2328
+ }
2329
+
2330
+ let devMessageSet;
2331
+ if (process.env.NODE_ENV !== "production") {
2332
+ devMessageSet = /*#__PURE__*/new Set();
2333
+ }
2334
+
2335
+ /**
2336
+ * Provides data to position a floating element and context to add interactions.
2337
+ * @see https://floating-ui.com/docs/useFloating
2338
+ */
2339
+ function useFloating(options) {
2340
+ var _options$elements2;
2341
+ if (options === void 0) {
2342
+ options = {};
2343
+ }
2344
+ const {
2345
+ open = false,
2346
+ onOpenChange: unstable_onOpenChange,
2347
+ nodeId
2348
+ } = options;
2349
+ if (process.env.NODE_ENV !== "production") {
2350
+ var _options$elements;
2351
+ const err = 'Floating UI: Cannot pass a virtual element to the ' + '`elements.reference` option, as it must be a real DOM element. ' + 'Use `refs.setPositionReference` instead.';
2352
+ if ((_options$elements = options.elements) != null && _options$elements.reference && !isElement(options.elements.reference)) {
2353
+ var _devMessageSet;
2354
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(err))) {
2355
+ var _devMessageSet2;
2356
+ (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(err);
2357
+ console.error(err);
2358
+ }
2359
+ }
2360
+ }
2361
+ const [_domReference, setDomReference] = React$1.useState(null);
2362
+ const domReference = ((_options$elements2 = options.elements) == null ? void 0 : _options$elements2.reference) || _domReference;
2363
+ const position = useFloating$1(options);
2364
+ const tree = useFloatingTree();
2365
+ const nested = useFloatingParentNodeId() != null;
2366
+ const onOpenChange = useEffectEvent((open, event, reason) => {
2367
+ if (open) {
2368
+ dataRef.current.openEvent = event;
2369
+ }
2370
+ events.emit('openchange', {
2371
+ open,
2372
+ event,
2373
+ reason,
2374
+ nested
2375
+ });
2376
+ unstable_onOpenChange == null || unstable_onOpenChange(open, event, reason);
2377
+ });
2378
+ const domReferenceRef = React$1.useRef(null);
2379
+ const dataRef = React$1.useRef({});
2380
+ const events = React$1.useState(() => createPubSub())[0];
2381
+ const floatingId = useId();
2382
+ const setPositionReference = React$1.useCallback(node => {
2383
+ const positionReference = isElement(node) ? {
2384
+ getBoundingClientRect: () => node.getBoundingClientRect(),
2385
+ contextElement: node
2386
+ } : node;
2387
+ position.refs.setReference(positionReference);
2388
+ }, [position.refs]);
2389
+ const setReference = React$1.useCallback(node => {
2390
+ if (isElement(node) || node === null) {
2391
+ domReferenceRef.current = node;
2392
+ setDomReference(node);
2393
+ }
2394
+
2395
+ // Backwards-compatibility for passing a virtual element to `reference`
2396
+ // after it has set the DOM reference.
2397
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
2398
+ // Don't allow setting virtual elements using the old technique back to
2399
+ // `null` to support `positionReference` + an unstable `reference`
2400
+ // callback ref.
2401
+ node !== null && !isElement(node)) {
2402
+ position.refs.setReference(node);
2403
+ }
2404
+ }, [position.refs]);
2405
+ const refs = React$1.useMemo(() => ({
2406
+ ...position.refs,
2407
+ setReference,
2408
+ setPositionReference,
2409
+ domReference: domReferenceRef
2410
+ }), [position.refs, setReference, setPositionReference]);
2411
+ const elements = React$1.useMemo(() => ({
2412
+ ...position.elements,
2413
+ domReference: domReference
2414
+ }), [position.elements, domReference]);
2415
+ const context = React$1.useMemo(() => ({
2416
+ ...position,
2417
+ refs,
2418
+ elements,
2419
+ dataRef,
2420
+ nodeId,
2421
+ floatingId,
2422
+ events,
2423
+ open,
2424
+ onOpenChange
2425
+ }), [position, nodeId, floatingId, events, open, onOpenChange, refs, elements]);
2426
+ index(() => {
2427
+ const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
2428
+ if (node) {
2429
+ node.context = context;
2430
+ }
2431
+ });
2432
+ return React$1.useMemo(() => ({
2433
+ ...position,
2434
+ context,
2435
+ refs,
2436
+ elements
2437
+ }), [position, refs, elements, context]);
2438
+ }
2439
+
2440
+ const ACTIVE_KEY = 'active';
2441
+ const SELECTED_KEY = 'selected';
2442
+ function mergeProps(userProps, propsList, elementKey) {
2443
+ const map = new Map();
2444
+ const isItem = elementKey === 'item';
2445
+ let domUserProps = userProps;
2446
+ if (isItem && userProps) {
2447
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2448
+ const {
2449
+ [ACTIVE_KEY]: _,
2450
+ [SELECTED_KEY]: __,
2451
+ ...validProps
2452
+ } = userProps;
2453
+ domUserProps = validProps;
2454
+ }
2455
+ return {
2456
+ ...(elementKey === 'floating' && {
2457
+ tabIndex: -1
2458
+ }),
2459
+ ...domUserProps,
2460
+ ...propsList.map(value => {
2461
+ const propsOrGetProps = value ? value[elementKey] : null;
2462
+ if (typeof propsOrGetProps === 'function') {
2463
+ return userProps ? propsOrGetProps(userProps) : null;
2464
+ }
2465
+ return propsOrGetProps;
2466
+ }).concat(userProps).reduce((acc, props) => {
2467
+ if (!props) {
2468
+ return acc;
2469
+ }
2470
+ Object.entries(props).forEach(_ref => {
2471
+ let [key, value] = _ref;
2472
+ if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
2473
+ return;
2474
+ }
2475
+ if (key.indexOf('on') === 0) {
2476
+ if (!map.has(key)) {
2477
+ map.set(key, []);
2478
+ }
2479
+ if (typeof value === 'function') {
2480
+ var _map$get;
2481
+ (_map$get = map.get(key)) == null || _map$get.push(value);
2482
+ acc[key] = function () {
2483
+ var _map$get2;
2484
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2485
+ args[_key] = arguments[_key];
2486
+ }
2487
+ return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map(fn => fn(...args)).find(val => val !== undefined);
2488
+ };
2489
+ }
2490
+ } else {
2491
+ acc[key] = value;
2492
+ }
2493
+ });
2494
+ return acc;
2495
+ }, {})
2496
+ };
2497
+ }
2498
+
2499
+ /**
2500
+ * Merges an array of interaction hooks' props into prop getters, allowing
2501
+ * event handler functions to be composed together without overwriting one
2502
+ * another.
2503
+ * @see https://floating-ui.com/docs/useInteractions
2504
+ */
2505
+ function useInteractions(propsList) {
2506
+ if (propsList === void 0) {
2507
+ propsList = [];
2508
+ }
2509
+ // The dependencies are a dynamic array, so we can't use the linter's
2510
+ // suggestion to add it to the deps array.
2511
+ const deps = propsList;
2512
+ const getReferenceProps = React$1.useCallback(userProps => mergeProps(userProps, propsList, 'reference'),
2513
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2514
+ deps);
2515
+ const getFloatingProps = React$1.useCallback(userProps => mergeProps(userProps, propsList, 'floating'),
2516
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2517
+ deps);
2518
+ const getItemProps = React$1.useCallback(userProps => mergeProps(userProps, propsList, 'item'),
2519
+ // Granularly check for `item` changes, because the `getItemProps` getter
2520
+ // should be as referentially stable as possible since it may be passed as
2521
+ // a prop to many components. All `item` key values must therefore be
2522
+ // memoized.
2523
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2524
+ propsList.map(key => key == null ? void 0 : key.item));
2525
+ return React$1.useMemo(() => ({
2526
+ getReferenceProps,
2527
+ getFloatingProps,
2528
+ getItemProps
2529
+ }), [getReferenceProps, getFloatingProps, getItemProps]);
2530
+ }
2531
+
2532
+ const componentRoleToAriaRoleMap = /*#__PURE__*/new Map([['select', 'listbox'], ['combobox', 'listbox'], ['label', false]]);
2533
+
2534
+ /**
2535
+ * Adds base screen reader props to the reference and floating elements for a
2536
+ * given floating element `role`.
2537
+ * @see https://floating-ui.com/docs/useRole
2538
+ */
2539
+ function useRole(context, props) {
2540
+ var _componentRoleToAriaR;
2541
+ if (props === void 0) {
2542
+ props = {};
2543
+ }
2544
+ const {
2545
+ open,
2546
+ floatingId
2547
+ } = context;
2548
+ const {
2549
+ enabled = true,
2550
+ role = 'dialog'
2551
+ } = props;
2552
+ const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
2553
+ const referenceId = useId();
2554
+ const parentId = useFloatingParentNodeId();
2555
+ const isNested = parentId != null;
2556
+ return React$1.useMemo(() => {
2557
+ if (!enabled) return {};
2558
+ const floatingProps = {
2559
+ id: floatingId,
2560
+ ...(ariaRole && {
2561
+ role: ariaRole
2562
+ })
2563
+ };
2564
+ if (ariaRole === 'tooltip' || role === 'label') {
2565
+ return {
2566
+ reference: {
2567
+ ["aria-" + (role === 'label' ? 'labelledby' : 'describedby')]: open ? floatingId : undefined
2568
+ },
2569
+ floating: floatingProps
2570
+ };
2571
+ }
2572
+ return {
2573
+ reference: {
2574
+ 'aria-expanded': open ? 'true' : 'false',
2575
+ 'aria-haspopup': ariaRole === 'alertdialog' ? 'dialog' : ariaRole,
2576
+ 'aria-controls': open ? floatingId : undefined,
2577
+ ...(ariaRole === 'listbox' && {
2578
+ role: 'combobox'
2579
+ }),
2580
+ ...(ariaRole === 'menu' && {
2581
+ id: referenceId
2582
+ }),
2583
+ ...(ariaRole === 'menu' && isNested && {
2584
+ role: 'menuitem'
2585
+ }),
2586
+ ...(role === 'select' && {
2587
+ 'aria-autocomplete': 'none'
2588
+ }),
2589
+ ...(role === 'combobox' && {
2590
+ 'aria-autocomplete': 'list'
2591
+ })
2592
+ },
2593
+ floating: {
2594
+ ...floatingProps,
2595
+ ...(ariaRole === 'menu' && {
2596
+ 'aria-labelledby': referenceId
2597
+ })
2598
+ },
2599
+ item(_ref) {
2600
+ let {
2601
+ active,
2602
+ selected
2603
+ } = _ref;
2604
+ const commonProps = {
2605
+ role: 'option',
2606
+ ...(active && {
2607
+ id: floatingId + "-option"
2608
+ })
2609
+ };
2610
+
2611
+ // For `menu`, we are unable to tell if the item is a `menuitemradio`
2612
+ // or `menuitemcheckbox`. For backwards-compatibility reasons, also
2613
+ // avoid defaulting to `menuitem` as it may overwrite custom role props.
2614
+ switch (role) {
2615
+ case 'select':
2616
+ return {
2617
+ ...commonProps,
2618
+ 'aria-selected': active && selected
2619
+ };
2620
+ case 'combobox':
2621
+ {
2622
+ return {
2623
+ ...commonProps,
2624
+ ...(active && {
2625
+ 'aria-selected': true
2626
+ })
2627
+ };
2628
+ }
2629
+ }
2630
+ return {};
2631
+ }
2632
+ };
2633
+ }, [enabled, role, ariaRole, open, floatingId, referenceId, isNested]);
2634
+ }
2635
+
2636
+ // TODO : Use Floating Portal?
2637
+ // TODO : Collisions dont seem to be working as expected, need to investigate
2638
+
2639
+ const ARROW_HEIGHT = 7;
2640
+ const GAP = 2;
2641
+ const Popper = _ref => {
2642
+ let {
2643
+ popperName = '',
2644
+ customRootClass = '',
2645
+ className = '',
2646
+ children,
2647
+ open = false,
2648
+ hoverDelay = 10,
2649
+ showArrow = true,
2650
+ pop = /*#__PURE__*/React.createElement(React.Fragment, null),
2651
+ ...props
2652
+ } = _ref;
2653
+ const rootClass = customClassSwitcher(customRootClass, popperName);
2654
+ const arrowRef = useRef(null);
2655
+ const [isOpen, setIsOpen] = useState(open);
2656
+ const {
2657
+ refs,
2658
+ floatingStyles,
2659
+ context
2660
+ } = useFloating({
2661
+ open: isOpen,
2662
+ middleware: [arrow({
2663
+ element: arrowRef
2664
+ }), offset(ARROW_HEIGHT + GAP),
2665
+ // autoPlacement({
2666
+ // crossAxis: 'center',
2667
+ // alignment: 'start',
2668
+ // autoAlignment: true,
2669
+ // allowedPlacements: ['top', 'bottom', 'left', 'right'],
2670
+ // padding: 5,
2671
+ // }),
2672
+ flip()],
2673
+ onOpenChange: setIsOpen,
2674
+ placement: 'top'
2675
+ });
2676
+ const role = useRole(context);
2677
+ const dismiss = useDismiss(context);
2678
+ const hover = useHover(context, {
2679
+ // delay: hoverDelay,
2680
+ });
2681
+ const {
2682
+ getReferenceProps,
2683
+ getFloatingProps
2684
+ } = useInteractions([hover, role, dismiss]);
2685
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", _extends$1({
2686
+ className: `${rootClass}-reference-element ${className}`,
2687
+ ref: refs.setReference
2688
+ }, getReferenceProps({
2689
+ onClick: () => {
2690
+ console.log('click');
2691
+ }
2692
+ })), children), isOpen && /*#__PURE__*/React.createElement("div", _extends$1({
2693
+ className: `${rootClass}-floating-element`,
2694
+ ref: refs.setFloating,
2695
+ style: floatingStyles
2696
+ }, getFloatingProps()), showArrow && /*#__PURE__*/React.createElement(FloatingArrow, {
2697
+ className: `rad-ui-arrow ${rootClass}-arrow`,
2698
+ ref: arrowRef,
2699
+ context: context
2700
+ }), pop));
2701
+ };
2702
+
2703
+ const COMPONENT_NAME = 'Tooltip';
2704
+ const Tooltip = _ref => {
2705
+ let {
2706
+ children,
2707
+ label,
2708
+ ...props
2709
+ } = _ref;
2710
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Popper, _extends$1({
2711
+ popperName: COMPONENT_NAME,
2712
+ pop: 'hello'
2713
+ }, props), children));
2714
+ };
2715
+
2716
+ export { Tooltip as default };