@servicetitan/anvil2 1.27.1 → 1.28.0

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