@radui/ui 0.0.1 → 0.0.2

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