power-focusable 4.3.29 → 4.3.30
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 +3 -3
- package/dist/index.cjs +18 -53
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,11 +24,11 @@ import {
|
|
|
24
24
|
} from 'power-focusable';
|
|
25
25
|
|
|
26
26
|
// CDNs
|
|
27
|
-
import { ... } 'https://esm.sh/power-focusable@4.3.
|
|
27
|
+
import { ... } 'https://esm.sh/power-focusable@4.3.30';
|
|
28
28
|
// or
|
|
29
|
-
import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable@4.3.
|
|
29
|
+
import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable@4.3.30/+esm';
|
|
30
30
|
// or
|
|
31
|
-
import { ... } 'https://esm.unpkg.com/power-focusable@4.3.
|
|
31
|
+
import { ... } 'https://esm.unpkg.com/power-focusable@4.3.30';
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## 🪄 Options
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
var FOCUSABLE_SELECTOR =
|
|
4
|
+
var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
|
|
5
5
|
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
6
6
|
/(,\s*)?\[tabindex="-1"\]/g,
|
|
7
7
|
""
|
|
@@ -80,29 +80,19 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
80
80
|
}) || include?.(node)) {
|
|
81
81
|
candidates[candidates.length] = node;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
85
|
-
const child = children2[i];
|
|
86
|
-
child && traverse2(child);
|
|
87
|
-
}
|
|
83
|
+
(composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
|
|
88
84
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
child && traverse2(child);
|
|
93
|
-
}
|
|
85
|
+
(composed ? getComposedChildren(container) : getChildren(container)).map(
|
|
86
|
+
traverse2
|
|
87
|
+
);
|
|
94
88
|
} else {
|
|
95
|
-
const
|
|
89
|
+
for (const match of container.querySelectorAll(
|
|
96
90
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
const matched = matches[i];
|
|
100
|
-
if (matched && isFocusable(matched, {
|
|
91
|
+
)) {
|
|
92
|
+
match && isFocusable(match, {
|
|
101
93
|
skipNegativeTabIndexCheck,
|
|
102
94
|
skipVisibilityCheck
|
|
103
|
-
}))
|
|
104
|
-
candidates[candidates.length] = matched;
|
|
105
|
-
}
|
|
95
|
+
}) && candidates.push(match);
|
|
106
96
|
}
|
|
107
97
|
}
|
|
108
98
|
return normalizeRadioGroup(
|
|
@@ -127,20 +117,13 @@ function inertOutside(element) {
|
|
|
127
117
|
function traverse(node, fn) {
|
|
128
118
|
const parent = getComposedParent(node);
|
|
129
119
|
if (parent) {
|
|
130
|
-
|
|
131
|
-
fn(sibling);
|
|
132
|
-
}
|
|
120
|
+
getComposedSiblings(node).map(fn);
|
|
133
121
|
traverse(parent, fn);
|
|
134
122
|
}
|
|
135
123
|
}
|
|
136
124
|
const elements = [];
|
|
137
125
|
traverse(element, (node) => node && applyInert(node) && elements.push(node));
|
|
138
|
-
return () =>
|
|
139
|
-
for (let i = 0, l = elements.length; i < l; i++) {
|
|
140
|
-
const element2 = elements[i];
|
|
141
|
-
element2 && restoreInert(element2);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
126
|
+
return () => elements.map(restoreInert);
|
|
144
127
|
}
|
|
145
128
|
function isFocusable(element, options = {}) {
|
|
146
129
|
if (!(element instanceof Element)) {
|
|
@@ -245,8 +228,7 @@ function isDisabledDeep(element) {
|
|
|
245
228
|
}
|
|
246
229
|
function normalizeRadioGroup(elements) {
|
|
247
230
|
let map = null;
|
|
248
|
-
for (
|
|
249
|
-
const element = elements[i];
|
|
231
|
+
for (const element of elements) {
|
|
250
232
|
if (!(element instanceof HTMLInputElement)) {
|
|
251
233
|
continue;
|
|
252
234
|
}
|
|
@@ -296,23 +278,10 @@ function normalizeRadioGroup(elements) {
|
|
|
296
278
|
function sortByTabIndex(elements) {
|
|
297
279
|
const ordered = [];
|
|
298
280
|
const natural = [];
|
|
299
|
-
for (
|
|
300
|
-
|
|
301
|
-
if (element) {
|
|
302
|
-
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
303
|
-
target[target.length] = element;
|
|
304
|
-
}
|
|
281
|
+
for (const element of elements) {
|
|
282
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
305
283
|
}
|
|
306
|
-
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
307
|
-
let count = 0;
|
|
308
|
-
const sorted = new Array(ordered.length + natural.length);
|
|
309
|
-
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
310
|
-
sorted[count++] = ordered[i];
|
|
311
|
-
}
|
|
312
|
-
for (let i = 0, l = natural.length; i < l; i++) {
|
|
313
|
-
sorted[count++] = natural[i];
|
|
314
|
-
}
|
|
315
|
-
return sorted;
|
|
284
|
+
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
316
285
|
}
|
|
317
286
|
function containsComposed(container, element) {
|
|
318
287
|
let current = element;
|
|
@@ -356,13 +325,9 @@ function getComposedSiblings(node) {
|
|
|
356
325
|
if (!parent) {
|
|
357
326
|
return [];
|
|
358
327
|
}
|
|
359
|
-
const siblings = parent instanceof HTMLSlotElement ? parent.assignedElements({ flatten: true }) : getComposedChildren(parent);
|
|
360
328
|
const filtered = [];
|
|
361
|
-
for (
|
|
362
|
-
|
|
363
|
-
if (sibling && sibling !== node) {
|
|
364
|
-
filtered[filtered.length] = sibling;
|
|
365
|
-
}
|
|
329
|
+
for (const sibling of (parent instanceof HTMLSlotElement ? parent.assignedElements({ flatten: true }) : getComposedChildren(parent)).filter((sibling2) => sibling2 !== node)) {
|
|
330
|
+
filtered.push(sibling);
|
|
366
331
|
}
|
|
367
332
|
return filtered;
|
|
368
333
|
}
|
|
@@ -482,7 +447,7 @@ function resolveOptions(options) {
|
|
|
482
447
|
* High-precision focus management utility with full composed tree support.
|
|
483
448
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
484
449
|
*
|
|
485
|
-
* @version 4.3.
|
|
450
|
+
* @version 4.3.30
|
|
486
451
|
* @author Yusuke Kamiyamane
|
|
487
452
|
* @license MIT
|
|
488
453
|
* @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.3.
|
|
6
|
+
* @version 4.3.30
|
|
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.3.
|
|
6
|
+
* @version 4.3.30
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var FOCUSABLE_SELECTOR =
|
|
2
|
+
var FOCUSABLE_SELECTOR = ':is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])';
|
|
3
3
|
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
4
4
|
/(,\s*)?\[tabindex="-1"\]/g,
|
|
5
5
|
""
|
|
@@ -78,29 +78,19 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
78
78
|
}) || include?.(node)) {
|
|
79
79
|
candidates[candidates.length] = node;
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
83
|
-
const child = children2[i];
|
|
84
|
-
child && traverse2(child);
|
|
85
|
-
}
|
|
81
|
+
(composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
|
|
86
82
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
child && traverse2(child);
|
|
91
|
-
}
|
|
83
|
+
(composed ? getComposedChildren(container) : getChildren(container)).map(
|
|
84
|
+
traverse2
|
|
85
|
+
);
|
|
92
86
|
} else {
|
|
93
|
-
const
|
|
87
|
+
for (const match of container.querySelectorAll(
|
|
94
88
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
const matched = matches[i];
|
|
98
|
-
if (matched && isFocusable(matched, {
|
|
89
|
+
)) {
|
|
90
|
+
match && isFocusable(match, {
|
|
99
91
|
skipNegativeTabIndexCheck,
|
|
100
92
|
skipVisibilityCheck
|
|
101
|
-
}))
|
|
102
|
-
candidates[candidates.length] = matched;
|
|
103
|
-
}
|
|
93
|
+
}) && candidates.push(match);
|
|
104
94
|
}
|
|
105
95
|
}
|
|
106
96
|
return normalizeRadioGroup(
|
|
@@ -125,20 +115,13 @@ function inertOutside(element) {
|
|
|
125
115
|
function traverse(node, fn) {
|
|
126
116
|
const parent = getComposedParent(node);
|
|
127
117
|
if (parent) {
|
|
128
|
-
|
|
129
|
-
fn(sibling);
|
|
130
|
-
}
|
|
118
|
+
getComposedSiblings(node).map(fn);
|
|
131
119
|
traverse(parent, fn);
|
|
132
120
|
}
|
|
133
121
|
}
|
|
134
122
|
const elements = [];
|
|
135
123
|
traverse(element, (node) => node && applyInert(node) && elements.push(node));
|
|
136
|
-
return () =>
|
|
137
|
-
for (let i = 0, l = elements.length; i < l; i++) {
|
|
138
|
-
const element2 = elements[i];
|
|
139
|
-
element2 && restoreInert(element2);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
124
|
+
return () => elements.map(restoreInert);
|
|
142
125
|
}
|
|
143
126
|
function isFocusable(element, options = {}) {
|
|
144
127
|
if (!(element instanceof Element)) {
|
|
@@ -243,8 +226,7 @@ function isDisabledDeep(element) {
|
|
|
243
226
|
}
|
|
244
227
|
function normalizeRadioGroup(elements) {
|
|
245
228
|
let map = null;
|
|
246
|
-
for (
|
|
247
|
-
const element = elements[i];
|
|
229
|
+
for (const element of elements) {
|
|
248
230
|
if (!(element instanceof HTMLInputElement)) {
|
|
249
231
|
continue;
|
|
250
232
|
}
|
|
@@ -294,23 +276,10 @@ function normalizeRadioGroup(elements) {
|
|
|
294
276
|
function sortByTabIndex(elements) {
|
|
295
277
|
const ordered = [];
|
|
296
278
|
const natural = [];
|
|
297
|
-
for (
|
|
298
|
-
|
|
299
|
-
if (element) {
|
|
300
|
-
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
301
|
-
target[target.length] = element;
|
|
302
|
-
}
|
|
279
|
+
for (const element of elements) {
|
|
280
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
303
281
|
}
|
|
304
|
-
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
305
|
-
let count = 0;
|
|
306
|
-
const sorted = new Array(ordered.length + natural.length);
|
|
307
|
-
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
308
|
-
sorted[count++] = ordered[i];
|
|
309
|
-
}
|
|
310
|
-
for (let i = 0, l = natural.length; i < l; i++) {
|
|
311
|
-
sorted[count++] = natural[i];
|
|
312
|
-
}
|
|
313
|
-
return sorted;
|
|
282
|
+
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
314
283
|
}
|
|
315
284
|
function containsComposed(container, element) {
|
|
316
285
|
let current = element;
|
|
@@ -354,13 +323,9 @@ function getComposedSiblings(node) {
|
|
|
354
323
|
if (!parent) {
|
|
355
324
|
return [];
|
|
356
325
|
}
|
|
357
|
-
const siblings = parent instanceof HTMLSlotElement ? parent.assignedElements({ flatten: true }) : getComposedChildren(parent);
|
|
358
326
|
const filtered = [];
|
|
359
|
-
for (
|
|
360
|
-
|
|
361
|
-
if (sibling && sibling !== node) {
|
|
362
|
-
filtered[filtered.length] = sibling;
|
|
363
|
-
}
|
|
327
|
+
for (const sibling of (parent instanceof HTMLSlotElement ? parent.assignedElements({ flatten: true }) : getComposedChildren(parent)).filter((sibling2) => sibling2 !== node)) {
|
|
328
|
+
filtered.push(sibling);
|
|
364
329
|
}
|
|
365
330
|
return filtered;
|
|
366
331
|
}
|
|
@@ -480,7 +445,7 @@ function resolveOptions(options) {
|
|
|
480
445
|
* High-precision focus management utility with full composed tree support.
|
|
481
446
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
482
447
|
*
|
|
483
|
-
* @version 4.3.
|
|
448
|
+
* @version 4.3.30
|
|
484
449
|
* @author Yusuke Kamiyamane
|
|
485
450
|
* @license MIT
|
|
486
451
|
* @copyright Copyright (c) Yusuke Kamiyamane
|