@y14e/roving-tabindex 1.2.0 → 1.2.2

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,19 +1,30 @@
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) {
13
- elements.forEach((element) => {
24
+ for (const element of elements) {
14
25
  const snapshot = snapshots.get(element);
15
26
  if (!snapshot) {
16
- return;
27
+ continue;
17
28
  }
18
29
  for (const [attribute, value] of snapshot.entries()) {
19
30
  if (value === null) {
@@ -23,7 +34,7 @@ function restoreAttributes(elements) {
23
34
  }
24
35
  }
25
36
  snapshots.delete(element);
26
- });
37
+ }
27
38
  }
28
39
  function saveAttributes(elements, attributes) {
29
40
  elements.forEach((element) => {
@@ -388,9 +399,9 @@ var RovingTabIndex = class {
388
399
  filter: this.#selectorFilter
389
400
  })
390
401
  ]);
391
- this.#focusables.forEach((focusable) => {
402
+ for (const focusable of this.#focusables) {
392
403
  if (current.has(focusable)) {
393
- return;
404
+ continue;
394
405
  }
395
406
  if (focusable.isConnected) {
396
407
  restoreAttributes([focusable]);
@@ -402,16 +413,16 @@ var RovingTabIndex = class {
402
413
  focusables.splice(index, 1);
403
414
  }
404
415
  });
405
- });
406
- current.forEach((c) => {
416
+ }
417
+ for (const c of current) {
407
418
  if (this.#focusables.has(c)) {
408
- return;
419
+ continue;
409
420
  }
410
421
  this.#focusables.add(c);
411
422
  saveAttributes([c], ["tabindex"]);
412
423
  c.setAttribute("tabindex", "-1");
413
424
  if (!this.#options.typeahead) {
414
- return;
425
+ continue;
415
426
  }
416
427
  const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
417
428
  const keys = new Set(
@@ -421,14 +432,16 @@ var RovingTabIndex = class {
421
432
  if (char) {
422
433
  keys.add(char);
423
434
  saveAttributes([c], ["aria-keyshortcuts"]);
424
- addTokenToAttribute(c, "aria-keyshortcuts", char);
435
+ addTokenToAttribute(c, "aria-keyshortcuts", char, {
436
+ caseInsensitive: true
437
+ });
425
438
  }
426
439
  keys.forEach((key) => {
427
440
  const focusables = this.#focusablesByFirstChar.get(key) ?? [];
428
441
  focusables.push(c);
429
442
  this.#focusablesByFirstChar.set(key, focusables);
430
443
  });
431
- });
444
+ }
432
445
  if (active && this.#focusables.has(active)) {
433
446
  this.#focusables.forEach((focusable) => {
434
447
  focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
@@ -466,7 +479,7 @@ function getActiveElement() {
466
479
  * Lightweight roving tabindex utility with fully focus management.
467
480
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
468
481
  *
469
- * @version 1.2.0
482
+ * @version 1.2.2
470
483
  * @author Yusuke Kamiyamane
471
484
  * @license MIT
472
485
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -478,7 +491,7 @@ function getActiveElement() {
478
491
  (**
479
492
  * Attributes Utils
480
493
  *
481
- * @version 1.0.0
494
+ * @version 1.0.3
482
495
  * @author Yusuke Kamiyamane
483
496
  * @license MIT
484
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.2.0
6
+ * @version 1.2.2
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.0
6
+ * @version 1.2.2
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -1,17 +1,28 @@
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) {
11
- elements.forEach((element) => {
22
+ for (const element of elements) {
12
23
  const snapshot = snapshots.get(element);
13
24
  if (!snapshot) {
14
- return;
25
+ continue;
15
26
  }
16
27
  for (const [attribute, value] of snapshot.entries()) {
17
28
  if (value === null) {
@@ -21,7 +32,7 @@ function restoreAttributes(elements) {
21
32
  }
22
33
  }
23
34
  snapshots.delete(element);
24
- });
35
+ }
25
36
  }
26
37
  function saveAttributes(elements, attributes) {
27
38
  elements.forEach((element) => {
@@ -386,9 +397,9 @@ var RovingTabIndex = class {
386
397
  filter: this.#selectorFilter
387
398
  })
388
399
  ]);
389
- this.#focusables.forEach((focusable) => {
400
+ for (const focusable of this.#focusables) {
390
401
  if (current.has(focusable)) {
391
- return;
402
+ continue;
392
403
  }
393
404
  if (focusable.isConnected) {
394
405
  restoreAttributes([focusable]);
@@ -400,16 +411,16 @@ var RovingTabIndex = class {
400
411
  focusables.splice(index, 1);
401
412
  }
402
413
  });
403
- });
404
- current.forEach((c) => {
414
+ }
415
+ for (const c of current) {
405
416
  if (this.#focusables.has(c)) {
406
- return;
417
+ continue;
407
418
  }
408
419
  this.#focusables.add(c);
409
420
  saveAttributes([c], ["tabindex"]);
410
421
  c.setAttribute("tabindex", "-1");
411
422
  if (!this.#options.typeahead) {
412
- return;
423
+ continue;
413
424
  }
414
425
  const shortcuts = c.ariaKeyShortcuts?.trim() ?? "";
415
426
  const keys = new Set(
@@ -419,14 +430,16 @@ var RovingTabIndex = class {
419
430
  if (char) {
420
431
  keys.add(char);
421
432
  saveAttributes([c], ["aria-keyshortcuts"]);
422
- addTokenToAttribute(c, "aria-keyshortcuts", char);
433
+ addTokenToAttribute(c, "aria-keyshortcuts", char, {
434
+ caseInsensitive: true
435
+ });
423
436
  }
424
437
  keys.forEach((key) => {
425
438
  const focusables = this.#focusablesByFirstChar.get(key) ?? [];
426
439
  focusables.push(c);
427
440
  this.#focusablesByFirstChar.set(key, focusables);
428
441
  });
429
- });
442
+ }
430
443
  if (active && this.#focusables.has(active)) {
431
444
  this.#focusables.forEach((focusable) => {
432
445
  focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
@@ -464,7 +477,7 @@ function getActiveElement() {
464
477
  * Lightweight roving tabindex utility with fully focus management.
465
478
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
466
479
  *
467
- * @version 1.2.0
480
+ * @version 1.2.2
468
481
  * @author Yusuke Kamiyamane
469
482
  * @license MIT
470
483
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -476,7 +489,7 @@ function getActiveElement() {
476
489
  (**
477
490
  * Attributes Utils
478
491
  *
479
- * @version 1.0.0
492
+ * @version 1.0.3
480
493
  * @author Yusuke Kamiyamane
481
494
  * @license MIT
482
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.2.0",
3
+ "version": "1.2.2",
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.0",
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",