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