@y14e/disclosure-css 2.1.0 → 2.1.1
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/README.md +3 -3
- package/dist/index.bundle.cjs +109 -42
- package/dist/index.bundle.js +109 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/disclosure-css
|
|
|
13
13
|
import { Disclosure } from '@y14e/disclosure-css';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { Disclosure } from 'https://esm.sh/@y14e/disclosure-css@2.1.
|
|
16
|
+
import { Disclosure } from 'https://esm.sh/@y14e/disclosure-css@2.1.1';
|
|
17
17
|
// or
|
|
18
|
-
import { Disclosure } from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@2.1.
|
|
18
|
+
import { Disclosure } from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@2.1.1/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { Disclosure } from 'https://esm.unpkg.com/@y14e/disclosure-css@2.1.
|
|
20
|
+
import { Disclosure } from 'https://esm.unpkg.com/@y14e/disclosure-css@2.1.1';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Usage
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -207,31 +207,25 @@ function normalizeRadioGroup(elements) {
|
|
|
207
207
|
map = /* @__PURE__ */ new Map();
|
|
208
208
|
}
|
|
209
209
|
const root = element.getRootNode();
|
|
210
|
-
|
|
210
|
+
const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
|
|
211
211
|
if (!groups) {
|
|
212
|
-
|
|
213
|
-
map.set(root, groups);
|
|
214
|
-
}
|
|
215
|
-
let group = groups.get(element.form);
|
|
216
|
-
if (!group) {
|
|
217
|
-
group = /* @__PURE__ */ new Map();
|
|
218
|
-
groups.set(element.form, group);
|
|
212
|
+
continue;
|
|
219
213
|
}
|
|
220
|
-
|
|
214
|
+
const { form, name } = element;
|
|
215
|
+
const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
|
|
221
216
|
if (!radios) {
|
|
222
|
-
|
|
223
|
-
group.set(element.name, radios);
|
|
217
|
+
continue;
|
|
224
218
|
}
|
|
225
|
-
radios.push(element);
|
|
219
|
+
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
226
220
|
}
|
|
227
221
|
if (!map) {
|
|
228
222
|
return elements;
|
|
229
223
|
}
|
|
230
224
|
const placeholder = /* @__PURE__ */ new Set();
|
|
231
|
-
for (const
|
|
232
|
-
for (const
|
|
233
|
-
for (const
|
|
234
|
-
const radio =
|
|
225
|
+
for (const v of map.values()) {
|
|
226
|
+
for (const w of v.values()) {
|
|
227
|
+
for (const x of w.values()) {
|
|
228
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
235
229
|
radio && placeholder.add(radio);
|
|
236
230
|
}
|
|
237
231
|
}
|
|
@@ -352,14 +346,15 @@ function resolveOptions2(options) {
|
|
|
352
346
|
}
|
|
353
347
|
|
|
354
348
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
349
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
355
350
|
function createRovingTabIndex(container, options = {}) {
|
|
356
351
|
if (!(container instanceof Element)) {
|
|
357
352
|
console.warn("Invalid container element");
|
|
358
353
|
return () => {
|
|
359
354
|
};
|
|
360
355
|
}
|
|
361
|
-
const
|
|
362
|
-
return () =>
|
|
356
|
+
const rovingTabIndex = new RovingTabIndex(container, options);
|
|
357
|
+
return () => rovingTabIndex.destroy();
|
|
363
358
|
}
|
|
364
359
|
var RovingTabIndex = class _RovingTabIndex {
|
|
365
360
|
static #initialized = /* @__PURE__ */ new Set();
|
|
@@ -418,18 +413,19 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
418
413
|
if (!(event instanceof KeyboardEvent)) {
|
|
419
414
|
return;
|
|
420
415
|
}
|
|
416
|
+
const { direction, typeahead, wrap = false } = this.#settings;
|
|
417
|
+
const isGrid = direction === "grid";
|
|
421
418
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
422
|
-
if (
|
|
419
|
+
if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
|
|
423
420
|
return;
|
|
424
421
|
}
|
|
425
|
-
const { direction, typeahead, wrap } = this.#settings;
|
|
426
422
|
const isBoth = direction === "both";
|
|
427
423
|
const isHorizontal = direction === "horizontal";
|
|
428
424
|
if (![
|
|
429
425
|
"End",
|
|
430
426
|
"Home",
|
|
431
|
-
...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
432
|
-
...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
427
|
+
...isGrid || isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
428
|
+
...isGrid || isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
433
429
|
].includes(key)) {
|
|
434
430
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
435
431
|
return;
|
|
@@ -448,39 +444,48 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
448
444
|
event.preventDefault();
|
|
449
445
|
let newIndex;
|
|
450
446
|
const activeIndex = candidates.indexOf(active);
|
|
451
|
-
let
|
|
447
|
+
let target = candidates;
|
|
452
448
|
switch (key) {
|
|
453
449
|
case "End":
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
450
|
+
case "Home": {
|
|
451
|
+
const rawIndex = key === "End" ? -1 : 0;
|
|
452
|
+
if (isGrid && !ctrlKey) {
|
|
453
|
+
const cell = this.#getCellsOfActiveRow().at(rawIndex);
|
|
454
|
+
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
455
|
+
} else {
|
|
456
|
+
newIndex = rawIndex;
|
|
457
|
+
}
|
|
463
458
|
break;
|
|
464
459
|
}
|
|
460
|
+
case "ArrowLeft":
|
|
461
|
+
case "ArrowUp":
|
|
465
462
|
case "ArrowRight":
|
|
466
463
|
case "ArrowDown": {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
if (["ArrowUp", "ArrowDown"].includes(key) && isGrid) {
|
|
465
|
+
const cell = this.#getNextCell(key, wrap);
|
|
466
|
+
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
467
|
+
} else {
|
|
468
|
+
if (isGrid) {
|
|
469
|
+
target = this.#getCellsOfActiveRow();
|
|
470
|
+
}
|
|
471
|
+
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
472
|
+
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
473
|
+
newIndex = isPrevious ? wrap ? rawIndex : Math.max(rawIndex, 0) : wrap ? rawIndex % target.length : Math.min(rawIndex, target.length - 1);
|
|
474
|
+
}
|
|
470
475
|
break;
|
|
471
476
|
}
|
|
472
477
|
default: {
|
|
473
478
|
const focusablesByFirstChar = new Set(
|
|
474
479
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
475
480
|
);
|
|
476
|
-
|
|
477
|
-
const afterIndex =
|
|
481
|
+
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
482
|
+
const afterIndex = target.findIndex(
|
|
478
483
|
(f) => candidates.indexOf(f) > activeIndex
|
|
479
484
|
);
|
|
480
485
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
481
486
|
}
|
|
482
487
|
}
|
|
483
|
-
const focusable =
|
|
488
|
+
const focusable = target.at(newIndex);
|
|
484
489
|
focusable && focusElement(focusable);
|
|
485
490
|
};
|
|
486
491
|
#update(active) {
|
|
@@ -550,6 +555,24 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
550
555
|
const { selector } = this.#settings;
|
|
551
556
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
552
557
|
}
|
|
558
|
+
#getCellCoords(cell) {
|
|
559
|
+
const { height, left, top, width } = cell.getBoundingClientRect();
|
|
560
|
+
return {
|
|
561
|
+
x: left + width / 2,
|
|
562
|
+
y: top + height / 2
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
#getCellsOfActiveRow() {
|
|
566
|
+
const active = getActiveElement();
|
|
567
|
+
if (!(active instanceof Element)) {
|
|
568
|
+
return [];
|
|
569
|
+
}
|
|
570
|
+
const activeRect = active.getBoundingClientRect();
|
|
571
|
+
return this.#getFocusables().filter((cell) => {
|
|
572
|
+
const cellRect = cell.getBoundingClientRect();
|
|
573
|
+
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
574
|
+
});
|
|
575
|
+
}
|
|
553
576
|
#getFocusables() {
|
|
554
577
|
return getFocusables(this.#container, {
|
|
555
578
|
composed: true,
|
|
@@ -558,6 +581,50 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
558
581
|
skipVisibilityCheck: true
|
|
559
582
|
});
|
|
560
583
|
}
|
|
584
|
+
#getNextCell(key, wrap) {
|
|
585
|
+
const cells = this.#getFocusables();
|
|
586
|
+
const active = getActiveElement();
|
|
587
|
+
if (!(active instanceof Element)) {
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
590
|
+
const activeCoords = this.#getCellCoords(active);
|
|
591
|
+
let min = Infinity;
|
|
592
|
+
let result = null;
|
|
593
|
+
for (const cell of cells) {
|
|
594
|
+
if (cell === active) {
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const cellCoords = this.#getCellCoords(cell);
|
|
598
|
+
const distances = {
|
|
599
|
+
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
600
|
+
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
601
|
+
};
|
|
602
|
+
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
603
|
+
const distance = distances.x ** 2 + distances.y ** 2;
|
|
604
|
+
if (distance < min) {
|
|
605
|
+
min = distance;
|
|
606
|
+
result = cell;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (!result && wrap) {
|
|
611
|
+
let max = -Infinity;
|
|
612
|
+
for (const cell of cells) {
|
|
613
|
+
if (cell === active) {
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
const cellCoords = this.#getCellCoords(cell);
|
|
617
|
+
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
618
|
+
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
619
|
+
if (distance > max) {
|
|
620
|
+
max = distance;
|
|
621
|
+
result = cell;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
561
628
|
#resolveOptions(options) {
|
|
562
629
|
let {
|
|
563
630
|
direction = "both",
|
|
@@ -569,7 +636,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
569
636
|
wrap = false
|
|
570
637
|
} = options;
|
|
571
638
|
direction = direction.toLowerCase();
|
|
572
|
-
if (!
|
|
639
|
+
if (!DIRECTIONS.includes(direction)) {
|
|
573
640
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
574
641
|
direction = "both";
|
|
575
642
|
}
|
|
@@ -780,7 +847,7 @@ var Disclosure = class _Disclosure {
|
|
|
780
847
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
781
848
|
* Using the <details> and <summary> element.
|
|
782
849
|
*
|
|
783
|
-
* @version 2.1.
|
|
850
|
+
* @version 2.1.1
|
|
784
851
|
* @author Yusuke Kamiyamane
|
|
785
852
|
* @license MIT
|
|
786
853
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -805,7 +872,7 @@ power-focusable/dist/index.js:
|
|
|
805
872
|
* High-precision focus management utility with full composed tree support.
|
|
806
873
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
807
874
|
*
|
|
808
|
-
* @version 4.3
|
|
875
|
+
* @version 4.4.3
|
|
809
876
|
* @author Yusuke Kamiyamane
|
|
810
877
|
* @license MIT
|
|
811
878
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -818,7 +885,7 @@ power-focusable/dist/index.js:
|
|
|
818
885
|
* Lightweight roving tabindex utility with fully focus management.
|
|
819
886
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
820
887
|
*
|
|
821
|
-
* @version 3.
|
|
888
|
+
* @version 3.3.2
|
|
822
889
|
* @author Yusuke Kamiyamane
|
|
823
890
|
* @license MIT
|
|
824
891
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -205,31 +205,25 @@ function normalizeRadioGroup(elements) {
|
|
|
205
205
|
map = /* @__PURE__ */ new Map();
|
|
206
206
|
}
|
|
207
207
|
const root = element.getRootNode();
|
|
208
|
-
|
|
208
|
+
const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
|
|
209
209
|
if (!groups) {
|
|
210
|
-
|
|
211
|
-
map.set(root, groups);
|
|
212
|
-
}
|
|
213
|
-
let group = groups.get(element.form);
|
|
214
|
-
if (!group) {
|
|
215
|
-
group = /* @__PURE__ */ new Map();
|
|
216
|
-
groups.set(element.form, group);
|
|
210
|
+
continue;
|
|
217
211
|
}
|
|
218
|
-
|
|
212
|
+
const { form, name } = element;
|
|
213
|
+
const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
|
|
219
214
|
if (!radios) {
|
|
220
|
-
|
|
221
|
-
group.set(element.name, radios);
|
|
215
|
+
continue;
|
|
222
216
|
}
|
|
223
|
-
radios.push(element);
|
|
217
|
+
(radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
|
|
224
218
|
}
|
|
225
219
|
if (!map) {
|
|
226
220
|
return elements;
|
|
227
221
|
}
|
|
228
222
|
const placeholder = /* @__PURE__ */ new Set();
|
|
229
|
-
for (const
|
|
230
|
-
for (const
|
|
231
|
-
for (const
|
|
232
|
-
const radio =
|
|
223
|
+
for (const v of map.values()) {
|
|
224
|
+
for (const w of v.values()) {
|
|
225
|
+
for (const x of w.values()) {
|
|
226
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
233
227
|
radio && placeholder.add(radio);
|
|
234
228
|
}
|
|
235
229
|
}
|
|
@@ -350,14 +344,15 @@ function resolveOptions2(options) {
|
|
|
350
344
|
}
|
|
351
345
|
|
|
352
346
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
347
|
+
var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
|
|
353
348
|
function createRovingTabIndex(container, options = {}) {
|
|
354
349
|
if (!(container instanceof Element)) {
|
|
355
350
|
console.warn("Invalid container element");
|
|
356
351
|
return () => {
|
|
357
352
|
};
|
|
358
353
|
}
|
|
359
|
-
const
|
|
360
|
-
return () =>
|
|
354
|
+
const rovingTabIndex = new RovingTabIndex(container, options);
|
|
355
|
+
return () => rovingTabIndex.destroy();
|
|
361
356
|
}
|
|
362
357
|
var RovingTabIndex = class _RovingTabIndex {
|
|
363
358
|
static #initialized = /* @__PURE__ */ new Set();
|
|
@@ -416,18 +411,19 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
416
411
|
if (!(event instanceof KeyboardEvent)) {
|
|
417
412
|
return;
|
|
418
413
|
}
|
|
414
|
+
const { direction, typeahead, wrap = false } = this.#settings;
|
|
415
|
+
const isGrid = direction === "grid";
|
|
419
416
|
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
420
|
-
if (
|
|
417
|
+
if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
|
|
421
418
|
return;
|
|
422
419
|
}
|
|
423
|
-
const { direction, typeahead, wrap } = this.#settings;
|
|
424
420
|
const isBoth = direction === "both";
|
|
425
421
|
const isHorizontal = direction === "horizontal";
|
|
426
422
|
if (![
|
|
427
423
|
"End",
|
|
428
424
|
"Home",
|
|
429
|
-
...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
430
|
-
...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
425
|
+
...isGrid || isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
|
|
426
|
+
...isGrid || isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
|
|
431
427
|
].includes(key)) {
|
|
432
428
|
if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
|
|
433
429
|
return;
|
|
@@ -446,39 +442,48 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
446
442
|
event.preventDefault();
|
|
447
443
|
let newIndex;
|
|
448
444
|
const activeIndex = candidates.indexOf(active);
|
|
449
|
-
let
|
|
445
|
+
let target = candidates;
|
|
450
446
|
switch (key) {
|
|
451
447
|
case "End":
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
|
|
448
|
+
case "Home": {
|
|
449
|
+
const rawIndex = key === "End" ? -1 : 0;
|
|
450
|
+
if (isGrid && !ctrlKey) {
|
|
451
|
+
const cell = this.#getCellsOfActiveRow().at(rawIndex);
|
|
452
|
+
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
453
|
+
} else {
|
|
454
|
+
newIndex = rawIndex;
|
|
455
|
+
}
|
|
461
456
|
break;
|
|
462
457
|
}
|
|
458
|
+
case "ArrowLeft":
|
|
459
|
+
case "ArrowUp":
|
|
463
460
|
case "ArrowRight":
|
|
464
461
|
case "ArrowDown": {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
462
|
+
if (["ArrowUp", "ArrowDown"].includes(key) && isGrid) {
|
|
463
|
+
const cell = this.#getNextCell(key, wrap);
|
|
464
|
+
newIndex = cell ? candidates.indexOf(cell) : activeIndex;
|
|
465
|
+
} else {
|
|
466
|
+
if (isGrid) {
|
|
467
|
+
target = this.#getCellsOfActiveRow();
|
|
468
|
+
}
|
|
469
|
+
const isPrevious = ["ArrowLeft", "ArrowUp"].includes(key);
|
|
470
|
+
const rawIndex = (isGrid ? target.indexOf(active) : activeIndex) + (isPrevious ? -1 : 1);
|
|
471
|
+
newIndex = isPrevious ? wrap ? rawIndex : Math.max(rawIndex, 0) : wrap ? rawIndex % target.length : Math.min(rawIndex, target.length - 1);
|
|
472
|
+
}
|
|
468
473
|
break;
|
|
469
474
|
}
|
|
470
475
|
default: {
|
|
471
476
|
const focusablesByFirstChar = new Set(
|
|
472
477
|
this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
|
|
473
478
|
);
|
|
474
|
-
|
|
475
|
-
const afterIndex =
|
|
479
|
+
target = candidates.filter((c) => focusablesByFirstChar.has(c));
|
|
480
|
+
const afterIndex = target.findIndex(
|
|
476
481
|
(f) => candidates.indexOf(f) > activeIndex
|
|
477
482
|
);
|
|
478
483
|
newIndex = afterIndex >= 0 ? afterIndex : 0;
|
|
479
484
|
}
|
|
480
485
|
}
|
|
481
|
-
const focusable =
|
|
486
|
+
const focusable = target.at(newIndex);
|
|
482
487
|
focusable && focusElement(focusable);
|
|
483
488
|
};
|
|
484
489
|
#update(active) {
|
|
@@ -548,6 +553,24 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
548
553
|
const { selector } = this.#settings;
|
|
549
554
|
return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
|
|
550
555
|
}
|
|
556
|
+
#getCellCoords(cell) {
|
|
557
|
+
const { height, left, top, width } = cell.getBoundingClientRect();
|
|
558
|
+
return {
|
|
559
|
+
x: left + width / 2,
|
|
560
|
+
y: top + height / 2
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
#getCellsOfActiveRow() {
|
|
564
|
+
const active = getActiveElement();
|
|
565
|
+
if (!(active instanceof Element)) {
|
|
566
|
+
return [];
|
|
567
|
+
}
|
|
568
|
+
const activeRect = active.getBoundingClientRect();
|
|
569
|
+
return this.#getFocusables().filter((cell) => {
|
|
570
|
+
const cellRect = cell.getBoundingClientRect();
|
|
571
|
+
return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
551
574
|
#getFocusables() {
|
|
552
575
|
return getFocusables(this.#container, {
|
|
553
576
|
composed: true,
|
|
@@ -556,6 +579,50 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
556
579
|
skipVisibilityCheck: true
|
|
557
580
|
});
|
|
558
581
|
}
|
|
582
|
+
#getNextCell(key, wrap) {
|
|
583
|
+
const cells = this.#getFocusables();
|
|
584
|
+
const active = getActiveElement();
|
|
585
|
+
if (!(active instanceof Element)) {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
const activeCoords = this.#getCellCoords(active);
|
|
589
|
+
let min = Infinity;
|
|
590
|
+
let result = null;
|
|
591
|
+
for (const cell of cells) {
|
|
592
|
+
if (cell === active) {
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
const cellCoords = this.#getCellCoords(cell);
|
|
596
|
+
const distances = {
|
|
597
|
+
x: Math.abs(cellCoords.x - activeCoords.x),
|
|
598
|
+
y: Math.abs(cellCoords.y - activeCoords.y)
|
|
599
|
+
};
|
|
600
|
+
if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
|
|
601
|
+
const distance = distances.x ** 2 + distances.y ** 2;
|
|
602
|
+
if (distance < min) {
|
|
603
|
+
min = distance;
|
|
604
|
+
result = cell;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (!result && wrap) {
|
|
609
|
+
let max = -Infinity;
|
|
610
|
+
for (const cell of cells) {
|
|
611
|
+
if (cell === active) {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
const cellCoords = this.#getCellCoords(cell);
|
|
615
|
+
if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
|
|
616
|
+
const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
|
|
617
|
+
if (distance > max) {
|
|
618
|
+
max = distance;
|
|
619
|
+
result = cell;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return result;
|
|
625
|
+
}
|
|
559
626
|
#resolveOptions(options) {
|
|
560
627
|
let {
|
|
561
628
|
direction = "both",
|
|
@@ -567,7 +634,7 @@ var RovingTabIndex = class _RovingTabIndex {
|
|
|
567
634
|
wrap = false
|
|
568
635
|
} = options;
|
|
569
636
|
direction = direction.toLowerCase();
|
|
570
|
-
if (!
|
|
637
|
+
if (!DIRECTIONS.includes(direction)) {
|
|
571
638
|
console.warn("Invalid direction option. Fallback: 'both'.");
|
|
572
639
|
direction = "both";
|
|
573
640
|
}
|
|
@@ -778,7 +845,7 @@ var Disclosure = class _Disclosure {
|
|
|
778
845
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
779
846
|
* Using the <details> and <summary> element.
|
|
780
847
|
*
|
|
781
|
-
* @version 2.1.
|
|
848
|
+
* @version 2.1.1
|
|
782
849
|
* @author Yusuke Kamiyamane
|
|
783
850
|
* @license MIT
|
|
784
851
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -803,7 +870,7 @@ power-focusable/dist/index.js:
|
|
|
803
870
|
* High-precision focus management utility with full composed tree support.
|
|
804
871
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
805
872
|
*
|
|
806
|
-
* @version 4.3
|
|
873
|
+
* @version 4.4.3
|
|
807
874
|
* @author Yusuke Kamiyamane
|
|
808
875
|
* @license MIT
|
|
809
876
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -816,7 +883,7 @@ power-focusable/dist/index.js:
|
|
|
816
883
|
* Lightweight roving tabindex utility with fully focus management.
|
|
817
884
|
* Designed for accessible menus, tabs, toolbars, and composite widgets.
|
|
818
885
|
*
|
|
819
|
-
* @version 3.
|
|
886
|
+
* @version 3.3.2
|
|
820
887
|
* @author Yusuke Kamiyamane
|
|
821
888
|
* @license MIT
|
|
822
889
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -170,7 +170,7 @@ var Disclosure = class _Disclosure {
|
|
|
170
170
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
171
171
|
* Using the <details> and <summary> element.
|
|
172
172
|
*
|
|
173
|
-
* @version 2.1.
|
|
173
|
+
* @version 2.1.1
|
|
174
174
|
* @author Yusuke Kamiyamane
|
|
175
175
|
* @license MIT
|
|
176
176
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -168,7 +168,7 @@ var Disclosure = class _Disclosure {
|
|
|
168
168
|
* WAI-ARIA compliant disclosure pattern implementation in TypeScript.
|
|
169
169
|
* Using the <details> and <summary> element.
|
|
170
170
|
*
|
|
171
|
-
* @version 2.1.
|
|
171
|
+
* @version 2.1.1
|
|
172
172
|
* @author Yusuke Kamiyamane
|
|
173
173
|
* @license MIT
|
|
174
174
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure-css",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
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.12",
|
|
58
|
-
"@y14e/roving-tabindex": "^3.
|
|
58
|
+
"@y14e/roving-tabindex": "^3.3.2"
|
|
59
59
|
}
|
|
60
60
|
}
|