power-focusable 2.1.5 → 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 +25 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -8
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -95,16 +101,22 @@ function isFocusable(element) {
|
|
|
95
101
|
return true;
|
|
96
102
|
}
|
|
97
103
|
function getRelativeFocusable(container, offset, options) {
|
|
98
|
-
const {
|
|
104
|
+
const {
|
|
105
|
+
active = getActiveElement(),
|
|
106
|
+
composed = false,
|
|
107
|
+
wrap = false
|
|
108
|
+
} = options;
|
|
99
109
|
const focusables = getFocusables(container, { composed });
|
|
100
110
|
const { length } = focusables;
|
|
101
111
|
if (!length) {
|
|
102
112
|
return null;
|
|
103
113
|
}
|
|
104
|
-
const active = a ?? getActiveElement();
|
|
105
114
|
if (!active || !containsDeep(container, active)) {
|
|
106
115
|
return null;
|
|
107
116
|
}
|
|
117
|
+
if (!(active instanceof HTMLElement)) {
|
|
118
|
+
throw new Error("Unreachable");
|
|
119
|
+
}
|
|
108
120
|
const currentIndex = focusables.indexOf(active);
|
|
109
121
|
if (currentIndex === -1) {
|
|
110
122
|
return null;
|
|
@@ -185,7 +197,7 @@ function normalizeRadioGroup(elements) {
|
|
|
185
197
|
let map = null;
|
|
186
198
|
for (let i = 0, l = elements.length; i < l; i++) {
|
|
187
199
|
const element = elements[i];
|
|
188
|
-
if (!isUngroupedRadio(element)) {
|
|
200
|
+
if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
|
|
189
201
|
continue;
|
|
190
202
|
}
|
|
191
203
|
if (!map) {
|
|
@@ -193,7 +205,9 @@ function normalizeRadioGroup(elements) {
|
|
|
193
205
|
}
|
|
194
206
|
const key = `${element.form?.id ?? "no-form"}::${element.name}`;
|
|
195
207
|
const group = map.get(key) ?? map.set(key, []).get(key);
|
|
196
|
-
group
|
|
208
|
+
if (group) {
|
|
209
|
+
group[group.length] = element;
|
|
210
|
+
}
|
|
197
211
|
}
|
|
198
212
|
if (!map) {
|
|
199
213
|
return elements;
|
|
@@ -214,6 +228,9 @@ function sortByTabIndex(elements) {
|
|
|
214
228
|
const natural = [];
|
|
215
229
|
for (let i = 0, l = elements.length; i < l; i++) {
|
|
216
230
|
const element = elements[i];
|
|
231
|
+
if (!element) {
|
|
232
|
+
throw new Error("Unreachable");
|
|
233
|
+
}
|
|
217
234
|
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
218
235
|
target[target.length] = element;
|
|
219
236
|
}
|
|
@@ -233,7 +250,7 @@ function sortByTabIndex(elements) {
|
|
|
233
250
|
* High-precision focus management utility with shadow DOM support.
|
|
234
251
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
235
252
|
*
|
|
236
|
-
* @version 2.1.
|
|
253
|
+
* @version 2.1.7
|
|
237
254
|
* @author Yusuke Kamiyamane
|
|
238
255
|
* @license MIT
|
|
239
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
|
+
* @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
|
+
* @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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -93,16 +99,22 @@ function isFocusable(element) {
|
|
|
93
99
|
return true;
|
|
94
100
|
}
|
|
95
101
|
function getRelativeFocusable(container, offset, options) {
|
|
96
|
-
const {
|
|
102
|
+
const {
|
|
103
|
+
active = getActiveElement(),
|
|
104
|
+
composed = false,
|
|
105
|
+
wrap = false
|
|
106
|
+
} = options;
|
|
97
107
|
const focusables = getFocusables(container, { composed });
|
|
98
108
|
const { length } = focusables;
|
|
99
109
|
if (!length) {
|
|
100
110
|
return null;
|
|
101
111
|
}
|
|
102
|
-
const active = a ?? getActiveElement();
|
|
103
112
|
if (!active || !containsDeep(container, active)) {
|
|
104
113
|
return null;
|
|
105
114
|
}
|
|
115
|
+
if (!(active instanceof HTMLElement)) {
|
|
116
|
+
throw new Error("Unreachable");
|
|
117
|
+
}
|
|
106
118
|
const currentIndex = focusables.indexOf(active);
|
|
107
119
|
if (currentIndex === -1) {
|
|
108
120
|
return null;
|
|
@@ -183,7 +195,7 @@ function normalizeRadioGroup(elements) {
|
|
|
183
195
|
let map = null;
|
|
184
196
|
for (let i = 0, l = elements.length; i < l; i++) {
|
|
185
197
|
const element = elements[i];
|
|
186
|
-
if (!isUngroupedRadio(element)) {
|
|
198
|
+
if (!(element instanceof HTMLInputElement) || !isUngroupedRadio(element)) {
|
|
187
199
|
continue;
|
|
188
200
|
}
|
|
189
201
|
if (!map) {
|
|
@@ -191,7 +203,9 @@ function normalizeRadioGroup(elements) {
|
|
|
191
203
|
}
|
|
192
204
|
const key = `${element.form?.id ?? "no-form"}::${element.name}`;
|
|
193
205
|
const group = map.get(key) ?? map.set(key, []).get(key);
|
|
194
|
-
group
|
|
206
|
+
if (group) {
|
|
207
|
+
group[group.length] = element;
|
|
208
|
+
}
|
|
195
209
|
}
|
|
196
210
|
if (!map) {
|
|
197
211
|
return elements;
|
|
@@ -212,6 +226,9 @@ function sortByTabIndex(elements) {
|
|
|
212
226
|
const natural = [];
|
|
213
227
|
for (let i = 0, l = elements.length; i < l; i++) {
|
|
214
228
|
const element = elements[i];
|
|
229
|
+
if (!element) {
|
|
230
|
+
throw new Error("Unreachable");
|
|
231
|
+
}
|
|
215
232
|
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
216
233
|
target[target.length] = element;
|
|
217
234
|
}
|
|
@@ -231,7 +248,7 @@ function sortByTabIndex(elements) {
|
|
|
231
248
|
* High-precision focus management utility with shadow DOM support.
|
|
232
249
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
233
250
|
*
|
|
234
|
-
* @version 2.1.
|
|
251
|
+
* @version 2.1.7
|
|
235
252
|
* @author Yusuke Kamiyamane
|
|
236
253
|
* @license MIT
|
|
237
254
|
* @copyright Copyright (c) Yusuke Kamiyamane
|