@vonage/vivid 4.4.0 → 4.6.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 (235) hide show
  1. package/custom-elements.json +7181 -6876
  2. package/elevation/index.cjs +1 -1
  3. package/elevation/index.js +1 -1
  4. package/index.cjs +80 -74
  5. package/index.js +23 -22
  6. package/lib/components.d.ts +1 -0
  7. package/lib/fab/fab.d.ts +1 -1
  8. package/lib/icon/icon.d.ts +1 -1
  9. package/lib/menu/menu.d.ts +2 -1
  10. package/lib/number-field/number-field.d.ts +3 -1
  11. package/lib/searchable-select/definition.d.ts +4 -0
  12. package/lib/searchable-select/locale.d.ts +6 -0
  13. package/lib/searchable-select/option-tag.d.ts +14 -0
  14. package/lib/searchable-select/option-tag.template.d.ts +4 -0
  15. package/lib/searchable-select/searchable-select.d.ts +29 -0
  16. package/lib/searchable-select/searchable-select.form-associated.d.ts +10 -0
  17. package/lib/searchable-select/searchable-select.template.d.ts +4 -0
  18. package/lib/select/select.d.ts +4 -1
  19. package/lib/tab/locale.d.ts +3 -0
  20. package/lib/tab/tab.d.ts +5 -1
  21. package/lib/tabs/tabs.d.ts +2 -0
  22. package/lib/tag/definition.d.ts +1 -0
  23. package/lib/text-field/text-field.d.ts +3 -1
  24. package/lib/video-player/video-player.d.ts +0 -1
  25. package/listbox/index.cjs +1 -1
  26. package/listbox/index.js +1 -1
  27. package/locales/de-DE.cjs +12 -0
  28. package/locales/de-DE.js +12 -0
  29. package/locales/en-GB.cjs +12 -0
  30. package/locales/en-GB.js +12 -0
  31. package/locales/en-US.cjs +12 -0
  32. package/locales/en-US.js +12 -0
  33. package/locales/ja-JP.cjs +12 -0
  34. package/locales/ja-JP.js +12 -0
  35. package/locales/zh-CN.cjs +12 -0
  36. package/locales/zh-CN.js +12 -0
  37. package/package.json +6 -1
  38. package/popup/index.cjs +1 -1
  39. package/popup/index.js +1 -1
  40. package/searchable-select/index.cjs +5 -0
  41. package/searchable-select/index.js +3 -0
  42. package/select/index.cjs +1 -1
  43. package/select/index.js +1 -1
  44. package/selectable-box/index.cjs +1 -1
  45. package/selectable-box/index.js +1 -1
  46. package/shared/anchored.js +1 -1
  47. package/shared/calendar-event.js +1 -1
  48. package/shared/definition.cjs +2 -2
  49. package/shared/definition.js +2 -2
  50. package/shared/definition11.cjs +1 -1
  51. package/shared/definition11.js +1 -1
  52. package/shared/definition12.cjs +1 -1
  53. package/shared/definition12.js +1 -1
  54. package/shared/definition13.js +1 -1
  55. package/shared/definition14.cjs +1 -1
  56. package/shared/definition14.js +1 -1
  57. package/shared/definition15.cjs +7 -8
  58. package/shared/definition15.js +2 -3
  59. package/shared/definition16.cjs +11 -7
  60. package/shared/definition16.js +10 -6
  61. package/shared/definition17.cjs +2 -2
  62. package/shared/definition17.js +2 -2
  63. package/shared/definition18.cjs +5 -6
  64. package/shared/definition18.js +3 -4
  65. package/shared/definition19.cjs +5 -6
  66. package/shared/definition19.js +3 -4
  67. package/shared/definition20.cjs +16 -38
  68. package/shared/definition20.js +17 -39
  69. package/shared/definition21.cjs +7 -6
  70. package/shared/definition21.js +8 -7
  71. package/shared/definition23.cjs +1 -1
  72. package/shared/definition23.js +2 -2
  73. package/shared/definition24.cjs +2 -2
  74. package/shared/definition24.js +2 -2
  75. package/shared/definition25.cjs +6 -7
  76. package/shared/definition25.js +2 -3
  77. package/shared/definition26.cjs +1 -1
  78. package/shared/definition26.js +2 -2
  79. package/shared/definition27.cjs +1 -1
  80. package/shared/definition27.js +1 -1
  81. package/shared/definition28.js +1 -1
  82. package/shared/definition29.cjs +8 -4
  83. package/shared/definition29.js +8 -4
  84. package/shared/definition3.cjs +1 -1
  85. package/shared/definition3.js +2 -2
  86. package/shared/definition30.cjs +4 -2
  87. package/shared/definition30.js +4 -2
  88. package/shared/definition31.cjs +1 -1
  89. package/shared/definition31.js +2 -2
  90. package/shared/definition32.cjs +1 -1
  91. package/shared/definition32.js +1 -1
  92. package/shared/definition34.cjs +2 -3
  93. package/shared/definition34.js +2 -3
  94. package/shared/definition35.cjs +21 -16
  95. package/shared/definition35.js +16 -11
  96. package/shared/definition36.cjs +50 -207
  97. package/shared/definition36.js +51 -207
  98. package/shared/definition37.js +1 -1
  99. package/shared/definition38.cjs +1 -1
  100. package/shared/definition38.js +1 -1
  101. package/shared/definition4.cjs +6 -4
  102. package/shared/definition4.js +7 -5
  103. package/shared/definition41.cjs +1 -1
  104. package/shared/definition41.js +1 -1
  105. package/shared/definition42.cjs +6 -7
  106. package/shared/definition42.js +6 -7
  107. package/shared/definition43.cjs +998 -643
  108. package/shared/definition43.js +992 -638
  109. package/shared/definition44.cjs +723 -112
  110. package/shared/definition44.js +722 -111
  111. package/shared/definition45.cjs +121 -79
  112. package/shared/definition45.js +120 -78
  113. package/shared/definition46.cjs +81 -616
  114. package/shared/definition46.js +80 -614
  115. package/shared/definition47.cjs +609 -116
  116. package/shared/definition47.js +607 -115
  117. package/shared/definition48.cjs +116 -134
  118. package/shared/definition48.js +115 -133
  119. package/shared/definition49.cjs +149 -19
  120. package/shared/definition49.js +148 -18
  121. package/shared/definition5.cjs +5 -6
  122. package/shared/definition5.js +5 -6
  123. package/shared/definition50.cjs +21 -82
  124. package/shared/definition50.js +20 -81
  125. package/shared/definition51.cjs +78 -494
  126. package/shared/definition51.js +77 -493
  127. package/shared/definition52.cjs +568 -28
  128. package/shared/definition52.js +567 -27
  129. package/shared/definition53.cjs +28 -123
  130. package/shared/definition53.js +27 -123
  131. package/shared/definition54.cjs +115 -296
  132. package/shared/definition54.js +114 -295
  133. package/shared/definition55.cjs +258 -318
  134. package/shared/definition55.js +252 -312
  135. package/shared/definition56.cjs +303 -784
  136. package/shared/definition56.js +298 -779
  137. package/shared/definition57.cjs +802 -95
  138. package/shared/definition57.js +801 -94
  139. package/shared/definition58.cjs +95 -60
  140. package/shared/definition58.js +94 -59
  141. package/shared/definition59.cjs +117 -75
  142. package/shared/definition59.js +116 -74
  143. package/shared/definition6.cjs +1 -1
  144. package/shared/definition6.js +1 -1
  145. package/shared/definition60.cjs +70 -285
  146. package/shared/definition60.js +71 -286
  147. package/shared/definition61.cjs +296 -325
  148. package/shared/definition61.js +295 -324
  149. package/shared/definition62.cjs +66160 -27
  150. package/shared/definition62.js +66159 -26
  151. package/shared/definition63.cjs +24 -1952
  152. package/shared/definition63.js +23 -1950
  153. package/shared/definition64.cjs +1976 -0
  154. package/shared/definition64.js +1971 -0
  155. package/shared/definition7.cjs +1 -1
  156. package/shared/definition7.js +1 -1
  157. package/shared/definition8.cjs +2 -3
  158. package/shared/definition8.js +3 -4
  159. package/shared/definition9.cjs +1 -1
  160. package/shared/definition9.js +1 -1
  161. package/shared/dialog/index.d.ts +1 -0
  162. package/shared/form-elements.cjs +236 -0
  163. package/shared/form-elements.js +229 -0
  164. package/shared/icon.js +1 -1
  165. package/shared/index2.cjs +6 -256
  166. package/shared/index2.js +6 -249
  167. package/shared/listbox-option.cjs +204 -0
  168. package/shared/listbox-option.js +201 -0
  169. package/shared/listbox.cjs +3 -3
  170. package/shared/listbox.js +1 -1
  171. package/shared/localization/Locale.d.ts +4 -0
  172. package/shared/localized.cjs +26 -2
  173. package/shared/localized.js +25 -2
  174. package/shared/playbackRates.cjs +13 -0
  175. package/shared/playbackRates.js +11 -0
  176. package/shared/presentationDate.cjs +11 -11
  177. package/shared/presentationDate.js +11 -11
  178. package/shared/scrollIntoView.cjs +51 -0
  179. package/shared/scrollIntoView.js +49 -0
  180. package/shared/slider.template.cjs +1 -1
  181. package/shared/slider.template.js +1 -1
  182. package/shared/text-anchor.cjs +1 -1
  183. package/shared/text-anchor.js +1 -1
  184. package/shared/text-field.cjs +1 -1
  185. package/shared/text-field.js +1 -1
  186. package/shared/utils/playbackRates.d.ts +1 -0
  187. package/shared/utils/scrollIntoView.d.ts +1 -0
  188. package/side-drawer/index.cjs +1 -1
  189. package/side-drawer/index.js +1 -1
  190. package/slider/index.cjs +1 -1
  191. package/slider/index.js +1 -1
  192. package/split-button/index.cjs +1 -1
  193. package/split-button/index.js +1 -1
  194. package/styles/core/all.css +1 -1
  195. package/styles/core/theme.css +1 -1
  196. package/styles/core/typography.css +1 -1
  197. package/styles/tokens/theme-dark.css +4 -4
  198. package/styles/tokens/theme-light.css +4 -4
  199. package/styles/tokens/vivid-2-compat.css +1 -1
  200. package/switch/index.cjs +1 -1
  201. package/switch/index.js +1 -1
  202. package/tab/index.cjs +1 -1
  203. package/tab/index.js +1 -1
  204. package/tab-panel/index.cjs +1 -1
  205. package/tab-panel/index.js +1 -1
  206. package/tabs/index.cjs +1 -1
  207. package/tabs/index.js +1 -1
  208. package/tag/index.cjs +1 -1
  209. package/tag/index.js +1 -1
  210. package/tag-group/index.cjs +1 -1
  211. package/tag-group/index.js +1 -1
  212. package/text-area/index.cjs +1 -1
  213. package/text-area/index.js +1 -1
  214. package/text-field/index.cjs +1 -1
  215. package/text-field/index.js +1 -1
  216. package/time-picker/index.cjs +1 -1
  217. package/time-picker/index.js +1 -1
  218. package/toggletip/index.cjs +1 -1
  219. package/toggletip/index.js +1 -1
  220. package/tooltip/index.cjs +1 -1
  221. package/tooltip/index.js +1 -1
  222. package/tree-item/index.cjs +1 -1
  223. package/tree-item/index.js +1 -1
  224. package/tree-view/index.cjs +1 -1
  225. package/tree-view/index.js +1 -1
  226. package/video-player/index.cjs +1 -1
  227. package/video-player/index.js +1 -1
  228. package/vivid.api.json +312 -8
  229. package/appearance-ui/index.cjs +0 -102
  230. package/appearance-ui/index.js +0 -100
  231. package/lib/appearance-ui/appearance-ui.d.ts +0 -12
  232. package/lib/appearance-ui/appearance-ui.template.d.ts +0 -4
  233. package/lib/appearance-ui/definition.d.ts +0 -3
  234. package/shared/video-player.cjs +0 -65860
  235. package/shared/video-player.js +0 -65857
@@ -0,0 +1,1976 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ const definition$1 = require('./definition11.cjs');
5
+ const definition = require('./definition63.cjs');
6
+ const ref = require('./ref.cjs');
7
+ const when = require('./when.cjs');
8
+ const classNames = require('./class-names.cjs');
9
+
10
+ const sides = ['top', 'right', 'bottom', 'left'];
11
+ const alignments = ['start', 'end'];
12
+ const placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []);
13
+ const min = Math.min;
14
+ const max = Math.max;
15
+ const round = Math.round;
16
+ const floor = Math.floor;
17
+ const createCoords = v => ({
18
+ x: v,
19
+ y: v
20
+ });
21
+ const oppositeSideMap = {
22
+ left: 'right',
23
+ right: 'left',
24
+ bottom: 'top',
25
+ top: 'bottom'
26
+ };
27
+ const oppositeAlignmentMap = {
28
+ start: 'end',
29
+ end: 'start'
30
+ };
31
+ function clamp(start, value, end) {
32
+ return max(start, min(value, end));
33
+ }
34
+ function evaluate(value, param) {
35
+ return typeof value === 'function' ? value(param) : value;
36
+ }
37
+ function getSide(placement) {
38
+ return placement.split('-')[0];
39
+ }
40
+ function getAlignment(placement) {
41
+ return placement.split('-')[1];
42
+ }
43
+ function getOppositeAxis(axis) {
44
+ return axis === 'x' ? 'y' : 'x';
45
+ }
46
+ function getAxisLength(axis) {
47
+ return axis === 'y' ? 'height' : 'width';
48
+ }
49
+ function getSideAxis(placement) {
50
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
51
+ }
52
+ function getAlignmentAxis(placement) {
53
+ return getOppositeAxis(getSideAxis(placement));
54
+ }
55
+ function getAlignmentSides(placement, rects, rtl) {
56
+ if (rtl === void 0) {
57
+ rtl = false;
58
+ }
59
+ const alignment = getAlignment(placement);
60
+ const alignmentAxis = getAlignmentAxis(placement);
61
+ const length = getAxisLength(alignmentAxis);
62
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
63
+ if (rects.reference[length] > rects.floating[length]) {
64
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
65
+ }
66
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
67
+ }
68
+ function getExpandedPlacements(placement) {
69
+ const oppositePlacement = getOppositePlacement(placement);
70
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
71
+ }
72
+ function getOppositeAlignmentPlacement(placement) {
73
+ return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
74
+ }
75
+ function getSideList(side, isStart, rtl) {
76
+ const lr = ['left', 'right'];
77
+ const rl = ['right', 'left'];
78
+ const tb = ['top', 'bottom'];
79
+ const bt = ['bottom', 'top'];
80
+ switch (side) {
81
+ case 'top':
82
+ case 'bottom':
83
+ if (rtl) return isStart ? rl : lr;
84
+ return isStart ? lr : rl;
85
+ case 'left':
86
+ case 'right':
87
+ return isStart ? tb : bt;
88
+ default:
89
+ return [];
90
+ }
91
+ }
92
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
93
+ const alignment = getAlignment(placement);
94
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
95
+ if (alignment) {
96
+ list = list.map(side => side + "-" + alignment);
97
+ if (flipAlignment) {
98
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
99
+ }
100
+ }
101
+ return list;
102
+ }
103
+ function getOppositePlacement(placement) {
104
+ return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
105
+ }
106
+ function expandPaddingObject(padding) {
107
+ return {
108
+ top: 0,
109
+ right: 0,
110
+ bottom: 0,
111
+ left: 0,
112
+ ...padding
113
+ };
114
+ }
115
+ function getPaddingObject(padding) {
116
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
117
+ top: padding,
118
+ right: padding,
119
+ bottom: padding,
120
+ left: padding
121
+ };
122
+ }
123
+ function rectToClientRect(rect) {
124
+ return {
125
+ ...rect,
126
+ top: rect.y,
127
+ left: rect.x,
128
+ right: rect.x + rect.width,
129
+ bottom: rect.y + rect.height
130
+ };
131
+ }
132
+
133
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
134
+ let {
135
+ reference,
136
+ floating
137
+ } = _ref;
138
+ const sideAxis = getSideAxis(placement);
139
+ const alignmentAxis = getAlignmentAxis(placement);
140
+ const alignLength = getAxisLength(alignmentAxis);
141
+ const side = getSide(placement);
142
+ const isVertical = sideAxis === 'y';
143
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
144
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
145
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
146
+ let coords;
147
+ switch (side) {
148
+ case 'top':
149
+ coords = {
150
+ x: commonX,
151
+ y: reference.y - floating.height
152
+ };
153
+ break;
154
+ case 'bottom':
155
+ coords = {
156
+ x: commonX,
157
+ y: reference.y + reference.height
158
+ };
159
+ break;
160
+ case 'right':
161
+ coords = {
162
+ x: reference.x + reference.width,
163
+ y: commonY
164
+ };
165
+ break;
166
+ case 'left':
167
+ coords = {
168
+ x: reference.x - floating.width,
169
+ y: commonY
170
+ };
171
+ break;
172
+ default:
173
+ coords = {
174
+ x: reference.x,
175
+ y: reference.y
176
+ };
177
+ }
178
+ switch (getAlignment(placement)) {
179
+ case 'start':
180
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
181
+ break;
182
+ case 'end':
183
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
184
+ break;
185
+ }
186
+ return coords;
187
+ }
188
+
189
+ /**
190
+ * Computes the `x` and `y` coordinates that will place the floating element
191
+ * next to a reference element when it is given a certain positioning strategy.
192
+ *
193
+ * This export does not have any `platform` interface logic. You will need to
194
+ * write one for the platform you are using Floating UI with.
195
+ */
196
+ const computePosition$1 = async (reference, floating, config) => {
197
+ const {
198
+ placement = 'bottom',
199
+ strategy = 'absolute',
200
+ middleware = [],
201
+ platform
202
+ } = config;
203
+ const validMiddleware = middleware.filter(Boolean);
204
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
205
+ let rects = await platform.getElementRects({
206
+ reference,
207
+ floating,
208
+ strategy
209
+ });
210
+ let {
211
+ x,
212
+ y
213
+ } = computeCoordsFromPlacement(rects, placement, rtl);
214
+ let statefulPlacement = placement;
215
+ let middlewareData = {};
216
+ let resetCount = 0;
217
+ for (let i = 0; i < validMiddleware.length; i++) {
218
+ const {
219
+ name,
220
+ fn
221
+ } = validMiddleware[i];
222
+ const {
223
+ x: nextX,
224
+ y: nextY,
225
+ data,
226
+ reset
227
+ } = await fn({
228
+ x,
229
+ y,
230
+ initialPlacement: placement,
231
+ placement: statefulPlacement,
232
+ strategy,
233
+ middlewareData,
234
+ rects,
235
+ platform,
236
+ elements: {
237
+ reference,
238
+ floating
239
+ }
240
+ });
241
+ x = nextX != null ? nextX : x;
242
+ y = nextY != null ? nextY : y;
243
+ middlewareData = {
244
+ ...middlewareData,
245
+ [name]: {
246
+ ...middlewareData[name],
247
+ ...data
248
+ }
249
+ };
250
+ if (reset && resetCount <= 50) {
251
+ resetCount++;
252
+ if (typeof reset === 'object') {
253
+ if (reset.placement) {
254
+ statefulPlacement = reset.placement;
255
+ }
256
+ if (reset.rects) {
257
+ rects = reset.rects === true ? await platform.getElementRects({
258
+ reference,
259
+ floating,
260
+ strategy
261
+ }) : reset.rects;
262
+ }
263
+ ({
264
+ x,
265
+ y
266
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
267
+ }
268
+ i = -1;
269
+ continue;
270
+ }
271
+ }
272
+ return {
273
+ x,
274
+ y,
275
+ placement: statefulPlacement,
276
+ strategy,
277
+ middlewareData
278
+ };
279
+ };
280
+
281
+ /**
282
+ * Resolves with an object of overflow side offsets that determine how much the
283
+ * element is overflowing a given clipping boundary on each side.
284
+ * - positive = overflowing the boundary by that number of pixels
285
+ * - negative = how many pixels left before it will overflow
286
+ * - 0 = lies flush with the boundary
287
+ * @see https://floating-ui.com/docs/detectOverflow
288
+ */
289
+ async function detectOverflow(state, options) {
290
+ var _await$platform$isEle;
291
+ if (options === void 0) {
292
+ options = {};
293
+ }
294
+ const {
295
+ x,
296
+ y,
297
+ platform,
298
+ rects,
299
+ elements,
300
+ strategy
301
+ } = state;
302
+ const {
303
+ boundary = 'clippingAncestors',
304
+ rootBoundary = 'viewport',
305
+ elementContext = 'floating',
306
+ altBoundary = false,
307
+ padding = 0
308
+ } = evaluate(options, state);
309
+ const paddingObject = getPaddingObject(padding);
310
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
311
+ const element = elements[altBoundary ? altContext : elementContext];
312
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
313
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
314
+ boundary,
315
+ rootBoundary,
316
+ strategy
317
+ }));
318
+ const rect = elementContext === 'floating' ? {
319
+ ...rects.floating,
320
+ x,
321
+ y
322
+ } : rects.reference;
323
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
324
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
325
+ x: 1,
326
+ y: 1
327
+ } : {
328
+ x: 1,
329
+ y: 1
330
+ };
331
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
332
+ rect,
333
+ offsetParent,
334
+ strategy
335
+ }) : rect);
336
+ return {
337
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
338
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
339
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
340
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
341
+ };
342
+ }
343
+
344
+ /**
345
+ * Provides data to position an inner element of the floating element so that it
346
+ * appears centered to the reference element.
347
+ * @see https://floating-ui.com/docs/arrow
348
+ */
349
+ const arrow = options => ({
350
+ name: 'arrow',
351
+ options,
352
+ async fn(state) {
353
+ const {
354
+ x,
355
+ y,
356
+ placement,
357
+ rects,
358
+ platform,
359
+ elements,
360
+ middlewareData
361
+ } = state;
362
+ // Since `element` is required, we don't Partial<> the type.
363
+ const {
364
+ element,
365
+ padding = 0
366
+ } = evaluate(options, state) || {};
367
+ if (element == null) {
368
+ return {};
369
+ }
370
+ const paddingObject = getPaddingObject(padding);
371
+ const coords = {
372
+ x,
373
+ y
374
+ };
375
+ const axis = getAlignmentAxis(placement);
376
+ const length = getAxisLength(axis);
377
+ const arrowDimensions = await platform.getDimensions(element);
378
+ const isYAxis = axis === 'y';
379
+ const minProp = isYAxis ? 'top' : 'left';
380
+ const maxProp = isYAxis ? 'bottom' : 'right';
381
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
382
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
383
+ const startDiff = coords[axis] - rects.reference[axis];
384
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
385
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
386
+
387
+ // DOM platform can return `window` as the `offsetParent`.
388
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
389
+ clientSize = elements.floating[clientProp] || rects.floating[length];
390
+ }
391
+ const centerToReference = endDiff / 2 - startDiff / 2;
392
+
393
+ // If the padding is large enough that it causes the arrow to no longer be
394
+ // centered, modify the padding so that it is centered.
395
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
396
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
397
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
398
+
399
+ // Make sure the arrow doesn't overflow the floating element if the center
400
+ // point is outside the floating element's bounds.
401
+ const min$1 = minPadding;
402
+ const max = clientSize - arrowDimensions[length] - maxPadding;
403
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
404
+ const offset = clamp(min$1, center, max);
405
+
406
+ // If the reference is small enough that the arrow's padding causes it to
407
+ // to point to nothing for an aligned placement, adjust the offset of the
408
+ // floating element itself. To ensure `shift()` continues to take action,
409
+ // a single reset is performed when this is true.
410
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
411
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
412
+ return {
413
+ [axis]: coords[axis] + alignmentOffset,
414
+ data: {
415
+ [axis]: offset,
416
+ centerOffset: center - offset - alignmentOffset,
417
+ ...(shouldAddOffset && {
418
+ alignmentOffset
419
+ })
420
+ },
421
+ reset: shouldAddOffset
422
+ };
423
+ }
424
+ });
425
+
426
+ function getPlacementList(alignment, autoAlignment, allowedPlacements) {
427
+ const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);
428
+ return allowedPlacementsSortedByAlignment.filter(placement => {
429
+ if (alignment) {
430
+ return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
431
+ }
432
+ return true;
433
+ });
434
+ }
435
+ /**
436
+ * Optimizes the visibility of the floating element by choosing the placement
437
+ * that has the most space available automatically, without needing to specify a
438
+ * preferred placement. Alternative to `flip`.
439
+ * @see https://floating-ui.com/docs/autoPlacement
440
+ */
441
+ const autoPlacement = function (options) {
442
+ if (options === void 0) {
443
+ options = {};
444
+ }
445
+ return {
446
+ name: 'autoPlacement',
447
+ options,
448
+ async fn(state) {
449
+ var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
450
+ const {
451
+ rects,
452
+ middlewareData,
453
+ placement,
454
+ platform,
455
+ elements
456
+ } = state;
457
+ const {
458
+ crossAxis = false,
459
+ alignment,
460
+ allowedPlacements = placements,
461
+ autoAlignment = true,
462
+ ...detectOverflowOptions
463
+ } = evaluate(options, state);
464
+ const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
465
+ const overflow = await detectOverflow(state, detectOverflowOptions);
466
+ const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
467
+ const currentPlacement = placements$1[currentIndex];
468
+ if (currentPlacement == null) {
469
+ return {};
470
+ }
471
+ const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
472
+
473
+ // Make `computeCoords` start from the right place.
474
+ if (placement !== currentPlacement) {
475
+ return {
476
+ reset: {
477
+ placement: placements$1[0]
478
+ }
479
+ };
480
+ }
481
+ const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
482
+ const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {
483
+ placement: currentPlacement,
484
+ overflows: currentOverflows
485
+ }];
486
+ const nextPlacement = placements$1[currentIndex + 1];
487
+
488
+ // There are more placements to check.
489
+ if (nextPlacement) {
490
+ return {
491
+ data: {
492
+ index: currentIndex + 1,
493
+ overflows: allOverflows
494
+ },
495
+ reset: {
496
+ placement: nextPlacement
497
+ }
498
+ };
499
+ }
500
+ const placementsSortedByMostSpace = allOverflows.map(d => {
501
+ const alignment = getAlignment(d.placement);
502
+ return [d.placement, alignment && crossAxis ?
503
+ // Check along the mainAxis and main crossAxis side.
504
+ d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :
505
+ // Check only the mainAxis.
506
+ d.overflows[0], d.overflows];
507
+ }).sort((a, b) => a[1] - b[1]);
508
+ const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,
509
+ // Aligned placements should not check their opposite crossAxis
510
+ // side.
511
+ getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));
512
+ const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
513
+ if (resetPlacement !== placement) {
514
+ return {
515
+ data: {
516
+ index: currentIndex + 1,
517
+ overflows: allOverflows
518
+ },
519
+ reset: {
520
+ placement: resetPlacement
521
+ }
522
+ };
523
+ }
524
+ return {};
525
+ }
526
+ };
527
+ };
528
+
529
+ /**
530
+ * Optimizes the visibility of the floating element by flipping the `placement`
531
+ * in order to keep it in view when the preferred placement(s) will overflow the
532
+ * clipping boundary. Alternative to `autoPlacement`.
533
+ * @see https://floating-ui.com/docs/flip
534
+ */
535
+ const flip = function (options) {
536
+ if (options === void 0) {
537
+ options = {};
538
+ }
539
+ return {
540
+ name: 'flip',
541
+ options,
542
+ async fn(state) {
543
+ var _middlewareData$arrow, _middlewareData$flip;
544
+ const {
545
+ placement,
546
+ middlewareData,
547
+ rects,
548
+ initialPlacement,
549
+ platform,
550
+ elements
551
+ } = state;
552
+ const {
553
+ mainAxis: checkMainAxis = true,
554
+ crossAxis: checkCrossAxis = true,
555
+ fallbackPlacements: specifiedFallbackPlacements,
556
+ fallbackStrategy = 'bestFit',
557
+ fallbackAxisSideDirection = 'none',
558
+ flipAlignment = true,
559
+ ...detectOverflowOptions
560
+ } = evaluate(options, state);
561
+
562
+ // If a reset by the arrow was caused due to an alignment offset being
563
+ // added, we should skip any logic now since `flip()` has already done its
564
+ // work.
565
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
566
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
567
+ return {};
568
+ }
569
+ const side = getSide(placement);
570
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
571
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
572
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
573
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
574
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
575
+ }
576
+ const placements = [initialPlacement, ...fallbackPlacements];
577
+ const overflow = await detectOverflow(state, detectOverflowOptions);
578
+ const overflows = [];
579
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
580
+ if (checkMainAxis) {
581
+ overflows.push(overflow[side]);
582
+ }
583
+ if (checkCrossAxis) {
584
+ const sides = getAlignmentSides(placement, rects, rtl);
585
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
586
+ }
587
+ overflowsData = [...overflowsData, {
588
+ placement,
589
+ overflows
590
+ }];
591
+
592
+ // One or more sides is overflowing.
593
+ if (!overflows.every(side => side <= 0)) {
594
+ var _middlewareData$flip2, _overflowsData$filter;
595
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
596
+ const nextPlacement = placements[nextIndex];
597
+ if (nextPlacement) {
598
+ // Try next placement and re-run the lifecycle.
599
+ return {
600
+ data: {
601
+ index: nextIndex,
602
+ overflows: overflowsData
603
+ },
604
+ reset: {
605
+ placement: nextPlacement
606
+ }
607
+ };
608
+ }
609
+
610
+ // First, find the candidates that fit on the mainAxis side of overflow,
611
+ // then find the placement that fits the best on the main crossAxis side.
612
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
613
+
614
+ // Otherwise fallback.
615
+ if (!resetPlacement) {
616
+ switch (fallbackStrategy) {
617
+ case 'bestFit':
618
+ {
619
+ var _overflowsData$map$so;
620
+ const placement = (_overflowsData$map$so = overflowsData.map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0];
621
+ if (placement) {
622
+ resetPlacement = placement;
623
+ }
624
+ break;
625
+ }
626
+ case 'initialPlacement':
627
+ resetPlacement = initialPlacement;
628
+ break;
629
+ }
630
+ }
631
+ if (placement !== resetPlacement) {
632
+ return {
633
+ reset: {
634
+ placement: resetPlacement
635
+ }
636
+ };
637
+ }
638
+ }
639
+ return {};
640
+ }
641
+ };
642
+ };
643
+
644
+ function getSideOffsets(overflow, rect) {
645
+ return {
646
+ top: overflow.top - rect.height,
647
+ right: overflow.right - rect.width,
648
+ bottom: overflow.bottom - rect.height,
649
+ left: overflow.left - rect.width
650
+ };
651
+ }
652
+ function isAnySideFullyClipped(overflow) {
653
+ return sides.some(side => overflow[side] >= 0);
654
+ }
655
+ /**
656
+ * Provides data to hide the floating element in applicable situations, such as
657
+ * when it is not in the same clipping context as the reference element.
658
+ * @see https://floating-ui.com/docs/hide
659
+ */
660
+ const hide = function (options) {
661
+ if (options === void 0) {
662
+ options = {};
663
+ }
664
+ return {
665
+ name: 'hide',
666
+ options,
667
+ async fn(state) {
668
+ const {
669
+ rects
670
+ } = state;
671
+ const {
672
+ strategy = 'referenceHidden',
673
+ ...detectOverflowOptions
674
+ } = evaluate(options, state);
675
+ switch (strategy) {
676
+ case 'referenceHidden':
677
+ {
678
+ const overflow = await detectOverflow(state, {
679
+ ...detectOverflowOptions,
680
+ elementContext: 'reference'
681
+ });
682
+ const offsets = getSideOffsets(overflow, rects.reference);
683
+ return {
684
+ data: {
685
+ referenceHiddenOffsets: offsets,
686
+ referenceHidden: isAnySideFullyClipped(offsets)
687
+ }
688
+ };
689
+ }
690
+ case 'escaped':
691
+ {
692
+ const overflow = await detectOverflow(state, {
693
+ ...detectOverflowOptions,
694
+ altBoundary: true
695
+ });
696
+ const offsets = getSideOffsets(overflow, rects.floating);
697
+ return {
698
+ data: {
699
+ escapedOffsets: offsets,
700
+ escaped: isAnySideFullyClipped(offsets)
701
+ }
702
+ };
703
+ }
704
+ default:
705
+ {
706
+ return {};
707
+ }
708
+ }
709
+ }
710
+ };
711
+ };
712
+
713
+ function getBoundingRect(rects) {
714
+ const minX = min(...rects.map(rect => rect.left));
715
+ const minY = min(...rects.map(rect => rect.top));
716
+ const maxX = max(...rects.map(rect => rect.right));
717
+ const maxY = max(...rects.map(rect => rect.bottom));
718
+ return {
719
+ x: minX,
720
+ y: minY,
721
+ width: maxX - minX,
722
+ height: maxY - minY
723
+ };
724
+ }
725
+ function getRectsByLine(rects) {
726
+ const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
727
+ const groups = [];
728
+ let prevRect = null;
729
+ for (let i = 0; i < sortedRects.length; i++) {
730
+ const rect = sortedRects[i];
731
+ if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
732
+ groups.push([rect]);
733
+ } else {
734
+ groups[groups.length - 1].push(rect);
735
+ }
736
+ prevRect = rect;
737
+ }
738
+ return groups.map(rect => rectToClientRect(getBoundingRect(rect)));
739
+ }
740
+ /**
741
+ * Provides improved positioning for inline reference elements that can span
742
+ * over multiple lines, such as hyperlinks or range selections.
743
+ * @see https://floating-ui.com/docs/inline
744
+ */
745
+ const inline = function (options) {
746
+ if (options === void 0) {
747
+ options = {};
748
+ }
749
+ return {
750
+ name: 'inline',
751
+ options,
752
+ async fn(state) {
753
+ const {
754
+ placement,
755
+ elements,
756
+ rects,
757
+ platform,
758
+ strategy
759
+ } = state;
760
+ // A MouseEvent's client{X,Y} coords can be up to 2 pixels off a
761
+ // ClientRect's bounds, despite the event listener being triggered. A
762
+ // padding of 2 seems to handle this issue.
763
+ const {
764
+ padding = 2,
765
+ x,
766
+ y
767
+ } = evaluate(options, state);
768
+ const nativeClientRects = Array.from((await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference))) || []);
769
+ const clientRects = getRectsByLine(nativeClientRects);
770
+ const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
771
+ const paddingObject = getPaddingObject(padding);
772
+ function getBoundingClientRect() {
773
+ // There are two rects and they are disjoined.
774
+ if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
775
+ // Find the first rect in which the point is fully inside.
776
+ return clientRects.find(rect => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback;
777
+ }
778
+
779
+ // There are 2 or more connected rects.
780
+ if (clientRects.length >= 2) {
781
+ if (getSideAxis(placement) === 'y') {
782
+ const firstRect = clientRects[0];
783
+ const lastRect = clientRects[clientRects.length - 1];
784
+ const isTop = getSide(placement) === 'top';
785
+ const top = firstRect.top;
786
+ const bottom = lastRect.bottom;
787
+ const left = isTop ? firstRect.left : lastRect.left;
788
+ const right = isTop ? firstRect.right : lastRect.right;
789
+ const width = right - left;
790
+ const height = bottom - top;
791
+ return {
792
+ top,
793
+ bottom,
794
+ left,
795
+ right,
796
+ width,
797
+ height,
798
+ x: left,
799
+ y: top
800
+ };
801
+ }
802
+ const isLeftSide = getSide(placement) === 'left';
803
+ const maxRight = max(...clientRects.map(rect => rect.right));
804
+ const minLeft = min(...clientRects.map(rect => rect.left));
805
+ const measureRects = clientRects.filter(rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
806
+ const top = measureRects[0].top;
807
+ const bottom = measureRects[measureRects.length - 1].bottom;
808
+ const left = minLeft;
809
+ const right = maxRight;
810
+ const width = right - left;
811
+ const height = bottom - top;
812
+ return {
813
+ top,
814
+ bottom,
815
+ left,
816
+ right,
817
+ width,
818
+ height,
819
+ x: left,
820
+ y: top
821
+ };
822
+ }
823
+ return fallback;
824
+ }
825
+ const resetRects = await platform.getElementRects({
826
+ reference: {
827
+ getBoundingClientRect
828
+ },
829
+ floating: elements.floating,
830
+ strategy
831
+ });
832
+ if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
833
+ return {
834
+ reset: {
835
+ rects: resetRects
836
+ }
837
+ };
838
+ }
839
+ return {};
840
+ }
841
+ };
842
+ };
843
+
844
+ // For type backwards-compatibility, the `OffsetOptions` type was also
845
+ // Derivable.
846
+ async function convertValueToCoords(state, options) {
847
+ const {
848
+ placement,
849
+ platform,
850
+ elements
851
+ } = state;
852
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
853
+ const side = getSide(placement);
854
+ const alignment = getAlignment(placement);
855
+ const isVertical = getSideAxis(placement) === 'y';
856
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
857
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
858
+ const rawValue = evaluate(options, state);
859
+
860
+ // eslint-disable-next-line prefer-const
861
+ let {
862
+ mainAxis,
863
+ crossAxis,
864
+ alignmentAxis
865
+ } = typeof rawValue === 'number' ? {
866
+ mainAxis: rawValue,
867
+ crossAxis: 0,
868
+ alignmentAxis: null
869
+ } : {
870
+ mainAxis: 0,
871
+ crossAxis: 0,
872
+ alignmentAxis: null,
873
+ ...rawValue
874
+ };
875
+ if (alignment && typeof alignmentAxis === 'number') {
876
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
877
+ }
878
+ return isVertical ? {
879
+ x: crossAxis * crossAxisMulti,
880
+ y: mainAxis * mainAxisMulti
881
+ } : {
882
+ x: mainAxis * mainAxisMulti,
883
+ y: crossAxis * crossAxisMulti
884
+ };
885
+ }
886
+
887
+ /**
888
+ * Modifies the placement by translating the floating element along the
889
+ * specified axes.
890
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
891
+ * object may be passed.
892
+ * @see https://floating-ui.com/docs/offset
893
+ */
894
+ const offset = function (options) {
895
+ return {
896
+ name: 'offset',
897
+ options,
898
+ async fn(state) {
899
+ var _middlewareData$offse, _middlewareData$arrow;
900
+ const {
901
+ x,
902
+ y,
903
+ placement,
904
+ middlewareData
905
+ } = state;
906
+ const diffCoords = await convertValueToCoords(state, options);
907
+
908
+ // If the placement is the same and the arrow caused an alignment offset
909
+ // then we don't need to change the positioning coordinates.
910
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
911
+ return {};
912
+ }
913
+ return {
914
+ x: x + diffCoords.x,
915
+ y: y + diffCoords.y,
916
+ data: {
917
+ ...diffCoords,
918
+ placement
919
+ }
920
+ };
921
+ }
922
+ };
923
+ };
924
+
925
+ /**
926
+ * Provides data that allows you to change the size of the floating element —
927
+ * for instance, prevent it from overflowing the clipping boundary or match the
928
+ * width of the reference element.
929
+ * @see https://floating-ui.com/docs/size
930
+ */
931
+ const size = function (options) {
932
+ if (options === void 0) {
933
+ options = {};
934
+ }
935
+ return {
936
+ name: 'size',
937
+ options,
938
+ async fn(state) {
939
+ const {
940
+ placement,
941
+ rects,
942
+ platform,
943
+ elements
944
+ } = state;
945
+ const {
946
+ apply = () => {},
947
+ ...detectOverflowOptions
948
+ } = evaluate(options, state);
949
+ const overflow = await detectOverflow(state, detectOverflowOptions);
950
+ const side = getSide(placement);
951
+ const alignment = getAlignment(placement);
952
+ const isYAxis = getSideAxis(placement) === 'y';
953
+ const {
954
+ width,
955
+ height
956
+ } = rects.floating;
957
+ let heightSide;
958
+ let widthSide;
959
+ if (side === 'top' || side === 'bottom') {
960
+ heightSide = side;
961
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
962
+ } else {
963
+ widthSide = side;
964
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
965
+ }
966
+ const overflowAvailableHeight = height - overflow[heightSide];
967
+ const overflowAvailableWidth = width - overflow[widthSide];
968
+ const noShift = !state.middlewareData.shift;
969
+ let availableHeight = overflowAvailableHeight;
970
+ let availableWidth = overflowAvailableWidth;
971
+ if (isYAxis) {
972
+ const maximumClippingWidth = width - overflow.left - overflow.right;
973
+ availableWidth = alignment || noShift ? min(overflowAvailableWidth, maximumClippingWidth) : maximumClippingWidth;
974
+ } else {
975
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
976
+ availableHeight = alignment || noShift ? min(overflowAvailableHeight, maximumClippingHeight) : maximumClippingHeight;
977
+ }
978
+ if (noShift && !alignment) {
979
+ const xMin = max(overflow.left, 0);
980
+ const xMax = max(overflow.right, 0);
981
+ const yMin = max(overflow.top, 0);
982
+ const yMax = max(overflow.bottom, 0);
983
+ if (isYAxis) {
984
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
985
+ } else {
986
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
987
+ }
988
+ }
989
+ await apply({
990
+ ...state,
991
+ availableWidth,
992
+ availableHeight
993
+ });
994
+ const nextDimensions = await platform.getDimensions(elements.floating);
995
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
996
+ return {
997
+ reset: {
998
+ rects: true
999
+ }
1000
+ };
1001
+ }
1002
+ return {};
1003
+ }
1004
+ };
1005
+ };
1006
+
1007
+ function getNodeName(node) {
1008
+ if (isNode(node)) {
1009
+ return (node.nodeName || '').toLowerCase();
1010
+ }
1011
+ // Mocked nodes in testing environments may not be instances of Node. By
1012
+ // returning `#document` an infinite loop won't occur.
1013
+ // https://github.com/floating-ui/floating-ui/issues/2317
1014
+ return '#document';
1015
+ }
1016
+ function getWindow(node) {
1017
+ var _node$ownerDocument;
1018
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
1019
+ }
1020
+ function getDocumentElement(node) {
1021
+ var _ref;
1022
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
1023
+ }
1024
+ function isNode(value) {
1025
+ return value instanceof Node || value instanceof getWindow(value).Node;
1026
+ }
1027
+ function isElement(value) {
1028
+ return value instanceof Element || value instanceof getWindow(value).Element;
1029
+ }
1030
+ function isHTMLElement(value) {
1031
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
1032
+ }
1033
+ function isShadowRoot(value) {
1034
+ // Browsers without `ShadowRoot` support.
1035
+ if (typeof ShadowRoot === 'undefined') {
1036
+ return false;
1037
+ }
1038
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
1039
+ }
1040
+ function isOverflowElement(element) {
1041
+ const {
1042
+ overflow,
1043
+ overflowX,
1044
+ overflowY,
1045
+ display
1046
+ } = getComputedStyle(element);
1047
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
1048
+ }
1049
+ function isTableElement(element) {
1050
+ return ['table', 'td', 'th'].includes(getNodeName(element));
1051
+ }
1052
+ function isContainingBlock(element) {
1053
+ const webkit = isWebKit();
1054
+ const css = getComputedStyle(element);
1055
+
1056
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1057
+ 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));
1058
+ }
1059
+ function getContainingBlock(element) {
1060
+ let currentNode = getParentNode(element);
1061
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
1062
+ if (isContainingBlock(currentNode)) {
1063
+ return currentNode;
1064
+ } else {
1065
+ currentNode = getParentNode(currentNode);
1066
+ }
1067
+ }
1068
+ return null;
1069
+ }
1070
+ function isWebKit() {
1071
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
1072
+ return CSS.supports('-webkit-backdrop-filter', 'none');
1073
+ }
1074
+ function isLastTraversableNode(node) {
1075
+ return ['html', 'body', '#document'].includes(getNodeName(node));
1076
+ }
1077
+ function getComputedStyle(element) {
1078
+ return getWindow(element).getComputedStyle(element);
1079
+ }
1080
+ function getNodeScroll(element) {
1081
+ if (isElement(element)) {
1082
+ return {
1083
+ scrollLeft: element.scrollLeft,
1084
+ scrollTop: element.scrollTop
1085
+ };
1086
+ }
1087
+ return {
1088
+ scrollLeft: element.pageXOffset,
1089
+ scrollTop: element.pageYOffset
1090
+ };
1091
+ }
1092
+ function getParentNode(node) {
1093
+ if (getNodeName(node) === 'html') {
1094
+ return node;
1095
+ }
1096
+ const result =
1097
+ // Step into the shadow DOM of the parent of a slotted node.
1098
+ node.assignedSlot ||
1099
+ // DOM Element detected.
1100
+ node.parentNode ||
1101
+ // ShadowRoot detected.
1102
+ isShadowRoot(node) && node.host ||
1103
+ // Fallback.
1104
+ getDocumentElement(node);
1105
+ return isShadowRoot(result) ? result.host : result;
1106
+ }
1107
+ function getNearestOverflowAncestor(node) {
1108
+ const parentNode = getParentNode(node);
1109
+ if (isLastTraversableNode(parentNode)) {
1110
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
1111
+ }
1112
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
1113
+ return parentNode;
1114
+ }
1115
+ return getNearestOverflowAncestor(parentNode);
1116
+ }
1117
+ function getOverflowAncestors(node, list, traverseIframes) {
1118
+ var _node$ownerDocument2;
1119
+ if (list === void 0) {
1120
+ list = [];
1121
+ }
1122
+ if (traverseIframes === void 0) {
1123
+ traverseIframes = true;
1124
+ }
1125
+ const scrollableAncestor = getNearestOverflowAncestor(node);
1126
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
1127
+ const win = getWindow(scrollableAncestor);
1128
+ if (isBody) {
1129
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
1130
+ }
1131
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
1132
+ }
1133
+
1134
+ function getCssDimensions(element) {
1135
+ const css = getComputedStyle(element);
1136
+ // In testing environments, the `width` and `height` properties are empty
1137
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
1138
+ let width = parseFloat(css.width) || 0;
1139
+ let height = parseFloat(css.height) || 0;
1140
+ const hasOffset = isHTMLElement(element);
1141
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
1142
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
1143
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1144
+ if (shouldFallback) {
1145
+ width = offsetWidth;
1146
+ height = offsetHeight;
1147
+ }
1148
+ return {
1149
+ width,
1150
+ height,
1151
+ $: shouldFallback
1152
+ };
1153
+ }
1154
+
1155
+ function unwrapElement(element) {
1156
+ return !isElement(element) ? element.contextElement : element;
1157
+ }
1158
+
1159
+ function getScale(element) {
1160
+ const domElement = unwrapElement(element);
1161
+ if (!isHTMLElement(domElement)) {
1162
+ return createCoords(1);
1163
+ }
1164
+ const rect = domElement.getBoundingClientRect();
1165
+ const {
1166
+ width,
1167
+ height,
1168
+ $
1169
+ } = getCssDimensions(domElement);
1170
+ let x = ($ ? round(rect.width) : rect.width) / width;
1171
+ let y = ($ ? round(rect.height) : rect.height) / height;
1172
+
1173
+ // 0, NaN, or Infinity should always fallback to 1.
1174
+
1175
+ if (!x || !Number.isFinite(x)) {
1176
+ x = 1;
1177
+ }
1178
+ if (!y || !Number.isFinite(y)) {
1179
+ y = 1;
1180
+ }
1181
+ return {
1182
+ x,
1183
+ y
1184
+ };
1185
+ }
1186
+
1187
+ const noOffsets = /*#__PURE__*/createCoords(0);
1188
+ function getVisualOffsets(element) {
1189
+ const win = getWindow(element);
1190
+ if (!isWebKit() || !win.visualViewport) {
1191
+ return noOffsets;
1192
+ }
1193
+ return {
1194
+ x: win.visualViewport.offsetLeft,
1195
+ y: win.visualViewport.offsetTop
1196
+ };
1197
+ }
1198
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1199
+ if (isFixed === void 0) {
1200
+ isFixed = false;
1201
+ }
1202
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1203
+ return false;
1204
+ }
1205
+ return isFixed;
1206
+ }
1207
+
1208
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1209
+ if (includeScale === void 0) {
1210
+ includeScale = false;
1211
+ }
1212
+ if (isFixedStrategy === void 0) {
1213
+ isFixedStrategy = false;
1214
+ }
1215
+ const clientRect = element.getBoundingClientRect();
1216
+ const domElement = unwrapElement(element);
1217
+ let scale = createCoords(1);
1218
+ if (includeScale) {
1219
+ if (offsetParent) {
1220
+ if (isElement(offsetParent)) {
1221
+ scale = getScale(offsetParent);
1222
+ }
1223
+ } else {
1224
+ scale = getScale(element);
1225
+ }
1226
+ }
1227
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1228
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
1229
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
1230
+ let width = clientRect.width / scale.x;
1231
+ let height = clientRect.height / scale.y;
1232
+ if (domElement) {
1233
+ const win = getWindow(domElement);
1234
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1235
+ let currentIFrame = win.frameElement;
1236
+ while (currentIFrame && offsetParent && offsetWin !== win) {
1237
+ const iframeScale = getScale(currentIFrame);
1238
+ const iframeRect = currentIFrame.getBoundingClientRect();
1239
+ const css = getComputedStyle(currentIFrame);
1240
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1241
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1242
+ x *= iframeScale.x;
1243
+ y *= iframeScale.y;
1244
+ width *= iframeScale.x;
1245
+ height *= iframeScale.y;
1246
+ x += left;
1247
+ y += top;
1248
+ currentIFrame = getWindow(currentIFrame).frameElement;
1249
+ }
1250
+ }
1251
+ return rectToClientRect({
1252
+ width,
1253
+ height,
1254
+ x,
1255
+ y
1256
+ });
1257
+ }
1258
+
1259
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1260
+ let {
1261
+ rect,
1262
+ offsetParent,
1263
+ strategy
1264
+ } = _ref;
1265
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1266
+ const documentElement = getDocumentElement(offsetParent);
1267
+ if (offsetParent === documentElement) {
1268
+ return rect;
1269
+ }
1270
+ let scroll = {
1271
+ scrollLeft: 0,
1272
+ scrollTop: 0
1273
+ };
1274
+ let scale = createCoords(1);
1275
+ const offsets = createCoords(0);
1276
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
1277
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1278
+ scroll = getNodeScroll(offsetParent);
1279
+ }
1280
+ if (isHTMLElement(offsetParent)) {
1281
+ const offsetRect = getBoundingClientRect(offsetParent);
1282
+ scale = getScale(offsetParent);
1283
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1284
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1285
+ }
1286
+ }
1287
+ return {
1288
+ width: rect.width * scale.x,
1289
+ height: rect.height * scale.y,
1290
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
1291
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
1292
+ };
1293
+ }
1294
+
1295
+ function getClientRects(element) {
1296
+ return Array.from(element.getClientRects());
1297
+ }
1298
+
1299
+ function getWindowScrollBarX(element) {
1300
+ // If <html> has a CSS width greater than the viewport, then this will be
1301
+ // incorrect for RTL.
1302
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
1303
+ }
1304
+
1305
+ // Gets the entire size of the scrollable document area, even extending outside
1306
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
1307
+ function getDocumentRect(element) {
1308
+ const html = getDocumentElement(element);
1309
+ const scroll = getNodeScroll(element);
1310
+ const body = element.ownerDocument.body;
1311
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1312
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1313
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1314
+ const y = -scroll.scrollTop;
1315
+ if (getComputedStyle(body).direction === 'rtl') {
1316
+ x += max(html.clientWidth, body.clientWidth) - width;
1317
+ }
1318
+ return {
1319
+ width,
1320
+ height,
1321
+ x,
1322
+ y
1323
+ };
1324
+ }
1325
+
1326
+ function getViewportRect(element, strategy) {
1327
+ const win = getWindow(element);
1328
+ const html = getDocumentElement(element);
1329
+ const visualViewport = win.visualViewport;
1330
+ let width = html.clientWidth;
1331
+ let height = html.clientHeight;
1332
+ let x = 0;
1333
+ let y = 0;
1334
+ if (visualViewport) {
1335
+ width = visualViewport.width;
1336
+ height = visualViewport.height;
1337
+ const visualViewportBased = isWebKit();
1338
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
1339
+ x = visualViewport.offsetLeft;
1340
+ y = visualViewport.offsetTop;
1341
+ }
1342
+ }
1343
+ return {
1344
+ width,
1345
+ height,
1346
+ x,
1347
+ y
1348
+ };
1349
+ }
1350
+
1351
+ // Returns the inner client rect, subtracting scrollbars if present.
1352
+ function getInnerBoundingClientRect(element, strategy) {
1353
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
1354
+ const top = clientRect.top + element.clientTop;
1355
+ const left = clientRect.left + element.clientLeft;
1356
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1357
+ const width = element.clientWidth * scale.x;
1358
+ const height = element.clientHeight * scale.y;
1359
+ const x = left * scale.x;
1360
+ const y = top * scale.y;
1361
+ return {
1362
+ width,
1363
+ height,
1364
+ x,
1365
+ y
1366
+ };
1367
+ }
1368
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1369
+ let rect;
1370
+ if (clippingAncestor === 'viewport') {
1371
+ rect = getViewportRect(element, strategy);
1372
+ } else if (clippingAncestor === 'document') {
1373
+ rect = getDocumentRect(getDocumentElement(element));
1374
+ } else if (isElement(clippingAncestor)) {
1375
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1376
+ } else {
1377
+ const visualOffsets = getVisualOffsets(element);
1378
+ rect = {
1379
+ ...clippingAncestor,
1380
+ x: clippingAncestor.x - visualOffsets.x,
1381
+ y: clippingAncestor.y - visualOffsets.y
1382
+ };
1383
+ }
1384
+ return rectToClientRect(rect);
1385
+ }
1386
+ function hasFixedPositionAncestor(element, stopNode) {
1387
+ const parentNode = getParentNode(element);
1388
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1389
+ return false;
1390
+ }
1391
+ return getComputedStyle(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
1392
+ }
1393
+
1394
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
1395
+ // clipping (or hiding) child elements. This returns all clipping ancestors
1396
+ // of the given element up the tree.
1397
+ function getClippingElementAncestors(element, cache) {
1398
+ const cachedResult = cache.get(element);
1399
+ if (cachedResult) {
1400
+ return cachedResult;
1401
+ }
1402
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
1403
+ let currentContainingBlockComputedStyle = null;
1404
+ const elementIsFixed = getComputedStyle(element).position === 'fixed';
1405
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1406
+
1407
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1408
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1409
+ const computedStyle = getComputedStyle(currentNode);
1410
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1411
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
1412
+ currentContainingBlockComputedStyle = null;
1413
+ }
1414
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1415
+ if (shouldDropCurrentNode) {
1416
+ // Drop non-containing blocks.
1417
+ result = result.filter(ancestor => ancestor !== currentNode);
1418
+ } else {
1419
+ // Record last containing block for next iteration.
1420
+ currentContainingBlockComputedStyle = computedStyle;
1421
+ }
1422
+ currentNode = getParentNode(currentNode);
1423
+ }
1424
+ cache.set(element, result);
1425
+ return result;
1426
+ }
1427
+
1428
+ // Gets the maximum area that the element is visible in due to any number of
1429
+ // clipping ancestors.
1430
+ function getClippingRect(_ref) {
1431
+ let {
1432
+ element,
1433
+ boundary,
1434
+ rootBoundary,
1435
+ strategy
1436
+ } = _ref;
1437
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
1438
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1439
+ const firstClippingAncestor = clippingAncestors[0];
1440
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
1441
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1442
+ accRect.top = max(rect.top, accRect.top);
1443
+ accRect.right = min(rect.right, accRect.right);
1444
+ accRect.bottom = min(rect.bottom, accRect.bottom);
1445
+ accRect.left = max(rect.left, accRect.left);
1446
+ return accRect;
1447
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1448
+ return {
1449
+ width: clippingRect.right - clippingRect.left,
1450
+ height: clippingRect.bottom - clippingRect.top,
1451
+ x: clippingRect.left,
1452
+ y: clippingRect.top
1453
+ };
1454
+ }
1455
+
1456
+ function getDimensions(element) {
1457
+ return getCssDimensions(element);
1458
+ }
1459
+
1460
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1461
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1462
+ const documentElement = getDocumentElement(offsetParent);
1463
+ const isFixed = strategy === 'fixed';
1464
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1465
+ let scroll = {
1466
+ scrollLeft: 0,
1467
+ scrollTop: 0
1468
+ };
1469
+ const offsets = createCoords(0);
1470
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1471
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1472
+ scroll = getNodeScroll(offsetParent);
1473
+ }
1474
+ if (isOffsetParentAnElement) {
1475
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1476
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1477
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1478
+ } else if (documentElement) {
1479
+ offsets.x = getWindowScrollBarX(documentElement);
1480
+ }
1481
+ }
1482
+ return {
1483
+ x: rect.left + scroll.scrollLeft - offsets.x,
1484
+ y: rect.top + scroll.scrollTop - offsets.y,
1485
+ width: rect.width,
1486
+ height: rect.height
1487
+ };
1488
+ }
1489
+
1490
+ function getTrueOffsetParent(element, polyfill) {
1491
+ if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {
1492
+ return null;
1493
+ }
1494
+ if (polyfill) {
1495
+ return polyfill(element);
1496
+ }
1497
+ return element.offsetParent;
1498
+ }
1499
+
1500
+ // Gets the closest ancestor positioned element. Handles some edge cases,
1501
+ // such as table ancestors and cross browser bugs.
1502
+ function getOffsetParent(element, polyfill) {
1503
+ const window = getWindow(element);
1504
+ if (!isHTMLElement(element)) {
1505
+ return window;
1506
+ }
1507
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1508
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
1509
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1510
+ }
1511
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
1512
+ return window;
1513
+ }
1514
+ return offsetParent || getContainingBlock(element) || window;
1515
+ }
1516
+
1517
+ const getElementRects = async function (_ref) {
1518
+ let {
1519
+ reference,
1520
+ floating,
1521
+ strategy
1522
+ } = _ref;
1523
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1524
+ const getDimensionsFn = this.getDimensions;
1525
+ return {
1526
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
1527
+ floating: {
1528
+ x: 0,
1529
+ y: 0,
1530
+ ...(await getDimensionsFn(floating))
1531
+ }
1532
+ };
1533
+ };
1534
+
1535
+ function isRTL(element) {
1536
+ return getComputedStyle(element).direction === 'rtl';
1537
+ }
1538
+
1539
+ const platform = {
1540
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1541
+ getDocumentElement,
1542
+ getClippingRect,
1543
+ getOffsetParent,
1544
+ getElementRects,
1545
+ getClientRects,
1546
+ getDimensions,
1547
+ getScale,
1548
+ isElement,
1549
+ isRTL
1550
+ };
1551
+
1552
+ // https://samthor.au/2021/observing-dom/
1553
+ function observeMove(element, onMove) {
1554
+ let io = null;
1555
+ let timeoutId;
1556
+ const root = getDocumentElement(element);
1557
+ function cleanup() {
1558
+ clearTimeout(timeoutId);
1559
+ io && io.disconnect();
1560
+ io = null;
1561
+ }
1562
+ function refresh(skip, threshold) {
1563
+ if (skip === void 0) {
1564
+ skip = false;
1565
+ }
1566
+ if (threshold === void 0) {
1567
+ threshold = 1;
1568
+ }
1569
+ cleanup();
1570
+ const {
1571
+ left,
1572
+ top,
1573
+ width,
1574
+ height
1575
+ } = element.getBoundingClientRect();
1576
+ if (!skip) {
1577
+ onMove();
1578
+ }
1579
+ if (!width || !height) {
1580
+ return;
1581
+ }
1582
+ const insetTop = floor(top);
1583
+ const insetRight = floor(root.clientWidth - (left + width));
1584
+ const insetBottom = floor(root.clientHeight - (top + height));
1585
+ const insetLeft = floor(left);
1586
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1587
+ const options = {
1588
+ rootMargin,
1589
+ threshold: max(0, min(1, threshold)) || 1
1590
+ };
1591
+ let isFirstUpdate = true;
1592
+ function handleObserve(entries) {
1593
+ const ratio = entries[0].intersectionRatio;
1594
+ if (ratio !== threshold) {
1595
+ if (!isFirstUpdate) {
1596
+ return refresh();
1597
+ }
1598
+ if (!ratio) {
1599
+ timeoutId = setTimeout(() => {
1600
+ refresh(false, 1e-7);
1601
+ }, 100);
1602
+ } else {
1603
+ refresh(false, ratio);
1604
+ }
1605
+ }
1606
+ isFirstUpdate = false;
1607
+ }
1608
+
1609
+ // Older browsers don't support a `document` as the root and will throw an
1610
+ // error.
1611
+ try {
1612
+ io = new IntersectionObserver(handleObserve, {
1613
+ ...options,
1614
+ // Handle <iframe>s
1615
+ root: root.ownerDocument
1616
+ });
1617
+ } catch (e) {
1618
+ io = new IntersectionObserver(handleObserve, options);
1619
+ }
1620
+ io.observe(element);
1621
+ }
1622
+ refresh(true);
1623
+ return cleanup;
1624
+ }
1625
+
1626
+ /**
1627
+ * Automatically updates the position of the floating element when necessary.
1628
+ * Should only be called when the floating element is mounted on the DOM or
1629
+ * visible on the screen.
1630
+ * @returns cleanup function that should be invoked when the floating element is
1631
+ * removed from the DOM or hidden from the screen.
1632
+ * @see https://floating-ui.com/docs/autoUpdate
1633
+ */
1634
+ function autoUpdate(reference, floating, update, options) {
1635
+ if (options === void 0) {
1636
+ options = {};
1637
+ }
1638
+ const {
1639
+ ancestorScroll = true,
1640
+ ancestorResize = true,
1641
+ elementResize = typeof ResizeObserver === 'function',
1642
+ layoutShift = typeof IntersectionObserver === 'function',
1643
+ animationFrame = false
1644
+ } = options;
1645
+ const referenceEl = unwrapElement(reference);
1646
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
1647
+ ancestors.forEach(ancestor => {
1648
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
1649
+ passive: true
1650
+ });
1651
+ ancestorResize && ancestor.addEventListener('resize', update);
1652
+ });
1653
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
1654
+ let reobserveFrame = -1;
1655
+ let resizeObserver = null;
1656
+ if (elementResize) {
1657
+ resizeObserver = new ResizeObserver(_ref => {
1658
+ let [firstEntry] = _ref;
1659
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
1660
+ // Prevent update loops when using the `size` middleware.
1661
+ // https://github.com/floating-ui/floating-ui/issues/1740
1662
+ resizeObserver.unobserve(floating);
1663
+ cancelAnimationFrame(reobserveFrame);
1664
+ reobserveFrame = requestAnimationFrame(() => {
1665
+ resizeObserver && resizeObserver.observe(floating);
1666
+ });
1667
+ }
1668
+ update();
1669
+ });
1670
+ if (referenceEl && !animationFrame) {
1671
+ resizeObserver.observe(referenceEl);
1672
+ }
1673
+ resizeObserver.observe(floating);
1674
+ }
1675
+ let frameId;
1676
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1677
+ if (animationFrame) {
1678
+ frameLoop();
1679
+ }
1680
+ function frameLoop() {
1681
+ const nextRefRect = getBoundingClientRect(reference);
1682
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
1683
+ update();
1684
+ }
1685
+ prevRefRect = nextRefRect;
1686
+ frameId = requestAnimationFrame(frameLoop);
1687
+ }
1688
+ update();
1689
+ return () => {
1690
+ ancestors.forEach(ancestor => {
1691
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
1692
+ ancestorResize && ancestor.removeEventListener('resize', update);
1693
+ });
1694
+ cleanupIo && cleanupIo();
1695
+ resizeObserver && resizeObserver.disconnect();
1696
+ resizeObserver = null;
1697
+ if (animationFrame) {
1698
+ cancelAnimationFrame(frameId);
1699
+ }
1700
+ };
1701
+ }
1702
+
1703
+ /**
1704
+ * Computes the `x` and `y` coordinates that will place the floating element
1705
+ * next to a reference element when it is given a certain CSS positioning
1706
+ * strategy.
1707
+ */
1708
+ const computePosition = (reference, floating, options) => {
1709
+ // This caches the expensive `getClippingElementAncestors` function so that
1710
+ // multiple lifecycle resets re-use the same result. It only lives for a
1711
+ // single call. If other functions become expensive, we can add them as well.
1712
+ const cache = new Map();
1713
+ const mergedOptions = {
1714
+ platform,
1715
+ ...options
1716
+ };
1717
+ const platformWithCache = {
1718
+ ...mergedOptions.platform,
1719
+ _c: cache
1720
+ };
1721
+ return computePosition$1(reference, floating, {
1722
+ ...mergedOptions,
1723
+ platform: platformWithCache
1724
+ });
1725
+ };
1726
+
1727
+ var __defProp = Object.defineProperty;
1728
+ var __decorateClass = (decorators, target, key, kind) => {
1729
+ var result = void 0 ;
1730
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1731
+ if (decorator = decorators[i])
1732
+ result = (decorator(target, key, result) ) || result;
1733
+ if (result) __defProp(target, key, result);
1734
+ return result;
1735
+ };
1736
+ const PlacementStrategy = {
1737
+ Flip: "flip",
1738
+ AutoPlacementHorizontal: "auto-placement-horizontal",
1739
+ AutoPlacementVertical: "auto-placement-vertical"
1740
+ };
1741
+ const placementStrategyMiddlewares = {
1742
+ [PlacementStrategy.Flip]: flip(),
1743
+ [PlacementStrategy.AutoPlacementHorizontal]: autoPlacement({
1744
+ allowedPlacements: [
1745
+ "bottom",
1746
+ "top",
1747
+ "bottom-start",
1748
+ "bottom-end",
1749
+ "top-start",
1750
+ "top-end"
1751
+ ]
1752
+ }),
1753
+ [PlacementStrategy.AutoPlacementVertical]: autoPlacement({
1754
+ allowedPlacements: [
1755
+ "left",
1756
+ "right",
1757
+ "left-start",
1758
+ "left-end",
1759
+ "right-start",
1760
+ "right-end"
1761
+ ]
1762
+ })
1763
+ };
1764
+ class Popup extends index.FoundationElement {
1765
+ constructor() {
1766
+ super(...arguments);
1767
+ this.open = false;
1768
+ this.dismissible = false;
1769
+ this.arrow = false;
1770
+ this.alternate = false;
1771
+ /**
1772
+ * The placement strategy of the popup.
1773
+ *
1774
+ * @public
1775
+ */
1776
+ this.placementStrategy = PlacementStrategy.Flip;
1777
+ this.animationFrame = false;
1778
+ this.strategy = "fixed";
1779
+ }
1780
+ get #middleware() {
1781
+ let middleware = [
1782
+ inline(),
1783
+ placementStrategyMiddlewares[this.placementStrategy],
1784
+ hide(),
1785
+ size({
1786
+ apply({ availableWidth, availableHeight, elements }) {
1787
+ Object.assign(elements.floating.style, {
1788
+ maxWidth: `${availableWidth}px`,
1789
+ maxHeight: `${availableHeight}px`
1790
+ });
1791
+ }
1792
+ })
1793
+ ];
1794
+ if (this.arrow) {
1795
+ middleware = [
1796
+ offset(12),
1797
+ ...middleware,
1798
+ arrow({ element: this.arrowEl, padding: 10 })
1799
+ ];
1800
+ }
1801
+ return middleware;
1802
+ }
1803
+ #cleanup;
1804
+ openChanged(_, newValue) {
1805
+ newValue ? this.$emit("vwc-popup:open") : this.$emit("vwc-popup:close");
1806
+ index.DOM.queueUpdate(() => this.#updateAutoUpdate());
1807
+ }
1808
+ /**
1809
+ * @internal
1810
+ */
1811
+ animationFrameChanged() {
1812
+ this.#updateAutoUpdate();
1813
+ }
1814
+ /**
1815
+ * @internal
1816
+ */
1817
+ anchorChanged() {
1818
+ this.#updateAutoUpdate();
1819
+ }
1820
+ connectedCallback() {
1821
+ super.connectedCallback();
1822
+ this.#updateAutoUpdate();
1823
+ }
1824
+ disconnectedCallback() {
1825
+ super.disconnectedCallback();
1826
+ this.#updateAutoUpdate();
1827
+ }
1828
+ #updateAutoUpdate() {
1829
+ this.#cleanup?.();
1830
+ if (this.anchorEl && this.open && this.popupEl) {
1831
+ this.#cleanup = autoUpdate(
1832
+ this.anchorEl,
1833
+ this.popupEl,
1834
+ () => this.updatePosition(),
1835
+ {
1836
+ animationFrame: this.animationFrame
1837
+ }
1838
+ );
1839
+ }
1840
+ }
1841
+ /**
1842
+ * Updates popup's position
1843
+ *
1844
+ * @public
1845
+ */
1846
+ async updatePosition() {
1847
+ if (!this.open || !this.anchorEl) {
1848
+ return;
1849
+ }
1850
+ const positionData = await computePosition(this.anchorEl, this.popupEl, {
1851
+ placement: this.placement,
1852
+ strategy: this.strategy,
1853
+ middleware: this.#middleware
1854
+ });
1855
+ this.#assignPopupPosition(positionData);
1856
+ if (this.arrow) {
1857
+ this.#assignArrowPosition(positionData);
1858
+ }
1859
+ }
1860
+ #assignPopupPosition(data) {
1861
+ const { x: popupX, y: popupY } = data;
1862
+ const { referenceHidden } = data.middlewareData.hide;
1863
+ Object.assign(this.popupEl.style, {
1864
+ left: `${popupX}px`,
1865
+ top: `${popupY}px`,
1866
+ visibility: referenceHidden ? "hidden" : "visible"
1867
+ });
1868
+ }
1869
+ #assignArrowPosition(data) {
1870
+ const { x: arrowX, y: arrowY } = data.middlewareData.arrow;
1871
+ const styles = {
1872
+ left: "calc(100% - 4px)",
1873
+ right: "-4px",
1874
+ top: "calc(100% - 4px)",
1875
+ bottom: "-4px"
1876
+ };
1877
+ const staticAxis = data.placement.split("-")[0];
1878
+ Object.assign(this.arrowEl.style, {
1879
+ left: arrowX ? `${arrowX}px` : styles[staticAxis],
1880
+ top: arrowY ? `${arrowY}px` : styles[staticAxis]
1881
+ });
1882
+ }
1883
+ get anchorEl() {
1884
+ return this.anchor ?? null;
1885
+ }
1886
+ show() {
1887
+ this.open = true;
1888
+ }
1889
+ hide() {
1890
+ this.open = false;
1891
+ }
1892
+ }
1893
+ __decorateClass([
1894
+ index.attr({
1895
+ mode: "boolean"
1896
+ })
1897
+ ], Popup.prototype, "open");
1898
+ __decorateClass([
1899
+ index.attr({
1900
+ mode: "boolean"
1901
+ })
1902
+ ], Popup.prototype, "dismissible");
1903
+ __decorateClass([
1904
+ index.attr({
1905
+ mode: "boolean"
1906
+ })
1907
+ ], Popup.prototype, "arrow");
1908
+ __decorateClass([
1909
+ index.attr({
1910
+ mode: "boolean"
1911
+ })
1912
+ ], Popup.prototype, "alternate");
1913
+ __decorateClass([
1914
+ index.attr({ mode: "fromView" })
1915
+ ], Popup.prototype, "placement");
1916
+ __decorateClass([
1917
+ index.attr({ mode: "boolean", attribute: "animation-frame" })
1918
+ ], Popup.prototype, "animationFrame");
1919
+ __decorateClass([
1920
+ index.attr({ mode: "fromView" })
1921
+ ], Popup.prototype, "strategy");
1922
+ __decorateClass([
1923
+ index.observable
1924
+ ], Popup.prototype, "anchor");
1925
+
1926
+ const styles = ":host{display:var(--_popup-display, inline)}.control{border-radius:inherit;background:var(--vvd-color-surface-4dp);contain:layout}.control:not(.open){display:none}.popup-wrapper{white-space:initial;z-index:var(--_popup-z-index, 10);border-radius:8px;inline-size:max-content}.popup-wrapper:not(.absolute){position:fixed}.popup-wrapper.absolute{position:absolute;top:0;left:0}.popup-content{display:grid;color:var(--vvd-color-canvas-text)}.dismissible .popup-content{align-content:start;grid-template-columns:1fr auto}.arrow{position:absolute;z-index:-1;width:8px;height:8px;background:var(--vvd-color-surface-4dp);transform:rotate(45deg)}.dismissible-button{align-self:flex-start;margin-block-start:4px;margin-inline-end:4px}";
1927
+
1928
+ const getClasses = ({ open, dismissible, alternate }) => classNames.classNames(
1929
+ "control",
1930
+ ["open", Boolean(open)],
1931
+ ["dismissible", Boolean(dismissible)],
1932
+ ["alternate", Boolean(alternate)]
1933
+ );
1934
+ const popupTemplate = (context) => {
1935
+ const elevationTag = context.tagFor(definition.Elevation);
1936
+ const buttonTag = context.tagFor(definition$1.Button);
1937
+ return index.html`
1938
+ <${elevationTag}>
1939
+ <div class="popup-wrapper ${(x) => x.strategy}" ${ref.ref(
1940
+ "popupEl"
1941
+ )} part="popup-base">
1942
+ <div class="${getClasses}" aria-hidden="${(x) => x.open ? "false" : "true"}"
1943
+ part="${(x) => x.alternate ? "vvd-theme-alternate" : ""}">
1944
+ <div class="popup-content">
1945
+ <slot></slot>
1946
+ ${when.when(
1947
+ (x) => x.dismissible,
1948
+ index.html`<${buttonTag} size="condensed" @click="${(x) => x.open = false}"
1949
+ class="dismissible-button" icon="close-small-solid" shape="pill"></${buttonTag}>`
1950
+ )}
1951
+ </div>
1952
+ ${when.when(
1953
+ (x) => x.arrow,
1954
+ index.html`<div class="arrow" ${ref.ref("arrowEl")}></div>`
1955
+ )}
1956
+ </div>
1957
+ </div>
1958
+ </${elevationTag}>`;
1959
+ };
1960
+
1961
+ const popupDefinition = Popup.compose({
1962
+ baseName: "popup",
1963
+ template: popupTemplate,
1964
+ styles
1965
+ });
1966
+ const popupRegistries = [
1967
+ popupDefinition(),
1968
+ ...definition.elevationRegistries,
1969
+ ...definition$1.buttonRegistries
1970
+ ];
1971
+ const registerPopup = index.registerFactory(popupRegistries);
1972
+
1973
+ exports.PlacementStrategy = PlacementStrategy;
1974
+ exports.Popup = Popup;
1975
+ exports.popupRegistries = popupRegistries;
1976
+ exports.registerPopup = registerPopup;