@y14e/disclosure 2.2.3 → 2.2.5
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.bundle.cjs +100 -139
- package/dist/index.bundle.js +100 -139
- package/dist/index.cjs +14 -34
- package/dist/index.js +14 -34
- package/package.json +3 -3
package/dist/index.bundle.cjs
CHANGED
|
@@ -91,26 +91,29 @@ function resolveOptions(options) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// node_modules/power-focusable/dist/index.js
|
|
94
|
-
function getComposedChildren(
|
|
95
|
-
if (
|
|
96
|
-
return [...
|
|
94
|
+
function getComposedChildren(element) {
|
|
95
|
+
if (element instanceof ShadowRoot) {
|
|
96
|
+
return [...element.children];
|
|
97
97
|
}
|
|
98
|
-
if (!(
|
|
98
|
+
if (!(element instanceof Element)) {
|
|
99
99
|
return [];
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
102
|
-
const assigned =
|
|
101
|
+
if (element instanceof HTMLSlotElement) {
|
|
102
|
+
const assigned = element.assignedElements({ flatten: true });
|
|
103
103
|
if (assigned.length) {
|
|
104
104
|
return assigned;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
if (
|
|
108
|
-
return [...
|
|
107
|
+
if (element instanceof HTMLElement && element.shadowRoot?.mode === "open") {
|
|
108
|
+
return [...element.shadowRoot.children];
|
|
109
109
|
}
|
|
110
|
-
return [...
|
|
110
|
+
return [...element.children];
|
|
111
111
|
}
|
|
112
112
|
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"])';
|
|
113
|
-
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
113
|
+
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
114
|
+
/(,\s*)?\[tabindex="-1"\]/g,
|
|
115
|
+
""
|
|
116
|
+
);
|
|
114
117
|
function focusElement(element) {
|
|
115
118
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
116
119
|
}
|
|
@@ -122,7 +125,7 @@ function getActiveElement() {
|
|
|
122
125
|
return current;
|
|
123
126
|
}
|
|
124
127
|
function getTabIndex(element) {
|
|
125
|
-
return "tabIndex" in element ? Number(element.tabIndex) :
|
|
128
|
+
return "tabIndex" in element ? Number(element.tabIndex) : -1;
|
|
126
129
|
}
|
|
127
130
|
function isDisabled(element) {
|
|
128
131
|
return "disabled" in element && !!element.disabled;
|
|
@@ -133,8 +136,8 @@ function isFormControl(element) {
|
|
|
133
136
|
function isInert(element) {
|
|
134
137
|
return "inert" in element && !!element.inert;
|
|
135
138
|
}
|
|
136
|
-
function isUngroupedRadio(
|
|
137
|
-
return
|
|
139
|
+
function isUngroupedRadio(input) {
|
|
140
|
+
return input.type === "radio" && !!input.name;
|
|
138
141
|
}
|
|
139
142
|
function resolveOptions2(options) {
|
|
140
143
|
let {
|
|
@@ -158,15 +161,11 @@ function resolveOptions2(options) {
|
|
|
158
161
|
composed = false;
|
|
159
162
|
}
|
|
160
163
|
if (filter !== void 0 && typeof filter !== "function") {
|
|
161
|
-
console.warn(
|
|
162
|
-
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
163
|
-
);
|
|
164
|
+
console.warn("Invalid filter function. Fallback: no filter function (undefined).");
|
|
164
165
|
filter = void 0;
|
|
165
166
|
}
|
|
166
167
|
if (include !== void 0 && typeof include !== "function") {
|
|
167
|
-
console.warn(
|
|
168
|
-
"Invalid include function. Fallback: no include function (undefined)."
|
|
169
|
-
);
|
|
168
|
+
console.warn("Invalid include function. Fallback: no include function (undefined).");
|
|
170
169
|
include = void 0;
|
|
171
170
|
}
|
|
172
171
|
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
@@ -211,10 +210,8 @@ function isDisabledDeep(element) {
|
|
|
211
210
|
if (isInert(current)) {
|
|
212
211
|
return true;
|
|
213
212
|
}
|
|
214
|
-
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
215
|
-
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
213
|
+
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current) && !current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
|
|
214
|
+
return true;
|
|
218
215
|
}
|
|
219
216
|
current = current.parentNode;
|
|
220
217
|
}
|
|
@@ -223,10 +220,7 @@ function isDisabledDeep(element) {
|
|
|
223
220
|
function normalizeRadioGroup(elements) {
|
|
224
221
|
let map = null;
|
|
225
222
|
for (const element of elements) {
|
|
226
|
-
if (!(element instanceof HTMLInputElement)) {
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (!isUngroupedRadio(element)) {
|
|
223
|
+
if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
|
|
230
224
|
continue;
|
|
231
225
|
}
|
|
232
226
|
if (!map) {
|
|
@@ -276,42 +270,24 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
276
270
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
277
271
|
container = document.body;
|
|
278
272
|
}
|
|
279
|
-
const {
|
|
280
|
-
composed,
|
|
281
|
-
filter,
|
|
282
|
-
include,
|
|
283
|
-
skipNegativeTabIndexCheck,
|
|
284
|
-
skipVisibilityCheck
|
|
285
|
-
} = resolveOptions2(options);
|
|
273
|
+
const { composed, filter, include, skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions2(options);
|
|
286
274
|
const candidates = [];
|
|
287
275
|
if (!composed && !include) {
|
|
288
276
|
for (const match of container.querySelectorAll(
|
|
289
277
|
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
290
278
|
)) {
|
|
291
|
-
match && isFocusable(match, {
|
|
292
|
-
skipNegativeTabIndexCheck,
|
|
293
|
-
skipVisibilityCheck
|
|
294
|
-
}) && candidates.push(match);
|
|
279
|
+
match && isFocusable(match, { skipNegativeTabIndexCheck, skipVisibilityCheck }) && candidates.push(match);
|
|
295
280
|
}
|
|
296
281
|
} else {
|
|
297
|
-
let traverse2 = function(
|
|
298
|
-
if (isFocusable(
|
|
299
|
-
|
|
300
|
-
skipVisibilityCheck
|
|
301
|
-
}) || include?.(node)) {
|
|
302
|
-
candidates.push(node);
|
|
282
|
+
let traverse2 = function(element) {
|
|
283
|
+
if (isFocusable(element, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(element)) {
|
|
284
|
+
candidates.push(element);
|
|
303
285
|
}
|
|
304
|
-
(!composed ? [...
|
|
305
|
-
traverse2
|
|
306
|
-
);
|
|
286
|
+
(!composed ? [...element.children] : getComposedChildren(element)).map(traverse2);
|
|
307
287
|
};
|
|
308
|
-
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
309
|
-
traverse2
|
|
310
|
-
);
|
|
288
|
+
(!composed ? [...container.children] : getComposedChildren(container)).map(traverse2);
|
|
311
289
|
}
|
|
312
|
-
return normalizeRadioGroup(
|
|
313
|
-
sortByTabIndex(!filter ? candidates : candidates.filter(filter))
|
|
314
|
-
);
|
|
290
|
+
return normalizeRadioGroup(sortByTabIndex(!filter ? candidates : candidates.filter(filter)));
|
|
315
291
|
}
|
|
316
292
|
function isFocusable(element, options = {}) {
|
|
317
293
|
if (!(element instanceof Element)) {
|
|
@@ -344,39 +320,29 @@ function isFocusable(element, options = {}) {
|
|
|
344
320
|
}
|
|
345
321
|
|
|
346
322
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
347
|
-
|
|
323
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
324
|
+
function getCellCenter(cell) {
|
|
348
325
|
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
349
326
|
return { x: left + width / 2, y: top + height / 2 };
|
|
350
327
|
}
|
|
351
|
-
function getCellsOfActiveRow(cells) {
|
|
352
|
-
const active = getActiveElement();
|
|
353
|
-
if (!(active instanceof Element)) {
|
|
354
|
-
return [];
|
|
355
|
-
}
|
|
356
|
-
const activeRect = active.getBoundingClientRect();
|
|
357
|
-
return cells.filter((cell) => {
|
|
358
|
-
const cellRect = cell.getBoundingClientRect();
|
|
359
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
328
|
function getNextCell(cells, key, wrap) {
|
|
363
329
|
const active = getActiveElement();
|
|
364
330
|
if (!(active instanceof Element)) {
|
|
365
331
|
return null;
|
|
366
332
|
}
|
|
367
|
-
const
|
|
333
|
+
const activeCenter = getCellCenter(active);
|
|
368
334
|
let min = Infinity;
|
|
369
335
|
let result = null;
|
|
370
336
|
for (const cell of cells) {
|
|
371
337
|
if (cell === active) {
|
|
372
338
|
continue;
|
|
373
339
|
}
|
|
374
|
-
const
|
|
340
|
+
const cellCenter = getCellCenter(cell);
|
|
375
341
|
const distances = {
|
|
376
|
-
x: Math.abs(
|
|
377
|
-
y: Math.abs(
|
|
342
|
+
x: Math.abs(cellCenter.x - activeCenter.x),
|
|
343
|
+
y: Math.abs(cellCenter.y - activeCenter.y)
|
|
378
344
|
};
|
|
379
|
-
if (key === "ArrowUp" &&
|
|
345
|
+
if (key === "ArrowUp" && cellCenter.y < activeCenter.y && distances.x < distances.y || key === "ArrowDown" && cellCenter.y > activeCenter.y && distances.x < distances.y) {
|
|
380
346
|
const distance = distances.x ** 2 + distances.y ** 2;
|
|
381
347
|
if (distance < min) {
|
|
382
348
|
min = distance;
|
|
@@ -390,9 +356,9 @@ function getNextCell(cells, key, wrap) {
|
|
|
390
356
|
if (cell === active) {
|
|
391
357
|
continue;
|
|
392
358
|
}
|
|
393
|
-
const
|
|
394
|
-
if (Math.abs(
|
|
395
|
-
const distance = key === "ArrowUp" ?
|
|
359
|
+
const cellCenter = getCellCenter(cell);
|
|
360
|
+
if (Math.abs(cellCenter.x - activeCenter.x) < cell.getBoundingClientRect().width / 2) {
|
|
361
|
+
const distance = key === "ArrowUp" ? cellCenter.y - activeCenter.y : activeCenter.y - cellCenter.y;
|
|
396
362
|
if (distance > max) {
|
|
397
363
|
max = distance;
|
|
398
364
|
result = cell;
|
|
@@ -402,7 +368,13 @@ function getNextCell(cells, key, wrap) {
|
|
|
402
368
|
}
|
|
403
369
|
return result;
|
|
404
370
|
}
|
|
405
|
-
|
|
371
|
+
function getSameRowCells(cells, current) {
|
|
372
|
+
const currentRect = current.getBoundingClientRect();
|
|
373
|
+
return cells.filter((cell) => {
|
|
374
|
+
const cellRect = cell.getBoundingClientRect();
|
|
375
|
+
return cellRect.top < currentRect.bottom && cellRect.bottom > currentRect.top;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
406
378
|
function resolveOptions3(options) {
|
|
407
379
|
let {
|
|
408
380
|
direction = "both",
|
|
@@ -414,9 +386,13 @@ function resolveOptions3(options) {
|
|
|
414
386
|
wrap = false
|
|
415
387
|
} = options;
|
|
416
388
|
if (typeof direction === "string") {
|
|
417
|
-
|
|
389
|
+
const lower = direction.toLowerCase();
|
|
390
|
+
const found = DIRECTIONS.find((d) => d === lower);
|
|
391
|
+
if (found) {
|
|
392
|
+
direction = found;
|
|
393
|
+
}
|
|
418
394
|
}
|
|
419
|
-
if (!DIRECTIONS.includes(direction)) {
|
|
395
|
+
if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
|
|
420
396
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
421
397
|
direction = "both";
|
|
422
398
|
}
|
|
@@ -448,15 +424,7 @@ function resolveOptions3(options) {
|
|
|
448
424
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
449
425
|
wrap = false;
|
|
450
426
|
}
|
|
451
|
-
return {
|
|
452
|
-
direction,
|
|
453
|
-
navigationOnly,
|
|
454
|
-
noMemory,
|
|
455
|
-
noStart,
|
|
456
|
-
selector,
|
|
457
|
-
typeahead,
|
|
458
|
-
wrap
|
|
459
|
-
};
|
|
427
|
+
return { direction, navigationOnly, noMemory, noStart, selector, typeahead, wrap };
|
|
460
428
|
}
|
|
461
429
|
function createRovingTabIndex(container, options = {}) {
|
|
462
430
|
if (!(container instanceof Element)) {
|
|
@@ -502,41 +470,48 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
502
470
|
this.#controller = new AbortController();
|
|
503
471
|
const { signal } = this.#controller;
|
|
504
472
|
container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
505
|
-
this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, {
|
|
506
|
-
signal
|
|
507
|
-
});
|
|
473
|
+
this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, { signal });
|
|
508
474
|
container.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
509
475
|
}
|
|
510
476
|
#onFocusIn = (event) => {
|
|
477
|
+
if (!(event instanceof FocusEvent)) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
511
480
|
const { target } = event;
|
|
512
481
|
target instanceof Element && this.#update(target);
|
|
513
482
|
};
|
|
514
483
|
#onFocusOut = (event) => {
|
|
484
|
+
if (!(event instanceof FocusEvent)) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
515
487
|
const target = event.relatedTarget;
|
|
516
488
|
(!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
|
|
517
489
|
};
|
|
518
490
|
#onKeyDown = (event) => {
|
|
519
|
-
|
|
491
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const direction = this.#getDirection();
|
|
520
495
|
const isGrid = direction === "grid";
|
|
521
496
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
522
497
|
if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
|
|
523
498
|
return;
|
|
524
499
|
}
|
|
525
500
|
const isBoth = direction === "both";
|
|
501
|
+
const is2D = isGrid || isBoth;
|
|
526
502
|
const isHorizontal = direction === "horizontal";
|
|
503
|
+
const { typeahead, wrap } = this.#settings;
|
|
527
504
|
if (![
|
|
528
505
|
"End",
|
|
529
506
|
"Home",
|
|
530
|
-
...
|
|
531
|
-
...
|
|
507
|
+
...is2D ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
508
|
+
...is2D ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
532
509
|
].includes(key)) {
|
|
533
510
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
534
511
|
return;
|
|
535
512
|
}
|
|
536
513
|
}
|
|
537
|
-
const candidates = this.#getFocusables().filter(
|
|
538
|
-
(f) => this.#focusables.has(f)
|
|
539
|
-
);
|
|
514
|
+
const candidates = this.#getFocusables().filter((f) => this.#focusables.has(f));
|
|
540
515
|
const active = getActiveElement();
|
|
541
516
|
if (!(active instanceof Element)) {
|
|
542
517
|
return;
|
|
@@ -553,7 +528,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
553
528
|
case "Home": {
|
|
554
529
|
const rawIndex = key === "End" ? -1 : 0;
|
|
555
530
|
if (isGrid && !ctrlKey) {
|
|
556
|
-
const cell = this.#
|
|
531
|
+
const cell = this.#getSameRowCells().at(rawIndex);
|
|
557
532
|
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
558
533
|
break;
|
|
559
534
|
}
|
|
@@ -570,11 +545,12 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
570
545
|
break;
|
|
571
546
|
}
|
|
572
547
|
if (isGrid) {
|
|
573
|
-
target = this.#
|
|
548
|
+
target = this.#getSameRowCells();
|
|
574
549
|
}
|
|
575
550
|
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
576
551
|
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
577
|
-
|
|
552
|
+
const { length } = target;
|
|
553
|
+
newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, length - 1) : rawIndex % length;
|
|
578
554
|
break;
|
|
579
555
|
}
|
|
580
556
|
default: {
|
|
@@ -582,9 +558,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
582
558
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
583
559
|
);
|
|
584
560
|
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
585
|
-
const afterIndex = target.findIndex(
|
|
586
|
-
(f) => candidates.indexOf(f) > activeIndex
|
|
587
|
-
);
|
|
561
|
+
const afterIndex = target.findIndex((f) => candidates.indexOf(f) > activeIndex);
|
|
588
562
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
589
563
|
}
|
|
590
564
|
}
|
|
@@ -633,9 +607,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
633
607
|
if (char) {
|
|
634
608
|
keys.add(char);
|
|
635
609
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
636
|
-
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
637
|
-
caseInsensitive: true
|
|
638
|
-
});
|
|
610
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, { caseInsensitive: true });
|
|
639
611
|
}
|
|
640
612
|
for (const key of keys) {
|
|
641
613
|
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
@@ -659,8 +631,13 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
659
631
|
const { selector } = this.#settings;
|
|
660
632
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
661
633
|
}
|
|
662
|
-
#
|
|
663
|
-
|
|
634
|
+
#getDirection() {
|
|
635
|
+
const { direction } = this.#settings;
|
|
636
|
+
if (typeof direction === "string") {
|
|
637
|
+
return direction;
|
|
638
|
+
}
|
|
639
|
+
const d = direction();
|
|
640
|
+
return DIRECTIONS.includes(d) ? d : "both";
|
|
664
641
|
}
|
|
665
642
|
#getFocusables() {
|
|
666
643
|
return getFocusables(this.#container, {
|
|
@@ -673,6 +650,10 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
673
650
|
#getNextCell(key, wrap) {
|
|
674
651
|
return getNextCell(this.#getFocusables(), key, wrap);
|
|
675
652
|
}
|
|
653
|
+
#getSameRowCells() {
|
|
654
|
+
const active = getActiveElement();
|
|
655
|
+
return active instanceof Element ? getSameRowCells(this.#getFocusables(), active) : [];
|
|
656
|
+
}
|
|
676
657
|
};
|
|
677
658
|
|
|
678
659
|
// src/defaults.ts
|
|
@@ -739,36 +720,27 @@ var Disclosure = class _Disclosure {
|
|
|
739
720
|
return;
|
|
740
721
|
}
|
|
741
722
|
this.#rootElement = root;
|
|
742
|
-
this.#settings = resolveOptions4(
|
|
743
|
-
resolveOptions4(defaults, _Disclosure.defaults),
|
|
744
|
-
options
|
|
745
|
-
);
|
|
723
|
+
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
746
724
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
747
725
|
this.#settings.animation.duration = 0;
|
|
748
726
|
}
|
|
749
727
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
750
728
|
this.#detailsElements = [
|
|
751
|
-
...this.#rootElement.querySelectorAll(
|
|
752
|
-
`details${NOT_NESTED}`
|
|
753
|
-
)
|
|
729
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
754
730
|
];
|
|
755
731
|
if (!this.#detailsElements.length) {
|
|
756
732
|
console.warn("Missing <details> elements");
|
|
757
733
|
return;
|
|
758
734
|
}
|
|
759
735
|
this.#summaryElements = [
|
|
760
|
-
...this.#rootElement.querySelectorAll(
|
|
761
|
-
`summary${NOT_NESTED}`
|
|
762
|
-
)
|
|
736
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
763
737
|
];
|
|
764
738
|
if (!this.#summaryElements.length) {
|
|
765
739
|
console.warn("Missing <summary> elements");
|
|
766
740
|
return;
|
|
767
741
|
}
|
|
768
742
|
this.#contentElements = [
|
|
769
|
-
...this.#rootElement.querySelectorAll(
|
|
770
|
-
`summary${NOT_NESTED} + *`
|
|
771
|
-
)
|
|
743
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
772
744
|
];
|
|
773
745
|
if (!this.#contentElements.length) {
|
|
774
746
|
console.warn("Missing content elements");
|
|
@@ -791,7 +763,7 @@ var Disclosure = class _Disclosure {
|
|
|
791
763
|
if (this.#isDestroyed) {
|
|
792
764
|
return;
|
|
793
765
|
}
|
|
794
|
-
if (!
|
|
766
|
+
if (!this.#isValidDetails(details)) {
|
|
795
767
|
console.warn("Invalid <details> element");
|
|
796
768
|
return;
|
|
797
769
|
}
|
|
@@ -832,18 +804,14 @@ var Disclosure = class _Disclosure {
|
|
|
832
804
|
if (this.#isDestroyed) {
|
|
833
805
|
return;
|
|
834
806
|
}
|
|
835
|
-
if (!
|
|
807
|
+
if (!this.#isValidDetails(details)) {
|
|
836
808
|
console.warn("Invalid <details> element");
|
|
837
809
|
return;
|
|
838
810
|
}
|
|
839
811
|
this.#toggle(details, true);
|
|
840
812
|
}
|
|
841
813
|
#initialize() {
|
|
842
|
-
saveAttributes(this.#summaryElements, [
|
|
843
|
-
"aria-disabled",
|
|
844
|
-
"style",
|
|
845
|
-
"tabindex"
|
|
846
|
-
]);
|
|
814
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
847
815
|
this.#eventController = new AbortController();
|
|
848
816
|
const { signal } = this.#eventController;
|
|
849
817
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -880,19 +848,11 @@ var Disclosure = class _Disclosure {
|
|
|
880
848
|
if (!(summary instanceof HTMLElement)) {
|
|
881
849
|
return;
|
|
882
850
|
}
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
return;
|
|
886
|
-
}
|
|
887
|
-
const { details } = binding;
|
|
888
|
-
this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
851
|
+
const details = this.#bindings.get(summary)?.details;
|
|
852
|
+
details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
889
853
|
};
|
|
890
854
|
#onContentAnimationFinish(content) {
|
|
891
|
-
const
|
|
892
|
-
if (!binding) {
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
const details = binding.details;
|
|
855
|
+
const details = this.#bindings.get(content)?.details;
|
|
896
856
|
if (!details) {
|
|
897
857
|
return;
|
|
898
858
|
}
|
|
@@ -909,9 +869,7 @@ var Disclosure = class _Disclosure {
|
|
|
909
869
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
910
870
|
return;
|
|
911
871
|
}
|
|
912
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
913
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
914
|
-
).length <= 1) {
|
|
872
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
915
873
|
return;
|
|
916
874
|
}
|
|
917
875
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -967,6 +925,9 @@ var Disclosure = class _Disclosure {
|
|
|
967
925
|
#isFocusable(element) {
|
|
968
926
|
return element.tabIndex >= 0;
|
|
969
927
|
}
|
|
928
|
+
#isValidDetails(details) {
|
|
929
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
930
|
+
}
|
|
970
931
|
async #waitAnimationsFinish() {
|
|
971
932
|
const promises = [];
|
|
972
933
|
for (const content of this.#contentElements) {
|
package/dist/index.bundle.js
CHANGED
|
@@ -89,26 +89,29 @@ function resolveOptions(options) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// node_modules/power-focusable/dist/index.js
|
|
92
|
-
function getComposedChildren(
|
|
93
|
-
if (
|
|
94
|
-
return [...
|
|
92
|
+
function getComposedChildren(element) {
|
|
93
|
+
if (element instanceof ShadowRoot) {
|
|
94
|
+
return [...element.children];
|
|
95
95
|
}
|
|
96
|
-
if (!(
|
|
96
|
+
if (!(element instanceof Element)) {
|
|
97
97
|
return [];
|
|
98
98
|
}
|
|
99
|
-
if (
|
|
100
|
-
const assigned =
|
|
99
|
+
if (element instanceof HTMLSlotElement) {
|
|
100
|
+
const assigned = element.assignedElements({ flatten: true });
|
|
101
101
|
if (assigned.length) {
|
|
102
102
|
return assigned;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
106
|
-
return [...
|
|
105
|
+
if (element instanceof HTMLElement && element.shadowRoot?.mode === "open") {
|
|
106
|
+
return [...element.shadowRoot.children];
|
|
107
107
|
}
|
|
108
|
-
return [...
|
|
108
|
+
return [...element.children];
|
|
109
109
|
}
|
|
110
110
|
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"])';
|
|
111
|
-
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
111
|
+
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
112
|
+
/(,\s*)?\[tabindex="-1"\]/g,
|
|
113
|
+
""
|
|
114
|
+
);
|
|
112
115
|
function focusElement(element) {
|
|
113
116
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
114
117
|
}
|
|
@@ -120,7 +123,7 @@ function getActiveElement() {
|
|
|
120
123
|
return current;
|
|
121
124
|
}
|
|
122
125
|
function getTabIndex(element) {
|
|
123
|
-
return "tabIndex" in element ? Number(element.tabIndex) :
|
|
126
|
+
return "tabIndex" in element ? Number(element.tabIndex) : -1;
|
|
124
127
|
}
|
|
125
128
|
function isDisabled(element) {
|
|
126
129
|
return "disabled" in element && !!element.disabled;
|
|
@@ -131,8 +134,8 @@ function isFormControl(element) {
|
|
|
131
134
|
function isInert(element) {
|
|
132
135
|
return "inert" in element && !!element.inert;
|
|
133
136
|
}
|
|
134
|
-
function isUngroupedRadio(
|
|
135
|
-
return
|
|
137
|
+
function isUngroupedRadio(input) {
|
|
138
|
+
return input.type === "radio" && !!input.name;
|
|
136
139
|
}
|
|
137
140
|
function resolveOptions2(options) {
|
|
138
141
|
let {
|
|
@@ -156,15 +159,11 @@ function resolveOptions2(options) {
|
|
|
156
159
|
composed = false;
|
|
157
160
|
}
|
|
158
161
|
if (filter !== void 0 && typeof filter !== "function") {
|
|
159
|
-
console.warn(
|
|
160
|
-
"Invalid filter function. Fallback: no filter function (undefined)."
|
|
161
|
-
);
|
|
162
|
+
console.warn("Invalid filter function. Fallback: no filter function (undefined).");
|
|
162
163
|
filter = void 0;
|
|
163
164
|
}
|
|
164
165
|
if (include !== void 0 && typeof include !== "function") {
|
|
165
|
-
console.warn(
|
|
166
|
-
"Invalid include function. Fallback: no include function (undefined)."
|
|
167
|
-
);
|
|
166
|
+
console.warn("Invalid include function. Fallback: no include function (undefined).");
|
|
168
167
|
include = void 0;
|
|
169
168
|
}
|
|
170
169
|
if (typeof skipNegativeTabIndexCheck !== "boolean") {
|
|
@@ -209,10 +208,8 @@ function isDisabledDeep(element) {
|
|
|
209
208
|
if (isInert(current)) {
|
|
210
209
|
return true;
|
|
211
210
|
}
|
|
212
|
-
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
213
|
-
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
211
|
+
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current) && !current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
|
|
212
|
+
return true;
|
|
216
213
|
}
|
|
217
214
|
current = current.parentNode;
|
|
218
215
|
}
|
|
@@ -221,10 +218,7 @@ function isDisabledDeep(element) {
|
|
|
221
218
|
function normalizeRadioGroup(elements) {
|
|
222
219
|
let map = null;
|
|
223
220
|
for (const element of elements) {
|
|
224
|
-
if (!(element instanceof HTMLInputElement)) {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (!isUngroupedRadio(element)) {
|
|
221
|
+
if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
|
|
228
222
|
continue;
|
|
229
223
|
}
|
|
230
224
|
if (!map) {
|
|
@@ -274,42 +268,24 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
274
268
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
275
269
|
container = document.body;
|
|
276
270
|
}
|
|
277
|
-
const {
|
|
278
|
-
composed,
|
|
279
|
-
filter,
|
|
280
|
-
include,
|
|
281
|
-
skipNegativeTabIndexCheck,
|
|
282
|
-
skipVisibilityCheck
|
|
283
|
-
} = resolveOptions2(options);
|
|
271
|
+
const { composed, filter, include, skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions2(options);
|
|
284
272
|
const candidates = [];
|
|
285
273
|
if (!composed && !include) {
|
|
286
274
|
for (const match of container.querySelectorAll(
|
|
287
275
|
!skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR : FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX
|
|
288
276
|
)) {
|
|
289
|
-
match && isFocusable(match, {
|
|
290
|
-
skipNegativeTabIndexCheck,
|
|
291
|
-
skipVisibilityCheck
|
|
292
|
-
}) && candidates.push(match);
|
|
277
|
+
match && isFocusable(match, { skipNegativeTabIndexCheck, skipVisibilityCheck }) && candidates.push(match);
|
|
293
278
|
}
|
|
294
279
|
} else {
|
|
295
|
-
let traverse2 = function(
|
|
296
|
-
if (isFocusable(
|
|
297
|
-
|
|
298
|
-
skipVisibilityCheck
|
|
299
|
-
}) || include?.(node)) {
|
|
300
|
-
candidates.push(node);
|
|
280
|
+
let traverse2 = function(element) {
|
|
281
|
+
if (isFocusable(element, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(element)) {
|
|
282
|
+
candidates.push(element);
|
|
301
283
|
}
|
|
302
|
-
(!composed ? [...
|
|
303
|
-
traverse2
|
|
304
|
-
);
|
|
284
|
+
(!composed ? [...element.children] : getComposedChildren(element)).map(traverse2);
|
|
305
285
|
};
|
|
306
|
-
(!composed ? [...container.children] : getComposedChildren(container)).map(
|
|
307
|
-
traverse2
|
|
308
|
-
);
|
|
286
|
+
(!composed ? [...container.children] : getComposedChildren(container)).map(traverse2);
|
|
309
287
|
}
|
|
310
|
-
return normalizeRadioGroup(
|
|
311
|
-
sortByTabIndex(!filter ? candidates : candidates.filter(filter))
|
|
312
|
-
);
|
|
288
|
+
return normalizeRadioGroup(sortByTabIndex(!filter ? candidates : candidates.filter(filter)));
|
|
313
289
|
}
|
|
314
290
|
function isFocusable(element, options = {}) {
|
|
315
291
|
if (!(element instanceof Element)) {
|
|
@@ -342,39 +318,29 @@ function isFocusable(element, options = {}) {
|
|
|
342
318
|
}
|
|
343
319
|
|
|
344
320
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
345
|
-
|
|
321
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
322
|
+
function getCellCenter(cell) {
|
|
346
323
|
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
347
324
|
return { x: left + width / 2, y: top + height / 2 };
|
|
348
325
|
}
|
|
349
|
-
function getCellsOfActiveRow(cells) {
|
|
350
|
-
const active = getActiveElement();
|
|
351
|
-
if (!(active instanceof Element)) {
|
|
352
|
-
return [];
|
|
353
|
-
}
|
|
354
|
-
const activeRect = active.getBoundingClientRect();
|
|
355
|
-
return cells.filter((cell) => {
|
|
356
|
-
const cellRect = cell.getBoundingClientRect();
|
|
357
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
326
|
function getNextCell(cells, key, wrap) {
|
|
361
327
|
const active = getActiveElement();
|
|
362
328
|
if (!(active instanceof Element)) {
|
|
363
329
|
return null;
|
|
364
330
|
}
|
|
365
|
-
const
|
|
331
|
+
const activeCenter = getCellCenter(active);
|
|
366
332
|
let min = Infinity;
|
|
367
333
|
let result = null;
|
|
368
334
|
for (const cell of cells) {
|
|
369
335
|
if (cell === active) {
|
|
370
336
|
continue;
|
|
371
337
|
}
|
|
372
|
-
const
|
|
338
|
+
const cellCenter = getCellCenter(cell);
|
|
373
339
|
const distances = {
|
|
374
|
-
x: Math.abs(
|
|
375
|
-
y: Math.abs(
|
|
340
|
+
x: Math.abs(cellCenter.x - activeCenter.x),
|
|
341
|
+
y: Math.abs(cellCenter.y - activeCenter.y)
|
|
376
342
|
};
|
|
377
|
-
if (key === "ArrowUp" &&
|
|
343
|
+
if (key === "ArrowUp" && cellCenter.y < activeCenter.y && distances.x < distances.y || key === "ArrowDown" && cellCenter.y > activeCenter.y && distances.x < distances.y) {
|
|
378
344
|
const distance = distances.x ** 2 + distances.y ** 2;
|
|
379
345
|
if (distance < min) {
|
|
380
346
|
min = distance;
|
|
@@ -388,9 +354,9 @@ function getNextCell(cells, key, wrap) {
|
|
|
388
354
|
if (cell === active) {
|
|
389
355
|
continue;
|
|
390
356
|
}
|
|
391
|
-
const
|
|
392
|
-
if (Math.abs(
|
|
393
|
-
const distance = key === "ArrowUp" ?
|
|
357
|
+
const cellCenter = getCellCenter(cell);
|
|
358
|
+
if (Math.abs(cellCenter.x - activeCenter.x) < cell.getBoundingClientRect().width / 2) {
|
|
359
|
+
const distance = key === "ArrowUp" ? cellCenter.y - activeCenter.y : activeCenter.y - cellCenter.y;
|
|
394
360
|
if (distance > max) {
|
|
395
361
|
max = distance;
|
|
396
362
|
result = cell;
|
|
@@ -400,7 +366,13 @@ function getNextCell(cells, key, wrap) {
|
|
|
400
366
|
}
|
|
401
367
|
return result;
|
|
402
368
|
}
|
|
403
|
-
|
|
369
|
+
function getSameRowCells(cells, current) {
|
|
370
|
+
const currentRect = current.getBoundingClientRect();
|
|
371
|
+
return cells.filter((cell) => {
|
|
372
|
+
const cellRect = cell.getBoundingClientRect();
|
|
373
|
+
return cellRect.top < currentRect.bottom && cellRect.bottom > currentRect.top;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
404
376
|
function resolveOptions3(options) {
|
|
405
377
|
let {
|
|
406
378
|
direction = "both",
|
|
@@ -412,9 +384,13 @@ function resolveOptions3(options) {
|
|
|
412
384
|
wrap = false
|
|
413
385
|
} = options;
|
|
414
386
|
if (typeof direction === "string") {
|
|
415
|
-
|
|
387
|
+
const lower = direction.toLowerCase();
|
|
388
|
+
const found = DIRECTIONS.find((d) => d === lower);
|
|
389
|
+
if (found) {
|
|
390
|
+
direction = found;
|
|
391
|
+
}
|
|
416
392
|
}
|
|
417
|
-
if (!DIRECTIONS.includes(direction)) {
|
|
393
|
+
if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
|
|
418
394
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
419
395
|
direction = "both";
|
|
420
396
|
}
|
|
@@ -446,15 +422,7 @@ function resolveOptions3(options) {
|
|
|
446
422
|
console.warn("Invalid wrap option. Fallback: false.");
|
|
447
423
|
wrap = false;
|
|
448
424
|
}
|
|
449
|
-
return {
|
|
450
|
-
direction,
|
|
451
|
-
navigationOnly,
|
|
452
|
-
noMemory,
|
|
453
|
-
noStart,
|
|
454
|
-
selector,
|
|
455
|
-
typeahead,
|
|
456
|
-
wrap
|
|
457
|
-
};
|
|
425
|
+
return { direction, navigationOnly, noMemory, noStart, selector, typeahead, wrap };
|
|
458
426
|
}
|
|
459
427
|
function createRovingTabIndex(container, options = {}) {
|
|
460
428
|
if (!(container instanceof Element)) {
|
|
@@ -500,41 +468,48 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
500
468
|
this.#controller = new AbortController();
|
|
501
469
|
const { signal } = this.#controller;
|
|
502
470
|
container.addEventListener("focusin", this.#onFocusIn, { signal });
|
|
503
|
-
this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, {
|
|
504
|
-
signal
|
|
505
|
-
});
|
|
471
|
+
this.#settings.noMemory && container.addEventListener("focusout", this.#onFocusOut, { signal });
|
|
506
472
|
container.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
507
473
|
}
|
|
508
474
|
#onFocusIn = (event) => {
|
|
475
|
+
if (!(event instanceof FocusEvent)) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
509
478
|
const { target } = event;
|
|
510
479
|
target instanceof Element && this.#update(target);
|
|
511
480
|
};
|
|
512
481
|
#onFocusOut = (event) => {
|
|
482
|
+
if (!(event instanceof FocusEvent)) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
513
485
|
const target = event.relatedTarget;
|
|
514
486
|
(!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
|
|
515
487
|
};
|
|
516
488
|
#onKeyDown = (event) => {
|
|
517
|
-
|
|
489
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const direction = this.#getDirection();
|
|
518
493
|
const isGrid = direction === "grid";
|
|
519
494
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
520
495
|
if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
|
|
521
496
|
return;
|
|
522
497
|
}
|
|
523
498
|
const isBoth = direction === "both";
|
|
499
|
+
const is2D = isGrid || isBoth;
|
|
524
500
|
const isHorizontal = direction === "horizontal";
|
|
501
|
+
const { typeahead, wrap } = this.#settings;
|
|
525
502
|
if (![
|
|
526
503
|
"End",
|
|
527
504
|
"Home",
|
|
528
|
-
...
|
|
529
|
-
...
|
|
505
|
+
...is2D ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
506
|
+
...is2D ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
530
507
|
].includes(key)) {
|
|
531
508
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
532
509
|
return;
|
|
533
510
|
}
|
|
534
511
|
}
|
|
535
|
-
const candidates = this.#getFocusables().filter(
|
|
536
|
-
(f) => this.#focusables.has(f)
|
|
537
|
-
);
|
|
512
|
+
const candidates = this.#getFocusables().filter((f) => this.#focusables.has(f));
|
|
538
513
|
const active = getActiveElement();
|
|
539
514
|
if (!(active instanceof Element)) {
|
|
540
515
|
return;
|
|
@@ -551,7 +526,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
551
526
|
case "Home": {
|
|
552
527
|
const rawIndex = key === "End" ? -1 : 0;
|
|
553
528
|
if (isGrid && !ctrlKey) {
|
|
554
|
-
const cell = this.#
|
|
529
|
+
const cell = this.#getSameRowCells().at(rawIndex);
|
|
555
530
|
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
556
531
|
break;
|
|
557
532
|
}
|
|
@@ -568,11 +543,12 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
568
543
|
break;
|
|
569
544
|
}
|
|
570
545
|
if (isGrid) {
|
|
571
|
-
target = this.#
|
|
546
|
+
target = this.#getSameRowCells();
|
|
572
547
|
}
|
|
573
548
|
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
574
549
|
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
575
|
-
|
|
550
|
+
const { length } = target;
|
|
551
|
+
newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, length - 1) : rawIndex % length;
|
|
576
552
|
break;
|
|
577
553
|
}
|
|
578
554
|
default: {
|
|
@@ -580,9 +556,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
580
556
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
581
557
|
);
|
|
582
558
|
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
583
|
-
const afterIndex = target.findIndex(
|
|
584
|
-
(f) => candidates.indexOf(f) > activeIndex
|
|
585
|
-
);
|
|
559
|
+
const afterIndex = target.findIndex((f) => candidates.indexOf(f) > activeIndex);
|
|
586
560
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
587
561
|
}
|
|
588
562
|
}
|
|
@@ -631,9 +605,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
631
605
|
if (char) {
|
|
632
606
|
keys.add(char);
|
|
633
607
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
634
|
-
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
635
|
-
caseInsensitive: true
|
|
636
|
-
});
|
|
608
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, { caseInsensitive: true });
|
|
637
609
|
}
|
|
638
610
|
for (const key of keys) {
|
|
639
611
|
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
@@ -657,8 +629,13 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
657
629
|
const { selector } = this.#settings;
|
|
658
630
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
659
631
|
}
|
|
660
|
-
#
|
|
661
|
-
|
|
632
|
+
#getDirection() {
|
|
633
|
+
const { direction } = this.#settings;
|
|
634
|
+
if (typeof direction === "string") {
|
|
635
|
+
return direction;
|
|
636
|
+
}
|
|
637
|
+
const d = direction();
|
|
638
|
+
return DIRECTIONS.includes(d) ? d : "both";
|
|
662
639
|
}
|
|
663
640
|
#getFocusables() {
|
|
664
641
|
return getFocusables(this.#container, {
|
|
@@ -671,6 +648,10 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
671
648
|
#getNextCell(key, wrap) {
|
|
672
649
|
return getNextCell(this.#getFocusables(), key, wrap);
|
|
673
650
|
}
|
|
651
|
+
#getSameRowCells() {
|
|
652
|
+
const active = getActiveElement();
|
|
653
|
+
return active instanceof Element ? getSameRowCells(this.#getFocusables(), active) : [];
|
|
654
|
+
}
|
|
674
655
|
};
|
|
675
656
|
|
|
676
657
|
// src/defaults.ts
|
|
@@ -737,36 +718,27 @@ var Disclosure = class _Disclosure {
|
|
|
737
718
|
return;
|
|
738
719
|
}
|
|
739
720
|
this.#rootElement = root;
|
|
740
|
-
this.#settings = resolveOptions4(
|
|
741
|
-
resolveOptions4(defaults, _Disclosure.defaults),
|
|
742
|
-
options
|
|
743
|
-
);
|
|
721
|
+
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
744
722
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
745
723
|
this.#settings.animation.duration = 0;
|
|
746
724
|
}
|
|
747
725
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
748
726
|
this.#detailsElements = [
|
|
749
|
-
...this.#rootElement.querySelectorAll(
|
|
750
|
-
`details${NOT_NESTED}`
|
|
751
|
-
)
|
|
727
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
752
728
|
];
|
|
753
729
|
if (!this.#detailsElements.length) {
|
|
754
730
|
console.warn("Missing <details> elements");
|
|
755
731
|
return;
|
|
756
732
|
}
|
|
757
733
|
this.#summaryElements = [
|
|
758
|
-
...this.#rootElement.querySelectorAll(
|
|
759
|
-
`summary${NOT_NESTED}`
|
|
760
|
-
)
|
|
734
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
761
735
|
];
|
|
762
736
|
if (!this.#summaryElements.length) {
|
|
763
737
|
console.warn("Missing <summary> elements");
|
|
764
738
|
return;
|
|
765
739
|
}
|
|
766
740
|
this.#contentElements = [
|
|
767
|
-
...this.#rootElement.querySelectorAll(
|
|
768
|
-
`summary${NOT_NESTED} + *`
|
|
769
|
-
)
|
|
741
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
770
742
|
];
|
|
771
743
|
if (!this.#contentElements.length) {
|
|
772
744
|
console.warn("Missing content elements");
|
|
@@ -789,7 +761,7 @@ var Disclosure = class _Disclosure {
|
|
|
789
761
|
if (this.#isDestroyed) {
|
|
790
762
|
return;
|
|
791
763
|
}
|
|
792
|
-
if (!
|
|
764
|
+
if (!this.#isValidDetails(details)) {
|
|
793
765
|
console.warn("Invalid <details> element");
|
|
794
766
|
return;
|
|
795
767
|
}
|
|
@@ -830,18 +802,14 @@ var Disclosure = class _Disclosure {
|
|
|
830
802
|
if (this.#isDestroyed) {
|
|
831
803
|
return;
|
|
832
804
|
}
|
|
833
|
-
if (!
|
|
805
|
+
if (!this.#isValidDetails(details)) {
|
|
834
806
|
console.warn("Invalid <details> element");
|
|
835
807
|
return;
|
|
836
808
|
}
|
|
837
809
|
this.#toggle(details, true);
|
|
838
810
|
}
|
|
839
811
|
#initialize() {
|
|
840
|
-
saveAttributes(this.#summaryElements, [
|
|
841
|
-
"aria-disabled",
|
|
842
|
-
"style",
|
|
843
|
-
"tabindex"
|
|
844
|
-
]);
|
|
812
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
845
813
|
this.#eventController = new AbortController();
|
|
846
814
|
const { signal } = this.#eventController;
|
|
847
815
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -878,19 +846,11 @@ var Disclosure = class _Disclosure {
|
|
|
878
846
|
if (!(summary instanceof HTMLElement)) {
|
|
879
847
|
return;
|
|
880
848
|
}
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
const { details } = binding;
|
|
886
|
-
this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
849
|
+
const details = this.#bindings.get(summary)?.details;
|
|
850
|
+
details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
887
851
|
};
|
|
888
852
|
#onContentAnimationFinish(content) {
|
|
889
|
-
const
|
|
890
|
-
if (!binding) {
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
const details = binding.details;
|
|
853
|
+
const details = this.#bindings.get(content)?.details;
|
|
894
854
|
if (!details) {
|
|
895
855
|
return;
|
|
896
856
|
}
|
|
@@ -907,9 +867,7 @@ var Disclosure = class _Disclosure {
|
|
|
907
867
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
908
868
|
return;
|
|
909
869
|
}
|
|
910
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
911
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
912
|
-
).length <= 1) {
|
|
870
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
913
871
|
return;
|
|
914
872
|
}
|
|
915
873
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -965,6 +923,9 @@ var Disclosure = class _Disclosure {
|
|
|
965
923
|
#isFocusable(element) {
|
|
966
924
|
return element.tabIndex >= 0;
|
|
967
925
|
}
|
|
926
|
+
#isValidDetails(details) {
|
|
927
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
928
|
+
}
|
|
968
929
|
async #waitAnimationsFinish() {
|
|
969
930
|
const promises = [];
|
|
970
931
|
for (const content of this.#contentElements) {
|
package/dist/index.cjs
CHANGED
|
@@ -69,36 +69,27 @@ var Disclosure = class _Disclosure {
|
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
this.#rootElement = root;
|
|
72
|
-
this.#settings = resolveOptions(
|
|
73
|
-
resolveOptions(defaults, _Disclosure.defaults),
|
|
74
|
-
options
|
|
75
|
-
);
|
|
72
|
+
this.#settings = resolveOptions(resolveOptions(defaults, _Disclosure.defaults), options);
|
|
76
73
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
77
74
|
this.#settings.animation.duration = 0;
|
|
78
75
|
}
|
|
79
76
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
80
77
|
this.#detailsElements = [
|
|
81
|
-
...this.#rootElement.querySelectorAll(
|
|
82
|
-
`details${NOT_NESTED}`
|
|
83
|
-
)
|
|
78
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
84
79
|
];
|
|
85
80
|
if (!this.#detailsElements.length) {
|
|
86
81
|
console.warn("Missing <details> elements");
|
|
87
82
|
return;
|
|
88
83
|
}
|
|
89
84
|
this.#summaryElements = [
|
|
90
|
-
...this.#rootElement.querySelectorAll(
|
|
91
|
-
`summary${NOT_NESTED}`
|
|
92
|
-
)
|
|
85
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
93
86
|
];
|
|
94
87
|
if (!this.#summaryElements.length) {
|
|
95
88
|
console.warn("Missing <summary> elements");
|
|
96
89
|
return;
|
|
97
90
|
}
|
|
98
91
|
this.#contentElements = [
|
|
99
|
-
...this.#rootElement.querySelectorAll(
|
|
100
|
-
`summary${NOT_NESTED} + *`
|
|
101
|
-
)
|
|
92
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
102
93
|
];
|
|
103
94
|
if (!this.#contentElements.length) {
|
|
104
95
|
console.warn("Missing content elements");
|
|
@@ -121,7 +112,7 @@ var Disclosure = class _Disclosure {
|
|
|
121
112
|
if (this.#isDestroyed) {
|
|
122
113
|
return;
|
|
123
114
|
}
|
|
124
|
-
if (!
|
|
115
|
+
if (!this.#isValidDetails(details)) {
|
|
125
116
|
console.warn("Invalid <details> element");
|
|
126
117
|
return;
|
|
127
118
|
}
|
|
@@ -162,18 +153,14 @@ var Disclosure = class _Disclosure {
|
|
|
162
153
|
if (this.#isDestroyed) {
|
|
163
154
|
return;
|
|
164
155
|
}
|
|
165
|
-
if (!
|
|
156
|
+
if (!this.#isValidDetails(details)) {
|
|
166
157
|
console.warn("Invalid <details> element");
|
|
167
158
|
return;
|
|
168
159
|
}
|
|
169
160
|
this.#toggle(details, true);
|
|
170
161
|
}
|
|
171
162
|
#initialize() {
|
|
172
|
-
attributeUtils.saveAttributes(this.#summaryElements, [
|
|
173
|
-
"aria-disabled",
|
|
174
|
-
"style",
|
|
175
|
-
"tabindex"
|
|
176
|
-
]);
|
|
163
|
+
attributeUtils.saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
177
164
|
this.#eventController = new AbortController();
|
|
178
165
|
const { signal } = this.#eventController;
|
|
179
166
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -210,19 +197,11 @@ var Disclosure = class _Disclosure {
|
|
|
210
197
|
if (!(summary instanceof HTMLElement)) {
|
|
211
198
|
return;
|
|
212
199
|
}
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
const { details } = binding;
|
|
218
|
-
this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
200
|
+
const details = this.#bindings.get(summary)?.details;
|
|
201
|
+
details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
219
202
|
};
|
|
220
203
|
#onContentAnimationFinish(content) {
|
|
221
|
-
const
|
|
222
|
-
if (!binding) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const details = binding.details;
|
|
204
|
+
const details = this.#bindings.get(content)?.details;
|
|
226
205
|
if (!details) {
|
|
227
206
|
return;
|
|
228
207
|
}
|
|
@@ -239,9 +218,7 @@ var Disclosure = class _Disclosure {
|
|
|
239
218
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
240
219
|
return;
|
|
241
220
|
}
|
|
242
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
243
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
244
|
-
).length <= 1) {
|
|
221
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
245
222
|
return;
|
|
246
223
|
}
|
|
247
224
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -297,6 +274,9 @@ var Disclosure = class _Disclosure {
|
|
|
297
274
|
#isFocusable(element) {
|
|
298
275
|
return element.tabIndex >= 0;
|
|
299
276
|
}
|
|
277
|
+
#isValidDetails(details) {
|
|
278
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
279
|
+
}
|
|
300
280
|
async #waitAnimationsFinish() {
|
|
301
281
|
const promises = [];
|
|
302
282
|
for (const content of this.#contentElements) {
|
package/dist/index.js
CHANGED
|
@@ -67,36 +67,27 @@ var Disclosure = class _Disclosure {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
this.#rootElement = root;
|
|
70
|
-
this.#settings = resolveOptions(
|
|
71
|
-
resolveOptions(defaults, _Disclosure.defaults),
|
|
72
|
-
options
|
|
73
|
-
);
|
|
70
|
+
this.#settings = resolveOptions(resolveOptions(defaults, _Disclosure.defaults), options);
|
|
74
71
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
75
72
|
this.#settings.animation.duration = 0;
|
|
76
73
|
}
|
|
77
74
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
78
75
|
this.#detailsElements = [
|
|
79
|
-
...this.#rootElement.querySelectorAll(
|
|
80
|
-
`details${NOT_NESTED}`
|
|
81
|
-
)
|
|
76
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
82
77
|
];
|
|
83
78
|
if (!this.#detailsElements.length) {
|
|
84
79
|
console.warn("Missing <details> elements");
|
|
85
80
|
return;
|
|
86
81
|
}
|
|
87
82
|
this.#summaryElements = [
|
|
88
|
-
...this.#rootElement.querySelectorAll(
|
|
89
|
-
`summary${NOT_NESTED}`
|
|
90
|
-
)
|
|
83
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
91
84
|
];
|
|
92
85
|
if (!this.#summaryElements.length) {
|
|
93
86
|
console.warn("Missing <summary> elements");
|
|
94
87
|
return;
|
|
95
88
|
}
|
|
96
89
|
this.#contentElements = [
|
|
97
|
-
...this.#rootElement.querySelectorAll(
|
|
98
|
-
`summary${NOT_NESTED} + *`
|
|
99
|
-
)
|
|
90
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
100
91
|
];
|
|
101
92
|
if (!this.#contentElements.length) {
|
|
102
93
|
console.warn("Missing content elements");
|
|
@@ -119,7 +110,7 @@ var Disclosure = class _Disclosure {
|
|
|
119
110
|
if (this.#isDestroyed) {
|
|
120
111
|
return;
|
|
121
112
|
}
|
|
122
|
-
if (!
|
|
113
|
+
if (!this.#isValidDetails(details)) {
|
|
123
114
|
console.warn("Invalid <details> element");
|
|
124
115
|
return;
|
|
125
116
|
}
|
|
@@ -160,18 +151,14 @@ var Disclosure = class _Disclosure {
|
|
|
160
151
|
if (this.#isDestroyed) {
|
|
161
152
|
return;
|
|
162
153
|
}
|
|
163
|
-
if (!
|
|
154
|
+
if (!this.#isValidDetails(details)) {
|
|
164
155
|
console.warn("Invalid <details> element");
|
|
165
156
|
return;
|
|
166
157
|
}
|
|
167
158
|
this.#toggle(details, true);
|
|
168
159
|
}
|
|
169
160
|
#initialize() {
|
|
170
|
-
saveAttributes(this.#summaryElements, [
|
|
171
|
-
"aria-disabled",
|
|
172
|
-
"style",
|
|
173
|
-
"tabindex"
|
|
174
|
-
]);
|
|
161
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
175
162
|
this.#eventController = new AbortController();
|
|
176
163
|
const { signal } = this.#eventController;
|
|
177
164
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -208,19 +195,11 @@ var Disclosure = class _Disclosure {
|
|
|
208
195
|
if (!(summary instanceof HTMLElement)) {
|
|
209
196
|
return;
|
|
210
197
|
}
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const { details } = binding;
|
|
216
|
-
this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
198
|
+
const details = this.#bindings.get(summary)?.details;
|
|
199
|
+
details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
|
|
217
200
|
};
|
|
218
201
|
#onContentAnimationFinish(content) {
|
|
219
|
-
const
|
|
220
|
-
if (!binding) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const details = binding.details;
|
|
202
|
+
const details = this.#bindings.get(content)?.details;
|
|
224
203
|
if (!details) {
|
|
225
204
|
return;
|
|
226
205
|
}
|
|
@@ -237,9 +216,7 @@ var Disclosure = class _Disclosure {
|
|
|
237
216
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
238
217
|
return;
|
|
239
218
|
}
|
|
240
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
241
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
242
|
-
).length <= 1) {
|
|
219
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
243
220
|
return;
|
|
244
221
|
}
|
|
245
222
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -295,6 +272,9 @@ var Disclosure = class _Disclosure {
|
|
|
295
272
|
#isFocusable(element) {
|
|
296
273
|
return element.tabIndex >= 0;
|
|
297
274
|
}
|
|
275
|
+
#isValidDetails(details) {
|
|
276
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
277
|
+
}
|
|
298
278
|
async #waitAnimationsFinish() {
|
|
299
279
|
const promises = [];
|
|
300
280
|
for (const content of this.#contentElements) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"esbuild": true
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@y14e/attribute-utils": "^2.0.
|
|
58
|
-
"@y14e/roving-tabindex": "^3.
|
|
57
|
+
"@y14e/attribute-utils": "^2.0.18",
|
|
58
|
+
"@y14e/roving-tabindex": "^3.5.5"
|
|
59
59
|
}
|
|
60
60
|
}
|