@haiilo/catalyst 0.2.3 → 0.4.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 (241) hide show
  1. package/dist/catalyst/assets/fonts/AzeretMono-Regular.woff2 +0 -0
  2. package/dist/catalyst/assets/fonts/DMSans-Bold.woff2 +0 -0
  3. package/dist/catalyst/assets/fonts/DMSans-BoldItalic.woff2 +0 -0
  4. package/dist/catalyst/assets/fonts/DMSans-Italic.woff2 +0 -0
  5. package/dist/catalyst/assets/fonts/DMSans-Medium.woff2 +0 -0
  6. package/dist/catalyst/assets/fonts/DMSans-MediumItalic.woff2 +0 -0
  7. package/dist/catalyst/assets/fonts/DMSans-Regular.woff2 +0 -0
  8. package/dist/catalyst/assets/fonts/Lato-Black.woff +0 -0
  9. package/dist/catalyst/assets/fonts/Lato-Black.woff2 +0 -0
  10. package/dist/catalyst/assets/fonts/Lato-BlackItalic.woff +0 -0
  11. package/dist/catalyst/assets/fonts/Lato-BlackItalic.woff2 +0 -0
  12. package/dist/catalyst/assets/fonts/Lato-Bold.woff +0 -0
  13. package/dist/catalyst/assets/fonts/Lato-Bold.woff2 +0 -0
  14. package/dist/catalyst/assets/fonts/Lato-BoldItalic.woff +0 -0
  15. package/dist/catalyst/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  16. package/dist/catalyst/assets/fonts/Lato-Hairline.woff +0 -0
  17. package/dist/catalyst/assets/fonts/Lato-Hairline.woff2 +0 -0
  18. package/dist/catalyst/assets/fonts/Lato-HairlineItalic.woff +0 -0
  19. package/dist/catalyst/assets/fonts/Lato-HairlineItalic.woff2 +0 -0
  20. package/dist/catalyst/assets/fonts/Lato-Heavy.woff +0 -0
  21. package/dist/catalyst/assets/fonts/Lato-Heavy.woff2 +0 -0
  22. package/dist/catalyst/assets/fonts/Lato-HeavyItalic.woff +0 -0
  23. package/dist/catalyst/assets/fonts/Lato-HeavyItalic.woff2 +0 -0
  24. package/dist/catalyst/assets/fonts/Lato-Italic.woff +0 -0
  25. package/dist/catalyst/assets/fonts/Lato-Italic.woff2 +0 -0
  26. package/dist/catalyst/assets/fonts/Lato-Light.woff +0 -0
  27. package/dist/catalyst/assets/fonts/Lato-Light.woff2 +0 -0
  28. package/dist/catalyst/assets/fonts/Lato-LightItalic.woff +0 -0
  29. package/dist/catalyst/assets/fonts/Lato-LightItalic.woff2 +0 -0
  30. package/dist/catalyst/assets/fonts/Lato-Medium.woff +0 -0
  31. package/dist/catalyst/assets/fonts/Lato-Medium.woff2 +0 -0
  32. package/dist/catalyst/assets/fonts/Lato-MediumItalic.woff +0 -0
  33. package/dist/catalyst/assets/fonts/Lato-MediumItalic.woff2 +0 -0
  34. package/dist/catalyst/assets/fonts/Lato-Regular.woff +0 -0
  35. package/dist/catalyst/assets/fonts/Lato-Regular.woff2 +0 -0
  36. package/dist/catalyst/assets/fonts/Lato-Semibold.woff +0 -0
  37. package/dist/catalyst/assets/fonts/Lato-Semibold.woff2 +0 -0
  38. package/dist/catalyst/assets/fonts/Lato-SemiboldItalic.woff +0 -0
  39. package/dist/catalyst/assets/fonts/Lato-SemiboldItalic.woff2 +0 -0
  40. package/dist/catalyst/assets/fonts/Lato-Thin.woff +0 -0
  41. package/dist/catalyst/assets/fonts/Lato-Thin.woff2 +0 -0
  42. package/dist/catalyst/assets/fonts/Lato-ThinItalic.woff +0 -0
  43. package/dist/catalyst/assets/fonts/Lato-ThinItalic.woff2 +0 -0
  44. package/dist/catalyst/catalyst.css +1 -1959
  45. package/dist/catalyst/catalyst.esm.js +1 -131
  46. package/dist/catalyst/catalyst.esm.js.map +1 -1
  47. package/dist/catalyst/index.esm.js +1 -2
  48. package/dist/catalyst/index.esm.js.map +1 -1
  49. package/dist/catalyst/p-89a97b7b.entry.js +10 -0
  50. package/dist/catalyst/p-89a97b7b.entry.js.map +1 -0
  51. package/dist/catalyst/p-ed826597.js +2 -0
  52. package/dist/catalyst/p-ed826597.js.map +1 -0
  53. package/dist/catalyst/p-ef0a8ae9.js +2 -0
  54. package/dist/catalyst/p-ef0a8ae9.js.map +1 -0
  55. package/dist/catalyst/p-f151cb13.js +2 -0
  56. package/dist/catalyst/p-f151cb13.js.map +1 -0
  57. package/dist/cjs/app-globals-7f2b1f8e.js +173 -0
  58. package/dist/cjs/app-globals-7f2b1f8e.js.map +1 -0
  59. package/dist/cjs/cat-alert_9.cjs.entry.js +4557 -0
  60. package/dist/cjs/cat-alert_9.cjs.entry.js.map +1 -0
  61. package/dist/cjs/cat-icon-registry-850c538c.js +47 -0
  62. package/dist/cjs/cat-icon-registry-850c538c.js.map +1 -0
  63. package/dist/cjs/catalyst.cjs.js +24 -0
  64. package/dist/cjs/catalyst.cjs.js.map +1 -0
  65. package/dist/cjs/index-c0881ae0.js +1348 -0
  66. package/dist/cjs/index-c0881ae0.js.map +1 -0
  67. package/dist/cjs/index.cjs.js +11 -0
  68. package/dist/cjs/index.cjs.js.map +1 -0
  69. package/dist/cjs/loader.cjs.js +26 -0
  70. package/dist/cjs/loader.cjs.js.map +1 -0
  71. package/dist/collection/assets/fonts/AzeretMono-Regular.woff2 +0 -0
  72. package/dist/collection/assets/fonts/DMSans-Bold.woff2 +0 -0
  73. package/dist/collection/assets/fonts/DMSans-BoldItalic.woff2 +0 -0
  74. package/dist/collection/assets/fonts/DMSans-Italic.woff2 +0 -0
  75. package/dist/collection/assets/fonts/DMSans-Medium.woff2 +0 -0
  76. package/dist/collection/assets/fonts/DMSans-MediumItalic.woff2 +0 -0
  77. package/dist/collection/assets/fonts/DMSans-Regular.woff2 +0 -0
  78. package/dist/collection/assets/fonts/Lato-Black.woff +0 -0
  79. package/dist/collection/assets/fonts/Lato-Black.woff2 +0 -0
  80. package/dist/collection/assets/fonts/Lato-BlackItalic.woff +0 -0
  81. package/dist/collection/assets/fonts/Lato-BlackItalic.woff2 +0 -0
  82. package/dist/collection/assets/fonts/Lato-Bold.woff +0 -0
  83. package/dist/collection/assets/fonts/Lato-Bold.woff2 +0 -0
  84. package/dist/collection/assets/fonts/Lato-BoldItalic.woff +0 -0
  85. package/dist/collection/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  86. package/dist/collection/assets/fonts/Lato-Hairline.woff +0 -0
  87. package/dist/collection/assets/fonts/Lato-Hairline.woff2 +0 -0
  88. package/dist/collection/assets/fonts/Lato-HairlineItalic.woff +0 -0
  89. package/dist/collection/assets/fonts/Lato-HairlineItalic.woff2 +0 -0
  90. package/dist/collection/assets/fonts/Lato-Heavy.woff +0 -0
  91. package/dist/collection/assets/fonts/Lato-Heavy.woff2 +0 -0
  92. package/dist/collection/assets/fonts/Lato-HeavyItalic.woff +0 -0
  93. package/dist/collection/assets/fonts/Lato-HeavyItalic.woff2 +0 -0
  94. package/dist/collection/assets/fonts/Lato-Italic.woff +0 -0
  95. package/dist/collection/assets/fonts/Lato-Italic.woff2 +0 -0
  96. package/dist/collection/assets/fonts/Lato-Light.woff +0 -0
  97. package/dist/collection/assets/fonts/Lato-Light.woff2 +0 -0
  98. package/dist/collection/assets/fonts/Lato-LightItalic.woff +0 -0
  99. package/dist/collection/assets/fonts/Lato-LightItalic.woff2 +0 -0
  100. package/dist/collection/assets/fonts/Lato-Medium.woff +0 -0
  101. package/dist/collection/assets/fonts/Lato-Medium.woff2 +0 -0
  102. package/dist/collection/assets/fonts/Lato-MediumItalic.woff +0 -0
  103. package/dist/collection/assets/fonts/Lato-MediumItalic.woff2 +0 -0
  104. package/dist/collection/assets/fonts/Lato-Regular.woff +0 -0
  105. package/dist/collection/assets/fonts/Lato-Regular.woff2 +0 -0
  106. package/dist/collection/assets/fonts/Lato-Semibold.woff +0 -0
  107. package/dist/collection/assets/fonts/Lato-Semibold.woff2 +0 -0
  108. package/dist/collection/assets/fonts/Lato-SemiboldItalic.woff +0 -0
  109. package/dist/collection/assets/fonts/Lato-SemiboldItalic.woff2 +0 -0
  110. package/dist/collection/assets/fonts/Lato-Thin.woff +0 -0
  111. package/dist/collection/assets/fonts/Lato-Thin.woff2 +0 -0
  112. package/dist/collection/assets/fonts/Lato-ThinItalic.woff +0 -0
  113. package/dist/collection/assets/fonts/Lato-ThinItalic.woff2 +0 -0
  114. package/dist/collection/collection-manifest.json +21 -0
  115. package/dist/collection/components/cat-alert/cat-alert.css +57 -0
  116. package/dist/collection/components/cat-alert/cat-alert.js +50 -0
  117. package/dist/collection/components/cat-alert/cat-alert.js.map +1 -0
  118. package/dist/collection/components/cat-badge/cat-badge.css +154 -0
  119. package/dist/collection/components/cat-badge/cat-badge.js +142 -0
  120. package/dist/collection/components/cat-badge/cat-badge.js.map +1 -0
  121. package/dist/collection/components/cat-button/cat-button.css +323 -0
  122. package/dist/collection/components/cat-button/cat-button.js +591 -0
  123. package/dist/collection/components/cat-button/cat-button.js.map +1 -0
  124. package/dist/collection/components/cat-icon/cat-icon-registry.js +42 -0
  125. package/dist/collection/components/cat-icon/cat-icon-registry.js.map +1 -0
  126. package/dist/collection/components/cat-icon/cat-icon.css +50 -0
  127. package/dist/collection/components/cat-icon/cat-icon.js +90 -0
  128. package/dist/collection/components/cat-icon/cat-icon.js.map +1 -0
  129. package/dist/collection/components/cat-menu/cat-menu.css +33 -0
  130. package/dist/collection/components/cat-menu/cat-menu.js +184 -0
  131. package/dist/collection/components/cat-menu/cat-menu.js.map +1 -0
  132. package/dist/collection/components/cat-scrollable/cat-scrollable.css +69 -0
  133. package/dist/collection/components/cat-scrollable/cat-scrollable.js +309 -0
  134. package/dist/collection/components/cat-scrollable/cat-scrollable.js.map +1 -0
  135. package/dist/collection/components/cat-skeleton/cat-skeleton.css +177 -0
  136. package/dist/collection/components/cat-skeleton/cat-skeleton.js +131 -0
  137. package/dist/collection/components/cat-skeleton/cat-skeleton.js.map +1 -0
  138. package/dist/collection/components/cat-spinner/cat-spinner.css +63 -0
  139. package/dist/collection/components/cat-spinner/cat-spinner.js +65 -0
  140. package/dist/collection/components/cat-spinner/cat-spinner.js.map +1 -0
  141. package/dist/collection/components/cat-tooltip/cat-tooltip.css +37 -0
  142. package/dist/collection/components/cat-tooltip/cat-tooltip.js +254 -0
  143. package/dist/collection/components/cat-tooltip/cat-tooltip.js.map +1 -0
  144. package/dist/collection/index.cdn.js +21 -0
  145. package/dist/collection/index.js +2 -0
  146. package/dist/collection/index.js.map +1 -0
  147. package/dist/collection/init.js +9 -0
  148. package/dist/collection/init.js.map +1 -0
  149. package/dist/collection/utils/breakpoints.js +12 -0
  150. package/dist/collection/utils/breakpoints.js.map +1 -0
  151. package/dist/collection/utils/first-tabbable.js +6 -0
  152. package/dist/collection/utils/first-tabbable.js.map +1 -0
  153. package/dist/collection/utils/is-touch-screen.js +3 -0
  154. package/dist/collection/utils/is-touch-screen.js.map +1 -0
  155. package/dist/collection/utils/media-matcher.js +55 -0
  156. package/dist/collection/utils/media-matcher.js.map +1 -0
  157. package/dist/collection/utils/platform.js +50 -0
  158. package/dist/collection/utils/platform.js.map +1 -0
  159. package/dist/collection/utils/utils.js +4 -0
  160. package/dist/collection/utils/utils.js.map +1 -0
  161. package/dist/{catalyst/cat-alert.entry.js → components/cat-alert.js} +28 -8
  162. package/dist/components/cat-alert.js.map +1 -0
  163. package/dist/{catalyst/cat-badge.entry.js → components/cat-badge.js} +32 -8
  164. package/dist/components/cat-badge.js.map +1 -0
  165. package/dist/{catalyst/cat-button.entry.js → components/cat-button.js} +60 -41
  166. package/dist/components/cat-button.js.map +1 -0
  167. package/dist/components/cat-icon-registry.js +45 -0
  168. package/dist/components/cat-icon-registry.js.map +1 -0
  169. package/dist/components/cat-icon.js +8 -0
  170. package/dist/components/cat-icon.js.map +1 -0
  171. package/dist/{catalyst/cat-icon.entry.js → components/cat-icon2.js} +28 -9
  172. package/dist/components/cat-icon2.js.map +1 -0
  173. package/dist/components/cat-menu.js +870 -0
  174. package/dist/components/cat-menu.js.map +1 -0
  175. package/dist/components/cat-scrollable.js +1363 -0
  176. package/dist/components/cat-scrollable.js.map +1 -0
  177. package/dist/{catalyst/cat-skeleton.entry.js → components/cat-skeleton.js} +31 -8
  178. package/dist/components/cat-skeleton.js.map +1 -0
  179. package/dist/components/cat-spinner.js +8 -0
  180. package/dist/components/cat-spinner.js.map +1 -0
  181. package/dist/{catalyst/cat-spinner.entry.js → components/cat-spinner2.js} +26 -8
  182. package/dist/components/cat-spinner2.js.map +1 -0
  183. package/dist/components/{cat-input.d.ts → cat-tooltip.d.ts} +4 -4
  184. package/dist/components/cat-tooltip.js +154 -0
  185. package/dist/components/cat-tooltip.js.map +1 -0
  186. package/dist/components/first-tabbable.js +1495 -0
  187. package/dist/components/first-tabbable.js.map +1 -0
  188. package/dist/components/index.js +173 -0
  189. package/dist/components/index.js.map +1 -0
  190. package/dist/esm/app-globals-8af9b2cf.js +171 -0
  191. package/dist/esm/app-globals-8af9b2cf.js.map +1 -0
  192. package/dist/esm/cat-alert_9.entry.js +4545 -0
  193. package/dist/esm/cat-alert_9.entry.js.map +1 -0
  194. package/dist/{catalyst → esm}/cat-icon-registry-59da2e37.js +0 -0
  195. package/dist/{catalyst → esm}/cat-icon-registry-59da2e37.js.map +0 -0
  196. package/dist/esm/catalyst.js +22 -0
  197. package/dist/esm/catalyst.js.map +1 -0
  198. package/dist/esm/index-0ff35bca.js +1320 -0
  199. package/dist/esm/index-0ff35bca.js.map +1 -0
  200. package/dist/esm/index.js +3 -0
  201. package/dist/esm/index.js.map +1 -0
  202. package/dist/esm/loader.js +22 -0
  203. package/dist/esm/loader.js.map +1 -0
  204. package/dist/esm/polyfills/core-js.js +11 -0
  205. package/dist/esm/polyfills/css-shim.js +1 -0
  206. package/dist/esm/polyfills/dom.js +79 -0
  207. package/dist/esm/polyfills/es5-html-element.js +1 -0
  208. package/dist/esm/polyfills/index.js +34 -0
  209. package/dist/esm/polyfills/system.js +6 -0
  210. package/dist/index.cjs.js +1 -0
  211. package/dist/index.js +1 -0
  212. package/dist/types/components/cat-menu/cat-menu.d.ts +0 -1
  213. package/dist/types/components/cat-tooltip/cat-tooltip.d.ts +46 -0
  214. package/dist/types/components.d.ts +61 -0
  215. package/dist/types/index.d.ts +1 -0
  216. package/dist/types/utils/first-tabbable.d.ts +4 -0
  217. package/dist/types/utils/is-touch-screen.d.ts +2 -0
  218. package/package.json +12 -19
  219. package/dist/catalyst/app-globals-54573336.js +0 -718
  220. package/dist/catalyst/app-globals-54573336.js.map +0 -1
  221. package/dist/catalyst/cat-alert.entry.js.map +0 -1
  222. package/dist/catalyst/cat-badge.entry.js.map +0 -1
  223. package/dist/catalyst/cat-button.entry.js.map +0 -1
  224. package/dist/catalyst/cat-icon.entry.js.map +0 -1
  225. package/dist/catalyst/cat-input.entry.js +0 -55
  226. package/dist/catalyst/cat-input.entry.js.map +0 -1
  227. package/dist/catalyst/cat-menu.entry.js +0 -2986
  228. package/dist/catalyst/cat-menu.entry.js.map +0 -1
  229. package/dist/catalyst/cat-scrollable.entry.js +0 -4523
  230. package/dist/catalyst/cat-scrollable.entry.js.map +0 -1
  231. package/dist/catalyst/cat-skeleton.entry.js.map +0 -1
  232. package/dist/catalyst/cat-spinner.entry.js.map +0 -1
  233. package/dist/catalyst/css-shim-e6dd2538.js +0 -6
  234. package/dist/catalyst/css-shim-e6dd2538.js.map +0 -1
  235. package/dist/catalyst/dom-7fc649b0.js +0 -75
  236. package/dist/catalyst/dom-7fc649b0.js.map +0 -1
  237. package/dist/catalyst/index-2df805aa.js +0 -3059
  238. package/dist/catalyst/index-2df805aa.js.map +0 -1
  239. package/dist/catalyst/shadow-css-4d56fa31.js +0 -390
  240. package/dist/catalyst/shadow-css-4d56fa31.js.map +0 -1
  241. package/dist/types/components/cat-input/cat-input.d.ts +0 -70
@@ -1,2986 +0,0 @@
1
- import { r as registerInstance, e as createEvent, h, f as Host } from './index-2df805aa.js';
2
-
3
- function getSide(placement) {
4
- return placement.split('-')[0];
5
- }
6
-
7
- function getAlignment(placement) {
8
- return placement.split('-')[1];
9
- }
10
-
11
- function getMainAxisFromPlacement(placement) {
12
- return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
13
- }
14
-
15
- function getLengthFromAxis(axis) {
16
- return axis === 'y' ? 'height' : 'width';
17
- }
18
-
19
- function computeCoordsFromPlacement(_ref, placement, rtl) {
20
- let {
21
- reference,
22
- floating
23
- } = _ref;
24
- const commonX = reference.x + reference.width / 2 - floating.width / 2;
25
- const commonY = reference.y + reference.height / 2 - floating.height / 2;
26
- const mainAxis = getMainAxisFromPlacement(placement);
27
- const length = getLengthFromAxis(mainAxis);
28
- const commonAlign = reference[length] / 2 - floating[length] / 2;
29
- const side = getSide(placement);
30
- const isVertical = mainAxis === 'x';
31
- let coords;
32
-
33
- switch (side) {
34
- case 'top':
35
- coords = {
36
- x: commonX,
37
- y: reference.y - floating.height
38
- };
39
- break;
40
-
41
- case 'bottom':
42
- coords = {
43
- x: commonX,
44
- y: reference.y + reference.height
45
- };
46
- break;
47
-
48
- case 'right':
49
- coords = {
50
- x: reference.x + reference.width,
51
- y: commonY
52
- };
53
- break;
54
-
55
- case 'left':
56
- coords = {
57
- x: reference.x - floating.width,
58
- y: commonY
59
- };
60
- break;
61
-
62
- default:
63
- coords = {
64
- x: reference.x,
65
- y: reference.y
66
- };
67
- }
68
-
69
- switch (getAlignment(placement)) {
70
- case 'start':
71
- coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
72
- break;
73
-
74
- case 'end':
75
- coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
76
- break;
77
- }
78
-
79
- return coords;
80
- }
81
-
82
- /**
83
- * Computes the `x` and `y` coordinates that will place the floating element
84
- * next to a reference element when it is given a certain positioning strategy.
85
- *
86
- * This export does not have any `platform` interface logic. You will need to
87
- * write one for the platform you are using Floating UI with.
88
- */
89
-
90
- const computePosition$1 = async (reference, floating, config) => {
91
- const {
92
- placement = 'bottom',
93
- strategy = 'absolute',
94
- middleware = [],
95
- platform
96
- } = config;
97
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
98
-
99
- if ("development" !== "production") {
100
- if (platform == null) {
101
- console.error(['Floating UI: `platform` property was not passed to config. If you', 'want to use Floating UI on the web, install @floating-ui/dom', 'instead of the /core package. Otherwise, you can create your own', '`platform`: https://floating-ui.com/docs/platform'].join(' '));
102
- }
103
-
104
- if (middleware.filter(_ref => {
105
- let {
106
- name
107
- } = _ref;
108
- return name === 'autoPlacement' || name === 'flip';
109
- }).length > 1) {
110
- throw new Error(['Floating UI: duplicate `flip` and/or `autoPlacement`', 'middleware detected. This will lead to an infinite loop. Ensure only', 'one of either has been passed to the `middleware` array.'].join(' '));
111
- }
112
- }
113
-
114
- let rects = await platform.getElementRects({
115
- reference,
116
- floating,
117
- strategy
118
- });
119
- let {
120
- x,
121
- y
122
- } = computeCoordsFromPlacement(rects, placement, rtl);
123
- let statefulPlacement = placement;
124
- let middlewareData = {};
125
- let _debug_loop_count_ = 0;
126
-
127
- for (let i = 0; i < middleware.length; i++) {
128
- if ("development" !== "production") {
129
- _debug_loop_count_++;
130
-
131
- if (_debug_loop_count_ > 100) {
132
- throw new Error(['Floating UI: The middleware lifecycle appears to be', 'running in an infinite loop. This is usually caused by a `reset`', 'continually being returned without a break condition.'].join(' '));
133
- }
134
- }
135
-
136
- const {
137
- name,
138
- fn
139
- } = middleware[i];
140
- const {
141
- x: nextX,
142
- y: nextY,
143
- data,
144
- reset
145
- } = await fn({
146
- x,
147
- y,
148
- initialPlacement: placement,
149
- placement: statefulPlacement,
150
- strategy,
151
- middlewareData,
152
- rects,
153
- platform,
154
- elements: {
155
- reference,
156
- floating
157
- }
158
- });
159
- x = nextX != null ? nextX : x;
160
- y = nextY != null ? nextY : y;
161
- middlewareData = { ...middlewareData,
162
- [name]: { ...middlewareData[name],
163
- ...data
164
- }
165
- };
166
-
167
- if (reset) {
168
- if (typeof reset === 'object') {
169
- if (reset.placement) {
170
- statefulPlacement = reset.placement;
171
- }
172
-
173
- if (reset.rects) {
174
- rects = reset.rects === true ? await platform.getElementRects({
175
- reference,
176
- floating,
177
- strategy
178
- }) : reset.rects;
179
- }
180
-
181
- ({
182
- x,
183
- y
184
- } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
185
- }
186
-
187
- i = -1;
188
- continue;
189
- }
190
- }
191
-
192
- return {
193
- x,
194
- y,
195
- placement: statefulPlacement,
196
- strategy,
197
- middlewareData
198
- };
199
- };
200
-
201
- function expandPaddingObject(padding) {
202
- return {
203
- top: 0,
204
- right: 0,
205
- bottom: 0,
206
- left: 0,
207
- ...padding
208
- };
209
- }
210
-
211
- function getSideObjectFromPadding(padding) {
212
- return typeof padding !== 'number' ? expandPaddingObject(padding) : {
213
- top: padding,
214
- right: padding,
215
- bottom: padding,
216
- left: padding
217
- };
218
- }
219
-
220
- function rectToClientRect(rect) {
221
- return { ...rect,
222
- top: rect.y,
223
- left: rect.x,
224
- right: rect.x + rect.width,
225
- bottom: rect.y + rect.height
226
- };
227
- }
228
-
229
- /**
230
- * Resolves with an object of overflow side offsets that determine how much the
231
- * element is overflowing a given clipping boundary.
232
- * - positive = overflowing the boundary by that number of pixels
233
- * - negative = how many pixels left before it will overflow
234
- * - 0 = lies flush with the boundary
235
- * @see https://floating-ui.com/docs/detectOverflow
236
- */
237
- async function detectOverflow(middlewareArguments, options) {
238
- var _await$platform$isEle;
239
-
240
- if (options === void 0) {
241
- options = {};
242
- }
243
-
244
- const {
245
- x,
246
- y,
247
- platform,
248
- rects,
249
- elements,
250
- strategy
251
- } = middlewareArguments;
252
- const {
253
- boundary = 'clippingAncestors',
254
- rootBoundary = 'viewport',
255
- elementContext = 'floating',
256
- altBoundary = false,
257
- padding = 0
258
- } = options;
259
- const paddingObject = getSideObjectFromPadding(padding);
260
- const altContext = elementContext === 'floating' ? 'reference' : 'floating';
261
- const element = elements[altBoundary ? altContext : elementContext];
262
- const clippingClientRect = rectToClientRect(await platform.getClippingRect({
263
- 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))),
264
- boundary,
265
- rootBoundary,
266
- strategy
267
- }));
268
- const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
269
- rect: elementContext === 'floating' ? { ...rects.floating,
270
- x,
271
- y
272
- } : rects.reference,
273
- offsetParent: await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating)),
274
- strategy
275
- }) : rects[elementContext]); // positive = overflowing the clipping rect
276
- // 0 or negative = within the clipping rect
277
-
278
- return {
279
- top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
280
- bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
281
- left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
282
- right: elementClientRect.right - clippingClientRect.right + paddingObject.right
283
- };
284
- }
285
-
286
- const min$1 = Math.min;
287
- const max$1 = Math.max;
288
-
289
- function within(min$1$1, value, max$1$1) {
290
- return max$1(min$1$1, min$1(value, max$1$1));
291
- }
292
-
293
- /**
294
- * Positions an inner element of the floating element such that it is centered
295
- * to the reference element.
296
- * @see https://floating-ui.com/docs/arrow
297
- */
298
- const arrow = options => ({
299
- name: 'arrow',
300
- options,
301
-
302
- async fn(middlewareArguments) {
303
- // Since `element` is required, we don't Partial<> the type
304
- const {
305
- element,
306
- padding = 0
307
- } = options != null ? options : {};
308
- const {
309
- x,
310
- y,
311
- placement,
312
- rects,
313
- platform
314
- } = middlewareArguments;
315
-
316
- if (element == null) {
317
- if ("development" !== "production") {
318
- console.warn('Floating UI: No `element` was passed to the `arrow` middleware.');
319
- }
320
-
321
- return {};
322
- }
323
-
324
- const paddingObject = getSideObjectFromPadding(padding);
325
- const coords = {
326
- x,
327
- y
328
- };
329
- const axis = getMainAxisFromPlacement(placement);
330
- const length = getLengthFromAxis(axis);
331
- const arrowDimensions = await platform.getDimensions(element);
332
- const minProp = axis === 'y' ? 'top' : 'left';
333
- const maxProp = axis === 'y' ? 'bottom' : 'right';
334
- const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
335
- const startDiff = coords[axis] - rects.reference[axis];
336
- const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
337
- const clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
338
- const centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the floating element if the center
339
- // point is outside of the floating element's bounds
340
-
341
- const min = paddingObject[minProp];
342
- const max = clientSize - arrowDimensions[length] - paddingObject[maxProp];
343
- const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
344
- const offset = within(min, center, max);
345
- return {
346
- data: {
347
- [axis]: offset,
348
- centerOffset: center - offset
349
- }
350
- };
351
- }
352
-
353
- });
354
-
355
- const hash$1 = {
356
- left: 'right',
357
- right: 'left',
358
- bottom: 'top',
359
- top: 'bottom'
360
- };
361
- function getOppositePlacement(placement) {
362
- return placement.replace(/left|right|bottom|top/g, matched => hash$1[matched]);
363
- }
364
-
365
- function getAlignmentSides(placement, rects, rtl) {
366
- if (rtl === void 0) {
367
- rtl = false;
368
- }
369
-
370
- const alignment = getAlignment(placement);
371
- const mainAxis = getMainAxisFromPlacement(placement);
372
- const length = getLengthFromAxis(mainAxis);
373
- let mainAlignmentSide = mainAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
374
-
375
- if (rects.reference[length] > rects.floating[length]) {
376
- mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
377
- }
378
-
379
- return {
380
- main: mainAlignmentSide,
381
- cross: getOppositePlacement(mainAlignmentSide)
382
- };
383
- }
384
-
385
- const hash = {
386
- start: 'end',
387
- end: 'start'
388
- };
389
- function getOppositeAlignmentPlacement(placement) {
390
- return placement.replace(/start|end/g, matched => hash[matched]);
391
- }
392
-
393
- const sides = ['top', 'right', 'bottom', 'left'];
394
- const allPlacements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-start", side + "-end"), []);
395
-
396
- function getPlacementList(alignment, autoAlignment, allowedPlacements) {
397
- const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);
398
- return allowedPlacementsSortedByAlignment.filter(placement => {
399
- if (alignment) {
400
- return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
401
- }
402
-
403
- return true;
404
- });
405
- }
406
-
407
- /**
408
- * Automatically chooses the `placement` which has the most space available.
409
- * @see https://floating-ui.com/docs/autoPlacement
410
- */
411
- const autoPlacement = function (options) {
412
- if (options === void 0) {
413
- options = {};
414
- }
415
-
416
- return {
417
- name: 'autoPlacement',
418
- options,
419
-
420
- async fn(middlewareArguments) {
421
- var _middlewareData$autoP, _middlewareData$autoP2, _middlewareData$autoP3, _middlewareData$autoP4, _placementsSortedByLe;
422
-
423
- const {
424
- x,
425
- y,
426
- rects,
427
- middlewareData,
428
- placement,
429
- platform,
430
- elements
431
- } = middlewareArguments;
432
- const {
433
- alignment = null,
434
- allowedPlacements = allPlacements,
435
- autoAlignment = true,
436
- ...detectOverflowOptions
437
- } = options;
438
- const placements = getPlacementList(alignment, autoAlignment, allowedPlacements);
439
- const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
440
- const currentIndex = (_middlewareData$autoP = (_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.index) != null ? _middlewareData$autoP : 0;
441
- const currentPlacement = placements[currentIndex];
442
-
443
- if (currentPlacement == null) {
444
- return {};
445
- }
446
-
447
- const {
448
- main,
449
- cross
450
- } = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))); // Make `computeCoords` start from the right place
451
-
452
- if (placement !== currentPlacement) {
453
- return {
454
- x,
455
- y,
456
- reset: {
457
- placement: placements[0]
458
- }
459
- };
460
- }
461
-
462
- const currentOverflows = [overflow[getSide(currentPlacement)], overflow[main], overflow[cross]];
463
- const allOverflows = [...((_middlewareData$autoP3 = (_middlewareData$autoP4 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP4.overflows) != null ? _middlewareData$autoP3 : []), {
464
- placement: currentPlacement,
465
- overflows: currentOverflows
466
- }];
467
- const nextPlacement = placements[currentIndex + 1]; // There are more placements to check
468
-
469
- if (nextPlacement) {
470
- return {
471
- data: {
472
- index: currentIndex + 1,
473
- overflows: allOverflows
474
- },
475
- reset: {
476
- placement: nextPlacement
477
- }
478
- };
479
- }
480
-
481
- const placementsSortedByLeastOverflow = allOverflows.slice().sort((a, b) => a.overflows[0] - b.overflows[0]);
482
- const placementThatFitsOnAllSides = (_placementsSortedByLe = placementsSortedByLeastOverflow.find(_ref => {
483
- let {
484
- overflows
485
- } = _ref;
486
- return overflows.every(overflow => overflow <= 0);
487
- })) == null ? void 0 : _placementsSortedByLe.placement;
488
- const resetPlacement = placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement;
489
-
490
- if (resetPlacement !== placement) {
491
- return {
492
- data: {
493
- index: currentIndex + 1,
494
- overflows: allOverflows
495
- },
496
- reset: {
497
- placement: resetPlacement
498
- }
499
- };
500
- }
501
-
502
- return {};
503
- }
504
-
505
- };
506
- };
507
-
508
- function getExpandedPlacements(placement) {
509
- const oppositePlacement = getOppositePlacement(placement);
510
- return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
511
- }
512
-
513
- /**
514
- * Changes the placement of the floating element to one that will fit if the
515
- * initially specified `placement` does not.
516
- * @see https://floating-ui.com/docs/flip
517
- */
518
- const flip = function (options) {
519
- if (options === void 0) {
520
- options = {};
521
- }
522
-
523
- return {
524
- name: 'flip',
525
- options,
526
-
527
- async fn(middlewareArguments) {
528
- var _middlewareData$flip;
529
-
530
- const {
531
- placement,
532
- middlewareData,
533
- rects,
534
- initialPlacement,
535
- platform,
536
- elements
537
- } = middlewareArguments;
538
- const {
539
- mainAxis: checkMainAxis = true,
540
- crossAxis: checkCrossAxis = true,
541
- fallbackPlacements: specifiedFallbackPlacements,
542
- fallbackStrategy = 'bestFit',
543
- flipAlignment = true,
544
- ...detectOverflowOptions
545
- } = options;
546
- const side = getSide(placement);
547
- const isBasePlacement = side === initialPlacement;
548
- const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
549
- const placements = [initialPlacement, ...fallbackPlacements];
550
- const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
551
- const overflows = [];
552
- let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
553
-
554
- if (checkMainAxis) {
555
- overflows.push(overflow[side]);
556
- }
557
-
558
- if (checkCrossAxis) {
559
- const {
560
- main,
561
- cross
562
- } = getAlignmentSides(placement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
563
- overflows.push(overflow[main], overflow[cross]);
564
- }
565
-
566
- overflowsData = [...overflowsData, {
567
- placement,
568
- overflows
569
- }]; // One or more sides is overflowing
570
-
571
- if (!overflows.every(side => side <= 0)) {
572
- var _middlewareData$flip$, _middlewareData$flip2;
573
-
574
- const nextIndex = ((_middlewareData$flip$ = (_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) != null ? _middlewareData$flip$ : 0) + 1;
575
- const nextPlacement = placements[nextIndex];
576
-
577
- if (nextPlacement) {
578
- // Try next placement and re-run the lifecycle
579
- return {
580
- data: {
581
- index: nextIndex,
582
- overflows: overflowsData
583
- },
584
- reset: {
585
- placement: nextPlacement
586
- }
587
- };
588
- }
589
-
590
- let resetPlacement = 'bottom';
591
-
592
- switch (fallbackStrategy) {
593
- case 'bestFit':
594
- {
595
- var _overflowsData$slice$;
596
-
597
- const placement = (_overflowsData$slice$ = overflowsData.slice().sort((a, b) => a.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0) - b.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0))[0]) == null ? void 0 : _overflowsData$slice$.placement;
598
-
599
- if (placement) {
600
- resetPlacement = placement;
601
- }
602
-
603
- break;
604
- }
605
-
606
- case 'initialPlacement':
607
- resetPlacement = initialPlacement;
608
- break;
609
- }
610
-
611
- if (placement !== resetPlacement) {
612
- return {
613
- reset: {
614
- placement: resetPlacement
615
- }
616
- };
617
- }
618
- }
619
-
620
- return {};
621
- }
622
-
623
- };
624
- };
625
-
626
- function getSideOffsets(overflow, rect) {
627
- return {
628
- top: overflow.top - rect.height,
629
- right: overflow.right - rect.width,
630
- bottom: overflow.bottom - rect.height,
631
- left: overflow.left - rect.width
632
- };
633
- }
634
-
635
- function isAnySideFullyClipped(overflow) {
636
- return sides.some(side => overflow[side] >= 0);
637
- }
638
-
639
- /**
640
- * Provides data to hide the floating element in applicable situations, such as
641
- * when it is not in the same clipping context as the reference element.
642
- * @see https://floating-ui.com/docs/hide
643
- */
644
- const hide = function (_temp) {
645
- let {
646
- strategy = 'referenceHidden',
647
- ...detectOverflowOptions
648
- } = _temp === void 0 ? {} : _temp;
649
- return {
650
- name: 'hide',
651
-
652
- async fn(middlewareArguments) {
653
- const {
654
- rects
655
- } = middlewareArguments;
656
-
657
- switch (strategy) {
658
- case 'referenceHidden':
659
- {
660
- const overflow = await detectOverflow(middlewareArguments, { ...detectOverflowOptions,
661
- elementContext: 'reference'
662
- });
663
- const offsets = getSideOffsets(overflow, rects.reference);
664
- return {
665
- data: {
666
- referenceHiddenOffsets: offsets,
667
- referenceHidden: isAnySideFullyClipped(offsets)
668
- }
669
- };
670
- }
671
-
672
- case 'escaped':
673
- {
674
- const overflow = await detectOverflow(middlewareArguments, { ...detectOverflowOptions,
675
- altBoundary: true
676
- });
677
- const offsets = getSideOffsets(overflow, rects.floating);
678
- return {
679
- data: {
680
- escapedOffsets: offsets,
681
- escaped: isAnySideFullyClipped(offsets)
682
- }
683
- };
684
- }
685
-
686
- default:
687
- {
688
- return {};
689
- }
690
- }
691
- }
692
-
693
- };
694
- };
695
-
696
- function convertValueToCoords(placement, rects, value, rtl) {
697
- if (rtl === void 0) {
698
- rtl = false;
699
- }
700
-
701
- const side = getSide(placement);
702
- const alignment = getAlignment(placement);
703
- const isVertical = getMainAxisFromPlacement(placement) === 'x';
704
- const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
705
- const crossAxisMulti = rtl && isVertical ? -1 : 1;
706
- const rawValue = typeof value === 'function' ? value({ ...rects,
707
- placement
708
- }) : value;
709
- const isNumber = typeof rawValue === 'number'; // eslint-disable-next-line prefer-const
710
-
711
- let {
712
- mainAxis,
713
- crossAxis,
714
- alignmentAxis
715
- } = isNumber ? {
716
- mainAxis: rawValue,
717
- crossAxis: 0,
718
- alignmentAxis: null
719
- } : {
720
- mainAxis: 0,
721
- crossAxis: 0,
722
- alignmentAxis: null,
723
- ...rawValue
724
- };
725
-
726
- if (alignment && typeof alignmentAxis === 'number') {
727
- crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
728
- }
729
-
730
- return isVertical ? {
731
- x: crossAxis * crossAxisMulti,
732
- y: mainAxis * mainAxisMulti
733
- } : {
734
- x: mainAxis * mainAxisMulti,
735
- y: crossAxis * crossAxisMulti
736
- };
737
- }
738
- /**
739
- * Displaces the floating element from its reference element.
740
- * @see https://floating-ui.com/docs/offset
741
- */
742
-
743
- const offset = function (value) {
744
- if (value === void 0) {
745
- value = 0;
746
- }
747
-
748
- return {
749
- name: 'offset',
750
- options: value,
751
-
752
- async fn(middlewareArguments) {
753
- const {
754
- x,
755
- y,
756
- placement,
757
- rects,
758
- platform,
759
- elements
760
- } = middlewareArguments;
761
- const diffCoords = convertValueToCoords(placement, rects, value, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
762
- return {
763
- x: x + diffCoords.x,
764
- y: y + diffCoords.y,
765
- data: diffCoords
766
- };
767
- }
768
-
769
- };
770
- };
771
-
772
- function getCrossAxis(axis) {
773
- return axis === 'x' ? 'y' : 'x';
774
- }
775
-
776
- /**
777
- * Shifts the floating element in order to keep it in view when it will overflow
778
- * a clipping boundary.
779
- * @see https://floating-ui.com/docs/shift
780
- */
781
- const shift = function (options) {
782
- if (options === void 0) {
783
- options = {};
784
- }
785
-
786
- return {
787
- name: 'shift',
788
- options,
789
-
790
- async fn(middlewareArguments) {
791
- const {
792
- x,
793
- y,
794
- placement
795
- } = middlewareArguments;
796
- const {
797
- mainAxis: checkMainAxis = true,
798
- crossAxis: checkCrossAxis = false,
799
- limiter = {
800
- fn: _ref => {
801
- let {
802
- x,
803
- y
804
- } = _ref;
805
- return {
806
- x,
807
- y
808
- };
809
- }
810
- },
811
- ...detectOverflowOptions
812
- } = options;
813
- const coords = {
814
- x,
815
- y
816
- };
817
- const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
818
- const mainAxis = getMainAxisFromPlacement(getSide(placement));
819
- const crossAxis = getCrossAxis(mainAxis);
820
- let mainAxisCoord = coords[mainAxis];
821
- let crossAxisCoord = coords[crossAxis];
822
-
823
- if (checkMainAxis) {
824
- const minSide = mainAxis === 'y' ? 'top' : 'left';
825
- const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
826
- const min = mainAxisCoord + overflow[minSide];
827
- const max = mainAxisCoord - overflow[maxSide];
828
- mainAxisCoord = within(min, mainAxisCoord, max);
829
- }
830
-
831
- if (checkCrossAxis) {
832
- const minSide = crossAxis === 'y' ? 'top' : 'left';
833
- const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
834
- const min = crossAxisCoord + overflow[minSide];
835
- const max = crossAxisCoord - overflow[maxSide];
836
- crossAxisCoord = within(min, crossAxisCoord, max);
837
- }
838
-
839
- const limitedCoords = limiter.fn({ ...middlewareArguments,
840
- [mainAxis]: mainAxisCoord,
841
- [crossAxis]: crossAxisCoord
842
- });
843
- return { ...limitedCoords,
844
- data: {
845
- x: limitedCoords.x - x,
846
- y: limitedCoords.y - y
847
- }
848
- };
849
- }
850
-
851
- };
852
- };
853
-
854
- /**
855
- * Built-in `limiter` that will stop `shift()` at a certain point.
856
- */
857
- const limitShift = function (options) {
858
- if (options === void 0) {
859
- options = {};
860
- }
861
-
862
- return {
863
- options,
864
-
865
- fn(middlewareArguments) {
866
- const {
867
- x,
868
- y,
869
- placement,
870
- rects,
871
- middlewareData
872
- } = middlewareArguments;
873
- const {
874
- offset = 0,
875
- mainAxis: checkMainAxis = true,
876
- crossAxis: checkCrossAxis = true
877
- } = options;
878
- const coords = {
879
- x,
880
- y
881
- };
882
- const mainAxis = getMainAxisFromPlacement(placement);
883
- const crossAxis = getCrossAxis(mainAxis);
884
- let mainAxisCoord = coords[mainAxis];
885
- let crossAxisCoord = coords[crossAxis];
886
- const rawOffset = typeof offset === 'function' ? offset({ ...rects,
887
- placement
888
- }) : offset;
889
- const computedOffset = typeof rawOffset === 'number' ? {
890
- mainAxis: rawOffset,
891
- crossAxis: 0
892
- } : {
893
- mainAxis: 0,
894
- crossAxis: 0,
895
- ...rawOffset
896
- };
897
-
898
- if (checkMainAxis) {
899
- const len = mainAxis === 'y' ? 'height' : 'width';
900
- const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
901
- const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
902
-
903
- if (mainAxisCoord < limitMin) {
904
- mainAxisCoord = limitMin;
905
- } else if (mainAxisCoord > limitMax) {
906
- mainAxisCoord = limitMax;
907
- }
908
- }
909
-
910
- if (checkCrossAxis) {
911
- var _middlewareData$offse, _middlewareData$offse2, _middlewareData$offse3, _middlewareData$offse4;
912
-
913
- const len = mainAxis === 'y' ? 'width' : 'height';
914
- const isOriginSide = ['top', 'left'].includes(getSide(placement));
915
- const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? (_middlewareData$offse = (_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) != null ? _middlewareData$offse : 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
916
- const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : (_middlewareData$offse3 = (_middlewareData$offse4 = middlewareData.offset) == null ? void 0 : _middlewareData$offse4[crossAxis]) != null ? _middlewareData$offse3 : 0) - (isOriginSide ? computedOffset.crossAxis : 0);
917
-
918
- if (crossAxisCoord < limitMin) {
919
- crossAxisCoord = limitMin;
920
- } else if (crossAxisCoord > limitMax) {
921
- crossAxisCoord = limitMax;
922
- }
923
- }
924
-
925
- return {
926
- [mainAxis]: mainAxisCoord,
927
- [crossAxis]: crossAxisCoord
928
- };
929
- }
930
-
931
- };
932
- };
933
-
934
- /**
935
- * Provides data to change the size of the floating element. For instance,
936
- * prevent it from overflowing its clipping boundary or match the width of the
937
- * reference element.
938
- * @see https://floating-ui.com/docs/size
939
- */
940
- const size = function (options) {
941
- if (options === void 0) {
942
- options = {};
943
- }
944
-
945
- return {
946
- name: 'size',
947
- options,
948
-
949
- async fn(middlewareArguments) {
950
- const {
951
- placement,
952
- rects,
953
- platform,
954
- elements
955
- } = middlewareArguments;
956
- const {
957
- apply,
958
- ...detectOverflowOptions
959
- } = options;
960
- const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
961
- const side = getSide(placement);
962
- const alignment = getAlignment(placement);
963
- let heightSide;
964
- let widthSide;
965
-
966
- if (side === 'top' || side === 'bottom') {
967
- heightSide = side;
968
- widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
969
- } else {
970
- widthSide = side;
971
- heightSide = alignment === 'end' ? 'top' : 'bottom';
972
- }
973
-
974
- const xMin = max$1(overflow.left, 0);
975
- const xMax = max$1(overflow.right, 0);
976
- const yMin = max$1(overflow.top, 0);
977
- const yMax = max$1(overflow.bottom, 0);
978
- const dimensions = {
979
- height: rects.floating.height - (['left', 'right'].includes(placement) ? 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max$1(overflow.top, overflow.bottom)) : overflow[heightSide]),
980
- width: rects.floating.width - (['top', 'bottom'].includes(placement) ? 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max$1(overflow.left, overflow.right)) : overflow[widthSide])
981
- };
982
- const prevDimensions = await platform.getDimensions(elements.floating);
983
- apply == null ? void 0 : apply({ ...dimensions,
984
- ...rects
985
- });
986
- const nextDimensions = await platform.getDimensions(elements.floating);
987
-
988
- if (prevDimensions.width !== nextDimensions.width || prevDimensions.height !== nextDimensions.height) {
989
- return {
990
- reset: {
991
- rects: true
992
- }
993
- };
994
- }
995
-
996
- return {};
997
- }
998
-
999
- };
1000
- };
1001
-
1002
- /**
1003
- * Provides improved positioning for inline reference elements that can span
1004
- * over multiple lines, such as hyperlinks or range selections.
1005
- * @see https://floating-ui.com/docs/inline
1006
- */
1007
- const inline = function (options) {
1008
- if (options === void 0) {
1009
- options = {};
1010
- }
1011
-
1012
- return {
1013
- name: 'inline',
1014
- options,
1015
-
1016
- async fn(middlewareArguments) {
1017
- var _await$platform$getCl;
1018
-
1019
- const {
1020
- placement,
1021
- elements,
1022
- rects,
1023
- platform,
1024
- strategy
1025
- } = middlewareArguments; // A MouseEvent's client{X,Y} coords can be up to 2 pixels off a
1026
- // ClientRect's bounds, despite the event listener being triggered. A
1027
- // padding of 2 seems to handle this issue.
1028
-
1029
- const {
1030
- padding = 2,
1031
- x,
1032
- y
1033
- } = options;
1034
- const fallback = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
1035
- rect: rects.reference,
1036
- offsetParent: await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating)),
1037
- strategy
1038
- }) : rects.reference);
1039
- const clientRects = (_await$platform$getCl = await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference))) != null ? _await$platform$getCl : [];
1040
- const paddingObject = getSideObjectFromPadding(padding);
1041
-
1042
- function getBoundingClientRect() {
1043
- // There are two rects and they are disjoined
1044
- if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
1045
- var _clientRects$find;
1046
-
1047
- // Find the first rect in which the point is fully inside
1048
- return (_clientRects$find = clientRects.find(rect => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom)) != null ? _clientRects$find : fallback;
1049
- } // There are 2 or more connected rects
1050
-
1051
-
1052
- if (clientRects.length >= 2) {
1053
- if (getMainAxisFromPlacement(placement) === 'x') {
1054
- const firstRect = clientRects[0];
1055
- const lastRect = clientRects[clientRects.length - 1];
1056
- const isTop = getSide(placement) === 'top';
1057
- const top = firstRect.top;
1058
- const bottom = lastRect.bottom;
1059
- const left = isTop ? firstRect.left : lastRect.left;
1060
- const right = isTop ? firstRect.right : lastRect.right;
1061
- const width = right - left;
1062
- const height = bottom - top;
1063
- return {
1064
- top,
1065
- bottom,
1066
- left,
1067
- right,
1068
- width,
1069
- height,
1070
- x: left,
1071
- y: top
1072
- };
1073
- }
1074
-
1075
- const isLeftSide = getSide(placement) === 'left';
1076
- const maxRight = max$1(...clientRects.map(rect => rect.right));
1077
- const minLeft = min$1(...clientRects.map(rect => rect.left));
1078
- const measureRects = clientRects.filter(rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
1079
- const top = measureRects[0].top;
1080
- const bottom = measureRects[measureRects.length - 1].bottom;
1081
- const left = minLeft;
1082
- const right = maxRight;
1083
- const width = right - left;
1084
- const height = bottom - top;
1085
- return {
1086
- top,
1087
- bottom,
1088
- left,
1089
- right,
1090
- width,
1091
- height,
1092
- x: left,
1093
- y: top
1094
- };
1095
- }
1096
-
1097
- return fallback;
1098
- }
1099
-
1100
- const resetRects = await platform.getElementRects({
1101
- reference: {
1102
- getBoundingClientRect
1103
- },
1104
- floating: elements.floating,
1105
- strategy
1106
- });
1107
-
1108
- 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) {
1109
- return {
1110
- reset: {
1111
- rects: resetRects
1112
- }
1113
- };
1114
- }
1115
-
1116
- return {};
1117
- }
1118
-
1119
- };
1120
- };
1121
-
1122
- function isWindow(value) {
1123
- return (value == null ? void 0 : value.toString()) === '[object Window]';
1124
- }
1125
- function getWindow(node) {
1126
- if (node == null) {
1127
- return window;
1128
- }
1129
-
1130
- if (!isWindow(node)) {
1131
- const ownerDocument = node.ownerDocument;
1132
- return ownerDocument ? ownerDocument.defaultView || window : window;
1133
- }
1134
-
1135
- return node;
1136
- }
1137
-
1138
- function getComputedStyle$1(element) {
1139
- return getWindow(element).getComputedStyle(element);
1140
- }
1141
-
1142
- function getNodeName(node) {
1143
- return isWindow(node) ? '' : node ? (node.nodeName || '').toLowerCase() : '';
1144
- }
1145
-
1146
- function isHTMLElement(value) {
1147
- return value instanceof getWindow(value).HTMLElement;
1148
- }
1149
- function isElement(value) {
1150
- return value instanceof getWindow(value).Element;
1151
- }
1152
- function isNode(value) {
1153
- return value instanceof getWindow(value).Node;
1154
- }
1155
- function isShadowRoot(node) {
1156
- const OwnElement = getWindow(node).ShadowRoot;
1157
- return node instanceof OwnElement || node instanceof ShadowRoot;
1158
- }
1159
- function isOverflowElement(element) {
1160
- // Firefox wants us to check `-x` and `-y` variations as well
1161
- const {
1162
- overflow,
1163
- overflowX,
1164
- overflowY
1165
- } = getComputedStyle$1(element);
1166
- return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
1167
- }
1168
- function isTableElement(element) {
1169
- return ['table', 'td', 'th'].includes(getNodeName(element));
1170
- }
1171
- function isContainingBlock(element) {
1172
- // TODO: Try and use feature detection here instead
1173
- const isFirefox = navigator.userAgent.toLowerCase().includes('firefox');
1174
- const css = getComputedStyle$1(element); // This is non-exhaustive but covers the most common CSS properties that
1175
- // create a containing block.
1176
- // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1177
-
1178
- return css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].includes(css.willChange) || isFirefox && css.willChange === 'filter' || isFirefox && (css.filter ? css.filter !== 'none' : false);
1179
- }
1180
- function isLayoutViewport() {
1181
- // Not Safari
1182
- return !/^((?!chrome|android).)*safari/i.test(navigator.userAgent); // Feature detection for this fails in various ways
1183
- // • Always-visible scrollbar or not
1184
- // • Width of <html>, etc.
1185
- // const vV = win.visualViewport;
1186
- // return vV ? Math.abs(win.innerWidth / vV.scale - vV.width) < 0.5 : true;
1187
- }
1188
-
1189
- const min = Math.min;
1190
- const max = Math.max;
1191
- const round = Math.round;
1192
-
1193
- function getBoundingClientRect(element, includeScale, isFixedStrategy) {
1194
- if (includeScale === void 0) {
1195
- includeScale = false;
1196
- }
1197
-
1198
- if (isFixedStrategy === void 0) {
1199
- isFixedStrategy = false;
1200
- }
1201
-
1202
- const clientRect = element.getBoundingClientRect();
1203
- let scaleX = 1;
1204
- let scaleY = 1;
1205
-
1206
- if (includeScale && isHTMLElement(element)) {
1207
- scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
1208
- scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
1209
- }
1210
-
1211
- const win = isElement(element) ? getWindow(element) : window;
1212
- const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
1213
- const x = (clientRect.left + (addVisualOffsets ? win.visualViewport.offsetLeft : 0)) / scaleX;
1214
- const y = (clientRect.top + (addVisualOffsets ? win.visualViewport.offsetTop : 0)) / scaleY;
1215
- const width = clientRect.width / scaleX;
1216
- const height = clientRect.height / scaleY;
1217
- return {
1218
- width,
1219
- height,
1220
- top: y,
1221
- right: x + width,
1222
- bottom: y + height,
1223
- left: x,
1224
- x,
1225
- y
1226
- };
1227
- }
1228
-
1229
- function getDocumentElement(node) {
1230
- return ((isNode(node) ? node.ownerDocument : node.document) || window.document).documentElement;
1231
- }
1232
-
1233
- function getNodeScroll(element) {
1234
- if (isWindow(element)) {
1235
- return {
1236
- scrollLeft: element.pageXOffset,
1237
- scrollTop: element.pageYOffset
1238
- };
1239
- }
1240
-
1241
- return {
1242
- scrollLeft: element.scrollLeft,
1243
- scrollTop: element.scrollTop
1244
- };
1245
- }
1246
-
1247
- function getWindowScrollBarX(element) {
1248
- // If <html> has a CSS width greater than the viewport, then this will be
1249
- // incorrect for RTL.
1250
- return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
1251
- }
1252
-
1253
- function isScaled(element) {
1254
- const rect = getBoundingClientRect(element);
1255
- return round(rect.width) !== element.offsetWidth || round(rect.height) !== element.offsetHeight;
1256
- }
1257
-
1258
- function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1259
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
1260
- const documentElement = getDocumentElement(offsetParent);
1261
- const rect = getBoundingClientRect(element, isOffsetParentAnElement && isScaled(offsetParent), strategy === 'fixed');
1262
- let scroll = {
1263
- scrollLeft: 0,
1264
- scrollTop: 0
1265
- };
1266
- const offsets = {
1267
- x: 0,
1268
- y: 0
1269
- };
1270
-
1271
- if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
1272
- if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1273
- scroll = getNodeScroll(offsetParent);
1274
- }
1275
-
1276
- if (isHTMLElement(offsetParent)) {
1277
- const offsetRect = getBoundingClientRect(offsetParent, true);
1278
- offsets.x = offsetRect.x + offsetParent.clientLeft;
1279
- offsets.y = offsetRect.y + offsetParent.clientTop;
1280
- } else if (documentElement) {
1281
- offsets.x = getWindowScrollBarX(documentElement);
1282
- }
1283
- }
1284
-
1285
- return {
1286
- x: rect.left + scroll.scrollLeft - offsets.x,
1287
- y: rect.top + scroll.scrollTop - offsets.y,
1288
- width: rect.width,
1289
- height: rect.height
1290
- };
1291
- }
1292
-
1293
- function getParentNode(node) {
1294
- if (getNodeName(node) === 'html') {
1295
- return node;
1296
- }
1297
-
1298
- return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
1299
- // @ts-ignore
1300
- node.assignedSlot || // step into the shadow DOM of the parent of a slotted node
1301
- node.parentNode || ( // DOM Element detected
1302
- isShadowRoot(node) ? node.host : null) || // ShadowRoot detected
1303
- getDocumentElement(node) // fallback
1304
-
1305
- );
1306
- }
1307
-
1308
- function getTrueOffsetParent(element) {
1309
- if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {
1310
- return null;
1311
- }
1312
-
1313
- return element.offsetParent;
1314
- }
1315
-
1316
- function getContainingBlock(element) {
1317
- let currentNode = getParentNode(element);
1318
-
1319
- if (isShadowRoot(currentNode)) {
1320
- currentNode = currentNode.host;
1321
- }
1322
-
1323
- while (isHTMLElement(currentNode) && !['html', 'body'].includes(getNodeName(currentNode))) {
1324
- if (isContainingBlock(currentNode)) {
1325
- return currentNode;
1326
- } else {
1327
- currentNode = currentNode.parentNode;
1328
- }
1329
- }
1330
-
1331
- return null;
1332
- } // Gets the closest ancestor positioned element. Handles some edge cases,
1333
- // such as table ancestors and cross browser bugs.
1334
-
1335
-
1336
- function getOffsetParent(element) {
1337
- const window = getWindow(element);
1338
- let offsetParent = getTrueOffsetParent(element);
1339
-
1340
- while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
1341
- offsetParent = getTrueOffsetParent(offsetParent);
1342
- }
1343
-
1344
- if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
1345
- return window;
1346
- }
1347
-
1348
- return offsetParent || getContainingBlock(element) || window;
1349
- }
1350
-
1351
- function getDimensions(element) {
1352
- if (isHTMLElement(element)) {
1353
- return {
1354
- width: element.offsetWidth,
1355
- height: element.offsetHeight
1356
- };
1357
- }
1358
-
1359
- const rect = getBoundingClientRect(element);
1360
- return {
1361
- width: rect.width,
1362
- height: rect.height
1363
- };
1364
- }
1365
-
1366
- function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1367
- let {
1368
- rect,
1369
- offsetParent,
1370
- strategy
1371
- } = _ref;
1372
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
1373
- const documentElement = getDocumentElement(offsetParent);
1374
-
1375
- if (offsetParent === documentElement) {
1376
- return rect;
1377
- }
1378
-
1379
- let scroll = {
1380
- scrollLeft: 0,
1381
- scrollTop: 0
1382
- };
1383
- const offsets = {
1384
- x: 0,
1385
- y: 0
1386
- };
1387
-
1388
- if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
1389
- if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1390
- scroll = getNodeScroll(offsetParent);
1391
- }
1392
-
1393
- if (isHTMLElement(offsetParent)) {
1394
- const offsetRect = getBoundingClientRect(offsetParent, true);
1395
- offsets.x = offsetRect.x + offsetParent.clientLeft;
1396
- offsets.y = offsetRect.y + offsetParent.clientTop;
1397
- } // This doesn't appear to be need to be negated.
1398
- // else if (documentElement) {
1399
- // offsets.x = getWindowScrollBarX(documentElement);
1400
- // }
1401
-
1402
- }
1403
-
1404
- return { ...rect,
1405
- x: rect.x - scroll.scrollLeft + offsets.x,
1406
- y: rect.y - scroll.scrollTop + offsets.y
1407
- };
1408
- }
1409
-
1410
- function getViewportRect(element, strategy) {
1411
- const win = getWindow(element);
1412
- const html = getDocumentElement(element);
1413
- const visualViewport = win.visualViewport;
1414
- let width = html.clientWidth;
1415
- let height = html.clientHeight;
1416
- let x = 0;
1417
- let y = 0;
1418
-
1419
- if (visualViewport) {
1420
- width = visualViewport.width;
1421
- height = visualViewport.height;
1422
- const layoutViewport = isLayoutViewport();
1423
-
1424
- if (layoutViewport || !layoutViewport && strategy === 'fixed') {
1425
- x = visualViewport.offsetLeft;
1426
- y = visualViewport.offsetTop;
1427
- }
1428
- }
1429
-
1430
- return {
1431
- width,
1432
- height,
1433
- x,
1434
- y
1435
- };
1436
- }
1437
-
1438
- // of the `<html>` and `<body>` rect bounds if horizontally scrollable
1439
-
1440
- function getDocumentRect(element) {
1441
- var _element$ownerDocumen;
1442
-
1443
- const html = getDocumentElement(element);
1444
- const scroll = getNodeScroll(element);
1445
- const body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
1446
- const width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
1447
- const height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
1448
- let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1449
- const y = -scroll.scrollTop;
1450
-
1451
- if (getComputedStyle$1(body || html).direction === 'rtl') {
1452
- x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
1453
- }
1454
-
1455
- return {
1456
- width,
1457
- height,
1458
- x,
1459
- y
1460
- };
1461
- }
1462
-
1463
- function getNearestOverflowAncestor(node) {
1464
- const parentNode = getParentNode(node);
1465
-
1466
- if (['html', 'body', '#document'].includes(getNodeName(parentNode))) {
1467
- // @ts-ignore assume body is always available
1468
- return node.ownerDocument.body;
1469
- }
1470
-
1471
- if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
1472
- return parentNode;
1473
- }
1474
-
1475
- return getNearestOverflowAncestor(parentNode);
1476
- }
1477
-
1478
- function getOverflowAncestors(node, list) {
1479
- var _node$ownerDocument;
1480
-
1481
- if (list === void 0) {
1482
- list = [];
1483
- }
1484
-
1485
- const scrollableAncestor = getNearestOverflowAncestor(node);
1486
- const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
1487
- const win = getWindow(scrollableAncestor);
1488
- const target = isBody ? [win].concat(win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []) : scrollableAncestor;
1489
- const updatedList = list.concat(target);
1490
- return isBody ? updatedList : // @ts-ignore: isBody tells us target will be an HTMLElement here
1491
- updatedList.concat(getOverflowAncestors(getParentNode(target)));
1492
- }
1493
-
1494
- function contains(parent, child) {
1495
- const rootNode = child.getRootNode == null ? void 0 : child.getRootNode(); // First, attempt with faster native method
1496
-
1497
- if (parent.contains(child)) {
1498
- return true;
1499
- } // then fallback to custom implementation with Shadow DOM support
1500
- else if (rootNode && isShadowRoot(rootNode)) {
1501
- let next = child;
1502
-
1503
- do {
1504
- // use `===` replace node.isSameNode()
1505
- if (next && parent === next) {
1506
- return true;
1507
- } // @ts-ignore: need a better way to handle this...
1508
-
1509
-
1510
- next = next.parentNode || next.host;
1511
- } while (next);
1512
- }
1513
-
1514
- return false;
1515
- }
1516
-
1517
- function getInnerBoundingClientRect(element, strategy) {
1518
- const clientRect = getBoundingClientRect(element, false, strategy === 'fixed');
1519
- const top = clientRect.top + element.clientTop;
1520
- const left = clientRect.left + element.clientLeft;
1521
- return {
1522
- top,
1523
- left,
1524
- x: left,
1525
- y: top,
1526
- right: left + element.clientWidth,
1527
- bottom: top + element.clientHeight,
1528
- width: element.clientWidth,
1529
- height: element.clientHeight
1530
- };
1531
- }
1532
-
1533
- function getClientRectFromClippingAncestor(element, clippingParent, strategy) {
1534
- if (clippingParent === 'viewport') {
1535
- return rectToClientRect(getViewportRect(element, strategy));
1536
- }
1537
-
1538
- if (isElement(clippingParent)) {
1539
- return getInnerBoundingClientRect(clippingParent, strategy);
1540
- }
1541
-
1542
- return rectToClientRect(getDocumentRect(getDocumentElement(element)));
1543
- } // A "clipping ancestor" is an overflowable container with the characteristic of
1544
- // clipping (or hiding) overflowing elements with a position different from
1545
- // `initial`
1546
-
1547
-
1548
- function getClippingAncestors(element) {
1549
- const clippingAncestors = getOverflowAncestors(element);
1550
- const canEscapeClipping = ['absolute', 'fixed'].includes(getComputedStyle$1(element).position);
1551
- const clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
1552
-
1553
- if (!isElement(clipperElement)) {
1554
- return [];
1555
- } // @ts-ignore isElement check ensures we return Array<Element>
1556
-
1557
-
1558
- return clippingAncestors.filter(clippingAncestors => isElement(clippingAncestors) && contains(clippingAncestors, clipperElement) && getNodeName(clippingAncestors) !== 'body');
1559
- } // Gets the maximum area that the element is visible in due to any number of
1560
- // clipping ancestors
1561
-
1562
-
1563
- function getClippingRect(_ref) {
1564
- let {
1565
- element,
1566
- boundary,
1567
- rootBoundary,
1568
- strategy
1569
- } = _ref;
1570
- const mainClippingAncestors = boundary === 'clippingAncestors' ? getClippingAncestors(element) : [].concat(boundary);
1571
- const clippingAncestors = [...mainClippingAncestors, rootBoundary];
1572
- const firstClippingAncestor = clippingAncestors[0];
1573
- const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
1574
- const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1575
- accRect.top = max(rect.top, accRect.top);
1576
- accRect.right = min(rect.right, accRect.right);
1577
- accRect.bottom = min(rect.bottom, accRect.bottom);
1578
- accRect.left = max(rect.left, accRect.left);
1579
- return accRect;
1580
- }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1581
- return {
1582
- width: clippingRect.right - clippingRect.left,
1583
- height: clippingRect.bottom - clippingRect.top,
1584
- x: clippingRect.left,
1585
- y: clippingRect.top
1586
- };
1587
- }
1588
-
1589
- const platform = {
1590
- getClippingRect,
1591
- convertOffsetParentRelativeRectToViewportRelativeRect,
1592
- isElement,
1593
- getDimensions,
1594
- getOffsetParent,
1595
- getDocumentElement,
1596
- getElementRects: _ref => {
1597
- let {
1598
- reference,
1599
- floating,
1600
- strategy
1601
- } = _ref;
1602
- return {
1603
- reference: getRectRelativeToOffsetParent(reference, getOffsetParent(floating), strategy),
1604
- floating: { ...getDimensions(floating),
1605
- x: 0,
1606
- y: 0
1607
- }
1608
- };
1609
- },
1610
- getClientRects: element => Array.from(element.getClientRects()),
1611
- isRTL: element => getComputedStyle$1(element).direction === 'rtl'
1612
- };
1613
-
1614
- /**
1615
- * Automatically updates the position of the floating element when necessary.
1616
- * @see https://floating-ui.com/docs/autoUpdate
1617
- */
1618
- function autoUpdate(reference, floating, update, options) {
1619
- if (options === void 0) {
1620
- options = {};
1621
- }
1622
-
1623
- const {
1624
- ancestorScroll: _ancestorScroll = true,
1625
- ancestorResize: _ancestorResize = true,
1626
- elementResize: _elementResize = true,
1627
- animationFrame = false
1628
- } = options;
1629
- let cleanedUp = false;
1630
- const ancestorScroll = _ancestorScroll && !animationFrame;
1631
- const ancestorResize = _ancestorResize && !animationFrame;
1632
- const elementResize = _elementResize && !animationFrame;
1633
- const ancestors = ancestorScroll || ancestorResize ? [...(isElement(reference) ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)] : [];
1634
- ancestors.forEach(ancestor => {
1635
- ancestorScroll && ancestor.addEventListener('scroll', update, {
1636
- passive: true
1637
- });
1638
- ancestorResize && ancestor.addEventListener('resize', update);
1639
- });
1640
- let observer = null;
1641
-
1642
- if (elementResize) {
1643
- observer = new ResizeObserver(update);
1644
- isElement(reference) && observer.observe(reference);
1645
- observer.observe(floating);
1646
- }
1647
-
1648
- let frameId;
1649
- let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1650
-
1651
- if (animationFrame) {
1652
- frameLoop();
1653
- }
1654
-
1655
- function frameLoop() {
1656
- if (cleanedUp) {
1657
- return;
1658
- }
1659
-
1660
- const nextRefRect = getBoundingClientRect(reference);
1661
-
1662
- if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
1663
- update();
1664
- }
1665
-
1666
- prevRefRect = nextRefRect;
1667
- frameId = requestAnimationFrame(frameLoop);
1668
- }
1669
-
1670
- return () => {
1671
- var _observer;
1672
-
1673
- cleanedUp = true;
1674
- ancestors.forEach(ancestor => {
1675
- ancestorScroll && ancestor.removeEventListener('scroll', update);
1676
- ancestorResize && ancestor.removeEventListener('resize', update);
1677
- });
1678
- (_observer = observer) == null ? void 0 : _observer.disconnect();
1679
- observer = null;
1680
-
1681
- if (animationFrame) {
1682
- cancelAnimationFrame(frameId);
1683
- }
1684
- };
1685
- }
1686
-
1687
- /**
1688
- * Computes the `x` and `y` coordinates that will place the floating element
1689
- * next to a reference element when it is given a certain CSS positioning
1690
- * strategy.
1691
- */
1692
-
1693
- const computePosition = (reference, floating, options) => computePosition$1(reference, floating, {
1694
- platform,
1695
- ...options
1696
- });
1697
-
1698
- /*!
1699
- * tabbable 5.3.0-beta.1
1700
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
1701
- */
1702
- var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]:not(slot)', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', 'details>summary:first-of-type', 'details'];
1703
- var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
1704
- var NoElement = typeof Element === 'undefined';
1705
- var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
1706
- var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
1707
- return element.getRootNode();
1708
- } : function (element) {
1709
- return element.ownerDocument;
1710
- };
1711
- /**
1712
- * @param {Element} el container to check in
1713
- * @param {boolean} includeContainer add container to check
1714
- * @param {(node: Element) => boolean} filter filter candidates
1715
- * @returns {Element[]}
1716
- */
1717
-
1718
- var getCandidates = function getCandidates(el, includeContainer, filter) {
1719
- var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
1720
-
1721
- if (includeContainer && matches.call(el, candidateSelector)) {
1722
- candidates.unshift(el);
1723
- }
1724
-
1725
- candidates = candidates.filter(filter);
1726
- return candidates;
1727
- };
1728
- /**
1729
- * @callback GetShadowRoot
1730
- * @param {Element} element to check for shadow root
1731
- * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
1732
- */
1733
-
1734
- /**
1735
- * @typedef {Object} CandidatesScope
1736
- * @property {Element} scope contains inner candidates
1737
- * @property {Element[]} candidates
1738
- */
1739
-
1740
- /**
1741
- * @typedef {Object} IterativeOptions
1742
- * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
1743
- * if a function, implies shadow support is enabled and either returns the shadow root of an element
1744
- * or a boolean stating if it has an undisclosed shadow root
1745
- * @property {(node: Element) => boolean} filter filter candidates
1746
- * @property {boolean} flatten if true then result will flatten any CandidatesScope into the returned list
1747
- */
1748
-
1749
- /**
1750
- * @param {Element[]} elements list of element containers to match candidates from
1751
- * @param {boolean} includeContainer add container list to check
1752
- * @param {IterativeOptions} options
1753
- * @returns {Array.<Element|CandidatesScope>}
1754
- */
1755
-
1756
-
1757
- var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
1758
- var candidates = [];
1759
- var elementsToCheck = Array.from(elements);
1760
-
1761
- while (elementsToCheck.length) {
1762
- var element = elementsToCheck.shift();
1763
-
1764
- if (element.tagName === 'SLOT') {
1765
- // add shadow dom slot scope (slot itself cannot be focusable)
1766
- var assigned = element.assignedElements();
1767
- var content = assigned.length ? assigned : element.children;
1768
- var nestedCandidates = getCandidatesIteratively(content, true, options);
1769
-
1770
- if (options.flatten) {
1771
- candidates.push.apply(candidates, nestedCandidates);
1772
- } else {
1773
- candidates.push({
1774
- scope: element,
1775
- candidates: nestedCandidates
1776
- });
1777
- }
1778
- } else {
1779
- // check candidate element
1780
- var validCandidate = matches.call(element, candidateSelector);
1781
-
1782
- if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
1783
- candidates.push(element);
1784
- } // iterate over shadow content if possible
1785
-
1786
-
1787
- var shadowRoot = element.shadowRoot || // check for an undisclosed shadow
1788
- typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
1789
-
1790
- if (shadowRoot) {
1791
- // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
1792
- // shadow exists, so look at light dom children as fallback BUT create a scope for any
1793
- // child candidates found because they're likely slotted elements (elements that are
1794
- // children of the web component element (which has the shadow), in the light dom, but
1795
- // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
1796
- // _after_ we return from this recursive call
1797
- var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
1798
-
1799
- if (options.flatten) {
1800
- candidates.push.apply(candidates, _nestedCandidates);
1801
- } else {
1802
- candidates.push({
1803
- scope: element,
1804
- candidates: _nestedCandidates
1805
- });
1806
- }
1807
- } else {
1808
- // there's not shadow so just dig into the element's (light dom) children
1809
- // __without__ giving the element special scope treatment
1810
- elementsToCheck.unshift.apply(elementsToCheck, element.children);
1811
- }
1812
- }
1813
- }
1814
-
1815
- return candidates;
1816
- };
1817
-
1818
- var isContentEditable = function isContentEditable(node) {
1819
- return node.contentEditable === 'true';
1820
- };
1821
-
1822
- var getTabindex = function getTabindex(node, isScope) {
1823
- var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);
1824
-
1825
- if (!isNaN(tabindexAttr)) {
1826
- return tabindexAttr;
1827
- } // Browsers do not return `tabIndex` correctly for contentEditable nodes;
1828
- // so if they don't have a tabindex attribute specifically set, assume it's 0.
1829
-
1830
-
1831
- if (isContentEditable(node)) {
1832
- return 0;
1833
- } // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
1834
- // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
1835
- // yet they are still part of the regular tab order; in FF, they get a default
1836
- // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
1837
- // order, consider their tab index to be 0.
1838
- //
1839
- // isScope is positive for custom element with shadow root or slot that by default
1840
- // have tabIndex -1, but need to be sorted by document order in order for their
1841
- // content to be inserted in the correct position
1842
-
1843
-
1844
- if ((isScope || node.nodeName === 'AUDIO' || node.nodeName === 'VIDEO' || node.nodeName === 'DETAILS') && node.getAttribute('tabindex') === null) {
1845
- return 0;
1846
- }
1847
-
1848
- return node.tabIndex;
1849
- };
1850
-
1851
- var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
1852
- return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
1853
- };
1854
-
1855
- var isInput = function isInput(node) {
1856
- return node.tagName === 'INPUT';
1857
- };
1858
-
1859
- var isHiddenInput = function isHiddenInput(node) {
1860
- return isInput(node) && node.type === 'hidden';
1861
- };
1862
-
1863
- var isDetailsWithSummary = function isDetailsWithSummary(node) {
1864
- var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
1865
- return child.tagName === 'SUMMARY';
1866
- });
1867
- return r;
1868
- };
1869
-
1870
- var getCheckedRadio = function getCheckedRadio(nodes, form) {
1871
- for (var i = 0; i < nodes.length; i++) {
1872
- if (nodes[i].checked && nodes[i].form === form) {
1873
- return nodes[i];
1874
- }
1875
- }
1876
- };
1877
-
1878
- var isTabbableRadio = function isTabbableRadio(node) {
1879
- if (!node.name) {
1880
- return true;
1881
- }
1882
-
1883
- var radioScope = node.form || getRootNode(node);
1884
-
1885
- var queryRadios = function queryRadios(name) {
1886
- return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
1887
- };
1888
-
1889
- var radioSet;
1890
-
1891
- if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
1892
- radioSet = queryRadios(window.CSS.escape(node.name));
1893
- } else {
1894
- try {
1895
- radioSet = queryRadios(node.name);
1896
- } catch (err) {
1897
- // eslint-disable-next-line no-console
1898
- console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
1899
- return false;
1900
- }
1901
- }
1902
-
1903
- var checked = getCheckedRadio(radioSet, node.form);
1904
- return !checked || checked === node;
1905
- };
1906
-
1907
- var isRadio = function isRadio(node) {
1908
- return isInput(node) && node.type === 'radio';
1909
- };
1910
-
1911
- var isNonTabbableRadio = function isNonTabbableRadio(node) {
1912
- return isRadio(node) && !isTabbableRadio(node);
1913
- };
1914
-
1915
- var isZeroArea = function isZeroArea(node) {
1916
- var _node$getBoundingClie = node.getBoundingClientRect(),
1917
- width = _node$getBoundingClie.width,
1918
- height = _node$getBoundingClie.height;
1919
-
1920
- return width === 0 && height === 0;
1921
- };
1922
-
1923
- var isHidden = function isHidden(node, _ref) {
1924
- var displayCheck = _ref.displayCheck,
1925
- getShadowRoot = _ref.getShadowRoot;
1926
-
1927
- if (getComputedStyle(node).visibility === 'hidden') {
1928
- return true;
1929
- }
1930
-
1931
- var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
1932
- var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
1933
-
1934
- if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
1935
- return true;
1936
- }
1937
-
1938
- if (!displayCheck || displayCheck === 'full') {
1939
- if (typeof getShadowRoot === 'function') {
1940
- // figure out if we should consider the node to be in an undisclosed shadow and use the
1941
- // 'non-zero-area' fallback
1942
- var originalNode = node;
1943
-
1944
- while (node) {
1945
- var parentElement = node.parentElement;
1946
- var rootNode = getRootNode(node);
1947
-
1948
- if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
1949
- ) {
1950
- // node has an undisclosed shadow which means we can only treat it as a black box, so we
1951
- // fall back to a non-zero-area test
1952
- return isZeroArea(node);
1953
- } else if (node.assignedSlot) {
1954
- // iterate up slot
1955
- node = node.assignedSlot;
1956
- } else if (!parentElement && rootNode !== node.ownerDocument) {
1957
- // cross shadow boundary
1958
- node = rootNode.host;
1959
- } else {
1960
- // iterate up normal dom
1961
- node = parentElement;
1962
- }
1963
- }
1964
-
1965
- node = originalNode;
1966
- } // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
1967
- // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
1968
- // it might be a falsy value, which means shadow DOM support is disabled
1969
- // didn't find it sitting in an undisclosed shadow (or shadows are disabled) so now we
1970
- // can just test to see if it would normally be visible or not
1971
- // this works wherever the node is: if there's at least one client rect, it's
1972
- // somehow displayed; it also covers the CSS 'display: contents' case where the
1973
- // node itself is hidden in place of its contents; and there's no need to search
1974
- // up the hierarchy either
1975
-
1976
-
1977
- return !node.getClientRects().length;
1978
- } else if (displayCheck === 'non-zero-area') {
1979
- return isZeroArea(node);
1980
- }
1981
-
1982
- return false;
1983
- }; // form fields (nested) inside a disabled fieldset are not focusable/tabbable
1984
- // unless they are in the _first_ <legend> element of the top-most disabled
1985
- // fieldset
1986
-
1987
-
1988
- var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
1989
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
1990
- var parentNode = node.parentElement; // check if `node` is contained in a disabled <fieldset>
1991
-
1992
- while (parentNode) {
1993
- if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
1994
- // look for the first <legend> among the children of the disabled <fieldset>
1995
- for (var i = 0; i < parentNode.children.length; i++) {
1996
- var child = parentNode.children.item(i); // when the first <legend> (in document order) is found
1997
-
1998
- if (child.tagName === 'LEGEND') {
1999
- // if its parent <fieldset> is not nested in another disabled <fieldset>,
2000
- // return whether `node` is a descendant of its first <legend>
2001
- return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
2002
- }
2003
- } // the disabled <fieldset> containing `node` has no <legend>
2004
-
2005
-
2006
- return true;
2007
- }
2008
-
2009
- parentNode = parentNode.parentElement;
2010
- }
2011
- } // else, node's tabbable/focusable state should not be affected by a fieldset's
2012
- // enabled/disabled state
2013
-
2014
-
2015
- return false;
2016
- };
2017
-
2018
- var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
2019
- if (node.disabled || isHiddenInput(node) || isHidden(node, options) || // For a details element with a summary, the summary element gets the focus
2020
- isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
2021
- return false;
2022
- }
2023
-
2024
- return true;
2025
- };
2026
-
2027
- var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
2028
- if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) {
2029
- return false;
2030
- }
2031
-
2032
- return true;
2033
- };
2034
- /**
2035
- * @param {Array.<Element|CandidatesScope>} candidates
2036
- * @returns Element[]
2037
- */
2038
-
2039
-
2040
- var sortByOrder = function sortByOrder(candidates) {
2041
- var regularTabbables = [];
2042
- var orderedTabbables = [];
2043
- candidates.forEach(function (item, i) {
2044
- var isScope = !!item.scope;
2045
- var element = isScope ? item.scope : item;
2046
- var candidateTabindex = getTabindex(element, isScope);
2047
- var elements = isScope ? sortByOrder(item.candidates) : element;
2048
-
2049
- if (candidateTabindex === 0) {
2050
- isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
2051
- } else {
2052
- orderedTabbables.push({
2053
- documentOrder: i,
2054
- tabIndex: candidateTabindex,
2055
- item: item,
2056
- isScope: isScope,
2057
- content: elements
2058
- });
2059
- }
2060
- });
2061
- return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
2062
- sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
2063
- return acc;
2064
- }, []).concat(regularTabbables);
2065
- };
2066
-
2067
- var tabbable = function tabbable(el, options) {
2068
- options = options || {};
2069
- var candidates;
2070
-
2071
- if (options.getShadowRoot) {
2072
- candidates = getCandidatesIteratively([el], options.includeContainer, {
2073
- filter: isNodeMatchingSelectorTabbable.bind(null, options),
2074
- flatten: false,
2075
- getShadowRoot: options.getShadowRoot
2076
- });
2077
- } else {
2078
- candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
2079
- }
2080
-
2081
- return sortByOrder(candidates);
2082
- };
2083
-
2084
- var focusable = function focusable(el, options) {
2085
- options = options || {};
2086
- var candidates;
2087
-
2088
- if (options.getShadowRoot) {
2089
- candidates = getCandidatesIteratively([el], options.includeContainer, {
2090
- filter: isNodeMatchingSelectorFocusable.bind(null, options),
2091
- flatten: true,
2092
- getShadowRoot: options.getShadowRoot
2093
- });
2094
- } else {
2095
- candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
2096
- }
2097
-
2098
- return candidates;
2099
- };
2100
-
2101
- var isTabbable = function isTabbable(node, options) {
2102
- options = options || {};
2103
-
2104
- if (!node) {
2105
- throw new Error('No node provided');
2106
- }
2107
-
2108
- if (matches.call(node, candidateSelector) === false) {
2109
- return false;
2110
- }
2111
-
2112
- return isNodeMatchingSelectorTabbable(options, node);
2113
- };
2114
-
2115
- var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
2116
-
2117
- var isFocusable = function isFocusable(node, options) {
2118
- options = options || {};
2119
-
2120
- if (!node) {
2121
- throw new Error('No node provided');
2122
- }
2123
-
2124
- if (matches.call(node, focusableCandidateSelector) === false) {
2125
- return false;
2126
- }
2127
-
2128
- return isNodeMatchingSelectorFocusable(options, node);
2129
- };
2130
-
2131
- /*!
2132
- * focus-trap 6.8.0-beta.2
2133
- * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
2134
- */
2135
-
2136
- function ownKeys(object, enumerableOnly) {
2137
- var keys = Object.keys(object);
2138
-
2139
- if (Object.getOwnPropertySymbols) {
2140
- var symbols = Object.getOwnPropertySymbols(object);
2141
- enumerableOnly && (symbols = symbols.filter(function (sym) {
2142
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2143
- })), keys.push.apply(keys, symbols);
2144
- }
2145
-
2146
- return keys;
2147
- }
2148
-
2149
- function _objectSpread2(target) {
2150
- for (var i = 1; i < arguments.length; i++) {
2151
- var source = null != arguments[i] ? arguments[i] : {};
2152
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
2153
- _defineProperty(target, key, source[key]);
2154
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
2155
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2156
- });
2157
- }
2158
-
2159
- return target;
2160
- }
2161
-
2162
- function _defineProperty(obj, key, value) {
2163
- if (key in obj) {
2164
- Object.defineProperty(obj, key, {
2165
- value: value,
2166
- enumerable: true,
2167
- configurable: true,
2168
- writable: true
2169
- });
2170
- } else {
2171
- obj[key] = value;
2172
- }
2173
-
2174
- return obj;
2175
- }
2176
-
2177
- var activeFocusTraps = function () {
2178
- var trapQueue = [];
2179
- return {
2180
- activateTrap: function activateTrap(trap) {
2181
- if (trapQueue.length > 0) {
2182
- var activeTrap = trapQueue[trapQueue.length - 1];
2183
-
2184
- if (activeTrap !== trap) {
2185
- activeTrap.pause();
2186
- }
2187
- }
2188
-
2189
- var trapIndex = trapQueue.indexOf(trap);
2190
-
2191
- if (trapIndex === -1) {
2192
- trapQueue.push(trap);
2193
- } else {
2194
- // move this existing trap to the front of the queue
2195
- trapQueue.splice(trapIndex, 1);
2196
- trapQueue.push(trap);
2197
- }
2198
- },
2199
- deactivateTrap: function deactivateTrap(trap) {
2200
- var trapIndex = trapQueue.indexOf(trap);
2201
-
2202
- if (trapIndex !== -1) {
2203
- trapQueue.splice(trapIndex, 1);
2204
- }
2205
-
2206
- if (trapQueue.length > 0) {
2207
- trapQueue[trapQueue.length - 1].unpause();
2208
- }
2209
- }
2210
- };
2211
- }();
2212
-
2213
- var isSelectableInput = function isSelectableInput(node) {
2214
- return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
2215
- };
2216
-
2217
- var isEscapeEvent = function isEscapeEvent(e) {
2218
- return e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27;
2219
- };
2220
-
2221
- var isTabEvent = function isTabEvent(e) {
2222
- return e.key === 'Tab' || e.keyCode === 9;
2223
- };
2224
-
2225
- var delay = function delay(fn) {
2226
- return setTimeout(fn, 0);
2227
- }; // Array.find/findIndex() are not supported on IE; this replicates enough
2228
- // of Array.findIndex() for our needs
2229
-
2230
-
2231
- var findIndex = function findIndex(arr, fn) {
2232
- var idx = -1;
2233
- arr.every(function (value, i) {
2234
- if (fn(value)) {
2235
- idx = i;
2236
- return false; // break
2237
- }
2238
-
2239
- return true; // next
2240
- });
2241
- return idx;
2242
- };
2243
- /**
2244
- * Get an option's value when it could be a plain value, or a handler that provides
2245
- * the value.
2246
- * @param {*} value Option's value to check.
2247
- * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
2248
- * @returns {*} The `value`, or the handler's returned value.
2249
- */
2250
-
2251
-
2252
- var valueOrHandler = function valueOrHandler(value) {
2253
- for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2254
- params[_key - 1] = arguments[_key];
2255
- }
2256
-
2257
- return typeof value === 'function' ? value.apply(void 0, params) : value;
2258
- };
2259
-
2260
- var getActualTarget = function getActualTarget(event) {
2261
- // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
2262
- // shadow host. However, event.target.composedPath() will be an array of
2263
- // nodes "clicked" from inner-most (the actual element inside the shadow) to
2264
- // outer-most (the host HTML document). If we have access to composedPath(),
2265
- // then use its first element; otherwise, fall back to event.target (and
2266
- // this only works for an _open_ shadow DOM; otherwise,
2267
- // composedPath()[0] === event.target always).
2268
- return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
2269
- };
2270
-
2271
- var createFocusTrap = function createFocusTrap(elements, userOptions) {
2272
- // SSR: a live trap shouldn't be created in this type of environment so this
2273
- // should be safe code to execute if the `document` option isn't specified
2274
- var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
2275
-
2276
- var config = _objectSpread2({
2277
- returnFocusOnDeactivate: true,
2278
- escapeDeactivates: true,
2279
- delayInitialFocus: true
2280
- }, userOptions);
2281
-
2282
- var state = {
2283
- // containers given to createFocusTrap()
2284
- // @type {Array<HTMLElement>}
2285
- containers: [],
2286
- // list of objects identifying tabbable nodes in `containers` in the trap
2287
- // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
2288
- // is active, but the trap should never get to a state where there isn't at least one group
2289
- // with at least one tabbable node in it (that would lead to an error condition that would
2290
- // result in an error being thrown)
2291
- // @type {Array<{
2292
- // container: HTMLElement,
2293
- // tabbableNodes: Array<HTMLElement>, // empty if none
2294
- // focusableNodes: Array<HTMLElement>, // empty if none
2295
- // firstTabbableNode: HTMLElement|null,
2296
- // lastTabbableNode: HTMLElement|null,
2297
- // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
2298
- // }>}
2299
- containerGroups: [],
2300
- // same order/length as `containers` list
2301
- // references to objects in `containerGroups`, but only those that actually have
2302
- // tabbable nodes in them
2303
- // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
2304
- // the same length
2305
- tabbableGroups: [],
2306
- nodeFocusedBeforeActivation: null,
2307
- mostRecentlyFocusedNode: null,
2308
- active: false,
2309
- paused: false,
2310
- // timer ID for when delayInitialFocus is true and initial focus in this trap
2311
- // has been delayed during activation
2312
- delayInitialFocusTimer: undefined
2313
- };
2314
- var trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later
2315
-
2316
- /**
2317
- * Gets a configuration option value.
2318
- * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
2319
- * value will be taken from this object. Otherwise, value will be taken from base configuration.
2320
- * @param {string} optionName Name of the option whose value is sought.
2321
- * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
2322
- * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
2323
- */
2324
-
2325
- var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
2326
- return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
2327
- };
2328
- /**
2329
- * Finds the index of the container that contains the element.
2330
- * @param {HTMLElement} element
2331
- * @returns {number} Index of the container in either `state.containers` or
2332
- * `state.containerGroups` (the order/length of these lists are the same); -1
2333
- * if the element isn't found.
2334
- */
2335
-
2336
-
2337
- var findContainerIndex = function findContainerIndex(element) {
2338
- // NOTE: search `containerGroups` because it's possible a group contains no tabbable
2339
- // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
2340
- // and we still need to find the element in there
2341
- return state.containerGroups.findIndex(function (_ref) {
2342
- var container = _ref.container,
2343
- tabbableNodes = _ref.tabbableNodes;
2344
- return container.contains(element) || // fall back to explicit tabbable search which will take into consideration any
2345
- // web components if the `tabbableOptions.getShadowRoot` option was used for
2346
- // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
2347
- // look inside web components even if open)
2348
- tabbableNodes.find(function (node) {
2349
- return node === element;
2350
- });
2351
- });
2352
- };
2353
- /**
2354
- * Gets the node for the given option, which is expected to be an option that
2355
- * can be either a DOM node, a string that is a selector to get a node, `false`
2356
- * (if a node is explicitly NOT given), or a function that returns any of these
2357
- * values.
2358
- * @param {string} optionName
2359
- * @returns {undefined | false | HTMLElement | SVGElement} Returns
2360
- * `undefined` if the option is not specified; `false` if the option
2361
- * resolved to `false` (node explicitly not given); otherwise, the resolved
2362
- * DOM node.
2363
- * @throws {Error} If the option is set, not `false`, and is not, or does not
2364
- * resolve to a node.
2365
- */
2366
-
2367
-
2368
- var getNodeForOption = function getNodeForOption(optionName) {
2369
- var optionValue = config[optionName];
2370
-
2371
- if (typeof optionValue === 'function') {
2372
- for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2373
- params[_key2 - 1] = arguments[_key2];
2374
- }
2375
-
2376
- optionValue = optionValue.apply(void 0, params);
2377
- }
2378
-
2379
- if (!optionValue) {
2380
- if (optionValue === undefined || optionValue === false) {
2381
- return optionValue;
2382
- } // else, empty string (invalid), null (invalid), 0 (invalid)
2383
-
2384
-
2385
- throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
2386
- }
2387
-
2388
- var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
2389
-
2390
- if (typeof optionValue === 'string') {
2391
- node = doc.querySelector(optionValue); // resolve to node, or null if fails
2392
-
2393
- if (!node) {
2394
- throw new Error("`".concat(optionName, "` as selector refers to no known node"));
2395
- }
2396
- }
2397
-
2398
- return node;
2399
- };
2400
-
2401
- var getInitialFocusNode = function getInitialFocusNode() {
2402
- var node = getNodeForOption('initialFocus'); // false explicitly indicates we want no initialFocus at all
2403
-
2404
- if (node === false) {
2405
- return false;
2406
- }
2407
-
2408
- if (node === undefined) {
2409
- // option not specified: use fallback options
2410
- if (findContainerIndex(doc.activeElement) >= 0) {
2411
- node = doc.activeElement;
2412
- } else {
2413
- var firstTabbableGroup = state.tabbableGroups[0];
2414
- var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
2415
-
2416
- node = firstTabbableNode || getNodeForOption('fallbackFocus');
2417
- }
2418
- }
2419
-
2420
- if (!node) {
2421
- throw new Error('Your focus-trap needs to have at least one focusable element');
2422
- }
2423
-
2424
- return node;
2425
- };
2426
-
2427
- var updateTabbableNodes = function updateTabbableNodes() {
2428
- state.containerGroups = state.containers.map(function (container) {
2429
- var _config$tabbableOptio, _config$tabbableOptio2;
2430
-
2431
- var tabbableNodes = tabbable(container, {
2432
- getShadowRoot: (_config$tabbableOptio = config.tabbableOptions) === null || _config$tabbableOptio === void 0 ? void 0 : _config$tabbableOptio.getShadowRoot
2433
- }); // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
2434
- // are a superset of tabbable nodes
2435
-
2436
- var focusableNodes = focusable(container, {
2437
- getShadowRoot: (_config$tabbableOptio2 = config.tabbableOptions) === null || _config$tabbableOptio2 === void 0 ? void 0 : _config$tabbableOptio2.getShadowRoot
2438
- });
2439
- return {
2440
- container: container,
2441
- tabbableNodes: tabbableNodes,
2442
- focusableNodes: focusableNodes,
2443
- firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null,
2444
- lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null,
2445
-
2446
- /**
2447
- * Finds the __tabbable__ node that follows the given node in the specified direction,
2448
- * in this container, if any.
2449
- * @param {HTMLElement} node
2450
- * @param {boolean} [forward] True if going in forward tab order; false if going
2451
- * in reverse.
2452
- * @returns {HTMLElement|undefined} The next tabbable node, if any.
2453
- */
2454
- nextTabbableNode: function nextTabbableNode(node) {
2455
- var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2456
- // NOTE: If tabindex is positive (in order to manipulate the tab order separate
2457
- // from the DOM order), this __will not work__ because the list of focusableNodes,
2458
- // while it contains tabbable nodes, does not sort its nodes in any order other
2459
- // than DOM order, because it can't: Where would you place focusable (but not
2460
- // tabbable) nodes in that order? They have no order, because they aren't tabbale...
2461
- // Support for positive tabindex is already broken and hard to manage (possibly
2462
- // not supportable, TBD), so this isn't going to make things worse than they
2463
- // already are, and at least makes things better for the majority of cases where
2464
- // tabindex is either 0/unset or negative.
2465
- // FYI, positive tabindex issue: https://github.com/focus-trap/focus-trap/issues/375
2466
- var nodeIdx = focusableNodes.findIndex(function (n) {
2467
- return n === node;
2468
- });
2469
-
2470
- if (nodeIdx < 0) {
2471
- return undefined;
2472
- }
2473
-
2474
- if (forward) {
2475
- return focusableNodes.slice(nodeIdx + 1).find(function (n) {
2476
- return isTabbable(n);
2477
- });
2478
- }
2479
-
2480
- return focusableNodes.slice(0, nodeIdx).reverse().find(function (n) {
2481
- return isTabbable(n);
2482
- });
2483
- }
2484
- };
2485
- });
2486
- state.tabbableGroups = state.containerGroups.filter(function (group) {
2487
- return group.tabbableNodes.length > 0;
2488
- }); // throw if no groups have tabbable nodes and we don't have a fallback focus node either
2489
-
2490
- if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
2491
- ) {
2492
- throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
2493
- }
2494
- };
2495
-
2496
- var tryFocus = function tryFocus(node) {
2497
- if (node === false) {
2498
- return;
2499
- }
2500
-
2501
- if (node === doc.activeElement) {
2502
- return;
2503
- }
2504
-
2505
- if (!node || !node.focus) {
2506
- tryFocus(getInitialFocusNode());
2507
- return;
2508
- }
2509
-
2510
- node.focus({
2511
- preventScroll: !!config.preventScroll
2512
- });
2513
- state.mostRecentlyFocusedNode = node;
2514
-
2515
- if (isSelectableInput(node)) {
2516
- node.select();
2517
- }
2518
- };
2519
-
2520
- var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
2521
- var node = getNodeForOption('setReturnFocus', previousActiveElement);
2522
- return node ? node : node === false ? false : previousActiveElement;
2523
- }; // This needs to be done on mousedown and touchstart instead of click
2524
- // so that it precedes the focus event.
2525
-
2526
-
2527
- var checkPointerDown = function checkPointerDown(e) {
2528
- var target = getActualTarget(e);
2529
-
2530
- if (findContainerIndex(target) >= 0) {
2531
- // allow the click since it ocurred inside the trap
2532
- return;
2533
- }
2534
-
2535
- if (valueOrHandler(config.clickOutsideDeactivates, e)) {
2536
- // immediately deactivate the trap
2537
- trap.deactivate({
2538
- // if, on deactivation, we should return focus to the node originally-focused
2539
- // when the trap was activated (or the configured `setReturnFocus` node),
2540
- // then assume it's also OK to return focus to the outside node that was
2541
- // just clicked, causing deactivation, as long as that node is focusable;
2542
- // if it isn't focusable, then return focus to the original node focused
2543
- // on activation (or the configured `setReturnFocus` node)
2544
- // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
2545
- // which will result in the outside click setting focus to the node
2546
- // that was clicked, whether it's focusable or not; by setting
2547
- // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
2548
- // on activation (or the configured `setReturnFocus` node)
2549
- returnFocus: config.returnFocusOnDeactivate && !isFocusable(target)
2550
- });
2551
- return;
2552
- } // This is needed for mobile devices.
2553
- // (If we'll only let `click` events through,
2554
- // then on mobile they will be blocked anyways if `touchstart` is blocked.)
2555
-
2556
-
2557
- if (valueOrHandler(config.allowOutsideClick, e)) {
2558
- // allow the click outside the trap to take place
2559
- return;
2560
- } // otherwise, prevent the click
2561
-
2562
-
2563
- e.preventDefault();
2564
- }; // In case focus escapes the trap for some strange reason, pull it back in.
2565
-
2566
-
2567
- var checkFocusIn = function checkFocusIn(e) {
2568
- var target = getActualTarget(e);
2569
- var targetContained = findContainerIndex(target) >= 0; // In Firefox when you Tab out of an iframe the Document is briefly focused.
2570
-
2571
- if (targetContained || target instanceof Document) {
2572
- if (targetContained) {
2573
- state.mostRecentlyFocusedNode = target;
2574
- }
2575
- } else {
2576
- // escaped! pull it back in to where it just left
2577
- e.stopImmediatePropagation();
2578
- tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
2579
- }
2580
- }; // Hijack Tab events on the first and last focusable nodes of the trap,
2581
- // in order to prevent focus from escaping. If it escapes for even a
2582
- // moment it can end up scrolling the page and causing confusion so we
2583
- // kind of need to capture the action at the keydown phase.
2584
-
2585
-
2586
- var checkTab = function checkTab(e) {
2587
- var target = getActualTarget(e);
2588
- updateTabbableNodes();
2589
- var destinationNode = null;
2590
-
2591
- if (state.tabbableGroups.length > 0) {
2592
- // make sure the target is actually contained in a group
2593
- // NOTE: the target may also be the container itself if it's focusable
2594
- // with tabIndex='-1' and was given initial focus
2595
- var containerIndex = findContainerIndex(target);
2596
- var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
2597
-
2598
- if (containerIndex < 0) {
2599
- // target not found in any group: quite possible focus has escaped the trap,
2600
- // so bring it back in to...
2601
- if (e.shiftKey) {
2602
- // ...the last node in the last group
2603
- destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
2604
- } else {
2605
- // ...the first node in the first group
2606
- destinationNode = state.tabbableGroups[0].firstTabbableNode;
2607
- }
2608
- } else if (e.shiftKey) {
2609
- // REVERSE
2610
- // is the target the first tabbable node in a group?
2611
- var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
2612
- var firstTabbableNode = _ref2.firstTabbableNode;
2613
- return target === firstTabbableNode;
2614
- });
2615
-
2616
- if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target) && !isTabbable(target) && !containerGroup.nextTabbableNode(target, false))) {
2617
- // an exception case where the target is either the container itself, or
2618
- // a non-tabbable node that was given focus (i.e. tabindex is negative
2619
- // and user clicked on it or node was programmatically given focus)
2620
- // and is not followed by any other tabbable node, in which
2621
- // case, we should handle shift+tab as if focus were on the container's
2622
- // first tabbable node, and go to the last tabbable node of the LAST group
2623
- startOfGroupIndex = containerIndex;
2624
- }
2625
-
2626
- if (startOfGroupIndex >= 0) {
2627
- // YES: then shift+tab should go to the last tabbable node in the
2628
- // previous group (and wrap around to the last tabbable node of
2629
- // the LAST group if it's the first tabbable node of the FIRST group)
2630
- var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
2631
- var destinationGroup = state.tabbableGroups[destinationGroupIndex];
2632
- destinationNode = destinationGroup.lastTabbableNode;
2633
- }
2634
- } else {
2635
- // FORWARD
2636
- // is the target the last tabbable node in a group?
2637
- var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
2638
- var lastTabbableNode = _ref3.lastTabbableNode;
2639
- return target === lastTabbableNode;
2640
- });
2641
-
2642
- if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target) && !isTabbable(target) && !containerGroup.nextTabbableNode(target))) {
2643
- // an exception case where the target is the container itself, or
2644
- // a non-tabbable node that was given focus (i.e. tabindex is negative
2645
- // and user clicked on it or node was programmatically given focus)
2646
- // and is not followed by any other tabbable node, in which
2647
- // case, we should handle tab as if focus were on the container's
2648
- // last tabbable node, and go to the first tabbable node of the FIRST group
2649
- lastOfGroupIndex = containerIndex;
2650
- }
2651
-
2652
- if (lastOfGroupIndex >= 0) {
2653
- // YES: then tab should go to the first tabbable node in the next
2654
- // group (and wrap around to the first tabbable node of the FIRST
2655
- // group if it's the last tabbable node of the LAST group)
2656
- var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
2657
-
2658
- var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
2659
- destinationNode = _destinationGroup.firstTabbableNode;
2660
- }
2661
- }
2662
- } else {
2663
- // NOTE: the fallbackFocus option does not support returning false to opt-out
2664
- destinationNode = getNodeForOption('fallbackFocus');
2665
- }
2666
-
2667
- if (destinationNode) {
2668
- e.preventDefault();
2669
- tryFocus(destinationNode);
2670
- } // else, let the browser take care of [shift+]tab and move the focus
2671
-
2672
- };
2673
-
2674
- var checkKey = function checkKey(e) {
2675
- if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) {
2676
- e.preventDefault();
2677
- trap.deactivate();
2678
- return;
2679
- }
2680
-
2681
- if (isTabEvent(e)) {
2682
- checkTab(e);
2683
- return;
2684
- }
2685
- };
2686
-
2687
- var checkClick = function checkClick(e) {
2688
- if (valueOrHandler(config.clickOutsideDeactivates, e)) {
2689
- return;
2690
- }
2691
-
2692
- var target = getActualTarget(e);
2693
-
2694
- if (findContainerIndex(target) >= 0) {
2695
- return;
2696
- }
2697
-
2698
- if (valueOrHandler(config.allowOutsideClick, e)) {
2699
- return;
2700
- }
2701
-
2702
- e.preventDefault();
2703
- e.stopImmediatePropagation();
2704
- }; //
2705
- // EVENT LISTENERS
2706
- //
2707
-
2708
-
2709
- var addListeners = function addListeners() {
2710
- if (!state.active) {
2711
- return;
2712
- } // There can be only one listening focus trap at a time
2713
-
2714
-
2715
- activeFocusTraps.activateTrap(trap); // Delay ensures that the focused element doesn't capture the event
2716
- // that caused the focus trap activation.
2717
-
2718
- state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
2719
- tryFocus(getInitialFocusNode());
2720
- }) : tryFocus(getInitialFocusNode());
2721
- doc.addEventListener('focusin', checkFocusIn, true);
2722
- doc.addEventListener('mousedown', checkPointerDown, {
2723
- capture: true,
2724
- passive: false
2725
- });
2726
- doc.addEventListener('touchstart', checkPointerDown, {
2727
- capture: true,
2728
- passive: false
2729
- });
2730
- doc.addEventListener('click', checkClick, {
2731
- capture: true,
2732
- passive: false
2733
- });
2734
- doc.addEventListener('keydown', checkKey, {
2735
- capture: true,
2736
- passive: false
2737
- });
2738
- return trap;
2739
- };
2740
-
2741
- var removeListeners = function removeListeners() {
2742
- if (!state.active) {
2743
- return;
2744
- }
2745
-
2746
- doc.removeEventListener('focusin', checkFocusIn, true);
2747
- doc.removeEventListener('mousedown', checkPointerDown, true);
2748
- doc.removeEventListener('touchstart', checkPointerDown, true);
2749
- doc.removeEventListener('click', checkClick, true);
2750
- doc.removeEventListener('keydown', checkKey, true);
2751
- return trap;
2752
- }; //
2753
- // TRAP DEFINITION
2754
- //
2755
-
2756
-
2757
- trap = {
2758
- activate: function activate(activateOptions) {
2759
- if (state.active) {
2760
- return this;
2761
- }
2762
-
2763
- var onActivate = getOption(activateOptions, 'onActivate');
2764
- var onPostActivate = getOption(activateOptions, 'onPostActivate');
2765
- var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
2766
-
2767
- if (!checkCanFocusTrap) {
2768
- updateTabbableNodes();
2769
- }
2770
-
2771
- state.active = true;
2772
- state.paused = false;
2773
- state.nodeFocusedBeforeActivation = doc.activeElement;
2774
-
2775
- if (onActivate) {
2776
- onActivate();
2777
- }
2778
-
2779
- var finishActivation = function finishActivation() {
2780
- if (checkCanFocusTrap) {
2781
- updateTabbableNodes();
2782
- }
2783
-
2784
- addListeners();
2785
-
2786
- if (onPostActivate) {
2787
- onPostActivate();
2788
- }
2789
- };
2790
-
2791
- if (checkCanFocusTrap) {
2792
- checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
2793
- return this;
2794
- }
2795
-
2796
- finishActivation();
2797
- return this;
2798
- },
2799
- deactivate: function deactivate(deactivateOptions) {
2800
- if (!state.active) {
2801
- return this;
2802
- }
2803
-
2804
- clearTimeout(state.delayInitialFocusTimer); // noop if undefined
2805
-
2806
- state.delayInitialFocusTimer = undefined;
2807
- removeListeners();
2808
- state.active = false;
2809
- state.paused = false;
2810
- activeFocusTraps.deactivateTrap(trap);
2811
- var onDeactivate = getOption(deactivateOptions, 'onDeactivate');
2812
- var onPostDeactivate = getOption(deactivateOptions, 'onPostDeactivate');
2813
- var checkCanReturnFocus = getOption(deactivateOptions, 'checkCanReturnFocus');
2814
-
2815
- if (onDeactivate) {
2816
- onDeactivate();
2817
- }
2818
-
2819
- var returnFocus = getOption(deactivateOptions, 'returnFocus', 'returnFocusOnDeactivate');
2820
-
2821
- var finishDeactivation = function finishDeactivation() {
2822
- delay(function () {
2823
- if (returnFocus) {
2824
- tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
2825
- }
2826
-
2827
- if (onPostDeactivate) {
2828
- onPostDeactivate();
2829
- }
2830
- });
2831
- };
2832
-
2833
- if (returnFocus && checkCanReturnFocus) {
2834
- checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
2835
- return this;
2836
- }
2837
-
2838
- finishDeactivation();
2839
- return this;
2840
- },
2841
- pause: function pause() {
2842
- if (state.paused || !state.active) {
2843
- return this;
2844
- }
2845
-
2846
- state.paused = true;
2847
- removeListeners();
2848
- return this;
2849
- },
2850
- unpause: function unpause() {
2851
- if (!state.paused || !state.active) {
2852
- return this;
2853
- }
2854
-
2855
- state.paused = false;
2856
- updateTabbableNodes();
2857
- addListeners();
2858
- return this;
2859
- },
2860
- updateContainerElements: function updateContainerElements(containerElements) {
2861
- var elementsAsArray = [].concat(containerElements).filter(Boolean);
2862
- state.containers = elementsAsArray.map(function (element) {
2863
- return typeof element === 'string' ? doc.querySelector(element) : element;
2864
- });
2865
-
2866
- if (state.active) {
2867
- updateTabbableNodes();
2868
- }
2869
-
2870
- return this;
2871
- }
2872
- }; // initialize container elements
2873
-
2874
- trap.updateContainerElements(elements);
2875
- return trap;
2876
- };
2877
-
2878
- const catMenuCss = ":host{display:inline-block}:host([hidden]){display:none}.content{padding-top:0.5rem;padding-bottom:0.5rem;position:absolute;background:white;display:none;overflow:auto;-webkit-overflow-scrolling:touch;min-width:8rem;max-width:16rem;min-height:2rem;max-height:calc(100vh - 48px);box-shadow:0 1px 4px 0 rgba(16, 29, 48, 0.2);border-radius:0.25rem}";
2879
-
2880
- let nextUniqueId = 0;
2881
- const CatMenu = class {
2882
- constructor(hostRef) {
2883
- registerInstance(this, hostRef);
2884
- this.catOpen = createEvent(this, "catOpen", 7);
2885
- this.catClose = createEvent(this, "catClose", 7);
2886
- this.id = nextUniqueId++;
2887
- /**
2888
- * The placement of the menu.
2889
- */
2890
- this.placement = 'bottom-start';
2891
- }
2892
- clickHandler(event) {
2893
- var _a;
2894
- // hide menu on button click
2895
- if (this.content && event.composedPath().includes(this.content)) {
2896
- (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
2897
- this.hide();
2898
- }
2899
- }
2900
- componentDidLoad() {
2901
- var _a, _b, _c, _d, _e;
2902
- this.trigger = this.firstTabbable(this.triggerSlot);
2903
- (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-haspopup', 'true');
2904
- (_b = this.trigger) === null || _b === void 0 ? void 0 : _b.setAttribute('aria-expanded', 'false');
2905
- (_c = this.trigger) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-controls', this.contentId);
2906
- (_d = this.content) === null || _d === void 0 ? void 0 : _d.setAttribute('id', this.contentId);
2907
- if (this.trigger && this.content) {
2908
- (_e = this.trigger) === null || _e === void 0 ? void 0 : _e.addEventListener('click', () => this.show());
2909
- autoUpdate(this.trigger, this.content, () => this.update());
2910
- }
2911
- this.keyListener = event => {
2912
- if (this.content && ['ArrowDown', 'ArrowUp'].includes(event.key)) {
2913
- const targetElements = tabbable(this.content, { includeContainer: false, getShadowRoot: true });
2914
- const activeElement = this.firstTabbable(document.activeElement);
2915
- const activeIdx = activeElement ? targetElements.indexOf(activeElement) : -1;
2916
- const activeOff = event.key === 'ArrowDown' ? 1 : -1;
2917
- const targetIdx = activeIdx < 0 ? 0 : (activeIdx + activeOff + targetElements.length) % targetElements.length;
2918
- targetElements[targetIdx].focus();
2919
- event.preventDefault();
2920
- }
2921
- };
2922
- document.addEventListener('keydown', this.keyListener);
2923
- }
2924
- disconnectedCallback() {
2925
- if (this.keyListener) {
2926
- document.removeEventListener('keydown', this.keyListener);
2927
- }
2928
- }
2929
- render() {
2930
- return (h(Host, null, h("slot", { name: "trigger", ref: el => (this.triggerSlot = el) }), h("div", { class: "content", ref: el => (this.content = el) }, h("slot", { name: "content" }))));
2931
- }
2932
- get contentId() {
2933
- return `cat-menu-${this.id}`;
2934
- }
2935
- show() {
2936
- var _a;
2937
- if (this.content) {
2938
- this.content.style.display = 'block';
2939
- (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-expanded', 'true');
2940
- this.catOpen.emit();
2941
- this.trap = this.trap
2942
- ? this.trap.updateContainerElements(this.content)
2943
- : createFocusTrap(this.content, {
2944
- tabbableOptions: {
2945
- getShadowRoot: true
2946
- },
2947
- allowOutsideClick: true,
2948
- clickOutsideDeactivates: event => !this.content || !event.composedPath().includes(this.content),
2949
- onPostDeactivate: () => this.hide()
2950
- });
2951
- this.trap.activate();
2952
- }
2953
- }
2954
- hide() {
2955
- var _a;
2956
- if (this.content) {
2957
- this.content.style.display = '';
2958
- (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-expanded', 'false');
2959
- this.catClose.emit();
2960
- }
2961
- }
2962
- update() {
2963
- if (this.trigger && this.content) {
2964
- computePosition(this.trigger, this.content, {
2965
- placement: this.placement,
2966
- middleware: [offset(CatMenu.OFFSET), flip()]
2967
- }).then(({ x, y }) => {
2968
- if (this.content) {
2969
- Object.assign(this.content.style, {
2970
- left: `${x}px`,
2971
- top: `${y}px`
2972
- });
2973
- }
2974
- });
2975
- }
2976
- }
2977
- firstTabbable(container) {
2978
- return (container ? tabbable(container, { includeContainer: true, getShadowRoot: true }) : []).shift();
2979
- }
2980
- };
2981
- CatMenu.OFFSET = 4;
2982
- CatMenu.style = catMenuCss;
2983
-
2984
- export { CatMenu as cat_menu };
2985
-
2986
- //# sourceMappingURL=cat-menu.entry.js.map