@y14e/roving-tabindex 3.1.18 → 3.1.19

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.18';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.19';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.18/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.19/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.18';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.19';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -457,20 +457,20 @@ var RovingTabIndex = class _RovingTabIndex {
457
457
  return;
458
458
  }
459
459
  }
460
+ const candidates = this.#getFocusables().filter(
461
+ (focusable2) => this.#focusables.has(focusable2)
462
+ );
460
463
  const active = getActiveElement();
461
464
  if (!(active instanceof Element)) {
462
465
  return;
463
466
  }
464
- const candidates = this.#getFocusables().filter(
465
- (focusable2) => this.#focusables.has(focusable2)
466
- );
467
467
  if (!candidates.includes(active)) {
468
468
  return;
469
469
  }
470
470
  event.preventDefault();
471
- const activeIndex = candidates.indexOf(active);
472
471
  let newIndex;
473
- let target = candidates;
472
+ const activeIndex = candidates.indexOf(active);
473
+ let focusables = candidates;
474
474
  switch (key) {
475
475
  case "End":
476
476
  newIndex = -1;
@@ -487,22 +487,24 @@ var RovingTabIndex = class _RovingTabIndex {
487
487
  case "ArrowRight":
488
488
  case "ArrowDown": {
489
489
  const rawIndex = activeIndex + 1;
490
- const length = target.length;
490
+ const length = focusables.length;
491
491
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
492
492
  break;
493
493
  }
494
494
  default: {
495
- const focusables = new Set(
495
+ const focusablesByFirstChar = new Set(
496
496
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
497
497
  );
498
- target = candidates.filter((focusable2) => focusables.has(focusable2));
499
- const afterIndex = target.findIndex(
498
+ focusables = candidates.filter(
499
+ (candidate) => focusablesByFirstChar.has(candidate)
500
+ );
501
+ const afterIndex = focusables.findIndex(
500
502
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
501
503
  );
502
504
  newIndex = afterIndex >= 0 ? afterIndex : 0;
503
505
  }
504
506
  }
505
- const focusable = target.at(newIndex);
507
+ const focusable = focusables.at(newIndex);
506
508
  focusable && focusElement(focusable);
507
509
  };
508
510
  #update(active) {
@@ -586,7 +588,7 @@ var RovingTabIndex = class _RovingTabIndex {
586
588
  * Lightweight roving tabindex utility with fully focus management.
587
589
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
588
590
  *
589
- * @version 3.1.18
591
+ * @version 3.1.19
590
592
  * @author Yusuke Kamiyamane
591
593
  * @license MIT
592
594
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -455,20 +455,20 @@ var RovingTabIndex = class _RovingTabIndex {
455
455
  return;
456
456
  }
457
457
  }
458
+ const candidates = this.#getFocusables().filter(
459
+ (focusable2) => this.#focusables.has(focusable2)
460
+ );
458
461
  const active = getActiveElement();
459
462
  if (!(active instanceof Element)) {
460
463
  return;
461
464
  }
462
- const candidates = this.#getFocusables().filter(
463
- (focusable2) => this.#focusables.has(focusable2)
464
- );
465
465
  if (!candidates.includes(active)) {
466
466
  return;
467
467
  }
468
468
  event.preventDefault();
469
- const activeIndex = candidates.indexOf(active);
470
469
  let newIndex;
471
- let target = candidates;
470
+ const activeIndex = candidates.indexOf(active);
471
+ let focusables = candidates;
472
472
  switch (key) {
473
473
  case "End":
474
474
  newIndex = -1;
@@ -485,22 +485,24 @@ var RovingTabIndex = class _RovingTabIndex {
485
485
  case "ArrowRight":
486
486
  case "ArrowDown": {
487
487
  const rawIndex = activeIndex + 1;
488
- const length = target.length;
488
+ const length = focusables.length;
489
489
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
490
490
  break;
491
491
  }
492
492
  default: {
493
- const focusables = new Set(
493
+ const focusablesByFirstChar = new Set(
494
494
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
495
495
  );
496
- target = candidates.filter((focusable2) => focusables.has(focusable2));
497
- const afterIndex = target.findIndex(
496
+ focusables = candidates.filter(
497
+ (candidate) => focusablesByFirstChar.has(candidate)
498
+ );
499
+ const afterIndex = focusables.findIndex(
498
500
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
499
501
  );
500
502
  newIndex = afterIndex >= 0 ? afterIndex : 0;
501
503
  }
502
504
  }
503
- const focusable = target.at(newIndex);
505
+ const focusable = focusables.at(newIndex);
504
506
  focusable && focusElement(focusable);
505
507
  };
506
508
  #update(active) {
@@ -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.18
589
+ * @version 3.1.19
588
590
  * @author Yusuke Kamiyamane
589
591
  * @license MIT
590
592
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -141,20 +141,20 @@ var RovingTabIndex = class _RovingTabIndex {
141
141
  return;
142
142
  }
143
143
  }
144
+ const candidates = this.#getFocusables().filter(
145
+ (focusable2) => this.#focusables.has(focusable2)
146
+ );
144
147
  const active = powerFocusable.getActiveElement();
145
148
  if (!(active instanceof Element)) {
146
149
  return;
147
150
  }
148
- const candidates = this.#getFocusables().filter(
149
- (focusable2) => this.#focusables.has(focusable2)
150
- );
151
151
  if (!candidates.includes(active)) {
152
152
  return;
153
153
  }
154
154
  event.preventDefault();
155
- const activeIndex = candidates.indexOf(active);
156
155
  let newIndex;
157
- let target = candidates;
156
+ const activeIndex = candidates.indexOf(active);
157
+ let focusables = candidates;
158
158
  switch (key) {
159
159
  case "End":
160
160
  newIndex = -1;
@@ -171,22 +171,24 @@ var RovingTabIndex = class _RovingTabIndex {
171
171
  case "ArrowRight":
172
172
  case "ArrowDown": {
173
173
  const rawIndex = activeIndex + 1;
174
- const length = target.length;
174
+ const length = focusables.length;
175
175
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
176
176
  break;
177
177
  }
178
178
  default: {
179
- const focusables = new Set(
179
+ const focusablesByFirstChar = new Set(
180
180
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
181
181
  );
182
- target = candidates.filter((focusable2) => focusables.has(focusable2));
183
- const afterIndex = target.findIndex(
182
+ focusables = candidates.filter(
183
+ (candidate) => focusablesByFirstChar.has(candidate)
184
+ );
185
+ const afterIndex = focusables.findIndex(
184
186
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
185
187
  );
186
188
  newIndex = afterIndex >= 0 ? afterIndex : 0;
187
189
  }
188
190
  }
189
- const focusable = target.at(newIndex);
191
+ const focusable = focusables.at(newIndex);
190
192
  focusable && powerFocusable.focusElement(focusable);
191
193
  };
192
194
  #update(active) {
@@ -270,7 +272,7 @@ var RovingTabIndex = class _RovingTabIndex {
270
272
  * Lightweight roving tabindex utility with fully focus management.
271
273
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
272
274
  *
273
- * @version 3.1.18
275
+ * @version 3.1.19
274
276
  * @author Yusuke Kamiyamane
275
277
  * @license MIT
276
278
  * @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.18
6
+ * @version 3.1.19
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.18
6
+ * @version 3.1.19
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -139,20 +139,20 @@ var RovingTabIndex = class _RovingTabIndex {
139
139
  return;
140
140
  }
141
141
  }
142
+ const candidates = this.#getFocusables().filter(
143
+ (focusable2) => this.#focusables.has(focusable2)
144
+ );
142
145
  const active = getActiveElement();
143
146
  if (!(active instanceof Element)) {
144
147
  return;
145
148
  }
146
- const candidates = this.#getFocusables().filter(
147
- (focusable2) => this.#focusables.has(focusable2)
148
- );
149
149
  if (!candidates.includes(active)) {
150
150
  return;
151
151
  }
152
152
  event.preventDefault();
153
- const activeIndex = candidates.indexOf(active);
154
153
  let newIndex;
155
- let target = candidates;
154
+ const activeIndex = candidates.indexOf(active);
155
+ let focusables = candidates;
156
156
  switch (key) {
157
157
  case "End":
158
158
  newIndex = -1;
@@ -169,22 +169,24 @@ var RovingTabIndex = class _RovingTabIndex {
169
169
  case "ArrowRight":
170
170
  case "ArrowDown": {
171
171
  const rawIndex = activeIndex + 1;
172
- const length = target.length;
172
+ const length = focusables.length;
173
173
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
174
174
  break;
175
175
  }
176
176
  default: {
177
- const focusables = new Set(
177
+ const focusablesByFirstChar = new Set(
178
178
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
179
179
  );
180
- target = candidates.filter((focusable2) => focusables.has(focusable2));
181
- const afterIndex = target.findIndex(
180
+ focusables = candidates.filter(
181
+ (candidate) => focusablesByFirstChar.has(candidate)
182
+ );
183
+ const afterIndex = focusables.findIndex(
182
184
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
183
185
  );
184
186
  newIndex = afterIndex >= 0 ? afterIndex : 0;
185
187
  }
186
188
  }
187
- const focusable = target.at(newIndex);
189
+ const focusable = focusables.at(newIndex);
188
190
  focusable && focusElement(focusable);
189
191
  };
190
192
  #update(active) {
@@ -268,7 +270,7 @@ var RovingTabIndex = class _RovingTabIndex {
268
270
  * Lightweight roving tabindex utility with fully focus management.
269
271
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
270
272
  *
271
- * @version 3.1.18
273
+ * @version 3.1.19
272
274
  * @author Yusuke Kamiyamane
273
275
  * @license MIT
274
276
  * @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.18",
3
+ "version": "3.1.19",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",