@radui/ui 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1751 @@
1
+ 'use client';
2
+ import * as React$1 from 'react';
3
+ import { useLayoutEffect, useEffect, useState } from 'react';
4
+ import * as ReactDOM from 'react-dom';
5
+
6
+ function getNodeName(node) {
7
+ if (isNode(node)) {
8
+ return (node.nodeName || '').toLowerCase();
9
+ }
10
+ // Mocked nodes in testing environments may not be instances of Node. By
11
+ // returning `#document` an infinite loop won't occur.
12
+ // https://github.com/floating-ui/floating-ui/issues/2317
13
+ return '#document';
14
+ }
15
+ function getWindow(node) {
16
+ var _node$ownerDocument;
17
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
18
+ }
19
+ function getDocumentElement(node) {
20
+ var _ref;
21
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
22
+ }
23
+ function isNode(value) {
24
+ return value instanceof Node || value instanceof getWindow(value).Node;
25
+ }
26
+ function isElement(value) {
27
+ return value instanceof Element || value instanceof getWindow(value).Element;
28
+ }
29
+ function isHTMLElement(value) {
30
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
31
+ }
32
+ function isShadowRoot(value) {
33
+ // Browsers without `ShadowRoot` support.
34
+ if (typeof ShadowRoot === 'undefined') {
35
+ return false;
36
+ }
37
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
38
+ }
39
+ function isOverflowElement(element) {
40
+ const {
41
+ overflow,
42
+ overflowX,
43
+ overflowY,
44
+ display
45
+ } = getComputedStyle(element);
46
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
47
+ }
48
+ function isTableElement(element) {
49
+ return ['table', 'td', 'th'].includes(getNodeName(element));
50
+ }
51
+ function isContainingBlock(element) {
52
+ const webkit = isWebKit();
53
+ const css = getComputedStyle(element);
54
+
55
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
56
+ 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));
57
+ }
58
+ function getContainingBlock(element) {
59
+ let currentNode = getParentNode(element);
60
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
61
+ if (isContainingBlock(currentNode)) {
62
+ return currentNode;
63
+ } else {
64
+ currentNode = getParentNode(currentNode);
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+ function isWebKit() {
70
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
71
+ return CSS.supports('-webkit-backdrop-filter', 'none');
72
+ }
73
+ function isLastTraversableNode(node) {
74
+ return ['html', 'body', '#document'].includes(getNodeName(node));
75
+ }
76
+ function getComputedStyle(element) {
77
+ return getWindow(element).getComputedStyle(element);
78
+ }
79
+ function getNodeScroll(element) {
80
+ if (isElement(element)) {
81
+ return {
82
+ scrollLeft: element.scrollLeft,
83
+ scrollTop: element.scrollTop
84
+ };
85
+ }
86
+ return {
87
+ scrollLeft: element.pageXOffset,
88
+ scrollTop: element.pageYOffset
89
+ };
90
+ }
91
+ function getParentNode(node) {
92
+ if (getNodeName(node) === 'html') {
93
+ return node;
94
+ }
95
+ const result =
96
+ // Step into the shadow DOM of the parent of a slotted node.
97
+ node.assignedSlot ||
98
+ // DOM Element detected.
99
+ node.parentNode ||
100
+ // ShadowRoot detected.
101
+ isShadowRoot(node) && node.host ||
102
+ // Fallback.
103
+ getDocumentElement(node);
104
+ return isShadowRoot(result) ? result.host : result;
105
+ }
106
+ function getNearestOverflowAncestor(node) {
107
+ const parentNode = getParentNode(node);
108
+ if (isLastTraversableNode(parentNode)) {
109
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
110
+ }
111
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
112
+ return parentNode;
113
+ }
114
+ return getNearestOverflowAncestor(parentNode);
115
+ }
116
+ function getOverflowAncestors(node, list, traverseIframes) {
117
+ var _node$ownerDocument2;
118
+ if (list === void 0) {
119
+ list = [];
120
+ }
121
+ if (traverseIframes === void 0) {
122
+ traverseIframes = true;
123
+ }
124
+ const scrollableAncestor = getNearestOverflowAncestor(node);
125
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
126
+ const win = getWindow(scrollableAncestor);
127
+ if (isBody) {
128
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
129
+ }
130
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
131
+ }
132
+
133
+ const min = Math.min;
134
+ const max = Math.max;
135
+ const round = Math.round;
136
+ const floor = Math.floor;
137
+ const createCoords = v => ({
138
+ x: v,
139
+ y: v
140
+ });
141
+ const oppositeSideMap = {
142
+ left: 'right',
143
+ right: 'left',
144
+ bottom: 'top',
145
+ top: 'bottom'
146
+ };
147
+ const oppositeAlignmentMap = {
148
+ start: 'end',
149
+ end: 'start'
150
+ };
151
+ function clamp(start, value, end) {
152
+ return max(start, min(value, end));
153
+ }
154
+ function evaluate(value, param) {
155
+ return typeof value === 'function' ? value(param) : value;
156
+ }
157
+ function getSide(placement) {
158
+ return placement.split('-')[0];
159
+ }
160
+ function getAlignment(placement) {
161
+ return placement.split('-')[1];
162
+ }
163
+ function getOppositeAxis(axis) {
164
+ return axis === 'x' ? 'y' : 'x';
165
+ }
166
+ function getAxisLength(axis) {
167
+ return axis === 'y' ? 'height' : 'width';
168
+ }
169
+ function getSideAxis(placement) {
170
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
171
+ }
172
+ function getAlignmentAxis(placement) {
173
+ return getOppositeAxis(getSideAxis(placement));
174
+ }
175
+ function getAlignmentSides(placement, rects, rtl) {
176
+ if (rtl === void 0) {
177
+ rtl = false;
178
+ }
179
+ const alignment = getAlignment(placement);
180
+ const alignmentAxis = getAlignmentAxis(placement);
181
+ const length = getAxisLength(alignmentAxis);
182
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
183
+ if (rects.reference[length] > rects.floating[length]) {
184
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
185
+ }
186
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
187
+ }
188
+ function getExpandedPlacements(placement) {
189
+ const oppositePlacement = getOppositePlacement(placement);
190
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
191
+ }
192
+ function getOppositeAlignmentPlacement(placement) {
193
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
194
+ }
195
+ function getSideList(side, isStart, rtl) {
196
+ const lr = ['left', 'right'];
197
+ const rl = ['right', 'left'];
198
+ const tb = ['top', 'bottom'];
199
+ const bt = ['bottom', 'top'];
200
+ switch (side) {
201
+ case 'top':
202
+ case 'bottom':
203
+ if (rtl) return isStart ? rl : lr;
204
+ return isStart ? lr : rl;
205
+ case 'left':
206
+ case 'right':
207
+ return isStart ? tb : bt;
208
+ default:
209
+ return [];
210
+ }
211
+ }
212
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
213
+ const alignment = getAlignment(placement);
214
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
215
+ if (alignment) {
216
+ list = list.map(side => side + "-" + alignment);
217
+ if (flipAlignment) {
218
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
219
+ }
220
+ }
221
+ return list;
222
+ }
223
+ function getOppositePlacement(placement) {
224
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
225
+ }
226
+ function expandPaddingObject(padding) {
227
+ return {
228
+ top: 0,
229
+ right: 0,
230
+ bottom: 0,
231
+ left: 0,
232
+ ...padding
233
+ };
234
+ }
235
+ function getPaddingObject(padding) {
236
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
237
+ top: padding,
238
+ right: padding,
239
+ bottom: padding,
240
+ left: padding
241
+ };
242
+ }
243
+ function rectToClientRect(rect) {
244
+ return {
245
+ ...rect,
246
+ top: rect.y,
247
+ left: rect.x,
248
+ right: rect.x + rect.width,
249
+ bottom: rect.y + rect.height
250
+ };
251
+ }
252
+
253
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
254
+ let {
255
+ reference,
256
+ floating
257
+ } = _ref;
258
+ const sideAxis = getSideAxis(placement);
259
+ const alignmentAxis = getAlignmentAxis(placement);
260
+ const alignLength = getAxisLength(alignmentAxis);
261
+ const side = getSide(placement);
262
+ const isVertical = sideAxis === 'y';
263
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
264
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
265
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
266
+ let coords;
267
+ switch (side) {
268
+ case 'top':
269
+ coords = {
270
+ x: commonX,
271
+ y: reference.y - floating.height
272
+ };
273
+ break;
274
+ case 'bottom':
275
+ coords = {
276
+ x: commonX,
277
+ y: reference.y + reference.height
278
+ };
279
+ break;
280
+ case 'right':
281
+ coords = {
282
+ x: reference.x + reference.width,
283
+ y: commonY
284
+ };
285
+ break;
286
+ case 'left':
287
+ coords = {
288
+ x: reference.x - floating.width,
289
+ y: commonY
290
+ };
291
+ break;
292
+ default:
293
+ coords = {
294
+ x: reference.x,
295
+ y: reference.y
296
+ };
297
+ }
298
+ switch (getAlignment(placement)) {
299
+ case 'start':
300
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
301
+ break;
302
+ case 'end':
303
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
304
+ break;
305
+ }
306
+ return coords;
307
+ }
308
+
309
+ /**
310
+ * Computes the `x` and `y` coordinates that will place the floating element
311
+ * next to a reference element when it is given a certain positioning strategy.
312
+ *
313
+ * This export does not have any `platform` interface logic. You will need to
314
+ * write one for the platform you are using Floating UI with.
315
+ */
316
+ const computePosition$1 = async (reference, floating, config) => {
317
+ const {
318
+ placement = 'bottom',
319
+ strategy = 'absolute',
320
+ middleware = [],
321
+ platform
322
+ } = config;
323
+ const validMiddleware = middleware.filter(Boolean);
324
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
325
+ let rects = await platform.getElementRects({
326
+ reference,
327
+ floating,
328
+ strategy
329
+ });
330
+ let {
331
+ x,
332
+ y
333
+ } = computeCoordsFromPlacement(rects, placement, rtl);
334
+ let statefulPlacement = placement;
335
+ let middlewareData = {};
336
+ let resetCount = 0;
337
+ for (let i = 0; i < validMiddleware.length; i++) {
338
+ const {
339
+ name,
340
+ fn
341
+ } = validMiddleware[i];
342
+ const {
343
+ x: nextX,
344
+ y: nextY,
345
+ data,
346
+ reset
347
+ } = await fn({
348
+ x,
349
+ y,
350
+ initialPlacement: placement,
351
+ placement: statefulPlacement,
352
+ strategy,
353
+ middlewareData,
354
+ rects,
355
+ platform,
356
+ elements: {
357
+ reference,
358
+ floating
359
+ }
360
+ });
361
+ x = nextX != null ? nextX : x;
362
+ y = nextY != null ? nextY : y;
363
+ middlewareData = {
364
+ ...middlewareData,
365
+ [name]: {
366
+ ...middlewareData[name],
367
+ ...data
368
+ }
369
+ };
370
+ if (reset && resetCount <= 50) {
371
+ resetCount++;
372
+ if (typeof reset === 'object') {
373
+ if (reset.placement) {
374
+ statefulPlacement = reset.placement;
375
+ }
376
+ if (reset.rects) {
377
+ rects = reset.rects === true ? await platform.getElementRects({
378
+ reference,
379
+ floating,
380
+ strategy
381
+ }) : reset.rects;
382
+ }
383
+ ({
384
+ x,
385
+ y
386
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
387
+ }
388
+ i = -1;
389
+ continue;
390
+ }
391
+ }
392
+ return {
393
+ x,
394
+ y,
395
+ placement: statefulPlacement,
396
+ strategy,
397
+ middlewareData
398
+ };
399
+ };
400
+
401
+ /**
402
+ * Resolves with an object of overflow side offsets that determine how much the
403
+ * element is overflowing a given clipping boundary on each side.
404
+ * - positive = overflowing the boundary by that number of pixels
405
+ * - negative = how many pixels left before it will overflow
406
+ * - 0 = lies flush with the boundary
407
+ * @see https://floating-ui.com/docs/detectOverflow
408
+ */
409
+ async function detectOverflow(state, options) {
410
+ var _await$platform$isEle;
411
+ if (options === void 0) {
412
+ options = {};
413
+ }
414
+ const {
415
+ x,
416
+ y,
417
+ platform,
418
+ rects,
419
+ elements,
420
+ strategy
421
+ } = state;
422
+ const {
423
+ boundary = 'clippingAncestors',
424
+ rootBoundary = 'viewport',
425
+ elementContext = 'floating',
426
+ altBoundary = false,
427
+ padding = 0
428
+ } = evaluate(options, state);
429
+ const paddingObject = getPaddingObject(padding);
430
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
431
+ const element = elements[altBoundary ? altContext : elementContext];
432
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
433
+ 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))),
434
+ boundary,
435
+ rootBoundary,
436
+ strategy
437
+ }));
438
+ const rect = elementContext === 'floating' ? {
439
+ ...rects.floating,
440
+ x,
441
+ y
442
+ } : rects.reference;
443
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
444
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
445
+ x: 1,
446
+ y: 1
447
+ } : {
448
+ x: 1,
449
+ y: 1
450
+ };
451
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
452
+ rect,
453
+ offsetParent,
454
+ strategy
455
+ }) : rect);
456
+ return {
457
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
458
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
459
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
460
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
461
+ };
462
+ }
463
+
464
+ /**
465
+ * Optimizes the visibility of the floating element by flipping the `placement`
466
+ * in order to keep it in view when the preferred placement(s) will overflow the
467
+ * clipping boundary. Alternative to `autoPlacement`.
468
+ * @see https://floating-ui.com/docs/flip
469
+ */
470
+ const flip = function (options) {
471
+ if (options === void 0) {
472
+ options = {};
473
+ }
474
+ return {
475
+ name: 'flip',
476
+ options,
477
+ async fn(state) {
478
+ var _middlewareData$arrow, _middlewareData$flip;
479
+ const {
480
+ placement,
481
+ middlewareData,
482
+ rects,
483
+ initialPlacement,
484
+ platform,
485
+ elements
486
+ } = state;
487
+ const {
488
+ mainAxis: checkMainAxis = true,
489
+ crossAxis: checkCrossAxis = true,
490
+ fallbackPlacements: specifiedFallbackPlacements,
491
+ fallbackStrategy = 'bestFit',
492
+ fallbackAxisSideDirection = 'none',
493
+ flipAlignment = true,
494
+ ...detectOverflowOptions
495
+ } = evaluate(options, state);
496
+
497
+ // If a reset by the arrow was caused due to an alignment offset being
498
+ // added, we should skip any logic now since `flip()` has already done its
499
+ // work.
500
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
501
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
502
+ return {};
503
+ }
504
+ const side = getSide(placement);
505
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
506
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
507
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
508
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
509
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
510
+ }
511
+ const placements = [initialPlacement, ...fallbackPlacements];
512
+ const overflow = await detectOverflow(state, detectOverflowOptions);
513
+ const overflows = [];
514
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
515
+ if (checkMainAxis) {
516
+ overflows.push(overflow[side]);
517
+ }
518
+ if (checkCrossAxis) {
519
+ const sides = getAlignmentSides(placement, rects, rtl);
520
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
521
+ }
522
+ overflowsData = [...overflowsData, {
523
+ placement,
524
+ overflows
525
+ }];
526
+
527
+ // One or more sides is overflowing.
528
+ if (!overflows.every(side => side <= 0)) {
529
+ var _middlewareData$flip2, _overflowsData$filter;
530
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
531
+ const nextPlacement = placements[nextIndex];
532
+ if (nextPlacement) {
533
+ // Try next placement and re-run the lifecycle.
534
+ return {
535
+ data: {
536
+ index: nextIndex,
537
+ overflows: overflowsData
538
+ },
539
+ reset: {
540
+ placement: nextPlacement
541
+ }
542
+ };
543
+ }
544
+
545
+ // First, find the candidates that fit on the mainAxis side of overflow,
546
+ // then find the placement that fits the best on the main crossAxis side.
547
+ 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;
548
+
549
+ // Otherwise fallback.
550
+ if (!resetPlacement) {
551
+ switch (fallbackStrategy) {
552
+ case 'bestFit':
553
+ {
554
+ var _overflowsData$map$so;
555
+ 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];
556
+ if (placement) {
557
+ resetPlacement = placement;
558
+ }
559
+ break;
560
+ }
561
+ case 'initialPlacement':
562
+ resetPlacement = initialPlacement;
563
+ break;
564
+ }
565
+ }
566
+ if (placement !== resetPlacement) {
567
+ return {
568
+ reset: {
569
+ placement: resetPlacement
570
+ }
571
+ };
572
+ }
573
+ }
574
+ return {};
575
+ }
576
+ };
577
+ };
578
+
579
+ // For type backwards-compatibility, the `OffsetOptions` type was also
580
+ // Derivable.
581
+ async function convertValueToCoords(state, options) {
582
+ const {
583
+ placement,
584
+ platform,
585
+ elements
586
+ } = state;
587
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
588
+ const side = getSide(placement);
589
+ const alignment = getAlignment(placement);
590
+ const isVertical = getSideAxis(placement) === 'y';
591
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
592
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
593
+ const rawValue = evaluate(options, state);
594
+
595
+ // eslint-disable-next-line prefer-const
596
+ let {
597
+ mainAxis,
598
+ crossAxis,
599
+ alignmentAxis
600
+ } = typeof rawValue === 'number' ? {
601
+ mainAxis: rawValue,
602
+ crossAxis: 0,
603
+ alignmentAxis: null
604
+ } : {
605
+ mainAxis: 0,
606
+ crossAxis: 0,
607
+ alignmentAxis: null,
608
+ ...rawValue
609
+ };
610
+ if (alignment && typeof alignmentAxis === 'number') {
611
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
612
+ }
613
+ return isVertical ? {
614
+ x: crossAxis * crossAxisMulti,
615
+ y: mainAxis * mainAxisMulti
616
+ } : {
617
+ x: mainAxis * mainAxisMulti,
618
+ y: crossAxis * crossAxisMulti
619
+ };
620
+ }
621
+
622
+ /**
623
+ * Modifies the placement by translating the floating element along the
624
+ * specified axes.
625
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
626
+ * object may be passed.
627
+ * @see https://floating-ui.com/docs/offset
628
+ */
629
+ const offset = function (options) {
630
+ if (options === void 0) {
631
+ options = 0;
632
+ }
633
+ return {
634
+ name: 'offset',
635
+ options,
636
+ async fn(state) {
637
+ var _middlewareData$offse, _middlewareData$arrow;
638
+ const {
639
+ x,
640
+ y,
641
+ placement,
642
+ middlewareData
643
+ } = state;
644
+ const diffCoords = await convertValueToCoords(state, options);
645
+
646
+ // If the placement is the same and the arrow caused an alignment offset
647
+ // then we don't need to change the positioning coordinates.
648
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
649
+ return {};
650
+ }
651
+ return {
652
+ x: x + diffCoords.x,
653
+ y: y + diffCoords.y,
654
+ data: {
655
+ ...diffCoords,
656
+ placement
657
+ }
658
+ };
659
+ }
660
+ };
661
+ };
662
+
663
+ /**
664
+ * Optimizes the visibility of the floating element by shifting it in order to
665
+ * keep it in view when it will overflow the clipping boundary.
666
+ * @see https://floating-ui.com/docs/shift
667
+ */
668
+ const shift = function (options) {
669
+ if (options === void 0) {
670
+ options = {};
671
+ }
672
+ return {
673
+ name: 'shift',
674
+ options,
675
+ async fn(state) {
676
+ const {
677
+ x,
678
+ y,
679
+ placement
680
+ } = state;
681
+ const {
682
+ mainAxis: checkMainAxis = true,
683
+ crossAxis: checkCrossAxis = false,
684
+ limiter = {
685
+ fn: _ref => {
686
+ let {
687
+ x,
688
+ y
689
+ } = _ref;
690
+ return {
691
+ x,
692
+ y
693
+ };
694
+ }
695
+ },
696
+ ...detectOverflowOptions
697
+ } = evaluate(options, state);
698
+ const coords = {
699
+ x,
700
+ y
701
+ };
702
+ const overflow = await detectOverflow(state, detectOverflowOptions);
703
+ const crossAxis = getSideAxis(getSide(placement));
704
+ const mainAxis = getOppositeAxis(crossAxis);
705
+ let mainAxisCoord = coords[mainAxis];
706
+ let crossAxisCoord = coords[crossAxis];
707
+ if (checkMainAxis) {
708
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
709
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
710
+ const min = mainAxisCoord + overflow[minSide];
711
+ const max = mainAxisCoord - overflow[maxSide];
712
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
713
+ }
714
+ if (checkCrossAxis) {
715
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
716
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
717
+ const min = crossAxisCoord + overflow[minSide];
718
+ const max = crossAxisCoord - overflow[maxSide];
719
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
720
+ }
721
+ const limitedCoords = limiter.fn({
722
+ ...state,
723
+ [mainAxis]: mainAxisCoord,
724
+ [crossAxis]: crossAxisCoord
725
+ });
726
+ return {
727
+ ...limitedCoords,
728
+ data: {
729
+ x: limitedCoords.x - x,
730
+ y: limitedCoords.y - y
731
+ }
732
+ };
733
+ }
734
+ };
735
+ };
736
+
737
+ function getCssDimensions(element) {
738
+ const css = getComputedStyle(element);
739
+ // In testing environments, the `width` and `height` properties are empty
740
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
741
+ let width = parseFloat(css.width) || 0;
742
+ let height = parseFloat(css.height) || 0;
743
+ const hasOffset = isHTMLElement(element);
744
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
745
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
746
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
747
+ if (shouldFallback) {
748
+ width = offsetWidth;
749
+ height = offsetHeight;
750
+ }
751
+ return {
752
+ width,
753
+ height,
754
+ $: shouldFallback
755
+ };
756
+ }
757
+
758
+ function unwrapElement(element) {
759
+ return !isElement(element) ? element.contextElement : element;
760
+ }
761
+
762
+ function getScale(element) {
763
+ const domElement = unwrapElement(element);
764
+ if (!isHTMLElement(domElement)) {
765
+ return createCoords(1);
766
+ }
767
+ const rect = domElement.getBoundingClientRect();
768
+ const {
769
+ width,
770
+ height,
771
+ $
772
+ } = getCssDimensions(domElement);
773
+ let x = ($ ? round(rect.width) : rect.width) / width;
774
+ let y = ($ ? round(rect.height) : rect.height) / height;
775
+
776
+ // 0, NaN, or Infinity should always fallback to 1.
777
+
778
+ if (!x || !Number.isFinite(x)) {
779
+ x = 1;
780
+ }
781
+ if (!y || !Number.isFinite(y)) {
782
+ y = 1;
783
+ }
784
+ return {
785
+ x,
786
+ y
787
+ };
788
+ }
789
+
790
+ const noOffsets = /*#__PURE__*/createCoords(0);
791
+ function getVisualOffsets(element) {
792
+ const win = getWindow(element);
793
+ if (!isWebKit() || !win.visualViewport) {
794
+ return noOffsets;
795
+ }
796
+ return {
797
+ x: win.visualViewport.offsetLeft,
798
+ y: win.visualViewport.offsetTop
799
+ };
800
+ }
801
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
802
+ if (isFixed === void 0) {
803
+ isFixed = false;
804
+ }
805
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
806
+ return false;
807
+ }
808
+ return isFixed;
809
+ }
810
+
811
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
812
+ if (includeScale === void 0) {
813
+ includeScale = false;
814
+ }
815
+ if (isFixedStrategy === void 0) {
816
+ isFixedStrategy = false;
817
+ }
818
+ const clientRect = element.getBoundingClientRect();
819
+ const domElement = unwrapElement(element);
820
+ let scale = createCoords(1);
821
+ if (includeScale) {
822
+ if (offsetParent) {
823
+ if (isElement(offsetParent)) {
824
+ scale = getScale(offsetParent);
825
+ }
826
+ } else {
827
+ scale = getScale(element);
828
+ }
829
+ }
830
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
831
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
832
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
833
+ let width = clientRect.width / scale.x;
834
+ let height = clientRect.height / scale.y;
835
+ if (domElement) {
836
+ const win = getWindow(domElement);
837
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
838
+ let currentIFrame = win.frameElement;
839
+ while (currentIFrame && offsetParent && offsetWin !== win) {
840
+ const iframeScale = getScale(currentIFrame);
841
+ const iframeRect = currentIFrame.getBoundingClientRect();
842
+ const css = getComputedStyle(currentIFrame);
843
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
844
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
845
+ x *= iframeScale.x;
846
+ y *= iframeScale.y;
847
+ width *= iframeScale.x;
848
+ height *= iframeScale.y;
849
+ x += left;
850
+ y += top;
851
+ currentIFrame = getWindow(currentIFrame).frameElement;
852
+ }
853
+ }
854
+ return rectToClientRect({
855
+ width,
856
+ height,
857
+ x,
858
+ y
859
+ });
860
+ }
861
+
862
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
863
+ let {
864
+ rect,
865
+ offsetParent,
866
+ strategy
867
+ } = _ref;
868
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
869
+ const documentElement = getDocumentElement(offsetParent);
870
+ if (offsetParent === documentElement) {
871
+ return rect;
872
+ }
873
+ let scroll = {
874
+ scrollLeft: 0,
875
+ scrollTop: 0
876
+ };
877
+ let scale = createCoords(1);
878
+ const offsets = createCoords(0);
879
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
880
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
881
+ scroll = getNodeScroll(offsetParent);
882
+ }
883
+ if (isHTMLElement(offsetParent)) {
884
+ const offsetRect = getBoundingClientRect(offsetParent);
885
+ scale = getScale(offsetParent);
886
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
887
+ offsets.y = offsetRect.y + offsetParent.clientTop;
888
+ }
889
+ }
890
+ return {
891
+ width: rect.width * scale.x,
892
+ height: rect.height * scale.y,
893
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
894
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
895
+ };
896
+ }
897
+
898
+ function getClientRects(element) {
899
+ return Array.from(element.getClientRects());
900
+ }
901
+
902
+ function getWindowScrollBarX(element) {
903
+ // If <html> has a CSS width greater than the viewport, then this will be
904
+ // incorrect for RTL.
905
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
906
+ }
907
+
908
+ // Gets the entire size of the scrollable document area, even extending outside
909
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
910
+ function getDocumentRect(element) {
911
+ const html = getDocumentElement(element);
912
+ const scroll = getNodeScroll(element);
913
+ const body = element.ownerDocument.body;
914
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
915
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
916
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
917
+ const y = -scroll.scrollTop;
918
+ if (getComputedStyle(body).direction === 'rtl') {
919
+ x += max(html.clientWidth, body.clientWidth) - width;
920
+ }
921
+ return {
922
+ width,
923
+ height,
924
+ x,
925
+ y
926
+ };
927
+ }
928
+
929
+ function getViewportRect(element, strategy) {
930
+ const win = getWindow(element);
931
+ const html = getDocumentElement(element);
932
+ const visualViewport = win.visualViewport;
933
+ let width = html.clientWidth;
934
+ let height = html.clientHeight;
935
+ let x = 0;
936
+ let y = 0;
937
+ if (visualViewport) {
938
+ width = visualViewport.width;
939
+ height = visualViewport.height;
940
+ const visualViewportBased = isWebKit();
941
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
942
+ x = visualViewport.offsetLeft;
943
+ y = visualViewport.offsetTop;
944
+ }
945
+ }
946
+ return {
947
+ width,
948
+ height,
949
+ x,
950
+ y
951
+ };
952
+ }
953
+
954
+ // Returns the inner client rect, subtracting scrollbars if present.
955
+ function getInnerBoundingClientRect(element, strategy) {
956
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
957
+ const top = clientRect.top + element.clientTop;
958
+ const left = clientRect.left + element.clientLeft;
959
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
960
+ const width = element.clientWidth * scale.x;
961
+ const height = element.clientHeight * scale.y;
962
+ const x = left * scale.x;
963
+ const y = top * scale.y;
964
+ return {
965
+ width,
966
+ height,
967
+ x,
968
+ y
969
+ };
970
+ }
971
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
972
+ let rect;
973
+ if (clippingAncestor === 'viewport') {
974
+ rect = getViewportRect(element, strategy);
975
+ } else if (clippingAncestor === 'document') {
976
+ rect = getDocumentRect(getDocumentElement(element));
977
+ } else if (isElement(clippingAncestor)) {
978
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
979
+ } else {
980
+ const visualOffsets = getVisualOffsets(element);
981
+ rect = {
982
+ ...clippingAncestor,
983
+ x: clippingAncestor.x - visualOffsets.x,
984
+ y: clippingAncestor.y - visualOffsets.y
985
+ };
986
+ }
987
+ return rectToClientRect(rect);
988
+ }
989
+ function hasFixedPositionAncestor(element, stopNode) {
990
+ const parentNode = getParentNode(element);
991
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
992
+ return false;
993
+ }
994
+ return getComputedStyle(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
995
+ }
996
+
997
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
998
+ // clipping (or hiding) child elements. This returns all clipping ancestors
999
+ // of the given element up the tree.
1000
+ function getClippingElementAncestors(element, cache) {
1001
+ const cachedResult = cache.get(element);
1002
+ if (cachedResult) {
1003
+ return cachedResult;
1004
+ }
1005
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
1006
+ let currentContainingBlockComputedStyle = null;
1007
+ const elementIsFixed = getComputedStyle(element).position === 'fixed';
1008
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1009
+
1010
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1011
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1012
+ const computedStyle = getComputedStyle(currentNode);
1013
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1014
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
1015
+ currentContainingBlockComputedStyle = null;
1016
+ }
1017
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1018
+ if (shouldDropCurrentNode) {
1019
+ // Drop non-containing blocks.
1020
+ result = result.filter(ancestor => ancestor !== currentNode);
1021
+ } else {
1022
+ // Record last containing block for next iteration.
1023
+ currentContainingBlockComputedStyle = computedStyle;
1024
+ }
1025
+ currentNode = getParentNode(currentNode);
1026
+ }
1027
+ cache.set(element, result);
1028
+ return result;
1029
+ }
1030
+
1031
+ // Gets the maximum area that the element is visible in due to any number of
1032
+ // clipping ancestors.
1033
+ function getClippingRect(_ref) {
1034
+ let {
1035
+ element,
1036
+ boundary,
1037
+ rootBoundary,
1038
+ strategy
1039
+ } = _ref;
1040
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
1041
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1042
+ const firstClippingAncestor = clippingAncestors[0];
1043
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
1044
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1045
+ accRect.top = max(rect.top, accRect.top);
1046
+ accRect.right = min(rect.right, accRect.right);
1047
+ accRect.bottom = min(rect.bottom, accRect.bottom);
1048
+ accRect.left = max(rect.left, accRect.left);
1049
+ return accRect;
1050
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1051
+ return {
1052
+ width: clippingRect.right - clippingRect.left,
1053
+ height: clippingRect.bottom - clippingRect.top,
1054
+ x: clippingRect.left,
1055
+ y: clippingRect.top
1056
+ };
1057
+ }
1058
+
1059
+ function getDimensions(element) {
1060
+ return getCssDimensions(element);
1061
+ }
1062
+
1063
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1064
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1065
+ const documentElement = getDocumentElement(offsetParent);
1066
+ const isFixed = strategy === 'fixed';
1067
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1068
+ let scroll = {
1069
+ scrollLeft: 0,
1070
+ scrollTop: 0
1071
+ };
1072
+ const offsets = createCoords(0);
1073
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1074
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1075
+ scroll = getNodeScroll(offsetParent);
1076
+ }
1077
+ if (isOffsetParentAnElement) {
1078
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1079
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1080
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1081
+ } else if (documentElement) {
1082
+ offsets.x = getWindowScrollBarX(documentElement);
1083
+ }
1084
+ }
1085
+ return {
1086
+ x: rect.left + scroll.scrollLeft - offsets.x,
1087
+ y: rect.top + scroll.scrollTop - offsets.y,
1088
+ width: rect.width,
1089
+ height: rect.height
1090
+ };
1091
+ }
1092
+
1093
+ function getTrueOffsetParent(element, polyfill) {
1094
+ if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {
1095
+ return null;
1096
+ }
1097
+ if (polyfill) {
1098
+ return polyfill(element);
1099
+ }
1100
+ return element.offsetParent;
1101
+ }
1102
+
1103
+ // Gets the closest ancestor positioned element. Handles some edge cases,
1104
+ // such as table ancestors and cross browser bugs.
1105
+ function getOffsetParent(element, polyfill) {
1106
+ const window = getWindow(element);
1107
+ if (!isHTMLElement(element)) {
1108
+ return window;
1109
+ }
1110
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1111
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
1112
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1113
+ }
1114
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
1115
+ return window;
1116
+ }
1117
+ return offsetParent || getContainingBlock(element) || window;
1118
+ }
1119
+
1120
+ const getElementRects = async function (_ref) {
1121
+ let {
1122
+ reference,
1123
+ floating,
1124
+ strategy
1125
+ } = _ref;
1126
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1127
+ const getDimensionsFn = this.getDimensions;
1128
+ return {
1129
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
1130
+ floating: {
1131
+ x: 0,
1132
+ y: 0,
1133
+ ...(await getDimensionsFn(floating))
1134
+ }
1135
+ };
1136
+ };
1137
+
1138
+ function isRTL(element) {
1139
+ return getComputedStyle(element).direction === 'rtl';
1140
+ }
1141
+
1142
+ const platform = {
1143
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1144
+ getDocumentElement,
1145
+ getClippingRect,
1146
+ getOffsetParent,
1147
+ getElementRects,
1148
+ getClientRects,
1149
+ getDimensions,
1150
+ getScale,
1151
+ isElement,
1152
+ isRTL
1153
+ };
1154
+
1155
+ // https://samthor.au/2021/observing-dom/
1156
+ function observeMove(element, onMove) {
1157
+ let io = null;
1158
+ let timeoutId;
1159
+ const root = getDocumentElement(element);
1160
+ function cleanup() {
1161
+ clearTimeout(timeoutId);
1162
+ io && io.disconnect();
1163
+ io = null;
1164
+ }
1165
+ function refresh(skip, threshold) {
1166
+ if (skip === void 0) {
1167
+ skip = false;
1168
+ }
1169
+ if (threshold === void 0) {
1170
+ threshold = 1;
1171
+ }
1172
+ cleanup();
1173
+ const {
1174
+ left,
1175
+ top,
1176
+ width,
1177
+ height
1178
+ } = element.getBoundingClientRect();
1179
+ if (!skip) {
1180
+ onMove();
1181
+ }
1182
+ if (!width || !height) {
1183
+ return;
1184
+ }
1185
+ const insetTop = floor(top);
1186
+ const insetRight = floor(root.clientWidth - (left + width));
1187
+ const insetBottom = floor(root.clientHeight - (top + height));
1188
+ const insetLeft = floor(left);
1189
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1190
+ const options = {
1191
+ rootMargin,
1192
+ threshold: max(0, min(1, threshold)) || 1
1193
+ };
1194
+ let isFirstUpdate = true;
1195
+ function handleObserve(entries) {
1196
+ const ratio = entries[0].intersectionRatio;
1197
+ if (ratio !== threshold) {
1198
+ if (!isFirstUpdate) {
1199
+ return refresh();
1200
+ }
1201
+ if (!ratio) {
1202
+ timeoutId = setTimeout(() => {
1203
+ refresh(false, 1e-7);
1204
+ }, 100);
1205
+ } else {
1206
+ refresh(false, ratio);
1207
+ }
1208
+ }
1209
+ isFirstUpdate = false;
1210
+ }
1211
+
1212
+ // Older browsers don't support a `document` as the root and will throw an
1213
+ // error.
1214
+ try {
1215
+ io = new IntersectionObserver(handleObserve, {
1216
+ ...options,
1217
+ // Handle <iframe>s
1218
+ root: root.ownerDocument
1219
+ });
1220
+ } catch (e) {
1221
+ io = new IntersectionObserver(handleObserve, options);
1222
+ }
1223
+ io.observe(element);
1224
+ }
1225
+ refresh(true);
1226
+ return cleanup;
1227
+ }
1228
+
1229
+ /**
1230
+ * Automatically updates the position of the floating element when necessary.
1231
+ * Should only be called when the floating element is mounted on the DOM or
1232
+ * visible on the screen.
1233
+ * @returns cleanup function that should be invoked when the floating element is
1234
+ * removed from the DOM or hidden from the screen.
1235
+ * @see https://floating-ui.com/docs/autoUpdate
1236
+ */
1237
+ function autoUpdate(reference, floating, update, options) {
1238
+ if (options === void 0) {
1239
+ options = {};
1240
+ }
1241
+ const {
1242
+ ancestorScroll = true,
1243
+ ancestorResize = true,
1244
+ elementResize = typeof ResizeObserver === 'function',
1245
+ layoutShift = typeof IntersectionObserver === 'function',
1246
+ animationFrame = false
1247
+ } = options;
1248
+ const referenceEl = unwrapElement(reference);
1249
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
1250
+ ancestors.forEach(ancestor => {
1251
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
1252
+ passive: true
1253
+ });
1254
+ ancestorResize && ancestor.addEventListener('resize', update);
1255
+ });
1256
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
1257
+ let reobserveFrame = -1;
1258
+ let resizeObserver = null;
1259
+ if (elementResize) {
1260
+ resizeObserver = new ResizeObserver(_ref => {
1261
+ let [firstEntry] = _ref;
1262
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
1263
+ // Prevent update loops when using the `size` middleware.
1264
+ // https://github.com/floating-ui/floating-ui/issues/1740
1265
+ resizeObserver.unobserve(floating);
1266
+ cancelAnimationFrame(reobserveFrame);
1267
+ reobserveFrame = requestAnimationFrame(() => {
1268
+ resizeObserver && resizeObserver.observe(floating);
1269
+ });
1270
+ }
1271
+ update();
1272
+ });
1273
+ if (referenceEl && !animationFrame) {
1274
+ resizeObserver.observe(referenceEl);
1275
+ }
1276
+ resizeObserver.observe(floating);
1277
+ }
1278
+ let frameId;
1279
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1280
+ if (animationFrame) {
1281
+ frameLoop();
1282
+ }
1283
+ function frameLoop() {
1284
+ const nextRefRect = getBoundingClientRect(reference);
1285
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
1286
+ update();
1287
+ }
1288
+ prevRefRect = nextRefRect;
1289
+ frameId = requestAnimationFrame(frameLoop);
1290
+ }
1291
+ update();
1292
+ return () => {
1293
+ ancestors.forEach(ancestor => {
1294
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
1295
+ ancestorResize && ancestor.removeEventListener('resize', update);
1296
+ });
1297
+ cleanupIo && cleanupIo();
1298
+ resizeObserver && resizeObserver.disconnect();
1299
+ resizeObserver = null;
1300
+ if (animationFrame) {
1301
+ cancelAnimationFrame(frameId);
1302
+ }
1303
+ };
1304
+ }
1305
+
1306
+ /**
1307
+ * Computes the `x` and `y` coordinates that will place the floating element
1308
+ * next to a reference element when it is given a certain CSS positioning
1309
+ * strategy.
1310
+ */
1311
+ const computePosition = (reference, floating, options) => {
1312
+ // This caches the expensive `getClippingElementAncestors` function so that
1313
+ // multiple lifecycle resets re-use the same result. It only lives for a
1314
+ // single call. If other functions become expensive, we can add them as well.
1315
+ const cache = new Map();
1316
+ const mergedOptions = {
1317
+ platform,
1318
+ ...options
1319
+ };
1320
+ const platformWithCache = {
1321
+ ...mergedOptions.platform,
1322
+ _c: cache
1323
+ };
1324
+ return computePosition$1(reference, floating, {
1325
+ ...mergedOptions,
1326
+ platform: platformWithCache
1327
+ });
1328
+ };
1329
+
1330
+ var index$1 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1331
+
1332
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1333
+ // functions
1334
+ function deepEqual(a, b) {
1335
+ if (a === b) {
1336
+ return true;
1337
+ }
1338
+ if (typeof a !== typeof b) {
1339
+ return false;
1340
+ }
1341
+ if (typeof a === 'function' && a.toString() === b.toString()) {
1342
+ return true;
1343
+ }
1344
+ let length, i, keys;
1345
+ if (a && b && typeof a == 'object') {
1346
+ if (Array.isArray(a)) {
1347
+ length = a.length;
1348
+ if (length != b.length) return false;
1349
+ for (i = length; i-- !== 0;) {
1350
+ if (!deepEqual(a[i], b[i])) {
1351
+ return false;
1352
+ }
1353
+ }
1354
+ return true;
1355
+ }
1356
+ keys = Object.keys(a);
1357
+ length = keys.length;
1358
+ if (length !== Object.keys(b).length) {
1359
+ return false;
1360
+ }
1361
+ for (i = length; i-- !== 0;) {
1362
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
1363
+ return false;
1364
+ }
1365
+ }
1366
+ for (i = length; i-- !== 0;) {
1367
+ const key = keys[i];
1368
+ if (key === '_owner' && a.$$typeof) {
1369
+ continue;
1370
+ }
1371
+ if (!deepEqual(a[key], b[key])) {
1372
+ return false;
1373
+ }
1374
+ }
1375
+ return true;
1376
+ }
1377
+ return a !== a && b !== b;
1378
+ }
1379
+
1380
+ function getDPR(element) {
1381
+ if (typeof window === 'undefined') {
1382
+ return 1;
1383
+ }
1384
+ const win = element.ownerDocument.defaultView || window;
1385
+ return win.devicePixelRatio || 1;
1386
+ }
1387
+
1388
+ function roundByDPR(element, value) {
1389
+ const dpr = getDPR(element);
1390
+ return Math.round(value * dpr) / dpr;
1391
+ }
1392
+
1393
+ function useLatestRef(value) {
1394
+ const ref = React$1.useRef(value);
1395
+ index$1(() => {
1396
+ ref.current = value;
1397
+ });
1398
+ return ref;
1399
+ }
1400
+
1401
+ /**
1402
+ * Provides data to position a floating element.
1403
+ * @see https://floating-ui.com/docs/useFloating
1404
+ */
1405
+ function useFloating$1(options) {
1406
+ if (options === void 0) {
1407
+ options = {};
1408
+ }
1409
+ const {
1410
+ placement = 'bottom',
1411
+ strategy = 'absolute',
1412
+ middleware = [],
1413
+ platform,
1414
+ elements: {
1415
+ reference: externalReference,
1416
+ floating: externalFloating
1417
+ } = {},
1418
+ transform = true,
1419
+ whileElementsMounted,
1420
+ open
1421
+ } = options;
1422
+ const [data, setData] = React$1.useState({
1423
+ x: 0,
1424
+ y: 0,
1425
+ strategy,
1426
+ placement,
1427
+ middlewareData: {},
1428
+ isPositioned: false
1429
+ });
1430
+ const [latestMiddleware, setLatestMiddleware] = React$1.useState(middleware);
1431
+ if (!deepEqual(latestMiddleware, middleware)) {
1432
+ setLatestMiddleware(middleware);
1433
+ }
1434
+ const [_reference, _setReference] = React$1.useState(null);
1435
+ const [_floating, _setFloating] = React$1.useState(null);
1436
+ const setReference = React$1.useCallback(node => {
1437
+ if (node != referenceRef.current) {
1438
+ referenceRef.current = node;
1439
+ _setReference(node);
1440
+ }
1441
+ }, [_setReference]);
1442
+ const setFloating = React$1.useCallback(node => {
1443
+ if (node !== floatingRef.current) {
1444
+ floatingRef.current = node;
1445
+ _setFloating(node);
1446
+ }
1447
+ }, [_setFloating]);
1448
+ const referenceEl = externalReference || _reference;
1449
+ const floatingEl = externalFloating || _floating;
1450
+ const referenceRef = React$1.useRef(null);
1451
+ const floatingRef = React$1.useRef(null);
1452
+ const dataRef = React$1.useRef(data);
1453
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
1454
+ const platformRef = useLatestRef(platform);
1455
+ const update = React$1.useCallback(() => {
1456
+ if (!referenceRef.current || !floatingRef.current) {
1457
+ return;
1458
+ }
1459
+ const config = {
1460
+ placement,
1461
+ strategy,
1462
+ middleware: latestMiddleware
1463
+ };
1464
+ if (platformRef.current) {
1465
+ config.platform = platformRef.current;
1466
+ }
1467
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
1468
+ const fullData = {
1469
+ ...data,
1470
+ isPositioned: true
1471
+ };
1472
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
1473
+ dataRef.current = fullData;
1474
+ ReactDOM.flushSync(() => {
1475
+ setData(fullData);
1476
+ });
1477
+ }
1478
+ });
1479
+ }, [latestMiddleware, placement, strategy, platformRef]);
1480
+ index$1(() => {
1481
+ if (open === false && dataRef.current.isPositioned) {
1482
+ dataRef.current.isPositioned = false;
1483
+ setData(data => ({
1484
+ ...data,
1485
+ isPositioned: false
1486
+ }));
1487
+ }
1488
+ }, [open]);
1489
+ const isMountedRef = React$1.useRef(false);
1490
+ index$1(() => {
1491
+ isMountedRef.current = true;
1492
+ return () => {
1493
+ isMountedRef.current = false;
1494
+ };
1495
+ }, []);
1496
+ index$1(() => {
1497
+ if (referenceEl) referenceRef.current = referenceEl;
1498
+ if (floatingEl) floatingRef.current = floatingEl;
1499
+ if (referenceEl && floatingEl) {
1500
+ if (whileElementsMountedRef.current) {
1501
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
1502
+ } else {
1503
+ update();
1504
+ }
1505
+ }
1506
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef]);
1507
+ const refs = React$1.useMemo(() => ({
1508
+ reference: referenceRef,
1509
+ floating: floatingRef,
1510
+ setReference,
1511
+ setFloating
1512
+ }), [setReference, setFloating]);
1513
+ const elements = React$1.useMemo(() => ({
1514
+ reference: referenceEl,
1515
+ floating: floatingEl
1516
+ }), [referenceEl, floatingEl]);
1517
+ const floatingStyles = React$1.useMemo(() => {
1518
+ const initialStyles = {
1519
+ position: strategy,
1520
+ left: 0,
1521
+ top: 0
1522
+ };
1523
+ if (!elements.floating) {
1524
+ return initialStyles;
1525
+ }
1526
+ const x = roundByDPR(elements.floating, data.x);
1527
+ const y = roundByDPR(elements.floating, data.y);
1528
+ if (transform) {
1529
+ return {
1530
+ ...initialStyles,
1531
+ transform: "translate(" + x + "px, " + y + "px)",
1532
+ ...(getDPR(elements.floating) >= 1.5 && {
1533
+ willChange: 'transform'
1534
+ })
1535
+ };
1536
+ }
1537
+ return {
1538
+ position: strategy,
1539
+ left: x,
1540
+ top: y
1541
+ };
1542
+ }, [strategy, transform, elements.floating, data.x, data.y]);
1543
+ return React$1.useMemo(() => ({
1544
+ ...data,
1545
+ update,
1546
+ refs,
1547
+ elements,
1548
+ floatingStyles
1549
+ }), [data, update, refs, elements, floatingStyles]);
1550
+ }
1551
+
1552
+ // `toString()` prevents bundlers from trying to `import { useInsertionEffect } from 'react'`
1553
+ const useInsertionEffect = React$1[/*#__PURE__*/'useInsertionEffect'.toString()];
1554
+ const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
1555
+ function useEffectEvent(callback) {
1556
+ const ref = React$1.useRef(() => {
1557
+ if (process.env.NODE_ENV !== "production") {
1558
+ throw new Error('Cannot call an event handler while rendering.');
1559
+ }
1560
+ });
1561
+ useSafeInsertionEffect(() => {
1562
+ ref.current = callback;
1563
+ });
1564
+ return React$1.useCallback(function () {
1565
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1566
+ args[_key] = arguments[_key];
1567
+ }
1568
+ return ref.current == null ? void 0 : ref.current(...args);
1569
+ }, []);
1570
+ }
1571
+
1572
+ var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1573
+
1574
+ let serverHandoffComplete = false;
1575
+ let count = 0;
1576
+ const genId = () => "floating-ui-" + count++;
1577
+ function useFloatingId() {
1578
+ const [id, setId] = React$1.useState(() => serverHandoffComplete ? genId() : undefined);
1579
+ index(() => {
1580
+ if (id == null) {
1581
+ setId(genId());
1582
+ }
1583
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1584
+ }, []);
1585
+ React$1.useEffect(() => {
1586
+ if (!serverHandoffComplete) {
1587
+ serverHandoffComplete = true;
1588
+ }
1589
+ }, []);
1590
+ return id;
1591
+ }
1592
+
1593
+ // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
1594
+ const useReactId = React$1[/*#__PURE__*/'useId'.toString()];
1595
+
1596
+ /**
1597
+ * Uses React 18's built-in `useId()` when available, or falls back to a
1598
+ * slightly less performant (requiring a double render) implementation for
1599
+ * earlier React versions.
1600
+ * @see https://floating-ui.com/docs/useId
1601
+ */
1602
+ const useId = useReactId || useFloatingId;
1603
+
1604
+ function createPubSub() {
1605
+ const map = new Map();
1606
+ return {
1607
+ emit(event, data) {
1608
+ var _map$get;
1609
+ (_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
1610
+ },
1611
+ on(event, listener) {
1612
+ map.set(event, [...(map.get(event) || []), listener]);
1613
+ },
1614
+ off(event, listener) {
1615
+ var _map$get2;
1616
+ map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
1617
+ }
1618
+ };
1619
+ }
1620
+
1621
+ const FloatingNodeContext = /*#__PURE__*/React$1.createContext(null);
1622
+ const FloatingTreeContext = /*#__PURE__*/React$1.createContext(null);
1623
+ const useFloatingParentNodeId = () => {
1624
+ var _React$useContext;
1625
+ return ((_React$useContext = React$1.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
1626
+ };
1627
+ const useFloatingTree = () => React$1.useContext(FloatingTreeContext);
1628
+
1629
+ let devMessageSet;
1630
+ if (process.env.NODE_ENV !== "production") {
1631
+ devMessageSet = /*#__PURE__*/new Set();
1632
+ }
1633
+
1634
+ /**
1635
+ * Provides data to position a floating element and context to add interactions.
1636
+ * @see https://floating-ui.com/docs/useFloating
1637
+ */
1638
+ function useFloating(options) {
1639
+ var _options$elements2;
1640
+ if (options === void 0) {
1641
+ options = {};
1642
+ }
1643
+ const {
1644
+ open = false,
1645
+ onOpenChange: unstable_onOpenChange,
1646
+ nodeId
1647
+ } = options;
1648
+ if (process.env.NODE_ENV !== "production") {
1649
+ var _options$elements;
1650
+ 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.';
1651
+ if ((_options$elements = options.elements) != null && _options$elements.reference && !isElement(options.elements.reference)) {
1652
+ var _devMessageSet;
1653
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(err))) {
1654
+ var _devMessageSet2;
1655
+ (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(err);
1656
+ console.error(err);
1657
+ }
1658
+ }
1659
+ }
1660
+ const [_domReference, setDomReference] = React$1.useState(null);
1661
+ const domReference = ((_options$elements2 = options.elements) == null ? void 0 : _options$elements2.reference) || _domReference;
1662
+ const position = useFloating$1(options);
1663
+ const tree = useFloatingTree();
1664
+ const nested = useFloatingParentNodeId() != null;
1665
+ const onOpenChange = useEffectEvent((open, event, reason) => {
1666
+ if (open) {
1667
+ dataRef.current.openEvent = event;
1668
+ }
1669
+ events.emit('openchange', {
1670
+ open,
1671
+ event,
1672
+ reason,
1673
+ nested
1674
+ });
1675
+ unstable_onOpenChange == null || unstable_onOpenChange(open, event, reason);
1676
+ });
1677
+ const domReferenceRef = React$1.useRef(null);
1678
+ const dataRef = React$1.useRef({});
1679
+ const events = React$1.useState(() => createPubSub())[0];
1680
+ const floatingId = useId();
1681
+ const setPositionReference = React$1.useCallback(node => {
1682
+ const positionReference = isElement(node) ? {
1683
+ getBoundingClientRect: () => node.getBoundingClientRect(),
1684
+ contextElement: node
1685
+ } : node;
1686
+ position.refs.setReference(positionReference);
1687
+ }, [position.refs]);
1688
+ const setReference = React$1.useCallback(node => {
1689
+ if (isElement(node) || node === null) {
1690
+ domReferenceRef.current = node;
1691
+ setDomReference(node);
1692
+ }
1693
+
1694
+ // Backwards-compatibility for passing a virtual element to `reference`
1695
+ // after it has set the DOM reference.
1696
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
1697
+ // Don't allow setting virtual elements using the old technique back to
1698
+ // `null` to support `positionReference` + an unstable `reference`
1699
+ // callback ref.
1700
+ node !== null && !isElement(node)) {
1701
+ position.refs.setReference(node);
1702
+ }
1703
+ }, [position.refs]);
1704
+ const refs = React$1.useMemo(() => ({
1705
+ ...position.refs,
1706
+ setReference,
1707
+ setPositionReference,
1708
+ domReference: domReferenceRef
1709
+ }), [position.refs, setReference, setPositionReference]);
1710
+ const elements = React$1.useMemo(() => ({
1711
+ ...position.elements,
1712
+ domReference: domReference
1713
+ }), [position.elements, domReference]);
1714
+ const context = React$1.useMemo(() => ({
1715
+ ...position,
1716
+ refs,
1717
+ elements,
1718
+ dataRef,
1719
+ nodeId,
1720
+ floatingId,
1721
+ events,
1722
+ open,
1723
+ onOpenChange
1724
+ }), [position, nodeId, floatingId, events, open, onOpenChange, refs, elements]);
1725
+ index(() => {
1726
+ const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
1727
+ if (node) {
1728
+ node.context = context;
1729
+ }
1730
+ });
1731
+ return React$1.useMemo(() => ({
1732
+ ...position,
1733
+ context,
1734
+ refs,
1735
+ elements
1736
+ }), [position, refs, elements, context]);
1737
+ }
1738
+
1739
+ const Dropdown = _ref => {
1740
+ const [isOpen, setIsOpen] = useState(false);
1741
+ // todo
1742
+ useFloating({
1743
+ open: isOpen,
1744
+ onOpenChange: setIsOpen,
1745
+ middleware: [offset(10), flip(), shift()],
1746
+ whileElementsMounted: autoUpdate
1747
+ });
1748
+ return /*#__PURE__*/React.createElement("div", null, "Dropdown");
1749
+ };
1750
+
1751
+ export { Dropdown as default };