power-focusable 4.1.2 → 4.1.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/README.md CHANGED
@@ -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) | undefined;
41
- include?: ((element: Element) => boolean) | undefined;
42
- wrap?: boolean; // default: false
38
+ anchor?: Element | null; // default: active element
39
+ composed?: boolean; // default: false
40
+ filter?: (element: Element) => boolean;
41
+ include?: (element: Element) => boolean;
42
+ wrap?: boolean; // default: false
43
43
  }
44
44
  ```
45
45
 
package/dist/index.cjs CHANGED
@@ -164,22 +164,25 @@ function isFocusable(element) {
164
164
  return true;
165
165
  }
166
166
  function getRelativeFocusable(container, offset, options) {
167
- const {
168
- anchor = getActiveElement(),
169
- composed = false,
170
- filter,
171
- include,
172
- wrap = false
173
- } = options;
174
- const focusables = getFocusables(container, { composed, filter, include });
175
- const { length } = focusables;
176
- if (!length) {
177
- return null;
167
+ let anchor = options.anchor ?? getActiveElement();
168
+ const { composed = false, filter, include, wrap = false } = options;
169
+ if (!(anchor instanceof Element)) {
170
+ const active = getActiveElement();
171
+ if (active instanceof Element) {
172
+ console.warn("Invalid anchor element. Fallback: active element.");
173
+ anchor = active;
174
+ } else {
175
+ console.warn("Invalid anchor element");
176
+ return null;
177
+ }
178
178
  }
179
- if (!anchor || !containsComposed(container, anchor)) {
179
+ if (!containsComposed(container, anchor)) {
180
+ console.warn("Mismatch elements");
180
181
  return null;
181
182
  }
182
- if (!(anchor instanceof Element)) {
183
+ const focusables = getFocusables(container, { composed, filter, include });
184
+ const { length } = focusables;
185
+ if (!length) {
183
186
  return null;
184
187
  }
185
188
  const currentIndex = focusables.indexOf(anchor);
@@ -408,7 +411,7 @@ function isUngroupedRadio(element) {
408
411
  * High-precision focus management utility with full composed tree support.
409
412
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
410
413
  *
411
- * @version 4.1.2
414
+ * @version 4.1.3
412
415
  * @author Yusuke Kamiyamane
413
416
  * @license MIT
414
417
  * @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.2
6
+ * @version 4.1.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
  * 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.2
6
+ * @version 4.1.3
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -162,22 +162,25 @@ function isFocusable(element) {
162
162
  return true;
163
163
  }
164
164
  function getRelativeFocusable(container, offset, options) {
165
- const {
166
- anchor = getActiveElement(),
167
- composed = false,
168
- filter,
169
- include,
170
- wrap = false
171
- } = options;
172
- const focusables = getFocusables(container, { composed, filter, include });
173
- const { length } = focusables;
174
- if (!length) {
175
- return null;
165
+ let anchor = options.anchor ?? getActiveElement();
166
+ const { composed = false, filter, include, wrap = false } = options;
167
+ if (!(anchor instanceof Element)) {
168
+ const active = getActiveElement();
169
+ if (active instanceof Element) {
170
+ console.warn("Invalid anchor element. Fallback: active element.");
171
+ anchor = active;
172
+ } else {
173
+ console.warn("Invalid anchor element");
174
+ return null;
175
+ }
176
176
  }
177
- if (!anchor || !containsComposed(container, anchor)) {
177
+ if (!containsComposed(container, anchor)) {
178
+ console.warn("Mismatch elements");
178
179
  return null;
179
180
  }
180
- if (!(anchor instanceof Element)) {
181
+ const focusables = getFocusables(container, { composed, filter, include });
182
+ const { length } = focusables;
183
+ if (!length) {
181
184
  return null;
182
185
  }
183
186
  const currentIndex = focusables.indexOf(anchor);
@@ -406,7 +409,7 @@ function isUngroupedRadio(element) {
406
409
  * High-precision focus management utility with full composed tree support.
407
410
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
408
411
  *
409
- * @version 4.1.2
412
+ * @version 4.1.3
410
413
  * @author Yusuke Kamiyamane
411
414
  * @license MIT
412
415
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "High-precision focus management utility with full composed tree support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",