power-focusable 2.1.6 → 2.1.7

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
@@ -24,14 +24,20 @@ function getFocusables(container = document.body, options = {}) {
24
24
  const assigned = node.assignedElements({ flatten: true });
25
25
  if (assigned.length) {
26
26
  for (let i = 0, l = assigned.length; i < l; i++) {
27
- traverse2(assigned[i]);
27
+ const a = assigned[i];
28
+ if (a) {
29
+ traverse2(a);
30
+ }
28
31
  }
29
32
  return;
30
33
  }
31
34
  }
32
35
  const children = node.childNodes;
33
36
  for (let i = 0, l = children.length; i < l; i++) {
34
- traverse2(children[i]);
37
+ const child = children[i];
38
+ if (child) {
39
+ traverse2(child);
40
+ }
35
41
  }
36
42
  };
37
43
  traverse2(container);
@@ -39,7 +45,7 @@ function getFocusables(container = document.body, options = {}) {
39
45
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
40
46
  for (let i = 0, l = candidates.length; i < l; i++) {
41
47
  const candidate = candidates[i];
42
- if (isFocusable(candidate)) {
48
+ if (candidate && isFocusable(candidate)) {
43
49
  elements[elements.length] = candidate;
44
50
  }
45
51
  }
@@ -108,6 +114,9 @@ function getRelativeFocusable(container, offset, options) {
108
114
  if (!active || !containsDeep(container, active)) {
109
115
  return null;
110
116
  }
117
+ if (!(active instanceof HTMLElement)) {
118
+ throw new Error("Unreachable");
119
+ }
111
120
  const currentIndex = focusables.indexOf(active);
112
121
  if (currentIndex === -1) {
113
122
  return null;
@@ -188,7 +197,7 @@ function normalizeRadioGroup(elements) {
188
197
  let map = null;
189
198
  for (let i = 0, l = elements.length; i < l; i++) {
190
199
  const element = elements[i];
191
- if (!isUngroupedRadio(element)) {
200
+ if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
192
201
  continue;
193
202
  }
194
203
  if (!map) {
@@ -196,7 +205,9 @@ function normalizeRadioGroup(elements) {
196
205
  }
197
206
  const key = `${element.form?.id ?? "no-form"}::${element.name}`;
198
207
  const group = map.get(key) ?? map.set(key, []).get(key);
199
- group[group.length] = element;
208
+ if (group) {
209
+ group[group.length] = element;
210
+ }
200
211
  }
201
212
  if (!map) {
202
213
  return elements;
@@ -217,6 +228,9 @@ function sortByTabIndex(elements) {
217
228
  const natural = [];
218
229
  for (let i = 0, l = elements.length; i < l; i++) {
219
230
  const element = elements[i];
231
+ if (!element) {
232
+ throw new Error("Unreachable");
233
+ }
220
234
  const target = getTabIndex(element) > 0 ? ordered : natural;
221
235
  target[target.length] = element;
222
236
  }
@@ -236,7 +250,7 @@ function sortByTabIndex(elements) {
236
250
  * High-precision focus management utility with shadow DOM support.
237
251
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
238
252
  *
239
- * @version 2.1.6
253
+ * @version 2.1.7
240
254
  * @author Yusuke Kamiyamane
241
255
  * @license MIT
242
256
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-precision focus management utility with shadow DOM support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
5
5
  *
6
- * @version 2.1.6
6
+ * @version 2.1.7
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 shadow DOM support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
5
5
  *
6
- * @version 2.1.6
6
+ * @version 2.1.7
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -22,14 +22,20 @@ function getFocusables(container = document.body, options = {}) {
22
22
  const assigned = node.assignedElements({ flatten: true });
23
23
  if (assigned.length) {
24
24
  for (let i = 0, l = assigned.length; i < l; i++) {
25
- traverse2(assigned[i]);
25
+ const a = assigned[i];
26
+ if (a) {
27
+ traverse2(a);
28
+ }
26
29
  }
27
30
  return;
28
31
  }
29
32
  }
30
33
  const children = node.childNodes;
31
34
  for (let i = 0, l = children.length; i < l; i++) {
32
- traverse2(children[i]);
35
+ const child = children[i];
36
+ if (child) {
37
+ traverse2(child);
38
+ }
33
39
  }
34
40
  };
35
41
  traverse2(container);
@@ -37,7 +43,7 @@ function getFocusables(container = document.body, options = {}) {
37
43
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
38
44
  for (let i = 0, l = candidates.length; i < l; i++) {
39
45
  const candidate = candidates[i];
40
- if (isFocusable(candidate)) {
46
+ if (candidate && isFocusable(candidate)) {
41
47
  elements[elements.length] = candidate;
42
48
  }
43
49
  }
@@ -106,6 +112,9 @@ function getRelativeFocusable(container, offset, options) {
106
112
  if (!active || !containsDeep(container, active)) {
107
113
  return null;
108
114
  }
115
+ if (!(active instanceof HTMLElement)) {
116
+ throw new Error("Unreachable");
117
+ }
109
118
  const currentIndex = focusables.indexOf(active);
110
119
  if (currentIndex === -1) {
111
120
  return null;
@@ -186,7 +195,7 @@ function normalizeRadioGroup(elements) {
186
195
  let map = null;
187
196
  for (let i = 0, l = elements.length; i < l; i++) {
188
197
  const element = elements[i];
189
- if (!isUngroupedRadio(element)) {
198
+ if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
190
199
  continue;
191
200
  }
192
201
  if (!map) {
@@ -194,7 +203,9 @@ function normalizeRadioGroup(elements) {
194
203
  }
195
204
  const key = `${element.form?.id ?? "no-form"}::${element.name}`;
196
205
  const group = map.get(key) ?? map.set(key, []).get(key);
197
- group[group.length] = element;
206
+ if (group) {
207
+ group[group.length] = element;
208
+ }
198
209
  }
199
210
  if (!map) {
200
211
  return elements;
@@ -215,6 +226,9 @@ function sortByTabIndex(elements) {
215
226
  const natural = [];
216
227
  for (let i = 0, l = elements.length; i < l; i++) {
217
228
  const element = elements[i];
229
+ if (!element) {
230
+ throw new Error("Unreachable");
231
+ }
218
232
  const target = getTabIndex(element) > 0 ? ordered : natural;
219
233
  target[target.length] = element;
220
234
  }
@@ -234,7 +248,7 @@ function sortByTabIndex(elements) {
234
248
  * High-precision focus management utility with shadow DOM support.
235
249
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
236
250
  *
237
- * @version 2.1.6
251
+ * @version 2.1.7
238
252
  * @author Yusuke Kamiyamane
239
253
  * @license MIT
240
254
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "High-precision focus management utility with shadow DOM support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",