@y14e/path-bar 1.0.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,4559 @@
1
+ // node_modules/@y14e/menu/dist/index.js
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
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
129
+ let {
130
+ reference,
131
+ floating
132
+ } = _ref;
133
+ const sideAxis = getSideAxis(placement);
134
+ const alignmentAxis = getAlignmentAxis(placement);
135
+ const alignLength = getAxisLength(alignmentAxis);
136
+ const side = getSide(placement);
137
+ const isVertical = sideAxis === "y";
138
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
139
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
140
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
141
+ let coords;
142
+ switch (side) {
143
+ case "top":
144
+ coords = {
145
+ x: commonX,
146
+ y: reference.y - floating.height
147
+ };
148
+ break;
149
+ case "bottom":
150
+ coords = {
151
+ x: commonX,
152
+ y: reference.y + reference.height
153
+ };
154
+ break;
155
+ case "right":
156
+ coords = {
157
+ x: reference.x + reference.width,
158
+ y: commonY
159
+ };
160
+ break;
161
+ case "left":
162
+ coords = {
163
+ x: reference.x - floating.width,
164
+ y: commonY
165
+ };
166
+ break;
167
+ default:
168
+ coords = {
169
+ x: reference.x,
170
+ y: reference.y
171
+ };
172
+ }
173
+ switch (getAlignment(placement)) {
174
+ case "start":
175
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
176
+ break;
177
+ case "end":
178
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
179
+ break;
180
+ }
181
+ return coords;
182
+ }
183
+ async function detectOverflow(state, options) {
184
+ var _await$platform$isEle;
185
+ if (options === void 0) {
186
+ options = {};
187
+ }
188
+ const {
189
+ x,
190
+ y,
191
+ platform: platform2,
192
+ rects,
193
+ elements,
194
+ strategy
195
+ } = state;
196
+ const {
197
+ boundary = "clippingAncestors",
198
+ rootBoundary = "viewport",
199
+ elementContext = "floating",
200
+ altBoundary = false,
201
+ padding = 0
202
+ } = evaluate(options, state);
203
+ const paddingObject = getPaddingObject(padding);
204
+ const altContext = elementContext === "floating" ? "reference" : "floating";
205
+ const element = elements[altBoundary ? altContext : elementContext];
206
+ const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
207
+ 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)),
208
+ boundary,
209
+ rootBoundary,
210
+ strategy
211
+ }));
212
+ const rect = elementContext === "floating" ? {
213
+ x,
214
+ y,
215
+ width: rects.floating.width,
216
+ height: rects.floating.height
217
+ } : rects.reference;
218
+ const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
219
+ const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
220
+ x: 1,
221
+ y: 1
222
+ } : {
223
+ x: 1,
224
+ y: 1
225
+ };
226
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
227
+ elements,
228
+ rect,
229
+ offsetParent,
230
+ strategy
231
+ }) : rect);
232
+ return {
233
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
234
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
235
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
236
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
237
+ };
238
+ }
239
+ var MAX_RESET_COUNT = 50;
240
+ var computePosition = async (reference, floating, config) => {
241
+ const {
242
+ placement = "bottom",
243
+ strategy = "absolute",
244
+ middleware = [],
245
+ platform: platform2
246
+ } = config;
247
+ const platformWithDetectOverflow = platform2.detectOverflow ? platform2 : {
248
+ ...platform2,
249
+ detectOverflow
250
+ };
251
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
252
+ let rects = await platform2.getElementRects({
253
+ reference,
254
+ floating,
255
+ strategy
256
+ });
257
+ let {
258
+ x,
259
+ y
260
+ } = computeCoordsFromPlacement(rects, placement, rtl);
261
+ let statefulPlacement = placement;
262
+ let resetCount = 0;
263
+ const middlewareData = {};
264
+ for (let i = 0; i < middleware.length; i++) {
265
+ const currentMiddleware = middleware[i];
266
+ if (!currentMiddleware) {
267
+ continue;
268
+ }
269
+ const {
270
+ name,
271
+ fn
272
+ } = currentMiddleware;
273
+ const {
274
+ x: nextX,
275
+ y: nextY,
276
+ data,
277
+ reset
278
+ } = await fn({
279
+ x,
280
+ y,
281
+ initialPlacement: placement,
282
+ placement: statefulPlacement,
283
+ strategy,
284
+ middlewareData,
285
+ rects,
286
+ platform: platformWithDetectOverflow,
287
+ elements: {
288
+ reference,
289
+ floating
290
+ }
291
+ });
292
+ x = nextX != null ? nextX : x;
293
+ y = nextY != null ? nextY : y;
294
+ middlewareData[name] = {
295
+ ...middlewareData[name],
296
+ ...data
297
+ };
298
+ if (reset && resetCount < MAX_RESET_COUNT) {
299
+ resetCount++;
300
+ if (typeof reset === "object") {
301
+ if (reset.placement) {
302
+ statefulPlacement = reset.placement;
303
+ }
304
+ if (reset.rects) {
305
+ rects = reset.rects === true ? await platform2.getElementRects({
306
+ reference,
307
+ floating,
308
+ strategy
309
+ }) : reset.rects;
310
+ }
311
+ ({
312
+ x,
313
+ y
314
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
315
+ }
316
+ i = -1;
317
+ }
318
+ }
319
+ return {
320
+ x,
321
+ y,
322
+ placement: statefulPlacement,
323
+ strategy,
324
+ middlewareData
325
+ };
326
+ };
327
+ var arrow = (options) => ({
328
+ name: "arrow",
329
+ options,
330
+ async fn(state) {
331
+ const {
332
+ x,
333
+ y,
334
+ placement,
335
+ rects,
336
+ platform: platform2,
337
+ elements,
338
+ middlewareData
339
+ } = state;
340
+ const {
341
+ element,
342
+ padding = 0
343
+ } = evaluate(options, state) || {};
344
+ if (element == null) {
345
+ return {};
346
+ }
347
+ const paddingObject = getPaddingObject(padding);
348
+ const coords = {
349
+ x,
350
+ y
351
+ };
352
+ const axis = getAlignmentAxis(placement);
353
+ const length = getAxisLength(axis);
354
+ const arrowDimensions = await platform2.getDimensions(element);
355
+ const isYAxis = axis === "y";
356
+ const minProp = isYAxis ? "top" : "left";
357
+ const maxProp = isYAxis ? "bottom" : "right";
358
+ const clientProp = isYAxis ? "clientHeight" : "clientWidth";
359
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
360
+ const startDiff = coords[axis] - rects.reference[axis];
361
+ const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element));
362
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
363
+ if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) {
364
+ clientSize = elements.floating[clientProp] || rects.floating[length];
365
+ }
366
+ const centerToReference = endDiff / 2 - startDiff / 2;
367
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
368
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
369
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
370
+ const min$1 = minPadding;
371
+ const max2 = clientSize - arrowDimensions[length] - maxPadding;
372
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
373
+ const offset3 = clamp(min$1, center, max2);
374
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset3 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
375
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
376
+ return {
377
+ [axis]: coords[axis] + alignmentOffset,
378
+ data: {
379
+ [axis]: offset3,
380
+ centerOffset: center - offset3 - alignmentOffset,
381
+ ...shouldAddOffset && {
382
+ alignmentOffset
383
+ }
384
+ },
385
+ reset: shouldAddOffset
386
+ };
387
+ }
388
+ });
389
+ var flip = function(options) {
390
+ if (options === void 0) {
391
+ options = {};
392
+ }
393
+ return {
394
+ name: "flip",
395
+ options,
396
+ async fn(state) {
397
+ var _middlewareData$arrow, _middlewareData$flip;
398
+ const {
399
+ placement,
400
+ middlewareData,
401
+ rects,
402
+ initialPlacement,
403
+ platform: platform2,
404
+ elements
405
+ } = state;
406
+ const {
407
+ mainAxis: checkMainAxis = true,
408
+ crossAxis: checkCrossAxis = true,
409
+ fallbackPlacements: specifiedFallbackPlacements,
410
+ fallbackStrategy = "bestFit",
411
+ fallbackAxisSideDirection = "none",
412
+ flipAlignment = true,
413
+ ...detectOverflowOptions
414
+ } = evaluate(options, state);
415
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
416
+ return {};
417
+ }
418
+ const side = getSide(placement);
419
+ const initialSideAxis = getSideAxis(initialPlacement);
420
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
421
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
422
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
423
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
424
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
425
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
426
+ }
427
+ const placements2 = [initialPlacement, ...fallbackPlacements];
428
+ const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
429
+ const overflows = [];
430
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
431
+ if (checkMainAxis) {
432
+ overflows.push(overflow[side]);
433
+ }
434
+ if (checkCrossAxis) {
435
+ const sides2 = getAlignmentSides(placement, rects, rtl);
436
+ overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
437
+ }
438
+ overflowsData = [...overflowsData, {
439
+ placement,
440
+ overflows
441
+ }];
442
+ if (!overflows.every((side2) => side2 <= 0)) {
443
+ var _middlewareData$flip2, _overflowsData$filter;
444
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
445
+ const nextPlacement = placements2[nextIndex];
446
+ if (nextPlacement) {
447
+ const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
448
+ if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
449
+ // overflows the main axis.
450
+ overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
451
+ return {
452
+ data: {
453
+ index: nextIndex,
454
+ overflows: overflowsData
455
+ },
456
+ reset: {
457
+ placement: nextPlacement
458
+ }
459
+ };
460
+ }
461
+ }
462
+ 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;
463
+ if (!resetPlacement) {
464
+ switch (fallbackStrategy) {
465
+ case "bestFit": {
466
+ var _overflowsData$filter2;
467
+ const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
468
+ if (hasFallbackAxisSideDirection) {
469
+ const currentSideAxis = getSideAxis(d.placement);
470
+ return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
471
+ // reading directions favoring greater width.
472
+ currentSideAxis === "y";
473
+ }
474
+ return true;
475
+ }).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];
476
+ if (placement2) {
477
+ resetPlacement = placement2;
478
+ }
479
+ break;
480
+ }
481
+ case "initialPlacement":
482
+ resetPlacement = initialPlacement;
483
+ break;
484
+ }
485
+ }
486
+ if (placement !== resetPlacement) {
487
+ return {
488
+ reset: {
489
+ placement: resetPlacement
490
+ }
491
+ };
492
+ }
493
+ }
494
+ return {};
495
+ }
496
+ };
497
+ };
498
+ var originSides = /* @__PURE__ */ new Set(["left", "top"]);
499
+ async function convertValueToCoords(state, options) {
500
+ const {
501
+ placement,
502
+ platform: platform2,
503
+ elements
504
+ } = state;
505
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
506
+ const side = getSide(placement);
507
+ const alignment = getAlignment(placement);
508
+ const isVertical = getSideAxis(placement) === "y";
509
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
510
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
511
+ const rawValue = evaluate(options, state);
512
+ let {
513
+ mainAxis,
514
+ crossAxis,
515
+ alignmentAxis
516
+ } = typeof rawValue === "number" ? {
517
+ mainAxis: rawValue,
518
+ crossAxis: 0,
519
+ alignmentAxis: null
520
+ } : {
521
+ mainAxis: rawValue.mainAxis || 0,
522
+ crossAxis: rawValue.crossAxis || 0,
523
+ alignmentAxis: rawValue.alignmentAxis
524
+ };
525
+ if (alignment && typeof alignmentAxis === "number") {
526
+ crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
527
+ }
528
+ return isVertical ? {
529
+ x: crossAxis * crossAxisMulti,
530
+ y: mainAxis * mainAxisMulti
531
+ } : {
532
+ x: mainAxis * mainAxisMulti,
533
+ y: crossAxis * crossAxisMulti
534
+ };
535
+ }
536
+ var offset = function(options) {
537
+ if (options === void 0) {
538
+ options = 0;
539
+ }
540
+ return {
541
+ name: "offset",
542
+ options,
543
+ async fn(state) {
544
+ var _middlewareData$offse, _middlewareData$arrow;
545
+ const {
546
+ x,
547
+ y,
548
+ placement,
549
+ middlewareData
550
+ } = state;
551
+ const diffCoords = await convertValueToCoords(state, options);
552
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
553
+ return {};
554
+ }
555
+ return {
556
+ x: x + diffCoords.x,
557
+ y: y + diffCoords.y,
558
+ data: {
559
+ ...diffCoords,
560
+ placement
561
+ }
562
+ };
563
+ }
564
+ };
565
+ };
566
+ var shift = function(options) {
567
+ if (options === void 0) {
568
+ options = {};
569
+ }
570
+ return {
571
+ name: "shift",
572
+ options,
573
+ async fn(state) {
574
+ const {
575
+ x,
576
+ y,
577
+ placement,
578
+ platform: platform2
579
+ } = state;
580
+ const {
581
+ mainAxis: checkMainAxis = true,
582
+ crossAxis: checkCrossAxis = false,
583
+ limiter = {
584
+ fn: (_ref) => {
585
+ let {
586
+ x: x2,
587
+ y: y2
588
+ } = _ref;
589
+ return {
590
+ x: x2,
591
+ y: y2
592
+ };
593
+ }
594
+ },
595
+ ...detectOverflowOptions
596
+ } = evaluate(options, state);
597
+ const coords = {
598
+ x,
599
+ y
600
+ };
601
+ const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
602
+ const crossAxis = getSideAxis(getSide(placement));
603
+ const mainAxis = getOppositeAxis(crossAxis);
604
+ let mainAxisCoord = coords[mainAxis];
605
+ let crossAxisCoord = coords[crossAxis];
606
+ if (checkMainAxis) {
607
+ const minSide = mainAxis === "y" ? "top" : "left";
608
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
609
+ const min2 = mainAxisCoord + overflow[minSide];
610
+ const max2 = mainAxisCoord - overflow[maxSide];
611
+ mainAxisCoord = clamp(min2, mainAxisCoord, max2);
612
+ }
613
+ if (checkCrossAxis) {
614
+ const minSide = crossAxis === "y" ? "top" : "left";
615
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
616
+ const min2 = crossAxisCoord + overflow[minSide];
617
+ const max2 = crossAxisCoord - overflow[maxSide];
618
+ crossAxisCoord = clamp(min2, crossAxisCoord, max2);
619
+ }
620
+ const limitedCoords = limiter.fn({
621
+ ...state,
622
+ [mainAxis]: mainAxisCoord,
623
+ [crossAxis]: crossAxisCoord
624
+ });
625
+ return {
626
+ ...limitedCoords,
627
+ data: {
628
+ x: limitedCoords.x - x,
629
+ y: limitedCoords.y - y,
630
+ enabled: {
631
+ [mainAxis]: checkMainAxis,
632
+ [crossAxis]: checkCrossAxis
633
+ }
634
+ }
635
+ };
636
+ }
637
+ };
638
+ };
639
+ function hasWindow() {
640
+ return typeof window !== "undefined";
641
+ }
642
+ function getNodeName(node) {
643
+ if (isNode(node)) {
644
+ return (node.nodeName || "").toLowerCase();
645
+ }
646
+ return "#document";
647
+ }
648
+ function getWindow(node) {
649
+ var _node$ownerDocument;
650
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
651
+ }
652
+ function getDocumentElement(node) {
653
+ var _ref;
654
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
655
+ }
656
+ function isNode(value) {
657
+ if (!hasWindow()) {
658
+ return false;
659
+ }
660
+ return value instanceof Node || value instanceof getWindow(value).Node;
661
+ }
662
+ function isElement(value) {
663
+ if (!hasWindow()) {
664
+ return false;
665
+ }
666
+ return value instanceof Element || value instanceof getWindow(value).Element;
667
+ }
668
+ function isHTMLElement(value) {
669
+ if (!hasWindow()) {
670
+ return false;
671
+ }
672
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
673
+ }
674
+ function isShadowRoot(value) {
675
+ if (!hasWindow() || typeof ShadowRoot === "undefined") {
676
+ return false;
677
+ }
678
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
679
+ }
680
+ function isOverflowElement(element) {
681
+ const {
682
+ overflow,
683
+ overflowX,
684
+ overflowY,
685
+ display
686
+ } = getComputedStyle2(element);
687
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== "inline" && display !== "contents";
688
+ }
689
+ function isTableElement(element) {
690
+ return /^(table|td|th)$/.test(getNodeName(element));
691
+ }
692
+ function isTopLayer(element) {
693
+ try {
694
+ if (element.matches(":popover-open")) {
695
+ return true;
696
+ }
697
+ } catch (_e) {
698
+ }
699
+ try {
700
+ return element.matches(":modal");
701
+ } catch (_e) {
702
+ return false;
703
+ }
704
+ }
705
+ var willChangeRe = /transform|translate|scale|rotate|perspective|filter/;
706
+ var containRe = /paint|layout|strict|content/;
707
+ var isNotNone = (value) => !!value && value !== "none";
708
+ var isWebKitValue;
709
+ function isContainingBlock(elementOrCss) {
710
+ const css = isElement(elementOrCss) ? getComputedStyle2(elementOrCss) : elementOrCss;
711
+ 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 || "");
712
+ }
713
+ function getContainingBlock(element) {
714
+ let currentNode = getParentNode(element);
715
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
716
+ if (isContainingBlock(currentNode)) {
717
+ return currentNode;
718
+ } else if (isTopLayer(currentNode)) {
719
+ return null;
720
+ }
721
+ currentNode = getParentNode(currentNode);
722
+ }
723
+ return null;
724
+ }
725
+ function isWebKit() {
726
+ if (isWebKitValue == null) {
727
+ isWebKitValue = typeof CSS !== "undefined" && CSS.supports && CSS.supports("-webkit-backdrop-filter", "none");
728
+ }
729
+ return isWebKitValue;
730
+ }
731
+ function isLastTraversableNode(node) {
732
+ return /^(html|body|#document)$/.test(getNodeName(node));
733
+ }
734
+ function getComputedStyle2(element) {
735
+ return getWindow(element).getComputedStyle(element);
736
+ }
737
+ function getNodeScroll(element) {
738
+ if (isElement(element)) {
739
+ return {
740
+ scrollLeft: element.scrollLeft,
741
+ scrollTop: element.scrollTop
742
+ };
743
+ }
744
+ return {
745
+ scrollLeft: element.scrollX,
746
+ scrollTop: element.scrollY
747
+ };
748
+ }
749
+ function getParentNode(node) {
750
+ if (getNodeName(node) === "html") {
751
+ return node;
752
+ }
753
+ const result = (
754
+ // Step into the shadow DOM of the parent of a slotted node.
755
+ node.assignedSlot || // DOM Element detected.
756
+ node.parentNode || // ShadowRoot detected.
757
+ isShadowRoot(node) && node.host || // Fallback.
758
+ getDocumentElement(node)
759
+ );
760
+ return isShadowRoot(result) ? result.host : result;
761
+ }
762
+ function getNearestOverflowAncestor(node) {
763
+ const parentNode = getParentNode(node);
764
+ if (isLastTraversableNode(parentNode)) {
765
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
766
+ }
767
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
768
+ return parentNode;
769
+ }
770
+ return getNearestOverflowAncestor(parentNode);
771
+ }
772
+ function getOverflowAncestors(node, list, traverseIframes) {
773
+ var _node$ownerDocument2;
774
+ if (list === void 0) {
775
+ list = [];
776
+ }
777
+ if (traverseIframes === void 0) {
778
+ traverseIframes = true;
779
+ }
780
+ const scrollableAncestor = getNearestOverflowAncestor(node);
781
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
782
+ const win = getWindow(scrollableAncestor);
783
+ if (isBody) {
784
+ const frameElement = getFrameElement(win);
785
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
786
+ } else {
787
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
788
+ }
789
+ }
790
+ function getFrameElement(win) {
791
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
792
+ }
793
+ function getCssDimensions(element) {
794
+ const css = getComputedStyle2(element);
795
+ let width = parseFloat(css.width) || 0;
796
+ let height = parseFloat(css.height) || 0;
797
+ const hasOffset = isHTMLElement(element);
798
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
799
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
800
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
801
+ if (shouldFallback) {
802
+ width = offsetWidth;
803
+ height = offsetHeight;
804
+ }
805
+ return {
806
+ width,
807
+ height,
808
+ $: shouldFallback
809
+ };
810
+ }
811
+ function unwrapElement(element) {
812
+ return !isElement(element) ? element.contextElement : element;
813
+ }
814
+ function getScale(element) {
815
+ const domElement = unwrapElement(element);
816
+ if (!isHTMLElement(domElement)) {
817
+ return createCoords(1);
818
+ }
819
+ const rect = domElement.getBoundingClientRect();
820
+ const {
821
+ width,
822
+ height,
823
+ $
824
+ } = getCssDimensions(domElement);
825
+ let x = ($ ? round(rect.width) : rect.width) / width;
826
+ let y = ($ ? round(rect.height) : rect.height) / height;
827
+ if (!x || !Number.isFinite(x)) {
828
+ x = 1;
829
+ }
830
+ if (!y || !Number.isFinite(y)) {
831
+ y = 1;
832
+ }
833
+ return {
834
+ x,
835
+ y
836
+ };
837
+ }
838
+ var noOffsets = /* @__PURE__ */ createCoords(0);
839
+ function getVisualOffsets(element) {
840
+ const win = getWindow(element);
841
+ if (!isWebKit() || !win.visualViewport) {
842
+ return noOffsets;
843
+ }
844
+ return {
845
+ x: win.visualViewport.offsetLeft,
846
+ y: win.visualViewport.offsetTop
847
+ };
848
+ }
849
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
850
+ if (isFixed === void 0) {
851
+ isFixed = false;
852
+ }
853
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
854
+ return false;
855
+ }
856
+ return isFixed;
857
+ }
858
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
859
+ if (includeScale === void 0) {
860
+ includeScale = false;
861
+ }
862
+ if (isFixedStrategy === void 0) {
863
+ isFixedStrategy = false;
864
+ }
865
+ const clientRect = element.getBoundingClientRect();
866
+ const domElement = unwrapElement(element);
867
+ let scale = createCoords(1);
868
+ if (includeScale) {
869
+ if (offsetParent) {
870
+ if (isElement(offsetParent)) {
871
+ scale = getScale(offsetParent);
872
+ }
873
+ } else {
874
+ scale = getScale(element);
875
+ }
876
+ }
877
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
878
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
879
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
880
+ let width = clientRect.width / scale.x;
881
+ let height = clientRect.height / scale.y;
882
+ if (domElement) {
883
+ const win = getWindow(domElement);
884
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
885
+ let currentWin = win;
886
+ let currentIFrame = getFrameElement(currentWin);
887
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
888
+ const iframeScale = getScale(currentIFrame);
889
+ const iframeRect = currentIFrame.getBoundingClientRect();
890
+ const css = getComputedStyle2(currentIFrame);
891
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
892
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
893
+ x *= iframeScale.x;
894
+ y *= iframeScale.y;
895
+ width *= iframeScale.x;
896
+ height *= iframeScale.y;
897
+ x += left;
898
+ y += top;
899
+ currentWin = getWindow(currentIFrame);
900
+ currentIFrame = getFrameElement(currentWin);
901
+ }
902
+ }
903
+ return rectToClientRect({
904
+ width,
905
+ height,
906
+ x,
907
+ y
908
+ });
909
+ }
910
+ function getWindowScrollBarX(element, rect) {
911
+ const leftScroll = getNodeScroll(element).scrollLeft;
912
+ if (!rect) {
913
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
914
+ }
915
+ return rect.left + leftScroll;
916
+ }
917
+ function getHTMLOffset(documentElement, scroll) {
918
+ const htmlRect = documentElement.getBoundingClientRect();
919
+ const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
920
+ const y = htmlRect.top + scroll.scrollTop;
921
+ return {
922
+ x,
923
+ y
924
+ };
925
+ }
926
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
927
+ let {
928
+ elements,
929
+ rect,
930
+ offsetParent,
931
+ strategy
932
+ } = _ref;
933
+ const isFixed = strategy === "fixed";
934
+ const documentElement = getDocumentElement(offsetParent);
935
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
936
+ if (offsetParent === documentElement || topLayer && isFixed) {
937
+ return rect;
938
+ }
939
+ let scroll = {
940
+ scrollLeft: 0,
941
+ scrollTop: 0
942
+ };
943
+ let scale = createCoords(1);
944
+ const offsets = createCoords(0);
945
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
946
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
947
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
948
+ scroll = getNodeScroll(offsetParent);
949
+ }
950
+ if (isOffsetParentAnElement) {
951
+ const offsetRect = getBoundingClientRect(offsetParent);
952
+ scale = getScale(offsetParent);
953
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
954
+ offsets.y = offsetRect.y + offsetParent.clientTop;
955
+ }
956
+ }
957
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
958
+ return {
959
+ width: rect.width * scale.x,
960
+ height: rect.height * scale.y,
961
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
962
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
963
+ };
964
+ }
965
+ function getClientRects(element) {
966
+ return Array.from(element.getClientRects());
967
+ }
968
+ function getDocumentRect(element) {
969
+ const html = getDocumentElement(element);
970
+ const scroll = getNodeScroll(element);
971
+ const body = element.ownerDocument.body;
972
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
973
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
974
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
975
+ const y = -scroll.scrollTop;
976
+ if (getComputedStyle2(body).direction === "rtl") {
977
+ x += max(html.clientWidth, body.clientWidth) - width;
978
+ }
979
+ return {
980
+ width,
981
+ height,
982
+ x,
983
+ y
984
+ };
985
+ }
986
+ var SCROLLBAR_MAX = 25;
987
+ function getViewportRect(element, strategy) {
988
+ const win = getWindow(element);
989
+ const html = getDocumentElement(element);
990
+ const visualViewport = win.visualViewport;
991
+ let width = html.clientWidth;
992
+ let height = html.clientHeight;
993
+ let x = 0;
994
+ let y = 0;
995
+ if (visualViewport) {
996
+ width = visualViewport.width;
997
+ height = visualViewport.height;
998
+ const visualViewportBased = isWebKit();
999
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
1000
+ x = visualViewport.offsetLeft;
1001
+ y = visualViewport.offsetTop;
1002
+ }
1003
+ }
1004
+ const windowScrollbarX = getWindowScrollBarX(html);
1005
+ if (windowScrollbarX <= 0) {
1006
+ const doc = html.ownerDocument;
1007
+ const body = doc.body;
1008
+ const bodyStyles = getComputedStyle(body);
1009
+ const bodyMarginInline = doc.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
1010
+ const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
1011
+ if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
1012
+ width -= clippingStableScrollbarWidth;
1013
+ }
1014
+ } else if (windowScrollbarX <= SCROLLBAR_MAX) {
1015
+ width += windowScrollbarX;
1016
+ }
1017
+ return {
1018
+ width,
1019
+ height,
1020
+ x,
1021
+ y
1022
+ };
1023
+ }
1024
+ function getInnerBoundingClientRect(element, strategy) {
1025
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
1026
+ const top = clientRect.top + element.clientTop;
1027
+ const left = clientRect.left + element.clientLeft;
1028
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1029
+ const width = element.clientWidth * scale.x;
1030
+ const height = element.clientHeight * scale.y;
1031
+ const x = left * scale.x;
1032
+ const y = top * scale.y;
1033
+ return {
1034
+ width,
1035
+ height,
1036
+ x,
1037
+ y
1038
+ };
1039
+ }
1040
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1041
+ let rect;
1042
+ if (clippingAncestor === "viewport") {
1043
+ rect = getViewportRect(element, strategy);
1044
+ } else if (clippingAncestor === "document") {
1045
+ rect = getDocumentRect(getDocumentElement(element));
1046
+ } else if (isElement(clippingAncestor)) {
1047
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1048
+ } else {
1049
+ const visualOffsets = getVisualOffsets(element);
1050
+ rect = {
1051
+ x: clippingAncestor.x - visualOffsets.x,
1052
+ y: clippingAncestor.y - visualOffsets.y,
1053
+ width: clippingAncestor.width,
1054
+ height: clippingAncestor.height
1055
+ };
1056
+ }
1057
+ return rectToClientRect(rect);
1058
+ }
1059
+ function hasFixedPositionAncestor(element, stopNode) {
1060
+ const parentNode = getParentNode(element);
1061
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1062
+ return false;
1063
+ }
1064
+ return getComputedStyle2(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
1065
+ }
1066
+ function getClippingElementAncestors(element, cache) {
1067
+ const cachedResult = cache.get(element);
1068
+ if (cachedResult) {
1069
+ return cachedResult;
1070
+ }
1071
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
1072
+ let currentContainingBlockComputedStyle = null;
1073
+ const elementIsFixed = getComputedStyle2(element).position === "fixed";
1074
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1075
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1076
+ const computedStyle = getComputedStyle2(currentNode);
1077
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1078
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
1079
+ currentContainingBlockComputedStyle = null;
1080
+ }
1081
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === "absolute" || currentContainingBlockComputedStyle.position === "fixed") || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1082
+ if (shouldDropCurrentNode) {
1083
+ result = result.filter((ancestor) => ancestor !== currentNode);
1084
+ } else {
1085
+ currentContainingBlockComputedStyle = computedStyle;
1086
+ }
1087
+ currentNode = getParentNode(currentNode);
1088
+ }
1089
+ cache.set(element, result);
1090
+ return result;
1091
+ }
1092
+ function getClippingRect(_ref) {
1093
+ let {
1094
+ element,
1095
+ boundary,
1096
+ rootBoundary,
1097
+ strategy
1098
+ } = _ref;
1099
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
1100
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1101
+ const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
1102
+ let top = firstRect.top;
1103
+ let right = firstRect.right;
1104
+ let bottom = firstRect.bottom;
1105
+ let left = firstRect.left;
1106
+ for (let i = 1; i < clippingAncestors.length; i++) {
1107
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
1108
+ top = max(rect.top, top);
1109
+ right = min(rect.right, right);
1110
+ bottom = min(rect.bottom, bottom);
1111
+ left = max(rect.left, left);
1112
+ }
1113
+ return {
1114
+ width: right - left,
1115
+ height: bottom - top,
1116
+ x: left,
1117
+ y: top
1118
+ };
1119
+ }
1120
+ function getDimensions(element) {
1121
+ const {
1122
+ width,
1123
+ height
1124
+ } = getCssDimensions(element);
1125
+ return {
1126
+ width,
1127
+ height
1128
+ };
1129
+ }
1130
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1131
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1132
+ const documentElement = getDocumentElement(offsetParent);
1133
+ const isFixed = strategy === "fixed";
1134
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1135
+ let scroll = {
1136
+ scrollLeft: 0,
1137
+ scrollTop: 0
1138
+ };
1139
+ const offsets = createCoords(0);
1140
+ function setLeftRTLScrollbarOffset() {
1141
+ offsets.x = getWindowScrollBarX(documentElement);
1142
+ }
1143
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1144
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
1145
+ scroll = getNodeScroll(offsetParent);
1146
+ }
1147
+ if (isOffsetParentAnElement) {
1148
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1149
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1150
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1151
+ } else if (documentElement) {
1152
+ setLeftRTLScrollbarOffset();
1153
+ }
1154
+ }
1155
+ if (isFixed && !isOffsetParentAnElement && documentElement) {
1156
+ setLeftRTLScrollbarOffset();
1157
+ }
1158
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1159
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
1160
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
1161
+ return {
1162
+ x,
1163
+ y,
1164
+ width: rect.width,
1165
+ height: rect.height
1166
+ };
1167
+ }
1168
+ function isStaticPositioned(element) {
1169
+ return getComputedStyle2(element).position === "static";
1170
+ }
1171
+ function getTrueOffsetParent(element, polyfill) {
1172
+ if (!isHTMLElement(element) || getComputedStyle2(element).position === "fixed") {
1173
+ return null;
1174
+ }
1175
+ if (polyfill) {
1176
+ return polyfill(element);
1177
+ }
1178
+ let rawOffsetParent = element.offsetParent;
1179
+ if (getDocumentElement(element) === rawOffsetParent) {
1180
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
1181
+ }
1182
+ return rawOffsetParent;
1183
+ }
1184
+ function getOffsetParent(element, polyfill) {
1185
+ const win = getWindow(element);
1186
+ if (isTopLayer(element)) {
1187
+ return win;
1188
+ }
1189
+ if (!isHTMLElement(element)) {
1190
+ let svgOffsetParent = getParentNode(element);
1191
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
1192
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
1193
+ return svgOffsetParent;
1194
+ }
1195
+ svgOffsetParent = getParentNode(svgOffsetParent);
1196
+ }
1197
+ return win;
1198
+ }
1199
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1200
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
1201
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1202
+ }
1203
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
1204
+ return win;
1205
+ }
1206
+ return offsetParent || getContainingBlock(element) || win;
1207
+ }
1208
+ var getElementRects = async function(data) {
1209
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1210
+ const getDimensionsFn = this.getDimensions;
1211
+ const floatingDimensions = await getDimensionsFn(data.floating);
1212
+ return {
1213
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
1214
+ floating: {
1215
+ x: 0,
1216
+ y: 0,
1217
+ width: floatingDimensions.width,
1218
+ height: floatingDimensions.height
1219
+ }
1220
+ };
1221
+ };
1222
+ function isRTL(element) {
1223
+ return getComputedStyle2(element).direction === "rtl";
1224
+ }
1225
+ var platform = {
1226
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1227
+ getDocumentElement,
1228
+ getClippingRect,
1229
+ getOffsetParent,
1230
+ getElementRects,
1231
+ getClientRects,
1232
+ getDimensions,
1233
+ getScale,
1234
+ isElement,
1235
+ isRTL
1236
+ };
1237
+ function rectsAreEqual(a, b) {
1238
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
1239
+ }
1240
+ function observeMove(element, onMove) {
1241
+ let io = null;
1242
+ let timeoutId;
1243
+ const root = getDocumentElement(element);
1244
+ function cleanup() {
1245
+ var _io;
1246
+ clearTimeout(timeoutId);
1247
+ (_io = io) == null || _io.disconnect();
1248
+ io = null;
1249
+ }
1250
+ function refresh(skip, threshold) {
1251
+ if (skip === void 0) {
1252
+ skip = false;
1253
+ }
1254
+ if (threshold === void 0) {
1255
+ threshold = 1;
1256
+ }
1257
+ cleanup();
1258
+ const elementRectForRootMargin = element.getBoundingClientRect();
1259
+ const {
1260
+ left,
1261
+ top,
1262
+ width,
1263
+ height
1264
+ } = elementRectForRootMargin;
1265
+ if (!skip) {
1266
+ onMove();
1267
+ }
1268
+ if (!width || !height) {
1269
+ return;
1270
+ }
1271
+ const insetTop = floor(top);
1272
+ const insetRight = floor(root.clientWidth - (left + width));
1273
+ const insetBottom = floor(root.clientHeight - (top + height));
1274
+ const insetLeft = floor(left);
1275
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1276
+ const options = {
1277
+ rootMargin,
1278
+ threshold: max(0, min(1, threshold)) || 1
1279
+ };
1280
+ let isFirstUpdate = true;
1281
+ function handleObserve(entries) {
1282
+ const ratio = entries[0].intersectionRatio;
1283
+ if (ratio !== threshold) {
1284
+ if (!isFirstUpdate) {
1285
+ return refresh();
1286
+ }
1287
+ if (!ratio) {
1288
+ timeoutId = setTimeout(() => {
1289
+ refresh(false, 1e-7);
1290
+ }, 1e3);
1291
+ } else {
1292
+ refresh(false, ratio);
1293
+ }
1294
+ }
1295
+ if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
1296
+ refresh();
1297
+ }
1298
+ isFirstUpdate = false;
1299
+ }
1300
+ try {
1301
+ io = new IntersectionObserver(handleObserve, {
1302
+ ...options,
1303
+ // Handle <iframe>s
1304
+ root: root.ownerDocument
1305
+ });
1306
+ } catch (_e) {
1307
+ io = new IntersectionObserver(handleObserve, options);
1308
+ }
1309
+ io.observe(element);
1310
+ }
1311
+ refresh(true);
1312
+ return cleanup;
1313
+ }
1314
+ function autoUpdate(reference, floating, update, options) {
1315
+ if (options === void 0) {
1316
+ options = {};
1317
+ }
1318
+ const {
1319
+ ancestorScroll = true,
1320
+ ancestorResize = true,
1321
+ elementResize = typeof ResizeObserver === "function",
1322
+ layoutShift = typeof IntersectionObserver === "function",
1323
+ animationFrame = false
1324
+ } = options;
1325
+ const referenceEl = unwrapElement(reference);
1326
+ const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...floating ? getOverflowAncestors(floating) : []] : [];
1327
+ ancestors.forEach((ancestor) => {
1328
+ ancestorScroll && ancestor.addEventListener("scroll", update, {
1329
+ passive: true
1330
+ });
1331
+ ancestorResize && ancestor.addEventListener("resize", update);
1332
+ });
1333
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
1334
+ let reobserveFrame = -1;
1335
+ let resizeObserver = null;
1336
+ if (elementResize) {
1337
+ resizeObserver = new ResizeObserver((_ref) => {
1338
+ let [firstEntry] = _ref;
1339
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
1340
+ resizeObserver.unobserve(floating);
1341
+ cancelAnimationFrame(reobserveFrame);
1342
+ reobserveFrame = requestAnimationFrame(() => {
1343
+ var _resizeObserver;
1344
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
1345
+ });
1346
+ }
1347
+ update();
1348
+ });
1349
+ if (referenceEl && !animationFrame) {
1350
+ resizeObserver.observe(referenceEl);
1351
+ }
1352
+ if (floating) {
1353
+ resizeObserver.observe(floating);
1354
+ }
1355
+ }
1356
+ let frameId;
1357
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1358
+ if (animationFrame) {
1359
+ frameLoop();
1360
+ }
1361
+ function frameLoop() {
1362
+ const nextRefRect = getBoundingClientRect(reference);
1363
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
1364
+ update();
1365
+ }
1366
+ prevRefRect = nextRefRect;
1367
+ frameId = requestAnimationFrame(frameLoop);
1368
+ }
1369
+ update();
1370
+ return () => {
1371
+ var _resizeObserver2;
1372
+ ancestors.forEach((ancestor) => {
1373
+ ancestorScroll && ancestor.removeEventListener("scroll", update);
1374
+ ancestorResize && ancestor.removeEventListener("resize", update);
1375
+ });
1376
+ cleanupIo == null || cleanupIo();
1377
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
1378
+ resizeObserver = null;
1379
+ if (animationFrame) {
1380
+ cancelAnimationFrame(frameId);
1381
+ }
1382
+ };
1383
+ }
1384
+ var offset2 = offset;
1385
+ var shift2 = shift;
1386
+ var flip2 = flip;
1387
+ var arrow2 = arrow;
1388
+ var computePosition2 = (reference, floating, options) => {
1389
+ const cache = /* @__PURE__ */ new Map();
1390
+ const mergedOptions = {
1391
+ platform,
1392
+ ...options
1393
+ };
1394
+ const platformWithCache = {
1395
+ ...mergedOptions.platform,
1396
+ _c: cache
1397
+ };
1398
+ return computePosition(reference, floating, {
1399
+ ...mergedOptions,
1400
+ platform: platformWithCache
1401
+ });
1402
+ };
1403
+ var defaultParser = (value) => value.split(/\s+/);
1404
+ var defaultSerializer = (tokens) => tokens.join(" ");
1405
+ function addTokenToAttribute(element, attribute, token, options = {}) {
1406
+ const {
1407
+ caseInsensitive = false,
1408
+ parse = defaultParser,
1409
+ serialize = defaultSerializer
1410
+ } = options;
1411
+ const value = element.getAttribute(attribute)?.trim();
1412
+ const tokens = value ? parse(value).filter(Boolean) : [];
1413
+ if (caseInsensitive) {
1414
+ const lower = token.toLowerCase();
1415
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
1416
+ tokens.push(token);
1417
+ element.setAttribute(attribute, serialize(tokens));
1418
+ }
1419
+ return;
1420
+ }
1421
+ const set = new Set(tokens);
1422
+ set.add(token);
1423
+ element.setAttribute(attribute, serialize([...set]));
1424
+ }
1425
+ var snapshots = /* @__PURE__ */ new WeakMap();
1426
+ function restoreAttributes(elements) {
1427
+ for (const element of elements) {
1428
+ const snapshot = snapshots.get(element);
1429
+ if (!snapshot) {
1430
+ continue;
1431
+ }
1432
+ for (const [attribute, value] of snapshot.entries()) {
1433
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
1434
+ }
1435
+ snapshots.delete(element);
1436
+ }
1437
+ }
1438
+ function saveAttributes(elements, attributes) {
1439
+ elements.forEach((element) => {
1440
+ let snapshot = snapshots.get(element);
1441
+ if (!snapshot) {
1442
+ snapshot = /* @__PURE__ */ new Map();
1443
+ snapshots.set(element, snapshot);
1444
+ }
1445
+ attributes.forEach((attribute) => {
1446
+ snapshot.set(attribute, element.getAttribute(attribute));
1447
+ });
1448
+ });
1449
+ }
1450
+ var Button = class {
1451
+ #element;
1452
+ #controller = null;
1453
+ #isDestroyed = false;
1454
+ constructor(element) {
1455
+ if (!(element instanceof HTMLElement)) {
1456
+ throw new TypeError("Invalid element");
1457
+ }
1458
+ if (element.hasAttribute("data-button-initialized")) {
1459
+ console.warn("Already initialized");
1460
+ return;
1461
+ }
1462
+ this.#element = element;
1463
+ this.#initialize();
1464
+ }
1465
+ destroy() {
1466
+ if (this.#isDestroyed) {
1467
+ return;
1468
+ }
1469
+ this.#isDestroyed = true;
1470
+ this.#controller?.abort();
1471
+ this.#controller = null;
1472
+ this.#element.removeAttribute("data-button-initialized");
1473
+ }
1474
+ #initialize() {
1475
+ this.#controller = new AbortController();
1476
+ this.#element.addEventListener("keydown", this.#onKeyDown, {
1477
+ signal: this.#controller.signal
1478
+ });
1479
+ this.#element.setAttribute("data-button-initialized", "");
1480
+ }
1481
+ #onKeyDown = (event) => {
1482
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
1483
+ if (altKey || ctrlKey || metaKey || shiftKey) {
1484
+ return;
1485
+ }
1486
+ if (!["Enter", " "].includes(key)) {
1487
+ return;
1488
+ }
1489
+ const active = getActiveElement();
1490
+ if (!(active instanceof HTMLElement)) {
1491
+ return;
1492
+ }
1493
+ event.preventDefault();
1494
+ active.click();
1495
+ };
1496
+ };
1497
+ function getActiveElement() {
1498
+ let current = document.activeElement;
1499
+ while (current?.shadowRoot?.activeElement) {
1500
+ current = current.shadowRoot.activeElement;
1501
+ }
1502
+ return current;
1503
+ }
1504
+ var snapshots2 = /* @__PURE__ */ new WeakMap();
1505
+ function restoreAttributes2(elements) {
1506
+ for (const element of elements) {
1507
+ const snapshot = snapshots2.get(element);
1508
+ if (!snapshot) {
1509
+ continue;
1510
+ }
1511
+ for (const [attribute, value] of snapshot.entries()) {
1512
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
1513
+ }
1514
+ snapshots2.delete(element);
1515
+ }
1516
+ }
1517
+ function saveAttributes2(elements, attributes) {
1518
+ elements.forEach((element) => {
1519
+ let snapshot = snapshots2.get(element);
1520
+ if (!snapshot) {
1521
+ snapshot = /* @__PURE__ */ new Map();
1522
+ snapshots2.set(element, snapshot);
1523
+ }
1524
+ attributes.forEach((attribute) => {
1525
+ snapshot.set(attribute, element.getAttribute(attribute));
1526
+ });
1527
+ });
1528
+ }
1529
+ 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"])`;
1530
+ function getFocusables(container = document.body, options = {}) {
1531
+ if (!(container instanceof Element)) {
1532
+ console.warn("Invalid container element. Fallback: <body> element.");
1533
+ container = document.body;
1534
+ }
1535
+ let {
1536
+ composed = false,
1537
+ filter,
1538
+ include,
1539
+ skipNegativeTabIndexCheck = false,
1540
+ skipVisibilityCheck = false
1541
+ } = options;
1542
+ if (typeof composed !== "boolean") {
1543
+ console.warn("Invalid composed option. Fallback: false.");
1544
+ composed = false;
1545
+ }
1546
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
1547
+ console.warn(
1548
+ "Invalid filter function. Fallback: no filter function (undefined)."
1549
+ );
1550
+ filter = void 0;
1551
+ }
1552
+ if (typeof include !== "undefined" && typeof include !== "function") {
1553
+ console.warn(
1554
+ "Invalid include function. Fallback: no include function (undefined)."
1555
+ );
1556
+ include = void 0;
1557
+ }
1558
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
1559
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
1560
+ skipNegativeTabIndexCheck = false;
1561
+ }
1562
+ if (typeof skipVisibilityCheck !== "boolean") {
1563
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
1564
+ skipVisibilityCheck = false;
1565
+ }
1566
+ const elements = [];
1567
+ if (composed || include) {
1568
+ let traverse2 = function(node) {
1569
+ if (node instanceof Element) {
1570
+ if (isFocusable(node, {
1571
+ skipNegativeTabIndexCheck,
1572
+ skipVisibilityCheck
1573
+ }) || include?.(node)) {
1574
+ elements[elements.length] = node;
1575
+ }
1576
+ }
1577
+ const children = getComposedChildren(node);
1578
+ for (let i = 0, l = children.length; i < l; i++) {
1579
+ const child = children[i];
1580
+ if (!child) {
1581
+ continue;
1582
+ }
1583
+ traverse2(child);
1584
+ }
1585
+ };
1586
+ traverse2(container);
1587
+ } else {
1588
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
1589
+ for (let i = 0, l = candidates.length; i < l; i++) {
1590
+ const candidate = candidates[i];
1591
+ if (!(candidate instanceof Element)) {
1592
+ continue;
1593
+ }
1594
+ if (isFocusable(candidate, {
1595
+ skipNegativeTabIndexCheck,
1596
+ skipVisibilityCheck
1597
+ })) {
1598
+ elements[elements.length] = candidate;
1599
+ }
1600
+ }
1601
+ }
1602
+ const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
1603
+ return filter ? unfiltered.filter(filter) : unfiltered;
1604
+ }
1605
+ function getNextFocusable(container = document.body, options = {}) {
1606
+ return getRelativeFocusable(container, 1, options);
1607
+ }
1608
+ function getPreviousFocusable(container = document.body, options = {}) {
1609
+ return getRelativeFocusable(container, -1, options);
1610
+ }
1611
+ function isFocusable(element, options = {}) {
1612
+ if (!(element instanceof Element)) {
1613
+ console.warn("Invalid element");
1614
+ return false;
1615
+ }
1616
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
1617
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
1618
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
1619
+ skipNegativeTabIndexCheck = false;
1620
+ }
1621
+ if (typeof skipVisibilityCheck !== "boolean") {
1622
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
1623
+ skipVisibilityCheck = false;
1624
+ }
1625
+ if (element.hasAttribute("hidden") || isInert(element)) {
1626
+ return false;
1627
+ }
1628
+ if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
1629
+ return false;
1630
+ }
1631
+ if (!element.matches(
1632
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR
1633
+ )) {
1634
+ return false;
1635
+ }
1636
+ if (isDisabledDeep(element)) {
1637
+ return false;
1638
+ }
1639
+ if (!skipVisibilityCheck && !element.checkVisibility({
1640
+ contentVisibilityAuto: true,
1641
+ opacityProperty: true,
1642
+ visibilityProperty: true
1643
+ })) {
1644
+ return false;
1645
+ }
1646
+ return true;
1647
+ }
1648
+ function getRelativeFocusable(container, offset3, options) {
1649
+ if (!(container instanceof Element)) {
1650
+ console.warn("Invalid container element. Fallback: <body> element.");
1651
+ container = document.body;
1652
+ }
1653
+ let {
1654
+ anchor = getActiveElement2(),
1655
+ composed = false,
1656
+ filter,
1657
+ include,
1658
+ skipNegativeTabIndexCheck = false,
1659
+ skipVisibilityCheck = false,
1660
+ wrap = false
1661
+ } = options;
1662
+ if (!(anchor instanceof Element)) {
1663
+ const active = getActiveElement2();
1664
+ if (active instanceof Element) {
1665
+ console.warn("Invalid anchor element. Fallback: active element.");
1666
+ anchor = active;
1667
+ } else {
1668
+ console.warn("Invalid anchor element");
1669
+ return null;
1670
+ }
1671
+ }
1672
+ if (!containsComposed(container, anchor)) {
1673
+ console.warn("Anchor (active) element not within container");
1674
+ return null;
1675
+ }
1676
+ if (typeof composed !== "boolean") {
1677
+ console.warn("Invalid composed option. Fallback: false.");
1678
+ composed = false;
1679
+ }
1680
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
1681
+ console.warn(
1682
+ "Invalid filter function. Fallback: no filter function (undefined)."
1683
+ );
1684
+ filter = void 0;
1685
+ }
1686
+ if (typeof include !== "undefined" && typeof include !== "function") {
1687
+ console.warn(
1688
+ "Invalid include function. Fallback: no include function (undefined)."
1689
+ );
1690
+ include = void 0;
1691
+ }
1692
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
1693
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
1694
+ skipNegativeTabIndexCheck = false;
1695
+ }
1696
+ if (typeof skipVisibilityCheck !== "boolean") {
1697
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
1698
+ skipVisibilityCheck = false;
1699
+ }
1700
+ if (typeof wrap !== "boolean") {
1701
+ console.warn("Invalid wrap option. Fallback: false.");
1702
+ wrap = false;
1703
+ }
1704
+ const settings = { composed, skipNegativeTabIndexCheck, skipVisibilityCheck };
1705
+ if (filter !== void 0) {
1706
+ Object.assign(settings, { filter });
1707
+ }
1708
+ if (include !== void 0) {
1709
+ Object.assign(settings, { include });
1710
+ }
1711
+ const focusables = getFocusables(container, settings);
1712
+ const { length } = focusables;
1713
+ if (!length) {
1714
+ return null;
1715
+ }
1716
+ const currentIndex = focusables.indexOf(anchor);
1717
+ if (currentIndex === -1) {
1718
+ return null;
1719
+ }
1720
+ const offsetIndex = currentIndex + offset3;
1721
+ if ((offsetIndex < 0 || offsetIndex >= length) && !wrap) {
1722
+ return null;
1723
+ }
1724
+ return focusables[(offsetIndex + length) % length] ?? null;
1725
+ }
1726
+ function isDisabledDeep(element) {
1727
+ let current = element;
1728
+ while (current) {
1729
+ if (current instanceof ShadowRoot) {
1730
+ if (current.mode !== "open") {
1731
+ return false;
1732
+ }
1733
+ current = current.host;
1734
+ continue;
1735
+ }
1736
+ if (!(current instanceof Element)) {
1737
+ current = current.parentNode;
1738
+ continue;
1739
+ }
1740
+ if (current === element && isFormControl(current) && isDisabled(current)) {
1741
+ return true;
1742
+ }
1743
+ if (isInert(current)) {
1744
+ return true;
1745
+ }
1746
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
1747
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
1748
+ return true;
1749
+ }
1750
+ }
1751
+ current = current.parentNode;
1752
+ }
1753
+ return false;
1754
+ }
1755
+ function normalizeRadioGroup(elements) {
1756
+ let map = null;
1757
+ for (let i = 0, l = elements.length; i < l; i++) {
1758
+ const element = elements[i];
1759
+ if (!(element instanceof HTMLInputElement)) {
1760
+ continue;
1761
+ }
1762
+ if (!isUngroupedRadio(element)) {
1763
+ continue;
1764
+ }
1765
+ if (!map) {
1766
+ map = /* @__PURE__ */ new Map();
1767
+ }
1768
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
1769
+ const group = map.get(key) ?? map.set(key, []).get(key);
1770
+ if (group) {
1771
+ group[group.length] = element;
1772
+ }
1773
+ }
1774
+ if (!map) {
1775
+ return elements;
1776
+ }
1777
+ const placeholder = /* @__PURE__ */ new Set();
1778
+ for (const group of map.values()) {
1779
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
1780
+ }
1781
+ return elements.filter((element) => {
1782
+ if (isUngroupedRadio(element)) {
1783
+ return placeholder.has(element);
1784
+ }
1785
+ return true;
1786
+ });
1787
+ }
1788
+ function sortByTabIndex(elements) {
1789
+ const ordered = [];
1790
+ const natural = [];
1791
+ for (let i = 0, l = elements.length; i < l; i++) {
1792
+ const element = elements[i];
1793
+ if (!element) {
1794
+ continue;
1795
+ }
1796
+ const target = getTabIndex(element) > 0 ? ordered : natural;
1797
+ target[target.length] = element;
1798
+ }
1799
+ ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
1800
+ let count = 0;
1801
+ const sorted = new Array(ordered.length + natural.length);
1802
+ for (let i = 0, l = ordered.length; i < l; i++) {
1803
+ sorted[count++] = ordered[i];
1804
+ }
1805
+ for (let i = 0, l = natural.length; i < l; i++) {
1806
+ sorted[count++] = natural[i];
1807
+ }
1808
+ return sorted;
1809
+ }
1810
+ function containsComposed(container, element) {
1811
+ let current = element;
1812
+ while (current) {
1813
+ if (current === container) {
1814
+ return true;
1815
+ }
1816
+ current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
1817
+ }
1818
+ return false;
1819
+ }
1820
+ function getComposedChildren(node) {
1821
+ if (node instanceof ShadowRoot) {
1822
+ return getChildren(node);
1823
+ }
1824
+ if (!(node instanceof Element)) {
1825
+ return [];
1826
+ }
1827
+ if (node instanceof HTMLSlotElement) {
1828
+ const assigned = node.assignedElements({ flatten: true });
1829
+ if (assigned.length) {
1830
+ return assigned;
1831
+ }
1832
+ }
1833
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
1834
+ return getChildren(node.shadowRoot);
1835
+ }
1836
+ return getChildren(node);
1837
+ }
1838
+ function getActiveElement2() {
1839
+ let current = document.activeElement;
1840
+ while (current?.shadowRoot?.activeElement) {
1841
+ current = current.shadowRoot.activeElement;
1842
+ }
1843
+ return current;
1844
+ }
1845
+ function getChildren(node) {
1846
+ const elements = [];
1847
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
1848
+ elements[elements.length] = child;
1849
+ }
1850
+ return elements;
1851
+ }
1852
+ function getTabIndex(element) {
1853
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
1854
+ }
1855
+ function isDisabled(element) {
1856
+ return "disabled" in element && !!element.disabled;
1857
+ }
1858
+ function isFormControl(element) {
1859
+ const name = element.tagName;
1860
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
1861
+ }
1862
+ function isInert(element) {
1863
+ return "inert" in element && !!element.inert;
1864
+ }
1865
+ function isUngroupedRadio(element) {
1866
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
1867
+ }
1868
+ 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;`;
1869
+ function createPortal(host, container = document.body) {
1870
+ if (!(host instanceof Element)) {
1871
+ console.warn("Invalid host element");
1872
+ return () => {
1873
+ };
1874
+ }
1875
+ if (host.hasAttribute("data-portaled")) {
1876
+ console.warn("Already portaled");
1877
+ return () => {
1878
+ };
1879
+ }
1880
+ if (!(container instanceof Element)) {
1881
+ console.warn("Invalid container element. Fallback: <body> element.");
1882
+ container = document.body;
1883
+ }
1884
+ if (containsComposed2(host, container)) {
1885
+ console.warn("Host element cannot contain the container element");
1886
+ return () => {
1887
+ };
1888
+ }
1889
+ const portal = new Portal(host, container);
1890
+ return () => portal.destroy();
1891
+ }
1892
+ var Portal = class {
1893
+ #host;
1894
+ #container;
1895
+ #entranceSentinel;
1896
+ #exitSentinel;
1897
+ #focusables = /* @__PURE__ */ new Set();
1898
+ #controller = null;
1899
+ #timer;
1900
+ #isDestroyed = false;
1901
+ constructor(host, container) {
1902
+ this.#host = host;
1903
+ this.#container = container;
1904
+ this.#entranceSentinel = this.#createSentinel();
1905
+ this.#exitSentinel = this.#createSentinel();
1906
+ this.#initialize();
1907
+ }
1908
+ destroy() {
1909
+ if (this.#isDestroyed) {
1910
+ return;
1911
+ }
1912
+ this.#isDestroyed = true;
1913
+ this.#controller?.abort();
1914
+ this.#controller = null;
1915
+ if (this.#timer !== void 0) {
1916
+ cancelAnimationFrame(this.#timer);
1917
+ this.#timer = void 0;
1918
+ }
1919
+ restoreAttributes2([...this.#focusables]);
1920
+ this.#focusables.clear();
1921
+ this.#exitSentinel.after(this.#host);
1922
+ this.#entranceSentinel.remove();
1923
+ this.#exitSentinel.remove();
1924
+ this.#host.removeAttribute("data-portaled");
1925
+ }
1926
+ #initialize() {
1927
+ this.#host.before(this.#entranceSentinel);
1928
+ this.#entranceSentinel.after(this.#exitSentinel);
1929
+ this.#container.append(this.#host);
1930
+ this.#update();
1931
+ this.#controller = new AbortController();
1932
+ const { signal } = this.#controller;
1933
+ document.addEventListener("focusin", this.#onFocusIn, {
1934
+ capture: true,
1935
+ signal
1936
+ });
1937
+ document.addEventListener("keydown", this.#onKeyDown, {
1938
+ capture: true,
1939
+ signal
1940
+ });
1941
+ this.#host.setAttribute("data-portaled", "");
1942
+ }
1943
+ #onFocusIn = (event) => {
1944
+ const current = event.target;
1945
+ const before = event.relatedTarget;
1946
+ if (!(before instanceof Element)) {
1947
+ return;
1948
+ }
1949
+ if (current === this.#entranceSentinel) {
1950
+ if (this.#host.contains(before)) {
1951
+ this.#moveFocus("previous");
1952
+ return;
1953
+ }
1954
+ this.#update();
1955
+ const first = [...this.#focusables][0];
1956
+ if (first) {
1957
+ focusElement(first);
1958
+ } else {
1959
+ const next = getNextFocusable(document.body, {
1960
+ anchor: this.#exitSentinel,
1961
+ composed: true
1962
+ });
1963
+ next && focusElement(next);
1964
+ }
1965
+ return;
1966
+ }
1967
+ if (current === this.#exitSentinel) {
1968
+ if (this.#host.contains(before)) {
1969
+ this.#moveFocus("next");
1970
+ return;
1971
+ }
1972
+ this.#update();
1973
+ const last = [...this.#focusables].at(-1);
1974
+ if (last) {
1975
+ focusElement(last);
1976
+ } else {
1977
+ const previous = getPreviousFocusable(document.body, {
1978
+ anchor: this.#entranceSentinel,
1979
+ composed: true
1980
+ });
1981
+ previous && focusElement(previous);
1982
+ }
1983
+ return;
1984
+ }
1985
+ };
1986
+ #onKeyDown = (event) => {
1987
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
1988
+ if (key !== "Tab" || altKey || ctrlKey || metaKey) {
1989
+ return;
1990
+ }
1991
+ const active = getActiveElement22();
1992
+ if (!(active instanceof Element)) {
1993
+ return;
1994
+ }
1995
+ if (!this.#host.contains(active)) {
1996
+ return;
1997
+ }
1998
+ this.#update();
1999
+ const focusables = this.#getFocusables();
2000
+ if (!focusables.length) {
2001
+ event.preventDefault();
2002
+ this.#moveFocus(shiftKey ? "previous" : "next");
2003
+ return;
2004
+ }
2005
+ const index = focusables.indexOf(active);
2006
+ if (index === -1) {
2007
+ return;
2008
+ }
2009
+ event.preventDefault();
2010
+ const focusable = focusables[index + (shiftKey ? -1 : 1)];
2011
+ focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
2012
+ };
2013
+ #update() {
2014
+ const current = /* @__PURE__ */ new Set([
2015
+ ...this.#getFocusables(),
2016
+ ...getFocusables(this.#host, { composed: true })
2017
+ ]);
2018
+ for (const focusable of this.#focusables) {
2019
+ if (current.has(focusable)) {
2020
+ continue;
2021
+ }
2022
+ focusable.isConnected && restoreAttributes2([focusable]);
2023
+ this.#focusables.delete(focusable);
2024
+ }
2025
+ for (const focusable of current) {
2026
+ if (this.#focusables.has(focusable)) {
2027
+ continue;
2028
+ }
2029
+ this.#focusables.add(focusable);
2030
+ saveAttributes2([focusable], ["tabindex"]);
2031
+ focusable.setAttribute("tabindex", "-1");
2032
+ }
2033
+ }
2034
+ #createSentinel() {
2035
+ const sentinel = document.createElement("span");
2036
+ sentinel.setAttribute("aria-hidden", "true");
2037
+ sentinel.setAttribute("data-portal-sentinel", "");
2038
+ sentinel.setAttribute("tabindex", "0");
2039
+ sentinel.style.cssText += VISUALLY_HIDDEN_CSS;
2040
+ return sentinel;
2041
+ }
2042
+ #focusSentinel(isPrevious) {
2043
+ this.#timer && cancelAnimationFrame(this.#timer);
2044
+ this.#timer = requestAnimationFrame(
2045
+ () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
2046
+ );
2047
+ }
2048
+ #getFocusables() {
2049
+ return getFocusables(this.#host, {
2050
+ composed: true,
2051
+ include: (element) => this.#focusables.has(element)
2052
+ });
2053
+ }
2054
+ #moveFocus(direction) {
2055
+ const options = {
2056
+ anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
2057
+ composed: true
2058
+ };
2059
+ const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
2060
+ focusable && focusElement(focusable);
2061
+ }
2062
+ };
2063
+ function containsComposed2(container, element) {
2064
+ let current = element;
2065
+ while (current) {
2066
+ if (current === container) {
2067
+ return true;
2068
+ }
2069
+ current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
2070
+ }
2071
+ return false;
2072
+ }
2073
+ function focusElement(element) {
2074
+ "focus" in element && typeof element.focus === "function" && element.focus();
2075
+ }
2076
+ function getActiveElement22() {
2077
+ let current = document.activeElement;
2078
+ while (current?.shadowRoot?.activeElement) {
2079
+ current = current.shadowRoot.activeElement;
2080
+ }
2081
+ return current;
2082
+ }
2083
+ var defaultParser2 = (value) => value.split(/\s+/);
2084
+ var defaultSerializer2 = (tokens) => tokens.join(" ");
2085
+ function addTokenToAttribute2(element, attribute, token, options = {}) {
2086
+ const {
2087
+ caseInsensitive = false,
2088
+ parse = defaultParser2,
2089
+ serialize = defaultSerializer2
2090
+ } = options;
2091
+ const value = element.getAttribute(attribute)?.trim();
2092
+ const tokens = value ? parse(value).filter(Boolean) : [];
2093
+ if (caseInsensitive) {
2094
+ const lower = token.toLowerCase();
2095
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
2096
+ tokens.push(token);
2097
+ element.setAttribute(attribute, serialize(tokens));
2098
+ }
2099
+ return;
2100
+ }
2101
+ const set = new Set(tokens);
2102
+ set.add(token);
2103
+ element.setAttribute(attribute, serialize([...set]));
2104
+ }
2105
+ var snapshots3 = /* @__PURE__ */ new WeakMap();
2106
+ function restoreAttributes3(elements) {
2107
+ for (const element of elements) {
2108
+ const snapshot = snapshots3.get(element);
2109
+ if (!snapshot) {
2110
+ continue;
2111
+ }
2112
+ for (const [attribute, value] of snapshot.entries()) {
2113
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
2114
+ }
2115
+ snapshots3.delete(element);
2116
+ }
2117
+ }
2118
+ function saveAttributes3(elements, attributes) {
2119
+ elements.forEach((element) => {
2120
+ let snapshot = snapshots3.get(element);
2121
+ if (!snapshot) {
2122
+ snapshot = /* @__PURE__ */ new Map();
2123
+ snapshots3.set(element, snapshot);
2124
+ }
2125
+ attributes.forEach((attribute) => {
2126
+ snapshot.set(attribute, element.getAttribute(attribute));
2127
+ });
2128
+ });
2129
+ }
2130
+ 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"])`;
2131
+ function getFocusables2(container = document.body, options = {}) {
2132
+ if (!(container instanceof Element)) {
2133
+ console.warn("Invalid container element. Fallback: <body> element.");
2134
+ container = document.body;
2135
+ }
2136
+ let {
2137
+ composed = false,
2138
+ filter,
2139
+ include,
2140
+ skipNegativeTabIndexCheck = false,
2141
+ skipVisibilityCheck = false
2142
+ } = options;
2143
+ if (typeof composed !== "boolean") {
2144
+ console.warn("Invalid composed option. Fallback: false.");
2145
+ composed = false;
2146
+ }
2147
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
2148
+ console.warn(
2149
+ "Invalid filter function. Fallback: no filter function (undefined)."
2150
+ );
2151
+ filter = void 0;
2152
+ }
2153
+ if (typeof include !== "undefined" && typeof include !== "function") {
2154
+ console.warn(
2155
+ "Invalid include function. Fallback: no include function (undefined)."
2156
+ );
2157
+ include = void 0;
2158
+ }
2159
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
2160
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
2161
+ skipNegativeTabIndexCheck = false;
2162
+ }
2163
+ if (typeof skipVisibilityCheck !== "boolean") {
2164
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
2165
+ skipVisibilityCheck = false;
2166
+ }
2167
+ const elements = [];
2168
+ if (composed || include) {
2169
+ let traverse2 = function(node) {
2170
+ if (node instanceof Element) {
2171
+ if (isFocusable2(node, {
2172
+ skipNegativeTabIndexCheck,
2173
+ skipVisibilityCheck
2174
+ }) || include?.(node)) {
2175
+ elements[elements.length] = node;
2176
+ }
2177
+ }
2178
+ const children = getComposedChildren2(node);
2179
+ for (let i = 0, l = children.length; i < l; i++) {
2180
+ const child = children[i];
2181
+ if (!child) {
2182
+ continue;
2183
+ }
2184
+ traverse2(child);
2185
+ }
2186
+ };
2187
+ traverse2(container);
2188
+ } else {
2189
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR2);
2190
+ for (let i = 0, l = candidates.length; i < l; i++) {
2191
+ const candidate = candidates[i];
2192
+ if (!(candidate instanceof Element)) {
2193
+ continue;
2194
+ }
2195
+ if (isFocusable2(candidate, {
2196
+ skipNegativeTabIndexCheck,
2197
+ skipVisibilityCheck
2198
+ })) {
2199
+ elements[elements.length] = candidate;
2200
+ }
2201
+ }
2202
+ }
2203
+ const unfiltered = normalizeRadioGroup2(sortByTabIndex2(elements));
2204
+ return filter ? unfiltered.filter(filter) : unfiltered;
2205
+ }
2206
+ function isFocusable2(element, options = {}) {
2207
+ if (!(element instanceof Element)) {
2208
+ console.warn("Invalid element");
2209
+ return false;
2210
+ }
2211
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
2212
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
2213
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
2214
+ skipNegativeTabIndexCheck = false;
2215
+ }
2216
+ if (typeof skipVisibilityCheck !== "boolean") {
2217
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
2218
+ skipVisibilityCheck = false;
2219
+ }
2220
+ if (element.hasAttribute("hidden") || isInert2(element)) {
2221
+ return false;
2222
+ }
2223
+ if (!skipNegativeTabIndexCheck && getTabIndex2(element) < 0) {
2224
+ return false;
2225
+ }
2226
+ if (!element.matches(
2227
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR2.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR2
2228
+ )) {
2229
+ return false;
2230
+ }
2231
+ if (isDisabledDeep2(element)) {
2232
+ return false;
2233
+ }
2234
+ if (!skipVisibilityCheck && !element.checkVisibility({
2235
+ contentVisibilityAuto: true,
2236
+ opacityProperty: true,
2237
+ visibilityProperty: true
2238
+ })) {
2239
+ return false;
2240
+ }
2241
+ return true;
2242
+ }
2243
+ function isDisabledDeep2(element) {
2244
+ let current = element;
2245
+ while (current) {
2246
+ if (current instanceof ShadowRoot) {
2247
+ if (current.mode !== "open") {
2248
+ return false;
2249
+ }
2250
+ current = current.host;
2251
+ continue;
2252
+ }
2253
+ if (!(current instanceof Element)) {
2254
+ current = current.parentNode;
2255
+ continue;
2256
+ }
2257
+ if (current === element && isFormControl2(current) && isDisabled2(current)) {
2258
+ return true;
2259
+ }
2260
+ if (isInert2(current)) {
2261
+ return true;
2262
+ }
2263
+ if (isFormControl2(element) && current.tagName === "FIELDSET" && isDisabled2(current)) {
2264
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
2265
+ return true;
2266
+ }
2267
+ }
2268
+ current = current.parentNode;
2269
+ }
2270
+ return false;
2271
+ }
2272
+ function normalizeRadioGroup2(elements) {
2273
+ let map = null;
2274
+ for (let i = 0, l = elements.length; i < l; i++) {
2275
+ const element = elements[i];
2276
+ if (!(element instanceof HTMLInputElement)) {
2277
+ continue;
2278
+ }
2279
+ if (!isUngroupedRadio2(element)) {
2280
+ continue;
2281
+ }
2282
+ if (!map) {
2283
+ map = /* @__PURE__ */ new Map();
2284
+ }
2285
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
2286
+ const group = map.get(key) ?? map.set(key, []).get(key);
2287
+ if (group) {
2288
+ group[group.length] = element;
2289
+ }
2290
+ }
2291
+ if (!map) {
2292
+ return elements;
2293
+ }
2294
+ const placeholder = /* @__PURE__ */ new Set();
2295
+ for (const group of map.values()) {
2296
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
2297
+ }
2298
+ return elements.filter((element) => {
2299
+ if (isUngroupedRadio2(element)) {
2300
+ return placeholder.has(element);
2301
+ }
2302
+ return true;
2303
+ });
2304
+ }
2305
+ function sortByTabIndex2(elements) {
2306
+ const ordered = [];
2307
+ const natural = [];
2308
+ for (let i = 0, l = elements.length; i < l; i++) {
2309
+ const element = elements[i];
2310
+ if (!element) {
2311
+ continue;
2312
+ }
2313
+ const target = getTabIndex2(element) > 0 ? ordered : natural;
2314
+ target[target.length] = element;
2315
+ }
2316
+ ordered.sort((a, b) => getTabIndex2(a) - getTabIndex2(b));
2317
+ let count = 0;
2318
+ const sorted = new Array(ordered.length + natural.length);
2319
+ for (let i = 0, l = ordered.length; i < l; i++) {
2320
+ sorted[count++] = ordered[i];
2321
+ }
2322
+ for (let i = 0, l = natural.length; i < l; i++) {
2323
+ sorted[count++] = natural[i];
2324
+ }
2325
+ return sorted;
2326
+ }
2327
+ function getComposedChildren2(node) {
2328
+ if (node instanceof ShadowRoot) {
2329
+ return getChildren2(node);
2330
+ }
2331
+ if (!(node instanceof Element)) {
2332
+ return [];
2333
+ }
2334
+ if (node instanceof HTMLSlotElement) {
2335
+ const assigned = node.assignedElements({ flatten: true });
2336
+ if (assigned.length) {
2337
+ return assigned;
2338
+ }
2339
+ }
2340
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
2341
+ return getChildren2(node.shadowRoot);
2342
+ }
2343
+ return getChildren2(node);
2344
+ }
2345
+ function getChildren2(node) {
2346
+ const elements = [];
2347
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
2348
+ elements[elements.length] = child;
2349
+ }
2350
+ return elements;
2351
+ }
2352
+ function getTabIndex2(element) {
2353
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
2354
+ }
2355
+ function isDisabled2(element) {
2356
+ return "disabled" in element && !!element.disabled;
2357
+ }
2358
+ function isFormControl2(element) {
2359
+ const name = element.tagName;
2360
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
2361
+ }
2362
+ function isInert2(element) {
2363
+ return "inert" in element && !!element.inert;
2364
+ }
2365
+ function isUngroupedRadio2(element) {
2366
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
2367
+ }
2368
+ function createRovingTabIndex(container, options = {}) {
2369
+ if (!(container instanceof Element)) {
2370
+ console.warn("Invalid container element");
2371
+ return () => {
2372
+ };
2373
+ }
2374
+ let {
2375
+ direction,
2376
+ navigationOnly = false,
2377
+ noMemory = false,
2378
+ noStart = false,
2379
+ selector,
2380
+ typeahead = false,
2381
+ wrap = false
2382
+ } = options;
2383
+ if (typeof direction !== "undefined" && !["horizontal", "vertical"].includes(direction)) {
2384
+ console.warn("Invalid direction option. Fallback: both (undefined).");
2385
+ direction = void 0;
2386
+ }
2387
+ if (typeof navigationOnly !== "boolean") {
2388
+ console.warn("Invalid navigationOnly option. Fallback: false.");
2389
+ navigationOnly = false;
2390
+ }
2391
+ if (typeof noMemory !== "boolean") {
2392
+ console.warn("Invalid noMemory option. Fallback: false.");
2393
+ noMemory = false;
2394
+ }
2395
+ if (typeof noStart !== "boolean") {
2396
+ console.warn("Invalid noStart option. Fallback: false.");
2397
+ noStart = false;
2398
+ }
2399
+ if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
2400
+ console.warn(
2401
+ "Invalid selector. Fallback: all focusable elements (undefined)."
2402
+ );
2403
+ selector = void 0;
2404
+ }
2405
+ if (typeof typeahead !== "boolean") {
2406
+ console.warn("Invalid typeahead option. Fallback: false.");
2407
+ typeahead = false;
2408
+ }
2409
+ if (typeof wrap !== "boolean") {
2410
+ console.warn("Invalid wrap option. Fallback: false.");
2411
+ wrap = false;
2412
+ }
2413
+ const settings = { navigationOnly, noMemory, noStart, typeahead, wrap };
2414
+ direction && Object.assign(settings, { direction });
2415
+ selector && Object.assign(settings, { selector });
2416
+ const roving = new RovingTabIndex(container, settings);
2417
+ return () => roving.destroy();
2418
+ }
2419
+ var RovingTabIndex = class {
2420
+ #container;
2421
+ #options;
2422
+ #focusables = /* @__PURE__ */ new Set();
2423
+ #focusablesByFirstChar = /* @__PURE__ */ new Map();
2424
+ #selectorFilter;
2425
+ #controller = null;
2426
+ #isDestroyed = false;
2427
+ constructor(container, options = {}) {
2428
+ this.#container = container;
2429
+ this.#options = options;
2430
+ this.#selectorFilter = this.#createSelectorFilter();
2431
+ this.#initialize();
2432
+ }
2433
+ destroy() {
2434
+ if (this.#isDestroyed) {
2435
+ return;
2436
+ }
2437
+ this.#isDestroyed = true;
2438
+ this.#controller?.abort();
2439
+ this.#controller = null;
2440
+ restoreAttributes3([...this.#focusables]);
2441
+ this.#focusables.clear();
2442
+ this.#focusablesByFirstChar.clear();
2443
+ this.#container.removeAttribute("data-roving-tabindex-initialized");
2444
+ }
2445
+ #initialize() {
2446
+ this.#update(document.activeElement);
2447
+ this.#controller = new AbortController();
2448
+ const { signal } = this.#controller;
2449
+ document.addEventListener("focusin", this.#onFocusIn, {
2450
+ capture: true,
2451
+ signal
2452
+ });
2453
+ document.addEventListener("keydown", this.#onKeyDown, {
2454
+ capture: true,
2455
+ signal
2456
+ });
2457
+ this.#container.setAttribute("data-roving-tabindex-initialized", "");
2458
+ }
2459
+ #onFocusIn = (event) => {
2460
+ const { target } = event;
2461
+ if (!(target instanceof Element)) {
2462
+ return;
2463
+ }
2464
+ const isFocusable22 = this.#focusables.has(target);
2465
+ if (this.#options.noMemory && !isFocusable22) {
2466
+ this.#update(null);
2467
+ return;
2468
+ }
2469
+ isFocusable22 && this.#update(target);
2470
+ };
2471
+ #onKeyDown = (event) => {
2472
+ if (!event.composedPath().includes(this.#container)) {
2473
+ return;
2474
+ }
2475
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
2476
+ if (altKey || ctrlKey || metaKey || shiftKey) {
2477
+ return;
2478
+ }
2479
+ const { direction, typeahead, wrap } = this.#options;
2480
+ const isBoth = !direction;
2481
+ const isHorizontal = direction === "horizontal";
2482
+ if (![
2483
+ "End",
2484
+ "Home",
2485
+ ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
2486
+ ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
2487
+ ].includes(key)) {
2488
+ if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
2489
+ return;
2490
+ }
2491
+ }
2492
+ const active = getActiveElement3();
2493
+ if (!(active instanceof HTMLElement)) {
2494
+ return;
2495
+ }
2496
+ const current = this.#getFocusables();
2497
+ if (!current.includes(active)) {
2498
+ return;
2499
+ }
2500
+ event.preventDefault();
2501
+ event.stopPropagation();
2502
+ const currentIndex = current.indexOf(active);
2503
+ let rawIndex;
2504
+ let newIndex = currentIndex;
2505
+ let target = current;
2506
+ switch (key) {
2507
+ case "End":
2508
+ newIndex = -1;
2509
+ break;
2510
+ case "Home":
2511
+ newIndex = 0;
2512
+ break;
2513
+ case "ArrowLeft":
2514
+ case "ArrowUp":
2515
+ rawIndex = currentIndex - 1;
2516
+ newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
2517
+ break;
2518
+ case "ArrowRight":
2519
+ case "ArrowDown":
2520
+ rawIndex = currentIndex + 1;
2521
+ newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
2522
+ break;
2523
+ default: {
2524
+ target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
2525
+ const foundIndex = target.findIndex(
2526
+ (focusable2) => current.indexOf(focusable2) > currentIndex
2527
+ );
2528
+ newIndex = foundIndex >= 0 ? foundIndex : 0;
2529
+ }
2530
+ }
2531
+ const focusable = target.at(newIndex);
2532
+ focusable && focusElement2(focusable);
2533
+ };
2534
+ #update(active) {
2535
+ const current = new Set(this.#getFocusables());
2536
+ for (const focusable of this.#focusables) {
2537
+ if (current.has(focusable)) {
2538
+ continue;
2539
+ }
2540
+ focusable.isConnected && restoreAttributes3([focusable]);
2541
+ this.#focusables.delete(focusable);
2542
+ this.#focusablesByFirstChar.forEach((focusables) => {
2543
+ const index = focusables.indexOf(focusable);
2544
+ index >= 0 && focusables.splice(index, 1);
2545
+ });
2546
+ }
2547
+ const { navigationOnly, noStart, typeahead } = this.#options;
2548
+ for (const focusable of current) {
2549
+ if (this.#focusables.has(focusable)) {
2550
+ continue;
2551
+ }
2552
+ this.#focusables.add(focusable);
2553
+ if (!navigationOnly) {
2554
+ saveAttributes3([focusable], ["tabindex"]);
2555
+ focusable.setAttribute("tabindex", "-1");
2556
+ }
2557
+ if (!typeahead) {
2558
+ continue;
2559
+ }
2560
+ const value = focusable.ariaKeyShortcuts?.trim();
2561
+ const keys = new Set(
2562
+ value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
2563
+ );
2564
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
2565
+ if (char) {
2566
+ keys.add(char);
2567
+ saveAttributes3([focusable], ["aria-keyshortcuts"]);
2568
+ addTokenToAttribute2(focusable, "aria-keyshortcuts", char, {
2569
+ caseInsensitive: true
2570
+ });
2571
+ }
2572
+ keys.forEach((key) => {
2573
+ const focusables = this.#focusablesByFirstChar.get(key) ?? [];
2574
+ focusables.push(focusable);
2575
+ this.#focusablesByFirstChar.set(key, focusables);
2576
+ });
2577
+ }
2578
+ if (navigationOnly) {
2579
+ return;
2580
+ }
2581
+ if (active && this.#focusables.has(active)) {
2582
+ this.#focusables.forEach((focusable) => {
2583
+ focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
2584
+ });
2585
+ return;
2586
+ }
2587
+ [...this.#focusables].forEach((focusable, i) => {
2588
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
2589
+ });
2590
+ }
2591
+ #createSelectorFilter() {
2592
+ const { selector } = this.#options;
2593
+ return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
2594
+ }
2595
+ #getFocusables() {
2596
+ return getFocusables2(this.#container, {
2597
+ composed: true,
2598
+ filter: this.#selectorFilter,
2599
+ skipNegativeTabIndexCheck: !this.#options.navigationOnly,
2600
+ skipVisibilityCheck: true
2601
+ });
2602
+ }
2603
+ };
2604
+ function focusElement2(element) {
2605
+ "focus" in element && typeof element.focus === "function" && element.focus();
2606
+ }
2607
+ function getActiveElement3() {
2608
+ let current = document.activeElement;
2609
+ while (current?.shadowRoot?.activeElement) {
2610
+ current = current.shadowRoot.activeElement;
2611
+ }
2612
+ return current;
2613
+ }
2614
+ var Menu = class _Menu {
2615
+ static defaults = {};
2616
+ static #menus = [];
2617
+ #rootElement;
2618
+ #defaults = {
2619
+ animation: { duration: 300 },
2620
+ delay: 200,
2621
+ popover: {
2622
+ menu: {
2623
+ arrow: true,
2624
+ middleware: [flip2(), offset2(), shift2()],
2625
+ placement: "bottom-start"
2626
+ },
2627
+ submenu: {
2628
+ arrow: true,
2629
+ middleware: [flip2(), offset2(), shift2()],
2630
+ placement: "right-start"
2631
+ },
2632
+ transformOrigin: true
2633
+ },
2634
+ selector: {
2635
+ checkboxItem: '[role="menuitemcheckbox"]',
2636
+ group: '[role="group"]',
2637
+ item: '[role^="menuitem"]',
2638
+ list: '[role="menu"]',
2639
+ radioItem: '[role="menuitemradio"]',
2640
+ trigger: "[data-menu-trigger]"
2641
+ }
2642
+ };
2643
+ #settings;
2644
+ #externalTrigger;
2645
+ #isMenubar;
2646
+ #isPortal;
2647
+ #isSubmenu;
2648
+ #popoverRef;
2649
+ #triggerElement;
2650
+ #listElement;
2651
+ #itemElements;
2652
+ #checkboxItemElements = [];
2653
+ #radioItemElements = [];
2654
+ #radioItemElementsByGroup = /* @__PURE__ */ new WeakMap();
2655
+ #arrowElement;
2656
+ #controller = null;
2657
+ #cleanupPopover = null;
2658
+ #cleanupPortal = null;
2659
+ #cleanupRovingTabIndex = null;
2660
+ #timers = [];
2661
+ #animation = null;
2662
+ #animationId = 0;
2663
+ #buttons = [];
2664
+ #submenus = [];
2665
+ #submenuTimer;
2666
+ #isDestroyed = false;
2667
+ constructor(root, options = {}, _internal = {}) {
2668
+ if (!(root instanceof HTMLElement)) {
2669
+ throw new TypeError("Invalid root element");
2670
+ }
2671
+ if (root.hasAttribute("data-menu-initialized")) {
2672
+ console.warn("Already initialized");
2673
+ return;
2674
+ }
2675
+ this.#rootElement = root;
2676
+ this.#defaults = this.#mergeOptions(this.#defaults, _Menu.defaults);
2677
+ this.#settings = this.#mergeOptions(this.#defaults, options);
2678
+ matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
2679
+ const {
2680
+ externalTrigger = null,
2681
+ isMenubar = false,
2682
+ isPortal = false,
2683
+ isSubmenu = false
2684
+ } = _internal;
2685
+ this.#externalTrigger = externalTrigger;
2686
+ this.#isMenubar = isMenubar;
2687
+ this.#isPortal = isPortal;
2688
+ this.#isSubmenu = isSubmenu;
2689
+ const { selector } = this.#settings;
2690
+ this.#triggerElement = this.#rootElement.querySelector(
2691
+ selector[this.#isSubmenu ? "item" : "trigger"]
2692
+ );
2693
+ this.#popoverRef = _internal.popoverRef ?? this.#triggerElement;
2694
+ this.#listElement = this.#rootElement.querySelector(
2695
+ selector.list
2696
+ );
2697
+ if (!this.#listElement) {
2698
+ console.warn("Missing list element");
2699
+ return;
2700
+ }
2701
+ this.#itemElements = [
2702
+ ...this.#listElement.querySelectorAll(
2703
+ `${selector.item}:not(:scope ${selector.list} *)`
2704
+ )
2705
+ ];
2706
+ if (!this.#itemElements.length) {
2707
+ console.warn("Missing item elements");
2708
+ return;
2709
+ }
2710
+ this.#itemElements.forEach((item) => {
2711
+ const role = item.role;
2712
+ role === "menuitemcheckbox" ? this.#checkboxItemElements.push(item) : role === "menuitemradio" && this.#radioItemElements.push(item);
2713
+ });
2714
+ this.#radioItemElements.forEach((item) => {
2715
+ let group = item.closest(selector.group);
2716
+ if (!group || !this.#rootElement.contains(group)) {
2717
+ group = this.#rootElement;
2718
+ }
2719
+ const items = this.#radioItemElementsByGroup.get(group) ?? [];
2720
+ items.push(item);
2721
+ this.#radioItemElementsByGroup.set(group, items);
2722
+ });
2723
+ const settings = this.#settings.popover[this.#isSubmenu ? "submenu" : "menu"];
2724
+ if (settings.arrow) {
2725
+ this.#arrowElement = document.createElement("div");
2726
+ this.#arrowElement.setAttribute("data-menu-arrow", "");
2727
+ this.#listElement.appendChild(this.#arrowElement);
2728
+ const middleware = settings.middleware;
2729
+ const index = middleware.findIndex((m) => m.name === "arrow");
2730
+ index >= 0 && middleware.splice(index, 1);
2731
+ middleware.push(arrow2({ element: this.#arrowElement }));
2732
+ } else {
2733
+ this.#arrowElement = null;
2734
+ }
2735
+ this.#initialize();
2736
+ }
2737
+ close() {
2738
+ this.#toggle(false);
2739
+ }
2740
+ async destroy(force = false) {
2741
+ if (this.#isDestroyed) {
2742
+ return;
2743
+ }
2744
+ this.#isDestroyed = true;
2745
+ this.#controller?.abort();
2746
+ this.#controller = null;
2747
+ this.#cleanupRovingTabIndex?.();
2748
+ this.#cleanupRovingTabIndex = null;
2749
+ this.#cleanupPortal?.();
2750
+ this.#cleanupPortal = null;
2751
+ this.#cleanupPopover?.();
2752
+ this.#cleanupPopover = null;
2753
+ this.#timers.forEach((timer) => {
2754
+ cancelAnimationFrame(timer);
2755
+ });
2756
+ this.#timers.length = 0;
2757
+ this.#clearSubmenuTimer();
2758
+ this.#buttons.forEach((button) => {
2759
+ button.destroy();
2760
+ });
2761
+ this.#buttons.length = 0;
2762
+ _Menu.#menus = _Menu.#menus.filter((menu) => menu !== this);
2763
+ this.#submenus && await Promise.all(this.#submenus.map((submenu) => submenu.destroy()));
2764
+ if (!force) {
2765
+ try {
2766
+ await this.#animation?.finished;
2767
+ } catch {
2768
+ }
2769
+ }
2770
+ this.#animation?.cancel();
2771
+ this.#animation = null;
2772
+ const trigger = this.#getTrigger();
2773
+ const elements = this.#itemElements;
2774
+ if (trigger) {
2775
+ elements.push(trigger);
2776
+ }
2777
+ if (this.#listElement) {
2778
+ elements.push(this.#listElement);
2779
+ }
2780
+ restoreAttributes(elements);
2781
+ this.#externalTrigger = null;
2782
+ this.#triggerElement = null;
2783
+ this.#listElement = null;
2784
+ this.#itemElements.length = 0;
2785
+ this.#checkboxItemElements.length = 0;
2786
+ this.#radioItemElements.length = 0;
2787
+ this.#arrowElement = null;
2788
+ this.#rootElement.removeAttribute("data-menu-initialized");
2789
+ }
2790
+ isOpen() {
2791
+ return this.#getTrigger()?.ariaExpanded === "true";
2792
+ }
2793
+ open(_initialFocus = false) {
2794
+ this.#toggle(true, { initialFocus: _initialFocus });
2795
+ }
2796
+ #initialize() {
2797
+ this.#controller = new AbortController();
2798
+ const { signal } = this.#controller;
2799
+ document.addEventListener("pointerdown", this.#onOutsidePointerDown, {
2800
+ capture: true,
2801
+ signal
2802
+ });
2803
+ this.#rootElement.addEventListener("focusout", this.#onRootFocusOut, {
2804
+ signal
2805
+ });
2806
+ if (!this.#listElement) {
2807
+ return;
2808
+ }
2809
+ saveAttributes([this.#listElement], ["aria-labelledby", "id", "role"]);
2810
+ const trigger = this.#getTrigger();
2811
+ if (trigger && this.#triggerElement) {
2812
+ saveAttributes(
2813
+ [trigger],
2814
+ [
2815
+ "aria-controls",
2816
+ "aria-disabled",
2817
+ "aria-expanded",
2818
+ "aria-haspopup",
2819
+ "id",
2820
+ "style",
2821
+ "tabindex"
2822
+ ]
2823
+ );
2824
+ const id = Math.random().toString(36).slice(-8);
2825
+ this.#listElement.id ||= `menu-list-${id}`;
2826
+ addTokenToAttribute(trigger, "aria-controls", this.#listElement.id);
2827
+ trigger.setAttribute("aria-expanded", "false");
2828
+ trigger.setAttribute("aria-haspopup", "true");
2829
+ trigger.id ||= `menu-trigger-${id}`;
2830
+ if (!isFocusable3(trigger)) {
2831
+ trigger.setAttribute("aria-disabled", "true");
2832
+ trigger.setAttribute("tabindex", "-1");
2833
+ trigger.style.setProperty("pointer-events", "none");
2834
+ }
2835
+ trigger.addEventListener("keydown", this.#onTriggerKeyDown, {
2836
+ signal
2837
+ });
2838
+ this.#triggerElement.addEventListener(
2839
+ "pointerdown",
2840
+ this.#onTriggerPointerDown,
2841
+ {
2842
+ signal
2843
+ }
2844
+ );
2845
+ addTokenToAttribute(this.#listElement, "aria-labelledby", trigger.id);
2846
+ this.#buttons.push(new Button(trigger));
2847
+ }
2848
+ this.#listElement.setAttribute("role", "menu");
2849
+ this.#listElement.addEventListener("keydown", this.#onListKeyDown, {
2850
+ signal
2851
+ });
2852
+ saveAttributes(this.#itemElements, [
2853
+ "aria-disabled",
2854
+ "data-menu-disabled",
2855
+ "role",
2856
+ "style",
2857
+ "tabindex"
2858
+ ]);
2859
+ this.#itemElements.forEach((item2) => {
2860
+ const parent = item2.parentElement;
2861
+ if (parent?.querySelector(this.#settings.selector.list)) {
2862
+ this.#submenus.push(
2863
+ new _Menu(parent, this.#settings, {
2864
+ isPortal: !!this.#triggerElement,
2865
+ isSubmenu: true
2866
+ })
2867
+ );
2868
+ } else if (item2.hasAttribute("disabled") || item2.tabIndex < 0) {
2869
+ item2.setAttribute("aria-disabled", "true");
2870
+ item2.setAttribute("data-menu-disabled", "");
2871
+ item2.style.setProperty("pointer-events", "none");
2872
+ }
2873
+ [this.#checkboxItemElements, this.#radioItemElements].every(
2874
+ (list2) => !list2.includes(item2)
2875
+ ) && item2.setAttribute("role", "menuitem");
2876
+ item2.addEventListener("pointerenter", this.#onItemPointerEnter, {
2877
+ signal
2878
+ });
2879
+ item2.addEventListener("pointerleave", this.#onItemPointerLeave, {
2880
+ signal
2881
+ });
2882
+ });
2883
+ this.#checkboxItemElements.forEach((item2) => {
2884
+ item2.setAttribute("role", "menuitemcheckbox");
2885
+ item2.addEventListener("click", this.#onCheckboxItemClick, { signal });
2886
+ });
2887
+ this.#radioItemElements.forEach((item2) => {
2888
+ item2.setAttribute("role", "menuitemradio");
2889
+ item2.addEventListener("click", this.#onRadioItemClick, { signal });
2890
+ });
2891
+ const { item, list } = this.#settings.selector;
2892
+ this.#cleanupRovingTabIndex = createRovingTabIndex(this.#listElement, {
2893
+ direction: "vertical",
2894
+ noMemory: true,
2895
+ noStart: !!this.#triggerElement,
2896
+ selector: `${item}:not(:scope ${list} *, [data-menu-disabled])`,
2897
+ typeahead: true,
2898
+ wrap: true
2899
+ });
2900
+ _Menu.#menus.push(this);
2901
+ !this.#isSubmenu && this.#rootElement.setAttribute("data-menu-initialized", "");
2902
+ }
2903
+ #onOutsidePointerDown = (event) => {
2904
+ if (!this.#triggerElement || this.#includesRoot(event)) {
2905
+ return;
2906
+ }
2907
+ this.#toggle(false, { restoreFocus: false });
2908
+ };
2909
+ #onRootFocusOut = (event) => {
2910
+ const target = event.relatedTarget;
2911
+ if (!(target instanceof HTMLElement) || // Not a type guard
2912
+ !this.#containsRoot(target)) {
2913
+ this.#toggle(false, { restoreFocus: false });
2914
+ }
2915
+ };
2916
+ #onTriggerKeyDown = (event) => {
2917
+ if (this.#handleExitKeys(event)) {
2918
+ return;
2919
+ }
2920
+ const { key, shiftKey } = event;
2921
+ if (shiftKey) {
2922
+ return;
2923
+ }
2924
+ if (![
2925
+ "Escape",
2926
+ ...this.#isSubmenu ? ["ArrowRight"] : ["ArrowUp", "ArrowDown"]
2927
+ ].includes(key)) {
2928
+ return;
2929
+ }
2930
+ if (key === "Escape") {
2931
+ this.#closeAndFocusTrigger();
2932
+ return;
2933
+ }
2934
+ event.preventDefault();
2935
+ event.stopPropagation();
2936
+ const isArrowUp = key === "ArrowUp";
2937
+ this.isOpen() ? this.#itemElements.filter(isFocusable3).at(isArrowUp ? -1 : 0)?.focus() : this.#toggle(true, {
2938
+ initialFocus: isArrowUp ? "last" : "first"
2939
+ });
2940
+ };
2941
+ #onTriggerPointerDown = (event) => {
2942
+ event.preventDefault();
2943
+ const trigger = this.#getTrigger();
2944
+ this.#toggle(
2945
+ this.#isSubmenu ? event.currentTarget === this.#triggerElement : trigger?.ariaExpanded !== "true",
2946
+ { initialFocus: false }
2947
+ );
2948
+ if (trigger) {
2949
+ trigger.style.setProperty("outline", "0");
2950
+ trigger.focus();
2951
+ }
2952
+ };
2953
+ #onListKeyDown = (event) => {
2954
+ this.#itemElements.forEach((item) => {
2955
+ item.style.removeProperty("outline");
2956
+ });
2957
+ if (this.#handleExitKeys(event, true)) {
2958
+ return;
2959
+ }
2960
+ const { key, shiftKey } = event;
2961
+ if (shiftKey) {
2962
+ return;
2963
+ }
2964
+ if (![
2965
+ "Enter",
2966
+ "Escape",
2967
+ " ",
2968
+ ...this.#isMenubar ? ["ArrowLeft", "ArrowRight"] : []
2969
+ ].includes(key)) {
2970
+ return;
2971
+ }
2972
+ event.preventDefault();
2973
+ event.stopPropagation();
2974
+ const active = getActiveElement4();
2975
+ if (!(active instanceof HTMLElement)) {
2976
+ return;
2977
+ }
2978
+ switch (key) {
2979
+ case "Enter":
2980
+ case " ":
2981
+ active.click();
2982
+ break;
2983
+ case "Escape":
2984
+ case "ArrowLeft":
2985
+ case "ArrowRight":
2986
+ this.#dispatchTriggerKeyDown(key);
2987
+ break;
2988
+ }
2989
+ };
2990
+ #onItemPointerEnter = (event) => {
2991
+ this.#clearSubmenuTimer();
2992
+ const item = event.currentTarget;
2993
+ if (!(item instanceof HTMLElement)) {
2994
+ return;
2995
+ }
2996
+ this.#submenuTimer = setTimeout(() => {
2997
+ this.#submenus.forEach((submenu) => {
2998
+ submenu.#toggle(submenu.#triggerElement === item);
2999
+ });
3000
+ item.style.setProperty("outline", "0");
3001
+ item.focus();
3002
+ }, this.#settings.delay);
3003
+ };
3004
+ #onItemPointerLeave = () => {
3005
+ this.#clearSubmenuTimer();
3006
+ };
3007
+ #onCheckboxItemClick = (event) => {
3008
+ const item = event.currentTarget;
3009
+ if (!(item instanceof HTMLElement)) {
3010
+ return;
3011
+ }
3012
+ item.setAttribute("aria-checked", String(item.ariaChecked !== "true"));
3013
+ };
3014
+ #onRadioItemClick = (event) => {
3015
+ const item = event.currentTarget;
3016
+ if (!(item instanceof HTMLElement)) {
3017
+ return;
3018
+ }
3019
+ const group = item.closest(this.#settings.selector.group) ?? this.#rootElement;
3020
+ this.#radioItemElementsByGroup.get(group)?.forEach((i) => {
3021
+ i.setAttribute("aria-checked", String(i === item));
3022
+ });
3023
+ };
3024
+ #toggle(isOpen, options = {}) {
3025
+ const trigger = this.#getTrigger();
3026
+ if (trigger?.ariaExpanded === String(isOpen)) {
3027
+ return;
3028
+ }
3029
+ trigger?.setAttribute("aria-expanded", String(isOpen));
3030
+ const { initialFocus = false, restoreFocus = true } = options;
3031
+ if (isOpen) {
3032
+ _Menu.#menus.filter((m) => !m.#containsRoot(this.#rootElement)).forEach((menu) => {
3033
+ menu.#toggle(false);
3034
+ });
3035
+ if (!this.#listElement) {
3036
+ return;
3037
+ }
3038
+ if (!this.#isPortal || !this.#isSubmenu && this.#triggerElement) {
3039
+ const style2 = this.#listElement.style;
3040
+ style2.setProperty("position", "fixed");
3041
+ if (!this.#cleanupPortal) {
3042
+ this.#cleanupPortal = createPortal(this.#listElement);
3043
+ }
3044
+ const timer2 = this.#timers[0];
3045
+ timer2 && cancelAnimationFrame(timer2);
3046
+ this.#timers[0] = requestAnimationFrame(
3047
+ () => style2.removeProperty("position")
3048
+ );
3049
+ }
3050
+ const timer = this.#timers[1];
3051
+ timer && cancelAnimationFrame(timer);
3052
+ this.#timers[1] = requestAnimationFrame(
3053
+ () => this.#listElement?.setAttribute("data-menu-open", "")
3054
+ );
3055
+ const { style } = this.#listElement;
3056
+ style.setProperty("display", "block");
3057
+ style.setProperty("opacity", "0");
3058
+ this.#triggerElement && this.#updatePopover();
3059
+ initialFocus && this.#itemElements.filter(isFocusable3).at(initialFocus === "first" ? 0 : -1)?.focus();
3060
+ } else {
3061
+ this.#clearSubmenuTimer();
3062
+ trigger?.style.removeProperty("outline");
3063
+ restoreFocus && this.#focusTrigger();
3064
+ }
3065
+ if (!this.#triggerElement) {
3066
+ return;
3067
+ }
3068
+ if (!this.#listElement) {
3069
+ return;
3070
+ }
3071
+ if (!isOpen) {
3072
+ this.#listElement.removeAttribute("data-menu-open");
3073
+ this.#cleanupPopover?.();
3074
+ this.#cleanupPopover = null;
3075
+ }
3076
+ const opacity = getComputedStyle(this.#listElement).getPropertyValue(
3077
+ "opacity"
3078
+ );
3079
+ const animationId = ++this.#animationId;
3080
+ this.#animation?.cancel();
3081
+ this.#animation = this.#listElement.animate(
3082
+ { opacity: isOpen ? [opacity, "1"] : [opacity, "0"] },
3083
+ { duration: this.#settings.animation.duration, easing: "ease" }
3084
+ );
3085
+ const cleanupAnimation = () => {
3086
+ if (animationId === this.#animationId) {
3087
+ this.#animation = null;
3088
+ }
3089
+ };
3090
+ const { signal } = this.#controller ?? new AbortController();
3091
+ this.#animation.addEventListener("cancel", cleanupAnimation, {
3092
+ once: true,
3093
+ signal
3094
+ });
3095
+ this.#animation.addEventListener(
3096
+ "finish",
3097
+ () => {
3098
+ if (animationId !== this.#animationId) {
3099
+ return;
3100
+ }
3101
+ cleanupAnimation();
3102
+ if (!this.#listElement) {
3103
+ return;
3104
+ }
3105
+ const { style } = this.#listElement;
3106
+ if (!isOpen) {
3107
+ this.#cleanupPortal?.();
3108
+ this.#cleanupPortal = null;
3109
+ this.#listElement.removeAttribute("data-menu-placement");
3110
+ style.setProperty("display", "none");
3111
+ ["left", "top", "transform-origin"].forEach((name) => {
3112
+ style.removeProperty(name);
3113
+ });
3114
+ this.#arrowElement && ["left", "top", "rotate"].forEach((name) => {
3115
+ this.#arrowElement?.style.removeProperty(name);
3116
+ });
3117
+ }
3118
+ style.removeProperty("opacity");
3119
+ },
3120
+ { once: true, signal }
3121
+ );
3122
+ }
3123
+ #clearSubmenuTimer() {
3124
+ if (this.#submenuTimer !== void 0) {
3125
+ clearTimeout(this.#submenuTimer);
3126
+ this.#submenuTimer = void 0;
3127
+ }
3128
+ }
3129
+ #closeAndFocusTrigger() {
3130
+ this.#toggle(false);
3131
+ const timer = this.#timers[2];
3132
+ timer && cancelAnimationFrame(timer);
3133
+ this.#timers[2] = requestAnimationFrame(() => this.#focusTrigger());
3134
+ }
3135
+ #containsRoot(element) {
3136
+ return this.#rootElement.contains(element) || !!this.#listElement?.contains(element);
3137
+ }
3138
+ #dispatchTriggerKeyDown(key) {
3139
+ const trigger = this.#getTrigger();
3140
+ if (!trigger) {
3141
+ return;
3142
+ }
3143
+ trigger.focus();
3144
+ trigger.dispatchEvent(new KeyboardEvent("keydown", { key }));
3145
+ }
3146
+ #focusTrigger() {
3147
+ const active = getActiveElement4();
3148
+ if (!(active instanceof HTMLElement)) {
3149
+ return;
3150
+ }
3151
+ this.#containsRoot(active) && this.#getTrigger()?.focus();
3152
+ }
3153
+ #getTrigger() {
3154
+ return this.#externalTrigger ?? this.#triggerElement;
3155
+ }
3156
+ #handleExitKeys(event, isList = false) {
3157
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
3158
+ if (shiftKey && key !== "Tab" || altKey || ctrlKey || metaKey) {
3159
+ return true;
3160
+ }
3161
+ const shouldPrevent = this.#isSubmenu && key === "ArrowLeft" && isList;
3162
+ if (shiftKey && key === "Tab" || shouldPrevent) {
3163
+ if (shouldPrevent) {
3164
+ event.preventDefault();
3165
+ event.stopPropagation();
3166
+ }
3167
+ this.#closeAndFocusTrigger();
3168
+ return true;
3169
+ }
3170
+ return false;
3171
+ }
3172
+ #includesRoot(event) {
3173
+ const path = event.composedPath();
3174
+ if (!this.#listElement) {
3175
+ return false;
3176
+ }
3177
+ return path.includes(this.#rootElement) || path.includes(this.#listElement);
3178
+ }
3179
+ #mergeOptions(target, source) {
3180
+ return {
3181
+ ...target,
3182
+ ...source,
3183
+ animation: { ...target.animation, ...source.animation ?? {} },
3184
+ popover: {
3185
+ ...target.popover,
3186
+ ...source.popover ?? {},
3187
+ menu: {
3188
+ ...target.popover?.menu,
3189
+ ...source.popover?.menu ?? {},
3190
+ middleware: Object.assign(
3191
+ [...target.popover?.menu?.middleware ?? []],
3192
+ [...source.popover?.menu?.middleware ?? []]
3193
+ )
3194
+ },
3195
+ submenu: {
3196
+ ...target.popover?.submenu,
3197
+ ...source.popover?.submenu ?? {},
3198
+ middleware: Object.assign(
3199
+ [...target.popover?.submenu?.middleware ?? []],
3200
+ [...source.popover?.submenu?.middleware ?? []]
3201
+ )
3202
+ }
3203
+ },
3204
+ selector: { ...target.selector, ...source.selector ?? {} }
3205
+ };
3206
+ }
3207
+ #updatePopover() {
3208
+ if (!this.#popoverRef) {
3209
+ return;
3210
+ }
3211
+ const compute = () => {
3212
+ if (!this.#popoverRef || !this.#listElement) {
3213
+ return;
3214
+ }
3215
+ const options = this.#settings.popover[this.#isSubmenu ? "submenu" : "menu"];
3216
+ computePosition2(this.#popoverRef, this.#listElement, {
3217
+ ...options,
3218
+ placement: options.placement
3219
+ }).then(
3220
+ ({
3221
+ x: listX,
3222
+ y: listY,
3223
+ placement,
3224
+ middlewareData
3225
+ }) => {
3226
+ if (!this.#listElement) {
3227
+ return;
3228
+ }
3229
+ const { style: listStyle } = this.#listElement;
3230
+ listStyle.setProperty("left", `${listX}px`);
3231
+ listStyle.setProperty("top", `${listY}px`);
3232
+ this.#listElement.setAttribute("data-menu-placement", placement);
3233
+ this.#settings.popover.transformOrigin && listStyle.setProperty(
3234
+ "transform-origin",
3235
+ {
3236
+ top: "50% 100%",
3237
+ "top-start": "0 100%",
3238
+ "top-end": "100% 100%",
3239
+ right: "0 50%",
3240
+ "right-start": "0 0",
3241
+ "right-end": "0 100%",
3242
+ bottom: "50% 0",
3243
+ "bottom-start": "0 0",
3244
+ "bottom-end": "100% 0",
3245
+ left: "100% 50%",
3246
+ "left-start": "100% 0",
3247
+ "left-end": "100% 100%"
3248
+ }[placement]
3249
+ );
3250
+ if (!this.#arrowElement) {
3251
+ return;
3252
+ }
3253
+ const arrowX = middlewareData.arrow?.x;
3254
+ const arrowY = middlewareData.arrow?.y;
3255
+ const { style: arrowStyle } = this.#arrowElement;
3256
+ arrowStyle.setProperty("left", arrowX ? `${arrowX}px` : "");
3257
+ arrowStyle.setProperty(
3258
+ "top",
3259
+ arrowY ? `${arrowY - this.#arrowElement.offsetHeight / 2}px` : ""
3260
+ );
3261
+ const side = placement.split("-")[0];
3262
+ if (!side) {
3263
+ return;
3264
+ }
3265
+ const styles = {
3266
+ top: { position: "bottom", rotate: "225deg" },
3267
+ right: { position: "left", rotate: "315deg" },
3268
+ bottom: { position: "top", rotate: "45deg" },
3269
+ left: { position: "right", rotate: "135deg" }
3270
+ }[side];
3271
+ if (!styles) {
3272
+ return;
3273
+ }
3274
+ arrowStyle.setProperty(
3275
+ styles.position,
3276
+ `${this.#arrowElement.offsetWidth / -2}px`
3277
+ );
3278
+ arrowStyle.setProperty("rotate", styles.rotate);
3279
+ }
3280
+ );
3281
+ };
3282
+ if (!this.#cleanupPopover) {
3283
+ this.#cleanupPopover = autoUpdate(
3284
+ this.#popoverRef,
3285
+ this.#listElement,
3286
+ compute
3287
+ );
3288
+ }
3289
+ }
3290
+ };
3291
+ function getActiveElement4() {
3292
+ let current = document.activeElement;
3293
+ while (current?.shadowRoot?.activeElement) {
3294
+ current = current.shadowRoot.activeElement;
3295
+ }
3296
+ return current;
3297
+ }
3298
+ function isFocusable3(element) {
3299
+ return !element.hasAttribute("data-menu-disabled") && !element.hasAttribute("disabled");
3300
+ }
3301
+
3302
+ // node_modules/@y14e/roving-tabindex/dist/index.js
3303
+ var defaultParser3 = (value) => value.split(/\s+/);
3304
+ var defaultSerializer3 = (tokens) => tokens.join(" ");
3305
+ function addTokenToAttribute3(element, attribute, token, options = {}) {
3306
+ const {
3307
+ caseInsensitive = false,
3308
+ parse = defaultParser3,
3309
+ serialize = defaultSerializer3
3310
+ } = options;
3311
+ const value = element.getAttribute(attribute)?.trim();
3312
+ const tokens = value ? parse(value).filter(Boolean) : [];
3313
+ if (caseInsensitive) {
3314
+ const lower = token.toLowerCase();
3315
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
3316
+ tokens.push(token);
3317
+ element.setAttribute(attribute, serialize(tokens));
3318
+ }
3319
+ return;
3320
+ }
3321
+ const set = new Set(tokens);
3322
+ set.add(token);
3323
+ element.setAttribute(attribute, serialize([...set]));
3324
+ }
3325
+ var snapshots4 = /* @__PURE__ */ new WeakMap();
3326
+ function restoreAttributes4(elements) {
3327
+ for (const element of elements) {
3328
+ const snapshot = snapshots4.get(element);
3329
+ if (!snapshot) {
3330
+ continue;
3331
+ }
3332
+ for (const [attribute, value] of snapshot.entries()) {
3333
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
3334
+ }
3335
+ snapshots4.delete(element);
3336
+ }
3337
+ }
3338
+ function saveAttributes4(elements, attributes) {
3339
+ elements.forEach((element) => {
3340
+ let snapshot = snapshots4.get(element);
3341
+ if (!snapshot) {
3342
+ snapshot = /* @__PURE__ */ new Map();
3343
+ snapshots4.set(element, snapshot);
3344
+ }
3345
+ attributes.forEach((attribute) => {
3346
+ snapshot.set(attribute, element.getAttribute(attribute));
3347
+ });
3348
+ });
3349
+ }
3350
+ var FOCUSABLE_SELECTOR3 = `: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"])`;
3351
+ function getFocusables3(container = document.body, options = {}) {
3352
+ if (!(container instanceof Element)) {
3353
+ console.warn("Invalid container element. Fallback: <body> element.");
3354
+ container = document.body;
3355
+ }
3356
+ let {
3357
+ composed = false,
3358
+ filter,
3359
+ include,
3360
+ skipNegativeTabIndexCheck = false,
3361
+ skipVisibilityCheck = false
3362
+ } = options;
3363
+ if (typeof composed !== "boolean") {
3364
+ console.warn("Invalid composed option. Fallback: false.");
3365
+ composed = false;
3366
+ }
3367
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
3368
+ console.warn(
3369
+ "Invalid filter function. Fallback: no filter function (undefined)."
3370
+ );
3371
+ filter = void 0;
3372
+ }
3373
+ if (typeof include !== "undefined" && typeof include !== "function") {
3374
+ console.warn(
3375
+ "Invalid include function. Fallback: no include function (undefined)."
3376
+ );
3377
+ include = void 0;
3378
+ }
3379
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
3380
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
3381
+ skipNegativeTabIndexCheck = false;
3382
+ }
3383
+ if (typeof skipVisibilityCheck !== "boolean") {
3384
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
3385
+ skipVisibilityCheck = false;
3386
+ }
3387
+ const elements = [];
3388
+ if (composed || include) {
3389
+ let traverse2 = function(node) {
3390
+ if (node instanceof Element) {
3391
+ if (isFocusable4(node, {
3392
+ skipNegativeTabIndexCheck,
3393
+ skipVisibilityCheck
3394
+ }) || include?.(node)) {
3395
+ elements[elements.length] = node;
3396
+ }
3397
+ }
3398
+ const children = getComposedChildren3(node);
3399
+ for (let i = 0, l = children.length; i < l; i++) {
3400
+ const child = children[i];
3401
+ if (!child) {
3402
+ continue;
3403
+ }
3404
+ traverse2(child);
3405
+ }
3406
+ };
3407
+ traverse2(container);
3408
+ } else {
3409
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR3);
3410
+ for (let i = 0, l = candidates.length; i < l; i++) {
3411
+ const candidate = candidates[i];
3412
+ if (!(candidate instanceof Element)) {
3413
+ continue;
3414
+ }
3415
+ if (isFocusable4(candidate, {
3416
+ skipNegativeTabIndexCheck,
3417
+ skipVisibilityCheck
3418
+ })) {
3419
+ elements[elements.length] = candidate;
3420
+ }
3421
+ }
3422
+ }
3423
+ const unfiltered = normalizeRadioGroup3(sortByTabIndex3(elements));
3424
+ return filter ? unfiltered.filter(filter) : unfiltered;
3425
+ }
3426
+ function isFocusable4(element, options = {}) {
3427
+ if (!(element instanceof Element)) {
3428
+ console.warn("Invalid element");
3429
+ return false;
3430
+ }
3431
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
3432
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
3433
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
3434
+ skipNegativeTabIndexCheck = false;
3435
+ }
3436
+ if (typeof skipVisibilityCheck !== "boolean") {
3437
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
3438
+ skipVisibilityCheck = false;
3439
+ }
3440
+ if (element.hasAttribute("hidden") || isInert3(element)) {
3441
+ return false;
3442
+ }
3443
+ if (!skipNegativeTabIndexCheck && getTabIndex3(element) < 0) {
3444
+ return false;
3445
+ }
3446
+ if (!element.matches(
3447
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR3.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR3
3448
+ )) {
3449
+ return false;
3450
+ }
3451
+ if (isDisabledDeep3(element)) {
3452
+ return false;
3453
+ }
3454
+ if (!skipVisibilityCheck && !element.checkVisibility({
3455
+ contentVisibilityAuto: true,
3456
+ opacityProperty: true,
3457
+ visibilityProperty: true
3458
+ })) {
3459
+ return false;
3460
+ }
3461
+ return true;
3462
+ }
3463
+ function isDisabledDeep3(element) {
3464
+ let current = element;
3465
+ while (current) {
3466
+ if (current instanceof ShadowRoot) {
3467
+ if (current.mode !== "open") {
3468
+ return false;
3469
+ }
3470
+ current = current.host;
3471
+ continue;
3472
+ }
3473
+ if (!(current instanceof Element)) {
3474
+ current = current.parentNode;
3475
+ continue;
3476
+ }
3477
+ if (current === element && isFormControl3(current) && isDisabled3(current)) {
3478
+ return true;
3479
+ }
3480
+ if (isInert3(current)) {
3481
+ return true;
3482
+ }
3483
+ if (isFormControl3(element) && current.tagName === "FIELDSET" && isDisabled3(current)) {
3484
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
3485
+ return true;
3486
+ }
3487
+ }
3488
+ current = current.parentNode;
3489
+ }
3490
+ return false;
3491
+ }
3492
+ function normalizeRadioGroup3(elements) {
3493
+ let map = null;
3494
+ for (let i = 0, l = elements.length; i < l; i++) {
3495
+ const element = elements[i];
3496
+ if (!(element instanceof HTMLInputElement)) {
3497
+ continue;
3498
+ }
3499
+ if (!isUngroupedRadio3(element)) {
3500
+ continue;
3501
+ }
3502
+ if (!map) {
3503
+ map = /* @__PURE__ */ new Map();
3504
+ }
3505
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
3506
+ const group = map.get(key) ?? map.set(key, []).get(key);
3507
+ if (group) {
3508
+ group[group.length] = element;
3509
+ }
3510
+ }
3511
+ if (!map) {
3512
+ return elements;
3513
+ }
3514
+ const placeholder = /* @__PURE__ */ new Set();
3515
+ for (const group of map.values()) {
3516
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
3517
+ }
3518
+ return elements.filter((element) => {
3519
+ if (isUngroupedRadio3(element)) {
3520
+ return placeholder.has(element);
3521
+ }
3522
+ return true;
3523
+ });
3524
+ }
3525
+ function sortByTabIndex3(elements) {
3526
+ const ordered = [];
3527
+ const natural = [];
3528
+ for (let i = 0, l = elements.length; i < l; i++) {
3529
+ const element = elements[i];
3530
+ if (!element) {
3531
+ continue;
3532
+ }
3533
+ const target = getTabIndex3(element) > 0 ? ordered : natural;
3534
+ target[target.length] = element;
3535
+ }
3536
+ ordered.sort((a, b) => getTabIndex3(a) - getTabIndex3(b));
3537
+ let count = 0;
3538
+ const sorted = new Array(ordered.length + natural.length);
3539
+ for (let i = 0, l = ordered.length; i < l; i++) {
3540
+ sorted[count++] = ordered[i];
3541
+ }
3542
+ for (let i = 0, l = natural.length; i < l; i++) {
3543
+ sorted[count++] = natural[i];
3544
+ }
3545
+ return sorted;
3546
+ }
3547
+ function getComposedChildren3(node) {
3548
+ if (node instanceof ShadowRoot) {
3549
+ return getChildren3(node);
3550
+ }
3551
+ if (!(node instanceof Element)) {
3552
+ return [];
3553
+ }
3554
+ if (node instanceof HTMLSlotElement) {
3555
+ const assigned = node.assignedElements({ flatten: true });
3556
+ if (assigned.length) {
3557
+ return assigned;
3558
+ }
3559
+ }
3560
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
3561
+ return getChildren3(node.shadowRoot);
3562
+ }
3563
+ return getChildren3(node);
3564
+ }
3565
+ function getChildren3(node) {
3566
+ const elements = [];
3567
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
3568
+ elements[elements.length] = child;
3569
+ }
3570
+ return elements;
3571
+ }
3572
+ function getTabIndex3(element) {
3573
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
3574
+ }
3575
+ function isDisabled3(element) {
3576
+ return "disabled" in element && !!element.disabled;
3577
+ }
3578
+ function isFormControl3(element) {
3579
+ const name = element.tagName;
3580
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
3581
+ }
3582
+ function isInert3(element) {
3583
+ return "inert" in element && !!element.inert;
3584
+ }
3585
+ function isUngroupedRadio3(element) {
3586
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
3587
+ }
3588
+ function createRovingTabIndex2(container, options = {}) {
3589
+ if (!(container instanceof Element)) {
3590
+ console.warn("Invalid container element");
3591
+ return () => {
3592
+ };
3593
+ }
3594
+ let {
3595
+ direction,
3596
+ navigationOnly = false,
3597
+ noMemory = false,
3598
+ noStart = false,
3599
+ selector,
3600
+ typeahead = false,
3601
+ wrap = false
3602
+ } = options;
3603
+ if (typeof direction !== "undefined" && !["horizontal", "vertical"].includes(direction)) {
3604
+ console.warn("Invalid direction option. Fallback: both (undefined).");
3605
+ direction = void 0;
3606
+ }
3607
+ if (typeof navigationOnly !== "boolean") {
3608
+ console.warn("Invalid navigationOnly option. Fallback: false.");
3609
+ navigationOnly = false;
3610
+ }
3611
+ if (typeof noMemory !== "boolean") {
3612
+ console.warn("Invalid noMemory option. Fallback: false.");
3613
+ noMemory = false;
3614
+ }
3615
+ if (typeof noStart !== "boolean") {
3616
+ console.warn("Invalid noStart option. Fallback: false.");
3617
+ noStart = false;
3618
+ }
3619
+ if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
3620
+ console.warn(
3621
+ "Invalid selector. Fallback: all focusable elements (undefined)."
3622
+ );
3623
+ selector = void 0;
3624
+ }
3625
+ if (typeof typeahead !== "boolean") {
3626
+ console.warn("Invalid typeahead option. Fallback: false.");
3627
+ typeahead = false;
3628
+ }
3629
+ if (typeof wrap !== "boolean") {
3630
+ console.warn("Invalid wrap option. Fallback: false.");
3631
+ wrap = false;
3632
+ }
3633
+ const settings = { navigationOnly, noMemory, noStart, typeahead, wrap };
3634
+ direction && Object.assign(settings, { direction });
3635
+ selector && Object.assign(settings, { selector });
3636
+ const roving = new RovingTabIndex2(container, settings);
3637
+ return () => roving.destroy();
3638
+ }
3639
+ var RovingTabIndex2 = class {
3640
+ #container;
3641
+ #options;
3642
+ #focusables = /* @__PURE__ */ new Set();
3643
+ #focusablesByFirstChar = /* @__PURE__ */ new Map();
3644
+ #selectorFilter;
3645
+ #controller = null;
3646
+ #isDestroyed = false;
3647
+ constructor(container, options = {}) {
3648
+ this.#container = container;
3649
+ this.#options = options;
3650
+ this.#selectorFilter = this.#createSelectorFilter();
3651
+ this.#initialize();
3652
+ }
3653
+ destroy() {
3654
+ if (this.#isDestroyed) {
3655
+ return;
3656
+ }
3657
+ this.#isDestroyed = true;
3658
+ this.#controller?.abort();
3659
+ this.#controller = null;
3660
+ restoreAttributes4([...this.#focusables]);
3661
+ this.#focusables.clear();
3662
+ this.#focusablesByFirstChar.clear();
3663
+ this.#container.removeAttribute("data-roving-tabindex-initialized");
3664
+ }
3665
+ #initialize() {
3666
+ this.#update(document.activeElement);
3667
+ this.#controller = new AbortController();
3668
+ const { signal } = this.#controller;
3669
+ document.addEventListener("focusin", this.#onFocusIn, {
3670
+ capture: true,
3671
+ signal
3672
+ });
3673
+ document.addEventListener("keydown", this.#onKeyDown, {
3674
+ capture: true,
3675
+ signal
3676
+ });
3677
+ this.#container.setAttribute("data-roving-tabindex-initialized", "");
3678
+ }
3679
+ #onFocusIn = (event) => {
3680
+ const { target } = event;
3681
+ if (!(target instanceof Element)) {
3682
+ return;
3683
+ }
3684
+ const isFocusable22 = this.#focusables.has(target);
3685
+ if (this.#options.noMemory && !isFocusable22) {
3686
+ this.#update(null);
3687
+ return;
3688
+ }
3689
+ isFocusable22 && this.#update(target);
3690
+ };
3691
+ #onKeyDown = (event) => {
3692
+ if (!event.composedPath().includes(this.#container)) {
3693
+ return;
3694
+ }
3695
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
3696
+ if (altKey || ctrlKey || metaKey || shiftKey) {
3697
+ return;
3698
+ }
3699
+ const { direction, typeahead, wrap } = this.#options;
3700
+ const isBoth = !direction;
3701
+ const isHorizontal = direction === "horizontal";
3702
+ if (![
3703
+ "End",
3704
+ "Home",
3705
+ ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
3706
+ ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
3707
+ ].includes(key)) {
3708
+ if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
3709
+ return;
3710
+ }
3711
+ }
3712
+ const active = getActiveElement5();
3713
+ if (!(active instanceof HTMLElement)) {
3714
+ return;
3715
+ }
3716
+ const current = this.#getFocusables();
3717
+ if (!current.includes(active)) {
3718
+ return;
3719
+ }
3720
+ event.preventDefault();
3721
+ event.stopPropagation();
3722
+ const currentIndex = current.indexOf(active);
3723
+ let rawIndex;
3724
+ let newIndex = currentIndex;
3725
+ let target = current;
3726
+ switch (key) {
3727
+ case "End":
3728
+ newIndex = -1;
3729
+ break;
3730
+ case "Home":
3731
+ newIndex = 0;
3732
+ break;
3733
+ case "ArrowLeft":
3734
+ case "ArrowUp":
3735
+ rawIndex = currentIndex - 1;
3736
+ newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
3737
+ break;
3738
+ case "ArrowRight":
3739
+ case "ArrowDown":
3740
+ rawIndex = currentIndex + 1;
3741
+ newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
3742
+ break;
3743
+ default: {
3744
+ target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
3745
+ const foundIndex = target.findIndex(
3746
+ (focusable2) => current.indexOf(focusable2) > currentIndex
3747
+ );
3748
+ newIndex = foundIndex >= 0 ? foundIndex : 0;
3749
+ }
3750
+ }
3751
+ const focusable = target.at(newIndex);
3752
+ focusable && focusElement3(focusable);
3753
+ };
3754
+ #update(active) {
3755
+ const current = new Set(this.#getFocusables());
3756
+ for (const focusable of this.#focusables) {
3757
+ if (current.has(focusable)) {
3758
+ continue;
3759
+ }
3760
+ focusable.isConnected && restoreAttributes4([focusable]);
3761
+ this.#focusables.delete(focusable);
3762
+ this.#focusablesByFirstChar.forEach((focusables) => {
3763
+ const index = focusables.indexOf(focusable);
3764
+ index >= 0 && focusables.splice(index, 1);
3765
+ });
3766
+ }
3767
+ const { navigationOnly, noStart, typeahead } = this.#options;
3768
+ for (const focusable of current) {
3769
+ if (this.#focusables.has(focusable)) {
3770
+ continue;
3771
+ }
3772
+ this.#focusables.add(focusable);
3773
+ if (!navigationOnly) {
3774
+ saveAttributes4([focusable], ["tabindex"]);
3775
+ focusable.setAttribute("tabindex", "-1");
3776
+ }
3777
+ if (!typeahead) {
3778
+ continue;
3779
+ }
3780
+ const value = focusable.ariaKeyShortcuts?.trim();
3781
+ const keys = new Set(
3782
+ value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
3783
+ );
3784
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
3785
+ if (char) {
3786
+ keys.add(char);
3787
+ saveAttributes4([focusable], ["aria-keyshortcuts"]);
3788
+ addTokenToAttribute3(focusable, "aria-keyshortcuts", char, {
3789
+ caseInsensitive: true
3790
+ });
3791
+ }
3792
+ keys.forEach((key) => {
3793
+ const focusables = this.#focusablesByFirstChar.get(key) ?? [];
3794
+ focusables.push(focusable);
3795
+ this.#focusablesByFirstChar.set(key, focusables);
3796
+ });
3797
+ }
3798
+ if (navigationOnly) {
3799
+ return;
3800
+ }
3801
+ if (active && this.#focusables.has(active)) {
3802
+ this.#focusables.forEach((focusable) => {
3803
+ focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
3804
+ });
3805
+ return;
3806
+ }
3807
+ [...this.#focusables].forEach((focusable, i) => {
3808
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
3809
+ });
3810
+ }
3811
+ #createSelectorFilter() {
3812
+ const { selector } = this.#options;
3813
+ return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
3814
+ }
3815
+ #getFocusables() {
3816
+ return getFocusables3(this.#container, {
3817
+ composed: true,
3818
+ filter: this.#selectorFilter,
3819
+ skipNegativeTabIndexCheck: !this.#options.navigationOnly,
3820
+ skipVisibilityCheck: true
3821
+ });
3822
+ }
3823
+ };
3824
+ function focusElement3(element) {
3825
+ "focus" in element && typeof element.focus === "function" && element.focus();
3826
+ }
3827
+ function getActiveElement5() {
3828
+ let current = document.activeElement;
3829
+ while (current?.shadowRoot?.activeElement) {
3830
+ current = current.shadowRoot.activeElement;
3831
+ }
3832
+ return current;
3833
+ }
3834
+
3835
+ // node_modules/power-focusable/dist/index.js
3836
+ var FOCUSABLE_SELECTOR4 = `: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"])`;
3837
+ function getFocusables4(container = document.body, options = {}) {
3838
+ if (!(container instanceof Element)) {
3839
+ console.warn("Invalid container element. Fallback: <body> element.");
3840
+ container = document.body;
3841
+ }
3842
+ let {
3843
+ composed = false,
3844
+ filter,
3845
+ include,
3846
+ skipNegativeTabIndexCheck = false,
3847
+ skipVisibilityCheck = false
3848
+ } = options;
3849
+ if (typeof composed !== "boolean") {
3850
+ console.warn("Invalid composed option. Fallback: false.");
3851
+ composed = false;
3852
+ }
3853
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
3854
+ console.warn(
3855
+ "Invalid filter function. Fallback: no filter function (undefined)."
3856
+ );
3857
+ filter = void 0;
3858
+ }
3859
+ if (typeof include !== "undefined" && typeof include !== "function") {
3860
+ console.warn(
3861
+ "Invalid include function. Fallback: no include function (undefined)."
3862
+ );
3863
+ include = void 0;
3864
+ }
3865
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
3866
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
3867
+ skipNegativeTabIndexCheck = false;
3868
+ }
3869
+ if (typeof skipVisibilityCheck !== "boolean") {
3870
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
3871
+ skipVisibilityCheck = false;
3872
+ }
3873
+ const elements = [];
3874
+ if (composed || include) {
3875
+ let traverse2 = function(node) {
3876
+ if (node instanceof Element) {
3877
+ if (isFocusable5(node, {
3878
+ skipNegativeTabIndexCheck,
3879
+ skipVisibilityCheck
3880
+ }) || include?.(node)) {
3881
+ elements[elements.length] = node;
3882
+ }
3883
+ }
3884
+ const children = getComposedChildren4(node);
3885
+ for (let i = 0, l = children.length; i < l; i++) {
3886
+ const child = children[i];
3887
+ if (!child) {
3888
+ continue;
3889
+ }
3890
+ traverse2(child);
3891
+ }
3892
+ };
3893
+ traverse2(container);
3894
+ } else {
3895
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR4);
3896
+ for (let i = 0, l = candidates.length; i < l; i++) {
3897
+ const candidate = candidates[i];
3898
+ if (!(candidate instanceof Element)) {
3899
+ continue;
3900
+ }
3901
+ if (isFocusable5(candidate, {
3902
+ skipNegativeTabIndexCheck,
3903
+ skipVisibilityCheck
3904
+ })) {
3905
+ elements[elements.length] = candidate;
3906
+ }
3907
+ }
3908
+ }
3909
+ const unfiltered = normalizeRadioGroup4(sortByTabIndex4(elements));
3910
+ return filter ? unfiltered.filter(filter) : unfiltered;
3911
+ }
3912
+ function getNextFocusable2(container = document.body, options = {}) {
3913
+ return getRelativeFocusable2(container, 1, options);
3914
+ }
3915
+ function isFocusable5(element, options = {}) {
3916
+ if (!(element instanceof Element)) {
3917
+ console.warn("Invalid element");
3918
+ return false;
3919
+ }
3920
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
3921
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
3922
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
3923
+ skipNegativeTabIndexCheck = false;
3924
+ }
3925
+ if (typeof skipVisibilityCheck !== "boolean") {
3926
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
3927
+ skipVisibilityCheck = false;
3928
+ }
3929
+ if (element.hasAttribute("hidden") || isInert4(element)) {
3930
+ return false;
3931
+ }
3932
+ if (!skipNegativeTabIndexCheck && getTabIndex4(element) < 0) {
3933
+ return false;
3934
+ }
3935
+ if (!element.matches(
3936
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR4.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR4
3937
+ )) {
3938
+ return false;
3939
+ }
3940
+ if (isDisabledDeep4(element)) {
3941
+ return false;
3942
+ }
3943
+ if (!skipVisibilityCheck && !element.checkVisibility({
3944
+ contentVisibilityAuto: true,
3945
+ opacityProperty: true,
3946
+ visibilityProperty: true
3947
+ })) {
3948
+ return false;
3949
+ }
3950
+ return true;
3951
+ }
3952
+ function getRelativeFocusable2(container, offset3, options) {
3953
+ if (!(container instanceof Element)) {
3954
+ console.warn("Invalid container element. Fallback: <body> element.");
3955
+ container = document.body;
3956
+ }
3957
+ let {
3958
+ anchor = getActiveElement6(),
3959
+ composed = false,
3960
+ filter,
3961
+ include,
3962
+ skipNegativeTabIndexCheck = false,
3963
+ skipVisibilityCheck = false,
3964
+ wrap = false
3965
+ } = options;
3966
+ if (!(anchor instanceof Element)) {
3967
+ const active = getActiveElement6();
3968
+ if (active instanceof Element) {
3969
+ console.warn("Invalid anchor element. Fallback: active element.");
3970
+ anchor = active;
3971
+ } else {
3972
+ console.warn("Invalid anchor element");
3973
+ return null;
3974
+ }
3975
+ }
3976
+ if (!containsComposed3(container, anchor)) {
3977
+ console.warn("Anchor (active) element not within container");
3978
+ return null;
3979
+ }
3980
+ if (typeof composed !== "boolean") {
3981
+ console.warn("Invalid composed option. Fallback: false.");
3982
+ composed = false;
3983
+ }
3984
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
3985
+ console.warn(
3986
+ "Invalid filter function. Fallback: no filter function (undefined)."
3987
+ );
3988
+ filter = void 0;
3989
+ }
3990
+ if (typeof include !== "undefined" && typeof include !== "function") {
3991
+ console.warn(
3992
+ "Invalid include function. Fallback: no include function (undefined)."
3993
+ );
3994
+ include = void 0;
3995
+ }
3996
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
3997
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
3998
+ skipNegativeTabIndexCheck = false;
3999
+ }
4000
+ if (typeof skipVisibilityCheck !== "boolean") {
4001
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
4002
+ skipVisibilityCheck = false;
4003
+ }
4004
+ if (typeof wrap !== "boolean") {
4005
+ console.warn("Invalid wrap option. Fallback: false.");
4006
+ wrap = false;
4007
+ }
4008
+ const settings = { composed, skipNegativeTabIndexCheck, skipVisibilityCheck };
4009
+ if (filter !== void 0) {
4010
+ Object.assign(settings, { filter });
4011
+ }
4012
+ if (include !== void 0) {
4013
+ Object.assign(settings, { include });
4014
+ }
4015
+ const focusables = getFocusables4(container, settings);
4016
+ const { length } = focusables;
4017
+ if (!length) {
4018
+ return null;
4019
+ }
4020
+ const currentIndex = focusables.indexOf(anchor);
4021
+ if (currentIndex === -1) {
4022
+ return null;
4023
+ }
4024
+ const offsetIndex = currentIndex + offset3;
4025
+ if ((offsetIndex < 0 || offsetIndex >= length) && !wrap) {
4026
+ return null;
4027
+ }
4028
+ return focusables[(offsetIndex + length) % length] ?? null;
4029
+ }
4030
+ function isDisabledDeep4(element) {
4031
+ let current = element;
4032
+ while (current) {
4033
+ if (current instanceof ShadowRoot) {
4034
+ if (current.mode !== "open") {
4035
+ return false;
4036
+ }
4037
+ current = current.host;
4038
+ continue;
4039
+ }
4040
+ if (!(current instanceof Element)) {
4041
+ current = current.parentNode;
4042
+ continue;
4043
+ }
4044
+ if (current === element && isFormControl4(current) && isDisabled4(current)) {
4045
+ return true;
4046
+ }
4047
+ if (isInert4(current)) {
4048
+ return true;
4049
+ }
4050
+ if (isFormControl4(element) && current.tagName === "FIELDSET" && isDisabled4(current)) {
4051
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
4052
+ return true;
4053
+ }
4054
+ }
4055
+ current = current.parentNode;
4056
+ }
4057
+ return false;
4058
+ }
4059
+ function normalizeRadioGroup4(elements) {
4060
+ let map = null;
4061
+ for (let i = 0, l = elements.length; i < l; i++) {
4062
+ const element = elements[i];
4063
+ if (!(element instanceof HTMLInputElement)) {
4064
+ continue;
4065
+ }
4066
+ if (!isUngroupedRadio4(element)) {
4067
+ continue;
4068
+ }
4069
+ if (!map) {
4070
+ map = /* @__PURE__ */ new Map();
4071
+ }
4072
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
4073
+ const group = map.get(key) ?? map.set(key, []).get(key);
4074
+ if (group) {
4075
+ group[group.length] = element;
4076
+ }
4077
+ }
4078
+ if (!map) {
4079
+ return elements;
4080
+ }
4081
+ const placeholder = /* @__PURE__ */ new Set();
4082
+ for (const group of map.values()) {
4083
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
4084
+ }
4085
+ return elements.filter((element) => {
4086
+ if (isUngroupedRadio4(element)) {
4087
+ return placeholder.has(element);
4088
+ }
4089
+ return true;
4090
+ });
4091
+ }
4092
+ function sortByTabIndex4(elements) {
4093
+ const ordered = [];
4094
+ const natural = [];
4095
+ for (let i = 0, l = elements.length; i < l; i++) {
4096
+ const element = elements[i];
4097
+ if (!element) {
4098
+ continue;
4099
+ }
4100
+ const target = getTabIndex4(element) > 0 ? ordered : natural;
4101
+ target[target.length] = element;
4102
+ }
4103
+ ordered.sort((a, b) => getTabIndex4(a) - getTabIndex4(b));
4104
+ let count = 0;
4105
+ const sorted = new Array(ordered.length + natural.length);
4106
+ for (let i = 0, l = ordered.length; i < l; i++) {
4107
+ sorted[count++] = ordered[i];
4108
+ }
4109
+ for (let i = 0, l = natural.length; i < l; i++) {
4110
+ sorted[count++] = natural[i];
4111
+ }
4112
+ return sorted;
4113
+ }
4114
+ function containsComposed3(container, element) {
4115
+ let current = element;
4116
+ while (current) {
4117
+ if (current === container) {
4118
+ return true;
4119
+ }
4120
+ current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
4121
+ }
4122
+ return false;
4123
+ }
4124
+ function getComposedChildren4(node) {
4125
+ if (node instanceof ShadowRoot) {
4126
+ return getChildren4(node);
4127
+ }
4128
+ if (!(node instanceof Element)) {
4129
+ return [];
4130
+ }
4131
+ if (node instanceof HTMLSlotElement) {
4132
+ const assigned = node.assignedElements({ flatten: true });
4133
+ if (assigned.length) {
4134
+ return assigned;
4135
+ }
4136
+ }
4137
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
4138
+ return getChildren4(node.shadowRoot);
4139
+ }
4140
+ return getChildren4(node);
4141
+ }
4142
+ function getActiveElement6() {
4143
+ let current = document.activeElement;
4144
+ while (current?.shadowRoot?.activeElement) {
4145
+ current = current.shadowRoot.activeElement;
4146
+ }
4147
+ return current;
4148
+ }
4149
+ function getChildren4(node) {
4150
+ const elements = [];
4151
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
4152
+ elements[elements.length] = child;
4153
+ }
4154
+ return elements;
4155
+ }
4156
+ function getTabIndex4(element) {
4157
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
4158
+ }
4159
+ function isDisabled4(element) {
4160
+ return "disabled" in element && !!element.disabled;
4161
+ }
4162
+ function isFormControl4(element) {
4163
+ const name = element.tagName;
4164
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
4165
+ }
4166
+ function isInert4(element) {
4167
+ return "inert" in element && !!element.inert;
4168
+ }
4169
+ function isUngroupedRadio4(element) {
4170
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
4171
+ }
4172
+
4173
+ // src/index.ts
4174
+ var PathBar = class _PathBar {
4175
+ static defaults = {};
4176
+ #rootElement;
4177
+ #defaults = {
4178
+ animation: { duration: 300 },
4179
+ popover: {
4180
+ arrow: true,
4181
+ middleware: [flip2(), offset2(), shift2()],
4182
+ placement: "bottom-start"
4183
+ },
4184
+ selector: {
4185
+ item: "li",
4186
+ list: "ol",
4187
+ menu: {
4188
+ item: '[role^="menuitem"]',
4189
+ list: '[role="menu"]',
4190
+ trigger: "[data-menu-trigger]"
4191
+ }
4192
+ }
4193
+ };
4194
+ #settings;
4195
+ #listElement;
4196
+ #itemElements;
4197
+ #linkElements;
4198
+ #bindings = /* @__PURE__ */ new WeakMap();
4199
+ #controller = null;
4200
+ #cleanupRovingTabIndex = null;
4201
+ #autoOpen = false;
4202
+ #menus = [];
4203
+ #isDestroyed = false;
4204
+ constructor(root, options = {}) {
4205
+ if (!(root instanceof HTMLElement)) {
4206
+ throw new TypeError("Invalid root element");
4207
+ }
4208
+ if (root.hasAttribute("data-path-bar-initialized")) {
4209
+ console.warn("Already initialized");
4210
+ return;
4211
+ }
4212
+ this.#rootElement = root;
4213
+ this.#defaults = this.#mergeOptions(this.#defaults, _PathBar.defaults);
4214
+ this.#settings = this.#mergeOptions(this.#defaults, options);
4215
+ matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
4216
+ const { selector } = this.#settings;
4217
+ this.#listElement = this.#rootElement.querySelector(
4218
+ selector.list
4219
+ );
4220
+ if (!this.#listElement) {
4221
+ console.warn("Missing list element");
4222
+ return;
4223
+ }
4224
+ this.#itemElements = [
4225
+ ...this.#listElement.querySelectorAll(
4226
+ `${selector.item}:not(:scope ${selector.list} *)`
4227
+ )
4228
+ ];
4229
+ if (!this.#itemElements.length) {
4230
+ console.warn("Missing item elements");
4231
+ return;
4232
+ }
4233
+ this.#linkElements = [
4234
+ ...this.#listElement.querySelectorAll(
4235
+ `${selector.list} > * > a`
4236
+ )
4237
+ ];
4238
+ if (!this.#linkElements.length) {
4239
+ console.warn("Missing <a> elements");
4240
+ return;
4241
+ }
4242
+ this.#initialize();
4243
+ }
4244
+ async destroy(force = false) {
4245
+ if (this.#isDestroyed) {
4246
+ return;
4247
+ }
4248
+ this.#isDestroyed = true;
4249
+ this.#controller?.abort();
4250
+ this.#controller = null;
4251
+ this.#cleanupRovingTabIndex?.();
4252
+ this.#cleanupRovingTabIndex = null;
4253
+ await Promise.all(this.#menus.map((menu) => menu.destroy(force)));
4254
+ this.#menus.length = 0;
4255
+ const elements = this.#itemElements;
4256
+ if (this.#listElement) {
4257
+ elements.push(this.#listElement);
4258
+ }
4259
+ this.#listElement = null;
4260
+ this.#itemElements.length = 0;
4261
+ this.#rootElement.removeAttribute("data-path-bar-initialized");
4262
+ }
4263
+ #initialize() {
4264
+ this.#controller = new AbortController();
4265
+ const { signal } = this.#controller;
4266
+ if (!this.#listElement) {
4267
+ return;
4268
+ }
4269
+ this.#listElement.addEventListener("focusin", this.#onFocusIn, { signal });
4270
+ this.#listElement.addEventListener("focusout", this.#onFocusOut, {
4271
+ signal
4272
+ });
4273
+ this.#linkElements.forEach((link) => {
4274
+ link.addEventListener("keydown", this.#onKeyDown, { signal });
4275
+ const menuRoot = link.nextElementSibling;
4276
+ if (!(menuRoot instanceof HTMLElement)) {
4277
+ return;
4278
+ }
4279
+ const { animation, popover, selector } = this.#settings;
4280
+ const menuInstance = new Menu(
4281
+ menuRoot,
4282
+ { animation, popover: { menu: popover }, selector: selector.menu },
4283
+ { externalTrigger: link, isMenubar: true }
4284
+ );
4285
+ this.#bindings.set(link, createBinding(link, menuInstance));
4286
+ this.#menus.push(menuInstance);
4287
+ });
4288
+ this.#cleanupRovingTabIndex = createRovingTabIndex2(this.#listElement, {
4289
+ direction: "horizontal",
4290
+ noMemory: true,
4291
+ selector: `${this.#settings.selector.list} > * > a`,
4292
+ wrap: true
4293
+ });
4294
+ this.#rootElement.setAttribute("data-path-bar-initialized", "");
4295
+ }
4296
+ #onFocusIn = (event) => {
4297
+ if (!this.#autoOpen && !this.#hasOpenMenu()) {
4298
+ return;
4299
+ }
4300
+ const target = event.target;
4301
+ if (!(target instanceof HTMLElement)) {
4302
+ return;
4303
+ }
4304
+ const link = this.#linkElements.indexOf(target) >= 0 ? target : target.closest(this.#settings.selector.item)?.querySelector("a");
4305
+ if (!link) {
4306
+ return;
4307
+ }
4308
+ const menu = this.#bindings.get(link)?.menu;
4309
+ if (menu) {
4310
+ this.#autoOpen = true;
4311
+ menu.open();
4312
+ return;
4313
+ }
4314
+ this.#closeAllMenus();
4315
+ };
4316
+ #onFocusOut = (event) => {
4317
+ const target = event.relatedTarget;
4318
+ if (!(target instanceof HTMLElement)) {
4319
+ return;
4320
+ }
4321
+ if (!this.#rootElement.contains(target) && !this.#hasOpenMenu()) {
4322
+ this.#autoOpen = false;
4323
+ }
4324
+ };
4325
+ #onKeyDown = (event) => {
4326
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
4327
+ if (altKey || ctrlKey || metaKey || shiftKey) {
4328
+ return;
4329
+ }
4330
+ if (!["Tab", "Escape"].includes(key)) {
4331
+ return;
4332
+ }
4333
+ switch (key) {
4334
+ case "Tab": {
4335
+ event.preventDefault();
4336
+ this.#closeAllMenus();
4337
+ const next = getNextFocusable2();
4338
+ next instanceof HTMLElement && next.focus();
4339
+ break;
4340
+ }
4341
+ case "Escape":
4342
+ this.#autoOpen = false;
4343
+ break;
4344
+ }
4345
+ };
4346
+ #closeAllMenus() {
4347
+ this.#menus.filter((menu) => menu.isOpen()).forEach((menu) => {
4348
+ menu.close();
4349
+ });
4350
+ }
4351
+ #hasOpenMenu() {
4352
+ return this.#menus.some((menu) => menu.isOpen());
4353
+ }
4354
+ #mergeOptions(target, source) {
4355
+ return {
4356
+ ...target,
4357
+ ...source,
4358
+ animation: { ...target.animation, ...source.animation ?? {} },
4359
+ popover: {
4360
+ ...target.popover,
4361
+ ...source.popover ?? {},
4362
+ middleware: Object.assign(
4363
+ [...target.popover?.middleware ?? []],
4364
+ [...source.popover?.middleware ?? []]
4365
+ )
4366
+ },
4367
+ selector: {
4368
+ ...target.selector,
4369
+ ...source.selector ?? {},
4370
+ menu: { ...target.selector?.menu, ...source.selector?.menu ?? {} }
4371
+ }
4372
+ };
4373
+ }
4374
+ };
4375
+ function createBinding(link, menu) {
4376
+ return { link, menu };
4377
+ }
4378
+ /**
4379
+ * Path Bar
4380
+ * Breadcrumb-style path bar implementation in TypeScript.
4381
+ * Supports keyboard navigation, integrated menus, and seamless menu traversal.
4382
+ *
4383
+ * @version 1.0.0
4384
+ * @author Yusuke Kamiyamane
4385
+ * @license MIT
4386
+ * @copyright Copyright (c) Yusuke Kamiyamane
4387
+ * @see {@link https://github.com/y14e/path-bar}
4388
+ */
4389
+ /*! Bundled license information:
4390
+
4391
+ @y14e/menu/dist/index.js:
4392
+ (**
4393
+ * Menu
4394
+ * WAI-ARIA compliant menu (menu button) pattern implementation in TypeScript.
4395
+ * Supports checkbox item, radio item, and infinitely nested menus.
4396
+ *
4397
+ * @version 1.7.1
4398
+ * @author Yusuke Kamiyamane
4399
+ * @license MIT
4400
+ * @copyright Copyright (c) Yusuke Kamiyamane
4401
+ * @see {@link https://github.com/y14e/menu}
4402
+ *)
4403
+ (*! Bundled license information:
4404
+
4405
+ @y14e/attributes-utils/dist/index.js:
4406
+ (**
4407
+ * Attributes Utils
4408
+ *
4409
+ * @version 1.1.1
4410
+ * @author Yusuke Kamiyamane
4411
+ * @license MIT
4412
+ * @copyright Copyright (c) Yusuke Kamiyamane
4413
+ * @see {@link https://github.com/y14e/attributes-utils}
4414
+ *)
4415
+
4416
+ @y14e/button/dist/index.js:
4417
+ (**
4418
+ * Button
4419
+ *
4420
+ * @version 1.0.0
4421
+ * @author Yusuke Kamiyamane
4422
+ * @license MIT
4423
+ * @copyright Copyright (c) Yusuke Kamiyamane
4424
+ * @see {@link https://github.com/y14e/button}
4425
+ *)
4426
+
4427
+ @y14e/portal/dist/index.js:
4428
+ (**
4429
+ * Portal
4430
+ * Lightweight DOM portal (teleport) utility with fully focus management.
4431
+ * Designed for accessible dialogs, menus, overlays, popovers.
4432
+ *
4433
+ * @version 1.2.14
4434
+ * @author Yusuke Kamiyamane
4435
+ * @license MIT
4436
+ * @copyright Copyright (c) Yusuke Kamiyamane
4437
+ * @see {@link https://github.com/y14e/portal}
4438
+ *)
4439
+ (*! Bundled license information:
4440
+
4441
+ @y14e/attributes-utils/dist/index.js:
4442
+ (**
4443
+ * Attributes Utils
4444
+ *
4445
+ * @version 1.1.1
4446
+ * @author Yusuke Kamiyamane
4447
+ * @license MIT
4448
+ * @copyright Copyright (c) Yusuke Kamiyamane
4449
+ * @see {@link https://github.com/y14e/attributes-utils}
4450
+ *)
4451
+
4452
+ power-focusable/dist/index.js:
4453
+ (**
4454
+ * Power Focusable
4455
+ * High-precision focus management utility with full composed tree support.
4456
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
4457
+ *
4458
+ * @version 4.3.2
4459
+ * @author Yusuke Kamiyamane
4460
+ * @license MIT
4461
+ * @copyright Copyright (c) Yusuke Kamiyamane
4462
+ * @see {@link https://github.com/y14e/power-focusable}
4463
+ *)
4464
+ *)
4465
+
4466
+ @y14e/roving-tabindex/dist/index.js:
4467
+ (**
4468
+ * Roving Tabindex
4469
+ * Lightweight roving tabindex utility with fully focus management.
4470
+ * Designed for accessible menus, tabs, toolbars, and composite widgets.
4471
+ *
4472
+ * @version 2.2.0
4473
+ * @author Yusuke Kamiyamane
4474
+ * @license MIT
4475
+ * @copyright Copyright (c) Yusuke Kamiyamane
4476
+ * @see {@link https://github.com/y14e/roving-tabindex}
4477
+ *)
4478
+ (*! Bundled license information:
4479
+
4480
+ @y14e/attributes-utils/dist/index.js:
4481
+ (**
4482
+ * Attributes Utils
4483
+ *
4484
+ * @version 1.1.1
4485
+ * @author Yusuke Kamiyamane
4486
+ * @license MIT
4487
+ * @copyright Copyright (c) Yusuke Kamiyamane
4488
+ * @see {@link https://github.com/y14e/attributes-utils}
4489
+ *)
4490
+
4491
+ power-focusable/dist/index.js:
4492
+ (**
4493
+ * Power Focusable
4494
+ * High-precision focus management utility with full composed tree support.
4495
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
4496
+ *
4497
+ * @version 4.3.2
4498
+ * @author Yusuke Kamiyamane
4499
+ * @license MIT
4500
+ * @copyright Copyright (c) Yusuke Kamiyamane
4501
+ * @see {@link https://github.com/y14e/power-focusable}
4502
+ *)
4503
+ *)
4504
+ *)
4505
+
4506
+ @y14e/roving-tabindex/dist/index.js:
4507
+ (**
4508
+ * Roving Tabindex
4509
+ * Lightweight roving tabindex utility with fully focus management.
4510
+ * Designed for accessible menus, tabs, toolbars, and composite widgets.
4511
+ *
4512
+ * @version 2.2.0
4513
+ * @author Yusuke Kamiyamane
4514
+ * @license MIT
4515
+ * @copyright Copyright (c) Yusuke Kamiyamane
4516
+ * @see {@link https://github.com/y14e/roving-tabindex}
4517
+ *)
4518
+ (*! Bundled license information:
4519
+
4520
+ @y14e/attributes-utils/dist/index.js:
4521
+ (**
4522
+ * Attributes Utils
4523
+ *
4524
+ * @version 1.1.1
4525
+ * @author Yusuke Kamiyamane
4526
+ * @license MIT
4527
+ * @copyright Copyright (c) Yusuke Kamiyamane
4528
+ * @see {@link https://github.com/y14e/attributes-utils}
4529
+ *)
4530
+
4531
+ power-focusable/dist/index.js:
4532
+ (**
4533
+ * Power Focusable
4534
+ * High-precision focus management utility with full composed tree support.
4535
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
4536
+ *
4537
+ * @version 4.3.2
4538
+ * @author Yusuke Kamiyamane
4539
+ * @license MIT
4540
+ * @copyright Copyright (c) Yusuke Kamiyamane
4541
+ * @see {@link https://github.com/y14e/power-focusable}
4542
+ *)
4543
+ *)
4544
+
4545
+ power-focusable/dist/index.js:
4546
+ (**
4547
+ * Power Focusable
4548
+ * High-precision focus management utility with full composed tree support.
4549
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
4550
+ *
4551
+ * @version 4.3.2
4552
+ * @author Yusuke Kamiyamane
4553
+ * @license MIT
4554
+ * @copyright Copyright (c) Yusuke Kamiyamane
4555
+ * @see {@link https://github.com/y14e/power-focusable}
4556
+ *)
4557
+ */
4558
+
4559
+ export { PathBar as default, flip2 as flip, offset2 as offset, shift2 as shift };