@vonage/vivid 3.0.0-next.120 → 3.0.0-next.122
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.
- package/custom-elements.json +119 -438
- package/header/index.js +4 -56
- package/index.js +40 -39
- package/layout/index.js +1 -1
- package/lib/accordion/definition.d.ts +0 -2
- package/lib/accordion-item/definition.d.ts +0 -2
- package/lib/action-group/definition.d.ts +0 -2
- package/lib/avatar/definition.d.ts +0 -2
- package/lib/badge/definition.d.ts +1 -1
- package/lib/banner/definition.d.ts +0 -2
- package/lib/breadcrumb/definition.d.ts +0 -2
- package/lib/breadcrumb-item/definition.d.ts +0 -2
- package/lib/button/definition.d.ts +0 -2
- package/lib/calendar/definition.d.ts +0 -2
- package/lib/calendar-event/definition.d.ts +0 -2
- package/lib/card/definition.d.ts +0 -2
- package/lib/checkbox/definition.d.ts +0 -2
- package/lib/components.d.ts +1 -0
- package/lib/dialog/definition.d.ts +0 -2
- package/lib/divider/definition.d.ts +0 -2
- package/lib/elevation/definition.d.ts +0 -2
- package/lib/fab/definition.d.ts +1 -1
- package/lib/focus/definition.d.ts +1 -1
- package/lib/header/definition.d.ts +1 -1
- package/lib/icon/definition.d.ts +1 -1
- package/lib/layout/definition.d.ts +1 -1
- package/lib/listbox/definition.d.ts +1 -1
- package/lib/menu/definition.d.ts +6 -2
- package/lib/menu-item/definition.d.ts +1 -1
- package/lib/nav/definition.d.ts +1 -1
- package/lib/nav-disclosure/definition.d.ts +1 -1
- package/lib/nav-item/definition.d.ts +1 -1
- package/lib/note/definition.d.ts +1 -1
- package/lib/number-field/definition.d.ts +2 -1
- package/lib/option/definition.d.ts +1 -1
- package/lib/popup/definition.d.ts +1 -2
- package/lib/progress/definition.d.ts +1 -1
- package/lib/progress-ring/definition.d.ts +1 -1
- package/lib/radio/definition.d.ts +1 -1
- package/lib/radio-group/definition.d.ts +6 -2
- package/lib/side-drawer/definition.d.ts +1 -1
- package/lib/slider/definition.d.ts +1 -1
- package/lib/switch/definition.d.ts +1 -1
- package/lib/text-anchor/definition.d.ts +1 -1
- package/lib/text-area/definition.d.ts +1 -1
- package/lib/text-field/definition.d.ts +1 -1
- package/lib/tooltip/definition.d.ts +1 -1
- package/listbox/index.js +2 -2
- package/menu/index.js +3 -3
- package/menu-item/index.js +1 -1
- package/nav/index.js +1 -1
- package/nav-disclosure/index.js +1 -1
- package/nav-item/index.js +1 -1
- package/note/index.js +1 -1
- package/number-field/index.js +8 -8
- package/option/index.js +1 -1
- package/package.json +3 -2
- package/popup/index.js +1 -1
- package/progress/index.js +1 -1
- package/progress-ring/index.js +1 -1
- package/radio/index.js +1 -1
- package/radio-group/index.js +1 -1
- package/shared/definition.js +7 -7
- package/shared/definition10.js +6 -6
- package/shared/definition11.js +9 -9
- package/shared/definition12.js +7 -7
- package/shared/definition13.js +7 -7
- package/shared/definition14.js +9 -9
- package/shared/definition15.js +6 -6
- package/shared/definition16.js +9 -9
- package/shared/definition17.js +10 -10
- package/shared/definition18.js +7 -7
- package/shared/definition19.js +9 -9
- package/shared/definition2.js +9 -9
- package/shared/definition20.js +48 -34
- package/shared/definition21.js +36 -1070
- package/shared/definition22.js +980 -163
- package/shared/definition23.js +212 -299
- package/shared/definition24.js +311 -1492
- package/shared/definition25.js +1493 -315
- package/shared/definition26.js +348 -15
- package/shared/definition27.js +13 -70
- package/shared/definition28.js +68 -24
- package/shared/definition29.js +22 -47
- package/shared/definition3.js +6 -6
- package/shared/definition30.js +41 -79
- package/shared/definition31.js +77 -60
- package/shared/definition32.js +68 -36
- package/shared/definition33.js +32 -422
- package/shared/definition34.js +419 -70
- package/shared/definition35.js +67 -573
- package/shared/definition36.js +528 -83
- package/shared/definition37.js +88 -220
- package/shared/definition38.js +247 -87
- package/shared/definition39.js +110 -68
- package/shared/definition4.js +7 -7
- package/shared/definition40.js +77 -0
- package/shared/definition5.js +7 -7
- package/shared/definition6.js +8 -8
- package/shared/definition7.js +8 -8
- package/shared/definition8.js +9 -9
- package/shared/definition9.js +9 -9
- package/shared/design-system/index.d.ts +2 -1
- package/shared/form-elements.js +1 -1
- package/shared/index.js +2 -2
- package/side-drawer/index.js +1 -1
- package/slider/index.js +1 -1
- package/styles/core/all.css +1 -1
- package/styles/core/theme.css +1 -1
- package/styles/core/typography.css +1 -1
- package/styles/tokens/theme-dark.css +4 -4
- package/styles/tokens/theme-light.css +4 -4
- package/switch/index.js +1 -1
- package/text-anchor/index.js +5 -5
- package/text-area/index.js +1 -1
- package/text-field/index.js +1 -1
- package/tooltip/index.js +2 -2
- package/vivid.api.json +545 -1162
package/shared/definition24.js
CHANGED
|
@@ -1,1529 +1,348 @@
|
|
|
1
|
-
import { F as FoundationElement,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import './
|
|
5
|
-
import './
|
|
6
|
-
import {
|
|
7
|
-
import { w as when } from './when.js';
|
|
1
|
+
import { F as FoundationElement, U as DOM, _ as __decorate, N as observable, a as attr, b as __metadata, h as html, r as registerFactory } from './index.js';
|
|
2
|
+
import { P as Popup, p as popupRegistries } from './definition25.js';
|
|
3
|
+
import { M as MenuItem, a as MenuItemRole, r as roleForMenuItem, m as menuItemRegistries } from './definition26.js';
|
|
4
|
+
import { i as isHTMLElement } from './dom.js';
|
|
5
|
+
import { g as keyHome, d as keyEnd, e as keyArrowUp, f as keyArrowDown } from './key-codes.js';
|
|
6
|
+
import { s as slotted } from './slotted.js';
|
|
8
7
|
import { r as ref } from './ref.js';
|
|
9
|
-
import { c as classNames } from './class-names.js';
|
|
10
|
-
|
|
11
|
-
function getSide(placement) {
|
|
12
|
-
return placement.split('-')[0];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getAlignment(placement) {
|
|
16
|
-
return placement.split('-')[1];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getMainAxisFromPlacement(placement) {
|
|
20
|
-
return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getLengthFromAxis(axis) {
|
|
24
|
-
return axis === 'y' ? 'height' : 'width';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
28
|
-
let {
|
|
29
|
-
reference,
|
|
30
|
-
floating
|
|
31
|
-
} = _ref;
|
|
32
|
-
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
33
|
-
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
34
|
-
const mainAxis = getMainAxisFromPlacement(placement);
|
|
35
|
-
const length = getLengthFromAxis(mainAxis);
|
|
36
|
-
const commonAlign = reference[length] / 2 - floating[length] / 2;
|
|
37
|
-
const side = getSide(placement);
|
|
38
|
-
const isVertical = mainAxis === 'x';
|
|
39
|
-
let coords;
|
|
40
|
-
|
|
41
|
-
switch (side) {
|
|
42
|
-
case 'top':
|
|
43
|
-
coords = {
|
|
44
|
-
x: commonX,
|
|
45
|
-
y: reference.y - floating.height
|
|
46
|
-
};
|
|
47
|
-
break;
|
|
48
|
-
|
|
49
|
-
case 'bottom':
|
|
50
|
-
coords = {
|
|
51
|
-
x: commonX,
|
|
52
|
-
y: reference.y + reference.height
|
|
53
|
-
};
|
|
54
|
-
break;
|
|
55
|
-
|
|
56
|
-
case 'right':
|
|
57
|
-
coords = {
|
|
58
|
-
x: reference.x + reference.width,
|
|
59
|
-
y: commonY
|
|
60
|
-
};
|
|
61
|
-
break;
|
|
62
|
-
|
|
63
|
-
case 'left':
|
|
64
|
-
coords = {
|
|
65
|
-
x: reference.x - floating.width,
|
|
66
|
-
y: commonY
|
|
67
|
-
};
|
|
68
|
-
break;
|
|
69
|
-
|
|
70
|
-
default:
|
|
71
|
-
coords = {
|
|
72
|
-
x: reference.x,
|
|
73
|
-
y: reference.y
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
switch (getAlignment(placement)) {
|
|
78
|
-
case 'start':
|
|
79
|
-
coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
80
|
-
break;
|
|
81
|
-
|
|
82
|
-
case 'end':
|
|
83
|
-
coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return coords;
|
|
88
|
-
}
|
|
89
8
|
|
|
90
9
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
10
|
+
* A Menu Custom HTML Element.
|
|
11
|
+
* Implements the {@link https://www.w3.org/TR/wai-aria-1.1/#menu | ARIA menu }.
|
|
93
12
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const computePosition$1 = async (reference, floating, config) => {
|
|
99
|
-
const {
|
|
100
|
-
placement = 'bottom',
|
|
101
|
-
strategy = 'absolute',
|
|
102
|
-
middleware = [],
|
|
103
|
-
platform
|
|
104
|
-
} = config;
|
|
105
|
-
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
|
|
106
|
-
|
|
107
|
-
let rects = await platform.getElementRects({
|
|
108
|
-
reference,
|
|
109
|
-
floating,
|
|
110
|
-
strategy
|
|
111
|
-
});
|
|
112
|
-
let {
|
|
113
|
-
x,
|
|
114
|
-
y
|
|
115
|
-
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
116
|
-
let statefulPlacement = placement;
|
|
117
|
-
let middlewareData = {};
|
|
118
|
-
let resetCount = 0;
|
|
119
|
-
|
|
120
|
-
for (let i = 0; i < middleware.length; i++) {
|
|
121
|
-
const {
|
|
122
|
-
name,
|
|
123
|
-
fn
|
|
124
|
-
} = middleware[i];
|
|
125
|
-
const {
|
|
126
|
-
x: nextX,
|
|
127
|
-
y: nextY,
|
|
128
|
-
data,
|
|
129
|
-
reset
|
|
130
|
-
} = await fn({
|
|
131
|
-
x,
|
|
132
|
-
y,
|
|
133
|
-
initialPlacement: placement,
|
|
134
|
-
placement: statefulPlacement,
|
|
135
|
-
strategy,
|
|
136
|
-
middlewareData,
|
|
137
|
-
rects,
|
|
138
|
-
platform,
|
|
139
|
-
elements: {
|
|
140
|
-
reference,
|
|
141
|
-
floating
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
x = nextX != null ? nextX : x;
|
|
145
|
-
y = nextY != null ? nextY : y;
|
|
146
|
-
middlewareData = { ...middlewareData,
|
|
147
|
-
[name]: { ...middlewareData[name],
|
|
148
|
-
...data
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
if (reset && resetCount <= 50) {
|
|
153
|
-
resetCount++;
|
|
154
|
-
|
|
155
|
-
if (typeof reset === 'object') {
|
|
156
|
-
if (reset.placement) {
|
|
157
|
-
statefulPlacement = reset.placement;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (reset.rects) {
|
|
161
|
-
rects = reset.rects === true ? await platform.getElementRects({
|
|
162
|
-
reference,
|
|
163
|
-
floating,
|
|
164
|
-
strategy
|
|
165
|
-
}) : reset.rects;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
({
|
|
169
|
-
x,
|
|
170
|
-
y
|
|
171
|
-
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
i = -1;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
x,
|
|
181
|
-
y,
|
|
182
|
-
placement: statefulPlacement,
|
|
183
|
-
strategy,
|
|
184
|
-
middlewareData
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function expandPaddingObject(padding) {
|
|
189
|
-
return {
|
|
190
|
-
top: 0,
|
|
191
|
-
right: 0,
|
|
192
|
-
bottom: 0,
|
|
193
|
-
left: 0,
|
|
194
|
-
...padding
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function getSideObjectFromPadding(padding) {
|
|
199
|
-
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
|
|
200
|
-
top: padding,
|
|
201
|
-
right: padding,
|
|
202
|
-
bottom: padding,
|
|
203
|
-
left: padding
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function rectToClientRect(rect) {
|
|
208
|
-
return { ...rect,
|
|
209
|
-
top: rect.y,
|
|
210
|
-
left: rect.x,
|
|
211
|
-
right: rect.x + rect.width,
|
|
212
|
-
bottom: rect.y + rect.height
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Resolves with an object of overflow side offsets that determine how much the
|
|
218
|
-
* element is overflowing a given clipping boundary.
|
|
219
|
-
* - positive = overflowing the boundary by that number of pixels
|
|
220
|
-
* - negative = how many pixels left before it will overflow
|
|
221
|
-
* - 0 = lies flush with the boundary
|
|
222
|
-
* @see https://floating-ui.com/docs/detectOverflow
|
|
223
|
-
*/
|
|
224
|
-
async function detectOverflow(middlewareArguments, options) {
|
|
225
|
-
var _await$platform$isEle;
|
|
226
|
-
|
|
227
|
-
if (options === void 0) {
|
|
228
|
-
options = {};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const {
|
|
232
|
-
x,
|
|
233
|
-
y,
|
|
234
|
-
platform,
|
|
235
|
-
rects,
|
|
236
|
-
elements,
|
|
237
|
-
strategy
|
|
238
|
-
} = middlewareArguments;
|
|
239
|
-
const {
|
|
240
|
-
boundary = 'clippingAncestors',
|
|
241
|
-
rootBoundary = 'viewport',
|
|
242
|
-
elementContext = 'floating',
|
|
243
|
-
altBoundary = false,
|
|
244
|
-
padding = 0
|
|
245
|
-
} = options;
|
|
246
|
-
const paddingObject = getSideObjectFromPadding(padding);
|
|
247
|
-
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
248
|
-
const element = elements[altBoundary ? altContext : elementContext];
|
|
249
|
-
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
250
|
-
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))),
|
|
251
|
-
boundary,
|
|
252
|
-
rootBoundary,
|
|
253
|
-
strategy
|
|
254
|
-
}));
|
|
255
|
-
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
256
|
-
rect: elementContext === 'floating' ? { ...rects.floating,
|
|
257
|
-
x,
|
|
258
|
-
y
|
|
259
|
-
} : rects.reference,
|
|
260
|
-
offsetParent: await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating)),
|
|
261
|
-
strategy
|
|
262
|
-
}) : rects[elementContext]);
|
|
263
|
-
return {
|
|
264
|
-
top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
|
|
265
|
-
bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
|
|
266
|
-
left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
|
|
267
|
-
right: elementClientRect.right - clippingClientRect.right + paddingObject.right
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const min$1 = Math.min;
|
|
272
|
-
const max$1 = Math.max;
|
|
273
|
-
|
|
274
|
-
function within(min$1$1, value, max$1$1) {
|
|
275
|
-
return max$1(min$1$1, min$1(value, max$1$1));
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Positions an inner element of the floating element such that it is centered
|
|
280
|
-
* to the reference element.
|
|
281
|
-
* @see https://floating-ui.com/docs/arrow
|
|
282
|
-
*/
|
|
283
|
-
const arrow = options => ({
|
|
284
|
-
name: 'arrow',
|
|
285
|
-
options,
|
|
286
|
-
|
|
287
|
-
async fn(middlewareArguments) {
|
|
288
|
-
// Since `element` is required, we don't Partial<> the type
|
|
289
|
-
const {
|
|
290
|
-
element,
|
|
291
|
-
padding = 0
|
|
292
|
-
} = options != null ? options : {};
|
|
293
|
-
const {
|
|
294
|
-
x,
|
|
295
|
-
y,
|
|
296
|
-
placement,
|
|
297
|
-
rects,
|
|
298
|
-
platform
|
|
299
|
-
} = middlewareArguments;
|
|
300
|
-
|
|
301
|
-
if (element == null) {
|
|
302
|
-
|
|
303
|
-
return {};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const paddingObject = getSideObjectFromPadding(padding);
|
|
307
|
-
const coords = {
|
|
308
|
-
x,
|
|
309
|
-
y
|
|
310
|
-
};
|
|
311
|
-
const axis = getMainAxisFromPlacement(placement);
|
|
312
|
-
const alignment = getAlignment(placement);
|
|
313
|
-
const length = getLengthFromAxis(axis);
|
|
314
|
-
const arrowDimensions = await platform.getDimensions(element);
|
|
315
|
-
const minProp = axis === 'y' ? 'top' : 'left';
|
|
316
|
-
const maxProp = axis === 'y' ? 'bottom' : 'right';
|
|
317
|
-
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
318
|
-
const startDiff = coords[axis] - rects.reference[axis];
|
|
319
|
-
const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
|
|
320
|
-
let clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
|
|
321
|
-
|
|
322
|
-
if (clientSize === 0) {
|
|
323
|
-
clientSize = rects.floating[length];
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the floating element if the center
|
|
327
|
-
// point is outside the floating element's bounds
|
|
328
|
-
|
|
329
|
-
const min = paddingObject[minProp];
|
|
330
|
-
const max = clientSize - arrowDimensions[length] - paddingObject[maxProp];
|
|
331
|
-
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
332
|
-
const offset = within(min, center, max); // Make sure that arrow points at the reference
|
|
333
|
-
|
|
334
|
-
const alignmentPadding = alignment === 'start' ? paddingObject[minProp] : paddingObject[maxProp];
|
|
335
|
-
const shouldAddOffset = alignmentPadding > 0 && center !== offset && rects.reference[length] <= rects.floating[length];
|
|
336
|
-
const alignmentOffset = shouldAddOffset ? center < min ? min - center : max - center : 0;
|
|
337
|
-
return {
|
|
338
|
-
[axis]: coords[axis] - alignmentOffset,
|
|
339
|
-
data: {
|
|
340
|
-
[axis]: offset,
|
|
341
|
-
centerOffset: center - offset
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
const hash$1 = {
|
|
349
|
-
left: 'right',
|
|
350
|
-
right: 'left',
|
|
351
|
-
bottom: 'top',
|
|
352
|
-
top: 'bottom'
|
|
353
|
-
};
|
|
354
|
-
function getOppositePlacement(placement) {
|
|
355
|
-
return placement.replace(/left|right|bottom|top/g, matched => hash$1[matched]);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function getAlignmentSides(placement, rects, rtl) {
|
|
359
|
-
if (rtl === void 0) {
|
|
360
|
-
rtl = false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const alignment = getAlignment(placement);
|
|
364
|
-
const mainAxis = getMainAxisFromPlacement(placement);
|
|
365
|
-
const length = getLengthFromAxis(mainAxis);
|
|
366
|
-
let mainAlignmentSide = mainAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
|
|
367
|
-
|
|
368
|
-
if (rects.reference[length] > rects.floating[length]) {
|
|
369
|
-
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
main: mainAlignmentSide,
|
|
374
|
-
cross: getOppositePlacement(mainAlignmentSide)
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const hash = {
|
|
379
|
-
start: 'end',
|
|
380
|
-
end: 'start'
|
|
381
|
-
};
|
|
382
|
-
function getOppositeAlignmentPlacement(placement) {
|
|
383
|
-
return placement.replace(/start|end/g, matched => hash[matched]);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const sides = ['top', 'right', 'bottom', 'left'];
|
|
387
|
-
|
|
388
|
-
function getExpandedPlacements(placement) {
|
|
389
|
-
const oppositePlacement = getOppositePlacement(placement);
|
|
390
|
-
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Changes the placement of the floating element to one that will fit if the
|
|
395
|
-
* initially specified `placement` does not.
|
|
396
|
-
* @see https://floating-ui.com/docs/flip
|
|
13
|
+
* @slot - The default slot for the menu items
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
397
16
|
*/
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
|
|
431
|
-
const overflows = [];
|
|
432
|
-
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
433
|
-
|
|
434
|
-
if (checkMainAxis) {
|
|
435
|
-
overflows.push(overflow[side]);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (checkCrossAxis) {
|
|
439
|
-
const {
|
|
440
|
-
main,
|
|
441
|
-
cross
|
|
442
|
-
} = getAlignmentSides(placement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
|
|
443
|
-
overflows.push(overflow[main], overflow[cross]);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
overflowsData = [...overflowsData, {
|
|
447
|
-
placement,
|
|
448
|
-
overflows
|
|
449
|
-
}]; // One or more sides is overflowing
|
|
450
|
-
|
|
451
|
-
if (!overflows.every(side => side <= 0)) {
|
|
452
|
-
var _middlewareData$flip$, _middlewareData$flip2;
|
|
453
|
-
|
|
454
|
-
const nextIndex = ((_middlewareData$flip$ = (_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) != null ? _middlewareData$flip$ : 0) + 1;
|
|
455
|
-
const nextPlacement = placements[nextIndex];
|
|
456
|
-
|
|
457
|
-
if (nextPlacement) {
|
|
458
|
-
// Try next placement and re-run the lifecycle
|
|
459
|
-
return {
|
|
460
|
-
data: {
|
|
461
|
-
index: nextIndex,
|
|
462
|
-
overflows: overflowsData
|
|
463
|
-
},
|
|
464
|
-
reset: {
|
|
465
|
-
placement: nextPlacement
|
|
17
|
+
class Menu$1 extends FoundationElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.expandedItem = null;
|
|
21
|
+
/**
|
|
22
|
+
* The index of the focusable element in the items array
|
|
23
|
+
* defaults to -1
|
|
24
|
+
*/
|
|
25
|
+
this.focusIndex = -1;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
this.isNestedMenu = () => {
|
|
30
|
+
return (this.parentElement !== null &&
|
|
31
|
+
isHTMLElement(this.parentElement) &&
|
|
32
|
+
this.parentElement.getAttribute("role") === "menuitem");
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* if focus is moving out of the menu, reset to a stable initial state
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
this.handleFocusOut = (e) => {
|
|
39
|
+
if (!this.contains(e.relatedTarget) && this.menuItems !== undefined) {
|
|
40
|
+
this.collapseExpandedItem();
|
|
41
|
+
// find our first focusable element
|
|
42
|
+
const focusIndex = this.menuItems.findIndex(this.isFocusableElement);
|
|
43
|
+
// set the current focus index's tabindex to -1
|
|
44
|
+
this.menuItems[this.focusIndex].setAttribute("tabindex", "-1");
|
|
45
|
+
// set the first focusable element tabindex to 0
|
|
46
|
+
this.menuItems[focusIndex].setAttribute("tabindex", "0");
|
|
47
|
+
// set the focus index
|
|
48
|
+
this.focusIndex = focusIndex;
|
|
466
49
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
var _overflowsData$map$so;
|
|
476
|
-
|
|
477
|
-
const placement = (_overflowsData$map$so = overflowsData.map(d => [d, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0].placement;
|
|
478
|
-
|
|
479
|
-
if (placement) {
|
|
480
|
-
resetPlacement = placement;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
break;
|
|
50
|
+
};
|
|
51
|
+
this.handleItemFocus = (e) => {
|
|
52
|
+
const targetItem = e.target;
|
|
53
|
+
if (this.menuItems !== undefined &&
|
|
54
|
+
targetItem !== this.menuItems[this.focusIndex]) {
|
|
55
|
+
this.menuItems[this.focusIndex].setAttribute("tabindex", "-1");
|
|
56
|
+
this.focusIndex = this.menuItems.indexOf(targetItem);
|
|
57
|
+
targetItem.setAttribute("tabindex", "0");
|
|
484
58
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return {
|
|
493
|
-
reset: {
|
|
494
|
-
placement: resetPlacement
|
|
59
|
+
};
|
|
60
|
+
this.handleExpandedChanged = (e) => {
|
|
61
|
+
if (e.defaultPrevented ||
|
|
62
|
+
e.target === null ||
|
|
63
|
+
this.menuItems === undefined ||
|
|
64
|
+
this.menuItems.indexOf(e.target) < 0) {
|
|
65
|
+
return;
|
|
495
66
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
const changedItem = e.target;
|
|
69
|
+
// closing an expanded item without opening another
|
|
70
|
+
if (this.expandedItem !== null &&
|
|
71
|
+
changedItem === this.expandedItem &&
|
|
72
|
+
changedItem.expanded === false) {
|
|
73
|
+
this.expandedItem = null;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (changedItem.expanded) {
|
|
77
|
+
if (this.expandedItem !== null && this.expandedItem !== changedItem) {
|
|
78
|
+
this.expandedItem.expanded = false;
|
|
79
|
+
}
|
|
80
|
+
this.menuItems[this.focusIndex].setAttribute("tabindex", "-1");
|
|
81
|
+
this.expandedItem = changedItem;
|
|
82
|
+
this.focusIndex = this.menuItems.indexOf(changedItem);
|
|
83
|
+
changedItem.setAttribute("tabindex", "0");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.removeItemListeners = () => {
|
|
87
|
+
if (this.menuItems !== undefined) {
|
|
88
|
+
this.menuItems.forEach((item) => {
|
|
89
|
+
item.removeEventListener("expanded-change", this.handleExpandedChanged);
|
|
90
|
+
item.removeEventListener("focus", this.handleItemFocus);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
this.setItems = () => {
|
|
95
|
+
const newItems = this.domChildren();
|
|
96
|
+
this.removeItemListeners();
|
|
97
|
+
this.menuItems = newItems;
|
|
98
|
+
const menuItems = this.menuItems.filter(this.isMenuItemElement);
|
|
99
|
+
// if our focus index is not -1 we have items
|
|
100
|
+
if (menuItems.length) {
|
|
101
|
+
this.focusIndex = 0;
|
|
102
|
+
}
|
|
103
|
+
function elementIndent(el) {
|
|
104
|
+
const role = el.getAttribute("role");
|
|
105
|
+
const startSlot = el.querySelector("[slot=start]");
|
|
106
|
+
if (role !== MenuItemRole.menuitem && startSlot === null) {
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
else if (role === MenuItemRole.menuitem && startSlot !== null) {
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
else if (role !== MenuItemRole.menuitem && startSlot !== null) {
|
|
113
|
+
return 2;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const indent = menuItems.reduce((accum, current) => {
|
|
120
|
+
const elementValue = elementIndent(current);
|
|
121
|
+
return accum > elementValue ? accum : elementValue;
|
|
122
|
+
}, 0);
|
|
123
|
+
menuItems.forEach((item, index) => {
|
|
124
|
+
item.setAttribute("tabindex", index === 0 ? "0" : "-1");
|
|
125
|
+
item.addEventListener("expanded-change", this.handleExpandedChanged);
|
|
126
|
+
item.addEventListener("focus", this.handleItemFocus);
|
|
127
|
+
if (item instanceof MenuItem) {
|
|
128
|
+
item.startColumnCount = indent;
|
|
129
|
+
}
|
|
556
130
|
});
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return isVertical ? {
|
|
610
|
-
x: crossAxis * crossAxisMulti,
|
|
611
|
-
y: mainAxis * mainAxisMulti
|
|
612
|
-
} : {
|
|
613
|
-
x: mainAxis * mainAxisMulti,
|
|
614
|
-
y: crossAxis * crossAxisMulti
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Displaces the floating element from its reference element.
|
|
619
|
-
* @see https://floating-ui.com/docs/offset
|
|
620
|
-
*/
|
|
621
|
-
|
|
622
|
-
const offset = function (value) {
|
|
623
|
-
if (value === void 0) {
|
|
624
|
-
value = 0;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return {
|
|
628
|
-
name: 'offset',
|
|
629
|
-
options: value,
|
|
630
|
-
|
|
631
|
-
async fn(middlewareArguments) {
|
|
632
|
-
const {
|
|
633
|
-
x,
|
|
634
|
-
y
|
|
635
|
-
} = middlewareArguments;
|
|
636
|
-
const diffCoords = await convertValueToCoords(middlewareArguments, value);
|
|
637
|
-
return {
|
|
638
|
-
x: x + diffCoords.x,
|
|
639
|
-
y: y + diffCoords.y,
|
|
640
|
-
data: diffCoords
|
|
641
|
-
};
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* handle change from child element
|
|
134
|
+
*/
|
|
135
|
+
this.changeHandler = (e) => {
|
|
136
|
+
if (this.menuItems === undefined) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const changedMenuItem = e.target;
|
|
140
|
+
const changeItemIndex = this.menuItems.indexOf(changedMenuItem);
|
|
141
|
+
if (changeItemIndex === -1) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (changedMenuItem.role === "menuitemradio" &&
|
|
145
|
+
changedMenuItem.checked === true) {
|
|
146
|
+
for (let i = changeItemIndex - 1; i >= 0; --i) {
|
|
147
|
+
const item = this.menuItems[i];
|
|
148
|
+
const role = item.getAttribute("role");
|
|
149
|
+
if (role === MenuItemRole.menuitemradio) {
|
|
150
|
+
item.checked = false;
|
|
151
|
+
}
|
|
152
|
+
if (role === "separator") {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const maxIndex = this.menuItems.length - 1;
|
|
157
|
+
for (let i = changeItemIndex + 1; i <= maxIndex; ++i) {
|
|
158
|
+
const item = this.menuItems[i];
|
|
159
|
+
const role = item.getAttribute("role");
|
|
160
|
+
if (role === MenuItemRole.menuitemradio) {
|
|
161
|
+
item.checked = false;
|
|
162
|
+
}
|
|
163
|
+
if (role === "separator") {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* check if the item is a menu item
|
|
171
|
+
*/
|
|
172
|
+
this.isMenuItemElement = (el) => {
|
|
173
|
+
return (isHTMLElement(el) &&
|
|
174
|
+
Menu$1.focusableElementRoles.hasOwnProperty(el.getAttribute("role")));
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* check if the item is focusable
|
|
178
|
+
*/
|
|
179
|
+
this.isFocusableElement = (el) => {
|
|
180
|
+
return this.isMenuItemElement(el);
|
|
181
|
+
};
|
|
642
182
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
* over multiple lines, such as hyperlinks or range selections.
|
|
650
|
-
* @see https://floating-ui.com/docs/inline
|
|
651
|
-
*/
|
|
652
|
-
const inline = function (options) {
|
|
653
|
-
if (options === void 0) {
|
|
654
|
-
options = {};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return {
|
|
658
|
-
name: 'inline',
|
|
659
|
-
options,
|
|
660
|
-
|
|
661
|
-
async fn(middlewareArguments) {
|
|
662
|
-
var _await$platform$getCl;
|
|
663
|
-
|
|
664
|
-
const {
|
|
665
|
-
placement,
|
|
666
|
-
elements,
|
|
667
|
-
rects,
|
|
668
|
-
platform,
|
|
669
|
-
strategy
|
|
670
|
-
} = middlewareArguments; // A MouseEvent's client{X,Y} coords can be up to 2 pixels off a
|
|
671
|
-
// ClientRect's bounds, despite the event listener being triggered. A
|
|
672
|
-
// padding of 2 seems to handle this issue.
|
|
673
|
-
|
|
674
|
-
const {
|
|
675
|
-
padding = 2,
|
|
676
|
-
x,
|
|
677
|
-
y
|
|
678
|
-
} = options;
|
|
679
|
-
const fallback = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
680
|
-
rect: rects.reference,
|
|
681
|
-
offsetParent: await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating)),
|
|
682
|
-
strategy
|
|
683
|
-
}) : rects.reference);
|
|
684
|
-
const clientRects = (_await$platform$getCl = await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference))) != null ? _await$platform$getCl : [];
|
|
685
|
-
const paddingObject = getSideObjectFromPadding(padding);
|
|
686
|
-
|
|
687
|
-
function getBoundingClientRect() {
|
|
688
|
-
// There are two rects and they are disjoined
|
|
689
|
-
if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
|
|
690
|
-
var _clientRects$find;
|
|
691
|
-
|
|
692
|
-
// Find the first rect in which the point is fully inside
|
|
693
|
-
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;
|
|
694
|
-
} // There are 2 or more connected rects
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (clientRects.length >= 2) {
|
|
698
|
-
if (getMainAxisFromPlacement(placement) === 'x') {
|
|
699
|
-
const firstRect = clientRects[0];
|
|
700
|
-
const lastRect = clientRects[clientRects.length - 1];
|
|
701
|
-
const isTop = getSide(placement) === 'top';
|
|
702
|
-
const top = firstRect.top;
|
|
703
|
-
const bottom = lastRect.bottom;
|
|
704
|
-
const left = isTop ? firstRect.left : lastRect.left;
|
|
705
|
-
const right = isTop ? firstRect.right : lastRect.right;
|
|
706
|
-
const width = right - left;
|
|
707
|
-
const height = bottom - top;
|
|
708
|
-
return {
|
|
709
|
-
top,
|
|
710
|
-
bottom,
|
|
711
|
-
left,
|
|
712
|
-
right,
|
|
713
|
-
width,
|
|
714
|
-
height,
|
|
715
|
-
x: left,
|
|
716
|
-
y: top
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
const isLeftSide = getSide(placement) === 'left';
|
|
721
|
-
const maxRight = max$1(...clientRects.map(rect => rect.right));
|
|
722
|
-
const minLeft = min$1(...clientRects.map(rect => rect.left));
|
|
723
|
-
const measureRects = clientRects.filter(rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
|
|
724
|
-
const top = measureRects[0].top;
|
|
725
|
-
const bottom = measureRects[measureRects.length - 1].bottom;
|
|
726
|
-
const left = minLeft;
|
|
727
|
-
const right = maxRight;
|
|
728
|
-
const width = right - left;
|
|
729
|
-
const height = bottom - top;
|
|
730
|
-
return {
|
|
731
|
-
top,
|
|
732
|
-
bottom,
|
|
733
|
-
left,
|
|
734
|
-
right,
|
|
735
|
-
width,
|
|
736
|
-
height,
|
|
737
|
-
x: left,
|
|
738
|
-
y: top
|
|
739
|
-
};
|
|
183
|
+
itemsChanged(oldValue, newValue) {
|
|
184
|
+
// only update children after the component is connected and
|
|
185
|
+
// the setItems has run on connectedCallback
|
|
186
|
+
// (menuItems is undefined until then)
|
|
187
|
+
if (this.$fastController.isConnected && this.menuItems !== undefined) {
|
|
188
|
+
this.setItems();
|
|
740
189
|
}
|
|
741
|
-
|
|
742
|
-
return fallback;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
const resetRects = await platform.getElementRects({
|
|
746
|
-
reference: {
|
|
747
|
-
getBoundingClientRect
|
|
748
|
-
},
|
|
749
|
-
floating: elements.floating,
|
|
750
|
-
strategy
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
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) {
|
|
754
|
-
return {
|
|
755
|
-
reset: {
|
|
756
|
-
rects: resetRects
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
return {};
|
|
762
190
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
if (!isWindow(node)) {
|
|
776
|
-
const ownerDocument = node.ownerDocument;
|
|
777
|
-
return ownerDocument ? ownerDocument.defaultView || window : window;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
return node;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
function getComputedStyle$1(element) {
|
|
784
|
-
return getWindow(element).getComputedStyle(element);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
function getNodeName(node) {
|
|
788
|
-
return isWindow(node) ? '' : node ? (node.nodeName || '').toLowerCase() : '';
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
function getUAString() {
|
|
792
|
-
const uaData = navigator.userAgentData;
|
|
793
|
-
|
|
794
|
-
if (uaData != null && uaData.brands) {
|
|
795
|
-
return uaData.brands.map(item => item.brand + "/" + item.version).join(' ');
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
return navigator.userAgent;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
function isHTMLElement(value) {
|
|
802
|
-
return value instanceof getWindow(value).HTMLElement;
|
|
803
|
-
}
|
|
804
|
-
function isElement(value) {
|
|
805
|
-
return value instanceof getWindow(value).Element;
|
|
806
|
-
}
|
|
807
|
-
function isNode(value) {
|
|
808
|
-
return value instanceof getWindow(value).Node;
|
|
809
|
-
}
|
|
810
|
-
function isShadowRoot(node) {
|
|
811
|
-
// Browsers without `ShadowRoot` support
|
|
812
|
-
if (typeof ShadowRoot === 'undefined') {
|
|
813
|
-
return false;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
const OwnElement = getWindow(node).ShadowRoot;
|
|
817
|
-
return node instanceof OwnElement || node instanceof ShadowRoot;
|
|
818
|
-
}
|
|
819
|
-
function isOverflowElement(element) {
|
|
820
|
-
// Firefox wants us to check `-x` and `-y` variations as well
|
|
821
|
-
const {
|
|
822
|
-
overflow,
|
|
823
|
-
overflowX,
|
|
824
|
-
overflowY
|
|
825
|
-
} = getComputedStyle$1(element);
|
|
826
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
827
|
-
}
|
|
828
|
-
function isTableElement(element) {
|
|
829
|
-
return ['table', 'td', 'th'].includes(getNodeName(element));
|
|
830
|
-
}
|
|
831
|
-
function isContainingBlock(element) {
|
|
832
|
-
// TODO: Try and use feature detection here instead
|
|
833
|
-
const isFirefox = /firefox/i.test(getUAString());
|
|
834
|
-
const css = getComputedStyle$1(element); // This is non-exhaustive but covers the most common CSS properties that
|
|
835
|
-
// create a containing block.
|
|
836
|
-
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
837
|
-
|
|
838
|
-
return css.transform !== 'none' || css.perspective !== 'none' || // @ts-ignore (TS 4.1 compat)
|
|
839
|
-
css.contain === 'paint' || ['transform', 'perspective'].includes(css.willChange) || isFirefox && css.willChange === 'filter' || isFirefox && (css.filter ? css.filter !== 'none' : false);
|
|
840
|
-
}
|
|
841
|
-
function isLayoutViewport() {
|
|
842
|
-
// Not Safari
|
|
843
|
-
return !/^((?!chrome|android).)*safari/i.test(getUAString()); // Feature detection for this fails in various ways
|
|
844
|
-
// • Always-visible scrollbar or not
|
|
845
|
-
// • Width of <html>, etc.
|
|
846
|
-
// const vV = win.visualViewport;
|
|
847
|
-
// return vV ? Math.abs(win.innerWidth / vV.scale - vV.width) < 0.5 : true;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
const min = Math.min;
|
|
851
|
-
const max = Math.max;
|
|
852
|
-
const round = Math.round;
|
|
853
|
-
|
|
854
|
-
function getBoundingClientRect(element, includeScale, isFixedStrategy) {
|
|
855
|
-
var _win$visualViewport$o, _win$visualViewport, _win$visualViewport$o2, _win$visualViewport2;
|
|
856
|
-
|
|
857
|
-
if (includeScale === void 0) {
|
|
858
|
-
includeScale = false;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
if (isFixedStrategy === void 0) {
|
|
862
|
-
isFixedStrategy = false;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
const clientRect = element.getBoundingClientRect();
|
|
866
|
-
let scaleX = 1;
|
|
867
|
-
let scaleY = 1;
|
|
868
|
-
|
|
869
|
-
if (includeScale && isHTMLElement(element)) {
|
|
870
|
-
scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
|
|
871
|
-
scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
const win = isElement(element) ? getWindow(element) : window;
|
|
875
|
-
const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
|
|
876
|
-
const x = (clientRect.left + (addVisualOffsets ? (_win$visualViewport$o = (_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) != null ? _win$visualViewport$o : 0 : 0)) / scaleX;
|
|
877
|
-
const y = (clientRect.top + (addVisualOffsets ? (_win$visualViewport$o2 = (_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) != null ? _win$visualViewport$o2 : 0 : 0)) / scaleY;
|
|
878
|
-
const width = clientRect.width / scaleX;
|
|
879
|
-
const height = clientRect.height / scaleY;
|
|
880
|
-
return {
|
|
881
|
-
width,
|
|
882
|
-
height,
|
|
883
|
-
top: y,
|
|
884
|
-
right: x + width,
|
|
885
|
-
bottom: y + height,
|
|
886
|
-
left: x,
|
|
887
|
-
x,
|
|
888
|
-
y
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function getDocumentElement(node) {
|
|
893
|
-
return ((isNode(node) ? node.ownerDocument : node.document) || window.document).documentElement;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
function getNodeScroll(element) {
|
|
897
|
-
if (isElement(element)) {
|
|
898
|
-
return {
|
|
899
|
-
scrollLeft: element.scrollLeft,
|
|
900
|
-
scrollTop: element.scrollTop
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
return {
|
|
905
|
-
scrollLeft: element.pageXOffset,
|
|
906
|
-
scrollTop: element.pageYOffset
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
function getWindowScrollBarX(element) {
|
|
911
|
-
// If <html> has a CSS width greater than the viewport, then this will be
|
|
912
|
-
// incorrect for RTL.
|
|
913
|
-
return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
function isScaled(element) {
|
|
917
|
-
const rect = getBoundingClientRect(element);
|
|
918
|
-
return round(rect.width) !== element.offsetWidth || round(rect.height) !== element.offsetHeight;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
922
|
-
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
923
|
-
const documentElement = getDocumentElement(offsetParent);
|
|
924
|
-
const rect = getBoundingClientRect(element, // @ts-ignore - checked above (TS 4.1 compat)
|
|
925
|
-
isOffsetParentAnElement && isScaled(offsetParent), strategy === 'fixed');
|
|
926
|
-
let scroll = {
|
|
927
|
-
scrollLeft: 0,
|
|
928
|
-
scrollTop: 0
|
|
929
|
-
};
|
|
930
|
-
const offsets = {
|
|
931
|
-
x: 0,
|
|
932
|
-
y: 0
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
|
|
936
|
-
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
937
|
-
scroll = getNodeScroll(offsetParent);
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
connectedCallback() {
|
|
195
|
+
super.connectedCallback();
|
|
196
|
+
DOM.queueUpdate(() => {
|
|
197
|
+
// wait until children have had a chance to
|
|
198
|
+
// connect before setting/checking their props/attributes
|
|
199
|
+
this.setItems();
|
|
200
|
+
});
|
|
201
|
+
this.addEventListener("change", this.changeHandler);
|
|
938
202
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
203
|
+
/**
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
disconnectedCallback() {
|
|
207
|
+
super.disconnectedCallback();
|
|
208
|
+
this.removeItemListeners();
|
|
209
|
+
this.menuItems = undefined;
|
|
210
|
+
this.removeEventListener("change", this.changeHandler);
|
|
946
211
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
function getParentNode(node) {
|
|
958
|
-
if (getNodeName(node) === 'html') {
|
|
959
|
-
return node;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
|
|
963
|
-
// @ts-ignore
|
|
964
|
-
node.assignedSlot || // step into the shadow DOM of the parent of a slotted node
|
|
965
|
-
node.parentNode || ( // DOM Element detected
|
|
966
|
-
isShadowRoot(node) ? node.host : null) || // ShadowRoot detected
|
|
967
|
-
getDocumentElement(node) // fallback
|
|
968
|
-
|
|
969
|
-
);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
function getTrueOffsetParent(element) {
|
|
973
|
-
if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {
|
|
974
|
-
return null;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
return element.offsetParent;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
function getContainingBlock(element) {
|
|
981
|
-
let currentNode = getParentNode(element);
|
|
982
|
-
|
|
983
|
-
if (isShadowRoot(currentNode)) {
|
|
984
|
-
currentNode = currentNode.host;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
while (isHTMLElement(currentNode) && !['html', 'body'].includes(getNodeName(currentNode))) {
|
|
988
|
-
if (isContainingBlock(currentNode)) {
|
|
989
|
-
return currentNode;
|
|
990
|
-
} else {
|
|
991
|
-
currentNode = currentNode.parentNode;
|
|
212
|
+
/**
|
|
213
|
+
* Focuses the first item in the menu.
|
|
214
|
+
*
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
217
|
+
focus() {
|
|
218
|
+
this.setFocus(0, 1);
|
|
992
219
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
|
|
1005
|
-
offsetParent = getTrueOffsetParent(offsetParent);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
|
|
1009
|
-
return window;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
return offsetParent || getContainingBlock(element) || window;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
function getDimensions(element) {
|
|
1016
|
-
if (isHTMLElement(element)) {
|
|
1017
|
-
return {
|
|
1018
|
-
width: element.offsetWidth,
|
|
1019
|
-
height: element.offsetHeight
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
const rect = getBoundingClientRect(element);
|
|
1024
|
-
return {
|
|
1025
|
-
width: rect.width,
|
|
1026
|
-
height: rect.height
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
1031
|
-
let {
|
|
1032
|
-
rect,
|
|
1033
|
-
offsetParent,
|
|
1034
|
-
strategy
|
|
1035
|
-
} = _ref;
|
|
1036
|
-
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1037
|
-
const documentElement = getDocumentElement(offsetParent);
|
|
1038
|
-
|
|
1039
|
-
if (offsetParent === documentElement) {
|
|
1040
|
-
return rect;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
let scroll = {
|
|
1044
|
-
scrollLeft: 0,
|
|
1045
|
-
scrollTop: 0
|
|
1046
|
-
};
|
|
1047
|
-
const offsets = {
|
|
1048
|
-
x: 0,
|
|
1049
|
-
y: 0
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
|
|
1053
|
-
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1054
|
-
scroll = getNodeScroll(offsetParent);
|
|
220
|
+
/**
|
|
221
|
+
* Collapses any expanded menu items.
|
|
222
|
+
*
|
|
223
|
+
* @public
|
|
224
|
+
*/
|
|
225
|
+
collapseExpandedItem() {
|
|
226
|
+
if (this.expandedItem !== null) {
|
|
227
|
+
this.expandedItem.expanded = false;
|
|
228
|
+
this.expandedItem = null;
|
|
229
|
+
}
|
|
1055
230
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
width = visualViewport.width;
|
|
1085
|
-
height = visualViewport.height;
|
|
1086
|
-
const layoutViewport = isLayoutViewport();
|
|
1087
|
-
|
|
1088
|
-
if (layoutViewport || !layoutViewport && strategy === 'fixed') {
|
|
1089
|
-
x = visualViewport.offsetLeft;
|
|
1090
|
-
y = visualViewport.offsetTop;
|
|
231
|
+
/**
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
handleMenuKeyDown(e) {
|
|
235
|
+
if (e.defaultPrevented || this.menuItems === undefined) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
switch (e.key) {
|
|
239
|
+
case keyArrowDown:
|
|
240
|
+
// go forward one index
|
|
241
|
+
this.setFocus(this.focusIndex + 1, 1);
|
|
242
|
+
return;
|
|
243
|
+
case keyArrowUp:
|
|
244
|
+
// go back one index
|
|
245
|
+
this.setFocus(this.focusIndex - 1, -1);
|
|
246
|
+
return;
|
|
247
|
+
case keyEnd:
|
|
248
|
+
// set focus on last item
|
|
249
|
+
this.setFocus(this.menuItems.length - 1, -1);
|
|
250
|
+
return;
|
|
251
|
+
case keyHome:
|
|
252
|
+
// set focus on first item
|
|
253
|
+
this.setFocus(0, 1);
|
|
254
|
+
return;
|
|
255
|
+
default:
|
|
256
|
+
// if we are not handling the event, do not prevent default
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
1091
259
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
x,
|
|
1098
|
-
y
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
// of the `<html>` and `<body>` rect bounds if horizontally scrollable
|
|
1103
|
-
|
|
1104
|
-
function getDocumentRect(element) {
|
|
1105
|
-
var _element$ownerDocumen;
|
|
1106
|
-
|
|
1107
|
-
const html = getDocumentElement(element);
|
|
1108
|
-
const scroll = getNodeScroll(element);
|
|
1109
|
-
const body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
|
|
1110
|
-
const width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
|
|
1111
|
-
const height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
|
|
1112
|
-
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
1113
|
-
const y = -scroll.scrollTop;
|
|
1114
|
-
|
|
1115
|
-
if (getComputedStyle$1(body || html).direction === 'rtl') {
|
|
1116
|
-
x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
return {
|
|
1120
|
-
width,
|
|
1121
|
-
height,
|
|
1122
|
-
x,
|
|
1123
|
-
y
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
function getNearestOverflowAncestor(node) {
|
|
1128
|
-
const parentNode = getParentNode(node);
|
|
1129
|
-
|
|
1130
|
-
if (['html', 'body', '#document'].includes(getNodeName(parentNode))) {
|
|
1131
|
-
// @ts-ignore assume body is always available
|
|
1132
|
-
return node.ownerDocument.body;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
1136
|
-
return parentNode;
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
return getNearestOverflowAncestor(parentNode);
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
function getOverflowAncestors(node, list) {
|
|
1143
|
-
var _node$ownerDocument;
|
|
1144
|
-
|
|
1145
|
-
if (list === void 0) {
|
|
1146
|
-
list = [];
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
1150
|
-
const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
|
|
1151
|
-
const win = getWindow(scrollableAncestor);
|
|
1152
|
-
const target = isBody ? [win].concat(win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []) : scrollableAncestor;
|
|
1153
|
-
const updatedList = list.concat(target);
|
|
1154
|
-
return isBody ? updatedList : // @ts-ignore: isBody tells us target will be an HTMLElement here
|
|
1155
|
-
updatedList.concat(getOverflowAncestors(target));
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
function contains(parent, child) {
|
|
1159
|
-
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode(); // First, attempt with faster native method
|
|
1160
|
-
|
|
1161
|
-
if (parent.contains(child)) {
|
|
1162
|
-
return true;
|
|
1163
|
-
} // then fallback to custom implementation with Shadow DOM support
|
|
1164
|
-
else if (rootNode && isShadowRoot(rootNode)) {
|
|
1165
|
-
let next = child;
|
|
1166
|
-
|
|
1167
|
-
do {
|
|
1168
|
-
// use `===` replace node.isSameNode()
|
|
1169
|
-
if (next && parent === next) {
|
|
1170
|
-
return true;
|
|
1171
|
-
} // @ts-ignore: need a better way to handle this...
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
next = next.parentNode || next.host;
|
|
1175
|
-
} while (next);
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
return false;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
function getInnerBoundingClientRect(element, strategy) {
|
|
1182
|
-
const clientRect = getBoundingClientRect(element, false, strategy === 'fixed');
|
|
1183
|
-
const top = clientRect.top + element.clientTop;
|
|
1184
|
-
const left = clientRect.left + element.clientLeft;
|
|
1185
|
-
return {
|
|
1186
|
-
top,
|
|
1187
|
-
left,
|
|
1188
|
-
x: left,
|
|
1189
|
-
y: top,
|
|
1190
|
-
right: left + element.clientWidth,
|
|
1191
|
-
bottom: top + element.clientHeight,
|
|
1192
|
-
width: element.clientWidth,
|
|
1193
|
-
height: element.clientHeight
|
|
1194
|
-
};
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
function getClientRectFromClippingAncestor(element, clippingParent, strategy) {
|
|
1198
|
-
if (clippingParent === 'viewport') {
|
|
1199
|
-
return rectToClientRect(getViewportRect(element, strategy));
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
if (isElement(clippingParent)) {
|
|
1203
|
-
return getInnerBoundingClientRect(clippingParent, strategy);
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
return rectToClientRect(getDocumentRect(getDocumentElement(element)));
|
|
1207
|
-
} // A "clipping ancestor" is an overflowable container with the characteristic of
|
|
1208
|
-
// clipping (or hiding) overflowing elements with a position different from
|
|
1209
|
-
// `initial`
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
function getClippingAncestors(element) {
|
|
1213
|
-
const clippingAncestors = getOverflowAncestors(element);
|
|
1214
|
-
const canEscapeClipping = ['absolute', 'fixed'].includes(getComputedStyle$1(element).position);
|
|
1215
|
-
const clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
|
|
1216
|
-
|
|
1217
|
-
if (!isElement(clipperElement)) {
|
|
1218
|
-
return [];
|
|
1219
|
-
} // @ts-ignore isElement check ensures we return Array<Element>
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
return clippingAncestors.filter(clippingAncestors => isElement(clippingAncestors) && contains(clippingAncestors, clipperElement) && getNodeName(clippingAncestors) !== 'body');
|
|
1223
|
-
} // Gets the maximum area that the element is visible in due to any number of
|
|
1224
|
-
// clipping ancestors
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
function getClippingRect(_ref) {
|
|
1228
|
-
let {
|
|
1229
|
-
element,
|
|
1230
|
-
boundary,
|
|
1231
|
-
rootBoundary,
|
|
1232
|
-
strategy
|
|
1233
|
-
} = _ref;
|
|
1234
|
-
const mainClippingAncestors = boundary === 'clippingAncestors' ? getClippingAncestors(element) : [].concat(boundary);
|
|
1235
|
-
const clippingAncestors = [...mainClippingAncestors, rootBoundary];
|
|
1236
|
-
const firstClippingAncestor = clippingAncestors[0];
|
|
1237
|
-
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
1238
|
-
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
1239
|
-
accRect.top = max(rect.top, accRect.top);
|
|
1240
|
-
accRect.right = min(rect.right, accRect.right);
|
|
1241
|
-
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
1242
|
-
accRect.left = max(rect.left, accRect.left);
|
|
1243
|
-
return accRect;
|
|
1244
|
-
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
1245
|
-
return {
|
|
1246
|
-
width: clippingRect.right - clippingRect.left,
|
|
1247
|
-
height: clippingRect.bottom - clippingRect.top,
|
|
1248
|
-
x: clippingRect.left,
|
|
1249
|
-
y: clippingRect.top
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
const platform = {
|
|
1254
|
-
getClippingRect,
|
|
1255
|
-
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
1256
|
-
isElement,
|
|
1257
|
-
getDimensions,
|
|
1258
|
-
getOffsetParent,
|
|
1259
|
-
getDocumentElement,
|
|
1260
|
-
getElementRects: _ref => {
|
|
1261
|
-
let {
|
|
1262
|
-
reference,
|
|
1263
|
-
floating,
|
|
1264
|
-
strategy
|
|
1265
|
-
} = _ref;
|
|
1266
|
-
return {
|
|
1267
|
-
reference: getRectRelativeToOffsetParent(reference, getOffsetParent(floating), strategy),
|
|
1268
|
-
floating: { ...getDimensions(floating),
|
|
1269
|
-
x: 0,
|
|
1270
|
-
y: 0
|
|
1271
|
-
}
|
|
1272
|
-
};
|
|
1273
|
-
},
|
|
1274
|
-
getClientRects: element => Array.from(element.getClientRects()),
|
|
1275
|
-
isRTL: element => getComputedStyle$1(element).direction === 'rtl'
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
/**
|
|
1279
|
-
* Automatically updates the position of the floating element when necessary.
|
|
1280
|
-
* @see https://floating-ui.com/docs/autoUpdate
|
|
1281
|
-
*/
|
|
1282
|
-
function autoUpdate(reference, floating, update, options) {
|
|
1283
|
-
if (options === void 0) {
|
|
1284
|
-
options = {};
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
const {
|
|
1288
|
-
ancestorScroll: _ancestorScroll = true,
|
|
1289
|
-
ancestorResize: _ancestorResize = true,
|
|
1290
|
-
elementResize = true,
|
|
1291
|
-
animationFrame = false
|
|
1292
|
-
} = options;
|
|
1293
|
-
const ancestorScroll = _ancestorScroll && !animationFrame;
|
|
1294
|
-
const ancestorResize = _ancestorResize && !animationFrame;
|
|
1295
|
-
const ancestors = ancestorScroll || ancestorResize ? [...(isElement(reference) ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)] : [];
|
|
1296
|
-
ancestors.forEach(ancestor => {
|
|
1297
|
-
ancestorScroll && ancestor.addEventListener('scroll', update, {
|
|
1298
|
-
passive: true
|
|
1299
|
-
});
|
|
1300
|
-
ancestorResize && ancestor.addEventListener('resize', update);
|
|
1301
|
-
});
|
|
1302
|
-
let observer = null;
|
|
1303
|
-
|
|
1304
|
-
if (elementResize) {
|
|
1305
|
-
let initialUpdate = true;
|
|
1306
|
-
observer = new ResizeObserver(() => {
|
|
1307
|
-
if (!initialUpdate) {
|
|
1308
|
-
update();
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
initialUpdate = false;
|
|
1312
|
-
});
|
|
1313
|
-
isElement(reference) && !animationFrame && observer.observe(reference);
|
|
1314
|
-
observer.observe(floating);
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
let frameId;
|
|
1318
|
-
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
1319
|
-
|
|
1320
|
-
if (animationFrame) {
|
|
1321
|
-
frameLoop();
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
function frameLoop() {
|
|
1325
|
-
const nextRefRect = getBoundingClientRect(reference);
|
|
1326
|
-
|
|
1327
|
-
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
|
1328
|
-
update();
|
|
260
|
+
/**
|
|
261
|
+
* get an array of valid DOM children
|
|
262
|
+
*/
|
|
263
|
+
domChildren() {
|
|
264
|
+
return Array.from(this.children).filter(child => !child.hasAttribute("hidden"));
|
|
1329
265
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
266
|
+
setFocus(focusIndex, adjustment) {
|
|
267
|
+
if (this.menuItems === undefined) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
while (focusIndex >= 0 && focusIndex < this.menuItems.length) {
|
|
271
|
+
const child = this.menuItems[focusIndex];
|
|
272
|
+
if (this.isFocusableElement(child)) {
|
|
273
|
+
// change the previous index to -1
|
|
274
|
+
if (this.focusIndex > -1 &&
|
|
275
|
+
this.menuItems.length >= this.focusIndex - 1) {
|
|
276
|
+
this.menuItems[this.focusIndex].setAttribute("tabindex", "-1");
|
|
277
|
+
}
|
|
278
|
+
// update the focus index
|
|
279
|
+
this.focusIndex = focusIndex;
|
|
280
|
+
// update the tabindex of next focusable element
|
|
281
|
+
child.setAttribute("tabindex", "0");
|
|
282
|
+
// focus the element
|
|
283
|
+
child.focus();
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
focusIndex += adjustment;
|
|
287
|
+
}
|
|
1348
288
|
}
|
|
1349
|
-
};
|
|
1350
289
|
}
|
|
290
|
+
Menu$1.focusableElementRoles = roleForMenuItem;
|
|
291
|
+
__decorate([
|
|
292
|
+
observable
|
|
293
|
+
], Menu$1.prototype, "items", void 0);
|
|
1351
294
|
|
|
1352
|
-
|
|
1353
|
-
* Computes the `x` and `y` coordinates that will place the floating element
|
|
1354
|
-
* next to a reference element when it is given a certain CSS positioning
|
|
1355
|
-
* strategy.
|
|
1356
|
-
*/
|
|
1357
|
-
|
|
1358
|
-
const computePosition = (reference, floating, options) => computePosition$1(reference, floating, {
|
|
1359
|
-
platform,
|
|
1360
|
-
...options
|
|
1361
|
-
});
|
|
295
|
+
var css_248z = ".base {\n max-inline-size: var(--menu-max-inline-size, 100%);\n min-inline-size: var(--menu-max-inline-size);\n padding-block: 8px;\n}";
|
|
1362
296
|
|
|
1363
|
-
|
|
1364
|
-
class Popup extends FoundationElement {
|
|
297
|
+
class Menu extends Menu$1 {
|
|
1365
298
|
constructor() {
|
|
1366
299
|
super(...arguments);
|
|
1367
|
-
_Popup_instances.add(this);
|
|
1368
|
-
_Popup_cleanup.set(this, void 0);
|
|
1369
300
|
this.open = false;
|
|
1370
|
-
this.
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
this.strategy = 'fixed';
|
|
1374
|
-
_Popup_handleKeydown.set(this, event => {
|
|
1375
|
-
if (event.key === keyEscape) {
|
|
1376
|
-
this.open = false;
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
}
|
|
1380
|
-
openChanged(_, newValue) {
|
|
1381
|
-
newValue ? this.$emit('open') : this.$emit('close');
|
|
1382
|
-
}
|
|
1383
|
-
disconnectedCallback() {
|
|
1384
|
-
var _a, _b;
|
|
1385
|
-
super.disconnectedCallback();
|
|
1386
|
-
(_a = this.anchorEl) === null || _a === void 0 ? void 0 : _a.removeEventListener('keydown', __classPrivateFieldGet(this, _Popup_handleKeydown, "f"));
|
|
1387
|
-
(_b = __classPrivateFieldGet(this, _Popup_cleanup, "f")) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
1388
|
-
}
|
|
1389
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
1390
|
-
var _a, _b, _c;
|
|
1391
|
-
super.attributeChangedCallback(name, oldValue, newValue);
|
|
1392
|
-
switch (name) {
|
|
1393
|
-
case 'anchor':
|
|
1394
|
-
{
|
|
1395
|
-
(_a = this.anchorEl) === null || _a === void 0 ? void 0 : _a.removeEventListener('keydown', __classPrivateFieldGet(this, _Popup_handleKeydown, "f"));
|
|
1396
|
-
this.anchorEl = __classPrivateFieldGet(this, _Popup_instances, "m", _Popup_getAnchor).call(this);
|
|
1397
|
-
(_b = this.anchorEl) === null || _b === void 0 ? void 0 : _b.addEventListener('keydown', __classPrivateFieldGet(this, _Popup_handleKeydown, "f"));
|
|
1398
|
-
break;
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
if (this.anchorEl && this.popupEl) {
|
|
1402
|
-
__classPrivateFieldSet(this, _Popup_cleanup, autoUpdate(this.anchorEl, this.popupEl, () => this.updatePosition()), "f");
|
|
1403
|
-
} else {
|
|
1404
|
-
(_c = __classPrivateFieldGet(this, _Popup_cleanup, "f")) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
async updatePosition() {
|
|
1408
|
-
if (!this.open || !this.anchorEl) {
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
const positionData = await computePosition(this.anchorEl, this.popupEl, {
|
|
1412
|
-
placement: this.placement,
|
|
1413
|
-
strategy: this.strategy,
|
|
1414
|
-
middleware: __classPrivateFieldGet(this, _Popup_instances, "a", _Popup_middleware_get)
|
|
1415
|
-
});
|
|
1416
|
-
__classPrivateFieldGet(this, _Popup_instances, "m", _Popup_assignPopupPosition).call(this, positionData);
|
|
1417
|
-
if (this.arrow) {
|
|
1418
|
-
__classPrivateFieldGet(this, _Popup_instances, "m", _Popup_assignArrowPosition).call(this, positionData);
|
|
1419
|
-
}
|
|
301
|
+
this.popupOpenChanged = () => {
|
|
302
|
+
this.open = this._popup.open;
|
|
303
|
+
};
|
|
1420
304
|
}
|
|
1421
305
|
}
|
|
1422
|
-
_Popup_cleanup = new WeakMap(), _Popup_handleKeydown = new WeakMap(), _Popup_instances = new WeakSet(), _Popup_arrowPosition_get = function _Popup_arrowPosition_get() {
|
|
1423
|
-
return {
|
|
1424
|
-
top: 'bottom',
|
|
1425
|
-
right: 'left',
|
|
1426
|
-
bottom: 'top',
|
|
1427
|
-
left: 'right'
|
|
1428
|
-
};
|
|
1429
|
-
}, _Popup_padding_get = function _Popup_padding_get() {
|
|
1430
|
-
return 0;
|
|
1431
|
-
}, _Popup_distance_get = function _Popup_distance_get() {
|
|
1432
|
-
return 12;
|
|
1433
|
-
}, _Popup_middleware_get = function _Popup_middleware_get() {
|
|
1434
|
-
const middleware = [flip(), hide(), inline()];
|
|
1435
|
-
if (this.arrow) {
|
|
1436
|
-
middleware.push(arrow({
|
|
1437
|
-
element: this.arrowEl,
|
|
1438
|
-
padding: __classPrivateFieldGet(this, _Popup_instances, "a", _Popup_padding_get)
|
|
1439
|
-
}), offset(__classPrivateFieldGet(this, _Popup_instances, "a", _Popup_distance_get)));
|
|
1440
|
-
}
|
|
1441
|
-
return middleware;
|
|
1442
|
-
}, _Popup_assignPopupPosition = function _Popup_assignPopupPosition(data) {
|
|
1443
|
-
const {
|
|
1444
|
-
x: popupX,
|
|
1445
|
-
y: popupY
|
|
1446
|
-
} = data;
|
|
1447
|
-
const {
|
|
1448
|
-
referenceHidden
|
|
1449
|
-
} = data.middlewareData.hide;
|
|
1450
|
-
Object.assign(this.popupEl.style, {
|
|
1451
|
-
left: `${popupX}px`,
|
|
1452
|
-
top: `${popupY}px`,
|
|
1453
|
-
visibility: referenceHidden ? 'hidden' : 'visible'
|
|
1454
|
-
});
|
|
1455
|
-
}, _Popup_assignArrowPosition = function _Popup_assignArrowPosition(data) {
|
|
1456
|
-
const {
|
|
1457
|
-
x: arrowX,
|
|
1458
|
-
y: arrowY
|
|
1459
|
-
} = data.middlewareData.arrow;
|
|
1460
|
-
const side = __classPrivateFieldGet(this, _Popup_instances, "a", _Popup_arrowPosition_get)[data.placement.split('-')[0]];
|
|
1461
|
-
Object.assign(this.arrowEl.style, {
|
|
1462
|
-
left: `${arrowX}px`,
|
|
1463
|
-
top: `${arrowY}px`,
|
|
1464
|
-
right: '',
|
|
1465
|
-
bottom: '',
|
|
1466
|
-
[side]: '-4px'
|
|
1467
|
-
});
|
|
1468
|
-
}, _Popup_getAnchor = function _Popup_getAnchor() {
|
|
1469
|
-
return this.anchor instanceof HTMLElement ? this.anchor : document.getElementById(this.anchor);
|
|
1470
|
-
};
|
|
1471
306
|
__decorate([attr({
|
|
1472
307
|
mode: 'boolean'
|
|
1473
|
-
}), __metadata("design:type", Object)],
|
|
1474
|
-
__decorate([attr(
|
|
1475
|
-
|
|
1476
|
-
}), __metadata("design:type", Object)], Popup.prototype, "dismissible", void 0);
|
|
1477
|
-
__decorate([attr({
|
|
1478
|
-
mode: 'boolean'
|
|
1479
|
-
}), __metadata("design:type", Object)], Popup.prototype, "arrow", void 0);
|
|
1480
|
-
__decorate([attr({
|
|
1481
|
-
mode: 'boolean'
|
|
1482
|
-
}), __metadata("design:type", Object)], Popup.prototype, "alternate", void 0);
|
|
1483
|
-
__decorate([attr({
|
|
1484
|
-
mode: 'fromView'
|
|
1485
|
-
}), __metadata("design:type", String)], Popup.prototype, "placement", void 0);
|
|
1486
|
-
__decorate([attr({
|
|
1487
|
-
mode: 'fromView'
|
|
1488
|
-
}), __metadata("design:type", String)], Popup.prototype, "strategy", void 0);
|
|
1489
|
-
__decorate([attr, __metadata("design:type", Object)], Popup.prototype, "anchor", void 0);
|
|
1490
|
-
|
|
1491
|
-
var css_248z = ".control {\n background: var(--vvd-color-surface-4dp);\n border-radius: inherit;\n contain: layout;\n inline-size: var(--_popup-width, fit-content);\n}\n.control:not(.open) {\n display: none;\n}\n\n.popup-wrapper {\n border-radius: 6px;\n}\n.popup-wrapper:not(.absolute) {\n position: fixed;\n}\n.popup-wrapper.absolute {\n position: absolute;\n inline-size: var(--_popup-width);\n}\n\n.popup-content {\n display: grid;\n color: var(--vvd-color-canvas-text); /* neutral-100 */\n}\n.dismissible .popup-content {\n align-content: start;\n grid-template-columns: 1fr auto;\n}\n\n.arrow {\n position: absolute;\n z-index: -1;\n width: 8px;\n height: 8px;\n background: var(--vvd-color-surface-4dp);\n transform: rotate(45deg);\n}\n\n.dismissible-button {\n align-self: flex-start;\n margin-block-start: 4px;\n margin-inline-end: 4px;\n}";
|
|
308
|
+
}), __metadata("design:type", Object)], Menu.prototype, "open", void 0);
|
|
309
|
+
__decorate([attr, __metadata("design:type", String)], Menu.prototype, "placement", void 0);
|
|
310
|
+
__decorate([attr, __metadata("design:type", String)], Menu.prototype, "anchor", void 0);
|
|
1492
311
|
|
|
1493
312
|
let _ = t => t,
|
|
1494
|
-
_t
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
const getClasses = ({
|
|
1498
|
-
open,
|
|
1499
|
-
dismissible,
|
|
1500
|
-
alternate
|
|
1501
|
-
}) => classNames('control', ['open', Boolean(open)], ['dismissible', Boolean(dismissible)], ['alternate', Boolean(alternate)]);
|
|
1502
|
-
const popupTemplate = context => {
|
|
1503
|
-
const elevationTag = context.tagFor(Elevation);
|
|
1504
|
-
const buttonTag = context.tagFor(Button);
|
|
313
|
+
_t;
|
|
314
|
+
const MenuTemplate = context => {
|
|
315
|
+
const popupTag = context.tagFor(Popup);
|
|
1505
316
|
return html(_t || (_t = _`
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
317
|
+
<template
|
|
318
|
+
slot="${0}"
|
|
319
|
+
>
|
|
320
|
+
<${0}
|
|
321
|
+
:placement=${0}
|
|
322
|
+
:open=${0}
|
|
323
|
+
:anchor=${0}
|
|
324
|
+
@open="${0}"
|
|
325
|
+
@close="${0}"
|
|
1514
326
|
${0}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
327
|
+
>
|
|
328
|
+
<div
|
|
329
|
+
class="base"
|
|
330
|
+
role="menu"
|
|
331
|
+
@keydown="${0}"
|
|
332
|
+
@focusout="${0}"
|
|
333
|
+
>
|
|
334
|
+
<slot ${0}></slot>
|
|
335
|
+
</div>
|
|
336
|
+
</${0}>
|
|
337
|
+
</template>`), x => x.slot || x.isNestedMenu() ? 'submenu' : void 0, popupTag, x => x.placement, x => x.open, x => x.anchor, x => x.popupOpenChanged(), x => x.popupOpenChanged(), ref('_popup'), (x, c) => x.handleMenuKeyDown(c.event), (x, c) => x.handleFocusOut(c.event), slotted('items'), popupTag);
|
|
1519
338
|
};
|
|
1520
339
|
|
|
1521
|
-
const
|
|
1522
|
-
baseName: '
|
|
1523
|
-
template:
|
|
340
|
+
const menuDefinition = Menu.compose({
|
|
341
|
+
baseName: 'menu',
|
|
342
|
+
template: MenuTemplate,
|
|
1524
343
|
styles: css_248z
|
|
1525
|
-
})
|
|
1526
|
-
const
|
|
1527
|
-
const
|
|
344
|
+
});
|
|
345
|
+
const menuRegistries = [menuDefinition(), ...popupRegistries, ...menuItemRegistries];
|
|
346
|
+
const registerMenu = registerFactory(menuRegistries);
|
|
1528
347
|
|
|
1529
|
-
export {
|
|
348
|
+
export { menuRegistries as a, menuDefinition as m, registerMenu as r };
|