@y14e/portal 1.3.5 → 1.3.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/README.md +3 -3
- package/dist/index.bundle.cjs +68 -99
- package/dist/index.bundle.js +68 -99
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -14
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i @y14e/portal
|
|
|
13
13
|
import { createPortal } from '@y14e/portal';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.
|
|
16
|
+
import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.7';
|
|
17
17
|
// or
|
|
18
|
-
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.
|
|
18
|
+
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.7/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.
|
|
20
|
+
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.7';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -3,33 +3,33 @@
|
|
|
3
3
|
// node_modules/@y14e/attribute-utils/dist/index.js
|
|
4
4
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
function restoreAttributes(element_or_elements) {
|
|
6
|
-
for (const
|
|
7
|
-
const snapshot = snapshots.get(
|
|
6
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
7
|
+
const snapshot = snapshots.get(e);
|
|
8
8
|
if (!snapshot) {
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
|
-
for (const [
|
|
12
|
-
|
|
11
|
+
for (const [n, v] of snapshot.entries()) {
|
|
12
|
+
v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
|
|
13
13
|
}
|
|
14
|
-
snapshots.delete(
|
|
14
|
+
snapshots.delete(e);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function saveAttributes(element_or_elements, name_or_names) {
|
|
18
18
|
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
19
|
-
(Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements])
|
|
20
|
-
let snapshot = snapshots.get(
|
|
19
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
20
|
+
let snapshot = snapshots.get(e);
|
|
21
21
|
if (!snapshot) {
|
|
22
22
|
snapshot = /* @__PURE__ */ new Map();
|
|
23
|
-
snapshots.set(
|
|
23
|
+
snapshots.set(e, snapshot);
|
|
24
24
|
}
|
|
25
|
-
names
|
|
26
|
-
snapshot.set(
|
|
27
|
-
}
|
|
28
|
-
}
|
|
25
|
+
for (const n of names) {
|
|
26
|
+
snapshot.set(n, e.getAttribute(n));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// node_modules/power-focusable/dist/index.js
|
|
32
|
-
var FOCUSABLE_SELECTOR =
|
|
32
|
+
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"])';
|
|
33
33
|
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
34
34
|
/(,\s*)?\[tabindex="-1"\]/g,
|
|
35
35
|
""
|
|
@@ -53,31 +53,21 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
53
53
|
skipNegativeTabIndexCheck,
|
|
54
54
|
skipVisibilityCheck
|
|
55
55
|
}) || include?.(node)) {
|
|
56
|
-
candidates
|
|
57
|
-
}
|
|
58
|
-
const children2 = composed ? getComposedChildren(node) : getChildren(node);
|
|
59
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
60
|
-
const child = children2[i];
|
|
61
|
-
child && traverse2(child);
|
|
56
|
+
candidates.push(node);
|
|
62
57
|
}
|
|
58
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
63
59
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
child && traverse2(child);
|
|
68
|
-
}
|
|
60
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
61
|
+
traverse2
|
|
62
|
+
);
|
|
69
63
|
} else {
|
|
70
|
-
const
|
|
64
|
+
for (const m of container.querySelectorAll(
|
|
71
65
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const matched = matches[i];
|
|
75
|
-
if (matched && isFocusable(matched, {
|
|
66
|
+
)) {
|
|
67
|
+
m && isFocusable(m, {
|
|
76
68
|
skipNegativeTabIndexCheck,
|
|
77
69
|
skipVisibilityCheck
|
|
78
|
-
}))
|
|
79
|
-
candidates[candidates.length] = matched;
|
|
80
|
-
}
|
|
70
|
+
}) && candidates.push(m);
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
73
|
return normalizeRadioGroup(
|
|
@@ -193,74 +183,60 @@ function isDisabledDeep(element) {
|
|
|
193
183
|
}
|
|
194
184
|
function normalizeRadioGroup(elements) {
|
|
195
185
|
let map = null;
|
|
196
|
-
for (
|
|
197
|
-
|
|
198
|
-
if (!(element instanceof HTMLInputElement)) {
|
|
186
|
+
for (const e of elements) {
|
|
187
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
199
188
|
continue;
|
|
200
189
|
}
|
|
201
|
-
if (!isUngroupedRadio(
|
|
190
|
+
if (!isUngroupedRadio(e)) {
|
|
202
191
|
continue;
|
|
203
192
|
}
|
|
204
193
|
if (!map) {
|
|
205
194
|
map = /* @__PURE__ */ new Map();
|
|
206
195
|
}
|
|
207
|
-
const root =
|
|
208
|
-
let
|
|
209
|
-
if (!
|
|
210
|
-
|
|
211
|
-
map.set(root,
|
|
196
|
+
const root = e.getRootNode();
|
|
197
|
+
let groups = map.get(root);
|
|
198
|
+
if (!groups) {
|
|
199
|
+
groups = /* @__PURE__ */ new Map();
|
|
200
|
+
map.set(root, groups);
|
|
212
201
|
}
|
|
213
|
-
let
|
|
214
|
-
if (!
|
|
215
|
-
|
|
216
|
-
|
|
202
|
+
let group = groups.get(e.form);
|
|
203
|
+
if (!group) {
|
|
204
|
+
group = /* @__PURE__ */ new Map();
|
|
205
|
+
groups.set(e.form, group);
|
|
217
206
|
}
|
|
218
|
-
let
|
|
219
|
-
if (!
|
|
220
|
-
|
|
221
|
-
|
|
207
|
+
let radios = group.get(e.name);
|
|
208
|
+
if (!radios) {
|
|
209
|
+
radios = [];
|
|
210
|
+
group.set(e.name, radios);
|
|
222
211
|
}
|
|
223
|
-
|
|
212
|
+
radios.push(e);
|
|
224
213
|
}
|
|
225
214
|
if (!map) {
|
|
226
215
|
return elements;
|
|
227
216
|
}
|
|
228
217
|
const placeholder = /* @__PURE__ */ new Set();
|
|
229
|
-
for (const
|
|
230
|
-
for (const
|
|
231
|
-
for (const
|
|
232
|
-
const radio =
|
|
218
|
+
for (const v of map.values()) {
|
|
219
|
+
for (const w of v.values()) {
|
|
220
|
+
for (const x of w.values()) {
|
|
221
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
233
222
|
radio && placeholder.add(radio);
|
|
234
223
|
}
|
|
235
224
|
}
|
|
236
225
|
}
|
|
237
|
-
return elements.filter((
|
|
238
|
-
if (!(
|
|
226
|
+
return elements.filter((e) => {
|
|
227
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
239
228
|
return true;
|
|
240
229
|
}
|
|
241
|
-
return !isUngroupedRadio(
|
|
230
|
+
return !isUngroupedRadio(e) || placeholder.has(e);
|
|
242
231
|
});
|
|
243
232
|
}
|
|
244
233
|
function sortByTabIndex(elements) {
|
|
245
234
|
const ordered = [];
|
|
246
235
|
const natural = [];
|
|
247
|
-
for (
|
|
248
|
-
|
|
249
|
-
if (element) {
|
|
250
|
-
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
251
|
-
target[target.length] = element;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
255
|
-
let count = 0;
|
|
256
|
-
const sorted = new Array(ordered.length + natural.length);
|
|
257
|
-
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
258
|
-
sorted[count++] = ordered[i];
|
|
259
|
-
}
|
|
260
|
-
for (let i = 0, l = natural.length; i < l; i++) {
|
|
261
|
-
sorted[count++] = natural[i];
|
|
236
|
+
for (const e of elements) {
|
|
237
|
+
(getTabIndex(e) > 0 ? ordered : natural).push(e);
|
|
262
238
|
}
|
|
263
|
-
return
|
|
239
|
+
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
264
240
|
}
|
|
265
241
|
function containsComposed(container, element) {
|
|
266
242
|
let current = element;
|
|
@@ -275,7 +251,7 @@ function containsComposed(container, element) {
|
|
|
275
251
|
}
|
|
276
252
|
function getComposedChildren(node) {
|
|
277
253
|
if (node instanceof ShadowRoot) {
|
|
278
|
-
return
|
|
254
|
+
return [...node.children];
|
|
279
255
|
}
|
|
280
256
|
if (!(node instanceof Element)) {
|
|
281
257
|
return [];
|
|
@@ -287,9 +263,9 @@ function getComposedChildren(node) {
|
|
|
287
263
|
}
|
|
288
264
|
}
|
|
289
265
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
290
|
-
return
|
|
266
|
+
return [...node.shadowRoot.children];
|
|
291
267
|
}
|
|
292
|
-
return
|
|
268
|
+
return [...node.children];
|
|
293
269
|
}
|
|
294
270
|
function focusElement(element) {
|
|
295
271
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -301,13 +277,6 @@ function getActiveElement() {
|
|
|
301
277
|
}
|
|
302
278
|
return current;
|
|
303
279
|
}
|
|
304
|
-
function getChildren(node) {
|
|
305
|
-
const elements = [];
|
|
306
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
307
|
-
elements[elements.length] = child;
|
|
308
|
-
}
|
|
309
|
-
return elements;
|
|
310
|
-
}
|
|
311
280
|
function getTabIndex(element) {
|
|
312
281
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
313
282
|
}
|
|
@@ -381,7 +350,7 @@ function resolveOptions(options) {
|
|
|
381
350
|
}
|
|
382
351
|
|
|
383
352
|
// src/index.ts
|
|
384
|
-
var VISUALLY_HIDDEN_CSS =
|
|
353
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
385
354
|
function createPortal(host, container = document.body, options = {}) {
|
|
386
355
|
if (!(host instanceof Element)) {
|
|
387
356
|
console.warn("Invalid host element");
|
|
@@ -443,9 +412,9 @@ var Portal = class {
|
|
|
443
412
|
this.#update();
|
|
444
413
|
this.#controller = new AbortController();
|
|
445
414
|
const { signal } = this.#controller;
|
|
446
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
447
|
-
|
|
448
|
-
}
|
|
415
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
416
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
417
|
+
}
|
|
449
418
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
450
419
|
this.#host.setAttribute("data-portaled", "");
|
|
451
420
|
}
|
|
@@ -503,17 +472,17 @@ var Portal = class {
|
|
|
503
472
|
...this.#getFocusables(),
|
|
504
473
|
...getFocusables(this.#host, { composed: true })
|
|
505
474
|
]);
|
|
506
|
-
for (const
|
|
507
|
-
if (!current.has(
|
|
508
|
-
restoreAttributes(
|
|
509
|
-
this.#focusables.delete(
|
|
475
|
+
for (const f of this.#focusables) {
|
|
476
|
+
if (!current.has(f)) {
|
|
477
|
+
restoreAttributes(f);
|
|
478
|
+
this.#focusables.delete(f);
|
|
510
479
|
}
|
|
511
480
|
}
|
|
512
|
-
for (const
|
|
513
|
-
if (!this.#focusables.has(
|
|
514
|
-
this.#focusables.add(
|
|
515
|
-
saveAttributes(
|
|
516
|
-
|
|
481
|
+
for (const f of current) {
|
|
482
|
+
if (!this.#focusables.has(f)) {
|
|
483
|
+
this.#focusables.add(f);
|
|
484
|
+
saveAttributes(f, "tabindex");
|
|
485
|
+
f.setAttribute("tabindex", "-1");
|
|
517
486
|
}
|
|
518
487
|
}
|
|
519
488
|
}
|
|
@@ -568,7 +537,7 @@ function resolveOptions2(options) {
|
|
|
568
537
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
569
538
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
570
539
|
*
|
|
571
|
-
* @version 1.3.
|
|
540
|
+
* @version 1.3.7
|
|
572
541
|
* @author Yusuke Kamiyamane
|
|
573
542
|
* @license MIT
|
|
574
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -580,7 +549,7 @@ function resolveOptions2(options) {
|
|
|
580
549
|
(**
|
|
581
550
|
* Attribute Utils
|
|
582
551
|
*
|
|
583
|
-
* @version 2.0.
|
|
552
|
+
* @version 2.0.11
|
|
584
553
|
* @author Yusuke Kamiyamane
|
|
585
554
|
* @license MIT
|
|
586
555
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -593,7 +562,7 @@ power-focusable/dist/index.js:
|
|
|
593
562
|
* High-precision focus management utility with full composed tree support.
|
|
594
563
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
595
564
|
*
|
|
596
|
-
* @version 4.3.
|
|
565
|
+
* @version 4.3.31
|
|
597
566
|
* @author Yusuke Kamiyamane
|
|
598
567
|
* @license MIT
|
|
599
568
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
// node_modules/@y14e/attribute-utils/dist/index.js
|
|
2
2
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
3
3
|
function restoreAttributes(element_or_elements) {
|
|
4
|
-
for (const
|
|
5
|
-
const snapshot = snapshots.get(
|
|
4
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
5
|
+
const snapshot = snapshots.get(e);
|
|
6
6
|
if (!snapshot) {
|
|
7
7
|
continue;
|
|
8
8
|
}
|
|
9
|
-
for (const [
|
|
10
|
-
|
|
9
|
+
for (const [n, v] of snapshot.entries()) {
|
|
10
|
+
v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
|
|
11
11
|
}
|
|
12
|
-
snapshots.delete(
|
|
12
|
+
snapshots.delete(e);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function saveAttributes(element_or_elements, name_or_names) {
|
|
16
16
|
const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
|
|
17
|
-
(Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements])
|
|
18
|
-
let snapshot = snapshots.get(
|
|
17
|
+
for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
18
|
+
let snapshot = snapshots.get(e);
|
|
19
19
|
if (!snapshot) {
|
|
20
20
|
snapshot = /* @__PURE__ */ new Map();
|
|
21
|
-
snapshots.set(
|
|
21
|
+
snapshots.set(e, snapshot);
|
|
22
22
|
}
|
|
23
|
-
names
|
|
24
|
-
snapshot.set(
|
|
25
|
-
}
|
|
26
|
-
}
|
|
23
|
+
for (const n of names) {
|
|
24
|
+
snapshot.set(n, e.getAttribute(n));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// node_modules/power-focusable/dist/index.js
|
|
30
|
-
var FOCUSABLE_SELECTOR =
|
|
30
|
+
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"])';
|
|
31
31
|
var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
|
|
32
32
|
/(,\s*)?\[tabindex="-1"\]/g,
|
|
33
33
|
""
|
|
@@ -51,31 +51,21 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
51
51
|
skipNegativeTabIndexCheck,
|
|
52
52
|
skipVisibilityCheck
|
|
53
53
|
}) || include?.(node)) {
|
|
54
|
-
candidates
|
|
55
|
-
}
|
|
56
|
-
const children2 = composed ? getComposedChildren(node) : getChildren(node);
|
|
57
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
58
|
-
const child = children2[i];
|
|
59
|
-
child && traverse2(child);
|
|
54
|
+
candidates.push(node);
|
|
60
55
|
}
|
|
56
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
61
57
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
child && traverse2(child);
|
|
66
|
-
}
|
|
58
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
59
|
+
traverse2
|
|
60
|
+
);
|
|
67
61
|
} else {
|
|
68
|
-
const
|
|
62
|
+
for (const m of container.querySelectorAll(
|
|
69
63
|
skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
const matched = matches[i];
|
|
73
|
-
if (matched && isFocusable(matched, {
|
|
64
|
+
)) {
|
|
65
|
+
m && isFocusable(m, {
|
|
74
66
|
skipNegativeTabIndexCheck,
|
|
75
67
|
skipVisibilityCheck
|
|
76
|
-
}))
|
|
77
|
-
candidates[candidates.length] = matched;
|
|
78
|
-
}
|
|
68
|
+
}) && candidates.push(m);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
71
|
return normalizeRadioGroup(
|
|
@@ -191,74 +181,60 @@ function isDisabledDeep(element) {
|
|
|
191
181
|
}
|
|
192
182
|
function normalizeRadioGroup(elements) {
|
|
193
183
|
let map = null;
|
|
194
|
-
for (
|
|
195
|
-
|
|
196
|
-
if (!(element instanceof HTMLInputElement)) {
|
|
184
|
+
for (const e of elements) {
|
|
185
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
197
186
|
continue;
|
|
198
187
|
}
|
|
199
|
-
if (!isUngroupedRadio(
|
|
188
|
+
if (!isUngroupedRadio(e)) {
|
|
200
189
|
continue;
|
|
201
190
|
}
|
|
202
191
|
if (!map) {
|
|
203
192
|
map = /* @__PURE__ */ new Map();
|
|
204
193
|
}
|
|
205
|
-
const root =
|
|
206
|
-
let
|
|
207
|
-
if (!
|
|
208
|
-
|
|
209
|
-
map.set(root,
|
|
194
|
+
const root = e.getRootNode();
|
|
195
|
+
let groups = map.get(root);
|
|
196
|
+
if (!groups) {
|
|
197
|
+
groups = /* @__PURE__ */ new Map();
|
|
198
|
+
map.set(root, groups);
|
|
210
199
|
}
|
|
211
|
-
let
|
|
212
|
-
if (!
|
|
213
|
-
|
|
214
|
-
|
|
200
|
+
let group = groups.get(e.form);
|
|
201
|
+
if (!group) {
|
|
202
|
+
group = /* @__PURE__ */ new Map();
|
|
203
|
+
groups.set(e.form, group);
|
|
215
204
|
}
|
|
216
|
-
let
|
|
217
|
-
if (!
|
|
218
|
-
|
|
219
|
-
|
|
205
|
+
let radios = group.get(e.name);
|
|
206
|
+
if (!radios) {
|
|
207
|
+
radios = [];
|
|
208
|
+
group.set(e.name, radios);
|
|
220
209
|
}
|
|
221
|
-
|
|
210
|
+
radios.push(e);
|
|
222
211
|
}
|
|
223
212
|
if (!map) {
|
|
224
213
|
return elements;
|
|
225
214
|
}
|
|
226
215
|
const placeholder = /* @__PURE__ */ new Set();
|
|
227
|
-
for (const
|
|
228
|
-
for (const
|
|
229
|
-
for (const
|
|
230
|
-
const radio =
|
|
216
|
+
for (const v of map.values()) {
|
|
217
|
+
for (const w of v.values()) {
|
|
218
|
+
for (const x of w.values()) {
|
|
219
|
+
const radio = x.find((r) => r.checked) ?? x[0];
|
|
231
220
|
radio && placeholder.add(radio);
|
|
232
221
|
}
|
|
233
222
|
}
|
|
234
223
|
}
|
|
235
|
-
return elements.filter((
|
|
236
|
-
if (!(
|
|
224
|
+
return elements.filter((e) => {
|
|
225
|
+
if (!(e instanceof HTMLInputElement)) {
|
|
237
226
|
return true;
|
|
238
227
|
}
|
|
239
|
-
return !isUngroupedRadio(
|
|
228
|
+
return !isUngroupedRadio(e) || placeholder.has(e);
|
|
240
229
|
});
|
|
241
230
|
}
|
|
242
231
|
function sortByTabIndex(elements) {
|
|
243
232
|
const ordered = [];
|
|
244
233
|
const natural = [];
|
|
245
|
-
for (
|
|
246
|
-
|
|
247
|
-
if (element) {
|
|
248
|
-
const target = getTabIndex(element) > 0 ? ordered : natural;
|
|
249
|
-
target[target.length] = element;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
|
|
253
|
-
let count = 0;
|
|
254
|
-
const sorted = new Array(ordered.length + natural.length);
|
|
255
|
-
for (let i = 0, l = ordered.length; i < l; i++) {
|
|
256
|
-
sorted[count++] = ordered[i];
|
|
257
|
-
}
|
|
258
|
-
for (let i = 0, l = natural.length; i < l; i++) {
|
|
259
|
-
sorted[count++] = natural[i];
|
|
234
|
+
for (const e of elements) {
|
|
235
|
+
(getTabIndex(e) > 0 ? ordered : natural).push(e);
|
|
260
236
|
}
|
|
261
|
-
return
|
|
237
|
+
return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
|
|
262
238
|
}
|
|
263
239
|
function containsComposed(container, element) {
|
|
264
240
|
let current = element;
|
|
@@ -273,7 +249,7 @@ function containsComposed(container, element) {
|
|
|
273
249
|
}
|
|
274
250
|
function getComposedChildren(node) {
|
|
275
251
|
if (node instanceof ShadowRoot) {
|
|
276
|
-
return
|
|
252
|
+
return [...node.children];
|
|
277
253
|
}
|
|
278
254
|
if (!(node instanceof Element)) {
|
|
279
255
|
return [];
|
|
@@ -285,9 +261,9 @@ function getComposedChildren(node) {
|
|
|
285
261
|
}
|
|
286
262
|
}
|
|
287
263
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
288
|
-
return
|
|
264
|
+
return [...node.shadowRoot.children];
|
|
289
265
|
}
|
|
290
|
-
return
|
|
266
|
+
return [...node.children];
|
|
291
267
|
}
|
|
292
268
|
function focusElement(element) {
|
|
293
269
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -299,13 +275,6 @@ function getActiveElement() {
|
|
|
299
275
|
}
|
|
300
276
|
return current;
|
|
301
277
|
}
|
|
302
|
-
function getChildren(node) {
|
|
303
|
-
const elements = [];
|
|
304
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
305
|
-
elements[elements.length] = child;
|
|
306
|
-
}
|
|
307
|
-
return elements;
|
|
308
|
-
}
|
|
309
278
|
function getTabIndex(element) {
|
|
310
279
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
311
280
|
}
|
|
@@ -379,7 +348,7 @@ function resolveOptions(options) {
|
|
|
379
348
|
}
|
|
380
349
|
|
|
381
350
|
// src/index.ts
|
|
382
|
-
var VISUALLY_HIDDEN_CSS =
|
|
351
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
383
352
|
function createPortal(host, container = document.body, options = {}) {
|
|
384
353
|
if (!(host instanceof Element)) {
|
|
385
354
|
console.warn("Invalid host element");
|
|
@@ -441,9 +410,9 @@ var Portal = class {
|
|
|
441
410
|
this.#update();
|
|
442
411
|
this.#controller = new AbortController();
|
|
443
412
|
const { signal } = this.#controller;
|
|
444
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
445
|
-
|
|
446
|
-
}
|
|
413
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
414
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
415
|
+
}
|
|
447
416
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
448
417
|
this.#host.setAttribute("data-portaled", "");
|
|
449
418
|
}
|
|
@@ -501,17 +470,17 @@ var Portal = class {
|
|
|
501
470
|
...this.#getFocusables(),
|
|
502
471
|
...getFocusables(this.#host, { composed: true })
|
|
503
472
|
]);
|
|
504
|
-
for (const
|
|
505
|
-
if (!current.has(
|
|
506
|
-
restoreAttributes(
|
|
507
|
-
this.#focusables.delete(
|
|
473
|
+
for (const f of this.#focusables) {
|
|
474
|
+
if (!current.has(f)) {
|
|
475
|
+
restoreAttributes(f);
|
|
476
|
+
this.#focusables.delete(f);
|
|
508
477
|
}
|
|
509
478
|
}
|
|
510
|
-
for (const
|
|
511
|
-
if (!this.#focusables.has(
|
|
512
|
-
this.#focusables.add(
|
|
513
|
-
saveAttributes(
|
|
514
|
-
|
|
479
|
+
for (const f of current) {
|
|
480
|
+
if (!this.#focusables.has(f)) {
|
|
481
|
+
this.#focusables.add(f);
|
|
482
|
+
saveAttributes(f, "tabindex");
|
|
483
|
+
f.setAttribute("tabindex", "-1");
|
|
515
484
|
}
|
|
516
485
|
}
|
|
517
486
|
}
|
|
@@ -566,7 +535,7 @@ function resolveOptions2(options) {
|
|
|
566
535
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
567
536
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
568
537
|
*
|
|
569
|
-
* @version 1.3.
|
|
538
|
+
* @version 1.3.7
|
|
570
539
|
* @author Yusuke Kamiyamane
|
|
571
540
|
* @license MIT
|
|
572
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -578,7 +547,7 @@ function resolveOptions2(options) {
|
|
|
578
547
|
(**
|
|
579
548
|
* Attribute Utils
|
|
580
549
|
*
|
|
581
|
-
* @version 2.0.
|
|
550
|
+
* @version 2.0.11
|
|
582
551
|
* @author Yusuke Kamiyamane
|
|
583
552
|
* @license MIT
|
|
584
553
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -591,7 +560,7 @@ power-focusable/dist/index.js:
|
|
|
591
560
|
* High-precision focus management utility with full composed tree support.
|
|
592
561
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
593
562
|
*
|
|
594
|
-
* @version 4.3.
|
|
563
|
+
* @version 4.3.31
|
|
595
564
|
* @author Yusuke Kamiyamane
|
|
596
565
|
* @license MIT
|
|
597
566
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var utils__namespace = /*#__PURE__*/_interopNamespace(utils);
|
|
|
25
25
|
var pf__namespace = /*#__PURE__*/_interopNamespace(pf);
|
|
26
26
|
|
|
27
27
|
// src/index.ts
|
|
28
|
-
var VISUALLY_HIDDEN_CSS =
|
|
28
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
29
29
|
function createPortal(host, container = document.body, options = {}) {
|
|
30
30
|
if (!(host instanceof Element)) {
|
|
31
31
|
console.warn("Invalid host element");
|
|
@@ -87,9 +87,9 @@ var Portal = class {
|
|
|
87
87
|
this.#update();
|
|
88
88
|
this.#controller = new AbortController();
|
|
89
89
|
const { signal } = this.#controller;
|
|
90
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
91
|
-
|
|
92
|
-
}
|
|
90
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
91
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
92
|
+
}
|
|
93
93
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
94
94
|
this.#host.setAttribute("data-portaled", "");
|
|
95
95
|
}
|
|
@@ -147,17 +147,17 @@ var Portal = class {
|
|
|
147
147
|
...this.#getFocusables(),
|
|
148
148
|
...pf__namespace.getFocusables(this.#host, { composed: true })
|
|
149
149
|
]);
|
|
150
|
-
for (const
|
|
151
|
-
if (!current.has(
|
|
152
|
-
utils__namespace.restoreAttributes(
|
|
153
|
-
this.#focusables.delete(
|
|
150
|
+
for (const f of this.#focusables) {
|
|
151
|
+
if (!current.has(f)) {
|
|
152
|
+
utils__namespace.restoreAttributes(f);
|
|
153
|
+
this.#focusables.delete(f);
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
for (const
|
|
157
|
-
if (!this.#focusables.has(
|
|
158
|
-
this.#focusables.add(
|
|
159
|
-
utils__namespace.saveAttributes(
|
|
160
|
-
|
|
156
|
+
for (const f of current) {
|
|
157
|
+
if (!this.#focusables.has(f)) {
|
|
158
|
+
this.#focusables.add(f);
|
|
159
|
+
utils__namespace.saveAttributes(f, "tabindex");
|
|
160
|
+
f.setAttribute("tabindex", "-1");
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -212,7 +212,7 @@ function resolveOptions(options) {
|
|
|
212
212
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
213
213
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
214
214
|
*
|
|
215
|
-
* @version 1.3.
|
|
215
|
+
* @version 1.3.7
|
|
216
216
|
* @author Yusuke Kamiyamane
|
|
217
217
|
* @license MIT
|
|
218
218
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
4
4
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.3.
|
|
6
|
+
* @version 1.3.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
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
4
4
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.3.
|
|
6
|
+
* @version 1.3.7
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as utils from '@y14e/attribute-utils';
|
|
|
2
2
|
import * as pf from 'power-focusable';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
var VISUALLY_HIDDEN_CSS =
|
|
5
|
+
var VISUALLY_HIDDEN_CSS = "border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;";
|
|
6
6
|
function createPortal(host, container = document.body, options = {}) {
|
|
7
7
|
if (!(host instanceof Element)) {
|
|
8
8
|
console.warn("Invalid host element");
|
|
@@ -64,9 +64,9 @@ var Portal = class {
|
|
|
64
64
|
this.#update();
|
|
65
65
|
this.#controller = new AbortController();
|
|
66
66
|
const { signal } = this.#controller;
|
|
67
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
68
|
-
|
|
69
|
-
}
|
|
67
|
+
for (const s of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
68
|
+
s.addEventListener("focus", this.#onFocus, { signal });
|
|
69
|
+
}
|
|
70
70
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
71
71
|
this.#host.setAttribute("data-portaled", "");
|
|
72
72
|
}
|
|
@@ -124,17 +124,17 @@ var Portal = class {
|
|
|
124
124
|
...this.#getFocusables(),
|
|
125
125
|
...pf.getFocusables(this.#host, { composed: true })
|
|
126
126
|
]);
|
|
127
|
-
for (const
|
|
128
|
-
if (!current.has(
|
|
129
|
-
utils.restoreAttributes(
|
|
130
|
-
this.#focusables.delete(
|
|
127
|
+
for (const f of this.#focusables) {
|
|
128
|
+
if (!current.has(f)) {
|
|
129
|
+
utils.restoreAttributes(f);
|
|
130
|
+
this.#focusables.delete(f);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
for (const
|
|
134
|
-
if (!this.#focusables.has(
|
|
135
|
-
this.#focusables.add(
|
|
136
|
-
utils.saveAttributes(
|
|
137
|
-
|
|
133
|
+
for (const f of current) {
|
|
134
|
+
if (!this.#focusables.has(f)) {
|
|
135
|
+
this.#focusables.add(f);
|
|
136
|
+
utils.saveAttributes(f, "tabindex");
|
|
137
|
+
f.setAttribute("tabindex", "-1");
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -189,7 +189,7 @@ function resolveOptions(options) {
|
|
|
189
189
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
190
190
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
191
191
|
*
|
|
192
|
-
* @version 1.3.
|
|
192
|
+
* @version 1.3.7
|
|
193
193
|
* @author Yusuke Kamiyamane
|
|
194
194
|
* @license MIT
|
|
195
195
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -46,10 +46,6 @@
|
|
|
46
46
|
"lint": "tsc --noEmit",
|
|
47
47
|
"prepublishOnly": "npm run build"
|
|
48
48
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"@y14e/attribute-utils": "^2.0.8",
|
|
51
|
-
"power-focusable": "^4.3.29"
|
|
52
|
-
},
|
|
53
49
|
"devDependencies": {
|
|
54
50
|
"bun-types": "latest",
|
|
55
51
|
"tsup": "^8.0.0",
|
|
@@ -60,5 +56,9 @@
|
|
|
60
56
|
},
|
|
61
57
|
"allowScripts": {
|
|
62
58
|
"esbuild": true
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@y14e/attribute-utils": "^2.0.11",
|
|
62
|
+
"power-focusable": "^4.3.31"
|
|
63
63
|
}
|
|
64
64
|
}
|