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