@y14e/menu 1.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.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.cjs +3301 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +3299 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3301 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
|
4
|
+
var min = Math.min;
|
|
5
|
+
var max = Math.max;
|
|
6
|
+
var round = Math.round;
|
|
7
|
+
var floor = Math.floor;
|
|
8
|
+
var createCoords = (v) => ({
|
|
9
|
+
x: v,
|
|
10
|
+
y: v
|
|
11
|
+
});
|
|
12
|
+
var oppositeSideMap = {
|
|
13
|
+
left: "right",
|
|
14
|
+
right: "left",
|
|
15
|
+
bottom: "top",
|
|
16
|
+
top: "bottom"
|
|
17
|
+
};
|
|
18
|
+
function clamp(start, value, end) {
|
|
19
|
+
return max(start, min(value, end));
|
|
20
|
+
}
|
|
21
|
+
function evaluate(value, param) {
|
|
22
|
+
return typeof value === "function" ? value(param) : value;
|
|
23
|
+
}
|
|
24
|
+
function getSide(placement) {
|
|
25
|
+
return placement.split("-")[0];
|
|
26
|
+
}
|
|
27
|
+
function getAlignment(placement) {
|
|
28
|
+
return placement.split("-")[1];
|
|
29
|
+
}
|
|
30
|
+
function getOppositeAxis(axis) {
|
|
31
|
+
return axis === "x" ? "y" : "x";
|
|
32
|
+
}
|
|
33
|
+
function getAxisLength(axis) {
|
|
34
|
+
return axis === "y" ? "height" : "width";
|
|
35
|
+
}
|
|
36
|
+
function getSideAxis(placement) {
|
|
37
|
+
const firstChar = placement[0];
|
|
38
|
+
return firstChar === "t" || firstChar === "b" ? "y" : "x";
|
|
39
|
+
}
|
|
40
|
+
function getAlignmentAxis(placement) {
|
|
41
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
42
|
+
}
|
|
43
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
44
|
+
if (rtl === void 0) {
|
|
45
|
+
rtl = false;
|
|
46
|
+
}
|
|
47
|
+
const alignment = getAlignment(placement);
|
|
48
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
49
|
+
const length = getAxisLength(alignmentAxis);
|
|
50
|
+
let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
|
|
51
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
52
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
53
|
+
}
|
|
54
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
55
|
+
}
|
|
56
|
+
function getExpandedPlacements(placement) {
|
|
57
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
58
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
59
|
+
}
|
|
60
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
61
|
+
return placement.includes("start") ? placement.replace("start", "end") : placement.replace("end", "start");
|
|
62
|
+
}
|
|
63
|
+
var lrPlacement = ["left", "right"];
|
|
64
|
+
var rlPlacement = ["right", "left"];
|
|
65
|
+
var tbPlacement = ["top", "bottom"];
|
|
66
|
+
var btPlacement = ["bottom", "top"];
|
|
67
|
+
function getSideList(side, isStart, rtl) {
|
|
68
|
+
switch (side) {
|
|
69
|
+
case "top":
|
|
70
|
+
case "bottom":
|
|
71
|
+
if (rtl) return isStart ? rlPlacement : lrPlacement;
|
|
72
|
+
return isStart ? lrPlacement : rlPlacement;
|
|
73
|
+
case "left":
|
|
74
|
+
case "right":
|
|
75
|
+
return isStart ? tbPlacement : btPlacement;
|
|
76
|
+
default:
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
81
|
+
const alignment = getAlignment(placement);
|
|
82
|
+
let list = getSideList(getSide(placement), direction === "start", rtl);
|
|
83
|
+
if (alignment) {
|
|
84
|
+
list = list.map((side) => side + "-" + alignment);
|
|
85
|
+
if (flipAlignment) {
|
|
86
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return list;
|
|
90
|
+
}
|
|
91
|
+
function getOppositePlacement(placement) {
|
|
92
|
+
const side = getSide(placement);
|
|
93
|
+
return oppositeSideMap[side] + placement.slice(side.length);
|
|
94
|
+
}
|
|
95
|
+
function expandPaddingObject(padding) {
|
|
96
|
+
return {
|
|
97
|
+
top: 0,
|
|
98
|
+
right: 0,
|
|
99
|
+
bottom: 0,
|
|
100
|
+
left: 0,
|
|
101
|
+
...padding
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function getPaddingObject(padding) {
|
|
105
|
+
return typeof padding !== "number" ? expandPaddingObject(padding) : {
|
|
106
|
+
top: padding,
|
|
107
|
+
right: padding,
|
|
108
|
+
bottom: padding,
|
|
109
|
+
left: padding
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function rectToClientRect(rect) {
|
|
113
|
+
const {
|
|
114
|
+
x,
|
|
115
|
+
y,
|
|
116
|
+
width,
|
|
117
|
+
height
|
|
118
|
+
} = rect;
|
|
119
|
+
return {
|
|
120
|
+
width,
|
|
121
|
+
height,
|
|
122
|
+
top: y,
|
|
123
|
+
left: x,
|
|
124
|
+
right: x + width,
|
|
125
|
+
bottom: y + height,
|
|
126
|
+
x,
|
|
127
|
+
y
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// node_modules/@floating-ui/core/dist/floating-ui.core.mjs
|
|
132
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
133
|
+
let {
|
|
134
|
+
reference,
|
|
135
|
+
floating
|
|
136
|
+
} = _ref;
|
|
137
|
+
const sideAxis = getSideAxis(placement);
|
|
138
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
139
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
140
|
+
const side = getSide(placement);
|
|
141
|
+
const isVertical = sideAxis === "y";
|
|
142
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
143
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
144
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
145
|
+
let coords;
|
|
146
|
+
switch (side) {
|
|
147
|
+
case "top":
|
|
148
|
+
coords = {
|
|
149
|
+
x: commonX,
|
|
150
|
+
y: reference.y - floating.height
|
|
151
|
+
};
|
|
152
|
+
break;
|
|
153
|
+
case "bottom":
|
|
154
|
+
coords = {
|
|
155
|
+
x: commonX,
|
|
156
|
+
y: reference.y + reference.height
|
|
157
|
+
};
|
|
158
|
+
break;
|
|
159
|
+
case "right":
|
|
160
|
+
coords = {
|
|
161
|
+
x: reference.x + reference.width,
|
|
162
|
+
y: commonY
|
|
163
|
+
};
|
|
164
|
+
break;
|
|
165
|
+
case "left":
|
|
166
|
+
coords = {
|
|
167
|
+
x: reference.x - floating.width,
|
|
168
|
+
y: commonY
|
|
169
|
+
};
|
|
170
|
+
break;
|
|
171
|
+
default:
|
|
172
|
+
coords = {
|
|
173
|
+
x: reference.x,
|
|
174
|
+
y: reference.y
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
switch (getAlignment(placement)) {
|
|
178
|
+
case "start":
|
|
179
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
180
|
+
break;
|
|
181
|
+
case "end":
|
|
182
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
return coords;
|
|
186
|
+
}
|
|
187
|
+
async function detectOverflow(state, options) {
|
|
188
|
+
var _await$platform$isEle;
|
|
189
|
+
if (options === void 0) {
|
|
190
|
+
options = {};
|
|
191
|
+
}
|
|
192
|
+
const {
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
platform: platform2,
|
|
196
|
+
rects,
|
|
197
|
+
elements,
|
|
198
|
+
strategy
|
|
199
|
+
} = state;
|
|
200
|
+
const {
|
|
201
|
+
boundary = "clippingAncestors",
|
|
202
|
+
rootBoundary = "viewport",
|
|
203
|
+
elementContext = "floating",
|
|
204
|
+
altBoundary = false,
|
|
205
|
+
padding = 0
|
|
206
|
+
} = evaluate(options, state);
|
|
207
|
+
const paddingObject = getPaddingObject(padding);
|
|
208
|
+
const altContext = elementContext === "floating" ? "reference" : "floating";
|
|
209
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
210
|
+
const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
|
|
211
|
+
element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
|
|
212
|
+
boundary,
|
|
213
|
+
rootBoundary,
|
|
214
|
+
strategy
|
|
215
|
+
}));
|
|
216
|
+
const rect = elementContext === "floating" ? {
|
|
217
|
+
x,
|
|
218
|
+
y,
|
|
219
|
+
width: rects.floating.width,
|
|
220
|
+
height: rects.floating.height
|
|
221
|
+
} : rects.reference;
|
|
222
|
+
const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
|
|
223
|
+
const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
|
|
224
|
+
x: 1,
|
|
225
|
+
y: 1
|
|
226
|
+
} : {
|
|
227
|
+
x: 1,
|
|
228
|
+
y: 1
|
|
229
|
+
};
|
|
230
|
+
const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
231
|
+
elements,
|
|
232
|
+
rect,
|
|
233
|
+
offsetParent,
|
|
234
|
+
strategy
|
|
235
|
+
}) : rect);
|
|
236
|
+
return {
|
|
237
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
238
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
239
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
240
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
var MAX_RESET_COUNT = 50;
|
|
244
|
+
var computePosition = async (reference, floating, config) => {
|
|
245
|
+
const {
|
|
246
|
+
placement = "bottom",
|
|
247
|
+
strategy = "absolute",
|
|
248
|
+
middleware = [],
|
|
249
|
+
platform: platform2
|
|
250
|
+
} = config;
|
|
251
|
+
const platformWithDetectOverflow = platform2.detectOverflow ? platform2 : {
|
|
252
|
+
...platform2,
|
|
253
|
+
detectOverflow
|
|
254
|
+
};
|
|
255
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
|
|
256
|
+
let rects = await platform2.getElementRects({
|
|
257
|
+
reference,
|
|
258
|
+
floating,
|
|
259
|
+
strategy
|
|
260
|
+
});
|
|
261
|
+
let {
|
|
262
|
+
x,
|
|
263
|
+
y
|
|
264
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
265
|
+
let statefulPlacement = placement;
|
|
266
|
+
let resetCount = 0;
|
|
267
|
+
const middlewareData = {};
|
|
268
|
+
for (let i = 0; i < middleware.length; i++) {
|
|
269
|
+
const currentMiddleware = middleware[i];
|
|
270
|
+
if (!currentMiddleware) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const {
|
|
274
|
+
name,
|
|
275
|
+
fn
|
|
276
|
+
} = currentMiddleware;
|
|
277
|
+
const {
|
|
278
|
+
x: nextX,
|
|
279
|
+
y: nextY,
|
|
280
|
+
data,
|
|
281
|
+
reset
|
|
282
|
+
} = await fn({
|
|
283
|
+
x,
|
|
284
|
+
y,
|
|
285
|
+
initialPlacement: placement,
|
|
286
|
+
placement: statefulPlacement,
|
|
287
|
+
strategy,
|
|
288
|
+
middlewareData,
|
|
289
|
+
rects,
|
|
290
|
+
platform: platformWithDetectOverflow,
|
|
291
|
+
elements: {
|
|
292
|
+
reference,
|
|
293
|
+
floating
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
x = nextX != null ? nextX : x;
|
|
297
|
+
y = nextY != null ? nextY : y;
|
|
298
|
+
middlewareData[name] = {
|
|
299
|
+
...middlewareData[name],
|
|
300
|
+
...data
|
|
301
|
+
};
|
|
302
|
+
if (reset && resetCount < MAX_RESET_COUNT) {
|
|
303
|
+
resetCount++;
|
|
304
|
+
if (typeof reset === "object") {
|
|
305
|
+
if (reset.placement) {
|
|
306
|
+
statefulPlacement = reset.placement;
|
|
307
|
+
}
|
|
308
|
+
if (reset.rects) {
|
|
309
|
+
rects = reset.rects === true ? await platform2.getElementRects({
|
|
310
|
+
reference,
|
|
311
|
+
floating,
|
|
312
|
+
strategy
|
|
313
|
+
}) : reset.rects;
|
|
314
|
+
}
|
|
315
|
+
({
|
|
316
|
+
x,
|
|
317
|
+
y
|
|
318
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
319
|
+
}
|
|
320
|
+
i = -1;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
x,
|
|
325
|
+
y,
|
|
326
|
+
placement: statefulPlacement,
|
|
327
|
+
strategy,
|
|
328
|
+
middlewareData
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
var arrow = (options) => ({
|
|
332
|
+
name: "arrow",
|
|
333
|
+
options,
|
|
334
|
+
async fn(state) {
|
|
335
|
+
const {
|
|
336
|
+
x,
|
|
337
|
+
y,
|
|
338
|
+
placement,
|
|
339
|
+
rects,
|
|
340
|
+
platform: platform2,
|
|
341
|
+
elements,
|
|
342
|
+
middlewareData
|
|
343
|
+
} = state;
|
|
344
|
+
const {
|
|
345
|
+
element,
|
|
346
|
+
padding = 0
|
|
347
|
+
} = evaluate(options, state) || {};
|
|
348
|
+
if (element == null) {
|
|
349
|
+
return {};
|
|
350
|
+
}
|
|
351
|
+
const paddingObject = getPaddingObject(padding);
|
|
352
|
+
const coords = {
|
|
353
|
+
x,
|
|
354
|
+
y
|
|
355
|
+
};
|
|
356
|
+
const axis = getAlignmentAxis(placement);
|
|
357
|
+
const length = getAxisLength(axis);
|
|
358
|
+
const arrowDimensions = await platform2.getDimensions(element);
|
|
359
|
+
const isYAxis = axis === "y";
|
|
360
|
+
const minProp = isYAxis ? "top" : "left";
|
|
361
|
+
const maxProp = isYAxis ? "bottom" : "right";
|
|
362
|
+
const clientProp = isYAxis ? "clientHeight" : "clientWidth";
|
|
363
|
+
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
364
|
+
const startDiff = coords[axis] - rects.reference[axis];
|
|
365
|
+
const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element));
|
|
366
|
+
let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
|
|
367
|
+
if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) {
|
|
368
|
+
clientSize = elements.floating[clientProp] || rects.floating[length];
|
|
369
|
+
}
|
|
370
|
+
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
371
|
+
const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
|
|
372
|
+
const minPadding = min(paddingObject[minProp], largestPossiblePadding);
|
|
373
|
+
const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
|
|
374
|
+
const min$1 = minPadding;
|
|
375
|
+
const max2 = clientSize - arrowDimensions[length] - maxPadding;
|
|
376
|
+
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
377
|
+
const offset3 = clamp(min$1, center, max2);
|
|
378
|
+
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset3 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
379
|
+
const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
|
|
380
|
+
return {
|
|
381
|
+
[axis]: coords[axis] + alignmentOffset,
|
|
382
|
+
data: {
|
|
383
|
+
[axis]: offset3,
|
|
384
|
+
centerOffset: center - offset3 - alignmentOffset,
|
|
385
|
+
...shouldAddOffset && {
|
|
386
|
+
alignmentOffset
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
reset: shouldAddOffset
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
var flip = function(options) {
|
|
394
|
+
if (options === void 0) {
|
|
395
|
+
options = {};
|
|
396
|
+
}
|
|
397
|
+
return {
|
|
398
|
+
name: "flip",
|
|
399
|
+
options,
|
|
400
|
+
async fn(state) {
|
|
401
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
402
|
+
const {
|
|
403
|
+
placement,
|
|
404
|
+
middlewareData,
|
|
405
|
+
rects,
|
|
406
|
+
initialPlacement,
|
|
407
|
+
platform: platform2,
|
|
408
|
+
elements
|
|
409
|
+
} = state;
|
|
410
|
+
const {
|
|
411
|
+
mainAxis: checkMainAxis = true,
|
|
412
|
+
crossAxis: checkCrossAxis = true,
|
|
413
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
414
|
+
fallbackStrategy = "bestFit",
|
|
415
|
+
fallbackAxisSideDirection = "none",
|
|
416
|
+
flipAlignment = true,
|
|
417
|
+
...detectOverflowOptions
|
|
418
|
+
} = evaluate(options, state);
|
|
419
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
const side = getSide(placement);
|
|
423
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
424
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
425
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
426
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
427
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
|
|
428
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
429
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
430
|
+
}
|
|
431
|
+
const placements2 = [initialPlacement, ...fallbackPlacements];
|
|
432
|
+
const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
|
|
433
|
+
const overflows = [];
|
|
434
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
435
|
+
if (checkMainAxis) {
|
|
436
|
+
overflows.push(overflow[side]);
|
|
437
|
+
}
|
|
438
|
+
if (checkCrossAxis) {
|
|
439
|
+
const sides2 = getAlignmentSides(placement, rects, rtl);
|
|
440
|
+
overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
|
|
441
|
+
}
|
|
442
|
+
overflowsData = [...overflowsData, {
|
|
443
|
+
placement,
|
|
444
|
+
overflows
|
|
445
|
+
}];
|
|
446
|
+
if (!overflows.every((side2) => side2 <= 0)) {
|
|
447
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
448
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
449
|
+
const nextPlacement = placements2[nextIndex];
|
|
450
|
+
if (nextPlacement) {
|
|
451
|
+
const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
|
|
452
|
+
if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
|
|
453
|
+
// overflows the main axis.
|
|
454
|
+
overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
|
|
455
|
+
return {
|
|
456
|
+
data: {
|
|
457
|
+
index: nextIndex,
|
|
458
|
+
overflows: overflowsData
|
|
459
|
+
},
|
|
460
|
+
reset: {
|
|
461
|
+
placement: nextPlacement
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
467
|
+
if (!resetPlacement) {
|
|
468
|
+
switch (fallbackStrategy) {
|
|
469
|
+
case "bestFit": {
|
|
470
|
+
var _overflowsData$filter2;
|
|
471
|
+
const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
|
|
472
|
+
if (hasFallbackAxisSideDirection) {
|
|
473
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
474
|
+
return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
|
|
475
|
+
// reading directions favoring greater width.
|
|
476
|
+
currentSideAxis === "y";
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
|
|
480
|
+
if (placement2) {
|
|
481
|
+
resetPlacement = placement2;
|
|
482
|
+
}
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
case "initialPlacement":
|
|
486
|
+
resetPlacement = initialPlacement;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (placement !== resetPlacement) {
|
|
491
|
+
return {
|
|
492
|
+
reset: {
|
|
493
|
+
placement: resetPlacement
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return {};
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
var originSides = /* @__PURE__ */ new Set(["left", "top"]);
|
|
503
|
+
async function convertValueToCoords(state, options) {
|
|
504
|
+
const {
|
|
505
|
+
placement,
|
|
506
|
+
platform: platform2,
|
|
507
|
+
elements
|
|
508
|
+
} = state;
|
|
509
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
510
|
+
const side = getSide(placement);
|
|
511
|
+
const alignment = getAlignment(placement);
|
|
512
|
+
const isVertical = getSideAxis(placement) === "y";
|
|
513
|
+
const mainAxisMulti = originSides.has(side) ? -1 : 1;
|
|
514
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
515
|
+
const rawValue = evaluate(options, state);
|
|
516
|
+
let {
|
|
517
|
+
mainAxis,
|
|
518
|
+
crossAxis,
|
|
519
|
+
alignmentAxis
|
|
520
|
+
} = typeof rawValue === "number" ? {
|
|
521
|
+
mainAxis: rawValue,
|
|
522
|
+
crossAxis: 0,
|
|
523
|
+
alignmentAxis: null
|
|
524
|
+
} : {
|
|
525
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
526
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
527
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
528
|
+
};
|
|
529
|
+
if (alignment && typeof alignmentAxis === "number") {
|
|
530
|
+
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
|
|
531
|
+
}
|
|
532
|
+
return isVertical ? {
|
|
533
|
+
x: crossAxis * crossAxisMulti,
|
|
534
|
+
y: mainAxis * mainAxisMulti
|
|
535
|
+
} : {
|
|
536
|
+
x: mainAxis * mainAxisMulti,
|
|
537
|
+
y: crossAxis * crossAxisMulti
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
var offset = function(options) {
|
|
541
|
+
if (options === void 0) {
|
|
542
|
+
options = 0;
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
name: "offset",
|
|
546
|
+
options,
|
|
547
|
+
async fn(state) {
|
|
548
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
549
|
+
const {
|
|
550
|
+
x,
|
|
551
|
+
y,
|
|
552
|
+
placement,
|
|
553
|
+
middlewareData
|
|
554
|
+
} = state;
|
|
555
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
556
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
557
|
+
return {};
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
x: x + diffCoords.x,
|
|
561
|
+
y: y + diffCoords.y,
|
|
562
|
+
data: {
|
|
563
|
+
...diffCoords,
|
|
564
|
+
placement
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
};
|
|
570
|
+
var shift = function(options) {
|
|
571
|
+
if (options === void 0) {
|
|
572
|
+
options = {};
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
name: "shift",
|
|
576
|
+
options,
|
|
577
|
+
async fn(state) {
|
|
578
|
+
const {
|
|
579
|
+
x,
|
|
580
|
+
y,
|
|
581
|
+
placement,
|
|
582
|
+
platform: platform2
|
|
583
|
+
} = state;
|
|
584
|
+
const {
|
|
585
|
+
mainAxis: checkMainAxis = true,
|
|
586
|
+
crossAxis: checkCrossAxis = false,
|
|
587
|
+
limiter = {
|
|
588
|
+
fn: (_ref) => {
|
|
589
|
+
let {
|
|
590
|
+
x: x2,
|
|
591
|
+
y: y2
|
|
592
|
+
} = _ref;
|
|
593
|
+
return {
|
|
594
|
+
x: x2,
|
|
595
|
+
y: y2
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
...detectOverflowOptions
|
|
600
|
+
} = evaluate(options, state);
|
|
601
|
+
const coords = {
|
|
602
|
+
x,
|
|
603
|
+
y
|
|
604
|
+
};
|
|
605
|
+
const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
|
|
606
|
+
const crossAxis = getSideAxis(getSide(placement));
|
|
607
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
608
|
+
let mainAxisCoord = coords[mainAxis];
|
|
609
|
+
let crossAxisCoord = coords[crossAxis];
|
|
610
|
+
if (checkMainAxis) {
|
|
611
|
+
const minSide = mainAxis === "y" ? "top" : "left";
|
|
612
|
+
const maxSide = mainAxis === "y" ? "bottom" : "right";
|
|
613
|
+
const min2 = mainAxisCoord + overflow[minSide];
|
|
614
|
+
const max2 = mainAxisCoord - overflow[maxSide];
|
|
615
|
+
mainAxisCoord = clamp(min2, mainAxisCoord, max2);
|
|
616
|
+
}
|
|
617
|
+
if (checkCrossAxis) {
|
|
618
|
+
const minSide = crossAxis === "y" ? "top" : "left";
|
|
619
|
+
const maxSide = crossAxis === "y" ? "bottom" : "right";
|
|
620
|
+
const min2 = crossAxisCoord + overflow[minSide];
|
|
621
|
+
const max2 = crossAxisCoord - overflow[maxSide];
|
|
622
|
+
crossAxisCoord = clamp(min2, crossAxisCoord, max2);
|
|
623
|
+
}
|
|
624
|
+
const limitedCoords = limiter.fn({
|
|
625
|
+
...state,
|
|
626
|
+
[mainAxis]: mainAxisCoord,
|
|
627
|
+
[crossAxis]: crossAxisCoord
|
|
628
|
+
});
|
|
629
|
+
return {
|
|
630
|
+
...limitedCoords,
|
|
631
|
+
data: {
|
|
632
|
+
x: limitedCoords.x - x,
|
|
633
|
+
y: limitedCoords.y - y,
|
|
634
|
+
enabled: {
|
|
635
|
+
[mainAxis]: checkMainAxis,
|
|
636
|
+
[crossAxis]: checkCrossAxis
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
|
|
645
|
+
function hasWindow() {
|
|
646
|
+
return typeof window !== "undefined";
|
|
647
|
+
}
|
|
648
|
+
function getNodeName(node) {
|
|
649
|
+
if (isNode(node)) {
|
|
650
|
+
return (node.nodeName || "").toLowerCase();
|
|
651
|
+
}
|
|
652
|
+
return "#document";
|
|
653
|
+
}
|
|
654
|
+
function getWindow(node) {
|
|
655
|
+
var _node$ownerDocument;
|
|
656
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
657
|
+
}
|
|
658
|
+
function getDocumentElement(node) {
|
|
659
|
+
var _ref;
|
|
660
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
661
|
+
}
|
|
662
|
+
function isNode(value) {
|
|
663
|
+
if (!hasWindow()) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
667
|
+
}
|
|
668
|
+
function isElement(value) {
|
|
669
|
+
if (!hasWindow()) {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
673
|
+
}
|
|
674
|
+
function isHTMLElement(value) {
|
|
675
|
+
if (!hasWindow()) {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
679
|
+
}
|
|
680
|
+
function isShadowRoot(value) {
|
|
681
|
+
if (!hasWindow() || typeof ShadowRoot === "undefined") {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
685
|
+
}
|
|
686
|
+
function isOverflowElement(element) {
|
|
687
|
+
const {
|
|
688
|
+
overflow,
|
|
689
|
+
overflowX,
|
|
690
|
+
overflowY,
|
|
691
|
+
display
|
|
692
|
+
} = getComputedStyle2(element);
|
|
693
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== "inline" && display !== "contents";
|
|
694
|
+
}
|
|
695
|
+
function isTableElement(element) {
|
|
696
|
+
return /^(table|td|th)$/.test(getNodeName(element));
|
|
697
|
+
}
|
|
698
|
+
function isTopLayer(element) {
|
|
699
|
+
try {
|
|
700
|
+
if (element.matches(":popover-open")) {
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
} catch (_e) {
|
|
704
|
+
}
|
|
705
|
+
try {
|
|
706
|
+
return element.matches(":modal");
|
|
707
|
+
} catch (_e) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
var willChangeRe = /transform|translate|scale|rotate|perspective|filter/;
|
|
712
|
+
var containRe = /paint|layout|strict|content/;
|
|
713
|
+
var isNotNone = (value) => !!value && value !== "none";
|
|
714
|
+
var isWebKitValue;
|
|
715
|
+
function isContainingBlock(elementOrCss) {
|
|
716
|
+
const css = isElement(elementOrCss) ? getComputedStyle2(elementOrCss) : elementOrCss;
|
|
717
|
+
return isNotNone(css.transform) || isNotNone(css.translate) || isNotNone(css.scale) || isNotNone(css.rotate) || isNotNone(css.perspective) || !isWebKit() && (isNotNone(css.backdropFilter) || isNotNone(css.filter)) || willChangeRe.test(css.willChange || "") || containRe.test(css.contain || "");
|
|
718
|
+
}
|
|
719
|
+
function getContainingBlock(element) {
|
|
720
|
+
let currentNode = getParentNode(element);
|
|
721
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
722
|
+
if (isContainingBlock(currentNode)) {
|
|
723
|
+
return currentNode;
|
|
724
|
+
} else if (isTopLayer(currentNode)) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
currentNode = getParentNode(currentNode);
|
|
728
|
+
}
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
function isWebKit() {
|
|
732
|
+
if (isWebKitValue == null) {
|
|
733
|
+
isWebKitValue = typeof CSS !== "undefined" && CSS.supports && CSS.supports("-webkit-backdrop-filter", "none");
|
|
734
|
+
}
|
|
735
|
+
return isWebKitValue;
|
|
736
|
+
}
|
|
737
|
+
function isLastTraversableNode(node) {
|
|
738
|
+
return /^(html|body|#document)$/.test(getNodeName(node));
|
|
739
|
+
}
|
|
740
|
+
function getComputedStyle2(element) {
|
|
741
|
+
return getWindow(element).getComputedStyle(element);
|
|
742
|
+
}
|
|
743
|
+
function getNodeScroll(element) {
|
|
744
|
+
if (isElement(element)) {
|
|
745
|
+
return {
|
|
746
|
+
scrollLeft: element.scrollLeft,
|
|
747
|
+
scrollTop: element.scrollTop
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
scrollLeft: element.scrollX,
|
|
752
|
+
scrollTop: element.scrollY
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
function getParentNode(node) {
|
|
756
|
+
if (getNodeName(node) === "html") {
|
|
757
|
+
return node;
|
|
758
|
+
}
|
|
759
|
+
const result = (
|
|
760
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
761
|
+
node.assignedSlot || // DOM Element detected.
|
|
762
|
+
node.parentNode || // ShadowRoot detected.
|
|
763
|
+
isShadowRoot(node) && node.host || // Fallback.
|
|
764
|
+
getDocumentElement(node)
|
|
765
|
+
);
|
|
766
|
+
return isShadowRoot(result) ? result.host : result;
|
|
767
|
+
}
|
|
768
|
+
function getNearestOverflowAncestor(node) {
|
|
769
|
+
const parentNode = getParentNode(node);
|
|
770
|
+
if (isLastTraversableNode(parentNode)) {
|
|
771
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
772
|
+
}
|
|
773
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
774
|
+
return parentNode;
|
|
775
|
+
}
|
|
776
|
+
return getNearestOverflowAncestor(parentNode);
|
|
777
|
+
}
|
|
778
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
779
|
+
var _node$ownerDocument2;
|
|
780
|
+
if (list === void 0) {
|
|
781
|
+
list = [];
|
|
782
|
+
}
|
|
783
|
+
if (traverseIframes === void 0) {
|
|
784
|
+
traverseIframes = true;
|
|
785
|
+
}
|
|
786
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
787
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
788
|
+
const win = getWindow(scrollableAncestor);
|
|
789
|
+
if (isBody) {
|
|
790
|
+
const frameElement = getFrameElement(win);
|
|
791
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
792
|
+
} else {
|
|
793
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function getFrameElement(win) {
|
|
797
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
|
|
801
|
+
function getCssDimensions(element) {
|
|
802
|
+
const css = getComputedStyle2(element);
|
|
803
|
+
let width = parseFloat(css.width) || 0;
|
|
804
|
+
let height = parseFloat(css.height) || 0;
|
|
805
|
+
const hasOffset = isHTMLElement(element);
|
|
806
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
807
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
808
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
809
|
+
if (shouldFallback) {
|
|
810
|
+
width = offsetWidth;
|
|
811
|
+
height = offsetHeight;
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
width,
|
|
815
|
+
height,
|
|
816
|
+
$: shouldFallback
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function unwrapElement(element) {
|
|
820
|
+
return !isElement(element) ? element.contextElement : element;
|
|
821
|
+
}
|
|
822
|
+
function getScale(element) {
|
|
823
|
+
const domElement = unwrapElement(element);
|
|
824
|
+
if (!isHTMLElement(domElement)) {
|
|
825
|
+
return createCoords(1);
|
|
826
|
+
}
|
|
827
|
+
const rect = domElement.getBoundingClientRect();
|
|
828
|
+
const {
|
|
829
|
+
width,
|
|
830
|
+
height,
|
|
831
|
+
$
|
|
832
|
+
} = getCssDimensions(domElement);
|
|
833
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
834
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
835
|
+
if (!x || !Number.isFinite(x)) {
|
|
836
|
+
x = 1;
|
|
837
|
+
}
|
|
838
|
+
if (!y || !Number.isFinite(y)) {
|
|
839
|
+
y = 1;
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
x,
|
|
843
|
+
y
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
var noOffsets = /* @__PURE__ */ createCoords(0);
|
|
847
|
+
function getVisualOffsets(element) {
|
|
848
|
+
const win = getWindow(element);
|
|
849
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
850
|
+
return noOffsets;
|
|
851
|
+
}
|
|
852
|
+
return {
|
|
853
|
+
x: win.visualViewport.offsetLeft,
|
|
854
|
+
y: win.visualViewport.offsetTop
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
858
|
+
if (isFixed === void 0) {
|
|
859
|
+
isFixed = false;
|
|
860
|
+
}
|
|
861
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
return isFixed;
|
|
865
|
+
}
|
|
866
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
867
|
+
if (includeScale === void 0) {
|
|
868
|
+
includeScale = false;
|
|
869
|
+
}
|
|
870
|
+
if (isFixedStrategy === void 0) {
|
|
871
|
+
isFixedStrategy = false;
|
|
872
|
+
}
|
|
873
|
+
const clientRect = element.getBoundingClientRect();
|
|
874
|
+
const domElement = unwrapElement(element);
|
|
875
|
+
let scale = createCoords(1);
|
|
876
|
+
if (includeScale) {
|
|
877
|
+
if (offsetParent) {
|
|
878
|
+
if (isElement(offsetParent)) {
|
|
879
|
+
scale = getScale(offsetParent);
|
|
880
|
+
}
|
|
881
|
+
} else {
|
|
882
|
+
scale = getScale(element);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
886
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
887
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
888
|
+
let width = clientRect.width / scale.x;
|
|
889
|
+
let height = clientRect.height / scale.y;
|
|
890
|
+
if (domElement) {
|
|
891
|
+
const win = getWindow(domElement);
|
|
892
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
893
|
+
let currentWin = win;
|
|
894
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
895
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
896
|
+
const iframeScale = getScale(currentIFrame);
|
|
897
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
898
|
+
const css = getComputedStyle2(currentIFrame);
|
|
899
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
900
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
901
|
+
x *= iframeScale.x;
|
|
902
|
+
y *= iframeScale.y;
|
|
903
|
+
width *= iframeScale.x;
|
|
904
|
+
height *= iframeScale.y;
|
|
905
|
+
x += left;
|
|
906
|
+
y += top;
|
|
907
|
+
currentWin = getWindow(currentIFrame);
|
|
908
|
+
currentIFrame = getFrameElement(currentWin);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return rectToClientRect({
|
|
912
|
+
width,
|
|
913
|
+
height,
|
|
914
|
+
x,
|
|
915
|
+
y
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function getWindowScrollBarX(element, rect) {
|
|
919
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
920
|
+
if (!rect) {
|
|
921
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
922
|
+
}
|
|
923
|
+
return rect.left + leftScroll;
|
|
924
|
+
}
|
|
925
|
+
function getHTMLOffset(documentElement, scroll) {
|
|
926
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
927
|
+
const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
|
|
928
|
+
const y = htmlRect.top + scroll.scrollTop;
|
|
929
|
+
return {
|
|
930
|
+
x,
|
|
931
|
+
y
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
935
|
+
let {
|
|
936
|
+
elements,
|
|
937
|
+
rect,
|
|
938
|
+
offsetParent,
|
|
939
|
+
strategy
|
|
940
|
+
} = _ref;
|
|
941
|
+
const isFixed = strategy === "fixed";
|
|
942
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
943
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
944
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
945
|
+
return rect;
|
|
946
|
+
}
|
|
947
|
+
let scroll = {
|
|
948
|
+
scrollLeft: 0,
|
|
949
|
+
scrollTop: 0
|
|
950
|
+
};
|
|
951
|
+
let scale = createCoords(1);
|
|
952
|
+
const offsets = createCoords(0);
|
|
953
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
954
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
955
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
956
|
+
scroll = getNodeScroll(offsetParent);
|
|
957
|
+
}
|
|
958
|
+
if (isOffsetParentAnElement) {
|
|
959
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
960
|
+
scale = getScale(offsetParent);
|
|
961
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
962
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
966
|
+
return {
|
|
967
|
+
width: rect.width * scale.x,
|
|
968
|
+
height: rect.height * scale.y,
|
|
969
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
|
|
970
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function getClientRects(element) {
|
|
974
|
+
return Array.from(element.getClientRects());
|
|
975
|
+
}
|
|
976
|
+
function getDocumentRect(element) {
|
|
977
|
+
const html = getDocumentElement(element);
|
|
978
|
+
const scroll = getNodeScroll(element);
|
|
979
|
+
const body = element.ownerDocument.body;
|
|
980
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
981
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
982
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
983
|
+
const y = -scroll.scrollTop;
|
|
984
|
+
if (getComputedStyle2(body).direction === "rtl") {
|
|
985
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
986
|
+
}
|
|
987
|
+
return {
|
|
988
|
+
width,
|
|
989
|
+
height,
|
|
990
|
+
x,
|
|
991
|
+
y
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
var SCROLLBAR_MAX = 25;
|
|
995
|
+
function getViewportRect(element, strategy) {
|
|
996
|
+
const win = getWindow(element);
|
|
997
|
+
const html = getDocumentElement(element);
|
|
998
|
+
const visualViewport = win.visualViewport;
|
|
999
|
+
let width = html.clientWidth;
|
|
1000
|
+
let height = html.clientHeight;
|
|
1001
|
+
let x = 0;
|
|
1002
|
+
let y = 0;
|
|
1003
|
+
if (visualViewport) {
|
|
1004
|
+
width = visualViewport.width;
|
|
1005
|
+
height = visualViewport.height;
|
|
1006
|
+
const visualViewportBased = isWebKit();
|
|
1007
|
+
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
|
|
1008
|
+
x = visualViewport.offsetLeft;
|
|
1009
|
+
y = visualViewport.offsetTop;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
const windowScrollbarX = getWindowScrollBarX(html);
|
|
1013
|
+
if (windowScrollbarX <= 0) {
|
|
1014
|
+
const doc = html.ownerDocument;
|
|
1015
|
+
const body = doc.body;
|
|
1016
|
+
const bodyStyles = getComputedStyle(body);
|
|
1017
|
+
const bodyMarginInline = doc.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
|
|
1018
|
+
const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
|
|
1019
|
+
if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
|
|
1020
|
+
width -= clippingStableScrollbarWidth;
|
|
1021
|
+
}
|
|
1022
|
+
} else if (windowScrollbarX <= SCROLLBAR_MAX) {
|
|
1023
|
+
width += windowScrollbarX;
|
|
1024
|
+
}
|
|
1025
|
+
return {
|
|
1026
|
+
width,
|
|
1027
|
+
height,
|
|
1028
|
+
x,
|
|
1029
|
+
y
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
1033
|
+
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
|
1034
|
+
const top = clientRect.top + element.clientTop;
|
|
1035
|
+
const left = clientRect.left + element.clientLeft;
|
|
1036
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
1037
|
+
const width = element.clientWidth * scale.x;
|
|
1038
|
+
const height = element.clientHeight * scale.y;
|
|
1039
|
+
const x = left * scale.x;
|
|
1040
|
+
const y = top * scale.y;
|
|
1041
|
+
return {
|
|
1042
|
+
width,
|
|
1043
|
+
height,
|
|
1044
|
+
x,
|
|
1045
|
+
y
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
1049
|
+
let rect;
|
|
1050
|
+
if (clippingAncestor === "viewport") {
|
|
1051
|
+
rect = getViewportRect(element, strategy);
|
|
1052
|
+
} else if (clippingAncestor === "document") {
|
|
1053
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
1054
|
+
} else if (isElement(clippingAncestor)) {
|
|
1055
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
1056
|
+
} else {
|
|
1057
|
+
const visualOffsets = getVisualOffsets(element);
|
|
1058
|
+
rect = {
|
|
1059
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
1060
|
+
y: clippingAncestor.y - visualOffsets.y,
|
|
1061
|
+
width: clippingAncestor.width,
|
|
1062
|
+
height: clippingAncestor.height
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
return rectToClientRect(rect);
|
|
1066
|
+
}
|
|
1067
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
1068
|
+
const parentNode = getParentNode(element);
|
|
1069
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
return getComputedStyle2(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1073
|
+
}
|
|
1074
|
+
function getClippingElementAncestors(element, cache) {
|
|
1075
|
+
const cachedResult = cache.get(element);
|
|
1076
|
+
if (cachedResult) {
|
|
1077
|
+
return cachedResult;
|
|
1078
|
+
}
|
|
1079
|
+
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
1080
|
+
let currentContainingBlockComputedStyle = null;
|
|
1081
|
+
const elementIsFixed = getComputedStyle2(element).position === "fixed";
|
|
1082
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
1083
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1084
|
+
const computedStyle = getComputedStyle2(currentNode);
|
|
1085
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
1086
|
+
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
|
1087
|
+
currentContainingBlockComputedStyle = null;
|
|
1088
|
+
}
|
|
1089
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === "absolute" || currentContainingBlockComputedStyle.position === "fixed") || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
1090
|
+
if (shouldDropCurrentNode) {
|
|
1091
|
+
result = result.filter((ancestor) => ancestor !== currentNode);
|
|
1092
|
+
} else {
|
|
1093
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
1094
|
+
}
|
|
1095
|
+
currentNode = getParentNode(currentNode);
|
|
1096
|
+
}
|
|
1097
|
+
cache.set(element, result);
|
|
1098
|
+
return result;
|
|
1099
|
+
}
|
|
1100
|
+
function getClippingRect(_ref) {
|
|
1101
|
+
let {
|
|
1102
|
+
element,
|
|
1103
|
+
boundary,
|
|
1104
|
+
rootBoundary,
|
|
1105
|
+
strategy
|
|
1106
|
+
} = _ref;
|
|
1107
|
+
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
1108
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
1109
|
+
const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
|
|
1110
|
+
let top = firstRect.top;
|
|
1111
|
+
let right = firstRect.right;
|
|
1112
|
+
let bottom = firstRect.bottom;
|
|
1113
|
+
let left = firstRect.left;
|
|
1114
|
+
for (let i = 1; i < clippingAncestors.length; i++) {
|
|
1115
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
|
|
1116
|
+
top = max(rect.top, top);
|
|
1117
|
+
right = min(rect.right, right);
|
|
1118
|
+
bottom = min(rect.bottom, bottom);
|
|
1119
|
+
left = max(rect.left, left);
|
|
1120
|
+
}
|
|
1121
|
+
return {
|
|
1122
|
+
width: right - left,
|
|
1123
|
+
height: bottom - top,
|
|
1124
|
+
x: left,
|
|
1125
|
+
y: top
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function getDimensions(element) {
|
|
1129
|
+
const {
|
|
1130
|
+
width,
|
|
1131
|
+
height
|
|
1132
|
+
} = getCssDimensions(element);
|
|
1133
|
+
return {
|
|
1134
|
+
width,
|
|
1135
|
+
height
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
1139
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1140
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1141
|
+
const isFixed = strategy === "fixed";
|
|
1142
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
1143
|
+
let scroll = {
|
|
1144
|
+
scrollLeft: 0,
|
|
1145
|
+
scrollTop: 0
|
|
1146
|
+
};
|
|
1147
|
+
const offsets = createCoords(0);
|
|
1148
|
+
function setLeftRTLScrollbarOffset() {
|
|
1149
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
1150
|
+
}
|
|
1151
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1152
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
1153
|
+
scroll = getNodeScroll(offsetParent);
|
|
1154
|
+
}
|
|
1155
|
+
if (isOffsetParentAnElement) {
|
|
1156
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
1157
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1158
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1159
|
+
} else if (documentElement) {
|
|
1160
|
+
setLeftRTLScrollbarOffset();
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
if (isFixed && !isOffsetParentAnElement && documentElement) {
|
|
1164
|
+
setLeftRTLScrollbarOffset();
|
|
1165
|
+
}
|
|
1166
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
1167
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
|
|
1168
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
|
|
1169
|
+
return {
|
|
1170
|
+
x,
|
|
1171
|
+
y,
|
|
1172
|
+
width: rect.width,
|
|
1173
|
+
height: rect.height
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
function isStaticPositioned(element) {
|
|
1177
|
+
return getComputedStyle2(element).position === "static";
|
|
1178
|
+
}
|
|
1179
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
1180
|
+
if (!isHTMLElement(element) || getComputedStyle2(element).position === "fixed") {
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
if (polyfill) {
|
|
1184
|
+
return polyfill(element);
|
|
1185
|
+
}
|
|
1186
|
+
let rawOffsetParent = element.offsetParent;
|
|
1187
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
1188
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
1189
|
+
}
|
|
1190
|
+
return rawOffsetParent;
|
|
1191
|
+
}
|
|
1192
|
+
function getOffsetParent(element, polyfill) {
|
|
1193
|
+
const win = getWindow(element);
|
|
1194
|
+
if (isTopLayer(element)) {
|
|
1195
|
+
return win;
|
|
1196
|
+
}
|
|
1197
|
+
if (!isHTMLElement(element)) {
|
|
1198
|
+
let svgOffsetParent = getParentNode(element);
|
|
1199
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
1200
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
1201
|
+
return svgOffsetParent;
|
|
1202
|
+
}
|
|
1203
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
1204
|
+
}
|
|
1205
|
+
return win;
|
|
1206
|
+
}
|
|
1207
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
1208
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
1209
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
1210
|
+
}
|
|
1211
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
1212
|
+
return win;
|
|
1213
|
+
}
|
|
1214
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
1215
|
+
}
|
|
1216
|
+
var getElementRects = async function(data) {
|
|
1217
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
1218
|
+
const getDimensionsFn = this.getDimensions;
|
|
1219
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
1220
|
+
return {
|
|
1221
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
1222
|
+
floating: {
|
|
1223
|
+
x: 0,
|
|
1224
|
+
y: 0,
|
|
1225
|
+
width: floatingDimensions.width,
|
|
1226
|
+
height: floatingDimensions.height
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
};
|
|
1230
|
+
function isRTL(element) {
|
|
1231
|
+
return getComputedStyle2(element).direction === "rtl";
|
|
1232
|
+
}
|
|
1233
|
+
var platform = {
|
|
1234
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
1235
|
+
getDocumentElement,
|
|
1236
|
+
getClippingRect,
|
|
1237
|
+
getOffsetParent,
|
|
1238
|
+
getElementRects,
|
|
1239
|
+
getClientRects,
|
|
1240
|
+
getDimensions,
|
|
1241
|
+
getScale,
|
|
1242
|
+
isElement,
|
|
1243
|
+
isRTL
|
|
1244
|
+
};
|
|
1245
|
+
function rectsAreEqual(a, b) {
|
|
1246
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
1247
|
+
}
|
|
1248
|
+
function observeMove(element, onMove) {
|
|
1249
|
+
let io = null;
|
|
1250
|
+
let timeoutId;
|
|
1251
|
+
const root = getDocumentElement(element);
|
|
1252
|
+
function cleanup() {
|
|
1253
|
+
var _io;
|
|
1254
|
+
clearTimeout(timeoutId);
|
|
1255
|
+
(_io = io) == null || _io.disconnect();
|
|
1256
|
+
io = null;
|
|
1257
|
+
}
|
|
1258
|
+
function refresh(skip, threshold) {
|
|
1259
|
+
if (skip === void 0) {
|
|
1260
|
+
skip = false;
|
|
1261
|
+
}
|
|
1262
|
+
if (threshold === void 0) {
|
|
1263
|
+
threshold = 1;
|
|
1264
|
+
}
|
|
1265
|
+
cleanup();
|
|
1266
|
+
const elementRectForRootMargin = element.getBoundingClientRect();
|
|
1267
|
+
const {
|
|
1268
|
+
left,
|
|
1269
|
+
top,
|
|
1270
|
+
width,
|
|
1271
|
+
height
|
|
1272
|
+
} = elementRectForRootMargin;
|
|
1273
|
+
if (!skip) {
|
|
1274
|
+
onMove();
|
|
1275
|
+
}
|
|
1276
|
+
if (!width || !height) {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
const insetTop = floor(top);
|
|
1280
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
1281
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
1282
|
+
const insetLeft = floor(left);
|
|
1283
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
1284
|
+
const options = {
|
|
1285
|
+
rootMargin,
|
|
1286
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
1287
|
+
};
|
|
1288
|
+
let isFirstUpdate = true;
|
|
1289
|
+
function handleObserve(entries) {
|
|
1290
|
+
const ratio = entries[0].intersectionRatio;
|
|
1291
|
+
if (ratio !== threshold) {
|
|
1292
|
+
if (!isFirstUpdate) {
|
|
1293
|
+
return refresh();
|
|
1294
|
+
}
|
|
1295
|
+
if (!ratio) {
|
|
1296
|
+
timeoutId = setTimeout(() => {
|
|
1297
|
+
refresh(false, 1e-7);
|
|
1298
|
+
}, 1e3);
|
|
1299
|
+
} else {
|
|
1300
|
+
refresh(false, ratio);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
|
|
1304
|
+
refresh();
|
|
1305
|
+
}
|
|
1306
|
+
isFirstUpdate = false;
|
|
1307
|
+
}
|
|
1308
|
+
try {
|
|
1309
|
+
io = new IntersectionObserver(handleObserve, {
|
|
1310
|
+
...options,
|
|
1311
|
+
// Handle <iframe>s
|
|
1312
|
+
root: root.ownerDocument
|
|
1313
|
+
});
|
|
1314
|
+
} catch (_e) {
|
|
1315
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
1316
|
+
}
|
|
1317
|
+
io.observe(element);
|
|
1318
|
+
}
|
|
1319
|
+
refresh(true);
|
|
1320
|
+
return cleanup;
|
|
1321
|
+
}
|
|
1322
|
+
function autoUpdate(reference, floating, update, options) {
|
|
1323
|
+
if (options === void 0) {
|
|
1324
|
+
options = {};
|
|
1325
|
+
}
|
|
1326
|
+
const {
|
|
1327
|
+
ancestorScroll = true,
|
|
1328
|
+
ancestorResize = true,
|
|
1329
|
+
elementResize = typeof ResizeObserver === "function",
|
|
1330
|
+
layoutShift = typeof IntersectionObserver === "function",
|
|
1331
|
+
animationFrame = false
|
|
1332
|
+
} = options;
|
|
1333
|
+
const referenceEl = unwrapElement(reference);
|
|
1334
|
+
const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...floating ? getOverflowAncestors(floating) : []] : [];
|
|
1335
|
+
ancestors.forEach((ancestor) => {
|
|
1336
|
+
ancestorScroll && ancestor.addEventListener("scroll", update, {
|
|
1337
|
+
passive: true
|
|
1338
|
+
});
|
|
1339
|
+
ancestorResize && ancestor.addEventListener("resize", update);
|
|
1340
|
+
});
|
|
1341
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
1342
|
+
let reobserveFrame = -1;
|
|
1343
|
+
let resizeObserver = null;
|
|
1344
|
+
if (elementResize) {
|
|
1345
|
+
resizeObserver = new ResizeObserver((_ref) => {
|
|
1346
|
+
let [firstEntry] = _ref;
|
|
1347
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
|
|
1348
|
+
resizeObserver.unobserve(floating);
|
|
1349
|
+
cancelAnimationFrame(reobserveFrame);
|
|
1350
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
1351
|
+
var _resizeObserver;
|
|
1352
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
update();
|
|
1356
|
+
});
|
|
1357
|
+
if (referenceEl && !animationFrame) {
|
|
1358
|
+
resizeObserver.observe(referenceEl);
|
|
1359
|
+
}
|
|
1360
|
+
if (floating) {
|
|
1361
|
+
resizeObserver.observe(floating);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
let frameId;
|
|
1365
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
1366
|
+
if (animationFrame) {
|
|
1367
|
+
frameLoop();
|
|
1368
|
+
}
|
|
1369
|
+
function frameLoop() {
|
|
1370
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
1371
|
+
if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
|
|
1372
|
+
update();
|
|
1373
|
+
}
|
|
1374
|
+
prevRefRect = nextRefRect;
|
|
1375
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
1376
|
+
}
|
|
1377
|
+
update();
|
|
1378
|
+
return () => {
|
|
1379
|
+
var _resizeObserver2;
|
|
1380
|
+
ancestors.forEach((ancestor) => {
|
|
1381
|
+
ancestorScroll && ancestor.removeEventListener("scroll", update);
|
|
1382
|
+
ancestorResize && ancestor.removeEventListener("resize", update);
|
|
1383
|
+
});
|
|
1384
|
+
cleanupIo == null || cleanupIo();
|
|
1385
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
1386
|
+
resizeObserver = null;
|
|
1387
|
+
if (animationFrame) {
|
|
1388
|
+
cancelAnimationFrame(frameId);
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
var offset2 = offset;
|
|
1393
|
+
var shift2 = shift;
|
|
1394
|
+
var flip2 = flip;
|
|
1395
|
+
var arrow2 = arrow;
|
|
1396
|
+
var computePosition2 = (reference, floating, options) => {
|
|
1397
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1398
|
+
const mergedOptions = {
|
|
1399
|
+
platform,
|
|
1400
|
+
...options
|
|
1401
|
+
};
|
|
1402
|
+
const platformWithCache = {
|
|
1403
|
+
...mergedOptions.platform,
|
|
1404
|
+
_c: cache
|
|
1405
|
+
};
|
|
1406
|
+
return computePosition(reference, floating, {
|
|
1407
|
+
...mergedOptions,
|
|
1408
|
+
platform: platformWithCache
|
|
1409
|
+
});
|
|
1410
|
+
};
|
|
1411
|
+
|
|
1412
|
+
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
1413
|
+
var defaultParser = (value) => value.split(/\s+/);
|
|
1414
|
+
var defaultSerializer = (tokens) => tokens.join(" ");
|
|
1415
|
+
function addTokenToAttribute(element, attribute, token, options = {}) {
|
|
1416
|
+
const {
|
|
1417
|
+
caseInsensitive = false,
|
|
1418
|
+
parse = defaultParser,
|
|
1419
|
+
serialize = defaultSerializer
|
|
1420
|
+
} = options;
|
|
1421
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
1422
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
1423
|
+
if (caseInsensitive) {
|
|
1424
|
+
const lower = token.toLowerCase();
|
|
1425
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
tokens.push(token);
|
|
1429
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const set = new Set(tokens);
|
|
1433
|
+
set.add(token);
|
|
1434
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
1435
|
+
}
|
|
1436
|
+
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
1437
|
+
function restoreAttributes(elements) {
|
|
1438
|
+
for (const element of elements) {
|
|
1439
|
+
const snapshot = snapshots.get(element);
|
|
1440
|
+
if (!snapshot) {
|
|
1441
|
+
continue;
|
|
1442
|
+
}
|
|
1443
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
1444
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
1445
|
+
}
|
|
1446
|
+
snapshots.delete(element);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
function saveAttributes(elements, attributes) {
|
|
1450
|
+
elements.forEach((element) => {
|
|
1451
|
+
let snapshot = snapshots.get(element);
|
|
1452
|
+
if (!snapshot) {
|
|
1453
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
1454
|
+
snapshots.set(element, snapshot);
|
|
1455
|
+
}
|
|
1456
|
+
attributes.forEach((attribute) => {
|
|
1457
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
1458
|
+
});
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// node_modules/@y14e/portal/dist/index.js
|
|
1463
|
+
var snapshots2 = /* @__PURE__ */ new WeakMap();
|
|
1464
|
+
function restoreAttributes2(elements) {
|
|
1465
|
+
for (const element of elements) {
|
|
1466
|
+
const snapshot = snapshots2.get(element);
|
|
1467
|
+
if (!snapshot) {
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
1471
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
1472
|
+
}
|
|
1473
|
+
snapshots2.delete(element);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function saveAttributes2(elements, attributes) {
|
|
1477
|
+
elements.forEach((element) => {
|
|
1478
|
+
let snapshot = snapshots2.get(element);
|
|
1479
|
+
if (!snapshot) {
|
|
1480
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
1481
|
+
snapshots2.set(element, snapshot);
|
|
1482
|
+
}
|
|
1483
|
+
attributes.forEach((attribute) => {
|
|
1484
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
1485
|
+
});
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
1489
|
+
function getFocusables(container = document.body, options = {}) {
|
|
1490
|
+
if (!(container instanceof Element)) {
|
|
1491
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
1492
|
+
container = document.body;
|
|
1493
|
+
}
|
|
1494
|
+
let {
|
|
1495
|
+
composed = false,
|
|
1496
|
+
filter,
|
|
1497
|
+
include,
|
|
1498
|
+
skipNegativeTabIndexCheck = false,
|
|
1499
|
+
skipVisibilityCheck = false
|
|
1500
|
+
} = options;
|
|
1501
|
+
if (typeof composed !== "boolean") {
|
|
1502
|
+
console.warn("Invalid composed option. Fallback: false.");
|
|
1503
|
+
composed = false;
|
|
1504
|
+
}
|
|
1505
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
1506
|
+
console.warn(
|
|
1507
|
+
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
1508
|
+
);
|
|
1509
|
+
filter = void 0;
|
|
1510
|
+
}
|
|
1511
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
1512
|
+
console.warn(
|
|
1513
|
+
"Invalid include function. Fallback: no include function (undefined)."
|
|
1514
|
+
);
|
|
1515
|
+
include = void 0;
|
|
1516
|
+
}
|
|
1517
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
1518
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
1519
|
+
skipNegativeTabIndexCheck = false;
|
|
1520
|
+
}
|
|
1521
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
1522
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
1523
|
+
skipVisibilityCheck = false;
|
|
1524
|
+
}
|
|
1525
|
+
const elements = [];
|
|
1526
|
+
if (composed || include) {
|
|
1527
|
+
let traverse2 = function(node) {
|
|
1528
|
+
if (node instanceof Element) {
|
|
1529
|
+
if (isFocusable(node, {
|
|
1530
|
+
skipNegativeTabIndexCheck,
|
|
1531
|
+
skipVisibilityCheck
|
|
1532
|
+
}) || include?.(node)) {
|
|
1533
|
+
elements[elements.length] = node;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
const children = getComposedChildren(node);
|
|
1537
|
+
for (let i = 0, l = children.length; i < l; i++) {
|
|
1538
|
+
const child = children[i];
|
|
1539
|
+
if (!child) {
|
|
1540
|
+
continue;
|
|
1541
|
+
}
|
|
1542
|
+
traverse2(child);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
traverse2(container);
|
|
1546
|
+
} else {
|
|
1547
|
+
const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
1548
|
+
for (let i = 0, l = candidates.length; i < l; i++) {
|
|
1549
|
+
const candidate = candidates[i];
|
|
1550
|
+
if (!(candidate instanceof Element)) {
|
|
1551
|
+
continue;
|
|
1552
|
+
}
|
|
1553
|
+
if (isFocusable(candidate, {
|
|
1554
|
+
skipNegativeTabIndexCheck,
|
|
1555
|
+
skipVisibilityCheck
|
|
1556
|
+
})) {
|
|
1557
|
+
elements[elements.length] = candidate;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
|
|
1562
|
+
return filter ? unfiltered.filter(filter) : unfiltered;
|
|
1563
|
+
}
|
|
1564
|
+
function getNextFocusable(container = document.body, options = {}) {
|
|
1565
|
+
return getRelativeFocusable(container, 1, options);
|
|
1566
|
+
}
|
|
1567
|
+
function getPreviousFocusable(container = document.body, options = {}) {
|
|
1568
|
+
return getRelativeFocusable(container, -1, options);
|
|
1569
|
+
}
|
|
1570
|
+
function isFocusable(element, options = {}) {
|
|
1571
|
+
if (!(element instanceof Element)) {
|
|
1572
|
+
console.warn("Invalid element");
|
|
1573
|
+
return false;
|
|
1574
|
+
}
|
|
1575
|
+
let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
|
|
1576
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
1577
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
1578
|
+
skipNegativeTabIndexCheck = false;
|
|
1579
|
+
}
|
|
1580
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
1581
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
1582
|
+
skipVisibilityCheck = false;
|
|
1583
|
+
}
|
|
1584
|
+
if (element.hasAttribute("hidden") || isInert(element)) {
|
|
1585
|
+
return false;
|
|
1586
|
+
}
|
|
1587
|
+
if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
|
|
1588
|
+
return false;
|
|
1589
|
+
}
|
|
1590
|
+
if (!element.matches(
|
|
1591
|
+
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR
|
|
1592
|
+
)) {
|
|
1593
|
+
return false;
|
|
1594
|
+
}
|
|
1595
|
+
if (isDisabledDeep(element)) {
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
if (!skipVisibilityCheck && !element.checkVisibility({
|
|
1599
|
+
contentVisibilityAuto: true,
|
|
1600
|
+
opacityProperty: true,
|
|
1601
|
+
visibilityProperty: true
|
|
1602
|
+
})) {
|
|
1603
|
+
return false;
|
|
1604
|
+
}
|
|
1605
|
+
return true;
|
|
1606
|
+
}
|
|
1607
|
+
function getRelativeFocusable(container, offset3, options) {
|
|
1608
|
+
if (!(container instanceof Element)) {
|
|
1609
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
1610
|
+
container = document.body;
|
|
1611
|
+
}
|
|
1612
|
+
let {
|
|
1613
|
+
anchor = getActiveElement(),
|
|
1614
|
+
composed = false,
|
|
1615
|
+
filter,
|
|
1616
|
+
include,
|
|
1617
|
+
skipNegativeTabIndexCheck = false,
|
|
1618
|
+
skipVisibilityCheck = false,
|
|
1619
|
+
wrap = false
|
|
1620
|
+
} = options;
|
|
1621
|
+
if (!(anchor instanceof Element)) {
|
|
1622
|
+
const active = getActiveElement();
|
|
1623
|
+
if (active instanceof Element) {
|
|
1624
|
+
console.warn("Invalid anchor element. Fallback: active element.");
|
|
1625
|
+
anchor = active;
|
|
1626
|
+
} else {
|
|
1627
|
+
console.warn("Invalid anchor element");
|
|
1628
|
+
return null;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (!containsComposed(container, anchor)) {
|
|
1632
|
+
console.warn("Anchor (active) element not within container");
|
|
1633
|
+
return null;
|
|
1634
|
+
}
|
|
1635
|
+
if (typeof composed !== "boolean") {
|
|
1636
|
+
console.warn("Invalid composed option. Fallback: false.");
|
|
1637
|
+
composed = false;
|
|
1638
|
+
}
|
|
1639
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
1640
|
+
console.warn(
|
|
1641
|
+
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
1642
|
+
);
|
|
1643
|
+
filter = void 0;
|
|
1644
|
+
}
|
|
1645
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
1646
|
+
console.warn(
|
|
1647
|
+
"Invalid include function. Fallback: no include function (undefined)."
|
|
1648
|
+
);
|
|
1649
|
+
include = void 0;
|
|
1650
|
+
}
|
|
1651
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
1652
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
1653
|
+
skipNegativeTabIndexCheck = false;
|
|
1654
|
+
}
|
|
1655
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
1656
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
1657
|
+
skipVisibilityCheck = false;
|
|
1658
|
+
}
|
|
1659
|
+
if (typeof wrap !== "boolean") {
|
|
1660
|
+
console.warn("Invalid wrap option. Fallback: false.");
|
|
1661
|
+
wrap = false;
|
|
1662
|
+
}
|
|
1663
|
+
const settings = { composed, skipNegativeTabIndexCheck, skipVisibilityCheck };
|
|
1664
|
+
if (filter !== void 0) {
|
|
1665
|
+
Object.assign(settings, { filter });
|
|
1666
|
+
}
|
|
1667
|
+
if (include !== void 0) {
|
|
1668
|
+
Object.assign(settings, { include });
|
|
1669
|
+
}
|
|
1670
|
+
const focusables = getFocusables(container, settings);
|
|
1671
|
+
const { length } = focusables;
|
|
1672
|
+
if (!length) {
|
|
1673
|
+
return null;
|
|
1674
|
+
}
|
|
1675
|
+
const currentIndex = focusables.indexOf(anchor);
|
|
1676
|
+
if (currentIndex === -1) {
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
const offsetIndex = currentIndex + offset3;
|
|
1680
|
+
if ((offsetIndex < 0 || offsetIndex >= length) && !wrap) {
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
return focusables[(offsetIndex + length) % length] ?? null;
|
|
1684
|
+
}
|
|
1685
|
+
function isDisabledDeep(element) {
|
|
1686
|
+
let current = element;
|
|
1687
|
+
while (current) {
|
|
1688
|
+
if (current instanceof ShadowRoot) {
|
|
1689
|
+
if (current.mode !== "open") {
|
|
1690
|
+
return false;
|
|
1691
|
+
}
|
|
1692
|
+
current = current.host;
|
|
1693
|
+
continue;
|
|
1694
|
+
}
|
|
1695
|
+
if (!(current instanceof Element)) {
|
|
1696
|
+
current = current.parentNode;
|
|
1697
|
+
continue;
|
|
1698
|
+
}
|
|
1699
|
+
if (current === element && isFormControl(current) && isDisabled(current)) {
|
|
1700
|
+
return true;
|
|
1701
|
+
}
|
|
1702
|
+
if (isInert(current)) {
|
|
1703
|
+
return true;
|
|
1704
|
+
}
|
|
1705
|
+
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
1706
|
+
if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
current = current.parentNode;
|
|
1711
|
+
}
|
|
1712
|
+
return false;
|
|
1713
|
+
}
|
|
1714
|
+
function normalizeRadioGroup(elements) {
|
|
1715
|
+
let map = null;
|
|
1716
|
+
for (let i = 0, l = elements.length; i < l; i++) {
|
|
1717
|
+
const element = elements[i];
|
|
1718
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
1719
|
+
continue;
|
|
1720
|
+
}
|
|
1721
|
+
if (!isUngroupedRadio(element)) {
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
if (!map) {
|
|
1725
|
+
map = /* @__PURE__ */ new Map();
|
|
1726
|
+
}
|
|
1727
|
+
const key = `${element.form?.id ?? "no-form"}::${element.name}`;
|
|
1728
|
+
const group = map.get(key) ?? map.set(key, []).get(key);
|
|
1729
|
+
if (group) {
|
|
1730
|
+
group[group.length] = element;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
if (!map) {
|
|
1734
|
+
return elements;
|
|
1735
|
+
}
|
|
1736
|
+
const placeholder = /* @__PURE__ */ new Set();
|
|
1737
|
+
for (const group of map.values()) {
|
|
1738
|
+
placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
|
|
1739
|
+
}
|
|
1740
|
+
return elements.filter((element) => {
|
|
1741
|
+
if (isUngroupedRadio(element)) {
|
|
1742
|
+
return placeholder.has(element);
|
|
1743
|
+
}
|
|
1744
|
+
return true;
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
function sortByTabIndex(elements) {
|
|
1748
|
+
const ordered = [];
|
|
1749
|
+
const natural = [];
|
|
1750
|
+
for (let i = 0, l = elements.length; i < l; i++) {
|
|
1751
|
+
const element = elements[i];
|
|
1752
|
+
if (!element) {
|
|
1753
|
+
continue;
|
|
1754
|
+
}
|
|
1755
|
+
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
1756
|
+
target[target.length] = element;
|
|
1757
|
+
}
|
|
1758
|
+
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
1759
|
+
let count = 0;
|
|
1760
|
+
const sorted = new Array(ordered.length + natural.length);
|
|
1761
|
+
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
1762
|
+
sorted[count++] = ordered[i];
|
|
1763
|
+
}
|
|
1764
|
+
for (let i = 0, l = natural.length; i < l; i++) {
|
|
1765
|
+
sorted[count++] = natural[i];
|
|
1766
|
+
}
|
|
1767
|
+
return sorted;
|
|
1768
|
+
}
|
|
1769
|
+
function containsComposed(container, element) {
|
|
1770
|
+
let current = element;
|
|
1771
|
+
while (current) {
|
|
1772
|
+
if (current === container) {
|
|
1773
|
+
return true;
|
|
1774
|
+
}
|
|
1775
|
+
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
1776
|
+
}
|
|
1777
|
+
return false;
|
|
1778
|
+
}
|
|
1779
|
+
function getComposedChildren(node) {
|
|
1780
|
+
if (node instanceof ShadowRoot) {
|
|
1781
|
+
return getChildren(node);
|
|
1782
|
+
}
|
|
1783
|
+
if (!(node instanceof Element)) {
|
|
1784
|
+
return [];
|
|
1785
|
+
}
|
|
1786
|
+
if (node instanceof HTMLSlotElement) {
|
|
1787
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
1788
|
+
if (assigned.length) {
|
|
1789
|
+
return assigned;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
1793
|
+
return getChildren(node.shadowRoot);
|
|
1794
|
+
}
|
|
1795
|
+
return getChildren(node);
|
|
1796
|
+
}
|
|
1797
|
+
function getActiveElement() {
|
|
1798
|
+
let current = document.activeElement;
|
|
1799
|
+
while (current?.shadowRoot?.activeElement) {
|
|
1800
|
+
current = current.shadowRoot.activeElement;
|
|
1801
|
+
}
|
|
1802
|
+
return current;
|
|
1803
|
+
}
|
|
1804
|
+
function getChildren(node) {
|
|
1805
|
+
const elements = [];
|
|
1806
|
+
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
1807
|
+
elements[elements.length] = child;
|
|
1808
|
+
}
|
|
1809
|
+
return elements;
|
|
1810
|
+
}
|
|
1811
|
+
function getTabIndex(element) {
|
|
1812
|
+
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
1813
|
+
}
|
|
1814
|
+
function isDisabled(element) {
|
|
1815
|
+
return "disabled" in element && !!element.disabled;
|
|
1816
|
+
}
|
|
1817
|
+
function isFormControl(element) {
|
|
1818
|
+
const name = element.tagName;
|
|
1819
|
+
return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
|
|
1820
|
+
}
|
|
1821
|
+
function isInert(element) {
|
|
1822
|
+
return "inert" in element && !!element.inert;
|
|
1823
|
+
}
|
|
1824
|
+
function isUngroupedRadio(element) {
|
|
1825
|
+
return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
|
|
1826
|
+
}
|
|
1827
|
+
var VISUALLY_HIDDEN_CSS = `border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;`;
|
|
1828
|
+
function createPortal(host, container = document.body) {
|
|
1829
|
+
if (!(host instanceof Element)) {
|
|
1830
|
+
console.warn("Invalid host element");
|
|
1831
|
+
return () => {
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
if (host.hasAttribute("data-portaled")) {
|
|
1835
|
+
console.warn("Already portaled");
|
|
1836
|
+
return () => {
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
if (!(container instanceof Element)) {
|
|
1840
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
1841
|
+
container = document.body;
|
|
1842
|
+
}
|
|
1843
|
+
if (containsComposed2(host, container)) {
|
|
1844
|
+
console.warn("Host element cannot contain the container element");
|
|
1845
|
+
return () => {
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
const portal = new Portal(host, container);
|
|
1849
|
+
return () => portal.destroy();
|
|
1850
|
+
}
|
|
1851
|
+
var Portal = class {
|
|
1852
|
+
#host;
|
|
1853
|
+
#container;
|
|
1854
|
+
#entranceSentinel;
|
|
1855
|
+
#exitSentinel;
|
|
1856
|
+
#focusables = /* @__PURE__ */ new Set();
|
|
1857
|
+
#controller = null;
|
|
1858
|
+
#isDestroyed = false;
|
|
1859
|
+
constructor(host, container) {
|
|
1860
|
+
this.#host = host;
|
|
1861
|
+
this.#container = container;
|
|
1862
|
+
this.#entranceSentinel = this.#createSentinel();
|
|
1863
|
+
this.#exitSentinel = this.#createSentinel();
|
|
1864
|
+
this.#initialize();
|
|
1865
|
+
}
|
|
1866
|
+
destroy() {
|
|
1867
|
+
if (this.#isDestroyed) {
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
this.#isDestroyed = true;
|
|
1871
|
+
this.#controller?.abort();
|
|
1872
|
+
this.#controller = null;
|
|
1873
|
+
restoreAttributes2([...this.#focusables]);
|
|
1874
|
+
this.#focusables.clear();
|
|
1875
|
+
this.#exitSentinel.after(this.#host);
|
|
1876
|
+
this.#entranceSentinel.remove();
|
|
1877
|
+
this.#exitSentinel.remove();
|
|
1878
|
+
this.#host.removeAttribute("data-portaled");
|
|
1879
|
+
}
|
|
1880
|
+
#initialize() {
|
|
1881
|
+
this.#host.before(this.#entranceSentinel);
|
|
1882
|
+
this.#entranceSentinel.after(this.#exitSentinel);
|
|
1883
|
+
this.#container.append(this.#host);
|
|
1884
|
+
this.#update();
|
|
1885
|
+
this.#controller = new AbortController();
|
|
1886
|
+
const { signal } = this.#controller;
|
|
1887
|
+
document.addEventListener("focusin", this.#onFocusIn, {
|
|
1888
|
+
capture: true,
|
|
1889
|
+
signal
|
|
1890
|
+
});
|
|
1891
|
+
document.addEventListener("keydown", this.#onKeyDown, {
|
|
1892
|
+
capture: true,
|
|
1893
|
+
signal
|
|
1894
|
+
});
|
|
1895
|
+
this.#host.setAttribute("data-portaled", "");
|
|
1896
|
+
}
|
|
1897
|
+
#onFocusIn = (event) => {
|
|
1898
|
+
const current = event.target;
|
|
1899
|
+
const before = event.relatedTarget;
|
|
1900
|
+
if (!(before instanceof Element)) {
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
if (current === this.#entranceSentinel) {
|
|
1904
|
+
if (this.#host.contains(before)) {
|
|
1905
|
+
this.#moveFocus("previous");
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
this.#update();
|
|
1909
|
+
const first = [...this.#focusables][0];
|
|
1910
|
+
first && focusElement(first);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
if (current === this.#exitSentinel) {
|
|
1914
|
+
if (this.#host.contains(before)) {
|
|
1915
|
+
this.#moveFocus("next");
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
this.#update();
|
|
1919
|
+
const last = [...this.#focusables].at(-1);
|
|
1920
|
+
last && focusElement(last);
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
#onKeyDown = (event) => {
|
|
1924
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
1925
|
+
if (key !== "Tab" || altKey || ctrlKey || metaKey) {
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
const active = getActiveElement2();
|
|
1929
|
+
if (!(active instanceof Element)) {
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
if (!this.#host.contains(active)) {
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
this.#update();
|
|
1936
|
+
const focusables = this.#getFocusables();
|
|
1937
|
+
if (!focusables.length) {
|
|
1938
|
+
event.preventDefault();
|
|
1939
|
+
this.#focusSentinel(shiftKey);
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
const index = focusables.indexOf(active);
|
|
1943
|
+
if (index === -1) {
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
event.preventDefault();
|
|
1947
|
+
const focusable = focusables[index + (shiftKey ? -1 : 1)];
|
|
1948
|
+
focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
|
|
1949
|
+
};
|
|
1950
|
+
#update() {
|
|
1951
|
+
const current = /* @__PURE__ */ new Set([
|
|
1952
|
+
...this.#getFocusables(),
|
|
1953
|
+
...getFocusables(this.#host, { composed: true })
|
|
1954
|
+
]);
|
|
1955
|
+
for (const focusable of this.#focusables) {
|
|
1956
|
+
if (current.has(focusable)) {
|
|
1957
|
+
continue;
|
|
1958
|
+
}
|
|
1959
|
+
focusable.isConnected && restoreAttributes2([focusable]);
|
|
1960
|
+
this.#focusables.delete(focusable);
|
|
1961
|
+
}
|
|
1962
|
+
for (const focusable of current) {
|
|
1963
|
+
if (this.#focusables.has(focusable)) {
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
this.#focusables.add(focusable);
|
|
1967
|
+
saveAttributes2([focusable], ["tabindex"]);
|
|
1968
|
+
focusable.setAttribute("tabindex", "-1");
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
#createSentinel() {
|
|
1972
|
+
const sentinel = document.createElement("span");
|
|
1973
|
+
sentinel.setAttribute("aria-hidden", "true");
|
|
1974
|
+
sentinel.setAttribute("data-portal-sentinel", "");
|
|
1975
|
+
sentinel.setAttribute("tabindex", "0");
|
|
1976
|
+
sentinel.style.cssText += VISUALLY_HIDDEN_CSS;
|
|
1977
|
+
return sentinel;
|
|
1978
|
+
}
|
|
1979
|
+
#focusSentinel(isPrevious) {
|
|
1980
|
+
requestAnimationFrame(
|
|
1981
|
+
() => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
|
|
1982
|
+
);
|
|
1983
|
+
}
|
|
1984
|
+
#getFocusables() {
|
|
1985
|
+
return getFocusables(this.#host, {
|
|
1986
|
+
composed: true,
|
|
1987
|
+
include: (element) => this.#focusables.has(element)
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
#moveFocus(direction) {
|
|
1991
|
+
const options = {
|
|
1992
|
+
anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
|
|
1993
|
+
composed: true
|
|
1994
|
+
};
|
|
1995
|
+
const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
|
|
1996
|
+
focusable && focusElement(focusable);
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
function containsComposed2(container, element) {
|
|
2000
|
+
let current = element;
|
|
2001
|
+
while (current) {
|
|
2002
|
+
if (current === container) {
|
|
2003
|
+
return true;
|
|
2004
|
+
}
|
|
2005
|
+
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
2006
|
+
}
|
|
2007
|
+
return false;
|
|
2008
|
+
}
|
|
2009
|
+
function focusElement(element) {
|
|
2010
|
+
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
2011
|
+
}
|
|
2012
|
+
function getActiveElement2() {
|
|
2013
|
+
let current = document.activeElement;
|
|
2014
|
+
while (current?.shadowRoot?.activeElement) {
|
|
2015
|
+
current = current.shadowRoot.activeElement;
|
|
2016
|
+
}
|
|
2017
|
+
return current;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
2021
|
+
var defaultParser2 = (value) => value.split(/\s+/);
|
|
2022
|
+
var defaultSerializer2 = (tokens) => tokens.join(" ");
|
|
2023
|
+
function addTokenToAttribute2(element, attribute, token, options = {}) {
|
|
2024
|
+
const {
|
|
2025
|
+
caseInsensitive = false,
|
|
2026
|
+
parse = defaultParser2,
|
|
2027
|
+
serialize = defaultSerializer2
|
|
2028
|
+
} = options;
|
|
2029
|
+
const value = element.getAttribute(attribute)?.trim();
|
|
2030
|
+
const tokens = value ? parse(value).filter(Boolean) : [];
|
|
2031
|
+
if (caseInsensitive) {
|
|
2032
|
+
const lower = token.toLowerCase();
|
|
2033
|
+
if (tokens.some((token2) => token2.toLowerCase() === lower)) {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
tokens.push(token);
|
|
2037
|
+
element.setAttribute(attribute, serialize(tokens));
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
const set = new Set(tokens);
|
|
2041
|
+
set.add(token);
|
|
2042
|
+
element.setAttribute(attribute, serialize([...set]));
|
|
2043
|
+
}
|
|
2044
|
+
var snapshots3 = /* @__PURE__ */ new WeakMap();
|
|
2045
|
+
function restoreAttributes3(elements) {
|
|
2046
|
+
for (const element of elements) {
|
|
2047
|
+
const snapshot = snapshots3.get(element);
|
|
2048
|
+
if (!snapshot) {
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
for (const [attribute, value] of snapshot.entries()) {
|
|
2052
|
+
value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
|
|
2053
|
+
}
|
|
2054
|
+
snapshots3.delete(element);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
function saveAttributes3(elements, attributes) {
|
|
2058
|
+
elements.forEach((element) => {
|
|
2059
|
+
let snapshot = snapshots3.get(element);
|
|
2060
|
+
if (!snapshot) {
|
|
2061
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
2062
|
+
snapshots3.set(element, snapshot);
|
|
2063
|
+
}
|
|
2064
|
+
attributes.forEach((attribute) => {
|
|
2065
|
+
snapshot.set(attribute, element.getAttribute(attribute));
|
|
2066
|
+
});
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
var FOCUSABLE_SELECTOR2 = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
|
|
2070
|
+
function getFocusables2(container = document.body, options = {}) {
|
|
2071
|
+
if (!(container instanceof Element)) {
|
|
2072
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
2073
|
+
container = document.body;
|
|
2074
|
+
}
|
|
2075
|
+
let {
|
|
2076
|
+
composed = false,
|
|
2077
|
+
filter,
|
|
2078
|
+
include,
|
|
2079
|
+
skipNegativeTabIndexCheck = false,
|
|
2080
|
+
skipVisibilityCheck = false
|
|
2081
|
+
} = options;
|
|
2082
|
+
if (typeof composed !== "boolean") {
|
|
2083
|
+
console.warn("Invalid composed option. Fallback: false.");
|
|
2084
|
+
composed = false;
|
|
2085
|
+
}
|
|
2086
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
2087
|
+
console.warn(
|
|
2088
|
+
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
2089
|
+
);
|
|
2090
|
+
filter = void 0;
|
|
2091
|
+
}
|
|
2092
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
2093
|
+
console.warn(
|
|
2094
|
+
"Invalid include function. Fallback: no include function (undefined)."
|
|
2095
|
+
);
|
|
2096
|
+
include = void 0;
|
|
2097
|
+
}
|
|
2098
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
2099
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
2100
|
+
skipNegativeTabIndexCheck = false;
|
|
2101
|
+
}
|
|
2102
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
2103
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
2104
|
+
skipVisibilityCheck = false;
|
|
2105
|
+
}
|
|
2106
|
+
const elements = [];
|
|
2107
|
+
if (composed || include) {
|
|
2108
|
+
let traverse2 = function(node) {
|
|
2109
|
+
if (node instanceof Element) {
|
|
2110
|
+
if (isFocusable2(node, {
|
|
2111
|
+
skipNegativeTabIndexCheck,
|
|
2112
|
+
skipVisibilityCheck
|
|
2113
|
+
}) || include?.(node)) {
|
|
2114
|
+
elements[elements.length] = node;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const children = getComposedChildren2(node);
|
|
2118
|
+
for (let i = 0, l = children.length; i < l; i++) {
|
|
2119
|
+
const child = children[i];
|
|
2120
|
+
if (!child) {
|
|
2121
|
+
continue;
|
|
2122
|
+
}
|
|
2123
|
+
traverse2(child);
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
traverse2(container);
|
|
2127
|
+
} else {
|
|
2128
|
+
const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR2);
|
|
2129
|
+
for (let i = 0, l = candidates.length; i < l; i++) {
|
|
2130
|
+
const candidate = candidates[i];
|
|
2131
|
+
if (!(candidate instanceof Element)) {
|
|
2132
|
+
continue;
|
|
2133
|
+
}
|
|
2134
|
+
if (isFocusable2(candidate, {
|
|
2135
|
+
skipNegativeTabIndexCheck,
|
|
2136
|
+
skipVisibilityCheck
|
|
2137
|
+
})) {
|
|
2138
|
+
elements[elements.length] = candidate;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
const unfiltered = normalizeRadioGroup2(sortByTabIndex2(elements));
|
|
2143
|
+
return filter ? unfiltered.filter(filter) : unfiltered;
|
|
2144
|
+
}
|
|
2145
|
+
function isFocusable2(element, options = {}) {
|
|
2146
|
+
if (!(element instanceof Element)) {
|
|
2147
|
+
console.warn("Invalid element");
|
|
2148
|
+
return false;
|
|
2149
|
+
}
|
|
2150
|
+
let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
|
|
2151
|
+
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
2152
|
+
console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
|
|
2153
|
+
skipNegativeTabIndexCheck = false;
|
|
2154
|
+
}
|
|
2155
|
+
if (typeof skipVisibilityCheck !== "boolean") {
|
|
2156
|
+
console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
|
|
2157
|
+
skipVisibilityCheck = false;
|
|
2158
|
+
}
|
|
2159
|
+
if (element.hasAttribute("hidden") || isInert2(element)) {
|
|
2160
|
+
return false;
|
|
2161
|
+
}
|
|
2162
|
+
if (!skipNegativeTabIndexCheck && getTabIndex2(element) < 0) {
|
|
2163
|
+
return false;
|
|
2164
|
+
}
|
|
2165
|
+
if (!element.matches(
|
|
2166
|
+
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR2.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR2
|
|
2167
|
+
)) {
|
|
2168
|
+
return false;
|
|
2169
|
+
}
|
|
2170
|
+
if (isDisabledDeep2(element)) {
|
|
2171
|
+
return false;
|
|
2172
|
+
}
|
|
2173
|
+
if (!skipVisibilityCheck && !element.checkVisibility({
|
|
2174
|
+
contentVisibilityAuto: true,
|
|
2175
|
+
opacityProperty: true,
|
|
2176
|
+
visibilityProperty: true
|
|
2177
|
+
})) {
|
|
2178
|
+
return false;
|
|
2179
|
+
}
|
|
2180
|
+
return true;
|
|
2181
|
+
}
|
|
2182
|
+
function isDisabledDeep2(element) {
|
|
2183
|
+
let current = element;
|
|
2184
|
+
while (current) {
|
|
2185
|
+
if (current instanceof ShadowRoot) {
|
|
2186
|
+
if (current.mode !== "open") {
|
|
2187
|
+
return false;
|
|
2188
|
+
}
|
|
2189
|
+
current = current.host;
|
|
2190
|
+
continue;
|
|
2191
|
+
}
|
|
2192
|
+
if (!(current instanceof Element)) {
|
|
2193
|
+
current = current.parentNode;
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
if (current === element && isFormControl2(current) && isDisabled2(current)) {
|
|
2197
|
+
return true;
|
|
2198
|
+
}
|
|
2199
|
+
if (isInert2(current)) {
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
if (isFormControl2(element) && current.tagName === "FIELDSET" && isDisabled2(current)) {
|
|
2203
|
+
if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
|
|
2204
|
+
return true;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
current = current.parentNode;
|
|
2208
|
+
}
|
|
2209
|
+
return false;
|
|
2210
|
+
}
|
|
2211
|
+
function normalizeRadioGroup2(elements) {
|
|
2212
|
+
let map = null;
|
|
2213
|
+
for (let i = 0, l = elements.length; i < l; i++) {
|
|
2214
|
+
const element = elements[i];
|
|
2215
|
+
if (!(element instanceof HTMLInputElement)) {
|
|
2216
|
+
continue;
|
|
2217
|
+
}
|
|
2218
|
+
if (!isUngroupedRadio2(element)) {
|
|
2219
|
+
continue;
|
|
2220
|
+
}
|
|
2221
|
+
if (!map) {
|
|
2222
|
+
map = /* @__PURE__ */ new Map();
|
|
2223
|
+
}
|
|
2224
|
+
const key = `${element.form?.id ?? "no-form"}::${element.name}`;
|
|
2225
|
+
const group = map.get(key) ?? map.set(key, []).get(key);
|
|
2226
|
+
if (group) {
|
|
2227
|
+
group[group.length] = element;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
if (!map) {
|
|
2231
|
+
return elements;
|
|
2232
|
+
}
|
|
2233
|
+
const placeholder = /* @__PURE__ */ new Set();
|
|
2234
|
+
for (const group of map.values()) {
|
|
2235
|
+
placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
|
|
2236
|
+
}
|
|
2237
|
+
return elements.filter((element) => {
|
|
2238
|
+
if (isUngroupedRadio2(element)) {
|
|
2239
|
+
return placeholder.has(element);
|
|
2240
|
+
}
|
|
2241
|
+
return true;
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
function sortByTabIndex2(elements) {
|
|
2245
|
+
const ordered = [];
|
|
2246
|
+
const natural = [];
|
|
2247
|
+
for (let i = 0, l = elements.length; i < l; i++) {
|
|
2248
|
+
const element = elements[i];
|
|
2249
|
+
if (!element) {
|
|
2250
|
+
continue;
|
|
2251
|
+
}
|
|
2252
|
+
const target = getTabIndex2(element) > 0 ? ordered : natural;
|
|
2253
|
+
target[target.length] = element;
|
|
2254
|
+
}
|
|
2255
|
+
ordered.sort((a, b) => getTabIndex2(a) - getTabIndex2(b));
|
|
2256
|
+
let count = 0;
|
|
2257
|
+
const sorted = new Array(ordered.length + natural.length);
|
|
2258
|
+
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
2259
|
+
sorted[count++] = ordered[i];
|
|
2260
|
+
}
|
|
2261
|
+
for (let i = 0, l = natural.length; i < l; i++) {
|
|
2262
|
+
sorted[count++] = natural[i];
|
|
2263
|
+
}
|
|
2264
|
+
return sorted;
|
|
2265
|
+
}
|
|
2266
|
+
function getComposedChildren2(node) {
|
|
2267
|
+
if (node instanceof ShadowRoot) {
|
|
2268
|
+
return getChildren2(node);
|
|
2269
|
+
}
|
|
2270
|
+
if (!(node instanceof Element)) {
|
|
2271
|
+
return [];
|
|
2272
|
+
}
|
|
2273
|
+
if (node instanceof HTMLSlotElement) {
|
|
2274
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
2275
|
+
if (assigned.length) {
|
|
2276
|
+
return assigned;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
2280
|
+
return getChildren2(node.shadowRoot);
|
|
2281
|
+
}
|
|
2282
|
+
return getChildren2(node);
|
|
2283
|
+
}
|
|
2284
|
+
function getChildren2(node) {
|
|
2285
|
+
const elements = [];
|
|
2286
|
+
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
2287
|
+
elements[elements.length] = child;
|
|
2288
|
+
}
|
|
2289
|
+
return elements;
|
|
2290
|
+
}
|
|
2291
|
+
function getTabIndex2(element) {
|
|
2292
|
+
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
2293
|
+
}
|
|
2294
|
+
function isDisabled2(element) {
|
|
2295
|
+
return "disabled" in element && !!element.disabled;
|
|
2296
|
+
}
|
|
2297
|
+
function isFormControl2(element) {
|
|
2298
|
+
const name = element.tagName;
|
|
2299
|
+
return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
|
|
2300
|
+
}
|
|
2301
|
+
function isInert2(element) {
|
|
2302
|
+
return "inert" in element && !!element.inert;
|
|
2303
|
+
}
|
|
2304
|
+
function isUngroupedRadio2(element) {
|
|
2305
|
+
return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
|
|
2306
|
+
}
|
|
2307
|
+
function createRovingTabIndex(container, options = {}) {
|
|
2308
|
+
if (!(container instanceof Element)) {
|
|
2309
|
+
console.warn("Invalid container element");
|
|
2310
|
+
return () => {
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
let {
|
|
2314
|
+
direction,
|
|
2315
|
+
navigationOnly = false,
|
|
2316
|
+
selector,
|
|
2317
|
+
typeahead = false,
|
|
2318
|
+
wrap = false
|
|
2319
|
+
} = options;
|
|
2320
|
+
if (typeof direction !== "undefined" && !["horizontal", "vertical"].includes(direction)) {
|
|
2321
|
+
console.warn("Invalid direction option. Fallback: both (undefined).");
|
|
2322
|
+
direction = void 0;
|
|
2323
|
+
}
|
|
2324
|
+
if (typeof navigationOnly !== "boolean") {
|
|
2325
|
+
console.warn("Invalid navigationOnly option. Fallback: false.");
|
|
2326
|
+
navigationOnly = false;
|
|
2327
|
+
}
|
|
2328
|
+
if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
|
|
2329
|
+
console.warn(
|
|
2330
|
+
"Invalid selector. Fallback: all focusable elements (undefined)."
|
|
2331
|
+
);
|
|
2332
|
+
selector = void 0;
|
|
2333
|
+
}
|
|
2334
|
+
if (typeof typeahead !== "boolean") {
|
|
2335
|
+
console.warn("Invalid typeahead option. Fallback: false.");
|
|
2336
|
+
typeahead = false;
|
|
2337
|
+
}
|
|
2338
|
+
if (typeof wrap !== "boolean") {
|
|
2339
|
+
console.warn("Invalid wrap option. Fallback: false.");
|
|
2340
|
+
wrap = false;
|
|
2341
|
+
}
|
|
2342
|
+
const settings = { navigationOnly, typeahead, wrap };
|
|
2343
|
+
if (direction) {
|
|
2344
|
+
Object.assign(settings, { direction });
|
|
2345
|
+
}
|
|
2346
|
+
if (selector) {
|
|
2347
|
+
Object.assign(settings, { selector });
|
|
2348
|
+
}
|
|
2349
|
+
const roving = new RovingTabIndex(container, settings);
|
|
2350
|
+
return () => roving.destroy();
|
|
2351
|
+
}
|
|
2352
|
+
var RovingTabIndex = class {
|
|
2353
|
+
#container;
|
|
2354
|
+
#options;
|
|
2355
|
+
#focusables = /* @__PURE__ */ new Set();
|
|
2356
|
+
#focusablesByFirstChar = /* @__PURE__ */ new Map();
|
|
2357
|
+
#selectorFilter;
|
|
2358
|
+
#controller = null;
|
|
2359
|
+
#isDestroyed = false;
|
|
2360
|
+
constructor(container, options = {}) {
|
|
2361
|
+
this.#container = container;
|
|
2362
|
+
this.#options = options;
|
|
2363
|
+
this.#selectorFilter = this.#createSelectorFilter();
|
|
2364
|
+
this.#initialize();
|
|
2365
|
+
}
|
|
2366
|
+
destroy() {
|
|
2367
|
+
if (this.#isDestroyed) {
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
this.#isDestroyed = true;
|
|
2371
|
+
this.#controller?.abort();
|
|
2372
|
+
this.#controller = null;
|
|
2373
|
+
restoreAttributes3([...this.#focusables]);
|
|
2374
|
+
this.#focusables.clear();
|
|
2375
|
+
this.#focusablesByFirstChar.clear();
|
|
2376
|
+
this.#container.removeAttribute("data-roving-tabindex-initialized");
|
|
2377
|
+
}
|
|
2378
|
+
#initialize() {
|
|
2379
|
+
this.#update(document.activeElement);
|
|
2380
|
+
this.#controller = new AbortController();
|
|
2381
|
+
const { signal } = this.#controller;
|
|
2382
|
+
document.addEventListener("focusin", this.#onFocusIn, {
|
|
2383
|
+
capture: true,
|
|
2384
|
+
signal
|
|
2385
|
+
});
|
|
2386
|
+
document.addEventListener("keydown", this.#onKeyDown, {
|
|
2387
|
+
capture: true,
|
|
2388
|
+
signal
|
|
2389
|
+
});
|
|
2390
|
+
this.#container.setAttribute("data-roving-tabindex-initialized", "");
|
|
2391
|
+
}
|
|
2392
|
+
#onFocusIn = (event) => {
|
|
2393
|
+
const { target } = event;
|
|
2394
|
+
if (!(target instanceof Element) || !this.#focusables.has(target)) {
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
this.#update(target);
|
|
2398
|
+
};
|
|
2399
|
+
#onKeyDown = (event) => {
|
|
2400
|
+
if (!event.composedPath().includes(this.#container)) {
|
|
2401
|
+
return;
|
|
2402
|
+
}
|
|
2403
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
2404
|
+
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
const { direction, typeahead, wrap } = this.#options;
|
|
2408
|
+
const isBoth = !direction;
|
|
2409
|
+
const isHorizontal = direction === "horizontal";
|
|
2410
|
+
if (![
|
|
2411
|
+
"End",
|
|
2412
|
+
"Home",
|
|
2413
|
+
...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
2414
|
+
...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
2415
|
+
].includes(key)) {
|
|
2416
|
+
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
const active = getActiveElement3();
|
|
2421
|
+
if (!(active instanceof HTMLElement)) {
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const current = this.#getFocusables();
|
|
2425
|
+
if (!current.includes(active)) {
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
event.preventDefault();
|
|
2429
|
+
event.stopPropagation();
|
|
2430
|
+
const currentIndex = current.indexOf(active);
|
|
2431
|
+
let rawIndex;
|
|
2432
|
+
let newIndex = currentIndex;
|
|
2433
|
+
let target = current;
|
|
2434
|
+
switch (key) {
|
|
2435
|
+
case "End":
|
|
2436
|
+
newIndex = -1;
|
|
2437
|
+
break;
|
|
2438
|
+
case "Home":
|
|
2439
|
+
newIndex = 0;
|
|
2440
|
+
break;
|
|
2441
|
+
case "ArrowLeft":
|
|
2442
|
+
case "ArrowUp":
|
|
2443
|
+
rawIndex = currentIndex - 1;
|
|
2444
|
+
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
2445
|
+
break;
|
|
2446
|
+
case "ArrowRight":
|
|
2447
|
+
case "ArrowDown":
|
|
2448
|
+
rawIndex = currentIndex + 1;
|
|
2449
|
+
newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
|
|
2450
|
+
break;
|
|
2451
|
+
default: {
|
|
2452
|
+
target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
|
|
2453
|
+
const foundIndex = target.findIndex(
|
|
2454
|
+
(focusable2) => current.indexOf(focusable2) > currentIndex
|
|
2455
|
+
);
|
|
2456
|
+
newIndex = foundIndex >= 0 ? foundIndex : 0;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
const focusable = target.at(newIndex);
|
|
2460
|
+
if (!focusable) {
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
focusElement2(focusable);
|
|
2464
|
+
};
|
|
2465
|
+
#update(active) {
|
|
2466
|
+
const current = new Set(this.#getFocusables());
|
|
2467
|
+
for (const focusable of this.#focusables) {
|
|
2468
|
+
if (current.has(focusable)) {
|
|
2469
|
+
continue;
|
|
2470
|
+
}
|
|
2471
|
+
focusable.isConnected && restoreAttributes3([focusable]);
|
|
2472
|
+
this.#focusables.delete(focusable);
|
|
2473
|
+
this.#focusablesByFirstChar.forEach((focusables) => {
|
|
2474
|
+
const index = focusables.indexOf(focusable);
|
|
2475
|
+
index >= 0 && focusables.splice(index, 1);
|
|
2476
|
+
});
|
|
2477
|
+
}
|
|
2478
|
+
const { navigationOnly } = this.#options;
|
|
2479
|
+
for (const focusable of current) {
|
|
2480
|
+
if (this.#focusables.has(focusable)) {
|
|
2481
|
+
continue;
|
|
2482
|
+
}
|
|
2483
|
+
this.#focusables.add(focusable);
|
|
2484
|
+
if (!navigationOnly) {
|
|
2485
|
+
saveAttributes3([focusable], ["tabindex"]);
|
|
2486
|
+
focusable.setAttribute("tabindex", "-1");
|
|
2487
|
+
}
|
|
2488
|
+
if (!this.#options.typeahead) {
|
|
2489
|
+
continue;
|
|
2490
|
+
}
|
|
2491
|
+
const value = focusable.ariaKeyShortcuts?.trim();
|
|
2492
|
+
const keys = new Set(
|
|
2493
|
+
value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
|
|
2494
|
+
);
|
|
2495
|
+
const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
|
|
2496
|
+
if (char) {
|
|
2497
|
+
keys.add(char);
|
|
2498
|
+
saveAttributes3([focusable], ["aria-keyshortcuts"]);
|
|
2499
|
+
addTokenToAttribute2(focusable, "aria-keyshortcuts", char, {
|
|
2500
|
+
caseInsensitive: true
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
keys.forEach((key) => {
|
|
2504
|
+
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
2505
|
+
focusables.push(focusable);
|
|
2506
|
+
this.#focusablesByFirstChar.set(key, focusables);
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
if (navigationOnly) {
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
if (active && this.#focusables.has(active)) {
|
|
2513
|
+
this.#focusables.forEach((focusable) => {
|
|
2514
|
+
focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
|
|
2515
|
+
});
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
[...this.#focusables].forEach((focusable, i) => {
|
|
2519
|
+
focusable.setAttribute("tabindex", i ? "-1" : "0");
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
#createSelectorFilter() {
|
|
2523
|
+
const { selector } = this.#options;
|
|
2524
|
+
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
2525
|
+
}
|
|
2526
|
+
#getFocusables() {
|
|
2527
|
+
return getFocusables2(this.#container, {
|
|
2528
|
+
composed: true,
|
|
2529
|
+
filter: this.#selectorFilter,
|
|
2530
|
+
skipNegativeTabIndexCheck: !this.#options.navigationOnly,
|
|
2531
|
+
skipVisibilityCheck: true
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
function focusElement2(element) {
|
|
2536
|
+
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
2537
|
+
}
|
|
2538
|
+
function getActiveElement3() {
|
|
2539
|
+
let current = document.activeElement;
|
|
2540
|
+
while (current?.shadowRoot?.activeElement) {
|
|
2541
|
+
current = current.shadowRoot.activeElement;
|
|
2542
|
+
}
|
|
2543
|
+
return current;
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
// src/index.ts
|
|
2547
|
+
var Menu = class _Menu {
|
|
2548
|
+
static defaults = {};
|
|
2549
|
+
static #menus = [];
|
|
2550
|
+
#rootElement;
|
|
2551
|
+
#defaults = {
|
|
2552
|
+
animation: { duration: 300 },
|
|
2553
|
+
delay: 200,
|
|
2554
|
+
popover: {
|
|
2555
|
+
menu: {
|
|
2556
|
+
arrow: true,
|
|
2557
|
+
middleware: [flip2(), offset2(), shift2()],
|
|
2558
|
+
placement: "bottom-start"
|
|
2559
|
+
},
|
|
2560
|
+
submenu: {
|
|
2561
|
+
arrow: true,
|
|
2562
|
+
middleware: [flip2(), offset2(), shift2()],
|
|
2563
|
+
placement: "right-start"
|
|
2564
|
+
},
|
|
2565
|
+
transformOrigin: true
|
|
2566
|
+
},
|
|
2567
|
+
selector: {
|
|
2568
|
+
checkboxItem: '[role="menuitemcheckbox"]',
|
|
2569
|
+
group: '[role="group"]',
|
|
2570
|
+
item: '[role^="menuitem"]',
|
|
2571
|
+
list: '[role="menu"]',
|
|
2572
|
+
radioItem: '[role="menuitemradio"]',
|
|
2573
|
+
trigger: "[data-menu-trigger]"
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
#settings;
|
|
2577
|
+
#isSubmenu;
|
|
2578
|
+
#isPortal;
|
|
2579
|
+
#triggerElement;
|
|
2580
|
+
#listElement;
|
|
2581
|
+
#itemElements;
|
|
2582
|
+
#checkboxItemElements = [];
|
|
2583
|
+
#radioItemElements = [];
|
|
2584
|
+
#radioItemElementsByGroup = /* @__PURE__ */ new WeakMap();
|
|
2585
|
+
#arrowElement;
|
|
2586
|
+
#controller = null;
|
|
2587
|
+
#animation = null;
|
|
2588
|
+
#submenus = [];
|
|
2589
|
+
#submenuTimer;
|
|
2590
|
+
#isDestroyed = false;
|
|
2591
|
+
#cleanupPortal = null;
|
|
2592
|
+
#cleanupRovingTabIndex = null;
|
|
2593
|
+
#cleanupPopover = null;
|
|
2594
|
+
constructor(root, options = {}, _internal = {}) {
|
|
2595
|
+
if (!(root instanceof HTMLElement)) {
|
|
2596
|
+
throw new TypeError("Invalid root element");
|
|
2597
|
+
}
|
|
2598
|
+
if (root.hasAttribute("data-menu-initialized")) {
|
|
2599
|
+
console.warn("Already initialized");
|
|
2600
|
+
return;
|
|
2601
|
+
}
|
|
2602
|
+
this.#rootElement = root;
|
|
2603
|
+
this.#defaults = this.#mergeOptions(this.#defaults, _Menu.defaults);
|
|
2604
|
+
this.#settings = this.#mergeOptions(this.#defaults, options);
|
|
2605
|
+
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
|
|
2606
|
+
const { isSubmenu = false, isPortal = false } = _internal;
|
|
2607
|
+
this.#isSubmenu = isSubmenu;
|
|
2608
|
+
this.#isPortal = isPortal;
|
|
2609
|
+
const { selector } = this.#settings;
|
|
2610
|
+
this.#triggerElement = this.#rootElement.querySelector(
|
|
2611
|
+
selector[!this.#isSubmenu ? "trigger" : "item"]
|
|
2612
|
+
);
|
|
2613
|
+
this.#listElement = this.#rootElement.querySelector(
|
|
2614
|
+
selector.list
|
|
2615
|
+
);
|
|
2616
|
+
if (!this.#listElement) {
|
|
2617
|
+
console.warn("Missing list element");
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
this.#itemElements = [
|
|
2621
|
+
...this.#listElement.querySelectorAll(
|
|
2622
|
+
`${selector.item}:not(:scope ${selector.list} *)`
|
|
2623
|
+
)
|
|
2624
|
+
];
|
|
2625
|
+
if (!this.#itemElements.length) {
|
|
2626
|
+
console.warn("Missing item elements");
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
this.#itemElements.forEach((item) => {
|
|
2630
|
+
const role = item.role;
|
|
2631
|
+
if (role === "menuitemcheckbox") {
|
|
2632
|
+
this.#checkboxItemElements.push(item);
|
|
2633
|
+
} else if (role === "menuitemradio") {
|
|
2634
|
+
this.#radioItemElements.push(item);
|
|
2635
|
+
}
|
|
2636
|
+
});
|
|
2637
|
+
this.#radioItemElements.forEach((item) => {
|
|
2638
|
+
let group = item.closest(selector.group);
|
|
2639
|
+
if (!group || !this.#rootElement.contains(group)) {
|
|
2640
|
+
group = this.#rootElement;
|
|
2641
|
+
}
|
|
2642
|
+
const items = this.#radioItemElementsByGroup.get(group) ?? [];
|
|
2643
|
+
items.push(item);
|
|
2644
|
+
this.#radioItemElementsByGroup.set(group, items);
|
|
2645
|
+
});
|
|
2646
|
+
const settings = this.#settings.popover[!this.#isSubmenu ? "menu" : "submenu"];
|
|
2647
|
+
if (settings.arrow) {
|
|
2648
|
+
this.#arrowElement = document.createElement("div");
|
|
2649
|
+
this.#arrowElement.setAttribute("data-menu-arrow", "");
|
|
2650
|
+
this.#listElement.appendChild(this.#arrowElement);
|
|
2651
|
+
const index = settings.middleware.findIndex((m) => m.name === "arrow");
|
|
2652
|
+
const option = arrow2({ element: this.#arrowElement });
|
|
2653
|
+
if (index !== -1) {
|
|
2654
|
+
settings.middleware.splice(index, 1);
|
|
2655
|
+
}
|
|
2656
|
+
settings.middleware.push(option);
|
|
2657
|
+
} else {
|
|
2658
|
+
this.#arrowElement = null;
|
|
2659
|
+
}
|
|
2660
|
+
this.#initialize();
|
|
2661
|
+
}
|
|
2662
|
+
open() {
|
|
2663
|
+
this.#toggle(true);
|
|
2664
|
+
}
|
|
2665
|
+
close() {
|
|
2666
|
+
this.#toggle(false);
|
|
2667
|
+
}
|
|
2668
|
+
async destroy(force = false) {
|
|
2669
|
+
if (this.#isDestroyed) {
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
this.#isDestroyed = true;
|
|
2673
|
+
this.#controller?.abort();
|
|
2674
|
+
this.#controller = null;
|
|
2675
|
+
this.#cleanupRovingTabIndex?.();
|
|
2676
|
+
this.#cleanupRovingTabIndex = null;
|
|
2677
|
+
this.#cleanupPortal?.();
|
|
2678
|
+
this.#cleanupPortal = null;
|
|
2679
|
+
this.#cleanupPopover?.();
|
|
2680
|
+
this.#cleanupPopover = null;
|
|
2681
|
+
this.#clearSubmenuTimer();
|
|
2682
|
+
_Menu.#menus = _Menu.#menus.filter((menu) => menu !== this);
|
|
2683
|
+
this.#submenus && await Promise.all(this.#submenus.map((submenu) => submenu.destroy()));
|
|
2684
|
+
if (!force) {
|
|
2685
|
+
try {
|
|
2686
|
+
await this.#animation?.finished;
|
|
2687
|
+
} catch {
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
this.#animation?.cancel();
|
|
2691
|
+
this.#animation = null;
|
|
2692
|
+
const elements = this.#itemElements;
|
|
2693
|
+
if (this.#triggerElement) {
|
|
2694
|
+
elements.push(this.#triggerElement);
|
|
2695
|
+
}
|
|
2696
|
+
if (this.#listElement) {
|
|
2697
|
+
elements.push(this.#listElement);
|
|
2698
|
+
}
|
|
2699
|
+
restoreAttributes(elements);
|
|
2700
|
+
this.#triggerElement = null;
|
|
2701
|
+
this.#listElement = null;
|
|
2702
|
+
this.#itemElements.length = 0;
|
|
2703
|
+
this.#checkboxItemElements.length = 0;
|
|
2704
|
+
this.#radioItemElements.length = 0;
|
|
2705
|
+
this.#arrowElement = null;
|
|
2706
|
+
this.#rootElement.removeAttribute("data-menu-initialized");
|
|
2707
|
+
}
|
|
2708
|
+
#initialize() {
|
|
2709
|
+
this.#controller = new AbortController();
|
|
2710
|
+
const { signal } = this.#controller;
|
|
2711
|
+
document.addEventListener("pointerdown", this.#onOutsidePointerDown, {
|
|
2712
|
+
capture: true,
|
|
2713
|
+
signal
|
|
2714
|
+
});
|
|
2715
|
+
this.#rootElement.addEventListener("focusin", this.#onRootFocusIn, {
|
|
2716
|
+
signal
|
|
2717
|
+
});
|
|
2718
|
+
this.#rootElement.addEventListener("focusout", this.#onRootFocusOut, {
|
|
2719
|
+
signal
|
|
2720
|
+
});
|
|
2721
|
+
if (!this.#listElement) {
|
|
2722
|
+
throw new Error("Unreachable");
|
|
2723
|
+
}
|
|
2724
|
+
saveAttributes([this.#listElement], ["aria-labelledby", "id", "role"]);
|
|
2725
|
+
if (this.#triggerElement) {
|
|
2726
|
+
saveAttributes(
|
|
2727
|
+
[this.#triggerElement],
|
|
2728
|
+
[
|
|
2729
|
+
"aria-controls",
|
|
2730
|
+
"aria-disabled",
|
|
2731
|
+
"aria-expanded",
|
|
2732
|
+
"aria-haspopup",
|
|
2733
|
+
"id",
|
|
2734
|
+
"style",
|
|
2735
|
+
"tabindex"
|
|
2736
|
+
]
|
|
2737
|
+
);
|
|
2738
|
+
const id = Math.random().toString(36).slice(-8);
|
|
2739
|
+
this.#listElement.id ||= `menu-list-${id}`;
|
|
2740
|
+
addTokenToAttribute(
|
|
2741
|
+
this.#triggerElement,
|
|
2742
|
+
"aria-controls",
|
|
2743
|
+
this.#listElement.id
|
|
2744
|
+
);
|
|
2745
|
+
this.#triggerElement.setAttribute("aria-expanded", "false");
|
|
2746
|
+
this.#triggerElement.setAttribute("aria-haspopup", "true");
|
|
2747
|
+
this.#triggerElement.id ||= `menu-trigger-${id}`;
|
|
2748
|
+
this.#triggerElement.setAttribute(
|
|
2749
|
+
"tabindex",
|
|
2750
|
+
isFocusable3(this.#triggerElement) && !this.#isSubmenu ? "0" : "-1"
|
|
2751
|
+
);
|
|
2752
|
+
if (!isFocusable3(this.#triggerElement)) {
|
|
2753
|
+
this.#triggerElement.setAttribute("aria-disabled", "true");
|
|
2754
|
+
this.#triggerElement.style.setProperty("pointer-events", "none");
|
|
2755
|
+
}
|
|
2756
|
+
this.#triggerElement.addEventListener("click", this.#onTriggerClick, {
|
|
2757
|
+
signal
|
|
2758
|
+
});
|
|
2759
|
+
this.#triggerElement.addEventListener("keydown", this.#onTriggerKeyDown, {
|
|
2760
|
+
signal
|
|
2761
|
+
});
|
|
2762
|
+
addTokenToAttribute(
|
|
2763
|
+
this.#listElement,
|
|
2764
|
+
"aria-labelledby",
|
|
2765
|
+
this.#triggerElement.id
|
|
2766
|
+
);
|
|
2767
|
+
}
|
|
2768
|
+
this.#listElement.setAttribute("role", "menu");
|
|
2769
|
+
this.#listElement.addEventListener("keydown", this.#onListKeyDown, {
|
|
2770
|
+
signal
|
|
2771
|
+
});
|
|
2772
|
+
saveAttributes(this.#itemElements, [
|
|
2773
|
+
"aria-disabled",
|
|
2774
|
+
"data-menu-disabled",
|
|
2775
|
+
"role",
|
|
2776
|
+
"style",
|
|
2777
|
+
"tabindex"
|
|
2778
|
+
]);
|
|
2779
|
+
this.#itemElements.forEach((item2) => {
|
|
2780
|
+
const parent = item2.parentElement;
|
|
2781
|
+
if (parent?.querySelector(this.#settings.selector.list)) {
|
|
2782
|
+
this.#submenus.push(
|
|
2783
|
+
new _Menu(parent, this.#settings, {
|
|
2784
|
+
isSubmenu: true,
|
|
2785
|
+
isPortal: !!this.#triggerElement
|
|
2786
|
+
})
|
|
2787
|
+
);
|
|
2788
|
+
} else if (item2.hasAttribute("disabled") || item2.tabIndex < 0) {
|
|
2789
|
+
item2.setAttribute("aria-disabled", "true");
|
|
2790
|
+
item2.setAttribute("data-menu-disabled", "");
|
|
2791
|
+
item2.style.setProperty("pointer-events", "none");
|
|
2792
|
+
}
|
|
2793
|
+
[this.#checkboxItemElements, this.#radioItemElements].every(
|
|
2794
|
+
(list2) => !list2.includes(item2)
|
|
2795
|
+
) && item2.setAttribute("role", "menuitem");
|
|
2796
|
+
item2.addEventListener("pointerenter", this.#onItemPointerEnter, {
|
|
2797
|
+
signal
|
|
2798
|
+
});
|
|
2799
|
+
item2.addEventListener("pointerleave", this.#onItemPointerLeave, {
|
|
2800
|
+
signal
|
|
2801
|
+
});
|
|
2802
|
+
});
|
|
2803
|
+
this.#checkboxItemElements.forEach((item2) => {
|
|
2804
|
+
item2.setAttribute("role", "menuitemcheckbox");
|
|
2805
|
+
item2.addEventListener("click", this.#onCheckboxItemClick, { signal });
|
|
2806
|
+
});
|
|
2807
|
+
this.#radioItemElements.forEach((item2) => {
|
|
2808
|
+
item2.setAttribute("role", "menuitemradio");
|
|
2809
|
+
item2.addEventListener("click", this.#onRadioItemClick, { signal });
|
|
2810
|
+
});
|
|
2811
|
+
this.#resetTabIndex();
|
|
2812
|
+
!this.#isSubmenu && this.#rootElement.setAttribute("data-menu-initialized", "");
|
|
2813
|
+
_Menu.#menus.push(this);
|
|
2814
|
+
const { item, list } = this.#settings.selector;
|
|
2815
|
+
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#listElement, {
|
|
2816
|
+
direction: "vertical",
|
|
2817
|
+
selector: `${item}:not(:scope ${list} *, [data-menu-disabled])`,
|
|
2818
|
+
typeahead: true,
|
|
2819
|
+
wrap: true
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
#onOutsidePointerDown = (event) => {
|
|
2823
|
+
if (!this.#triggerElement || this.#includesRoot(event)) {
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
this.#resetTabIndex();
|
|
2827
|
+
this.close();
|
|
2828
|
+
};
|
|
2829
|
+
#onRootFocusIn = (event) => {
|
|
2830
|
+
const target = event.currentTarget;
|
|
2831
|
+
const active = getActiveElement4();
|
|
2832
|
+
if (!(target instanceof HTMLElement) || !(active instanceof HTMLElement)) {
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
!this.#containsRoot(target) && !this.#containsRoot(active) && this.#resetTabIndex(true);
|
|
2836
|
+
};
|
|
2837
|
+
#onRootFocusOut = (event) => {
|
|
2838
|
+
const target = event.relatedTarget;
|
|
2839
|
+
if (!(target instanceof HTMLElement) || // Not a type guard
|
|
2840
|
+
!this.#containsRoot(target)) {
|
|
2841
|
+
this.#resetTabIndex();
|
|
2842
|
+
this.close();
|
|
2843
|
+
}
|
|
2844
|
+
};
|
|
2845
|
+
#onTriggerClick = (event) => {
|
|
2846
|
+
event.preventDefault();
|
|
2847
|
+
this.#toggle(
|
|
2848
|
+
!this.#isSubmenu ? this.#triggerElement?.ariaExpanded !== "true" : event.currentTarget === this.#triggerElement
|
|
2849
|
+
);
|
|
2850
|
+
};
|
|
2851
|
+
#onTriggerKeyDown = (event) => {
|
|
2852
|
+
const { key } = event;
|
|
2853
|
+
if (![
|
|
2854
|
+
"Enter",
|
|
2855
|
+
" ",
|
|
2856
|
+
...!this.#isSubmenu ? ["ArrowUp", "ArrowDown"] : ["ArrowRight"]
|
|
2857
|
+
].includes(key)) {
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
event.preventDefault();
|
|
2861
|
+
event.stopPropagation();
|
|
2862
|
+
if (key !== "Enter" && key !== " ") {
|
|
2863
|
+
this.open();
|
|
2864
|
+
}
|
|
2865
|
+
const focusables = this.#itemElements.filter(isFocusable3);
|
|
2866
|
+
let index = 0;
|
|
2867
|
+
switch (key) {
|
|
2868
|
+
case "Enter":
|
|
2869
|
+
case " ":
|
|
2870
|
+
this.#triggerElement?.click();
|
|
2871
|
+
return;
|
|
2872
|
+
case "ArrowUp":
|
|
2873
|
+
index = -1;
|
|
2874
|
+
break;
|
|
2875
|
+
case "ArrowRight":
|
|
2876
|
+
return;
|
|
2877
|
+
case "ArrowDown":
|
|
2878
|
+
index = 0;
|
|
2879
|
+
break;
|
|
2880
|
+
}
|
|
2881
|
+
focusables.at(index)?.focus();
|
|
2882
|
+
};
|
|
2883
|
+
#onListKeyDown = (event) => {
|
|
2884
|
+
const { shiftKey, key } = event;
|
|
2885
|
+
if (key === "Tab" && (!this.#triggerElement && shiftKey || !shiftKey)) {
|
|
2886
|
+
return;
|
|
2887
|
+
}
|
|
2888
|
+
if (shiftKey && key === "Tab") {
|
|
2889
|
+
this.close();
|
|
2890
|
+
requestAnimationFrame(() => this.#triggerElement?.focus());
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
if (![
|
|
2894
|
+
"Enter",
|
|
2895
|
+
"Escape",
|
|
2896
|
+
" ",
|
|
2897
|
+
...this.#isSubmenu ? ["ArrowLeft"] : []
|
|
2898
|
+
].includes(key)) {
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
2901
|
+
event.preventDefault();
|
|
2902
|
+
event.stopPropagation();
|
|
2903
|
+
const active = getActiveElement4();
|
|
2904
|
+
if (!(active instanceof HTMLElement)) {
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
switch (key) {
|
|
2908
|
+
case "Tab":
|
|
2909
|
+
case "Escape":
|
|
2910
|
+
case "ArrowLeft":
|
|
2911
|
+
this.close();
|
|
2912
|
+
return;
|
|
2913
|
+
case "Enter":
|
|
2914
|
+
case " ":
|
|
2915
|
+
active.click();
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
};
|
|
2919
|
+
#onItemPointerEnter = (event) => {
|
|
2920
|
+
this.#clearSubmenuTimer();
|
|
2921
|
+
const item = event.currentTarget;
|
|
2922
|
+
if (!(item instanceof HTMLElement)) {
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
this.#submenuTimer = setTimeout(() => {
|
|
2926
|
+
this.#submenus.forEach((submenu) => {
|
|
2927
|
+
submenu.#toggle(submenu.#triggerElement === item);
|
|
2928
|
+
});
|
|
2929
|
+
item.focus();
|
|
2930
|
+
}, this.#settings.delay);
|
|
2931
|
+
};
|
|
2932
|
+
#onItemPointerLeave = () => {
|
|
2933
|
+
this.#clearSubmenuTimer();
|
|
2934
|
+
};
|
|
2935
|
+
#onCheckboxItemClick = (event) => {
|
|
2936
|
+
const item = event.currentTarget;
|
|
2937
|
+
if (!(item instanceof HTMLElement)) {
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
item.setAttribute("aria-checked", String(item.ariaChecked !== "true"));
|
|
2941
|
+
};
|
|
2942
|
+
#onRadioItemClick = (event) => {
|
|
2943
|
+
const item = event.currentTarget;
|
|
2944
|
+
if (!(item instanceof HTMLElement)) {
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
const group = item.closest(this.#settings.selector.group) ?? this.#rootElement;
|
|
2948
|
+
this.#radioItemElementsByGroup.get(group)?.forEach((i) => {
|
|
2949
|
+
i.setAttribute("aria-checked", String(i === item));
|
|
2950
|
+
});
|
|
2951
|
+
};
|
|
2952
|
+
#toggle(isOpen) {
|
|
2953
|
+
if (this.#triggerElement?.ariaExpanded === String(isOpen)) {
|
|
2954
|
+
return;
|
|
2955
|
+
}
|
|
2956
|
+
this.#triggerElement?.setAttribute("aria-expanded", String(isOpen));
|
|
2957
|
+
if (isOpen) {
|
|
2958
|
+
_Menu.#menus.filter((m) => !m.#containsRoot(this.#rootElement)).forEach((menu) => {
|
|
2959
|
+
menu.close();
|
|
2960
|
+
});
|
|
2961
|
+
if (!this.#listElement) {
|
|
2962
|
+
throw new Error("Unreachable");
|
|
2963
|
+
}
|
|
2964
|
+
if (!this.#isSubmenu && this.#triggerElement || !this.#isPortal) {
|
|
2965
|
+
const style2 = this.#listElement.style;
|
|
2966
|
+
style2.setProperty("position", "fixed");
|
|
2967
|
+
this.#cleanupPortal = createPortal(this.#listElement);
|
|
2968
|
+
requestAnimationFrame(() => style2.removeProperty("position"));
|
|
2969
|
+
}
|
|
2970
|
+
requestAnimationFrame(
|
|
2971
|
+
() => this.#listElement?.setAttribute("data-menu-open", "")
|
|
2972
|
+
);
|
|
2973
|
+
const { style } = this.#listElement;
|
|
2974
|
+
style.setProperty("display", "block");
|
|
2975
|
+
style.setProperty("opacity", "0");
|
|
2976
|
+
this.#triggerElement && this.#updatePopover();
|
|
2977
|
+
this.#itemElements.find(isFocusable3)?.focus();
|
|
2978
|
+
} else {
|
|
2979
|
+
this.#clearSubmenuTimer();
|
|
2980
|
+
const active = getActiveElement4();
|
|
2981
|
+
if (!(active instanceof HTMLElement)) {
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
this.#triggerElement && this.#containsRoot(active) && this.#triggerElement.focus();
|
|
2985
|
+
}
|
|
2986
|
+
if (!this.#triggerElement) {
|
|
2987
|
+
return;
|
|
2988
|
+
}
|
|
2989
|
+
if (!this.#listElement) {
|
|
2990
|
+
throw new Error("Unreachable");
|
|
2991
|
+
}
|
|
2992
|
+
if (!isOpen) {
|
|
2993
|
+
this.#listElement.removeAttribute("data-menu-open");
|
|
2994
|
+
this.#cleanupPopover?.();
|
|
2995
|
+
this.#cleanupPopover = null;
|
|
2996
|
+
}
|
|
2997
|
+
const opacity = getComputedStyle(this.#listElement).getPropertyValue(
|
|
2998
|
+
"opacity"
|
|
2999
|
+
);
|
|
3000
|
+
this.#animation?.cancel();
|
|
3001
|
+
this.#animation = this.#listElement.animate(
|
|
3002
|
+
{ opacity: isOpen ? [opacity, "1"] : [opacity, "0"] },
|
|
3003
|
+
{ duration: this.#settings.animation.duration, easing: "ease" }
|
|
3004
|
+
);
|
|
3005
|
+
const cleanupAnimation = () => {
|
|
3006
|
+
this.#animation = null;
|
|
3007
|
+
};
|
|
3008
|
+
const { signal } = this.#controller ?? new AbortController();
|
|
3009
|
+
this.#animation.addEventListener("cancel", cleanupAnimation, {
|
|
3010
|
+
once: true,
|
|
3011
|
+
signal
|
|
3012
|
+
});
|
|
3013
|
+
this.#animation.addEventListener(
|
|
3014
|
+
"finish",
|
|
3015
|
+
() => {
|
|
3016
|
+
cleanupAnimation();
|
|
3017
|
+
if (!this.#listElement) {
|
|
3018
|
+
throw new Error("Unreachable");
|
|
3019
|
+
}
|
|
3020
|
+
const { style } = this.#listElement;
|
|
3021
|
+
if (!isOpen) {
|
|
3022
|
+
this.#cleanupPortal?.();
|
|
3023
|
+
this.#cleanupPortal = null;
|
|
3024
|
+
this.#listElement.removeAttribute("data-menu-placement");
|
|
3025
|
+
style.setProperty("display", "none");
|
|
3026
|
+
["left", "top", "transform-origin"].forEach((name) => {
|
|
3027
|
+
style.removeProperty(name);
|
|
3028
|
+
});
|
|
3029
|
+
if (this.#arrowElement) {
|
|
3030
|
+
["left", "top", "rotate"].forEach((name) => {
|
|
3031
|
+
this.#arrowElement?.style.removeProperty(name);
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
style.removeProperty("opacity");
|
|
3036
|
+
},
|
|
3037
|
+
{ once: true, signal }
|
|
3038
|
+
);
|
|
3039
|
+
}
|
|
3040
|
+
#clearSubmenuTimer() {
|
|
3041
|
+
if (this.#submenuTimer !== void 0) {
|
|
3042
|
+
clearTimeout(this.#submenuTimer);
|
|
3043
|
+
this.#submenuTimer = void 0;
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
#containsRoot(element) {
|
|
3047
|
+
return this.#rootElement.contains(element) || this.#listElement?.contains(element);
|
|
3048
|
+
}
|
|
3049
|
+
#includesRoot(event) {
|
|
3050
|
+
const path = event.composedPath();
|
|
3051
|
+
if (!this.#listElement) {
|
|
3052
|
+
return false;
|
|
3053
|
+
}
|
|
3054
|
+
return path.includes(this.#rootElement) || path.includes(this.#listElement);
|
|
3055
|
+
}
|
|
3056
|
+
#mergeOptions(target, source) {
|
|
3057
|
+
return {
|
|
3058
|
+
...target,
|
|
3059
|
+
...source,
|
|
3060
|
+
animation: { ...target.animation, ...source.animation ?? {} },
|
|
3061
|
+
popover: {
|
|
3062
|
+
...target.popover,
|
|
3063
|
+
...source.popover ?? {},
|
|
3064
|
+
menu: {
|
|
3065
|
+
...target.popover?.menu,
|
|
3066
|
+
...source.popover?.menu ?? {},
|
|
3067
|
+
middleware: Object.assign(
|
|
3068
|
+
[...target.popover?.menu?.middleware ?? []],
|
|
3069
|
+
[...source.popover?.menu?.middleware ?? []]
|
|
3070
|
+
)
|
|
3071
|
+
},
|
|
3072
|
+
submenu: {
|
|
3073
|
+
...target.popover?.submenu,
|
|
3074
|
+
...source.popover?.submenu ?? {},
|
|
3075
|
+
middleware: Object.assign(
|
|
3076
|
+
[...target.popover?.submenu?.middleware ?? []],
|
|
3077
|
+
[...source.popover?.submenu?.middleware ?? []]
|
|
3078
|
+
)
|
|
3079
|
+
}
|
|
3080
|
+
},
|
|
3081
|
+
selector: { ...target.selector, ...source.selector ?? {} }
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
#resetTabIndex(isForce = false) {
|
|
3085
|
+
if (this.#triggerElement || isForce) {
|
|
3086
|
+
this.#itemElements.forEach((item) => {
|
|
3087
|
+
item.setAttribute("tabindex", "-1");
|
|
3088
|
+
});
|
|
3089
|
+
} else {
|
|
3090
|
+
let isFound = false;
|
|
3091
|
+
this.#itemElements.forEach((item) => {
|
|
3092
|
+
if (!isFound && isFocusable3(item)) {
|
|
3093
|
+
isFound = true;
|
|
3094
|
+
item.setAttribute("tabindex", "0");
|
|
3095
|
+
} else {
|
|
3096
|
+
item.setAttribute("tabindex", "-1");
|
|
3097
|
+
}
|
|
3098
|
+
});
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
#updatePopover() {
|
|
3102
|
+
if (!this.#triggerElement) {
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
3105
|
+
const compute = () => {
|
|
3106
|
+
if (!this.#triggerElement || !this.#listElement) {
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
const options = this.#settings.popover[!this.#isSubmenu ? "menu" : "submenu"];
|
|
3110
|
+
computePosition2(this.#triggerElement, this.#listElement, {
|
|
3111
|
+
...options,
|
|
3112
|
+
placement: options.placement
|
|
3113
|
+
}).then(
|
|
3114
|
+
({
|
|
3115
|
+
x: listX,
|
|
3116
|
+
y: listY,
|
|
3117
|
+
placement,
|
|
3118
|
+
middlewareData
|
|
3119
|
+
}) => {
|
|
3120
|
+
if (!this.#listElement) {
|
|
3121
|
+
throw new Error("Unreachable");
|
|
3122
|
+
}
|
|
3123
|
+
const { style: listStyle } = this.#listElement;
|
|
3124
|
+
listStyle.setProperty("left", `${listX}px`);
|
|
3125
|
+
listStyle.setProperty("top", `${listY}px`);
|
|
3126
|
+
this.#listElement.setAttribute("data-menu-placement", placement);
|
|
3127
|
+
if (this.#settings.popover.transformOrigin) {
|
|
3128
|
+
listStyle.setProperty(
|
|
3129
|
+
"transform-origin",
|
|
3130
|
+
{
|
|
3131
|
+
top: "50% 100%",
|
|
3132
|
+
"top-start": "0 100%",
|
|
3133
|
+
"top-end": "100% 100%",
|
|
3134
|
+
right: "0 50%",
|
|
3135
|
+
"right-start": "0 0",
|
|
3136
|
+
"right-end": "0 100%",
|
|
3137
|
+
bottom: "50% 0",
|
|
3138
|
+
"bottom-start": "0 0",
|
|
3139
|
+
"bottom-end": "100% 0",
|
|
3140
|
+
left: "100% 50%",
|
|
3141
|
+
"left-start": "100% 0",
|
|
3142
|
+
"left-end": "100% 100%"
|
|
3143
|
+
}[placement]
|
|
3144
|
+
);
|
|
3145
|
+
}
|
|
3146
|
+
if (!this.#arrowElement) {
|
|
3147
|
+
return;
|
|
3148
|
+
}
|
|
3149
|
+
const arrowX = middlewareData.arrow?.x;
|
|
3150
|
+
const arrowY = middlewareData.arrow?.y;
|
|
3151
|
+
const { style: arrowStyle } = this.#arrowElement;
|
|
3152
|
+
arrowStyle.setProperty("left", arrowX ? `${arrowX}px` : "");
|
|
3153
|
+
arrowStyle.setProperty(
|
|
3154
|
+
"top",
|
|
3155
|
+
arrowY ? `${arrowY - this.#arrowElement.offsetHeight / 2}px` : ""
|
|
3156
|
+
);
|
|
3157
|
+
const side = placement.split("-")[0];
|
|
3158
|
+
if (!side) {
|
|
3159
|
+
return;
|
|
3160
|
+
}
|
|
3161
|
+
const styles = {
|
|
3162
|
+
top: { position: "bottom", rotate: "225deg" },
|
|
3163
|
+
right: { position: "left", rotate: "315deg" },
|
|
3164
|
+
bottom: { position: "top", rotate: "45deg" },
|
|
3165
|
+
left: { position: "right", rotate: "135deg" }
|
|
3166
|
+
}[side];
|
|
3167
|
+
if (!styles) {
|
|
3168
|
+
return;
|
|
3169
|
+
}
|
|
3170
|
+
arrowStyle.setProperty(
|
|
3171
|
+
styles.position,
|
|
3172
|
+
`${this.#arrowElement.offsetWidth / -2}px`
|
|
3173
|
+
);
|
|
3174
|
+
arrowStyle.setProperty("rotate", styles.rotate);
|
|
3175
|
+
}
|
|
3176
|
+
);
|
|
3177
|
+
};
|
|
3178
|
+
compute();
|
|
3179
|
+
if (!this.#cleanupPopover) {
|
|
3180
|
+
this.#cleanupPopover = autoUpdate(
|
|
3181
|
+
this.#triggerElement,
|
|
3182
|
+
this.#listElement,
|
|
3183
|
+
compute
|
|
3184
|
+
);
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
};
|
|
3188
|
+
function getActiveElement4() {
|
|
3189
|
+
let current = document.activeElement;
|
|
3190
|
+
while (current?.shadowRoot?.activeElement) {
|
|
3191
|
+
current = current.shadowRoot.activeElement;
|
|
3192
|
+
}
|
|
3193
|
+
return current;
|
|
3194
|
+
}
|
|
3195
|
+
function isFocusable3(element) {
|
|
3196
|
+
return !element.hasAttribute("data-menu-disabled") && !element.hasAttribute("disabled");
|
|
3197
|
+
}
|
|
3198
|
+
/**
|
|
3199
|
+
* Menu
|
|
3200
|
+
* WAI-ARIA compliant menu (menu button) pattern implementation in TypeScript.
|
|
3201
|
+
* Supports checkbox item, radio item, and infinitely nested menus.
|
|
3202
|
+
*
|
|
3203
|
+
* @version 1.4.0
|
|
3204
|
+
* @author Yusuke Kamiyamane
|
|
3205
|
+
* @license MIT
|
|
3206
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3207
|
+
* @see {@link https://github.com/y14e/menu}
|
|
3208
|
+
*/
|
|
3209
|
+
/*! Bundled license information:
|
|
3210
|
+
|
|
3211
|
+
@y14e/attributes-utils/dist/index.js:
|
|
3212
|
+
(**
|
|
3213
|
+
* Attributes Utils
|
|
3214
|
+
*
|
|
3215
|
+
* @version 1.1.0
|
|
3216
|
+
* @author Yusuke Kamiyamane
|
|
3217
|
+
* @license MIT
|
|
3218
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3219
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
3220
|
+
*)
|
|
3221
|
+
|
|
3222
|
+
@y14e/portal/dist/index.js:
|
|
3223
|
+
(**
|
|
3224
|
+
* Portal
|
|
3225
|
+
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
3226
|
+
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
3227
|
+
*
|
|
3228
|
+
* @version 1.2.9
|
|
3229
|
+
* @author Yusuke Kamiyamane
|
|
3230
|
+
* @license MIT
|
|
3231
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3232
|
+
* @see {@link https://github.com/y14e/portal}
|
|
3233
|
+
*)
|
|
3234
|
+
(*! Bundled license information:
|
|
3235
|
+
|
|
3236
|
+
@y14e/attributes-utils/dist/index.js:
|
|
3237
|
+
(**
|
|
3238
|
+
* Attributes Utils
|
|
3239
|
+
*
|
|
3240
|
+
* @version 1.1.0
|
|
3241
|
+
* @author Yusuke Kamiyamane
|
|
3242
|
+
* @license MIT
|
|
3243
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3244
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
3245
|
+
*)
|
|
3246
|
+
|
|
3247
|
+
power-focusable/dist/index.js:
|
|
3248
|
+
(**
|
|
3249
|
+
* Power Focusable
|
|
3250
|
+
* High-precision focus management utility with full composed tree support.
|
|
3251
|
+
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
3252
|
+
*
|
|
3253
|
+
* @version 4.3.1
|
|
3254
|
+
* @author Yusuke Kamiyamane
|
|
3255
|
+
* @license MIT
|
|
3256
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3257
|
+
* @see {@link https://github.com/y14e/power-focusable}
|
|
3258
|
+
*)
|
|
3259
|
+
*)
|
|
3260
|
+
|
|
3261
|
+
@y14e/roving-tabindex/dist/index.js:
|
|
3262
|
+
(**
|
|
3263
|
+
* Roving Tabindex
|
|
3264
|
+
* Lightweight roving tabindex utility with fully focus management.
|
|
3265
|
+
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
3266
|
+
*
|
|
3267
|
+
* @version 2.0.6
|
|
3268
|
+
* @author Yusuke Kamiyamane
|
|
3269
|
+
* @license MIT
|
|
3270
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3271
|
+
* @see {@link https://github.com/y14e/roving-tabindex}
|
|
3272
|
+
*)
|
|
3273
|
+
(*! Bundled license information:
|
|
3274
|
+
|
|
3275
|
+
@y14e/attributes-utils/dist/index.js:
|
|
3276
|
+
(**
|
|
3277
|
+
* Attributes Utils
|
|
3278
|
+
*
|
|
3279
|
+
* @version 1.1.0
|
|
3280
|
+
* @author Yusuke Kamiyamane
|
|
3281
|
+
* @license MIT
|
|
3282
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3283
|
+
* @see {@link https://github.com/y14e/attributes-utils}
|
|
3284
|
+
*)
|
|
3285
|
+
|
|
3286
|
+
power-focusable/dist/index.js:
|
|
3287
|
+
(**
|
|
3288
|
+
* Power Focusable
|
|
3289
|
+
* High-precision focus management utility with full composed tree support.
|
|
3290
|
+
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
3291
|
+
*
|
|
3292
|
+
* @version 4.3.1
|
|
3293
|
+
* @author Yusuke Kamiyamane
|
|
3294
|
+
* @license MIT
|
|
3295
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
3296
|
+
* @see {@link https://github.com/y14e/power-focusable}
|
|
3297
|
+
*)
|
|
3298
|
+
*)
|
|
3299
|
+
*/
|
|
3300
|
+
|
|
3301
|
+
module.exports = Menu;
|