@y14e/roving-tabindex 3.1.17 → 3.1.18

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 CHANGED
@@ -13,11 +13,11 @@ npm i @y14e/roving-tabindex
13
13
  import { createRovingTabIndex } from '@y14e/roving-tabindex';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.17';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.18';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.17/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.18/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.17';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.18';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -24,8 +24,8 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
24
24
  }
25
25
  }
26
26
  var snapshots = /* @__PURE__ */ new WeakMap();
27
- function restoreAttributes(elements) {
28
- for (const element of elements) {
27
+ function restoreAttributes(element_or_elements) {
28
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
29
29
  const snapshot = snapshots.get(element);
30
30
  if (!snapshot) {
31
31
  continue;
@@ -36,8 +36,9 @@ function restoreAttributes(elements) {
36
36
  snapshots.delete(element);
37
37
  }
38
38
  }
39
- function saveAttributes(elements, attributes) {
40
- elements.forEach((element) => {
39
+ function saveAttributes(element_or_elements, attribute_or_attributes) {
40
+ const attributes = Array.isArray(attribute_or_attributes) ? attribute_or_attributes : [attribute_or_attributes];
41
+ (Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
41
42
  let snapshot = snapshots.get(element);
42
43
  if (!snapshot) {
43
44
  snapshot = /* @__PURE__ */ new Map();
@@ -91,14 +92,14 @@ function getFocusables(container = document.body, options = {}) {
91
92
  console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
92
93
  skipVisibilityCheck = false;
93
94
  }
94
- const elements = [];
95
+ const candidates = [];
95
96
  if (composed || include) {
96
97
  let traverse2 = function(node) {
97
98
  if (isFocusable(node, {
98
99
  skipNegativeTabIndexCheck,
99
100
  skipVisibilityCheck
100
101
  }) || include?.(node)) {
101
- elements[elements.length] = node;
102
+ candidates[candidates.length] = node;
102
103
  }
103
104
  const children2 = composed ? getComposedChildren(node) : getChildren(node);
104
105
  for (let i = 0, l = children2.length; i < l; i++) {
@@ -112,21 +113,22 @@ function getFocusables(container = document.body, options = {}) {
112
113
  child && traverse2(child);
113
114
  }
114
115
  } else {
115
- const candidates = container.querySelectorAll(
116
+ const matches = container.querySelectorAll(
116
117
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
117
118
  );
118
- for (let i = 0, l = candidates.length; i < l; i++) {
119
- const candidate = candidates[i];
120
- if (candidate && isFocusable(candidate, {
119
+ for (let i = 0, l = matches.length; i < l; i++) {
120
+ const matched = matches[i];
121
+ if (matched && isFocusable(matched, {
121
122
  skipNegativeTabIndexCheck,
122
123
  skipVisibilityCheck
123
124
  })) {
124
- elements[elements.length] = candidate;
125
+ candidates[candidates.length] = matched;
125
126
  }
126
127
  }
127
128
  }
128
- const filtered = filter ? elements.filter(filter) : elements;
129
- return normalizeRadioGroup(sortByTabIndex(filtered));
129
+ return normalizeRadioGroup(
130
+ sortByTabIndex(filter ? candidates.filter(filter) : candidates)
131
+ );
130
132
  }
131
133
  function isFocusable(element, options = {}) {
132
134
  if (!(element instanceof Element)) {
@@ -405,7 +407,7 @@ var RovingTabIndex = class _RovingTabIndex {
405
407
  this.#controller = null;
406
408
  this.#focusables.forEach((focusable) => {
407
409
  _RovingTabIndex.#initialized.delete(focusable);
408
- restoreAttributes([focusable]);
410
+ restoreAttributes(focusable);
409
411
  });
410
412
  this.#focusables.clear();
411
413
  this.#focusablesByFirstChar.clear();
@@ -508,7 +510,7 @@ var RovingTabIndex = class _RovingTabIndex {
508
510
  for (const focusable of this.#focusables) {
509
511
  if (!current.has(focusable)) {
510
512
  _RovingTabIndex.#initialized.delete(focusable);
511
- restoreAttributes([focusable]);
513
+ restoreAttributes(focusable);
512
514
  this.#focusables.delete(focusable);
513
515
  for (const [key, focusables] of this.#focusablesByFirstChar) {
514
516
  const index = focusables.indexOf(focusable);
@@ -530,7 +532,7 @@ var RovingTabIndex = class _RovingTabIndex {
530
532
  this.#focusables.add(focusable);
531
533
  _RovingTabIndex.#initialized.add(focusable);
532
534
  if (!navigationOnly) {
533
- saveAttributes([focusable], ["tabindex"]);
535
+ saveAttributes(focusable, "tabindex");
534
536
  focusable.setAttribute("tabindex", "-1");
535
537
  }
536
538
  if (!typeahead) {
@@ -543,7 +545,7 @@ var RovingTabIndex = class _RovingTabIndex {
543
545
  );
544
546
  if (char) {
545
547
  keys.add(char);
546
- saveAttributes([focusable], ["aria-keyshortcuts"]);
548
+ saveAttributes(focusable, "aria-keyshortcuts");
547
549
  addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
548
550
  caseInsensitive: true
549
551
  });
@@ -584,7 +586,7 @@ var RovingTabIndex = class _RovingTabIndex {
584
586
  * Lightweight roving tabindex utility with fully focus management.
585
587
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
586
588
  *
587
- * @version 3.1.17
589
+ * @version 3.1.18
588
590
  * @author Yusuke Kamiyamane
589
591
  * @license MIT
590
592
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -596,7 +598,7 @@ var RovingTabIndex = class _RovingTabIndex {
596
598
  (**
597
599
  * Attributes Utils
598
600
  *
599
- * @version 1.1.3
601
+ * @version 1.1.4
600
602
  * @author Yusuke Kamiyamane
601
603
  * @license MIT
602
604
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -609,7 +611,7 @@ power-focusable/dist/index.js:
609
611
  * High-precision focus management utility with full composed tree support.
610
612
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
611
613
  *
612
- * @version 4.3.20
614
+ * @version 4.3.21
613
615
  * @author Yusuke Kamiyamane
614
616
  * @license MIT
615
617
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -22,8 +22,8 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
22
22
  }
23
23
  }
24
24
  var snapshots = /* @__PURE__ */ new WeakMap();
25
- function restoreAttributes(elements) {
26
- for (const element of elements) {
25
+ function restoreAttributes(element_or_elements) {
26
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
27
27
  const snapshot = snapshots.get(element);
28
28
  if (!snapshot) {
29
29
  continue;
@@ -34,8 +34,9 @@ function restoreAttributes(elements) {
34
34
  snapshots.delete(element);
35
35
  }
36
36
  }
37
- function saveAttributes(elements, attributes) {
38
- elements.forEach((element) => {
37
+ function saveAttributes(element_or_elements, attribute_or_attributes) {
38
+ const attributes = Array.isArray(attribute_or_attributes) ? attribute_or_attributes : [attribute_or_attributes];
39
+ (Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
39
40
  let snapshot = snapshots.get(element);
40
41
  if (!snapshot) {
41
42
  snapshot = /* @__PURE__ */ new Map();
@@ -89,14 +90,14 @@ function getFocusables(container = document.body, options = {}) {
89
90
  console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
90
91
  skipVisibilityCheck = false;
91
92
  }
92
- const elements = [];
93
+ const candidates = [];
93
94
  if (composed || include) {
94
95
  let traverse2 = function(node) {
95
96
  if (isFocusable(node, {
96
97
  skipNegativeTabIndexCheck,
97
98
  skipVisibilityCheck
98
99
  }) || include?.(node)) {
99
- elements[elements.length] = node;
100
+ candidates[candidates.length] = node;
100
101
  }
101
102
  const children2 = composed ? getComposedChildren(node) : getChildren(node);
102
103
  for (let i = 0, l = children2.length; i < l; i++) {
@@ -110,21 +111,22 @@ function getFocusables(container = document.body, options = {}) {
110
111
  child && traverse2(child);
111
112
  }
112
113
  } else {
113
- const candidates = container.querySelectorAll(
114
+ const matches = container.querySelectorAll(
114
115
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
115
116
  );
116
- for (let i = 0, l = candidates.length; i < l; i++) {
117
- const candidate = candidates[i];
118
- if (candidate && isFocusable(candidate, {
117
+ for (let i = 0, l = matches.length; i < l; i++) {
118
+ const matched = matches[i];
119
+ if (matched && isFocusable(matched, {
119
120
  skipNegativeTabIndexCheck,
120
121
  skipVisibilityCheck
121
122
  })) {
122
- elements[elements.length] = candidate;
123
+ candidates[candidates.length] = matched;
123
124
  }
124
125
  }
125
126
  }
126
- const filtered = filter ? elements.filter(filter) : elements;
127
- return normalizeRadioGroup(sortByTabIndex(filtered));
127
+ return normalizeRadioGroup(
128
+ sortByTabIndex(filter ? candidates.filter(filter) : candidates)
129
+ );
128
130
  }
129
131
  function isFocusable(element, options = {}) {
130
132
  if (!(element instanceof Element)) {
@@ -403,7 +405,7 @@ var RovingTabIndex = class _RovingTabIndex {
403
405
  this.#controller = null;
404
406
  this.#focusables.forEach((focusable) => {
405
407
  _RovingTabIndex.#initialized.delete(focusable);
406
- restoreAttributes([focusable]);
408
+ restoreAttributes(focusable);
407
409
  });
408
410
  this.#focusables.clear();
409
411
  this.#focusablesByFirstChar.clear();
@@ -506,7 +508,7 @@ var RovingTabIndex = class _RovingTabIndex {
506
508
  for (const focusable of this.#focusables) {
507
509
  if (!current.has(focusable)) {
508
510
  _RovingTabIndex.#initialized.delete(focusable);
509
- restoreAttributes([focusable]);
511
+ restoreAttributes(focusable);
510
512
  this.#focusables.delete(focusable);
511
513
  for (const [key, focusables] of this.#focusablesByFirstChar) {
512
514
  const index = focusables.indexOf(focusable);
@@ -528,7 +530,7 @@ var RovingTabIndex = class _RovingTabIndex {
528
530
  this.#focusables.add(focusable);
529
531
  _RovingTabIndex.#initialized.add(focusable);
530
532
  if (!navigationOnly) {
531
- saveAttributes([focusable], ["tabindex"]);
533
+ saveAttributes(focusable, "tabindex");
532
534
  focusable.setAttribute("tabindex", "-1");
533
535
  }
534
536
  if (!typeahead) {
@@ -541,7 +543,7 @@ var RovingTabIndex = class _RovingTabIndex {
541
543
  );
542
544
  if (char) {
543
545
  keys.add(char);
544
- saveAttributes([focusable], ["aria-keyshortcuts"]);
546
+ saveAttributes(focusable, "aria-keyshortcuts");
545
547
  addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
546
548
  caseInsensitive: true
547
549
  });
@@ -582,7 +584,7 @@ var RovingTabIndex = class _RovingTabIndex {
582
584
  * Lightweight roving tabindex utility with fully focus management.
583
585
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
584
586
  *
585
- * @version 3.1.17
587
+ * @version 3.1.18
586
588
  * @author Yusuke Kamiyamane
587
589
  * @license MIT
588
590
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -594,7 +596,7 @@ var RovingTabIndex = class _RovingTabIndex {
594
596
  (**
595
597
  * Attributes Utils
596
598
  *
597
- * @version 1.1.3
599
+ * @version 1.1.4
598
600
  * @author Yusuke Kamiyamane
599
601
  * @license MIT
600
602
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -607,7 +609,7 @@ power-focusable/dist/index.js:
607
609
  * High-precision focus management utility with full composed tree support.
608
610
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
609
611
  *
610
- * @version 4.3.20
612
+ * @version 4.3.21
611
613
  * @author Yusuke Kamiyamane
612
614
  * @license MIT
613
615
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -91,7 +91,7 @@ var RovingTabIndex = class _RovingTabIndex {
91
91
  this.#controller = null;
92
92
  this.#focusables.forEach((focusable) => {
93
93
  _RovingTabIndex.#initialized.delete(focusable);
94
- attributesUtils.restoreAttributes([focusable]);
94
+ attributesUtils.restoreAttributes(focusable);
95
95
  });
96
96
  this.#focusables.clear();
97
97
  this.#focusablesByFirstChar.clear();
@@ -194,7 +194,7 @@ var RovingTabIndex = class _RovingTabIndex {
194
194
  for (const focusable of this.#focusables) {
195
195
  if (!current.has(focusable)) {
196
196
  _RovingTabIndex.#initialized.delete(focusable);
197
- attributesUtils.restoreAttributes([focusable]);
197
+ attributesUtils.restoreAttributes(focusable);
198
198
  this.#focusables.delete(focusable);
199
199
  for (const [key, focusables] of this.#focusablesByFirstChar) {
200
200
  const index = focusables.indexOf(focusable);
@@ -216,7 +216,7 @@ var RovingTabIndex = class _RovingTabIndex {
216
216
  this.#focusables.add(focusable);
217
217
  _RovingTabIndex.#initialized.add(focusable);
218
218
  if (!navigationOnly) {
219
- attributesUtils.saveAttributes([focusable], ["tabindex"]);
219
+ attributesUtils.saveAttributes(focusable, "tabindex");
220
220
  focusable.setAttribute("tabindex", "-1");
221
221
  }
222
222
  if (!typeahead) {
@@ -229,7 +229,7 @@ var RovingTabIndex = class _RovingTabIndex {
229
229
  );
230
230
  if (char) {
231
231
  keys.add(char);
232
- attributesUtils.saveAttributes([focusable], ["aria-keyshortcuts"]);
232
+ attributesUtils.saveAttributes(focusable, "aria-keyshortcuts");
233
233
  attributesUtils.addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
234
234
  caseInsensitive: true
235
235
  });
@@ -270,7 +270,7 @@ var RovingTabIndex = class _RovingTabIndex {
270
270
  * Lightweight roving tabindex utility with fully focus management.
271
271
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
272
272
  *
273
- * @version 3.1.17
273
+ * @version 3.1.18
274
274
  * @author Yusuke Kamiyamane
275
275
  * @license MIT
276
276
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.1.17
6
+ * @version 3.1.18
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.1.17
6
+ * @version 3.1.18
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -89,7 +89,7 @@ var RovingTabIndex = class _RovingTabIndex {
89
89
  this.#controller = null;
90
90
  this.#focusables.forEach((focusable) => {
91
91
  _RovingTabIndex.#initialized.delete(focusable);
92
- restoreAttributes([focusable]);
92
+ restoreAttributes(focusable);
93
93
  });
94
94
  this.#focusables.clear();
95
95
  this.#focusablesByFirstChar.clear();
@@ -192,7 +192,7 @@ var RovingTabIndex = class _RovingTabIndex {
192
192
  for (const focusable of this.#focusables) {
193
193
  if (!current.has(focusable)) {
194
194
  _RovingTabIndex.#initialized.delete(focusable);
195
- restoreAttributes([focusable]);
195
+ restoreAttributes(focusable);
196
196
  this.#focusables.delete(focusable);
197
197
  for (const [key, focusables] of this.#focusablesByFirstChar) {
198
198
  const index = focusables.indexOf(focusable);
@@ -214,7 +214,7 @@ var RovingTabIndex = class _RovingTabIndex {
214
214
  this.#focusables.add(focusable);
215
215
  _RovingTabIndex.#initialized.add(focusable);
216
216
  if (!navigationOnly) {
217
- saveAttributes([focusable], ["tabindex"]);
217
+ saveAttributes(focusable, "tabindex");
218
218
  focusable.setAttribute("tabindex", "-1");
219
219
  }
220
220
  if (!typeahead) {
@@ -227,7 +227,7 @@ var RovingTabIndex = class _RovingTabIndex {
227
227
  );
228
228
  if (char) {
229
229
  keys.add(char);
230
- saveAttributes([focusable], ["aria-keyshortcuts"]);
230
+ saveAttributes(focusable, "aria-keyshortcuts");
231
231
  addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
232
232
  caseInsensitive: true
233
233
  });
@@ -268,7 +268,7 @@ var RovingTabIndex = class _RovingTabIndex {
268
268
  * Lightweight roving tabindex utility with fully focus management.
269
269
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
270
270
  *
271
- * @version 3.1.17
271
+ * @version 3.1.18
272
272
  * @author Yusuke Kamiyamane
273
273
  * @license MIT
274
274
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "3.1.17",
3
+ "version": "3.1.18",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -56,7 +56,7 @@
56
56
  "node": ">=18"
57
57
  },
58
58
  "dependencies": {
59
- "@y14e/attributes-utils": "^1.1.3",
60
- "power-focusable": "^4.3.20"
59
+ "@y14e/attributes-utils": "^1.1.4",
60
+ "power-focusable": "^4.3.21"
61
61
  }
62
62
  }