@y14e/roving-tabindex 1.1.4 → 1.2.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/dist/index.cjs CHANGED
@@ -10,10 +10,10 @@ function addTokenToAttribute(element, attribute, token) {
10
10
  }
11
11
  var snapshots = /* @__PURE__ */ new WeakMap();
12
12
  function restoreAttributes(elements) {
13
- elements.forEach((element) => {
13
+ for (const element of elements) {
14
14
  const snapshot = snapshots.get(element);
15
15
  if (!snapshot) {
16
- return;
16
+ continue;
17
17
  }
18
18
  for (const [attribute, value] of snapshot.entries()) {
19
19
  if (value === null) {
@@ -23,7 +23,7 @@ function restoreAttributes(elements) {
23
23
  }
24
24
  }
25
25
  snapshots.delete(element);
26
- });
26
+ }
27
27
  }
28
28
  function saveAttributes(elements, attributes) {
29
29
  elements.forEach((element) => {
@@ -45,14 +45,17 @@ function getFocusables(container = document.body, options = {}) {
45
45
  console.warn("Invalid container element. Fallback: <body> element.");
46
46
  container = document.body;
47
47
  }
48
- const { composed = false } = options;
49
- let { filter, include } = options;
50
- if (filter && typeof filter !== "function") {
51
- console.warn("Invalid filter function");
48
+ let { composed = false, filter, include } = options;
49
+ if (typeof composed !== "boolean") {
50
+ console.warn("Invalid composed. Fallback: false.");
51
+ composed = false;
52
+ }
53
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
54
+ console.warn("Invalid filter. Fallback: no filter function (undefined).");
52
55
  filter = void 0;
53
56
  }
54
- if (include && typeof include !== "function") {
55
- console.warn("Invalid include function");
57
+ if (typeof include !== "undefined" && typeof include !== "function") {
58
+ console.warn("Invalid include. Fallback: no include function (undefined).");
56
59
  include = void 0;
57
60
  }
58
61
  const elements = [];
@@ -324,7 +327,7 @@ var RovingTabIndex = class {
324
327
  ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
325
328
  ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
326
329
  ].includes(key)) {
327
- if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toLowerCase())) {
330
+ if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
328
331
  return;
329
332
  }
330
333
  }
@@ -363,7 +366,7 @@ var RovingTabIndex = class {
363
366
  if (!typeahead) {
364
367
  break;
365
368
  }
366
- target = this.#focusablesByFirstChar.get(key.toLowerCase()) ?? [];
369
+ target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
367
370
  const foundIndex = target.findIndex(
368
371
  (focusable2) => focusables.indexOf(focusable2) > currentIndex
369
372
  );
@@ -385,9 +388,9 @@ var RovingTabIndex = class {
385
388
  filter: this.#selectorFilter
386
389
  })
387
390
  ]);
388
- this.#focusables.forEach((focusable) => {
391
+ for (const focusable of this.#focusables) {
389
392
  if (current.has(focusable)) {
390
- return;
393
+ continue;
391
394
  }
392
395
  if (focusable.isConnected) {
393
396
  restoreAttributes([focusable]);
@@ -399,22 +402,22 @@ var RovingTabIndex = class {
399
402
  focusables.splice(index, 1);
400
403
  }
401
404
  });
402
- });
403
- current.forEach((c) => {
405
+ }
406
+ for (const c of current) {
404
407
  if (this.#focusables.has(c)) {
405
- return;
408
+ continue;
406
409
  }
407
410
  this.#focusables.add(c);
408
411
  saveAttributes([c], ["tabindex"]);
409
412
  c.setAttribute("tabindex", "-1");
410
413
  if (!this.#options.typeahead) {
411
- return;
414
+ continue;
412
415
  }
413
416
  const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
414
417
  const keys = new Set(
415
- shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toLowerCase()) : []
418
+ shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
416
419
  );
417
- const char = c.textContent?.trim()?.at(0)?.toLowerCase();
420
+ const char = c.textContent?.trim()?.at(0)?.toUpperCase();
418
421
  if (char) {
419
422
  keys.add(char);
420
423
  saveAttributes([c], ["aria-keyshortcuts"]);
@@ -425,7 +428,7 @@ var RovingTabIndex = class {
425
428
  focusables.push(c);
426
429
  this.#focusablesByFirstChar.set(key, focusables);
427
430
  });
428
- });
431
+ }
429
432
  if (active && this.#focusables.has(active)) {
430
433
  this.#focusables.forEach((focusable) => {
431
434
  focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
@@ -463,7 +466,7 @@ function getActiveElement() {
463
466
  * Lightweight roving tabindex utility with fully focus management.
464
467
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
465
468
  *
466
- * @version 1.1.4
469
+ * @version 1.2.1
467
470
  * @author Yusuke Kamiyamane
468
471
  * @license MIT
469
472
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -475,7 +478,7 @@ function getActiveElement() {
475
478
  (**
476
479
  * Attributes Utils
477
480
  *
478
- * @version 1.0.0
481
+ * @version 1.0.2
479
482
  * @author Yusuke Kamiyamane
480
483
  * @license MIT
481
484
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -488,7 +491,7 @@ power-focusable/dist/index.js:
488
491
  * High-precision focus management utility with full composed tree support.
489
492
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
490
493
  *
491
- * @version 4.1.5
494
+ * @version 4.1.7
492
495
  * @author Yusuke Kamiyamane
493
496
  * @license MIT
494
497
  * @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 1.1.4
6
+ * @version 1.2.1
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 1.1.4
6
+ * @version 1.2.1
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -8,10 +8,10 @@ function addTokenToAttribute(element, attribute, token) {
8
8
  }
9
9
  var snapshots = /* @__PURE__ */ new WeakMap();
10
10
  function restoreAttributes(elements) {
11
- elements.forEach((element) => {
11
+ for (const element of elements) {
12
12
  const snapshot = snapshots.get(element);
13
13
  if (!snapshot) {
14
- return;
14
+ continue;
15
15
  }
16
16
  for (const [attribute, value] of snapshot.entries()) {
17
17
  if (value === null) {
@@ -21,7 +21,7 @@ function restoreAttributes(elements) {
21
21
  }
22
22
  }
23
23
  snapshots.delete(element);
24
- });
24
+ }
25
25
  }
26
26
  function saveAttributes(elements, attributes) {
27
27
  elements.forEach((element) => {
@@ -43,14 +43,17 @@ function getFocusables(container = document.body, options = {}) {
43
43
  console.warn("Invalid container element. Fallback: <body> element.");
44
44
  container = document.body;
45
45
  }
46
- const { composed = false } = options;
47
- let { filter, include } = options;
48
- if (filter && typeof filter !== "function") {
49
- console.warn("Invalid filter function");
46
+ let { composed = false, filter, include } = options;
47
+ if (typeof composed !== "boolean") {
48
+ console.warn("Invalid composed. Fallback: false.");
49
+ composed = false;
50
+ }
51
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
52
+ console.warn("Invalid filter. Fallback: no filter function (undefined).");
50
53
  filter = void 0;
51
54
  }
52
- if (include && typeof include !== "function") {
53
- console.warn("Invalid include function");
55
+ if (typeof include !== "undefined" && typeof include !== "function") {
56
+ console.warn("Invalid include. Fallback: no include function (undefined).");
54
57
  include = void 0;
55
58
  }
56
59
  const elements = [];
@@ -322,7 +325,7 @@ var RovingTabIndex = class {
322
325
  ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
323
326
  ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
324
327
  ].includes(key)) {
325
- if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toLowerCase())) {
328
+ if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
326
329
  return;
327
330
  }
328
331
  }
@@ -361,7 +364,7 @@ var RovingTabIndex = class {
361
364
  if (!typeahead) {
362
365
  break;
363
366
  }
364
- target = this.#focusablesByFirstChar.get(key.toLowerCase()) ?? [];
367
+ target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
365
368
  const foundIndex = target.findIndex(
366
369
  (focusable2) => focusables.indexOf(focusable2) > currentIndex
367
370
  );
@@ -383,9 +386,9 @@ var RovingTabIndex = class {
383
386
  filter: this.#selectorFilter
384
387
  })
385
388
  ]);
386
- this.#focusables.forEach((focusable) => {
389
+ for (const focusable of this.#focusables) {
387
390
  if (current.has(focusable)) {
388
- return;
391
+ continue;
389
392
  }
390
393
  if (focusable.isConnected) {
391
394
  restoreAttributes([focusable]);
@@ -397,22 +400,22 @@ var RovingTabIndex = class {
397
400
  focusables.splice(index, 1);
398
401
  }
399
402
  });
400
- });
401
- current.forEach((c) => {
403
+ }
404
+ for (const c of current) {
402
405
  if (this.#focusables.has(c)) {
403
- return;
406
+ continue;
404
407
  }
405
408
  this.#focusables.add(c);
406
409
  saveAttributes([c], ["tabindex"]);
407
410
  c.setAttribute("tabindex", "-1");
408
411
  if (!this.#options.typeahead) {
409
- return;
412
+ continue;
410
413
  }
411
414
  const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
412
415
  const keys = new Set(
413
- shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toLowerCase()) : []
416
+ shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
414
417
  );
415
- const char = c.textContent?.trim()?.at(0)?.toLowerCase();
418
+ const char = c.textContent?.trim()?.at(0)?.toUpperCase();
416
419
  if (char) {
417
420
  keys.add(char);
418
421
  saveAttributes([c], ["aria-keyshortcuts"]);
@@ -423,7 +426,7 @@ var RovingTabIndex = class {
423
426
  focusables.push(c);
424
427
  this.#focusablesByFirstChar.set(key, focusables);
425
428
  });
426
- });
429
+ }
427
430
  if (active && this.#focusables.has(active)) {
428
431
  this.#focusables.forEach((focusable) => {
429
432
  focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
@@ -461,7 +464,7 @@ function getActiveElement() {
461
464
  * Lightweight roving tabindex utility with fully focus management.
462
465
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
463
466
  *
464
- * @version 1.1.4
467
+ * @version 1.2.1
465
468
  * @author Yusuke Kamiyamane
466
469
  * @license MIT
467
470
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -473,7 +476,7 @@ function getActiveElement() {
473
476
  (**
474
477
  * Attributes Utils
475
478
  *
476
- * @version 1.0.0
479
+ * @version 1.0.2
477
480
  * @author Yusuke Kamiyamane
478
481
  * @license MIT
479
482
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -486,7 +489,7 @@ power-focusable/dist/index.js:
486
489
  * High-precision focus management utility with full composed tree support.
487
490
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
488
491
  *
489
- * @version 4.1.5
492
+ * @version 4.1.7
490
493
  * @author Yusuke Kamiyamane
491
494
  * @license MIT
492
495
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -48,9 +48,9 @@
48
48
  },
49
49
  "homepage": "https://github.com/y14e/roving-tabindex#readme",
50
50
  "devDependencies": {
51
- "@y14e/attributes-utils": "^1.0.0",
51
+ "@y14e/attributes-utils": "^1.0.2",
52
52
  "bun-types": "latest",
53
- "power-focusable": "^4.1.5",
53
+ "power-focusable": "^4.1.7",
54
54
  "tsup": "^8.0.0",
55
55
  "typescript": "^5.6.0"
56
56
  },