@y14e/roving-tabindex 1.2.1 → 1.2.3

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
@@ -1,12 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  // node_modules/@y14e/attributes-utils/dist/index.js
4
- function addTokenToAttribute(element, attribute, token) {
5
- const tokens = new Set(
6
- element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
7
- );
8
- tokens.add(token);
9
- element.setAttribute(attribute, [...tokens].join(" "));
4
+ function addTokenToAttribute(element, attribute, token, options = {}) {
5
+ const { caseInsensitive = false } = options;
6
+ const value = element.getAttribute(attribute)?.trim();
7
+ const tokens = value ? value.split(/\s+/) : [];
8
+ if (caseInsensitive) {
9
+ const lower = token.toLowerCase();
10
+ if (tokens.some((token2) => token2.toLowerCase() === lower)) {
11
+ return;
12
+ }
13
+ tokens.push(token);
14
+ element.setAttribute(attribute, tokens.join(" "));
15
+ return;
16
+ }
17
+ const set = new Set(tokens);
18
+ set.add(token);
19
+ element.setAttribute(attribute, [...set].join(" "));
20
+ return;
10
21
  }
11
22
  var snapshots = /* @__PURE__ */ new WeakMap();
12
23
  function restoreAttributes(elements) {
@@ -326,10 +337,8 @@ var RovingTabIndex = class {
326
337
  "Home",
327
338
  ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
328
339
  ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
329
- ].includes(key)) {
330
- if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
331
- return;
332
- }
340
+ ].includes(key) && (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase()))) {
341
+ return;
333
342
  }
334
343
  const active = getActiveElement();
335
344
  if (!(active instanceof HTMLElement)) {
@@ -413,15 +422,17 @@ var RovingTabIndex = class {
413
422
  if (!this.#options.typeahead) {
414
423
  continue;
415
424
  }
416
- const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
425
+ const value = c.ariaKeyShortcuts?.trim();
417
426
  const keys = new Set(
418
- shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
427
+ value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
419
428
  );
420
429
  const char = c.textContent?.trim()?.at(0)?.toUpperCase();
421
430
  if (char) {
422
431
  keys.add(char);
423
432
  saveAttributes([c], ["aria-keyshortcuts"]);
424
- addTokenToAttribute(c, "aria-keyshortcuts", char);
433
+ addTokenToAttribute(c, "aria-keyshortcuts", char, {
434
+ caseInsensitive: true
435
+ });
425
436
  }
426
437
  keys.forEach((key) => {
427
438
  const focusables = this.#focusablesByFirstChar.get(key) ?? [];
@@ -466,7 +477,7 @@ function getActiveElement() {
466
477
  * Lightweight roving tabindex utility with fully focus management.
467
478
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
468
479
  *
469
- * @version 1.2.1
480
+ * @version 1.2.3
470
481
  * @author Yusuke Kamiyamane
471
482
  * @license MIT
472
483
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -478,7 +489,7 @@ function getActiveElement() {
478
489
  (**
479
490
  * Attributes Utils
480
491
  *
481
- * @version 1.0.2
492
+ * @version 1.0.3
482
493
  * @author Yusuke Kamiyamane
483
494
  * @license MIT
484
495
  * @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.2.1
6
+ * @version 1.2.3
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.2.1
6
+ * @version 1.2.3
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -1,10 +1,21 @@
1
1
  // node_modules/@y14e/attributes-utils/dist/index.js
2
- function addTokenToAttribute(element, attribute, token) {
3
- const tokens = new Set(
4
- element.getAttribute(attribute)?.trim().split(/\s+/) ?? []
5
- );
6
- tokens.add(token);
7
- element.setAttribute(attribute, [...tokens].join(" "));
2
+ function addTokenToAttribute(element, attribute, token, options = {}) {
3
+ const { caseInsensitive = false } = options;
4
+ const value = element.getAttribute(attribute)?.trim();
5
+ const tokens = value ? value.split(/\s+/) : [];
6
+ if (caseInsensitive) {
7
+ const lower = token.toLowerCase();
8
+ if (tokens.some((token2) => token2.toLowerCase() === lower)) {
9
+ return;
10
+ }
11
+ tokens.push(token);
12
+ element.setAttribute(attribute, tokens.join(" "));
13
+ return;
14
+ }
15
+ const set = new Set(tokens);
16
+ set.add(token);
17
+ element.setAttribute(attribute, [...set].join(" "));
18
+ return;
8
19
  }
9
20
  var snapshots = /* @__PURE__ */ new WeakMap();
10
21
  function restoreAttributes(elements) {
@@ -324,10 +335,8 @@ var RovingTabIndex = class {
324
335
  "Home",
325
336
  ...isBoth ? ["ArrowLeft", "ArrowUp"] : [`Arrow${isHorizontal ? "Left" : "Up"}`],
326
337
  ...isBoth ? ["ArrowRight", "ArrowDown"] : [`Arrow${isHorizontal ? "Right" : "Down"}`]
327
- ].includes(key)) {
328
- if (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase())) {
329
- return;
330
- }
338
+ ].includes(key) && (!typeahead || !/^\S$/i.test(key) || !this.#focusablesByFirstChar.has(key.toUpperCase()))) {
339
+ return;
331
340
  }
332
341
  const active = getActiveElement();
333
342
  if (!(active instanceof HTMLElement)) {
@@ -411,15 +420,17 @@ var RovingTabIndex = class {
411
420
  if (!this.#options.typeahead) {
412
421
  continue;
413
422
  }
414
- const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
423
+ const value = c.ariaKeyShortcuts?.trim();
415
424
  const keys = new Set(
416
- shortcuts ? shortcuts.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
425
+ value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
417
426
  );
418
427
  const char = c.textContent?.trim()?.at(0)?.toUpperCase();
419
428
  if (char) {
420
429
  keys.add(char);
421
430
  saveAttributes([c], ["aria-keyshortcuts"]);
422
- addTokenToAttribute(c, "aria-keyshortcuts", char);
431
+ addTokenToAttribute(c, "aria-keyshortcuts", char, {
432
+ caseInsensitive: true
433
+ });
423
434
  }
424
435
  keys.forEach((key) => {
425
436
  const focusables = this.#focusablesByFirstChar.get(key) ?? [];
@@ -464,7 +475,7 @@ function getActiveElement() {
464
475
  * Lightweight roving tabindex utility with fully focus management.
465
476
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
466
477
  *
467
- * @version 1.2.1
478
+ * @version 1.2.3
468
479
  * @author Yusuke Kamiyamane
469
480
  * @license MIT
470
481
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -476,7 +487,7 @@ function getActiveElement() {
476
487
  (**
477
488
  * Attributes Utils
478
489
  *
479
- * @version 1.0.2
490
+ * @version 1.0.3
480
491
  * @author Yusuke Kamiyamane
481
492
  * @license MIT
482
493
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "homepage": "https://github.com/y14e/roving-tabindex#readme",
50
50
  "devDependencies": {
51
- "@y14e/attributes-utils": "^1.0.2",
51
+ "@y14e/attributes-utils": "^1.0.3",
52
52
  "bun-types": "latest",
53
53
  "power-focusable": "^4.1.7",
54
54
  "tsup": "^8.0.0",