@y14e/disclosure 2.2.4 → 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 +87 -127
- package/dist/index.bundle.js +87 -127
- package/dist/index.cjs +11 -23
- package/dist/index.js +11 -23
- package/package.json +2 -2
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)) {
|
|
@@ -345,39 +321,28 @@ function isFocusable(element, options = {}) {
|
|
|
345
321
|
|
|
346
322
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
347
323
|
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
348
|
-
function
|
|
324
|
+
function getCellCenter(cell) {
|
|
349
325
|
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
350
326
|
return { x: left + width / 2, y: top + height / 2 };
|
|
351
327
|
}
|
|
352
|
-
function getCellsOfActiveRow(cells) {
|
|
353
|
-
const active = getActiveElement();
|
|
354
|
-
if (!(active instanceof Element)) {
|
|
355
|
-
return [];
|
|
356
|
-
}
|
|
357
|
-
const activeRect = active.getBoundingClientRect();
|
|
358
|
-
return cells.filter((cell) => {
|
|
359
|
-
const cellRect = cell.getBoundingClientRect();
|
|
360
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
328
|
function getNextCell(cells, key, wrap) {
|
|
364
329
|
const active = getActiveElement();
|
|
365
330
|
if (!(active instanceof Element)) {
|
|
366
331
|
return null;
|
|
367
332
|
}
|
|
368
|
-
const
|
|
333
|
+
const activeCenter = getCellCenter(active);
|
|
369
334
|
let min = Infinity;
|
|
370
335
|
let result = null;
|
|
371
336
|
for (const cell of cells) {
|
|
372
337
|
if (cell === active) {
|
|
373
338
|
continue;
|
|
374
339
|
}
|
|
375
|
-
const
|
|
340
|
+
const cellCenter = getCellCenter(cell);
|
|
376
341
|
const distances = {
|
|
377
|
-
x: Math.abs(
|
|
378
|
-
y: Math.abs(
|
|
342
|
+
x: Math.abs(cellCenter.x - activeCenter.x),
|
|
343
|
+
y: Math.abs(cellCenter.y - activeCenter.y)
|
|
379
344
|
};
|
|
380
|
-
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) {
|
|
381
346
|
const distance = distances.x ** 2 + distances.y ** 2;
|
|
382
347
|
if (distance < min) {
|
|
383
348
|
min = distance;
|
|
@@ -391,9 +356,9 @@ function getNextCell(cells, key, wrap) {
|
|
|
391
356
|
if (cell === active) {
|
|
392
357
|
continue;
|
|
393
358
|
}
|
|
394
|
-
const
|
|
395
|
-
if (Math.abs(
|
|
396
|
-
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;
|
|
397
362
|
if (distance > max) {
|
|
398
363
|
max = distance;
|
|
399
364
|
result = cell;
|
|
@@ -403,6 +368,13 @@ function getNextCell(cells, key, wrap) {
|
|
|
403
368
|
}
|
|
404
369
|
return result;
|
|
405
370
|
}
|
|
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,7 +386,11 @@ 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
395
|
if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
|
|
420
396
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
@@ -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,20 +470,27 @@ 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) => {
|
|
491
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
519
494
|
const direction = this.#getDirection();
|
|
520
495
|
const isGrid = direction === "grid";
|
|
521
496
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
@@ -523,21 +498,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
523
498
|
return;
|
|
524
499
|
}
|
|
525
500
|
const isBoth = direction === "both";
|
|
501
|
+
const is2D = isGrid || isBoth;
|
|
526
502
|
const isHorizontal = direction === "horizontal";
|
|
527
|
-
const { typeahead, wrap
|
|
503
|
+
const { typeahead, wrap } = this.#settings;
|
|
528
504
|
if (![
|
|
529
505
|
"End",
|
|
530
506
|
"Home",
|
|
531
|
-
...
|
|
532
|
-
...
|
|
507
|
+
...is2D ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
508
|
+
...is2D ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
533
509
|
].includes(key)) {
|
|
534
510
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
535
511
|
return;
|
|
536
512
|
}
|
|
537
513
|
}
|
|
538
|
-
const candidates = this.#getFocusables().filter(
|
|
539
|
-
(f) => this.#focusables.has(f)
|
|
540
|
-
);
|
|
514
|
+
const candidates = this.#getFocusables().filter((f) => this.#focusables.has(f));
|
|
541
515
|
const active = getActiveElement();
|
|
542
516
|
if (!(active instanceof Element)) {
|
|
543
517
|
return;
|
|
@@ -554,7 +528,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
554
528
|
case "Home": {
|
|
555
529
|
const rawIndex = key === "End" ? -1 : 0;
|
|
556
530
|
if (isGrid && !ctrlKey) {
|
|
557
|
-
const cell = this.#
|
|
531
|
+
const cell = this.#getSameRowCells().at(rawIndex);
|
|
558
532
|
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
559
533
|
break;
|
|
560
534
|
}
|
|
@@ -571,11 +545,12 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
571
545
|
break;
|
|
572
546
|
}
|
|
573
547
|
if (isGrid) {
|
|
574
|
-
target = this.#
|
|
548
|
+
target = this.#getSameRowCells();
|
|
575
549
|
}
|
|
576
550
|
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
577
551
|
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
578
|
-
|
|
552
|
+
const { length } = target;
|
|
553
|
+
newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, length - 1) : rawIndex % length;
|
|
579
554
|
break;
|
|
580
555
|
}
|
|
581
556
|
default: {
|
|
@@ -583,9 +558,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
583
558
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
584
559
|
);
|
|
585
560
|
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
586
|
-
const afterIndex = target.findIndex(
|
|
587
|
-
(f) => candidates.indexOf(f) > activeIndex
|
|
588
|
-
);
|
|
561
|
+
const afterIndex = target.findIndex((f) => candidates.indexOf(f) > activeIndex);
|
|
589
562
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
590
563
|
}
|
|
591
564
|
}
|
|
@@ -634,9 +607,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
634
607
|
if (char) {
|
|
635
608
|
keys.add(char);
|
|
636
609
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
637
|
-
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
638
|
-
caseInsensitive: true
|
|
639
|
-
});
|
|
610
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, { caseInsensitive: true });
|
|
640
611
|
}
|
|
641
612
|
for (const key of keys) {
|
|
642
613
|
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
@@ -660,9 +631,6 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
660
631
|
const { selector } = this.#settings;
|
|
661
632
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
662
633
|
}
|
|
663
|
-
#getCellsOfActiveRow() {
|
|
664
|
-
return getCellsOfActiveRow(this.#getFocusables());
|
|
665
|
-
}
|
|
666
634
|
#getDirection() {
|
|
667
635
|
const { direction } = this.#settings;
|
|
668
636
|
if (typeof direction === "string") {
|
|
@@ -682,6 +650,10 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
682
650
|
#getNextCell(key, wrap) {
|
|
683
651
|
return getNextCell(this.#getFocusables(), key, wrap);
|
|
684
652
|
}
|
|
653
|
+
#getSameRowCells() {
|
|
654
|
+
const active = getActiveElement();
|
|
655
|
+
return active instanceof Element ? getSameRowCells(this.#getFocusables(), active) : [];
|
|
656
|
+
}
|
|
685
657
|
};
|
|
686
658
|
|
|
687
659
|
// src/defaults.ts
|
|
@@ -748,36 +720,27 @@ var Disclosure = class _Disclosure {
|
|
|
748
720
|
return;
|
|
749
721
|
}
|
|
750
722
|
this.#rootElement = root;
|
|
751
|
-
this.#settings = resolveOptions4(
|
|
752
|
-
resolveOptions4(defaults, _Disclosure.defaults),
|
|
753
|
-
options
|
|
754
|
-
);
|
|
723
|
+
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
755
724
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
756
725
|
this.#settings.animation.duration = 0;
|
|
757
726
|
}
|
|
758
727
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
759
728
|
this.#detailsElements = [
|
|
760
|
-
...this.#rootElement.querySelectorAll(
|
|
761
|
-
`details${NOT_NESTED}`
|
|
762
|
-
)
|
|
729
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
763
730
|
];
|
|
764
731
|
if (!this.#detailsElements.length) {
|
|
765
732
|
console.warn("Missing <details> elements");
|
|
766
733
|
return;
|
|
767
734
|
}
|
|
768
735
|
this.#summaryElements = [
|
|
769
|
-
...this.#rootElement.querySelectorAll(
|
|
770
|
-
`summary${NOT_NESTED}`
|
|
771
|
-
)
|
|
736
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
772
737
|
];
|
|
773
738
|
if (!this.#summaryElements.length) {
|
|
774
739
|
console.warn("Missing <summary> elements");
|
|
775
740
|
return;
|
|
776
741
|
}
|
|
777
742
|
this.#contentElements = [
|
|
778
|
-
...this.#rootElement.querySelectorAll(
|
|
779
|
-
`summary${NOT_NESTED} + *`
|
|
780
|
-
)
|
|
743
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
781
744
|
];
|
|
782
745
|
if (!this.#contentElements.length) {
|
|
783
746
|
console.warn("Missing content elements");
|
|
@@ -800,7 +763,7 @@ var Disclosure = class _Disclosure {
|
|
|
800
763
|
if (this.#isDestroyed) {
|
|
801
764
|
return;
|
|
802
765
|
}
|
|
803
|
-
if (!
|
|
766
|
+
if (!this.#isValidDetails(details)) {
|
|
804
767
|
console.warn("Invalid <details> element");
|
|
805
768
|
return;
|
|
806
769
|
}
|
|
@@ -841,18 +804,14 @@ var Disclosure = class _Disclosure {
|
|
|
841
804
|
if (this.#isDestroyed) {
|
|
842
805
|
return;
|
|
843
806
|
}
|
|
844
|
-
if (!
|
|
807
|
+
if (!this.#isValidDetails(details)) {
|
|
845
808
|
console.warn("Invalid <details> element");
|
|
846
809
|
return;
|
|
847
810
|
}
|
|
848
811
|
this.#toggle(details, true);
|
|
849
812
|
}
|
|
850
813
|
#initialize() {
|
|
851
|
-
saveAttributes(this.#summaryElements, [
|
|
852
|
-
"aria-disabled",
|
|
853
|
-
"style",
|
|
854
|
-
"tabindex"
|
|
855
|
-
]);
|
|
814
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
856
815
|
this.#eventController = new AbortController();
|
|
857
816
|
const { signal } = this.#eventController;
|
|
858
817
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -910,9 +869,7 @@ var Disclosure = class _Disclosure {
|
|
|
910
869
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
911
870
|
return;
|
|
912
871
|
}
|
|
913
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
914
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
915
|
-
).length <= 1) {
|
|
872
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
916
873
|
return;
|
|
917
874
|
}
|
|
918
875
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -968,6 +925,9 @@ var Disclosure = class _Disclosure {
|
|
|
968
925
|
#isFocusable(element) {
|
|
969
926
|
return element.tabIndex >= 0;
|
|
970
927
|
}
|
|
928
|
+
#isValidDetails(details) {
|
|
929
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
930
|
+
}
|
|
971
931
|
async #waitAnimationsFinish() {
|
|
972
932
|
const promises = [];
|
|
973
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)) {
|
|
@@ -343,39 +319,28 @@ function isFocusable(element, options = {}) {
|
|
|
343
319
|
|
|
344
320
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
345
321
|
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
346
|
-
function
|
|
322
|
+
function getCellCenter(cell) {
|
|
347
323
|
const { left, top, width, height } = cell.getBoundingClientRect();
|
|
348
324
|
return { x: left + width / 2, y: top + height / 2 };
|
|
349
325
|
}
|
|
350
|
-
function getCellsOfActiveRow(cells) {
|
|
351
|
-
const active = getActiveElement();
|
|
352
|
-
if (!(active instanceof Element)) {
|
|
353
|
-
return [];
|
|
354
|
-
}
|
|
355
|
-
const activeRect = active.getBoundingClientRect();
|
|
356
|
-
return cells.filter((cell) => {
|
|
357
|
-
const cellRect = cell.getBoundingClientRect();
|
|
358
|
-
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
326
|
function getNextCell(cells, key, wrap) {
|
|
362
327
|
const active = getActiveElement();
|
|
363
328
|
if (!(active instanceof Element)) {
|
|
364
329
|
return null;
|
|
365
330
|
}
|
|
366
|
-
const
|
|
331
|
+
const activeCenter = getCellCenter(active);
|
|
367
332
|
let min = Infinity;
|
|
368
333
|
let result = null;
|
|
369
334
|
for (const cell of cells) {
|
|
370
335
|
if (cell === active) {
|
|
371
336
|
continue;
|
|
372
337
|
}
|
|
373
|
-
const
|
|
338
|
+
const cellCenter = getCellCenter(cell);
|
|
374
339
|
const distances = {
|
|
375
|
-
x: Math.abs(
|
|
376
|
-
y: Math.abs(
|
|
340
|
+
x: Math.abs(cellCenter.x - activeCenter.x),
|
|
341
|
+
y: Math.abs(cellCenter.y - activeCenter.y)
|
|
377
342
|
};
|
|
378
|
-
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) {
|
|
379
344
|
const distance = distances.x ** 2 + distances.y ** 2;
|
|
380
345
|
if (distance < min) {
|
|
381
346
|
min = distance;
|
|
@@ -389,9 +354,9 @@ function getNextCell(cells, key, wrap) {
|
|
|
389
354
|
if (cell === active) {
|
|
390
355
|
continue;
|
|
391
356
|
}
|
|
392
|
-
const
|
|
393
|
-
if (Math.abs(
|
|
394
|
-
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;
|
|
395
360
|
if (distance > max) {
|
|
396
361
|
max = distance;
|
|
397
362
|
result = cell;
|
|
@@ -401,6 +366,13 @@ function getNextCell(cells, key, wrap) {
|
|
|
401
366
|
}
|
|
402
367
|
return result;
|
|
403
368
|
}
|
|
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,7 +384,11 @@ 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
393
|
if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
|
|
418
394
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
@@ -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,20 +468,27 @@ 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) => {
|
|
489
|
+
if (!(event instanceof KeyboardEvent)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
517
492
|
const direction = this.#getDirection();
|
|
518
493
|
const isGrid = direction === "grid";
|
|
519
494
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
@@ -521,21 +496,20 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
521
496
|
return;
|
|
522
497
|
}
|
|
523
498
|
const isBoth = direction === "both";
|
|
499
|
+
const is2D = isGrid || isBoth;
|
|
524
500
|
const isHorizontal = direction === "horizontal";
|
|
525
|
-
const { typeahead, wrap
|
|
501
|
+
const { typeahead, wrap } = this.#settings;
|
|
526
502
|
if (![
|
|
527
503
|
"End",
|
|
528
504
|
"Home",
|
|
529
|
-
...
|
|
530
|
-
...
|
|
505
|
+
...is2D ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
506
|
+
...is2D ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
531
507
|
].includes(key)) {
|
|
532
508
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
533
509
|
return;
|
|
534
510
|
}
|
|
535
511
|
}
|
|
536
|
-
const candidates = this.#getFocusables().filter(
|
|
537
|
-
(f) => this.#focusables.has(f)
|
|
538
|
-
);
|
|
512
|
+
const candidates = this.#getFocusables().filter((f) => this.#focusables.has(f));
|
|
539
513
|
const active = getActiveElement();
|
|
540
514
|
if (!(active instanceof Element)) {
|
|
541
515
|
return;
|
|
@@ -552,7 +526,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
552
526
|
case "Home": {
|
|
553
527
|
const rawIndex = key === "End" ? -1 : 0;
|
|
554
528
|
if (isGrid && !ctrlKey) {
|
|
555
|
-
const cell = this.#
|
|
529
|
+
const cell = this.#getSameRowCells().at(rawIndex);
|
|
556
530
|
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
557
531
|
break;
|
|
558
532
|
}
|
|
@@ -569,11 +543,12 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
569
543
|
break;
|
|
570
544
|
}
|
|
571
545
|
if (isGrid) {
|
|
572
|
-
target = this.#
|
|
546
|
+
target = this.#getSameRowCells();
|
|
573
547
|
}
|
|
574
548
|
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
575
549
|
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
576
|
-
|
|
550
|
+
const { length } = target;
|
|
551
|
+
newIndex = isPrevious ? !wrap ? Math.max(rawIndex, 0) : rawIndex : !wrap ? Math.min(rawIndex, length - 1) : rawIndex % length;
|
|
577
552
|
break;
|
|
578
553
|
}
|
|
579
554
|
default: {
|
|
@@ -581,9 +556,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
581
556
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
582
557
|
);
|
|
583
558
|
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
584
|
-
const afterIndex = target.findIndex(
|
|
585
|
-
(f) => candidates.indexOf(f) > activeIndex
|
|
586
|
-
);
|
|
559
|
+
const afterIndex = target.findIndex((f) => candidates.indexOf(f) > activeIndex);
|
|
587
560
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
588
561
|
}
|
|
589
562
|
}
|
|
@@ -632,9 +605,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
632
605
|
if (char) {
|
|
633
606
|
keys.add(char);
|
|
634
607
|
saveAttributes(focusable, "aria-keyshortcuts");
|
|
635
|
-
addAttributeToken(focusable, "aria-keyshortcuts", char, {
|
|
636
|
-
caseInsensitive: true
|
|
637
|
-
});
|
|
608
|
+
addAttributeToken(focusable, "aria-keyshortcuts", char, { caseInsensitive: true });
|
|
638
609
|
}
|
|
639
610
|
for (const key of keys) {
|
|
640
611
|
const focusables = this.#focusablesByFirstChar.get(key) ?? [];
|
|
@@ -658,9 +629,6 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
658
629
|
const { selector } = this.#settings;
|
|
659
630
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
660
631
|
}
|
|
661
|
-
#getCellsOfActiveRow() {
|
|
662
|
-
return getCellsOfActiveRow(this.#getFocusables());
|
|
663
|
-
}
|
|
664
632
|
#getDirection() {
|
|
665
633
|
const { direction } = this.#settings;
|
|
666
634
|
if (typeof direction === "string") {
|
|
@@ -680,6 +648,10 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
680
648
|
#getNextCell(key, wrap) {
|
|
681
649
|
return getNextCell(this.#getFocusables(), key, wrap);
|
|
682
650
|
}
|
|
651
|
+
#getSameRowCells() {
|
|
652
|
+
const active = getActiveElement();
|
|
653
|
+
return active instanceof Element ? getSameRowCells(this.#getFocusables(), active) : [];
|
|
654
|
+
}
|
|
683
655
|
};
|
|
684
656
|
|
|
685
657
|
// src/defaults.ts
|
|
@@ -746,36 +718,27 @@ var Disclosure = class _Disclosure {
|
|
|
746
718
|
return;
|
|
747
719
|
}
|
|
748
720
|
this.#rootElement = root;
|
|
749
|
-
this.#settings = resolveOptions4(
|
|
750
|
-
resolveOptions4(defaults, _Disclosure.defaults),
|
|
751
|
-
options
|
|
752
|
-
);
|
|
721
|
+
this.#settings = resolveOptions4(resolveOptions4(defaults, _Disclosure.defaults), options);
|
|
753
722
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
754
723
|
this.#settings.animation.duration = 0;
|
|
755
724
|
}
|
|
756
725
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
757
726
|
this.#detailsElements = [
|
|
758
|
-
...this.#rootElement.querySelectorAll(
|
|
759
|
-
`details${NOT_NESTED}`
|
|
760
|
-
)
|
|
727
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
761
728
|
];
|
|
762
729
|
if (!this.#detailsElements.length) {
|
|
763
730
|
console.warn("Missing <details> elements");
|
|
764
731
|
return;
|
|
765
732
|
}
|
|
766
733
|
this.#summaryElements = [
|
|
767
|
-
...this.#rootElement.querySelectorAll(
|
|
768
|
-
`summary${NOT_NESTED}`
|
|
769
|
-
)
|
|
734
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
770
735
|
];
|
|
771
736
|
if (!this.#summaryElements.length) {
|
|
772
737
|
console.warn("Missing <summary> elements");
|
|
773
738
|
return;
|
|
774
739
|
}
|
|
775
740
|
this.#contentElements = [
|
|
776
|
-
...this.#rootElement.querySelectorAll(
|
|
777
|
-
`summary${NOT_NESTED} + *`
|
|
778
|
-
)
|
|
741
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
779
742
|
];
|
|
780
743
|
if (!this.#contentElements.length) {
|
|
781
744
|
console.warn("Missing content elements");
|
|
@@ -798,7 +761,7 @@ var Disclosure = class _Disclosure {
|
|
|
798
761
|
if (this.#isDestroyed) {
|
|
799
762
|
return;
|
|
800
763
|
}
|
|
801
|
-
if (!
|
|
764
|
+
if (!this.#isValidDetails(details)) {
|
|
802
765
|
console.warn("Invalid <details> element");
|
|
803
766
|
return;
|
|
804
767
|
}
|
|
@@ -839,18 +802,14 @@ var Disclosure = class _Disclosure {
|
|
|
839
802
|
if (this.#isDestroyed) {
|
|
840
803
|
return;
|
|
841
804
|
}
|
|
842
|
-
if (!
|
|
805
|
+
if (!this.#isValidDetails(details)) {
|
|
843
806
|
console.warn("Invalid <details> element");
|
|
844
807
|
return;
|
|
845
808
|
}
|
|
846
809
|
this.#toggle(details, true);
|
|
847
810
|
}
|
|
848
811
|
#initialize() {
|
|
849
|
-
saveAttributes(this.#summaryElements, [
|
|
850
|
-
"aria-disabled",
|
|
851
|
-
"style",
|
|
852
|
-
"tabindex"
|
|
853
|
-
]);
|
|
812
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
854
813
|
this.#eventController = new AbortController();
|
|
855
814
|
const { signal } = this.#eventController;
|
|
856
815
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -908,9 +867,7 @@ var Disclosure = class _Disclosure {
|
|
|
908
867
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
909
868
|
return;
|
|
910
869
|
}
|
|
911
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
912
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
913
|
-
).length <= 1) {
|
|
870
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
914
871
|
return;
|
|
915
872
|
}
|
|
916
873
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -966,6 +923,9 @@ var Disclosure = class _Disclosure {
|
|
|
966
923
|
#isFocusable(element) {
|
|
967
924
|
return element.tabIndex >= 0;
|
|
968
925
|
}
|
|
926
|
+
#isValidDetails(details) {
|
|
927
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
928
|
+
}
|
|
969
929
|
async #waitAnimationsFinish() {
|
|
970
930
|
const promises = [];
|
|
971
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) => {
|
|
@@ -231,9 +218,7 @@ var Disclosure = class _Disclosure {
|
|
|
231
218
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
232
219
|
return;
|
|
233
220
|
}
|
|
234
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
235
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
236
|
-
).length <= 1) {
|
|
221
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
237
222
|
return;
|
|
238
223
|
}
|
|
239
224
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -289,6 +274,9 @@ var Disclosure = class _Disclosure {
|
|
|
289
274
|
#isFocusable(element) {
|
|
290
275
|
return element.tabIndex >= 0;
|
|
291
276
|
}
|
|
277
|
+
#isValidDetails(details) {
|
|
278
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
279
|
+
}
|
|
292
280
|
async #waitAnimationsFinish() {
|
|
293
281
|
const promises = [];
|
|
294
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) => {
|
|
@@ -229,9 +216,7 @@ var Disclosure = class _Disclosure {
|
|
|
229
216
|
if (details.hasAttribute("data-disclosure-open") === isExpand) {
|
|
230
217
|
return;
|
|
231
218
|
}
|
|
232
|
-
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter(
|
|
233
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
234
|
-
).length <= 1) {
|
|
219
|
+
if (!isExpand && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
235
220
|
return;
|
|
236
221
|
}
|
|
237
222
|
const name = details.getAttribute("data-disclosure-name");
|
|
@@ -287,6 +272,9 @@ var Disclosure = class _Disclosure {
|
|
|
287
272
|
#isFocusable(element) {
|
|
288
273
|
return element.tabIndex >= 0;
|
|
289
274
|
}
|
|
275
|
+
#isValidDetails(details) {
|
|
276
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
277
|
+
}
|
|
290
278
|
async #waitAnimationsFinish() {
|
|
291
279
|
const promises = [];
|
|
292
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",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@y14e/attribute-utils": "^2.0.18",
|
|
58
|
-
"@y14e/roving-tabindex": "^3.5.
|
|
58
|
+
"@y14e/roving-tabindex": "^3.5.5"
|
|
59
59
|
}
|
|
60
60
|
}
|