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