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