power-focusable 3.0.0 → 3.0.2
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 +65 -56
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +65 -56
- 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) {
|
|
@@ -241,7 +201,7 @@ function isDisabledDeep(element) {
|
|
|
241
201
|
if (current === element && isFormControl(current) && isDisabled(current)) {
|
|
242
202
|
return true;
|
|
243
203
|
}
|
|
244
|
-
if (current
|
|
204
|
+
if (isInert(current)) {
|
|
245
205
|
return true;
|
|
246
206
|
}
|
|
247
207
|
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
@@ -308,6 +268,65 @@ 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
|
+
const siblings = node.assignedSlot.children;
|
|
312
|
+
const filtered = [];
|
|
313
|
+
for (let i = 0, l = siblings.length; i < l; i++) {
|
|
314
|
+
const sibling = siblings[i];
|
|
315
|
+
if (sibling !== node) {
|
|
316
|
+
if (!(sibling instanceof Element)) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
filtered[filtered.length] = sibling;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return filtered;
|
|
323
|
+
}
|
|
324
|
+
const parent = getComposedParent(node);
|
|
325
|
+
if (!parent) {
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
return getSiblings(node);
|
|
329
|
+
}
|
|
311
330
|
var inertRefCounts = /* @__PURE__ */ new WeakMap();
|
|
312
331
|
function applyInert(element) {
|
|
313
332
|
if (isInert(element) && !inertRefCounts.has(element)) {
|
|
@@ -332,16 +351,6 @@ function restoreInert(element) {
|
|
|
332
351
|
}
|
|
333
352
|
inertRefCounts.set(element, count - 1);
|
|
334
353
|
}
|
|
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
354
|
function focus(element) {
|
|
346
355
|
if ("focus" in element && typeof element.focus === "function") {
|
|
347
356
|
element.focus();
|
|
@@ -362,7 +371,7 @@ function getChildren(node) {
|
|
|
362
371
|
return elements;
|
|
363
372
|
}
|
|
364
373
|
function getSiblings(node) {
|
|
365
|
-
const parent =
|
|
374
|
+
const parent = getComposedParent(node);
|
|
366
375
|
if (!parent) {
|
|
367
376
|
return [];
|
|
368
377
|
}
|
|
@@ -403,7 +412,7 @@ function setInert(element, boolean) {
|
|
|
403
412
|
* Handles complex focus rules including tabindex ordering, radio groups, inert,
|
|
404
413
|
* and shadow DOM.
|
|
405
414
|
*
|
|
406
|
-
* @version 3.0.
|
|
415
|
+
* @version 3.0.2
|
|
407
416
|
* @author Yusuke Kamiyamane
|
|
408
417
|
* @license MIT
|
|
409
418
|
* @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) {
|
|
@@ -239,7 +199,7 @@ function isDisabledDeep(element) {
|
|
|
239
199
|
if (current === element && isFormControl(current) && isDisabled(current)) {
|
|
240
200
|
return true;
|
|
241
201
|
}
|
|
242
|
-
if (current
|
|
202
|
+
if (isInert(current)) {
|
|
243
203
|
return true;
|
|
244
204
|
}
|
|
245
205
|
if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
|
|
@@ -306,6 +266,65 @@ 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
|
+
const siblings = node.assignedSlot.children;
|
|
310
|
+
const filtered = [];
|
|
311
|
+
for (let i = 0, l = siblings.length; i < l; i++) {
|
|
312
|
+
const sibling = siblings[i];
|
|
313
|
+
if (sibling !== node) {
|
|
314
|
+
if (!(sibling instanceof Element)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
filtered[filtered.length] = sibling;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return filtered;
|
|
321
|
+
}
|
|
322
|
+
const parent = getComposedParent(node);
|
|
323
|
+
if (!parent) {
|
|
324
|
+
return [];
|
|
325
|
+
}
|
|
326
|
+
return getSiblings(node);
|
|
327
|
+
}
|
|
309
328
|
var inertRefCounts = /* @__PURE__ */ new WeakMap();
|
|
310
329
|
function applyInert(element) {
|
|
311
330
|
if (isInert(element) && !inertRefCounts.has(element)) {
|
|
@@ -330,16 +349,6 @@ function restoreInert(element) {
|
|
|
330
349
|
}
|
|
331
350
|
inertRefCounts.set(element, count - 1);
|
|
332
351
|
}
|
|
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
352
|
function focus(element) {
|
|
344
353
|
if ("focus" in element && typeof element.focus === "function") {
|
|
345
354
|
element.focus();
|
|
@@ -360,7 +369,7 @@ function getChildren(node) {
|
|
|
360
369
|
return elements;
|
|
361
370
|
}
|
|
362
371
|
function getSiblings(node) {
|
|
363
|
-
const parent =
|
|
372
|
+
const parent = getComposedParent(node);
|
|
364
373
|
if (!parent) {
|
|
365
374
|
return [];
|
|
366
375
|
}
|
|
@@ -401,7 +410,7 @@ function setInert(element, boolean) {
|
|
|
401
410
|
* Handles complex focus rules including tabindex ordering, radio groups, inert,
|
|
402
411
|
* and shadow DOM.
|
|
403
412
|
*
|
|
404
|
-
* @version 3.0.
|
|
413
|
+
* @version 3.0.2
|
|
405
414
|
* @author Yusuke Kamiyamane
|
|
406
415
|
* @license MIT
|
|
407
416
|
* @copyright Copyright (c) Yusuke Kamiyamane
|