@trackunit/react-components 0.1.157 → 0.1.158

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/index.esm.js CHANGED
@@ -1859,7 +1859,7 @@ function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "func
1859
1859
  * //=> Sun Jul 02 1995 00:00:00
1860
1860
  */
1861
1861
 
1862
- function max$2(dirtyDatesArray) {
1862
+ function max$1(dirtyDatesArray) {
1863
1863
  requiredArgs(1, arguments);
1864
1864
  var datesArray; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method
1865
1865
 
@@ -1907,7 +1907,7 @@ function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "func
1907
1907
  * //=> Wed Feb 11 1987 00:00:00
1908
1908
  */
1909
1909
 
1910
- function min$2(dirtyDatesArray) {
1910
+ function min$1(dirtyDatesArray) {
1911
1911
  requiredArgs(1, arguments);
1912
1912
  var datesArray; // `dirtyDatesArray` is Array, Set or Map, or object with custom `forEach` method
1913
1913
 
@@ -13919,10 +13919,10 @@ function getNextFocus(focusedDay, options) {
13919
13919
  };
13920
13920
  var newFocusedDay = moveFns[moveBy](focusedDay, direction === 'after' ? 1 : -1);
13921
13921
  if (direction === 'before' && fromDate) {
13922
- newFocusedDay = max$2([fromDate, newFocusedDay]);
13922
+ newFocusedDay = max$1([fromDate, newFocusedDay]);
13923
13923
  }
13924
13924
  else if (direction === 'after' && toDate) {
13925
- newFocusedDay = min$2([toDate, newFocusedDay]);
13925
+ newFocusedDay = min$1([toDate, newFocusedDay]);
13926
13926
  }
13927
13927
  var isFocusable = true;
13928
13928
  if (modifiers) {
@@ -14784,20 +14784,372 @@ const DayPicker = ({ onDaySelect, disabledDays, selectedDays, language, classNam
14784
14784
  return (jsx(DayPicker$1, { onDayClick: onDaySelect, selected: selectedDays, locale: locale, disabled: disabledDays, className: `custom-day-picker ${className !== null && className !== void 0 ? className : ""}`, max: max, footer: jsx("div", { "data-testid": dataTestId }) }));
14785
14785
  };
14786
14786
 
14787
+ const min = Math.min;
14788
+ const max = Math.max;
14789
+ const round = Math.round;
14790
+ const floor = Math.floor;
14791
+ const createCoords = v => ({
14792
+ x: v,
14793
+ y: v
14794
+ });
14795
+ const oppositeSideMap = {
14796
+ left: 'right',
14797
+ right: 'left',
14798
+ bottom: 'top',
14799
+ top: 'bottom'
14800
+ };
14801
+ const oppositeAlignmentMap = {
14802
+ start: 'end',
14803
+ end: 'start'
14804
+ };
14805
+ function clamp(start, value, end) {
14806
+ return max(start, min(value, end));
14807
+ }
14808
+ function evaluate(value, param) {
14809
+ return typeof value === 'function' ? value(param) : value;
14810
+ }
14811
+ function getSide(placement) {
14812
+ return placement.split('-')[0];
14813
+ }
14787
14814
  function getAlignment(placement) {
14788
14815
  return placement.split('-')[1];
14789
14816
  }
14790
-
14791
- function getLengthFromAxis(axis) {
14817
+ function getOppositeAxis(axis) {
14818
+ return axis === 'x' ? 'y' : 'x';
14819
+ }
14820
+ function getAxisLength(axis) {
14792
14821
  return axis === 'y' ? 'height' : 'width';
14793
14822
  }
14823
+ function getSideAxis(placement) {
14824
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
14825
+ }
14826
+ function getAlignmentAxis(placement) {
14827
+ return getOppositeAxis(getSideAxis(placement));
14828
+ }
14829
+ function getAlignmentSides(placement, rects, rtl) {
14830
+ if (rtl === void 0) {
14831
+ rtl = false;
14832
+ }
14833
+ const alignment = getAlignment(placement);
14834
+ const alignmentAxis = getAlignmentAxis(placement);
14835
+ const length = getAxisLength(alignmentAxis);
14836
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
14837
+ if (rects.reference[length] > rects.floating[length]) {
14838
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
14839
+ }
14840
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
14841
+ }
14842
+ function getExpandedPlacements(placement) {
14843
+ const oppositePlacement = getOppositePlacement(placement);
14844
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
14845
+ }
14846
+ function getOppositeAlignmentPlacement(placement) {
14847
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
14848
+ }
14849
+ function getSideList(side, isStart, rtl) {
14850
+ const lr = ['left', 'right'];
14851
+ const rl = ['right', 'left'];
14852
+ const tb = ['top', 'bottom'];
14853
+ const bt = ['bottom', 'top'];
14854
+ switch (side) {
14855
+ case 'top':
14856
+ case 'bottom':
14857
+ if (rtl) return isStart ? rl : lr;
14858
+ return isStart ? lr : rl;
14859
+ case 'left':
14860
+ case 'right':
14861
+ return isStart ? tb : bt;
14862
+ default:
14863
+ return [];
14864
+ }
14865
+ }
14866
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
14867
+ const alignment = getAlignment(placement);
14868
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
14869
+ if (alignment) {
14870
+ list = list.map(side => side + "-" + alignment);
14871
+ if (flipAlignment) {
14872
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
14873
+ }
14874
+ }
14875
+ return list;
14876
+ }
14877
+ function getOppositePlacement(placement) {
14878
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
14879
+ }
14880
+ function expandPaddingObject(padding) {
14881
+ return {
14882
+ top: 0,
14883
+ right: 0,
14884
+ bottom: 0,
14885
+ left: 0,
14886
+ ...padding
14887
+ };
14888
+ }
14889
+ function getPaddingObject(padding) {
14890
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
14891
+ top: padding,
14892
+ right: padding,
14893
+ bottom: padding,
14894
+ left: padding
14895
+ };
14896
+ }
14897
+ function rectToClientRect(rect) {
14898
+ return {
14899
+ ...rect,
14900
+ top: rect.y,
14901
+ left: rect.x,
14902
+ right: rect.x + rect.width,
14903
+ bottom: rect.y + rect.height
14904
+ };
14905
+ }
14794
14906
 
14795
- function getSide(placement) {
14796
- return placement.split('-')[0];
14907
+ function getNodeName(node) {
14908
+ if (isNode(node)) {
14909
+ return (node.nodeName || '').toLowerCase();
14910
+ }
14911
+ // Mocked nodes in testing environments may not be instances of Node. By
14912
+ // returning `#document` an infinite loop won't occur.
14913
+ // https://github.com/floating-ui/floating-ui/issues/2317
14914
+ return '#document';
14915
+ }
14916
+ function getWindow(node) {
14917
+ var _node$ownerDocument;
14918
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
14919
+ }
14920
+ function getDocumentElement(node) {
14921
+ var _ref;
14922
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
14923
+ }
14924
+ function isNode(value) {
14925
+ return value instanceof Node || value instanceof getWindow(value).Node;
14926
+ }
14927
+ function isElement(value) {
14928
+ return value instanceof Element || value instanceof getWindow(value).Element;
14929
+ }
14930
+ function isHTMLElement(value) {
14931
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
14932
+ }
14933
+ function isShadowRoot(value) {
14934
+ // Browsers without `ShadowRoot` support.
14935
+ if (typeof ShadowRoot === 'undefined') {
14936
+ return false;
14937
+ }
14938
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
14939
+ }
14940
+ function isOverflowElement(element) {
14941
+ const {
14942
+ overflow,
14943
+ overflowX,
14944
+ overflowY,
14945
+ display
14946
+ } = getComputedStyle$1(element);
14947
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
14948
+ }
14949
+ function isTableElement(element) {
14950
+ return ['table', 'td', 'th'].includes(getNodeName(element));
14951
+ }
14952
+ function isContainingBlock(element) {
14953
+ const webkit = isWebKit();
14954
+ const css = getComputedStyle$1(element);
14955
+
14956
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
14957
+ 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));
14958
+ }
14959
+ function getContainingBlock(element) {
14960
+ let currentNode = getParentNode(element);
14961
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
14962
+ if (isContainingBlock(currentNode)) {
14963
+ return currentNode;
14964
+ } else {
14965
+ currentNode = getParentNode(currentNode);
14966
+ }
14967
+ }
14968
+ return null;
14969
+ }
14970
+ function isWebKit() {
14971
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
14972
+ return CSS.supports('-webkit-backdrop-filter', 'none');
14973
+ }
14974
+ function isLastTraversableNode(node) {
14975
+ return ['html', 'body', '#document'].includes(getNodeName(node));
14976
+ }
14977
+ function getComputedStyle$1(element) {
14978
+ return getWindow(element).getComputedStyle(element);
14979
+ }
14980
+ function getNodeScroll(element) {
14981
+ if (isElement(element)) {
14982
+ return {
14983
+ scrollLeft: element.scrollLeft,
14984
+ scrollTop: element.scrollTop
14985
+ };
14986
+ }
14987
+ return {
14988
+ scrollLeft: element.pageXOffset,
14989
+ scrollTop: element.pageYOffset
14990
+ };
14991
+ }
14992
+ function getParentNode(node) {
14993
+ if (getNodeName(node) === 'html') {
14994
+ return node;
14995
+ }
14996
+ const result =
14997
+ // Step into the shadow DOM of the parent of a slotted node.
14998
+ node.assignedSlot ||
14999
+ // DOM Element detected.
15000
+ node.parentNode ||
15001
+ // ShadowRoot detected.
15002
+ isShadowRoot(node) && node.host ||
15003
+ // Fallback.
15004
+ getDocumentElement(node);
15005
+ return isShadowRoot(result) ? result.host : result;
15006
+ }
15007
+ function getNearestOverflowAncestor(node) {
15008
+ const parentNode = getParentNode(node);
15009
+ if (isLastTraversableNode(parentNode)) {
15010
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
15011
+ }
15012
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
15013
+ return parentNode;
15014
+ }
15015
+ return getNearestOverflowAncestor(parentNode);
15016
+ }
15017
+ function getOverflowAncestors(node, list) {
15018
+ var _node$ownerDocument2;
15019
+ if (list === void 0) {
15020
+ list = [];
15021
+ }
15022
+ const scrollableAncestor = getNearestOverflowAncestor(node);
15023
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
15024
+ const win = getWindow(scrollableAncestor);
15025
+ if (isBody) {
15026
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
15027
+ }
15028
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor));
14797
15029
  }
14798
15030
 
14799
- function getMainAxisFromPlacement(placement) {
14800
- return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
15031
+ function activeElement(doc) {
15032
+ let activeElement = doc.activeElement;
15033
+ while (((_activeElement = activeElement) == null ? void 0 : (_activeElement$shadow = _activeElement.shadowRoot) == null ? void 0 : _activeElement$shadow.activeElement) != null) {
15034
+ var _activeElement, _activeElement$shadow;
15035
+ activeElement = activeElement.shadowRoot.activeElement;
15036
+ }
15037
+ return activeElement;
15038
+ }
15039
+ function contains(parent, child) {
15040
+ if (!parent || !child) {
15041
+ return false;
15042
+ }
15043
+ const rootNode = child.getRootNode && child.getRootNode();
15044
+
15045
+ // First, attempt with faster native method
15046
+ if (parent.contains(child)) {
15047
+ return true;
15048
+ }
15049
+
15050
+ // then fallback to custom implementation with Shadow DOM support
15051
+ if (rootNode && isShadowRoot(rootNode)) {
15052
+ let next = child;
15053
+ while (next) {
15054
+ if (parent === next) {
15055
+ return true;
15056
+ }
15057
+ // @ts-ignore
15058
+ next = next.parentNode || next.host;
15059
+ }
15060
+ }
15061
+
15062
+ // Give up, the result is false
15063
+ return false;
15064
+ }
15065
+ // Avoid Chrome DevTools blue warning.
15066
+ function getPlatform() {
15067
+ const uaData = navigator.userAgentData;
15068
+ if (uaData != null && uaData.platform) {
15069
+ return uaData.platform;
15070
+ }
15071
+ return navigator.platform;
15072
+ }
15073
+ function getUserAgent() {
15074
+ const uaData = navigator.userAgentData;
15075
+ if (uaData && Array.isArray(uaData.brands)) {
15076
+ return uaData.brands.map(_ref => {
15077
+ let {
15078
+ brand,
15079
+ version
15080
+ } = _ref;
15081
+ return brand + "/" + version;
15082
+ }).join(' ');
15083
+ }
15084
+ return navigator.userAgent;
15085
+ }
15086
+
15087
+ // License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
15088
+ function isVirtualClick(event) {
15089
+ if (event.mozInputSource === 0 && event.isTrusted) {
15090
+ return true;
15091
+ }
15092
+ const androidRe = /Android/i;
15093
+ if ((androidRe.test(getPlatform()) || androidRe.test(getUserAgent())) && event.pointerType) {
15094
+ return event.type === 'click' && event.buttons === 1;
15095
+ }
15096
+ return event.detail === 0 && !event.pointerType;
15097
+ }
15098
+ function isVirtualPointerEvent(event) {
15099
+ return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType !== 'mouse' ||
15100
+ // iOS VoiceOver returns 0.333• for width/height.
15101
+ event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0;
15102
+ }
15103
+ function isSafari() {
15104
+ // Chrome DevTools does not complain about navigator.vendor
15105
+ return /apple/i.test(navigator.vendor);
15106
+ }
15107
+ function isMouseLikePointerType(pointerType, strict) {
15108
+ // On some Linux machines with Chromium, mouse inputs return a `pointerType`
15109
+ // of "pen": https://github.com/floating-ui/floating-ui/issues/2015
15110
+ const values = ['mouse', 'pen'];
15111
+ if (!strict) {
15112
+ values.push('', undefined);
15113
+ }
15114
+ return values.includes(pointerType);
15115
+ }
15116
+ function isReactEvent(event) {
15117
+ return 'nativeEvent' in event;
15118
+ }
15119
+ function isRootElement(element) {
15120
+ return element.matches('html,body');
15121
+ }
15122
+ function getDocument(node) {
15123
+ return (node == null ? void 0 : node.ownerDocument) || document;
15124
+ }
15125
+ function isEventTargetWithin(event, node) {
15126
+ if (node == null) {
15127
+ return false;
15128
+ }
15129
+ if ('composedPath' in event) {
15130
+ return event.composedPath().includes(node);
15131
+ }
15132
+
15133
+ // TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
15134
+ const e = event;
15135
+ return e.target != null && node.contains(e.target);
15136
+ }
15137
+ function getTarget(event) {
15138
+ if ('composedPath' in event) {
15139
+ return event.composedPath()[0];
15140
+ }
15141
+
15142
+ // TS thinks `event` is of type never as it assumes all browsers support
15143
+ // `composedPath()`, but browsers without shadow DOM don't.
15144
+ return event.target;
15145
+ }
15146
+ const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
15147
+ function isTypeableElement(element) {
15148
+ return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
15149
+ }
15150
+ function stopEvent(event) {
15151
+ event.preventDefault();
15152
+ event.stopPropagation();
14801
15153
  }
14802
15154
 
14803
15155
  function computeCoordsFromPlacement(_ref, placement, rtl) {
@@ -14805,13 +15157,14 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
14805
15157
  reference,
14806
15158
  floating
14807
15159
  } = _ref;
15160
+ const sideAxis = getSideAxis(placement);
15161
+ const alignmentAxis = getAlignmentAxis(placement);
15162
+ const alignLength = getAxisLength(alignmentAxis);
15163
+ const side = getSide(placement);
15164
+ const isVertical = sideAxis === 'y';
14808
15165
  const commonX = reference.x + reference.width / 2 - floating.width / 2;
14809
15166
  const commonY = reference.y + reference.height / 2 - floating.height / 2;
14810
- const mainAxis = getMainAxisFromPlacement(placement);
14811
- const length = getLengthFromAxis(mainAxis);
14812
- const commonAlign = reference[length] / 2 - floating[length] / 2;
14813
- const side = getSide(placement);
14814
- const isVertical = mainAxis === 'x';
15167
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
14815
15168
  let coords;
14816
15169
  switch (side) {
14817
15170
  case 'top':
@@ -14846,10 +15199,10 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
14846
15199
  }
14847
15200
  switch (getAlignment(placement)) {
14848
15201
  case 'start':
14849
- coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
15202
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
14850
15203
  break;
14851
15204
  case 'end':
14852
- coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
15205
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
14853
15206
  break;
14854
15207
  }
14855
15208
  return coords;
@@ -14871,22 +15224,6 @@ const computePosition$1 = async (reference, floating, config) => {
14871
15224
  } = config;
14872
15225
  const validMiddleware = middleware.filter(Boolean);
14873
15226
  const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
14874
- if (process.env.NODE_ENV !== "production") {
14875
- if (platform == null) {
14876
- console.error(['Floating UI: `platform` property was not passed to config. If you', 'want to use Floating UI on the web, install @floating-ui/dom', 'instead of the /core package. Otherwise, you can create your own', '`platform`: https://floating-ui.com/docs/platform'].join(' '));
14877
- }
14878
- if (validMiddleware.filter(_ref => {
14879
- let {
14880
- name
14881
- } = _ref;
14882
- return name === 'autoPlacement' || name === 'flip';
14883
- }).length > 1) {
14884
- throw new Error(['Floating UI: duplicate `flip` and/or `autoPlacement` middleware', 'detected. This will lead to an infinite loop. Ensure only one of', 'either has been passed to the `middleware` array.'].join(' '));
14885
- }
14886
- if (!reference || !floating) {
14887
- console.error(['Floating UI: The reference and/or floating element was not defined', 'when `computePosition()` was called. Ensure that both elements have', 'been created and can be measured.'].join(' '));
14888
- }
14889
- }
14890
15227
  let rects = await platform.getElementRects({
14891
15228
  reference,
14892
15229
  floating,
@@ -14932,11 +15269,6 @@ const computePosition$1 = async (reference, floating, config) => {
14932
15269
  ...data
14933
15270
  }
14934
15271
  };
14935
- if (process.env.NODE_ENV !== "production") {
14936
- if (resetCount > 50) {
14937
- console.warn(['Floating UI: The middleware lifecycle appears to be running in an', 'infinite loop. This is usually caused by a `reset` continually', 'being returned without a break condition.'].join(' '));
14938
- }
14939
- }
14940
15272
  if (reset && resetCount <= 50) {
14941
15273
  resetCount++;
14942
15274
  if (typeof reset === 'object') {
@@ -14968,35 +15300,6 @@ const computePosition$1 = async (reference, floating, config) => {
14968
15300
  };
14969
15301
  };
14970
15302
 
14971
- function expandPaddingObject(padding) {
14972
- return {
14973
- top: 0,
14974
- right: 0,
14975
- bottom: 0,
14976
- left: 0,
14977
- ...padding
14978
- };
14979
- }
14980
-
14981
- function getSideObjectFromPadding(padding) {
14982
- return typeof padding !== 'number' ? expandPaddingObject(padding) : {
14983
- top: padding,
14984
- right: padding,
14985
- bottom: padding,
14986
- left: padding
14987
- };
14988
- }
14989
-
14990
- function rectToClientRect(rect) {
14991
- return {
14992
- ...rect,
14993
- top: rect.y,
14994
- left: rect.x,
14995
- right: rect.x + rect.width,
14996
- bottom: rect.y + rect.height
14997
- };
14998
- }
14999
-
15000
15303
  /**
15001
15304
  * Resolves with an object of overflow side offsets that determine how much the
15002
15305
  * element is overflowing a given clipping boundary on each side.
@@ -15024,8 +15327,8 @@ async function detectOverflow(state, options) {
15024
15327
  elementContext = 'floating',
15025
15328
  altBoundary = false,
15026
15329
  padding = 0
15027
- } = options;
15028
- const paddingObject = getSideObjectFromPadding(padding);
15330
+ } = evaluate(options, state);
15331
+ const paddingObject = getPaddingObject(padding);
15029
15332
  const altContext = elementContext === 'floating' ? 'reference' : 'floating';
15030
15333
  const element = elements[altBoundary ? altContext : elementContext];
15031
15334
  const clippingClientRect = rectToClientRect(await platform.getClippingRect({
@@ -15043,98 +15346,21 @@ async function detectOverflow(state, options) {
15043
15346
  const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
15044
15347
  x: 1,
15045
15348
  y: 1
15046
- } : {
15047
- x: 1,
15048
- y: 1
15049
- };
15050
- const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
15051
- rect,
15052
- offsetParent,
15053
- strategy
15054
- }) : rect);
15055
- if (process.env.NODE_ENV !== "production") ;
15056
- return {
15057
- top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
15058
- bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
15059
- left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
15060
- right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
15061
- };
15062
- }
15063
-
15064
- const min$1 = Math.min;
15065
- const max$1 = Math.max;
15066
-
15067
- function within(min$1$1, value, max$1$1) {
15068
- return max$1(min$1$1, min$1(value, max$1$1));
15069
- }
15070
-
15071
- const oppositeSideMap = {
15072
- left: 'right',
15073
- right: 'left',
15074
- bottom: 'top',
15075
- top: 'bottom'
15076
- };
15077
- function getOppositePlacement(placement) {
15078
- return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
15079
- }
15080
-
15081
- function getAlignmentSides(placement, rects, rtl) {
15082
- if (rtl === void 0) {
15083
- rtl = false;
15084
- }
15085
- const alignment = getAlignment(placement);
15086
- const mainAxis = getMainAxisFromPlacement(placement);
15087
- const length = getLengthFromAxis(mainAxis);
15088
- let mainAlignmentSide = mainAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
15089
- if (rects.reference[length] > rects.floating[length]) {
15090
- mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
15091
- }
15092
- return {
15093
- main: mainAlignmentSide,
15094
- cross: getOppositePlacement(mainAlignmentSide)
15095
- };
15096
- }
15097
-
15098
- const oppositeAlignmentMap = {
15099
- start: 'end',
15100
- end: 'start'
15101
- };
15102
- function getOppositeAlignmentPlacement(placement) {
15103
- return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
15104
- }
15105
-
15106
- function getExpandedPlacements(placement) {
15107
- const oppositePlacement = getOppositePlacement(placement);
15108
- return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
15109
- }
15110
-
15111
- function getSideList(side, isStart, rtl) {
15112
- const lr = ['left', 'right'];
15113
- const rl = ['right', 'left'];
15114
- const tb = ['top', 'bottom'];
15115
- const bt = ['bottom', 'top'];
15116
- switch (side) {
15117
- case 'top':
15118
- case 'bottom':
15119
- if (rtl) return isStart ? rl : lr;
15120
- return isStart ? lr : rl;
15121
- case 'left':
15122
- case 'right':
15123
- return isStart ? tb : bt;
15124
- default:
15125
- return [];
15126
- }
15127
- }
15128
- function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
15129
- const alignment = getAlignment(placement);
15130
- let list = getSideList(getSide(placement), direction === 'start', rtl);
15131
- if (alignment) {
15132
- list = list.map(side => side + "-" + alignment);
15133
- if (flipAlignment) {
15134
- list = list.concat(list.map(getOppositeAlignmentPlacement));
15135
- }
15136
- }
15137
- return list;
15349
+ } : {
15350
+ x: 1,
15351
+ y: 1
15352
+ };
15353
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
15354
+ rect,
15355
+ offsetParent,
15356
+ strategy
15357
+ }) : rect);
15358
+ return {
15359
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
15360
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
15361
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
15362
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
15363
+ };
15138
15364
  }
15139
15365
 
15140
15366
  /**
@@ -15168,7 +15394,7 @@ const flip = function (options) {
15168
15394
  fallbackAxisSideDirection = 'none',
15169
15395
  flipAlignment = true,
15170
15396
  ...detectOverflowOptions
15171
- } = options;
15397
+ } = evaluate(options, state);
15172
15398
  const side = getSide(placement);
15173
15399
  const isBasePlacement = getSide(initialPlacement) === initialPlacement;
15174
15400
  const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
@@ -15184,11 +15410,8 @@ const flip = function (options) {
15184
15410
  overflows.push(overflow[side]);
15185
15411
  }
15186
15412
  if (checkCrossAxis) {
15187
- const {
15188
- main,
15189
- cross
15190
- } = getAlignmentSides(placement, rects, rtl);
15191
- overflows.push(overflow[main], overflow[cross]);
15413
+ const sides = getAlignmentSides(placement, rects, rtl);
15414
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
15192
15415
  }
15193
15416
  overflowsData = [...overflowsData, {
15194
15417
  placement,
@@ -15247,7 +15470,9 @@ const flip = function (options) {
15247
15470
  };
15248
15471
  };
15249
15472
 
15250
- async function convertValueToCoords(state, value) {
15473
+ // For type backwards-compatibility, the `OffsetOptions` type was also
15474
+ // Derivable.
15475
+ async function convertValueToCoords(state, options) {
15251
15476
  const {
15252
15477
  placement,
15253
15478
  platform,
@@ -15256,10 +15481,10 @@ async function convertValueToCoords(state, value) {
15256
15481
  const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
15257
15482
  const side = getSide(placement);
15258
15483
  const alignment = getAlignment(placement);
15259
- const isVertical = getMainAxisFromPlacement(placement) === 'x';
15484
+ const isVertical = getSideAxis(placement) === 'y';
15260
15485
  const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
15261
15486
  const crossAxisMulti = rtl && isVertical ? -1 : 1;
15262
- const rawValue = typeof value === 'function' ? value(state) : value;
15487
+ const rawValue = evaluate(options, state);
15263
15488
 
15264
15489
  // eslint-disable-next-line prefer-const
15265
15490
  let {
@@ -15295,19 +15520,19 @@ async function convertValueToCoords(state, value) {
15295
15520
  * object may be passed.
15296
15521
  * @see https://floating-ui.com/docs/offset
15297
15522
  */
15298
- const offset = function (value) {
15299
- if (value === void 0) {
15300
- value = 0;
15523
+ const offset = function (options) {
15524
+ if (options === void 0) {
15525
+ options = 0;
15301
15526
  }
15302
15527
  return {
15303
15528
  name: 'offset',
15304
- options: value,
15529
+ options,
15305
15530
  async fn(state) {
15306
15531
  const {
15307
15532
  x,
15308
15533
  y
15309
15534
  } = state;
15310
- const diffCoords = await convertValueToCoords(state, value);
15535
+ const diffCoords = await convertValueToCoords(state, options);
15311
15536
  return {
15312
15537
  x: x + diffCoords.x,
15313
15538
  y: y + diffCoords.y,
@@ -15317,10 +15542,6 @@ const offset = function (value) {
15317
15542
  };
15318
15543
  };
15319
15544
 
15320
- function getCrossAxis(axis) {
15321
- return axis === 'x' ? 'y' : 'x';
15322
- }
15323
-
15324
15545
  /**
15325
15546
  * Optimizes the visibility of the floating element by shifting it in order to
15326
15547
  * keep it in view when it will overflow the clipping boundary.
@@ -15355,14 +15576,14 @@ const shift = function (options) {
15355
15576
  }
15356
15577
  },
15357
15578
  ...detectOverflowOptions
15358
- } = options;
15579
+ } = evaluate(options, state);
15359
15580
  const coords = {
15360
15581
  x,
15361
15582
  y
15362
15583
  };
15363
15584
  const overflow = await detectOverflow(state, detectOverflowOptions);
15364
- const mainAxis = getMainAxisFromPlacement(getSide(placement));
15365
- const crossAxis = getCrossAxis(mainAxis);
15585
+ const crossAxis = getSideAxis(getSide(placement));
15586
+ const mainAxis = getOppositeAxis(crossAxis);
15366
15587
  let mainAxisCoord = coords[mainAxis];
15367
15588
  let crossAxisCoord = coords[crossAxis];
15368
15589
  if (checkMainAxis) {
@@ -15370,14 +15591,14 @@ const shift = function (options) {
15370
15591
  const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
15371
15592
  const min = mainAxisCoord + overflow[minSide];
15372
15593
  const max = mainAxisCoord - overflow[maxSide];
15373
- mainAxisCoord = within(min, mainAxisCoord, max);
15594
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
15374
15595
  }
15375
15596
  if (checkCrossAxis) {
15376
15597
  const minSide = crossAxis === 'y' ? 'top' : 'left';
15377
15598
  const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
15378
15599
  const min = crossAxisCoord + overflow[minSide];
15379
15600
  const max = crossAxisCoord - overflow[maxSide];
15380
- crossAxisCoord = within(min, crossAxisCoord, max);
15601
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
15381
15602
  }
15382
15603
  const limitedCoords = limiter.fn({
15383
15604
  ...state,
@@ -15418,12 +15639,11 @@ const size = function (options) {
15418
15639
  const {
15419
15640
  apply = () => {},
15420
15641
  ...detectOverflowOptions
15421
- } = options;
15642
+ } = evaluate(options, state);
15422
15643
  const overflow = await detectOverflow(state, detectOverflowOptions);
15423
15644
  const side = getSide(placement);
15424
15645
  const alignment = getAlignment(placement);
15425
- const axis = getMainAxisFromPlacement(placement);
15426
- const isXAxis = axis === 'x';
15646
+ const isYAxis = getSideAxis(placement) === 'y';
15427
15647
  const {
15428
15648
  width,
15429
15649
  height
@@ -15439,26 +15659,25 @@ const size = function (options) {
15439
15659
  }
15440
15660
  const overflowAvailableHeight = height - overflow[heightSide];
15441
15661
  const overflowAvailableWidth = width - overflow[widthSide];
15662
+ const noShift = !state.middlewareData.shift;
15442
15663
  let availableHeight = overflowAvailableHeight;
15443
15664
  let availableWidth = overflowAvailableWidth;
15444
- if (isXAxis) {
15445
- availableWidth = min$1(
15446
- // Maximum clipping viewport width
15447
- width - overflow.right - overflow.left, overflowAvailableWidth);
15665
+ if (isYAxis) {
15666
+ const maximumClippingWidth = width - overflow.left - overflow.right;
15667
+ availableWidth = alignment || noShift ? min(overflowAvailableWidth, maximumClippingWidth) : maximumClippingWidth;
15448
15668
  } else {
15449
- availableHeight = min$1(
15450
- // Maximum clipping viewport height
15451
- height - overflow.bottom - overflow.top, overflowAvailableHeight);
15452
- }
15453
- if (!state.middlewareData.shift && !alignment) {
15454
- const xMin = max$1(overflow.left, 0);
15455
- const xMax = max$1(overflow.right, 0);
15456
- const yMin = max$1(overflow.top, 0);
15457
- const yMax = max$1(overflow.bottom, 0);
15458
- if (isXAxis) {
15459
- availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max$1(overflow.left, overflow.right));
15669
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
15670
+ availableHeight = alignment || noShift ? min(overflowAvailableHeight, maximumClippingHeight) : maximumClippingHeight;
15671
+ }
15672
+ if (noShift && !alignment) {
15673
+ const xMin = max(overflow.left, 0);
15674
+ const xMax = max(overflow.right, 0);
15675
+ const yMin = max(overflow.top, 0);
15676
+ const yMax = max(overflow.bottom, 0);
15677
+ if (isYAxis) {
15678
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
15460
15679
  } else {
15461
- availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max$1(overflow.top, overflow.bottom));
15680
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
15462
15681
  }
15463
15682
  }
15464
15683
  await apply({
@@ -15479,106 +15698,13 @@ const size = function (options) {
15479
15698
  };
15480
15699
  };
15481
15700
 
15482
- function getWindow$1(node) {
15483
- var _node$ownerDocument;
15484
- return ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
15485
- }
15486
-
15487
- function getComputedStyle$1(element) {
15488
- return getWindow$1(element).getComputedStyle(element);
15489
- }
15490
-
15491
- function isNode(value) {
15492
- return value instanceof getWindow$1(value).Node;
15493
- }
15494
- function getNodeName(node) {
15495
- return isNode(node) ? (node.nodeName || '').toLowerCase() : '';
15496
- }
15497
-
15498
- let uaString;
15499
- function getUAString() {
15500
- if (uaString) {
15501
- return uaString;
15502
- }
15503
- const uaData = navigator.userAgentData;
15504
- if (uaData && Array.isArray(uaData.brands)) {
15505
- uaString = uaData.brands.map(item => item.brand + "/" + item.version).join(' ');
15506
- return uaString;
15507
- }
15508
- return navigator.userAgent;
15509
- }
15510
-
15511
- function isHTMLElement$1(value) {
15512
- return value instanceof getWindow$1(value).HTMLElement;
15513
- }
15514
- function isElement$1(value) {
15515
- return value instanceof getWindow$1(value).Element;
15516
- }
15517
- function isShadowRoot$1(node) {
15518
- // Browsers without `ShadowRoot` support.
15519
- if (typeof ShadowRoot === 'undefined') {
15520
- return false;
15521
- }
15522
- const OwnElement = getWindow$1(node).ShadowRoot;
15523
- return node instanceof OwnElement || node instanceof ShadowRoot;
15524
- }
15525
- function isOverflowElement(element) {
15526
- const {
15527
- overflow,
15528
- overflowX,
15529
- overflowY,
15530
- display
15531
- } = getComputedStyle$1(element);
15532
- return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
15533
- }
15534
- function isTableElement(element) {
15535
- return ['table', 'td', 'th'].includes(getNodeName(element));
15536
- }
15537
- function isContainingBlock(element) {
15538
- // TODO: Try to use feature detection here instead.
15539
- const isFirefox = /firefox/i.test(getUAString());
15540
- const css = getComputedStyle$1(element);
15541
- const backdropFilter = css.backdropFilter || css.WebkitBackdropFilter;
15542
-
15543
- // This is non-exhaustive but covers the most common CSS properties that
15544
- // create a containing block.
15545
- // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
15546
- return css.transform !== 'none' || css.perspective !== 'none' || (backdropFilter ? backdropFilter !== 'none' : false) || isFirefox && css.willChange === 'filter' || isFirefox && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective'].some(value => css.willChange.includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => {
15547
- // Add type check for old browsers.
15548
- const contain = css.contain;
15549
- return contain != null ? contain.includes(value) : false;
15550
- });
15551
- }
15552
-
15553
- /**
15554
- * Determines whether or not `.getBoundingClientRect()` is affected by visual
15555
- * viewport offsets. In Safari, the `x`/`y` offsets are values relative to the
15556
- * visual viewport, while in other engines, they are values relative to the
15557
- * layout viewport.
15558
- */
15559
- function isClientRectVisualViewportBased() {
15560
- // TODO: Try to use feature detection here instead. Feature detection for
15561
- // this can fail in various ways, making the userAgent check the most
15562
- // reliable:
15563
- // • Always-visible scrollbar or not
15564
- // • Width of <html>
15565
-
15566
- // Is Safari.
15567
- return /^((?!chrome|android).)*safari/i.test(getUAString());
15568
- }
15569
- function isLastTraversableNode(node) {
15570
- return ['html', 'body', '#document'].includes(getNodeName(node));
15571
- }
15572
-
15573
- const min = Math.min;
15574
- const max = Math.max;
15575
- const round = Math.round;
15576
-
15577
15701
  function getCssDimensions(element) {
15578
15702
  const css = getComputedStyle$1(element);
15579
- let width = parseFloat(css.width);
15580
- let height = parseFloat(css.height);
15581
- const hasOffset = isHTMLElement$1(element);
15703
+ // In testing environments, the `width` and `height` properties are empty
15704
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
15705
+ let width = parseFloat(css.width) || 0;
15706
+ let height = parseFloat(css.height) || 0;
15707
+ const hasOffset = isHTMLElement(element);
15582
15708
  const offsetWidth = hasOffset ? element.offsetWidth : width;
15583
15709
  const offsetHeight = hasOffset ? element.offsetHeight : height;
15584
15710
  const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
@@ -15589,31 +15715,27 @@ function getCssDimensions(element) {
15589
15715
  return {
15590
15716
  width,
15591
15717
  height,
15592
- fallback: shouldFallback
15718
+ $: shouldFallback
15593
15719
  };
15594
15720
  }
15595
15721
 
15596
15722
  function unwrapElement(element) {
15597
- return !isElement$1(element) ? element.contextElement : element;
15723
+ return !isElement(element) ? element.contextElement : element;
15598
15724
  }
15599
15725
 
15600
- const FALLBACK_SCALE = {
15601
- x: 1,
15602
- y: 1
15603
- };
15604
15726
  function getScale(element) {
15605
15727
  const domElement = unwrapElement(element);
15606
- if (!isHTMLElement$1(domElement)) {
15607
- return FALLBACK_SCALE;
15728
+ if (!isHTMLElement(domElement)) {
15729
+ return createCoords(1);
15608
15730
  }
15609
15731
  const rect = domElement.getBoundingClientRect();
15610
15732
  const {
15611
15733
  width,
15612
15734
  height,
15613
- fallback
15735
+ $
15614
15736
  } = getCssDimensions(domElement);
15615
- let x = (fallback ? round(rect.width) : rect.width) / width;
15616
- let y = (fallback ? round(rect.height) : rect.height) / height;
15737
+ let x = ($ ? round(rect.width) : rect.width) / width;
15738
+ let y = ($ ? round(rect.height) : rect.height) / height;
15617
15739
 
15618
15740
  // 0, NaN, or Infinity should always fallback to 1.
15619
15741
 
@@ -15629,8 +15751,28 @@ function getScale(element) {
15629
15751
  };
15630
15752
  }
15631
15753
 
15754
+ const noOffsets = /*#__PURE__*/createCoords(0);
15755
+ function getVisualOffsets(element) {
15756
+ const win = getWindow(element);
15757
+ if (!isWebKit() || !win.visualViewport) {
15758
+ return noOffsets;
15759
+ }
15760
+ return {
15761
+ x: win.visualViewport.offsetLeft,
15762
+ y: win.visualViewport.offsetTop
15763
+ };
15764
+ }
15765
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
15766
+ if (isFixed === void 0) {
15767
+ isFixed = false;
15768
+ }
15769
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
15770
+ return false;
15771
+ }
15772
+ return isFixed;
15773
+ }
15774
+
15632
15775
  function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
15633
- var _win$visualViewport, _win$visualViewport2;
15634
15776
  if (includeScale === void 0) {
15635
15777
  includeScale = false;
15636
15778
  }
@@ -15639,39 +15781,38 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
15639
15781
  }
15640
15782
  const clientRect = element.getBoundingClientRect();
15641
15783
  const domElement = unwrapElement(element);
15642
- let scale = FALLBACK_SCALE;
15784
+ let scale = createCoords(1);
15643
15785
  if (includeScale) {
15644
15786
  if (offsetParent) {
15645
- if (isElement$1(offsetParent)) {
15787
+ if (isElement(offsetParent)) {
15646
15788
  scale = getScale(offsetParent);
15647
15789
  }
15648
15790
  } else {
15649
15791
  scale = getScale(element);
15650
15792
  }
15651
15793
  }
15652
- const win = domElement ? getWindow$1(domElement) : window;
15653
- const addVisualOffsets = isClientRectVisualViewportBased() && isFixedStrategy;
15654
- let x = (clientRect.left + (addVisualOffsets ? ((_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) || 0 : 0)) / scale.x;
15655
- let y = (clientRect.top + (addVisualOffsets ? ((_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) || 0 : 0)) / scale.y;
15794
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
15795
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
15796
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
15656
15797
  let width = clientRect.width / scale.x;
15657
15798
  let height = clientRect.height / scale.y;
15658
15799
  if (domElement) {
15659
- const win = getWindow$1(domElement);
15660
- const offsetWin = offsetParent && isElement$1(offsetParent) ? getWindow$1(offsetParent) : offsetParent;
15800
+ const win = getWindow(domElement);
15801
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
15661
15802
  let currentIFrame = win.frameElement;
15662
15803
  while (currentIFrame && offsetParent && offsetWin !== win) {
15663
15804
  const iframeScale = getScale(currentIFrame);
15664
15805
  const iframeRect = currentIFrame.getBoundingClientRect();
15665
- const css = getComputedStyle(currentIFrame);
15666
- iframeRect.x += (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
15667
- iframeRect.y += (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
15806
+ const css = getComputedStyle$1(currentIFrame);
15807
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
15808
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
15668
15809
  x *= iframeScale.x;
15669
15810
  y *= iframeScale.y;
15670
15811
  width *= iframeScale.x;
15671
15812
  height *= iframeScale.y;
15672
- x += iframeRect.x;
15673
- y += iframeRect.y;
15674
- currentIFrame = getWindow$1(currentIFrame).frameElement;
15813
+ x += left;
15814
+ y += top;
15815
+ currentIFrame = getWindow(currentIFrame).frameElement;
15675
15816
  }
15676
15817
  }
15677
15818
  return rectToClientRect({
@@ -15682,30 +15823,13 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
15682
15823
  });
15683
15824
  }
15684
15825
 
15685
- function getDocumentElement(node) {
15686
- return ((isNode(node) ? node.ownerDocument : node.document) || window.document).documentElement;
15687
- }
15688
-
15689
- function getNodeScroll(element) {
15690
- if (isElement$1(element)) {
15691
- return {
15692
- scrollLeft: element.scrollLeft,
15693
- scrollTop: element.scrollTop
15694
- };
15695
- }
15696
- return {
15697
- scrollLeft: element.pageXOffset,
15698
- scrollTop: element.pageYOffset
15699
- };
15700
- }
15701
-
15702
15826
  function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
15703
15827
  let {
15704
15828
  rect,
15705
15829
  offsetParent,
15706
15830
  strategy
15707
15831
  } = _ref;
15708
- const isOffsetParentAnElement = isHTMLElement$1(offsetParent);
15832
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
15709
15833
  const documentElement = getDocumentElement(offsetParent);
15710
15834
  if (offsetParent === documentElement) {
15711
15835
  return rect;
@@ -15714,19 +15838,13 @@ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
15714
15838
  scrollLeft: 0,
15715
15839
  scrollTop: 0
15716
15840
  };
15717
- let scale = {
15718
- x: 1,
15719
- y: 1
15720
- };
15721
- const offsets = {
15722
- x: 0,
15723
- y: 0
15724
- };
15841
+ let scale = createCoords(1);
15842
+ const offsets = createCoords(0);
15725
15843
  if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
15726
15844
  if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
15727
15845
  scroll = getNodeScroll(offsetParent);
15728
15846
  }
15729
- if (isHTMLElement$1(offsetParent)) {
15847
+ if (isHTMLElement(offsetParent)) {
15730
15848
  const offsetRect = getBoundingClientRect(offsetParent);
15731
15849
  scale = getScale(offsetParent);
15732
15850
  offsets.x = offsetRect.x + offsetParent.clientLeft;
@@ -15741,6 +15859,10 @@ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
15741
15859
  };
15742
15860
  }
15743
15861
 
15862
+ function getClientRects(element) {
15863
+ return Array.from(element.getClientRects());
15864
+ }
15865
+
15744
15866
  function getWindowScrollBarX(element) {
15745
15867
  // If <html> has a CSS width greater than the viewport, then this will be
15746
15868
  // incorrect for RTL.
@@ -15768,51 +15890,8 @@ function getDocumentRect(element) {
15768
15890
  };
15769
15891
  }
15770
15892
 
15771
- function getParentNode(node) {
15772
- if (getNodeName(node) === 'html') {
15773
- return node;
15774
- }
15775
- const result =
15776
- // Step into the shadow DOM of the parent of a slotted node.
15777
- node.assignedSlot ||
15778
- // DOM Element detected.
15779
- node.parentNode ||
15780
- // ShadowRoot detected.
15781
- isShadowRoot$1(node) && node.host ||
15782
- // Fallback.
15783
- getDocumentElement(node);
15784
- return isShadowRoot$1(result) ? result.host : result;
15785
- }
15786
-
15787
- function getNearestOverflowAncestor(node) {
15788
- const parentNode = getParentNode(node);
15789
- if (isLastTraversableNode(parentNode)) {
15790
- // `getParentNode` will never return a `Document` due to the fallback
15791
- // check, so it's either the <html> or <body> element.
15792
- return parentNode.ownerDocument.body;
15793
- }
15794
- if (isHTMLElement$1(parentNode) && isOverflowElement(parentNode)) {
15795
- return parentNode;
15796
- }
15797
- return getNearestOverflowAncestor(parentNode);
15798
- }
15799
-
15800
- function getOverflowAncestors(node, list) {
15801
- var _node$ownerDocument;
15802
- if (list === void 0) {
15803
- list = [];
15804
- }
15805
- const scrollableAncestor = getNearestOverflowAncestor(node);
15806
- const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
15807
- const win = getWindow$1(scrollableAncestor);
15808
- if (isBody) {
15809
- return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
15810
- }
15811
- return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor));
15812
- }
15813
-
15814
15893
  function getViewportRect(element, strategy) {
15815
- const win = getWindow$1(element);
15894
+ const win = getWindow(element);
15816
15895
  const html = getDocumentElement(element);
15817
15896
  const visualViewport = win.visualViewport;
15818
15897
  let width = html.clientWidth;
@@ -15822,7 +15901,7 @@ function getViewportRect(element, strategy) {
15822
15901
  if (visualViewport) {
15823
15902
  width = visualViewport.width;
15824
15903
  height = visualViewport.height;
15825
- const visualViewportBased = isClientRectVisualViewportBased();
15904
+ const visualViewportBased = isWebKit();
15826
15905
  if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
15827
15906
  x = visualViewport.offsetLeft;
15828
15907
  y = visualViewport.offsetTop;
@@ -15841,10 +15920,7 @@ function getInnerBoundingClientRect(element, strategy) {
15841
15920
  const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
15842
15921
  const top = clientRect.top + element.clientTop;
15843
15922
  const left = clientRect.left + element.clientLeft;
15844
- const scale = isHTMLElement$1(element) ? getScale(element) : {
15845
- x: 1,
15846
- y: 1
15847
- };
15923
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
15848
15924
  const width = element.clientWidth * scale.x;
15849
15925
  const height = element.clientHeight * scale.y;
15850
15926
  const x = left * scale.x;
@@ -15862,22 +15938,25 @@ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy)
15862
15938
  rect = getViewportRect(element, strategy);
15863
15939
  } else if (clippingAncestor === 'document') {
15864
15940
  rect = getDocumentRect(getDocumentElement(element));
15865
- } else if (isElement$1(clippingAncestor)) {
15941
+ } else if (isElement(clippingAncestor)) {
15866
15942
  rect = getInnerBoundingClientRect(clippingAncestor, strategy);
15867
15943
  } else {
15868
- const mutableRect = {
15869
- ...clippingAncestor
15944
+ const visualOffsets = getVisualOffsets(element);
15945
+ rect = {
15946
+ ...clippingAncestor,
15947
+ x: clippingAncestor.x - visualOffsets.x,
15948
+ y: clippingAncestor.y - visualOffsets.y
15870
15949
  };
15871
- if (isClientRectVisualViewportBased()) {
15872
- var _win$visualViewport, _win$visualViewport2;
15873
- const win = getWindow$1(element);
15874
- mutableRect.x -= ((_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) || 0;
15875
- mutableRect.y -= ((_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) || 0;
15876
- }
15877
- rect = mutableRect;
15878
15950
  }
15879
15951
  return rectToClientRect(rect);
15880
15952
  }
15953
+ function hasFixedPositionAncestor(element, stopNode) {
15954
+ const parentNode = getParentNode(element);
15955
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
15956
+ return false;
15957
+ }
15958
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
15959
+ }
15881
15960
 
15882
15961
  // A "clipping ancestor" is an `overflow` element with the characteristic of
15883
15962
  // clipping (or hiding) child elements. This returns all clipping ancestors
@@ -15887,27 +15966,25 @@ function getClippingElementAncestors(element, cache) {
15887
15966
  if (cachedResult) {
15888
15967
  return cachedResult;
15889
15968
  }
15890
- let result = getOverflowAncestors(element).filter(el => isElement$1(el) && getNodeName(el) !== 'body');
15969
+ let result = getOverflowAncestors(element).filter(el => isElement(el) && getNodeName(el) !== 'body');
15891
15970
  let currentContainingBlockComputedStyle = null;
15892
15971
  const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
15893
15972
  let currentNode = elementIsFixed ? getParentNode(element) : element;
15894
15973
 
15895
15974
  // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
15896
- while (isElement$1(currentNode) && !isLastTraversableNode(currentNode)) {
15975
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
15897
15976
  const computedStyle = getComputedStyle$1(currentNode);
15898
- const containingBlock = isContainingBlock(currentNode);
15899
- const shouldIgnoreCurrentNode = computedStyle.position === 'fixed';
15900
- if (shouldIgnoreCurrentNode) {
15977
+ const currentNodeIsContaining = isContainingBlock(currentNode);
15978
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
15901
15979
  currentContainingBlockComputedStyle = null;
15980
+ }
15981
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
15982
+ if (shouldDropCurrentNode) {
15983
+ // Drop non-containing blocks.
15984
+ result = result.filter(ancestor => ancestor !== currentNode);
15902
15985
  } else {
15903
- const shouldDropCurrentNode = elementIsFixed ? !containingBlock && !currentContainingBlockComputedStyle : !containingBlock && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position);
15904
- if (shouldDropCurrentNode) {
15905
- // Drop non-containing blocks.
15906
- result = result.filter(ancestor => ancestor !== currentNode);
15907
- } else {
15908
- // Record last containing block for next iteration.
15909
- currentContainingBlockComputedStyle = computedStyle;
15910
- }
15986
+ // Record last containing block for next iteration.
15987
+ currentContainingBlockComputedStyle = computedStyle;
15911
15988
  }
15912
15989
  currentNode = getParentNode(currentNode);
15913
15990
  }
@@ -15947,8 +16024,38 @@ function getDimensions(element) {
15947
16024
  return getCssDimensions(element);
15948
16025
  }
15949
16026
 
16027
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
16028
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
16029
+ const documentElement = getDocumentElement(offsetParent);
16030
+ const isFixed = strategy === 'fixed';
16031
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
16032
+ let scroll = {
16033
+ scrollLeft: 0,
16034
+ scrollTop: 0
16035
+ };
16036
+ const offsets = createCoords(0);
16037
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
16038
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
16039
+ scroll = getNodeScroll(offsetParent);
16040
+ }
16041
+ if (isOffsetParentAnElement) {
16042
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
16043
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
16044
+ offsets.y = offsetRect.y + offsetParent.clientTop;
16045
+ } else if (documentElement) {
16046
+ offsets.x = getWindowScrollBarX(documentElement);
16047
+ }
16048
+ }
16049
+ return {
16050
+ x: rect.left + scroll.scrollLeft - offsets.x,
16051
+ y: rect.top + scroll.scrollTop - offsets.y,
16052
+ width: rect.width,
16053
+ height: rect.height
16054
+ };
16055
+ }
16056
+
15950
16057
  function getTrueOffsetParent(element, polyfill) {
15951
- if (!isHTMLElement$1(element) || getComputedStyle$1(element).position === 'fixed') {
16058
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
15952
16059
  return null;
15953
16060
  }
15954
16061
  if (polyfill) {
@@ -15956,23 +16063,12 @@ function getTrueOffsetParent(element, polyfill) {
15956
16063
  }
15957
16064
  return element.offsetParent;
15958
16065
  }
15959
- function getContainingBlock(element) {
15960
- let currentNode = getParentNode(element);
15961
- while (isHTMLElement$1(currentNode) && !isLastTraversableNode(currentNode)) {
15962
- if (isContainingBlock(currentNode)) {
15963
- return currentNode;
15964
- } else {
15965
- currentNode = getParentNode(currentNode);
15966
- }
15967
- }
15968
- return null;
15969
- }
15970
16066
 
15971
16067
  // Gets the closest ancestor positioned element. Handles some edge cases,
15972
16068
  // such as table ancestors and cross browser bugs.
15973
16069
  function getOffsetParent(element, polyfill) {
15974
- const window = getWindow$1(element);
15975
- if (!isHTMLElement$1(element)) {
16070
+ const window = getWindow(element);
16071
+ if (!isHTMLElement(element)) {
15976
16072
  return window;
15977
16073
  }
15978
16074
  let offsetParent = getTrueOffsetParent(element, polyfill);
@@ -15985,67 +16081,115 @@ function getOffsetParent(element, polyfill) {
15985
16081
  return offsetParent || getContainingBlock(element) || window;
15986
16082
  }
15987
16083
 
15988
- function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
15989
- const isOffsetParentAnElement = isHTMLElement$1(offsetParent);
15990
- const documentElement = getDocumentElement(offsetParent);
15991
- const rect = getBoundingClientRect(element, true, strategy === 'fixed', offsetParent);
15992
- let scroll = {
15993
- scrollLeft: 0,
15994
- scrollTop: 0
15995
- };
15996
- const offsets = {
15997
- x: 0,
15998
- y: 0
15999
- };
16000
- if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
16001
- if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
16002
- scroll = getNodeScroll(offsetParent);
16003
- }
16004
- if (isHTMLElement$1(offsetParent)) {
16005
- const offsetRect = getBoundingClientRect(offsetParent, true);
16006
- offsets.x = offsetRect.x + offsetParent.clientLeft;
16007
- offsets.y = offsetRect.y + offsetParent.clientTop;
16008
- } else if (documentElement) {
16009
- offsets.x = getWindowScrollBarX(documentElement);
16010
- }
16011
- }
16084
+ const getElementRects = async function (_ref) {
16085
+ let {
16086
+ reference,
16087
+ floating,
16088
+ strategy
16089
+ } = _ref;
16090
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
16091
+ const getDimensionsFn = this.getDimensions;
16012
16092
  return {
16013
- x: rect.left + scroll.scrollLeft - offsets.x,
16014
- y: rect.top + scroll.scrollTop - offsets.y,
16015
- width: rect.width,
16016
- height: rect.height
16093
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
16094
+ floating: {
16095
+ x: 0,
16096
+ y: 0,
16097
+ ...(await getDimensionsFn(floating))
16098
+ }
16017
16099
  };
16100
+ };
16101
+
16102
+ function isRTL(element) {
16103
+ return getComputedStyle$1(element).direction === 'rtl';
16018
16104
  }
16019
16105
 
16020
16106
  const platform = {
16021
- getClippingRect,
16022
16107
  convertOffsetParentRelativeRectToViewportRelativeRect,
16023
- isElement: isElement$1,
16024
- getDimensions,
16025
- getOffsetParent,
16026
16108
  getDocumentElement,
16109
+ getClippingRect,
16110
+ getOffsetParent,
16111
+ getElementRects,
16112
+ getClientRects,
16113
+ getDimensions,
16027
16114
  getScale,
16028
- async getElementRects(_ref) {
16029
- let {
16030
- reference,
16031
- floating,
16032
- strategy
16033
- } = _ref;
16034
- const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
16035
- const getDimensionsFn = this.getDimensions;
16036
- return {
16037
- reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
16038
- floating: {
16039
- x: 0,
16040
- y: 0,
16041
- ...(await getDimensionsFn(floating))
16042
- }
16043
- };
16044
- },
16045
- getClientRects: element => Array.from(element.getClientRects()),
16046
- isRTL: element => getComputedStyle$1(element).direction === 'rtl'
16115
+ isElement,
16116
+ isRTL
16047
16117
  };
16048
16118
 
16119
+ // https://samthor.au/2021/observing-dom/
16120
+ function observeMove(element, onMove) {
16121
+ let io = null;
16122
+ let timeoutId;
16123
+ const root = getDocumentElement(element);
16124
+ function cleanup() {
16125
+ clearTimeout(timeoutId);
16126
+ io && io.disconnect();
16127
+ io = null;
16128
+ }
16129
+ function refresh(skip, threshold) {
16130
+ if (skip === void 0) {
16131
+ skip = false;
16132
+ }
16133
+ if (threshold === void 0) {
16134
+ threshold = 1;
16135
+ }
16136
+ cleanup();
16137
+ const {
16138
+ left,
16139
+ top,
16140
+ width,
16141
+ height
16142
+ } = element.getBoundingClientRect();
16143
+ if (!skip) {
16144
+ onMove();
16145
+ }
16146
+ if (!width || !height) {
16147
+ return;
16148
+ }
16149
+ const insetTop = floor(top);
16150
+ const insetRight = floor(root.clientWidth - (left + width));
16151
+ const insetBottom = floor(root.clientHeight - (top + height));
16152
+ const insetLeft = floor(left);
16153
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
16154
+ const options = {
16155
+ rootMargin,
16156
+ threshold: max(0, min(1, threshold)) || 1
16157
+ };
16158
+ let isFirstUpdate = true;
16159
+ function handleObserve(entries) {
16160
+ const ratio = entries[0].intersectionRatio;
16161
+ if (ratio !== threshold) {
16162
+ if (!isFirstUpdate) {
16163
+ return refresh();
16164
+ }
16165
+ if (!ratio) {
16166
+ timeoutId = setTimeout(() => {
16167
+ refresh(false, 1e-7);
16168
+ }, 100);
16169
+ } else {
16170
+ refresh(false, ratio);
16171
+ }
16172
+ }
16173
+ isFirstUpdate = false;
16174
+ }
16175
+
16176
+ // Older browsers don't support a `document` as the root and will throw an
16177
+ // error.
16178
+ try {
16179
+ io = new IntersectionObserver(handleObserve, {
16180
+ ...options,
16181
+ // Handle <iframe>s
16182
+ root: root.ownerDocument
16183
+ });
16184
+ } catch (e) {
16185
+ io = new IntersectionObserver(handleObserve, options);
16186
+ }
16187
+ io.observe(element);
16188
+ }
16189
+ refresh(true);
16190
+ return cleanup;
16191
+ }
16192
+
16049
16193
  /**
16050
16194
  * Automatically updates the position of the floating element when necessary.
16051
16195
  * Should only be called when the floating element is mounted on the DOM or
@@ -16059,29 +16203,41 @@ function autoUpdate(reference, floating, update, options) {
16059
16203
  options = {};
16060
16204
  }
16061
16205
  const {
16062
- ancestorScroll: _ancestorScroll = true,
16206
+ ancestorScroll = true,
16063
16207
  ancestorResize = true,
16064
- elementResize = true,
16208
+ elementResize = typeof ResizeObserver === 'function',
16209
+ layoutShift = typeof IntersectionObserver === 'function',
16065
16210
  animationFrame = false
16066
16211
  } = options;
16067
- const ancestorScroll = _ancestorScroll && !animationFrame;
16068
- const ancestors = ancestorScroll || ancestorResize ? [...(isElement$1(reference) ? getOverflowAncestors(reference) : reference.contextElement ? getOverflowAncestors(reference.contextElement) : []), ...getOverflowAncestors(floating)] : [];
16212
+ const referenceEl = unwrapElement(reference);
16213
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
16069
16214
  ancestors.forEach(ancestor => {
16070
16215
  ancestorScroll && ancestor.addEventListener('scroll', update, {
16071
16216
  passive: true
16072
16217
  });
16073
16218
  ancestorResize && ancestor.addEventListener('resize', update);
16074
16219
  });
16075
- let observer = null;
16220
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
16221
+ let reobserveFrame = -1;
16222
+ let resizeObserver = null;
16076
16223
  if (elementResize) {
16077
- observer = new ResizeObserver(() => {
16224
+ resizeObserver = new ResizeObserver(_ref => {
16225
+ let [firstEntry] = _ref;
16226
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
16227
+ // Prevent update loops when using the `size` middleware.
16228
+ // https://github.com/floating-ui/floating-ui/issues/1740
16229
+ resizeObserver.unobserve(floating);
16230
+ cancelAnimationFrame(reobserveFrame);
16231
+ reobserveFrame = requestAnimationFrame(() => {
16232
+ resizeObserver && resizeObserver.observe(floating);
16233
+ });
16234
+ }
16078
16235
  update();
16079
16236
  });
16080
- isElement$1(reference) && !animationFrame && observer.observe(reference);
16081
- if (!isElement$1(reference) && reference.contextElement && !animationFrame) {
16082
- observer.observe(reference.contextElement);
16237
+ if (referenceEl && !animationFrame) {
16238
+ resizeObserver.observe(referenceEl);
16083
16239
  }
16084
- observer.observe(floating);
16240
+ resizeObserver.observe(floating);
16085
16241
  }
16086
16242
  let frameId;
16087
16243
  let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
@@ -16098,13 +16254,13 @@ function autoUpdate(reference, floating, update, options) {
16098
16254
  }
16099
16255
  update();
16100
16256
  return () => {
16101
- var _observer;
16102
16257
  ancestors.forEach(ancestor => {
16103
16258
  ancestorScroll && ancestor.removeEventListener('scroll', update);
16104
16259
  ancestorResize && ancestor.removeEventListener('resize', update);
16105
16260
  });
16106
- (_observer = observer) == null ? void 0 : _observer.disconnect();
16107
- observer = null;
16261
+ cleanupIo && cleanupIo();
16262
+ resizeObserver && resizeObserver.disconnect();
16263
+ resizeObserver = null;
16108
16264
  if (animationFrame) {
16109
16265
  cancelAnimationFrame(frameId);
16110
16266
  }
@@ -16167,7 +16323,7 @@ function deepEqual(a, b) {
16167
16323
  return false;
16168
16324
  }
16169
16325
  for (i = length; i-- !== 0;) {
16170
- if (!Object.prototype.hasOwnProperty.call(b, keys[i])) {
16326
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
16171
16327
  return false;
16172
16328
  }
16173
16329
  }
@@ -16185,6 +16341,19 @@ function deepEqual(a, b) {
16185
16341
  return a !== a && b !== b;
16186
16342
  }
16187
16343
 
16344
+ function getDPR(element) {
16345
+ if (typeof window === 'undefined') {
16346
+ return 1;
16347
+ }
16348
+ const win = element.ownerDocument.defaultView || window;
16349
+ return win.devicePixelRatio || 1;
16350
+ }
16351
+
16352
+ function roundByDPR(element, value) {
16353
+ const dpr = getDPR(element);
16354
+ return Math.round(value * dpr) / dpr;
16355
+ }
16356
+
16188
16357
  function useLatestRef$1(value) {
16189
16358
  const ref = React.useRef(value);
16190
16359
  index$1(() => {
@@ -16206,12 +16375,17 @@ function useFloating$1(options) {
16206
16375
  strategy = 'absolute',
16207
16376
  middleware = [],
16208
16377
  platform,
16378
+ elements: {
16379
+ reference: externalReference,
16380
+ floating: externalFloating
16381
+ } = {},
16382
+ transform = true,
16209
16383
  whileElementsMounted,
16210
16384
  open
16211
16385
  } = options;
16212
16386
  const [data, setData] = React.useState({
16213
- x: null,
16214
- y: null,
16387
+ x: 0,
16388
+ y: 0,
16215
16389
  strategy,
16216
16390
  placement,
16217
16391
  middlewareData: {},
@@ -16221,25 +16395,27 @@ function useFloating$1(options) {
16221
16395
  if (!deepEqual(latestMiddleware, middleware)) {
16222
16396
  setLatestMiddleware(middleware);
16223
16397
  }
16224
- const referenceRef = React.useRef(null);
16225
- const floatingRef = React.useRef(null);
16226
- const dataRef = React.useRef(data);
16227
- const whileElementsMountedRef = useLatestRef$1(whileElementsMounted);
16228
- const platformRef = useLatestRef$1(platform);
16229
- const [reference, _setReference] = React.useState(null);
16230
- const [floating, _setFloating] = React.useState(null);
16398
+ const [_reference, _setReference] = React.useState(null);
16399
+ const [_floating, _setFloating] = React.useState(null);
16231
16400
  const setReference = React.useCallback(node => {
16232
- if (referenceRef.current !== node) {
16401
+ if (node != referenceRef.current) {
16233
16402
  referenceRef.current = node;
16234
16403
  _setReference(node);
16235
16404
  }
16236
- }, []);
16405
+ }, [_setReference]);
16237
16406
  const setFloating = React.useCallback(node => {
16238
- if (floatingRef.current !== node) {
16407
+ if (node !== floatingRef.current) {
16239
16408
  floatingRef.current = node;
16240
16409
  _setFloating(node);
16241
16410
  }
16242
- }, []);
16411
+ }, [_setFloating]);
16412
+ const referenceEl = externalReference || _reference;
16413
+ const floatingEl = externalFloating || _floating;
16414
+ const referenceRef = React.useRef(null);
16415
+ const floatingRef = React.useRef(null);
16416
+ const dataRef = React.useRef(data);
16417
+ const whileElementsMountedRef = useLatestRef$1(whileElementsMounted);
16418
+ const platformRef = useLatestRef$1(platform);
16243
16419
  const update = React.useCallback(() => {
16244
16420
  if (!referenceRef.current || !floatingRef.current) {
16245
16421
  return;
@@ -16282,14 +16458,16 @@ function useFloating$1(options) {
16282
16458
  };
16283
16459
  }, []);
16284
16460
  index$1(() => {
16285
- if (reference && floating) {
16461
+ if (referenceEl) referenceRef.current = referenceEl;
16462
+ if (floatingEl) floatingRef.current = floatingEl;
16463
+ if (referenceEl && floatingEl) {
16286
16464
  if (whileElementsMountedRef.current) {
16287
- return whileElementsMountedRef.current(reference, floating, update);
16465
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
16288
16466
  } else {
16289
16467
  update();
16290
16468
  }
16291
16469
  }
16292
- }, [reference, floating, update, whileElementsMountedRef]);
16470
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef]);
16293
16471
  const refs = React.useMemo(() => ({
16294
16472
  reference: referenceRef,
16295
16473
  floating: floatingRef,
@@ -16297,147 +16475,44 @@ function useFloating$1(options) {
16297
16475
  setFloating
16298
16476
  }), [setReference, setFloating]);
16299
16477
  const elements = React.useMemo(() => ({
16300
- reference,
16301
- floating
16302
- }), [reference, floating]);
16478
+ reference: referenceEl,
16479
+ floating: floatingEl
16480
+ }), [referenceEl, floatingEl]);
16481
+ const floatingStyles = React.useMemo(() => {
16482
+ const initialStyles = {
16483
+ position: strategy,
16484
+ left: 0,
16485
+ top: 0
16486
+ };
16487
+ if (!elements.floating) {
16488
+ return initialStyles;
16489
+ }
16490
+ const x = roundByDPR(elements.floating, data.x);
16491
+ const y = roundByDPR(elements.floating, data.y);
16492
+ if (transform) {
16493
+ return {
16494
+ ...initialStyles,
16495
+ transform: "translate(" + x + "px, " + y + "px)",
16496
+ ...(getDPR(elements.floating) >= 1.5 && {
16497
+ willChange: 'transform'
16498
+ })
16499
+ };
16500
+ }
16501
+ return {
16502
+ position: strategy,
16503
+ left: x,
16504
+ top: y
16505
+ };
16506
+ }, [strategy, transform, elements.floating, data.x, data.y]);
16303
16507
  return React.useMemo(() => ({
16304
16508
  ...data,
16305
16509
  update,
16306
16510
  refs,
16307
16511
  elements,
16308
- reference: setReference,
16309
- floating: setFloating
16310
- }), [data, update, refs, elements, setReference, setFloating]);
16512
+ floatingStyles
16513
+ }), [data, update, refs, elements, floatingStyles]);
16311
16514
  }
16312
16515
 
16313
- var getDefaultParent = function (originalTarget) {
16314
- if (typeof document === 'undefined') {
16315
- return null;
16316
- }
16317
- var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
16318
- return sampleTarget.ownerDocument.body;
16319
- };
16320
- var counterMap = new WeakMap();
16321
- var uncontrolledNodes = new WeakMap();
16322
- var markerMap = {};
16323
- var lockCount = 0;
16324
- var unwrapHost = function (node) {
16325
- return node && (node.host || unwrapHost(node.parentNode));
16326
- };
16327
- var correctTargets = function (parent, targets) {
16328
- return targets.map(function (target) {
16329
- if (parent.contains(target)) {
16330
- return target;
16331
- }
16332
- var correctedTarget = unwrapHost(target);
16333
- if (correctedTarget && parent.contains(correctedTarget)) {
16334
- return correctedTarget;
16335
- }
16336
- console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
16337
- return null;
16338
- }).filter(function (x) { return Boolean(x); });
16339
- };
16340
- /**
16341
- * Marks everything except given node(or nodes) as aria-hidden
16342
- * @param {Element | Element[]} originalTarget - elements to keep on the page
16343
- * @param [parentNode] - top element, defaults to document.body
16344
- * @param {String} [markerName] - a special attribute to mark every node
16345
- * @param {String} [controlAttribute] - html Attribute to control
16346
- * @return {Undo} undo command
16347
- */
16348
- var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) {
16349
- var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
16350
- if (!markerMap[markerName]) {
16351
- markerMap[markerName] = new WeakMap();
16352
- }
16353
- var markerCounter = markerMap[markerName];
16354
- var hiddenNodes = [];
16355
- var elementsToKeep = new Set();
16356
- var elementsToStop = new Set(targets);
16357
- var keep = function (el) {
16358
- if (!el || elementsToKeep.has(el)) {
16359
- return;
16360
- }
16361
- elementsToKeep.add(el);
16362
- keep(el.parentNode);
16363
- };
16364
- targets.forEach(keep);
16365
- var deep = function (parent) {
16366
- if (!parent || elementsToStop.has(parent)) {
16367
- return;
16368
- }
16369
- Array.prototype.forEach.call(parent.children, function (node) {
16370
- if (elementsToKeep.has(node)) {
16371
- deep(node);
16372
- }
16373
- else {
16374
- var attr = node.getAttribute(controlAttribute);
16375
- var alreadyHidden = attr !== null && attr !== 'false';
16376
- var counterValue = (counterMap.get(node) || 0) + 1;
16377
- var markerValue = (markerCounter.get(node) || 0) + 1;
16378
- counterMap.set(node, counterValue);
16379
- markerCounter.set(node, markerValue);
16380
- hiddenNodes.push(node);
16381
- if (counterValue === 1 && alreadyHidden) {
16382
- uncontrolledNodes.set(node, true);
16383
- }
16384
- if (markerValue === 1) {
16385
- node.setAttribute(markerName, 'true');
16386
- }
16387
- if (!alreadyHidden) {
16388
- node.setAttribute(controlAttribute, 'true');
16389
- }
16390
- }
16391
- });
16392
- };
16393
- deep(parentNode);
16394
- elementsToKeep.clear();
16395
- lockCount++;
16396
- return function () {
16397
- hiddenNodes.forEach(function (node) {
16398
- var counterValue = counterMap.get(node) - 1;
16399
- var markerValue = markerCounter.get(node) - 1;
16400
- counterMap.set(node, counterValue);
16401
- markerCounter.set(node, markerValue);
16402
- if (!counterValue) {
16403
- if (!uncontrolledNodes.has(node)) {
16404
- node.removeAttribute(controlAttribute);
16405
- }
16406
- uncontrolledNodes.delete(node);
16407
- }
16408
- if (!markerValue) {
16409
- node.removeAttribute(markerName);
16410
- }
16411
- });
16412
- lockCount--;
16413
- if (!lockCount) {
16414
- // clear
16415
- counterMap = new WeakMap();
16416
- counterMap = new WeakMap();
16417
- uncontrolledNodes = new WeakMap();
16418
- markerMap = {};
16419
- }
16420
- };
16421
- };
16422
- /**
16423
- * Marks everything except given node(or nodes) as aria-hidden
16424
- * @param {Element | Element[]} originalTarget - elements to keep on the page
16425
- * @param [parentNode] - top element, defaults to document.body
16426
- * @param {String} [markerName] - a special attribute to mark every node
16427
- * @return {Undo} undo command
16428
- */
16429
- var hideOthers = function (originalTarget, parentNode, markerName) {
16430
- if (markerName === void 0) { markerName = 'data-aria-hidden'; }
16431
- var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
16432
- var activeParentNode = parentNode || getDefaultParent(originalTarget);
16433
- if (!activeParentNode) {
16434
- return function () { return null; };
16435
- }
16436
- // we should not hide ariaLive elements - https://github.com/theKashey/aria-hidden/issues/10
16437
- targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll('[aria-live]')));
16438
- return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
16439
- };
16440
-
16441
16516
  /*!
16442
16517
  * tabbable 6.0.1
16443
16518
  * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
@@ -16860,8 +16935,53 @@ var tabbable = function tabbable(el, options) {
16860
16935
  return sortByOrder(candidates);
16861
16936
  };
16862
16937
 
16938
+ /**
16939
+ * Merges an array of refs into a single memoized callback ref or `null`.
16940
+ * @see https://floating-ui.com/docs/useMergeRefs
16941
+ */
16942
+ function useMergeRefs(refs) {
16943
+ return React.useMemo(() => {
16944
+ if (refs.every(ref => ref == null)) {
16945
+ return null;
16946
+ }
16947
+ return value => {
16948
+ refs.forEach(ref => {
16949
+ if (typeof ref === 'function') {
16950
+ ref(value);
16951
+ } else if (ref != null) {
16952
+ ref.current = value;
16953
+ }
16954
+ });
16955
+ };
16956
+ // eslint-disable-next-line react-hooks/exhaustive-deps
16957
+ }, refs);
16958
+ }
16959
+
16960
+ let rafId = 0;
16961
+ function enqueueFocus(el, options) {
16962
+ if (options === void 0) {
16963
+ options = {};
16964
+ }
16965
+ const {
16966
+ preventScroll = false,
16967
+ cancelPrevious = true,
16968
+ sync = false
16969
+ } = options;
16970
+ cancelPrevious && cancelAnimationFrame(rafId);
16971
+ const exec = () => el == null ? void 0 : el.focus({
16972
+ preventScroll
16973
+ });
16974
+ if (sync) {
16975
+ exec();
16976
+ } else {
16977
+ rafId = requestAnimationFrame(exec);
16978
+ }
16979
+ }
16980
+
16981
+ var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
16982
+
16863
16983
  function _extends() {
16864
- _extends = Object.assign || function (target) {
16984
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
16865
16985
  for (var i = 1; i < arguments.length; i++) {
16866
16986
  var source = arguments[i];
16867
16987
  for (var key in source) {
@@ -16875,8 +16995,6 @@ function _extends() {
16875
16995
  return _extends.apply(this, arguments);
16876
16996
  }
16877
16997
 
16878
- var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
16879
-
16880
16998
  let serverHandoffComplete = false;
16881
16999
  let count = 0;
16882
17000
  const genId = () => "floating-ui-" + count++;
@@ -16932,105 +17050,8 @@ const useFloatingParentNodeId = () => {
16932
17050
  };
16933
17051
  const useFloatingTree = () => React.useContext(FloatingTreeContext);
16934
17052
 
16935
- function getDocument(node) {
16936
- return (node == null ? void 0 : node.ownerDocument) || document;
16937
- }
16938
-
16939
- // Avoid Chrome DevTools blue warning.
16940
- function getPlatform() {
16941
- const uaData = navigator.userAgentData;
16942
- if (uaData != null && uaData.platform) {
16943
- return uaData.platform;
16944
- }
16945
- return navigator.platform;
16946
- }
16947
- function getUserAgent() {
16948
- const uaData = navigator.userAgentData;
16949
- if (uaData && Array.isArray(uaData.brands)) {
16950
- return uaData.brands.map(_ref => {
16951
- let {
16952
- brand,
16953
- version
16954
- } = _ref;
16955
- return brand + "/" + version;
16956
- }).join(' ');
16957
- }
16958
- return navigator.userAgent;
16959
- }
16960
-
16961
- function getWindow(value) {
16962
- return getDocument(value).defaultView || window;
16963
- }
16964
- function isElement(value) {
16965
- return value ? value instanceof getWindow(value).Element : false;
16966
- }
16967
- function isHTMLElement(value) {
16968
- return value ? value instanceof getWindow(value).HTMLElement : false;
16969
- }
16970
- function isShadowRoot(node) {
16971
- // Browsers without `ShadowRoot` support
16972
- if (typeof ShadowRoot === 'undefined') {
16973
- return false;
16974
- }
16975
- const OwnElement = getWindow(node).ShadowRoot;
16976
- return node instanceof OwnElement || node instanceof ShadowRoot;
16977
- }
16978
-
16979
- // License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
16980
- function isVirtualClick(event) {
16981
- if (event.mozInputSource === 0 && event.isTrusted) {
16982
- return true;
16983
- }
16984
- const androidRe = /Android/i;
16985
- if ((androidRe.test(getPlatform()) || androidRe.test(getUserAgent())) && event.pointerType) {
16986
- return event.type === 'click' && event.buttons === 1;
16987
- }
16988
- return event.detail === 0 && !event.pointerType;
16989
- }
16990
- function isVirtualPointerEvent(event) {
16991
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType !== 'mouse' ||
16992
- // iOS VoiceOver returns 0.333• for width/height.
16993
- event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0;
16994
- }
16995
- function isSafari() {
16996
- // Chrome DevTools does not complain about navigator.vendor
16997
- return /apple/i.test(navigator.vendor);
16998
- }
16999
- function isMouseLikePointerType(pointerType, strict) {
17000
- // On some Linux machines with Chromium, mouse inputs return a `pointerType`
17001
- // of "pen": https://github.com/floating-ui/floating-ui/issues/2015
17002
- const values = ['mouse', 'pen'];
17003
- if (!strict) {
17004
- values.push('', undefined);
17005
- }
17006
- return values.includes(pointerType);
17007
- }
17008
-
17009
- function contains(parent, child) {
17010
- if (!parent || !child) {
17011
- return false;
17012
- }
17013
- const rootNode = child.getRootNode && child.getRootNode();
17014
-
17015
- // First, attempt with faster native method
17016
- if (parent.contains(child)) {
17017
- return true;
17018
- }
17019
-
17020
- // then fallback to custom implementation with Shadow DOM support
17021
- if (rootNode && isShadowRoot(rootNode)) {
17022
- let next = child;
17023
- while (next) {
17024
- if (parent === next) {
17025
- return true;
17026
- }
17027
- // @ts-ignore
17028
- next = next.parentNode || next.host;
17029
- }
17030
- }
17031
-
17032
- // Give up, the result is false
17033
- return false;
17053
+ function createAttribute(name) {
17054
+ return "data-floating-ui-" + name;
17034
17055
  }
17035
17056
 
17036
17057
  function useLatestRef(value) {
@@ -17041,7 +17062,7 @@ function useLatestRef(value) {
17041
17062
  return ref;
17042
17063
  }
17043
17064
 
17044
- const safePolygonIdentifier = 'data-floating-ui-safe-polygon';
17065
+ const safePolygonIdentifier = /*#__PURE__*/createAttribute('safe-polygon');
17045
17066
  function getDelay(value, prop, pointerType) {
17046
17067
  if (pointerType && !isMouseLikePointerType(pointerType)) {
17047
17068
  return 0;
@@ -17056,7 +17077,7 @@ function getDelay(value, prop, pointerType) {
17056
17077
  * CSS `:hover`.
17057
17078
  * @see https://floating-ui.com/docs/useHover
17058
17079
  */
17059
- const useHover$1 = function (context, props) {
17080
+ function useHover$1(context, props) {
17060
17081
  if (props === void 0) {
17061
17082
  props = {};
17062
17083
  }
@@ -17116,9 +17137,9 @@ const useHover$1 = function (context, props) {
17116
17137
  if (!enabled || !handleCloseRef.current || !open) {
17117
17138
  return;
17118
17139
  }
17119
- function onLeave() {
17140
+ function onLeave(event) {
17120
17141
  if (isHoverOpen()) {
17121
- onOpenChange(false);
17142
+ onOpenChange(false, event);
17122
17143
  }
17123
17144
  }
17124
17145
  const html = getDocument(floating).documentElement;
@@ -17127,17 +17148,17 @@ const useHover$1 = function (context, props) {
17127
17148
  html.removeEventListener('mouseleave', onLeave);
17128
17149
  };
17129
17150
  }, [floating, open, onOpenChange, enabled, handleCloseRef, dataRef, isHoverOpen]);
17130
- const closeWithDelay = React.useCallback(function (runElseBranch) {
17151
+ const closeWithDelay = React.useCallback(function (event, runElseBranch) {
17131
17152
  if (runElseBranch === void 0) {
17132
17153
  runElseBranch = true;
17133
17154
  }
17134
17155
  const closeDelay = getDelay(delayRef.current, 'close', pointerTypeRef.current);
17135
17156
  if (closeDelay && !handlerRef.current) {
17136
17157
  clearTimeout(timeoutRef.current);
17137
- timeoutRef.current = setTimeout(() => onOpenChange(false), closeDelay);
17158
+ timeoutRef.current = setTimeout(() => onOpenChange(false, event), closeDelay);
17138
17159
  } else if (runElseBranch) {
17139
17160
  clearTimeout(timeoutRef.current);
17140
- onOpenChange(false);
17161
+ onOpenChange(false, event);
17141
17162
  }
17142
17163
  }, [delayRef, onOpenChange]);
17143
17164
  const cleanupMouseMoveHandler = React.useCallback(() => {
@@ -17169,14 +17190,13 @@ const useHover$1 = function (context, props) {
17169
17190
  if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || restMs > 0 && getDelay(delayRef.current, 'open') === 0) {
17170
17191
  return;
17171
17192
  }
17172
- dataRef.current.openEvent = event;
17173
17193
  const openDelay = getDelay(delayRef.current, 'open', pointerTypeRef.current);
17174
17194
  if (openDelay) {
17175
17195
  timeoutRef.current = setTimeout(() => {
17176
- onOpenChange(true);
17196
+ onOpenChange(true, event);
17177
17197
  }, openDelay);
17178
17198
  } else {
17179
- onOpenChange(true);
17199
+ onOpenChange(true, event);
17180
17200
  }
17181
17201
  }
17182
17202
  function onMouseLeave(event) {
@@ -17199,7 +17219,8 @@ const useHover$1 = function (context, props) {
17199
17219
  onClose() {
17200
17220
  clearPointerEvents();
17201
17221
  cleanupMouseMoveHandler();
17202
- closeWithDelay();
17222
+ // Should the event expose that it was closed by `safePolygon`?
17223
+ closeWithDelay(event);
17203
17224
  }
17204
17225
  });
17205
17226
  const handler = handlerRef.current;
@@ -17215,7 +17236,7 @@ const useHover$1 = function (context, props) {
17215
17236
  // consistently.
17216
17237
  const shouldClose = pointerTypeRef.current === 'touch' ? !contains(floating, event.relatedTarget) : true;
17217
17238
  if (shouldClose) {
17218
- closeWithDelay();
17239
+ closeWithDelay(event);
17219
17240
  }
17220
17241
  }
17221
17242
 
@@ -17234,7 +17255,7 @@ const useHover$1 = function (context, props) {
17234
17255
  onClose() {
17235
17256
  clearPointerEvents();
17236
17257
  cleanupMouseMoveHandler();
17237
- closeWithDelay();
17258
+ closeWithDelay(event);
17238
17259
  }
17239
17260
  })(event);
17240
17261
  }
@@ -17301,7 +17322,7 @@ const useHover$1 = function (context, props) {
17301
17322
  clearTimeout(restTimeoutRef.current);
17302
17323
  clearPointerEvents();
17303
17324
  };
17304
- }, [enabled, cleanupMouseMoveHandler, clearPointerEvents]);
17325
+ }, [enabled, domReference, cleanupMouseMoveHandler, clearPointerEvents]);
17305
17326
  return React.useMemo(() => {
17306
17327
  if (!enabled) {
17307
17328
  return {};
@@ -17313,14 +17334,14 @@ const useHover$1 = function (context, props) {
17313
17334
  reference: {
17314
17335
  onPointerDown: setPointerRef,
17315
17336
  onPointerEnter: setPointerRef,
17316
- onMouseMove() {
17337
+ onMouseMove(event) {
17317
17338
  if (open || restMs === 0) {
17318
17339
  return;
17319
17340
  }
17320
17341
  clearTimeout(restTimeoutRef.current);
17321
17342
  restTimeoutRef.current = setTimeout(() => {
17322
17343
  if (!blockMouseMoveRef.current) {
17323
- onOpenChange(true);
17344
+ onOpenChange(true, event.nativeEvent);
17324
17345
  }
17325
17346
  }, restMs);
17326
17347
  }
@@ -17329,51 +17350,18 @@ const useHover$1 = function (context, props) {
17329
17350
  onMouseEnter() {
17330
17351
  clearTimeout(timeoutRef.current);
17331
17352
  },
17332
- onMouseLeave() {
17353
+ onMouseLeave(event) {
17333
17354
  events.emit('dismiss', {
17334
17355
  type: 'mouseLeave',
17335
17356
  data: {
17336
17357
  returnFocus: false
17337
17358
  }
17338
17359
  });
17339
- closeWithDelay(false);
17360
+ closeWithDelay(event.nativeEvent, false);
17340
17361
  }
17341
17362
  }
17342
17363
  };
17343
17364
  }, [events, enabled, restMs, open, onOpenChange, closeWithDelay]);
17344
- };
17345
-
17346
- /**
17347
- * Find the real active element. Traverses into shadowRoots.
17348
- */
17349
- function activeElement(doc) {
17350
- let activeElement = doc.activeElement;
17351
- while (((_activeElement = activeElement) == null ? void 0 : (_activeElement$shadow = _activeElement.shadowRoot) == null ? void 0 : _activeElement$shadow.activeElement) != null) {
17352
- var _activeElement, _activeElement$shadow;
17353
- activeElement = activeElement.shadowRoot.activeElement;
17354
- }
17355
- return activeElement;
17356
- }
17357
-
17358
- let rafId = 0;
17359
- function enqueueFocus(el, options) {
17360
- if (options === void 0) {
17361
- options = {};
17362
- }
17363
- const {
17364
- preventScroll = false,
17365
- cancelPrevious = true,
17366
- sync = false
17367
- } = options;
17368
- cancelPrevious && cancelAnimationFrame(rafId);
17369
- const exec = () => el == null ? void 0 : el.focus({
17370
- preventScroll
17371
- });
17372
- if (sync) {
17373
- exec();
17374
- } else {
17375
- rafId = requestAnimationFrame(exec);
17376
- }
17377
17365
  }
17378
17366
 
17379
17367
  function getAncestors(nodes, id) {
@@ -17409,24 +17397,107 @@ function getChildren(nodes, id) {
17409
17397
  return allChildren;
17410
17398
  }
17411
17399
 
17412
- function getTarget(event) {
17413
- if ('composedPath' in event) {
17414
- return event.composedPath()[0];
17400
+ // Modified to add conditional `aria-hidden` support:
17401
+ // https://github.com/theKashey/aria-hidden/blob/9220c8f4a4fd35f63bee5510a9f41a37264382d4/src/index.ts
17402
+ let counterMap = /*#__PURE__*/new WeakMap();
17403
+ let uncontrolledElementsSet = /*#__PURE__*/new WeakSet();
17404
+ let markerMap = {};
17405
+ let lockCount = 0;
17406
+ const supportsInert = () => typeof HTMLElement !== 'undefined' && 'inert' in HTMLElement.prototype;
17407
+ const unwrapHost = node => node && (node.host || unwrapHost(node.parentNode));
17408
+ const correctElements = (parent, targets) => targets.map(target => {
17409
+ if (parent.contains(target)) {
17410
+ return target;
17415
17411
  }
17416
-
17417
- // TS thinks `event` is of type never as it assumes all browsers support
17418
- // `composedPath()`, but browsers without shadow DOM don't.
17419
- return event.target;
17420
- }
17421
-
17422
- const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
17423
- function isTypeableElement(element) {
17424
- return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
17412
+ const correctedTarget = unwrapHost(target);
17413
+ if (parent.contains(correctedTarget)) {
17414
+ return correctedTarget;
17415
+ }
17416
+ return null;
17417
+ }).filter(x => x != null);
17418
+ function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, inert) {
17419
+ const markerName = 'data-floating-ui-inert';
17420
+ const controlAttribute = inert ? 'inert' : ariaHidden ? 'aria-hidden' : null;
17421
+ const avoidElements = correctElements(body, uncorrectedAvoidElements);
17422
+ const elementsToKeep = new Set();
17423
+ const elementsToStop = new Set(avoidElements);
17424
+ const hiddenElements = [];
17425
+ if (!markerMap[markerName]) {
17426
+ markerMap[markerName] = new WeakMap();
17427
+ }
17428
+ const markerCounter = markerMap[markerName];
17429
+ avoidElements.forEach(keep);
17430
+ deep(body);
17431
+ elementsToKeep.clear();
17432
+ function keep(el) {
17433
+ if (!el || elementsToKeep.has(el)) {
17434
+ return;
17435
+ }
17436
+ elementsToKeep.add(el);
17437
+ el.parentNode && keep(el.parentNode);
17438
+ }
17439
+ function deep(parent) {
17440
+ if (!parent || elementsToStop.has(parent)) {
17441
+ return;
17442
+ }
17443
+ Array.prototype.forEach.call(parent.children, node => {
17444
+ if (elementsToKeep.has(node)) {
17445
+ deep(node);
17446
+ } else {
17447
+ const attr = controlAttribute ? node.getAttribute(controlAttribute) : null;
17448
+ const alreadyHidden = attr !== null && attr !== 'false';
17449
+ const counterValue = (counterMap.get(node) || 0) + 1;
17450
+ const markerValue = (markerCounter.get(node) || 0) + 1;
17451
+ counterMap.set(node, counterValue);
17452
+ markerCounter.set(node, markerValue);
17453
+ hiddenElements.push(node);
17454
+ if (counterValue === 1 && alreadyHidden) {
17455
+ uncontrolledElementsSet.add(node);
17456
+ }
17457
+ if (markerValue === 1) {
17458
+ node.setAttribute(markerName, '');
17459
+ }
17460
+ if (!alreadyHidden && controlAttribute) {
17461
+ node.setAttribute(controlAttribute, 'true');
17462
+ }
17463
+ }
17464
+ });
17465
+ }
17466
+ lockCount++;
17467
+ return () => {
17468
+ hiddenElements.forEach(element => {
17469
+ const counterValue = (counterMap.get(element) || 0) - 1;
17470
+ const markerValue = (markerCounter.get(element) || 0) - 1;
17471
+ counterMap.set(element, counterValue);
17472
+ markerCounter.set(element, markerValue);
17473
+ if (!counterValue) {
17474
+ if (!uncontrolledElementsSet.has(element) && controlAttribute) {
17475
+ element.removeAttribute(controlAttribute);
17476
+ }
17477
+ uncontrolledElementsSet.delete(element);
17478
+ }
17479
+ if (!markerValue) {
17480
+ element.removeAttribute(markerName);
17481
+ }
17482
+ });
17483
+ lockCount--;
17484
+ if (!lockCount) {
17485
+ counterMap = new WeakMap();
17486
+ counterMap = new WeakMap();
17487
+ uncontrolledElementsSet = new WeakSet();
17488
+ markerMap = {};
17489
+ }
17490
+ };
17425
17491
  }
17426
-
17427
- function stopEvent(event) {
17428
- event.preventDefault();
17429
- event.stopPropagation();
17492
+ function markOthers(avoidElements, ariaHidden, inert) {
17493
+ if (ariaHidden === void 0) {
17494
+ ariaHidden = false;
17495
+ }
17496
+ if (inert === void 0) {
17497
+ inert = false;
17498
+ }
17499
+ const body = getDocument(avoidElements[0]).body;
17500
+ return applyAttributeToOthers(avoidElements.concat(Array.from(body.querySelectorAll('[aria-live]'))), body, ariaHidden, inert);
17430
17501
  }
17431
17502
 
17432
17503
  const getTabbableOptions = () => ({
@@ -17516,20 +17587,20 @@ const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref)
17516
17587
  document.removeEventListener('keydown', setActiveElementOnTab);
17517
17588
  };
17518
17589
  }, []);
17519
- return /*#__PURE__*/React.createElement("span", _extends({}, props, {
17520
- ref: ref,
17521
- tabIndex: 0
17590
+ const restProps = {
17591
+ ref,
17592
+ tabIndex: 0,
17522
17593
  // Role is only for VoiceOver
17523
- ,
17524
- role: role,
17525
- "aria-hidden": role ? undefined : true,
17526
- "data-floating-ui-focus-guard": "",
17594
+ role,
17595
+ 'aria-hidden': role ? undefined : true,
17596
+ [createAttribute('focus-guard')]: '',
17527
17597
  style: HIDDEN_STYLES
17528
- }));
17598
+ };
17599
+ return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
17529
17600
  });
17530
17601
 
17531
17602
  const PortalContext = /*#__PURE__*/React.createContext(null);
17532
- const useFloatingPortalNode = function (_temp) {
17603
+ function useFloatingPortalNode(_temp) {
17533
17604
  let {
17534
17605
  id,
17535
17606
  root
@@ -17537,20 +17608,39 @@ const useFloatingPortalNode = function (_temp) {
17537
17608
  const [portalNode, setPortalNode] = React.useState(null);
17538
17609
  const uniqueId = useId();
17539
17610
  const portalContext = usePortalContext();
17611
+ const data = React.useMemo(() => ({
17612
+ id,
17613
+ root,
17614
+ portalContext,
17615
+ uniqueId
17616
+ }), [id, root, portalContext, uniqueId]);
17617
+ const dataRef = React.useRef();
17618
+ index(() => {
17619
+ return () => {
17620
+ portalNode == null ? void 0 : portalNode.remove();
17621
+ };
17622
+ }, [portalNode, data]);
17540
17623
  index(() => {
17624
+ if (dataRef.current === data) return;
17625
+ dataRef.current = data;
17626
+ const {
17627
+ id,
17628
+ root,
17629
+ portalContext,
17630
+ uniqueId
17631
+ } = data;
17541
17632
  const existingIdRoot = id ? document.getElementById(id) : null;
17542
- const attr = 'data-floating-ui-portal';
17633
+ const attr = createAttribute('portal');
17543
17634
  if (existingIdRoot) {
17544
17635
  const subRoot = document.createElement('div');
17545
17636
  subRoot.id = uniqueId;
17546
17637
  subRoot.setAttribute(attr, '');
17547
17638
  existingIdRoot.appendChild(subRoot);
17548
17639
  setPortalNode(subRoot);
17549
- return () => {
17550
- subRoot.remove();
17551
- };
17552
17640
  } else {
17553
- let container = (portalContext == null ? void 0 : portalContext.portalNode) || root || document.body;
17641
+ let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
17642
+ if (container && !isElement(container)) container = container.current;
17643
+ container = container || document.body;
17554
17644
  let idWrapper = null;
17555
17645
  if (id) {
17556
17646
  idWrapper = document.createElement('div');
@@ -17560,25 +17650,19 @@ const useFloatingPortalNode = function (_temp) {
17560
17650
  const subRoot = document.createElement('div');
17561
17651
  subRoot.id = uniqueId;
17562
17652
  subRoot.setAttribute(attr, '');
17563
- setPortalNode(subRoot);
17564
17653
  container = idWrapper || container;
17565
17654
  container.appendChild(subRoot);
17566
- return () => {
17567
- var _idWrapper;
17568
- subRoot.remove();
17569
- (_idWrapper = idWrapper) == null ? void 0 : _idWrapper.remove();
17570
- };
17655
+ setPortalNode(subRoot);
17571
17656
  }
17572
- }, [id, root, portalContext, uniqueId]);
17657
+ }, [data]);
17573
17658
  return portalNode;
17574
- };
17575
-
17659
+ }
17576
17660
  /**
17577
17661
  * Portals the floating element into a given container element — by default,
17578
17662
  * outside of the app root and into the body.
17579
17663
  * @see https://floating-ui.com/docs/FloatingPortal
17580
17664
  */
17581
- const FloatingPortal = _ref => {
17665
+ function FloatingPortal(_ref) {
17582
17666
  let {
17583
17667
  children,
17584
17668
  id,
@@ -17599,7 +17683,9 @@ const FloatingPortal = _ref => {
17599
17683
  // rendered.
17600
17684
  !!focusManagerState &&
17601
17685
  // Guards are only for non-modal focus management.
17602
- !focusManagerState.modal && !!(root || portalNode) && preserveTabOrder;
17686
+ !focusManagerState.modal &&
17687
+ // Don't render if unmount is transitioning.
17688
+ focusManagerState.open && preserveTabOrder && !!(root || portalNode);
17603
17689
 
17604
17690
  // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
17605
17691
  React.useEffect(() => {
@@ -17661,11 +17747,11 @@ const FloatingPortal = _ref => {
17661
17747
  } else {
17662
17748
  const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
17663
17749
  nextTabbable == null ? void 0 : nextTabbable.focus();
17664
- (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false));
17750
+ (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent));
17665
17751
  }
17666
17752
  }
17667
17753
  }));
17668
- };
17754
+ }
17669
17755
  const usePortalContext = () => React.useContext(PortalContext);
17670
17756
 
17671
17757
  const VisuallyHiddenDismiss = /*#__PURE__*/React.forwardRef(function VisuallyHiddenDismiss(props, ref) {
@@ -17680,18 +17766,19 @@ const VisuallyHiddenDismiss = /*#__PURE__*/React.forwardRef(function VisuallyHid
17680
17766
  * Provides focus management for the floating element.
17681
17767
  * @see https://floating-ui.com/docs/FloatingFocusManager
17682
17768
  */
17683
- function FloatingFocusManager(_ref) {
17684
- let {
17769
+ function FloatingFocusManager(props) {
17770
+ const {
17685
17771
  context,
17686
17772
  children,
17773
+ disabled = false,
17687
17774
  order = ['content'],
17688
- guards = true,
17775
+ guards: _guards = true,
17689
17776
  initialFocus = 0,
17690
17777
  returnFocus = true,
17691
17778
  modal = true,
17692
17779
  visuallyHiddenDismiss = false,
17693
17780
  closeOnFocusOut = true
17694
- } = _ref;
17781
+ } = props;
17695
17782
  const {
17696
17783
  open,
17697
17784
  refs,
@@ -17704,12 +17791,14 @@ function FloatingFocusManager(_ref) {
17704
17791
  floating
17705
17792
  }
17706
17793
  } = context;
17794
+
17795
+ // Force the guards to be rendered if the `inert` attribute is not supported.
17796
+ const guards = supportsInert() ? _guards : true;
17707
17797
  const orderRef = useLatestRef(order);
17708
17798
  const initialFocusRef = useLatestRef(initialFocus);
17709
17799
  const returnFocusRef = useLatestRef(returnFocus);
17710
17800
  const tree = useFloatingTree();
17711
17801
  const portalContext = usePortalContext();
17712
- const [tabbableContentLength, setTabbableContentLength] = React.useState(null);
17713
17802
 
17714
17803
  // Controlled by `useListNavigation`.
17715
17804
  const ignoreInitialFocus = typeof initialFocus === 'number' && initialFocus < 0;
@@ -17725,7 +17814,7 @@ function FloatingFocusManager(_ref) {
17725
17814
  // aria-hidden should be applied to all nodes still. Further, the visually
17726
17815
  // hidden dismiss button should only appear at the end of the list, not the
17727
17816
  // start.
17728
- const isTypeableCombobox = domReference && domReference.getAttribute('role') === 'combobox' && isTypeableElement(domReference);
17817
+ const isUntrappedTypeableCombobox = domReference && domReference.getAttribute('role') === 'combobox' && isTypeableElement(domReference) && ignoreInitialFocus;
17729
17818
  const getTabbableContent = React.useCallback(function (container) {
17730
17819
  if (container === void 0) {
17731
17820
  container = floating;
@@ -17745,13 +17834,11 @@ function FloatingFocusManager(_ref) {
17745
17834
  }).filter(Boolean).flat();
17746
17835
  }, [domReference, floating, orderRef, getTabbableContent]);
17747
17836
  React.useEffect(() => {
17748
- if (!modal) {
17749
- return;
17750
- }
17837
+ if (disabled || !modal) return;
17751
17838
  function onKeyDown(event) {
17752
17839
  if (event.key === 'Tab') {
17753
17840
  // The focus guards have nothing to focus, so we need to stop the event.
17754
- if (getTabbableContent().length === 0 && !isTypeableCombobox) {
17841
+ if (contains(floating, activeElement(getDocument(floating))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
17755
17842
  stopEvent(event);
17756
17843
  }
17757
17844
  const els = getTabbableElements();
@@ -17775,11 +17862,9 @@ function FloatingFocusManager(_ref) {
17775
17862
  return () => {
17776
17863
  doc.removeEventListener('keydown', onKeyDown);
17777
17864
  };
17778
- }, [domReference, floating, modal, orderRef, refs, isTypeableCombobox, getTabbableContent, getTabbableElements]);
17865
+ }, [disabled, domReference, floating, modal, orderRef, refs, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
17779
17866
  React.useEffect(() => {
17780
- if (!closeOnFocusOut) {
17781
- return;
17782
- }
17867
+ if (disabled || !closeOnFocusOut) return;
17783
17868
 
17784
17869
  // In Safari, buttons lose focus when pressing them.
17785
17870
  function handlePointerDown() {
@@ -17790,22 +17875,24 @@ function FloatingFocusManager(_ref) {
17790
17875
  }
17791
17876
  function handleFocusOutside(event) {
17792
17877
  const relatedTarget = event.relatedTarget;
17793
- const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute('data-floating-ui-focus-guard') || tree && (getChildren(tree.nodesRef.current, nodeId).find(node => {
17794
- var _node$context, _node$context2;
17795
- return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
17796
- }) || getAncestors(tree.nodesRef.current, nodeId).find(node => {
17797
- var _node$context3, _node$context4;
17798
- return ((_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating) === relatedTarget || ((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.domReference) === relatedTarget;
17799
- })));
17800
-
17801
- // Focus did not move inside the floating tree, and there are no tabbable
17802
- // portal guards to handle closing.
17803
- if (relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current &&
17804
- // Fix React 18 Strict Mode returnFocus due to double rendering.
17805
- relatedTarget !== previouslyFocusedElementRef.current) {
17806
- preventReturnFocusRef.current = true;
17807
- onOpenChange(false);
17808
- }
17878
+ queueMicrotask(() => {
17879
+ const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute(createAttribute('focus-guard')) || tree && (getChildren(tree.nodesRef.current, nodeId).find(node => {
17880
+ var _node$context, _node$context2;
17881
+ return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
17882
+ }) || getAncestors(tree.nodesRef.current, nodeId).find(node => {
17883
+ var _node$context3, _node$context4;
17884
+ return ((_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating) === relatedTarget || ((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.domReference) === relatedTarget;
17885
+ })));
17886
+
17887
+ // Focus did not move inside the floating tree, and there are no tabbable
17888
+ // portal guards to handle closing.
17889
+ if (relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current &&
17890
+ // Fix React 18 Strict Mode returnFocus due to double rendering.
17891
+ relatedTarget !== previouslyFocusedElementRef.current) {
17892
+ preventReturnFocusRef.current = true;
17893
+ onOpenChange(false, event);
17894
+ }
17895
+ });
17809
17896
  }
17810
17897
  if (floating && isHTMLElement(domReference)) {
17811
17898
  domReference.addEventListener('focusout', handleFocusOutside);
@@ -17817,63 +17904,46 @@ function FloatingFocusManager(_ref) {
17817
17904
  !modal && floating.removeEventListener('focusout', handleFocusOutside);
17818
17905
  };
17819
17906
  }
17820
- }, [domReference, floating, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut]);
17907
+ }, [disabled, domReference, floating, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut]);
17821
17908
  React.useEffect(() => {
17822
17909
  var _portalContext$portal;
17910
+ if (disabled) return;
17911
+
17823
17912
  // Don't hide portals nested within the parent portal.
17824
- const portalNodes = Array.from((portalContext == null ? void 0 : (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll('[data-floating-ui-portal]')) || []);
17825
- function getDismissButtons() {
17826
- return [startDismissButtonRef.current, endDismissButtonRef.current].filter(Boolean);
17827
- }
17828
- if (floating && modal) {
17829
- const insideNodes = [floating, ...portalNodes, ...getDismissButtons()];
17830
- const cleanup = hideOthers(orderRef.current.includes('reference') || isTypeableCombobox ? insideNodes.concat(domReference || []) : insideNodes);
17913
+ const portalNodes = Array.from((portalContext == null ? void 0 : (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll("[" + createAttribute('portal') + "]")) || []);
17914
+ if (floating) {
17915
+ const insideElements = [floating, ...portalNodes, startDismissButtonRef.current, endDismissButtonRef.current, orderRef.current.includes('reference') || isUntrappedTypeableCombobox ? domReference : null].filter(x => x != null);
17916
+ const cleanup = modal ? markOthers(insideElements, guards, !guards) : markOthers(insideElements);
17831
17917
  return () => {
17832
17918
  cleanup();
17833
17919
  };
17834
17920
  }
17835
- }, [domReference, floating, modal, orderRef, portalContext, isTypeableCombobox]);
17836
- React.useEffect(() => {
17837
- if (modal && !guards && floating) {
17838
- const tabIndexValues = [];
17839
- const options = getTabbableOptions();
17840
- const allTabbable = tabbable(getDocument(floating).body, options);
17841
- const floatingTabbable = getTabbableElements();
17842
-
17843
- // Exclude all tabbable elements that are part of the order
17844
- const elements = allTabbable.filter(el => !floatingTabbable.includes(el));
17845
- elements.forEach((el, i) => {
17846
- tabIndexValues[i] = el.getAttribute('tabindex');
17847
- el.setAttribute('tabindex', '-1');
17848
- });
17849
- return () => {
17850
- elements.forEach((el, i) => {
17851
- const value = tabIndexValues[i];
17852
- if (value == null) {
17853
- el.removeAttribute('tabindex');
17854
- } else {
17855
- el.setAttribute('tabindex', value);
17856
- }
17857
- });
17858
- };
17859
- }
17860
- }, [floating, modal, guards, getTabbableElements]);
17921
+ }, [disabled, domReference, floating, modal, orderRef, portalContext, isUntrappedTypeableCombobox, guards]);
17861
17922
  index(() => {
17862
- if (!floating) return;
17923
+ if (disabled || !floating) return;
17863
17924
  const doc = getDocument(floating);
17925
+ const previouslyFocusedElement = activeElement(doc);
17926
+
17927
+ // Wait for any layout effect state setters to execute to set `tabIndex`.
17928
+ queueMicrotask(() => {
17929
+ const focusableElements = getTabbableElements(floating);
17930
+ const initialFocusValue = initialFocusRef.current;
17931
+ const elToFocus = (typeof initialFocusValue === 'number' ? focusableElements[initialFocusValue] : initialFocusValue.current) || floating;
17932
+ const focusAlreadyInsideFloatingEl = contains(floating, previouslyFocusedElement);
17933
+ if (!ignoreInitialFocus && !focusAlreadyInsideFloatingEl && open) {
17934
+ enqueueFocus(elToFocus, {
17935
+ preventScroll: elToFocus === floating
17936
+ });
17937
+ }
17938
+ });
17939
+ }, [disabled, open, floating, ignoreInitialFocus, getTabbableElements, initialFocusRef]);
17940
+ index(() => {
17941
+ if (disabled || !floating) return;
17864
17942
  let preventReturnFocusScroll = false;
17943
+ const doc = getDocument(floating);
17865
17944
  const previouslyFocusedElement = activeElement(doc);
17866
17945
  const contextData = dataRef.current;
17867
- const initialFocusValue = initialFocusRef.current;
17868
17946
  previouslyFocusedElementRef.current = previouslyFocusedElement;
17869
- const focusableElements = getTabbableElements(floating);
17870
- const elToFocus = (typeof initialFocusValue === 'number' ? focusableElements[initialFocusValue] : initialFocusValue.current) || floating;
17871
-
17872
- // If the `useListNavigation` hook is active, always ignore `initialFocus`
17873
- // because it has its own handling of the initial focus.
17874
- !ignoreInitialFocus && open && enqueueFocus(elToFocus, {
17875
- preventScroll: elToFocus === floating
17876
- });
17877
17947
 
17878
17948
  // Dismissing via outside press should always ignore `returnFocus` to
17879
17949
  // prevent unwanted scrolling.
@@ -17906,8 +17976,6 @@ function FloatingFocusManager(_ref) {
17906
17976
  if (
17907
17977
  // eslint-disable-next-line react-hooks/exhaustive-deps
17908
17978
  returnFocusRef.current && isHTMLElement(previouslyFocusedElementRef.current) && !preventReturnFocusRef.current) {
17909
- // `isPointerDownRef.current` to avoid the focus ring from appearing on
17910
- // the reference element when click-toggling it.
17911
17979
  enqueueFocus(previouslyFocusedElementRef.current, {
17912
17980
  // When dismissing nested floating elements, by the time the rAF has
17913
17981
  // executed, the menus will all have been unmounted. When they try
@@ -17918,49 +17986,58 @@ function FloatingFocusManager(_ref) {
17918
17986
  });
17919
17987
  }
17920
17988
  };
17921
- }, [open, floating, getTabbableElements, returnFocusRef, initialFocusRef, dataRef, refs, events, ignoreInitialFocus, tree, nodeId]);
17989
+ }, [disabled, floating, returnFocusRef, dataRef, refs, events, tree, nodeId]);
17922
17990
 
17923
17991
  // Synchronize the `context` & `modal` value to the FloatingPortal context.
17924
17992
  // It will decide whether or not it needs to render its own guards.
17925
17993
  index(() => {
17926
- if (!portalContext) return;
17994
+ if (disabled || !portalContext) return;
17927
17995
  portalContext.setFocusManagerState({
17928
- ...context,
17929
17996
  modal,
17930
- closeOnFocusOut
17931
- // Not concerned about the <RT> generic type.
17997
+ closeOnFocusOut,
17998
+ open,
17999
+ onOpenChange,
18000
+ refs
17932
18001
  });
17933
-
17934
18002
  return () => {
17935
18003
  portalContext.setFocusManagerState(null);
17936
18004
  };
17937
- }, [portalContext, modal, closeOnFocusOut, context]);
18005
+ }, [disabled, portalContext, modal, open, onOpenChange, refs, closeOnFocusOut]);
17938
18006
  index(() => {
17939
- if (ignoreInitialFocus || !floating) return;
17940
- function setState() {
17941
- if (activeElement(getDocument(floating)) !== refs.domReference.current) {
17942
- setTabbableContentLength(getTabbableContent().length);
17943
- }
17944
- }
17945
- setState();
17946
- if (typeof MutationObserver === 'function') {
17947
- const observer = new MutationObserver(setState);
18007
+ if (disabled) return;
18008
+ if (floating && typeof MutationObserver === 'function' && !ignoreInitialFocus) {
18009
+ const handleMutation = () => {
18010
+ const tabIndex = floating.getAttribute('tabindex');
18011
+ if (orderRef.current.includes('floating') || activeElement(getDocument(floating)) !== refs.domReference.current && getTabbableContent().length === 0) {
18012
+ if (tabIndex !== '0') {
18013
+ floating.setAttribute('tabindex', '0');
18014
+ }
18015
+ } else if (tabIndex !== '-1') {
18016
+ floating.setAttribute('tabindex', '-1');
18017
+ }
18018
+ };
18019
+ handleMutation();
18020
+ const observer = new MutationObserver(handleMutation);
17948
18021
  observer.observe(floating, {
17949
18022
  childList: true,
17950
- subtree: true
18023
+ subtree: true,
18024
+ attributes: true
17951
18025
  });
17952
18026
  return () => {
17953
18027
  observer.disconnect();
17954
18028
  };
17955
18029
  }
17956
- }, [floating, getTabbableContent, ignoreInitialFocus, refs]);
17957
- const shouldRenderGuards = guards && (isInsidePortal || modal) && !isTypeableCombobox;
18030
+ }, [disabled, floating, refs, orderRef, getTabbableContent, ignoreInitialFocus]);
17958
18031
  function renderDismissButton(location) {
17959
- return visuallyHiddenDismiss && modal ? /*#__PURE__*/React.createElement(VisuallyHiddenDismiss, {
18032
+ if (disabled || !visuallyHiddenDismiss || !modal) {
18033
+ return null;
18034
+ }
18035
+ return /*#__PURE__*/React.createElement(VisuallyHiddenDismiss, {
17960
18036
  ref: location === 'start' ? startDismissButtonRef : endDismissButtonRef,
17961
- onClick: () => onOpenChange(false)
17962
- }, typeof visuallyHiddenDismiss === 'string' ? visuallyHiddenDismiss : 'Dismiss') : null;
18037
+ onClick: event => onOpenChange(false, event.nativeEvent)
18038
+ }, typeof visuallyHiddenDismiss === 'string' ? visuallyHiddenDismiss : 'Dismiss');
17963
18039
  }
18040
+ const shouldRenderGuards = !disabled && guards && !isUntrappedTypeableCombobox && (isInsidePortal || modal);
17964
18041
  return /*#__PURE__*/React.createElement(React.Fragment, null, shouldRenderGuards && /*#__PURE__*/React.createElement(FocusGuard, {
17965
18042
  "data-type": "inside",
17966
18043
  ref: portalContext == null ? void 0 : portalContext.beforeInsideRef,
@@ -17979,9 +18056,7 @@ function FloatingFocusManager(_ref) {
17979
18056
  }
17980
18057
  }
17981
18058
  }
17982
- }), isTypeableCombobox ? null : renderDismissButton('start'), /*#__PURE__*/React.cloneElement(children, tabbableContentLength === 0 || order.includes('floating') ? {
17983
- tabIndex: 0
17984
- } : {}), renderDismissButton('end'), shouldRenderGuards && /*#__PURE__*/React.createElement(FocusGuard, {
18059
+ }), !isUntrappedTypeableCombobox && renderDismissButton('start'), children, renderDismissButton('end'), shouldRenderGuards && /*#__PURE__*/React.createElement(FocusGuard, {
17985
18060
  "data-type": "inside",
17986
18061
  ref: portalContext == null ? void 0 : portalContext.afterInsideRef,
17987
18062
  onFocus: event => {
@@ -18013,7 +18088,7 @@ function isSpaceIgnored(element) {
18013
18088
  * Opens or closes the floating element when clicking the reference element.
18014
18089
  * @see https://floating-ui.com/docs/useClick
18015
18090
  */
18016
- const useClick = function (context, props) {
18091
+ function useClick(context, props) {
18017
18092
  if (props === void 0) {
18018
18093
  props = {};
18019
18094
  }
@@ -18033,10 +18108,9 @@ const useClick = function (context, props) {
18033
18108
  keyboardHandlers = true
18034
18109
  } = props;
18035
18110
  const pointerTypeRef = React.useRef();
18111
+ const didKeyDownRef = React.useRef(false);
18036
18112
  return React.useMemo(() => {
18037
- if (!enabled) {
18038
- return {};
18039
- }
18113
+ if (!enabled) return {};
18040
18114
  return {
18041
18115
  reference: {
18042
18116
  onPointerDown(event) {
@@ -18054,16 +18128,13 @@ const useClick = function (context, props) {
18054
18128
  if (eventOption === 'click') {
18055
18129
  return;
18056
18130
  }
18057
- if (open) {
18058
- if (toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'mousedown' : true)) {
18059
- onOpenChange(false);
18060
- }
18131
+ if (open && toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'mousedown' : true)) {
18132
+ onOpenChange(false, event.nativeEvent);
18061
18133
  } else {
18062
18134
  // Prevent stealing focus from the floating element
18063
18135
  event.preventDefault();
18064
- onOpenChange(true);
18136
+ onOpenChange(true, event.nativeEvent);
18065
18137
  }
18066
- dataRef.current.openEvent = event.nativeEvent;
18067
18138
  },
18068
18139
  onClick(event) {
18069
18140
  if (eventOption === 'mousedown' && pointerTypeRef.current) {
@@ -18073,63 +18144,52 @@ const useClick = function (context, props) {
18073
18144
  if (isMouseLikePointerType(pointerTypeRef.current, true) && ignoreMouse) {
18074
18145
  return;
18075
18146
  }
18076
- if (open) {
18077
- if (toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'click' : true)) {
18078
- onOpenChange(false);
18079
- }
18147
+ if (open && toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'click' : true)) {
18148
+ onOpenChange(false, event.nativeEvent);
18080
18149
  } else {
18081
- onOpenChange(true);
18150
+ onOpenChange(true, event.nativeEvent);
18082
18151
  }
18083
- dataRef.current.openEvent = event.nativeEvent;
18084
18152
  },
18085
18153
  onKeyDown(event) {
18086
18154
  pointerTypeRef.current = undefined;
18087
- if (!keyboardHandlers) {
18088
- return;
18089
- }
18090
- if (isButtonTarget(event)) {
18155
+ if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) {
18091
18156
  return;
18092
18157
  }
18093
18158
  if (event.key === ' ' && !isSpaceIgnored(domReference)) {
18094
18159
  // Prevent scrolling
18095
18160
  event.preventDefault();
18161
+ didKeyDownRef.current = true;
18096
18162
  }
18097
18163
  if (event.key === 'Enter') {
18098
- if (open) {
18099
- if (toggle) {
18100
- onOpenChange(false);
18101
- }
18164
+ if (open && toggle) {
18165
+ onOpenChange(false, event.nativeEvent);
18102
18166
  } else {
18103
- onOpenChange(true);
18167
+ onOpenChange(true, event.nativeEvent);
18104
18168
  }
18105
18169
  }
18106
18170
  },
18107
18171
  onKeyUp(event) {
18108
- if (!keyboardHandlers) {
18109
- return;
18110
- }
18111
- if (isButtonTarget(event) || isSpaceIgnored(domReference)) {
18172
+ if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference)) {
18112
18173
  return;
18113
18174
  }
18114
- if (event.key === ' ') {
18115
- if (open) {
18116
- if (toggle) {
18117
- onOpenChange(false);
18118
- }
18175
+ if (event.key === ' ' && didKeyDownRef.current) {
18176
+ didKeyDownRef.current = false;
18177
+ if (open && toggle) {
18178
+ onOpenChange(false, event.nativeEvent);
18119
18179
  } else {
18120
- onOpenChange(true);
18180
+ onOpenChange(true, event.nativeEvent);
18121
18181
  }
18122
18182
  }
18123
18183
  }
18124
18184
  }
18125
18185
  };
18126
18186
  }, [enabled, dataRef, eventOption, ignoreMouse, keyboardHandlers, domReference, toggle, open, onOpenChange]);
18127
- };
18187
+ }
18128
18188
 
18129
18189
  // `toString()` prevents bundlers from trying to `import { useInsertionEffect } from 'react'`
18130
18190
  const useInsertionEffect = React[/*#__PURE__*/'useInsertionEffect'.toString()];
18131
18191
  const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
18132
- function useEvent(callback) {
18192
+ function useEffectEvent(callback) {
18133
18193
  const ref = React.useRef(() => {
18134
18194
  if (process.env.NODE_ENV !== "production") {
18135
18195
  throw new Error('Cannot call an event handler while rendering.');
@@ -18146,26 +18206,6 @@ function useEvent(callback) {
18146
18206
  }, []);
18147
18207
  }
18148
18208
 
18149
- /**
18150
- * Check whether the event.target is within the provided node. Uses event.composedPath if available for custom element support.
18151
- *
18152
- * @param event The event whose target/composedPath to check
18153
- * @param node The node to check against
18154
- * @returns Whether the event.target/composedPath is within the node.
18155
- */
18156
- function isEventTargetWithin(event, node) {
18157
- if (node == null) {
18158
- return false;
18159
- }
18160
- if ('composedPath' in event) {
18161
- return event.composedPath().includes(node);
18162
- }
18163
-
18164
- // TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
18165
- const e = event;
18166
- return e.target != null && node.contains(e.target);
18167
- }
18168
-
18169
18209
  const bubbleHandlerKeys = {
18170
18210
  pointerdown: 'onPointerDown',
18171
18211
  mousedown: 'onMouseDown',
@@ -18188,7 +18228,7 @@ const normalizeBubblesProp = bubbles => {
18188
18228
  * the user presses the `escape` key or outside of the floating element.
18189
18229
  * @see https://floating-ui.com/docs/useDismiss
18190
18230
  */
18191
- const useDismiss = function (context, props) {
18231
+ function useDismiss(context, props) {
18192
18232
  if (props === void 0) {
18193
18233
  props = {};
18194
18234
  }
@@ -18216,14 +18256,14 @@ const useDismiss = function (context, props) {
18216
18256
  } = props;
18217
18257
  const tree = useFloatingTree();
18218
18258
  const nested = useFloatingParentNodeId() != null;
18219
- const outsidePressFn = useEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
18259
+ const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
18220
18260
  const outsidePress = typeof unstable_outsidePress === 'function' ? outsidePressFn : unstable_outsidePress;
18221
18261
  const insideReactTreeRef = React.useRef(false);
18222
18262
  const {
18223
18263
  escapeKeyBubbles,
18224
18264
  outsidePressBubbles
18225
18265
  } = normalizeBubblesProp(bubbles);
18226
- const closeOnEscapeKeyDown = useEvent(event => {
18266
+ const closeOnEscapeKeyDown = useEffectEvent(event => {
18227
18267
  if (!open || !enabled || !escapeKey || event.key !== 'Escape') {
18228
18268
  return;
18229
18269
  }
@@ -18252,9 +18292,9 @@ const useDismiss = function (context, props) {
18252
18292
  }
18253
18293
  }
18254
18294
  });
18255
- onOpenChange(false);
18295
+ onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event);
18256
18296
  });
18257
- const closeOnPressOutside = useEvent(event => {
18297
+ const closeOnPressOutside = useEffectEvent(event => {
18258
18298
  // Given developers can stop the propagation of the synthetic event,
18259
18299
  // we can only be confident with a positive value.
18260
18300
  const insideReactTree = insideReactTreeRef.current;
@@ -18266,6 +18306,28 @@ const useDismiss = function (context, props) {
18266
18306
  return;
18267
18307
  }
18268
18308
  const target = getTarget(event);
18309
+ const inertSelector = "[" + createAttribute('inert') + "]";
18310
+ const markers = getDocument(floating).querySelectorAll(inertSelector);
18311
+ let targetRootAncestor = isElement(target) ? target : null;
18312
+ while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
18313
+ const nextParent = getParentNode(targetRootAncestor);
18314
+ if (nextParent === getDocument(floating).body || !isElement(nextParent)) {
18315
+ break;
18316
+ } else {
18317
+ targetRootAncestor = nextParent;
18318
+ }
18319
+ }
18320
+
18321
+ // Check if the click occurred on a third-party element injected after the
18322
+ // floating element rendered.
18323
+ if (markers.length && isElement(target) && !isRootElement(target) &&
18324
+ // Clicked on a direct ancestor (e.g. FloatingOverlay).
18325
+ !contains(target, floating) &&
18326
+ // If the target root element contains none of the markers, then the
18327
+ // element was injected after the floating element rendered.
18328
+ Array.from(markers).every(marker => !contains(targetRootAncestor, marker))) {
18329
+ return;
18330
+ }
18269
18331
 
18270
18332
  // Check if the click occurred on the scrollbar
18271
18333
  if (isHTMLElement(target) && floating) {
@@ -18280,7 +18342,7 @@ const useDismiss = function (context, props) {
18280
18342
  // check for. Plus, for modal dialogs with backdrops, it is more
18281
18343
  // important that the backdrop is checked but not so much the window.
18282
18344
  if (canScrollY) {
18283
- const isRTL = getWindow(floating).getComputedStyle(target).direction === 'rtl';
18345
+ const isRTL = getComputedStyle$1(target).direction === 'rtl';
18284
18346
  if (isRTL) {
18285
18347
  xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
18286
18348
  }
@@ -18318,7 +18380,7 @@ const useDismiss = function (context, props) {
18318
18380
  } : isVirtualClick(event) || isVirtualPointerEvent(event)
18319
18381
  }
18320
18382
  });
18321
- onOpenChange(false);
18383
+ onOpenChange(false, event);
18322
18384
  });
18323
18385
  React.useEffect(() => {
18324
18386
  if (!open || !enabled) {
@@ -18326,8 +18388,8 @@ const useDismiss = function (context, props) {
18326
18388
  }
18327
18389
  dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
18328
18390
  dataRef.current.__outsidePressBubbles = outsidePressBubbles;
18329
- function onScroll() {
18330
- onOpenChange(false);
18391
+ function onScroll(event) {
18392
+ onOpenChange(false, event);
18331
18393
  }
18332
18394
  const doc = getDocument(floating);
18333
18395
  escapeKey && doc.addEventListener('keydown', closeOnEscapeKeyDown);
@@ -18373,7 +18435,7 @@ const useDismiss = function (context, props) {
18373
18435
  return {
18374
18436
  reference: {
18375
18437
  onKeyDown: closeOnEscapeKeyDown,
18376
- [bubbleHandlerKeys[referencePressEvent]]: () => {
18438
+ [bubbleHandlerKeys[referencePressEvent]]: event => {
18377
18439
  if (referencePress) {
18378
18440
  events.emit('dismiss', {
18379
18441
  type: 'referencePress',
@@ -18381,7 +18443,7 @@ const useDismiss = function (context, props) {
18381
18443
  returnFocus: false
18382
18444
  }
18383
18445
  });
18384
- onOpenChange(false);
18446
+ onOpenChange(false, event.nativeEvent);
18385
18447
  }
18386
18448
  }
18387
18449
  },
@@ -18393,91 +18455,19 @@ const useDismiss = function (context, props) {
18393
18455
  }
18394
18456
  };
18395
18457
  }, [enabled, events, referencePress, outsidePressEvent, referencePressEvent, onOpenChange, closeOnEscapeKeyDown]);
18396
- };
18397
-
18398
- /**
18399
- * Merges an array of refs into a single memoized callback ref or `null`.
18400
- * @see https://floating-ui.com/docs/useMergeRefs
18401
- */
18402
- function useMergeRefs(refs) {
18403
- return React.useMemo(() => {
18404
- if (refs.every(ref => ref == null)) {
18405
- return null;
18406
- }
18407
- return value => {
18408
- refs.forEach(ref => {
18409
- if (typeof ref === 'function') {
18410
- ref(value);
18411
- } else if (ref != null) {
18412
- ref.current = value;
18413
- }
18414
- });
18415
- };
18416
- // eslint-disable-next-line react-hooks/exhaustive-deps
18417
- }, refs);
18418
18458
  }
18419
18459
 
18420
- /**
18421
- * Adds base screen reader props to the reference and floating elements for a
18422
- * given floating element `role`.
18423
- * @see https://floating-ui.com/docs/useRole
18424
- */
18425
- const useRole = function (context, props) {
18426
- if (props === void 0) {
18427
- props = {};
18428
- }
18429
- const {
18430
- open,
18431
- floatingId
18432
- } = context;
18433
- const {
18434
- enabled = true,
18435
- role = 'dialog'
18436
- } = props;
18437
- const referenceId = useId();
18438
- return React.useMemo(() => {
18439
- const floatingProps = {
18440
- id: floatingId,
18441
- role
18442
- };
18443
- if (!enabled) {
18444
- return {};
18445
- }
18446
- if (role === 'tooltip') {
18447
- return {
18448
- reference: {
18449
- 'aria-describedby': open ? floatingId : undefined
18450
- },
18451
- floating: floatingProps
18452
- };
18453
- }
18454
- return {
18455
- reference: {
18456
- 'aria-expanded': open ? 'true' : 'false',
18457
- 'aria-haspopup': role === 'alertdialog' ? 'dialog' : role,
18458
- 'aria-controls': open ? floatingId : undefined,
18459
- ...(role === 'listbox' && {
18460
- role: 'combobox'
18461
- }),
18462
- ...(role === 'menu' && {
18463
- id: referenceId
18464
- })
18465
- },
18466
- floating: {
18467
- ...floatingProps,
18468
- ...(role === 'menu' && {
18469
- 'aria-labelledby': referenceId
18470
- })
18471
- }
18472
- };
18473
- }, [enabled, role, open, floatingId, referenceId]);
18474
- };
18460
+ let devMessageSet;
18461
+ if (process.env.NODE_ENV !== "production") {
18462
+ devMessageSet = /*#__PURE__*/new Set();
18463
+ }
18475
18464
 
18476
18465
  /**
18477
18466
  * Provides data to position a floating element and context to add interactions.
18478
18467
  * @see https://floating-ui.com/docs/react
18479
18468
  */
18480
18469
  function useFloating(options) {
18470
+ var _options$elements2;
18481
18471
  if (options === void 0) {
18482
18472
  options = {};
18483
18473
  }
@@ -18486,13 +18476,32 @@ function useFloating(options) {
18486
18476
  onOpenChange: unstable_onOpenChange,
18487
18477
  nodeId
18488
18478
  } = options;
18479
+ if (process.env.NODE_ENV !== "production") {
18480
+ var _options$elements;
18481
+ 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.';
18482
+ if ((_options$elements = options.elements) != null && _options$elements.reference && !isElement(options.elements.reference)) {
18483
+ var _devMessageSet;
18484
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(err))) {
18485
+ var _devMessageSet2;
18486
+ (_devMessageSet2 = devMessageSet) == null ? void 0 : _devMessageSet2.add(err);
18487
+ console.error(err);
18488
+ }
18489
+ }
18490
+ }
18491
+ const [_domReference, setDomReference] = React.useState(null);
18492
+ const domReference = ((_options$elements2 = options.elements) == null ? void 0 : _options$elements2.reference) || _domReference;
18489
18493
  const position = useFloating$1(options);
18490
18494
  const tree = useFloatingTree();
18495
+ const onOpenChange = useEffectEvent((open, event) => {
18496
+ if (open) {
18497
+ dataRef.current.openEvent = event;
18498
+ }
18499
+ unstable_onOpenChange == null ? void 0 : unstable_onOpenChange(open, event);
18500
+ });
18491
18501
  const domReferenceRef = React.useRef(null);
18492
18502
  const dataRef = React.useRef({});
18493
18503
  const events = React.useState(() => createPubSub())[0];
18494
18504
  const floatingId = useId();
18495
- const [domReference, setDomReference] = React.useState(null);
18496
18505
  const setPositionReference = React.useCallback(node => {
18497
18506
  const positionReference = isElement(node) ? {
18498
18507
  getBoundingClientRect: () => node.getBoundingClientRect(),
@@ -18526,7 +18535,6 @@ function useFloating(options) {
18526
18535
  ...position.elements,
18527
18536
  domReference: domReference
18528
18537
  }), [position.elements, domReference]);
18529
- const onOpenChange = useEvent(unstable_onOpenChange);
18530
18538
  const context = React.useMemo(() => ({
18531
18539
  ...position,
18532
18540
  refs,
@@ -18548,10 +18556,8 @@ function useFloating(options) {
18548
18556
  ...position,
18549
18557
  context,
18550
18558
  refs,
18551
- elements,
18552
- reference: setReference,
18553
- positionReference: setPositionReference
18554
- }), [position, refs, elements, context, setReference, setPositionReference]);
18559
+ elements
18560
+ }), [position, refs, elements, context]);
18555
18561
  }
18556
18562
 
18557
18563
  function mergeProps(userProps, propsList, elementKey) {
@@ -18590,7 +18596,14 @@ function mergeProps(userProps, propsList, elementKey) {
18590
18596
  }, {})
18591
18597
  };
18592
18598
  }
18593
- const useInteractions = function (propsList) {
18599
+
18600
+ /**
18601
+ * Merges an array of interaction hooks' props into prop getters, allowing
18602
+ * event handler functions to be composed together without overwriting one
18603
+ * another.
18604
+ * @see https://floating-ui.com/docs/react#interaction-hooks
18605
+ */
18606
+ function useInteractions(propsList) {
18594
18607
  if (propsList === void 0) {
18595
18608
  propsList = [];
18596
18609
  }
@@ -18615,7 +18628,63 @@ const useInteractions = function (propsList) {
18615
18628
  getFloatingProps,
18616
18629
  getItemProps
18617
18630
  }), [getReferenceProps, getFloatingProps, getItemProps]);
18618
- };
18631
+ }
18632
+
18633
+ /**
18634
+ * Adds base screen reader props to the reference and floating elements for a
18635
+ * given floating element `role`.
18636
+ * @see https://floating-ui.com/docs/useRole
18637
+ */
18638
+ function useRole(context, props) {
18639
+ if (props === void 0) {
18640
+ props = {};
18641
+ }
18642
+ const {
18643
+ open,
18644
+ floatingId
18645
+ } = context;
18646
+ const {
18647
+ enabled = true,
18648
+ role = 'dialog'
18649
+ } = props;
18650
+ const referenceId = useId();
18651
+ return React.useMemo(() => {
18652
+ const floatingProps = {
18653
+ id: floatingId,
18654
+ role
18655
+ };
18656
+ if (!enabled) {
18657
+ return {};
18658
+ }
18659
+ if (role === 'tooltip') {
18660
+ return {
18661
+ reference: {
18662
+ 'aria-describedby': open ? floatingId : undefined
18663
+ },
18664
+ floating: floatingProps
18665
+ };
18666
+ }
18667
+ return {
18668
+ reference: {
18669
+ 'aria-expanded': open ? 'true' : 'false',
18670
+ 'aria-haspopup': role === 'alertdialog' ? 'dialog' : role,
18671
+ 'aria-controls': open ? floatingId : undefined,
18672
+ ...(role === 'listbox' && {
18673
+ role: 'combobox'
18674
+ }),
18675
+ ...(role === 'menu' && {
18676
+ id: referenceId
18677
+ })
18678
+ },
18679
+ floating: {
18680
+ ...floatingProps,
18681
+ ...(role === 'menu' && {
18682
+ 'aria-labelledby': referenceId
18683
+ })
18684
+ }
18685
+ };
18686
+ }, [enabled, role, open, floatingId, referenceId]);
18687
+ }
18619
18688
 
18620
18689
  /**
18621
18690
  * The hook that powers the Popover component.