power-focusable 3.0.0 → 3.0.1
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 +55 -55
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -55
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
55
55
|
elements[elements.length] = node;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
const children =
|
|
58
|
+
const children = getComposedChildren(node);
|
|
59
59
|
for (let i = 0, l = children.length; i < l; i++) {
|
|
60
60
|
const child = children[i];
|
|
61
61
|
if (!child) {
|
|
@@ -107,11 +107,11 @@ function inertOutside(element) {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
function traverse(node, callback) {
|
|
110
|
-
const parent =
|
|
110
|
+
const parent = getComposedParent(node);
|
|
111
111
|
if (!parent) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
|
-
for (const sibling of
|
|
114
|
+
for (const sibling of getComposedSiblings(node)) {
|
|
115
115
|
callback(sibling);
|
|
116
116
|
}
|
|
117
117
|
traverse(parent, callback);
|
|
@@ -157,34 +157,6 @@ function isFocusable(element) {
|
|
|
157
157
|
}
|
|
158
158
|
return true;
|
|
159
159
|
}
|
|
160
|
-
function getChildrenComposed(node) {
|
|
161
|
-
if (node instanceof ShadowRoot) {
|
|
162
|
-
return getChildren(node);
|
|
163
|
-
}
|
|
164
|
-
if (!(node instanceof Element)) {
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
if (node instanceof HTMLSlotElement) {
|
|
168
|
-
const assigned = node.assignedElements({ flatten: true });
|
|
169
|
-
if (assigned.length) {
|
|
170
|
-
return assigned;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
174
|
-
return getChildren(node.shadowRoot);
|
|
175
|
-
}
|
|
176
|
-
return getChildren(node);
|
|
177
|
-
}
|
|
178
|
-
function getParentComposed(node) {
|
|
179
|
-
if (node instanceof Element && node.assignedSlot) {
|
|
180
|
-
return node.assignedSlot;
|
|
181
|
-
}
|
|
182
|
-
const parent = node.parentNode;
|
|
183
|
-
if (parent instanceof ShadowRoot) {
|
|
184
|
-
return parent.host;
|
|
185
|
-
}
|
|
186
|
-
return parent instanceof Element ? parent : null;
|
|
187
|
-
}
|
|
188
160
|
function getRelativeFocusable(container, offset, options) {
|
|
189
161
|
const {
|
|
190
162
|
active = getActiveElement(),
|
|
@@ -212,18 +184,6 @@ function getRelativeFocusable(container, offset, options) {
|
|
|
212
184
|
}
|
|
213
185
|
return focusables[(offsetIndex + length) % length] ?? null;
|
|
214
186
|
}
|
|
215
|
-
function getSiblingsComposed(node) {
|
|
216
|
-
if (node.assignedSlot) {
|
|
217
|
-
return [...node.assignedSlot.children].filter(
|
|
218
|
-
(child) => child instanceof Element && child !== node
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
const parent = getParentComposed(node);
|
|
222
|
-
if (!parent) {
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
return getSiblings(node);
|
|
226
|
-
}
|
|
227
187
|
function isDisabledDeep(element) {
|
|
228
188
|
let current = element;
|
|
229
189
|
while (current) {
|
|
@@ -308,6 +268,56 @@ function sortByTabIndex(elements) {
|
|
|
308
268
|
}
|
|
309
269
|
return sorted;
|
|
310
270
|
}
|
|
271
|
+
function containsComposed(container, element) {
|
|
272
|
+
let current = element;
|
|
273
|
+
while (current) {
|
|
274
|
+
if (current === container) {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
function getComposedChildren(node) {
|
|
282
|
+
if (node instanceof ShadowRoot) {
|
|
283
|
+
return getChildren(node);
|
|
284
|
+
}
|
|
285
|
+
if (!(node instanceof Element)) {
|
|
286
|
+
return [];
|
|
287
|
+
}
|
|
288
|
+
if (node instanceof HTMLSlotElement) {
|
|
289
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
290
|
+
if (assigned.length) {
|
|
291
|
+
return assigned;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
295
|
+
return getChildren(node.shadowRoot);
|
|
296
|
+
}
|
|
297
|
+
return getChildren(node);
|
|
298
|
+
}
|
|
299
|
+
function getComposedParent(node) {
|
|
300
|
+
if (node instanceof Element && node.assignedSlot) {
|
|
301
|
+
return node.assignedSlot;
|
|
302
|
+
}
|
|
303
|
+
const parent = node.parentNode;
|
|
304
|
+
if (parent instanceof ShadowRoot) {
|
|
305
|
+
return parent.host;
|
|
306
|
+
}
|
|
307
|
+
return parent instanceof Element ? parent : null;
|
|
308
|
+
}
|
|
309
|
+
function getComposedSiblings(node) {
|
|
310
|
+
if (node.assignedSlot) {
|
|
311
|
+
return [...node.assignedSlot.children].filter(
|
|
312
|
+
(child) => child instanceof Element && child !== node
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
const parent = getComposedParent(node);
|
|
316
|
+
if (!parent) {
|
|
317
|
+
return [];
|
|
318
|
+
}
|
|
319
|
+
return getSiblings(node);
|
|
320
|
+
}
|
|
311
321
|
var inertRefCounts = /* @__PURE__ */ new WeakMap();
|
|
312
322
|
function applyInert(element) {
|
|
313
323
|
if (isInert(element) && !inertRefCounts.has(element)) {
|
|
@@ -332,16 +342,6 @@ function restoreInert(element) {
|
|
|
332
342
|
}
|
|
333
343
|
inertRefCounts.set(element, count - 1);
|
|
334
344
|
}
|
|
335
|
-
function containsComposed(container, element) {
|
|
336
|
-
let current = element;
|
|
337
|
-
while (current) {
|
|
338
|
-
if (current === container) {
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
342
|
-
}
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
345
|
function focus(element) {
|
|
346
346
|
if ("focus" in element && typeof element.focus === "function") {
|
|
347
347
|
element.focus();
|
|
@@ -362,7 +362,7 @@ function getChildren(node) {
|
|
|
362
362
|
return elements;
|
|
363
363
|
}
|
|
364
364
|
function getSiblings(node) {
|
|
365
|
-
const parent =
|
|
365
|
+
const parent = getComposedParent(node);
|
|
366
366
|
if (!parent) {
|
|
367
367
|
return [];
|
|
368
368
|
}
|
|
@@ -403,7 +403,7 @@ function setInert(element, boolean) {
|
|
|
403
403
|
* Handles complex focus rules including tabindex ordering, radio groups, inert,
|
|
404
404
|
* and shadow DOM.
|
|
405
405
|
*
|
|
406
|
-
* @version 3.0.
|
|
406
|
+
* @version 3.0.1
|
|
407
407
|
* @author Yusuke Kamiyamane
|
|
408
408
|
* @license MIT
|
|
409
409
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
53
53
|
elements[elements.length] = node;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const children =
|
|
56
|
+
const children = getComposedChildren(node);
|
|
57
57
|
for (let i = 0, l = children.length; i < l; i++) {
|
|
58
58
|
const child = children[i];
|
|
59
59
|
if (!child) {
|
|
@@ -105,11 +105,11 @@ function inertOutside(element) {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
function traverse(node, callback) {
|
|
108
|
-
const parent =
|
|
108
|
+
const parent = getComposedParent(node);
|
|
109
109
|
if (!parent) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
for (const sibling of
|
|
112
|
+
for (const sibling of getComposedSiblings(node)) {
|
|
113
113
|
callback(sibling);
|
|
114
114
|
}
|
|
115
115
|
traverse(parent, callback);
|
|
@@ -155,34 +155,6 @@ function isFocusable(element) {
|
|
|
155
155
|
}
|
|
156
156
|
return true;
|
|
157
157
|
}
|
|
158
|
-
function getChildrenComposed(node) {
|
|
159
|
-
if (node instanceof ShadowRoot) {
|
|
160
|
-
return getChildren(node);
|
|
161
|
-
}
|
|
162
|
-
if (!(node instanceof Element)) {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
if (node instanceof HTMLSlotElement) {
|
|
166
|
-
const assigned = node.assignedElements({ flatten: true });
|
|
167
|
-
if (assigned.length) {
|
|
168
|
-
return assigned;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
172
|
-
return getChildren(node.shadowRoot);
|
|
173
|
-
}
|
|
174
|
-
return getChildren(node);
|
|
175
|
-
}
|
|
176
|
-
function getParentComposed(node) {
|
|
177
|
-
if (node instanceof Element && node.assignedSlot) {
|
|
178
|
-
return node.assignedSlot;
|
|
179
|
-
}
|
|
180
|
-
const parent = node.parentNode;
|
|
181
|
-
if (parent instanceof ShadowRoot) {
|
|
182
|
-
return parent.host;
|
|
183
|
-
}
|
|
184
|
-
return parent instanceof Element ? parent : null;
|
|
185
|
-
}
|
|
186
158
|
function getRelativeFocusable(container, offset, options) {
|
|
187
159
|
const {
|
|
188
160
|
active = getActiveElement(),
|
|
@@ -210,18 +182,6 @@ function getRelativeFocusable(container, offset, options) {
|
|
|
210
182
|
}
|
|
211
183
|
return focusables[(offsetIndex + length) % length] ?? null;
|
|
212
184
|
}
|
|
213
|
-
function getSiblingsComposed(node) {
|
|
214
|
-
if (node.assignedSlot) {
|
|
215
|
-
return [...node.assignedSlot.children].filter(
|
|
216
|
-
(child) => child instanceof Element && child !== node
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
const parent = getParentComposed(node);
|
|
220
|
-
if (!parent) {
|
|
221
|
-
return [];
|
|
222
|
-
}
|
|
223
|
-
return getSiblings(node);
|
|
224
|
-
}
|
|
225
185
|
function isDisabledDeep(element) {
|
|
226
186
|
let current = element;
|
|
227
187
|
while (current) {
|
|
@@ -306,6 +266,56 @@ function sortByTabIndex(elements) {
|
|
|
306
266
|
}
|
|
307
267
|
return sorted;
|
|
308
268
|
}
|
|
269
|
+
function containsComposed(container, element) {
|
|
270
|
+
let current = element;
|
|
271
|
+
while (current) {
|
|
272
|
+
if (current === container) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
276
|
+
}
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
function getComposedChildren(node) {
|
|
280
|
+
if (node instanceof ShadowRoot) {
|
|
281
|
+
return getChildren(node);
|
|
282
|
+
}
|
|
283
|
+
if (!(node instanceof Element)) {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
if (node instanceof HTMLSlotElement) {
|
|
287
|
+
const assigned = node.assignedElements({ flatten: true });
|
|
288
|
+
if (assigned.length) {
|
|
289
|
+
return assigned;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
293
|
+
return getChildren(node.shadowRoot);
|
|
294
|
+
}
|
|
295
|
+
return getChildren(node);
|
|
296
|
+
}
|
|
297
|
+
function getComposedParent(node) {
|
|
298
|
+
if (node instanceof Element && node.assignedSlot) {
|
|
299
|
+
return node.assignedSlot;
|
|
300
|
+
}
|
|
301
|
+
const parent = node.parentNode;
|
|
302
|
+
if (parent instanceof ShadowRoot) {
|
|
303
|
+
return parent.host;
|
|
304
|
+
}
|
|
305
|
+
return parent instanceof Element ? parent : null;
|
|
306
|
+
}
|
|
307
|
+
function getComposedSiblings(node) {
|
|
308
|
+
if (node.assignedSlot) {
|
|
309
|
+
return [...node.assignedSlot.children].filter(
|
|
310
|
+
(child) => child instanceof Element && child !== node
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
const parent = getComposedParent(node);
|
|
314
|
+
if (!parent) {
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
return getSiblings(node);
|
|
318
|
+
}
|
|
309
319
|
var inertRefCounts = /* @__PURE__ */ new WeakMap();
|
|
310
320
|
function applyInert(element) {
|
|
311
321
|
if (isInert(element) && !inertRefCounts.has(element)) {
|
|
@@ -330,16 +340,6 @@ function restoreInert(element) {
|
|
|
330
340
|
}
|
|
331
341
|
inertRefCounts.set(element, count - 1);
|
|
332
342
|
}
|
|
333
|
-
function containsComposed(container, element) {
|
|
334
|
-
let current = element;
|
|
335
|
-
while (current) {
|
|
336
|
-
if (current === container) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
|
|
340
|
-
}
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
343
|
function focus(element) {
|
|
344
344
|
if ("focus" in element && typeof element.focus === "function") {
|
|
345
345
|
element.focus();
|
|
@@ -360,7 +360,7 @@ function getChildren(node) {
|
|
|
360
360
|
return elements;
|
|
361
361
|
}
|
|
362
362
|
function getSiblings(node) {
|
|
363
|
-
const parent =
|
|
363
|
+
const parent = getComposedParent(node);
|
|
364
364
|
if (!parent) {
|
|
365
365
|
return [];
|
|
366
366
|
}
|
|
@@ -401,7 +401,7 @@ function setInert(element, boolean) {
|
|
|
401
401
|
* Handles complex focus rules including tabindex ordering, radio groups, inert,
|
|
402
402
|
* and shadow DOM.
|
|
403
403
|
*
|
|
404
|
-
* @version 3.0.
|
|
404
|
+
* @version 3.0.1
|
|
405
405
|
* @author Yusuke Kamiyamane
|
|
406
406
|
* @license MIT
|
|
407
407
|
* @copyright Copyright (c) Yusuke Kamiyamane
|