power-focusable 4.1.0 → 4.1.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/README.md CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  // CDNs
27
27
  import { ... } 'https://esm.sh/power-focusable'
28
28
  // or
29
- import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable/dist/index.js';
29
+ import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable/+esm';
30
30
  // or
31
31
  import { ... } 'https://unpkg.com/power-focusable/dist/index.js';
32
32
  ```
@@ -35,11 +35,11 @@ import { ... } 'https://unpkg.com/power-focusable/dist/index.js';
35
35
 
36
36
  ```ts
37
37
  interface PowerFocusableOptions {
38
- anchor?: Element | null; // default: document.activeElement
39
- composed?: boolean; // default: false
40
- filter?: (element: Element) => boolean; // default: () => true
41
- include?: (element: Element) => boolean; // default: undefined
42
- wrap?: boolean; // default: false
38
+ anchor?: Element | null; // default: document.activeElement
39
+ composed?: boolean; // default: false
40
+ filter?: ((element: Element) => boolean) | undefined;
41
+ include?: ((element: Element) => boolean) | undefined;
42
+ wrap?: boolean; // default: false
43
43
  }
44
44
  ```
45
45
 
package/dist/index.cjs CHANGED
@@ -44,9 +44,18 @@ function getFocusables(container = document.body, options = {}) {
44
44
  console.warn("Invalid container element. Fallback: <body> element.");
45
45
  container = document.body;
46
46
  }
47
- const { composed = false, filter = () => true, include } = options;
47
+ const { composed = false } = options;
48
+ let { filter, include } = options;
49
+ if (filter && typeof filter !== "function") {
50
+ console.warn("Invalid filter function. Fallback: undefined.");
51
+ filter = void 0;
52
+ }
53
+ if (include && typeof include !== "function") {
54
+ console.warn("Invalid include function. Fallback: undefined.");
55
+ include = void 0;
56
+ }
48
57
  const elements = [];
49
- if (composed || typeof include === "function") {
58
+ if (composed || include) {
50
59
  let traverse2 = function(node) {
51
60
  if (node instanceof Element) {
52
61
  if (isFocusable(node) || include?.(node)) {
@@ -75,7 +84,8 @@ function getFocusables(container = document.body, options = {}) {
75
84
  }
76
85
  }
77
86
  }
78
- return normalizeRadioGroup(sortByTabIndex(elements)).filter(filter);
87
+ const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
88
+ return filter ? unfiltered.filter(filter) : unfiltered;
79
89
  }
80
90
  function getNextFocusable(container = document.body, options = {}) {
81
91
  if (!(container instanceof Element)) {
@@ -157,7 +167,7 @@ function getRelativeFocusable(container, offset, options) {
157
167
  const {
158
168
  anchor = getActiveElement(),
159
169
  composed = false,
160
- filter = () => true,
170
+ filter,
161
171
  include,
162
172
  wrap = false
163
173
  } = options;
@@ -398,7 +408,7 @@ function isUngroupedRadio(element) {
398
408
  * High-precision focus management utility with full composed tree support.
399
409
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
400
410
  *
401
- * @version 4.1.0
411
+ * @version 4.1.2
402
412
  * @author Yusuke Kamiyamane
403
413
  * @license MIT
404
414
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-precision focus management utility with full composed tree support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
5
5
  *
6
- * @version 4.1.0
6
+ * @version 4.1.2
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -12,7 +12,7 @@
12
12
  interface PowerFocusableOptions {
13
13
  readonly anchor?: Element | null;
14
14
  readonly composed?: boolean;
15
- readonly filter?: (element: Element) => boolean;
15
+ readonly filter?: ((element: Element) => boolean) | undefined;
16
16
  readonly include?: ((element: Element) => boolean) | undefined;
17
17
  readonly wrap?: boolean;
18
18
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-precision focus management utility with full composed tree support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
5
5
  *
6
- * @version 4.1.0
6
+ * @version 4.1.2
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -12,7 +12,7 @@
12
12
  interface PowerFocusableOptions {
13
13
  readonly anchor?: Element | null;
14
14
  readonly composed?: boolean;
15
- readonly filter?: (element: Element) => boolean;
15
+ readonly filter?: ((element: Element) => boolean) | undefined;
16
16
  readonly include?: ((element: Element) => boolean) | undefined;
17
17
  readonly wrap?: boolean;
18
18
  }
package/dist/index.js CHANGED
@@ -42,9 +42,18 @@ function getFocusables(container = document.body, options = {}) {
42
42
  console.warn("Invalid container element. Fallback: <body> element.");
43
43
  container = document.body;
44
44
  }
45
- const { composed = false, filter = () => true, include } = options;
45
+ const { composed = false } = options;
46
+ let { filter, include } = options;
47
+ if (filter && typeof filter !== "function") {
48
+ console.warn("Invalid filter function. Fallback: undefined.");
49
+ filter = void 0;
50
+ }
51
+ if (include && typeof include !== "function") {
52
+ console.warn("Invalid include function. Fallback: undefined.");
53
+ include = void 0;
54
+ }
46
55
  const elements = [];
47
- if (composed || typeof include === "function") {
56
+ if (composed || include) {
48
57
  let traverse2 = function(node) {
49
58
  if (node instanceof Element) {
50
59
  if (isFocusable(node) || include?.(node)) {
@@ -73,7 +82,8 @@ function getFocusables(container = document.body, options = {}) {
73
82
  }
74
83
  }
75
84
  }
76
- return normalizeRadioGroup(sortByTabIndex(elements)).filter(filter);
85
+ const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
86
+ return filter ? unfiltered.filter(filter) : unfiltered;
77
87
  }
78
88
  function getNextFocusable(container = document.body, options = {}) {
79
89
  if (!(container instanceof Element)) {
@@ -155,7 +165,7 @@ function getRelativeFocusable(container, offset, options) {
155
165
  const {
156
166
  anchor = getActiveElement(),
157
167
  composed = false,
158
- filter = () => true,
168
+ filter,
159
169
  include,
160
170
  wrap = false
161
171
  } = options;
@@ -396,7 +406,7 @@ function isUngroupedRadio(element) {
396
406
  * High-precision focus management utility with full composed tree support.
397
407
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
398
408
  *
399
- * @version 4.1.0
409
+ * @version 4.1.2
400
410
  * @author Yusuke Kamiyamane
401
411
  * @license MIT
402
412
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "High-precision focus management utility with full composed tree support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",