@y14e/roving-tabindex 3.0.7 → 3.0.9

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
@@ -10,14 +10,14 @@ npm i @y14e/roving-tabindex
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.7';
13
+ import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.9';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.7';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.9';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.7/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.9/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.7';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.9';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -253,6 +253,16 @@ function getComposedChildren(node) {
253
253
  }
254
254
  return getChildren(node);
255
255
  }
256
+ function focusElement(element) {
257
+ "focus" in element && typeof element.focus === "function" && element.focus();
258
+ }
259
+ function getActiveElement() {
260
+ let current = document.activeElement;
261
+ while (current?.shadowRoot?.activeElement) {
262
+ current = current.shadowRoot.activeElement;
263
+ }
264
+ return current;
265
+ }
256
266
  function getChildren(node) {
257
267
  const elements = [];
258
268
  for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
@@ -287,6 +297,7 @@ function createRovingTabIndex(container, options = {}) {
287
297
  const roving = new RovingTabIndex(container, options);
288
298
  return () => roving.destroy();
289
299
  }
300
+ var initialized = /* @__PURE__ */ new Set();
290
301
  var RovingTabIndex = class {
291
302
  #container;
292
303
  #settings;
@@ -362,13 +373,16 @@ var RovingTabIndex = class {
362
373
  }
363
374
  #initialize() {
364
375
  this.#update(document.activeElement);
376
+ if (!(this.#container instanceof HTMLElement)) {
377
+ return;
378
+ }
365
379
  this.#controller = new AbortController();
366
380
  const { signal } = this.#controller;
367
- document.addEventListener("focusin", this.#onFocusIn, {
381
+ this.#container.addEventListener("focusin", this.#onFocusIn, {
368
382
  capture: true,
369
383
  signal
370
384
  });
371
- document.addEventListener("keydown", this.#onKeyDown, {
385
+ this.#container.addEventListener("keydown", this.#onKeyDown, {
372
386
  capture: true,
373
387
  signal
374
388
  });
@@ -383,9 +397,6 @@ var RovingTabIndex = class {
383
397
  this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
384
398
  };
385
399
  #onKeyDown = (event) => {
386
- if (!event.composedPath().includes(this.#container)) {
387
- return;
388
- }
389
400
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
390
401
  if (altKey || ctrlKey || metaKey || shiftKey) {
391
402
  return;
@@ -459,10 +470,14 @@ var RovingTabIndex = class {
459
470
  }
460
471
  const { navigationOnly, noStart, typeahead } = this.#settings;
461
472
  for (const focusable of current) {
473
+ if (initialized.has(focusable)) {
474
+ throw new TypeError("Already initialized");
475
+ }
462
476
  if (this.#focusables.has(focusable)) {
463
477
  continue;
464
478
  }
465
479
  this.#focusables.add(focusable);
480
+ initialized.add(focusable);
466
481
  if (!navigationOnly) {
467
482
  saveAttributes([focusable], ["tabindex"]);
468
483
  focusable.setAttribute("tabindex", "-1");
@@ -513,22 +528,12 @@ var RovingTabIndex = class {
513
528
  });
514
529
  }
515
530
  };
516
- function focusElement(element) {
517
- "focus" in element && typeof element.focus === "function" && element.focus();
518
- }
519
- function getActiveElement() {
520
- let current = document.activeElement;
521
- while (current?.shadowRoot?.activeElement) {
522
- current = current.shadowRoot.activeElement;
523
- }
524
- return current;
525
- }
526
531
  /**
527
532
  * Roving Tabindex
528
533
  * Lightweight roving tabindex utility with fully focus management.
529
534
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
530
535
  *
531
- * @version 3.0.7
536
+ * @version 3.0.9
532
537
  * @author Yusuke Kamiyamane
533
538
  * @license MIT
534
539
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -563,6 +568,8 @@ power-focusable/dist/index.js:
563
568
 
564
569
  exports.addTokenToAttribute = addTokenToAttribute;
565
570
  exports.createRovingTabIndex = createRovingTabIndex;
571
+ exports.focusElement = focusElement;
572
+ exports.getActiveElement = getActiveElement;
566
573
  exports.getFocusables = getFocusables;
567
574
  exports.restoreAttributes = restoreAttributes;
568
575
  exports.saveAttributes = saveAttributes;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { addTokenToAttribute, restoreAttributes, saveAttributes } from '@y14e/attributes-utils';
2
- export { getFocusables } from 'power-focusable';
2
+ export { focusElement, getActiveElement, getFocusables } from 'power-focusable';
3
3
 
4
4
  /**
5
5
  * Roving Tabindex
6
6
  * Lightweight roving tabindex utility with fully focus management.
7
7
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
8
8
  *
9
- * @version 3.0.7
9
+ * @version 3.0.9
10
10
  * @author Yusuke Kamiyamane
11
11
  * @license MIT
12
12
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { addTokenToAttribute, restoreAttributes, saveAttributes } from '@y14e/attributes-utils';
2
- export { getFocusables } from 'power-focusable';
2
+ export { focusElement, getActiveElement, getFocusables } from 'power-focusable';
3
3
 
4
4
  /**
5
5
  * Roving Tabindex
6
6
  * Lightweight roving tabindex utility with fully focus management.
7
7
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
8
8
  *
9
- * @version 3.0.7
9
+ * @version 3.0.9
10
10
  * @author Yusuke Kamiyamane
11
11
  * @license MIT
12
12
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -251,6 +251,16 @@ function getComposedChildren(node) {
251
251
  }
252
252
  return getChildren(node);
253
253
  }
254
+ function focusElement(element) {
255
+ "focus" in element && typeof element.focus === "function" && element.focus();
256
+ }
257
+ function getActiveElement() {
258
+ let current = document.activeElement;
259
+ while (current?.shadowRoot?.activeElement) {
260
+ current = current.shadowRoot.activeElement;
261
+ }
262
+ return current;
263
+ }
254
264
  function getChildren(node) {
255
265
  const elements = [];
256
266
  for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
@@ -285,6 +295,7 @@ function createRovingTabIndex(container, options = {}) {
285
295
  const roving = new RovingTabIndex(container, options);
286
296
  return () => roving.destroy();
287
297
  }
298
+ var initialized = /* @__PURE__ */ new Set();
288
299
  var RovingTabIndex = class {
289
300
  #container;
290
301
  #settings;
@@ -360,13 +371,16 @@ var RovingTabIndex = class {
360
371
  }
361
372
  #initialize() {
362
373
  this.#update(document.activeElement);
374
+ if (!(this.#container instanceof HTMLElement)) {
375
+ return;
376
+ }
363
377
  this.#controller = new AbortController();
364
378
  const { signal } = this.#controller;
365
- document.addEventListener("focusin", this.#onFocusIn, {
379
+ this.#container.addEventListener("focusin", this.#onFocusIn, {
366
380
  capture: true,
367
381
  signal
368
382
  });
369
- document.addEventListener("keydown", this.#onKeyDown, {
383
+ this.#container.addEventListener("keydown", this.#onKeyDown, {
370
384
  capture: true,
371
385
  signal
372
386
  });
@@ -381,9 +395,6 @@ var RovingTabIndex = class {
381
395
  this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
382
396
  };
383
397
  #onKeyDown = (event) => {
384
- if (!event.composedPath().includes(this.#container)) {
385
- return;
386
- }
387
398
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
388
399
  if (altKey || ctrlKey || metaKey || shiftKey) {
389
400
  return;
@@ -457,10 +468,14 @@ var RovingTabIndex = class {
457
468
  }
458
469
  const { navigationOnly, noStart, typeahead } = this.#settings;
459
470
  for (const focusable of current) {
471
+ if (initialized.has(focusable)) {
472
+ throw new TypeError("Already initialized");
473
+ }
460
474
  if (this.#focusables.has(focusable)) {
461
475
  continue;
462
476
  }
463
477
  this.#focusables.add(focusable);
478
+ initialized.add(focusable);
464
479
  if (!navigationOnly) {
465
480
  saveAttributes([focusable], ["tabindex"]);
466
481
  focusable.setAttribute("tabindex", "-1");
@@ -511,22 +526,12 @@ var RovingTabIndex = class {
511
526
  });
512
527
  }
513
528
  };
514
- function focusElement(element) {
515
- "focus" in element && typeof element.focus === "function" && element.focus();
516
- }
517
- function getActiveElement() {
518
- let current = document.activeElement;
519
- while (current?.shadowRoot?.activeElement) {
520
- current = current.shadowRoot.activeElement;
521
- }
522
- return current;
523
- }
524
529
  /**
525
530
  * Roving Tabindex
526
531
  * Lightweight roving tabindex utility with fully focus management.
527
532
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
528
533
  *
529
- * @version 3.0.7
534
+ * @version 3.0.9
530
535
  * @author Yusuke Kamiyamane
531
536
  * @license MIT
532
537
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -559,4 +564,4 @@ power-focusable/dist/index.js:
559
564
  *)
560
565
  */
561
566
 
562
- export { addTokenToAttribute, createRovingTabIndex, getFocusables, restoreAttributes, saveAttributes };
567
+ export { addTokenToAttribute, createRovingTabIndex, focusElement, getActiveElement, getFocusables, restoreAttributes, saveAttributes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -50,7 +50,7 @@
50
50
  "devDependencies": {
51
51
  "@y14e/attributes-utils": "^1.1.2",
52
52
  "bun-types": "latest",
53
- "power-focusable": "^4.3.3",
53
+ "power-focusable": "^4.3.4",
54
54
  "tsup": "^8.0.0",
55
55
  "typescript": "^5.6.0"
56
56
  },