@y14e/portal 1.3.5 → 1.3.6
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 +22 -46
- package/dist/index.bundle.js +22 -46
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- 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.6';
|
|
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.6/+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.6';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -16,20 +16,20 @@ function restoreAttributes(element_or_elements) {
|
|
|
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])
|
|
19
|
+
for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
20
20
|
let snapshot = snapshots.get(element);
|
|
21
21
|
if (!snapshot) {
|
|
22
22
|
snapshot = /* @__PURE__ */ new Map();
|
|
23
23
|
snapshots.set(element, snapshot);
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
for (const name of names) {
|
|
26
26
|
snapshot.set(name, element.getAttribute(name));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
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
|
""
|
|
@@ -55,29 +55,19 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
55
55
|
}) || include?.(node)) {
|
|
56
56
|
candidates[candidates.length] = node;
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
60
|
-
const child = children2[i];
|
|
61
|
-
child && traverse2(child);
|
|
62
|
-
}
|
|
58
|
+
(composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
|
|
63
59
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
child && traverse2(child);
|
|
68
|
-
}
|
|
60
|
+
(composed ? getComposedChildren(container) : getChildren(container)).map(
|
|
61
|
+
traverse2
|
|
62
|
+
);
|
|
69
63
|
} else {
|
|
70
|
-
const
|
|
64
|
+
for (const match 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
|
+
match && isFocusable(match, {
|
|
76
68
|
skipNegativeTabIndexCheck,
|
|
77
69
|
skipVisibilityCheck
|
|
78
|
-
}))
|
|
79
|
-
candidates[candidates.length] = matched;
|
|
80
|
-
}
|
|
70
|
+
}) && candidates.push(match);
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
73
|
return normalizeRadioGroup(
|
|
@@ -193,8 +183,7 @@ function isDisabledDeep(element) {
|
|
|
193
183
|
}
|
|
194
184
|
function normalizeRadioGroup(elements) {
|
|
195
185
|
let map = null;
|
|
196
|
-
for (
|
|
197
|
-
const element = elements[i];
|
|
186
|
+
for (const element of elements) {
|
|
198
187
|
if (!(element instanceof HTMLInputElement)) {
|
|
199
188
|
continue;
|
|
200
189
|
}
|
|
@@ -244,23 +233,10 @@ function normalizeRadioGroup(elements) {
|
|
|
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];
|
|
236
|
+
for (const element of elements) {
|
|
237
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
259
238
|
}
|
|
260
|
-
|
|
261
|
-
sorted[count++] = natural[i];
|
|
262
|
-
}
|
|
263
|
-
return sorted;
|
|
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;
|
|
@@ -443,9 +419,9 @@ var Portal = class {
|
|
|
443
419
|
this.#update();
|
|
444
420
|
this.#controller = new AbortController();
|
|
445
421
|
const { signal } = this.#controller;
|
|
446
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
422
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
447
423
|
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
448
|
-
}
|
|
424
|
+
}
|
|
449
425
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
450
426
|
this.#host.setAttribute("data-portaled", "");
|
|
451
427
|
}
|
|
@@ -568,7 +544,7 @@ function resolveOptions2(options) {
|
|
|
568
544
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
569
545
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
570
546
|
*
|
|
571
|
-
* @version 1.3.
|
|
547
|
+
* @version 1.3.6
|
|
572
548
|
* @author Yusuke Kamiyamane
|
|
573
549
|
* @license MIT
|
|
574
550
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -580,7 +556,7 @@ function resolveOptions2(options) {
|
|
|
580
556
|
(**
|
|
581
557
|
* Attribute Utils
|
|
582
558
|
*
|
|
583
|
-
* @version 2.0.
|
|
559
|
+
* @version 2.0.10
|
|
584
560
|
* @author Yusuke Kamiyamane
|
|
585
561
|
* @license MIT
|
|
586
562
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -593,7 +569,7 @@ power-focusable/dist/index.js:
|
|
|
593
569
|
* High-precision focus management utility with full composed tree support.
|
|
594
570
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
595
571
|
*
|
|
596
|
-
* @version 4.3.
|
|
572
|
+
* @version 4.3.30
|
|
597
573
|
* @author Yusuke Kamiyamane
|
|
598
574
|
* @license MIT
|
|
599
575
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -14,20 +14,20 @@ function restoreAttributes(element_or_elements) {
|
|
|
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])
|
|
17
|
+
for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
|
|
18
18
|
let snapshot = snapshots.get(element);
|
|
19
19
|
if (!snapshot) {
|
|
20
20
|
snapshot = /* @__PURE__ */ new Map();
|
|
21
21
|
snapshots.set(element, snapshot);
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
for (const name of names) {
|
|
24
24
|
snapshot.set(name, element.getAttribute(name));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
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
|
""
|
|
@@ -53,29 +53,19 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
53
53
|
}) || include?.(node)) {
|
|
54
54
|
candidates[candidates.length] = node;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
for (let i = 0, l = children2.length; i < l; i++) {
|
|
58
|
-
const child = children2[i];
|
|
59
|
-
child && traverse2(child);
|
|
60
|
-
}
|
|
56
|
+
(composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
|
|
61
57
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
child && traverse2(child);
|
|
66
|
-
}
|
|
58
|
+
(composed ? getComposedChildren(container) : getChildren(container)).map(
|
|
59
|
+
traverse2
|
|
60
|
+
);
|
|
67
61
|
} else {
|
|
68
|
-
const
|
|
62
|
+
for (const match 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
|
+
match && isFocusable(match, {
|
|
74
66
|
skipNegativeTabIndexCheck,
|
|
75
67
|
skipVisibilityCheck
|
|
76
|
-
}))
|
|
77
|
-
candidates[candidates.length] = matched;
|
|
78
|
-
}
|
|
68
|
+
}) && candidates.push(match);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
71
|
return normalizeRadioGroup(
|
|
@@ -191,8 +181,7 @@ function isDisabledDeep(element) {
|
|
|
191
181
|
}
|
|
192
182
|
function normalizeRadioGroup(elements) {
|
|
193
183
|
let map = null;
|
|
194
|
-
for (
|
|
195
|
-
const element = elements[i];
|
|
184
|
+
for (const element of elements) {
|
|
196
185
|
if (!(element instanceof HTMLInputElement)) {
|
|
197
186
|
continue;
|
|
198
187
|
}
|
|
@@ -242,23 +231,10 @@ function normalizeRadioGroup(elements) {
|
|
|
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];
|
|
234
|
+
for (const element of elements) {
|
|
235
|
+
(getTabIndex(element) > 0 ? ordered : natural).push(element);
|
|
257
236
|
}
|
|
258
|
-
|
|
259
|
-
sorted[count++] = natural[i];
|
|
260
|
-
}
|
|
261
|
-
return sorted;
|
|
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;
|
|
@@ -441,9 +417,9 @@ var Portal = class {
|
|
|
441
417
|
this.#update();
|
|
442
418
|
this.#controller = new AbortController();
|
|
443
419
|
const { signal } = this.#controller;
|
|
444
|
-
[this.#entranceSentinel, this.#exitSentinel]
|
|
420
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
445
421
|
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
446
|
-
}
|
|
422
|
+
}
|
|
447
423
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
448
424
|
this.#host.setAttribute("data-portaled", "");
|
|
449
425
|
}
|
|
@@ -566,7 +542,7 @@ function resolveOptions2(options) {
|
|
|
566
542
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
567
543
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
568
544
|
*
|
|
569
|
-
* @version 1.3.
|
|
545
|
+
* @version 1.3.6
|
|
570
546
|
* @author Yusuke Kamiyamane
|
|
571
547
|
* @license MIT
|
|
572
548
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -578,7 +554,7 @@ function resolveOptions2(options) {
|
|
|
578
554
|
(**
|
|
579
555
|
* Attribute Utils
|
|
580
556
|
*
|
|
581
|
-
* @version 2.0.
|
|
557
|
+
* @version 2.0.10
|
|
582
558
|
* @author Yusuke Kamiyamane
|
|
583
559
|
* @license MIT
|
|
584
560
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -591,7 +567,7 @@ power-focusable/dist/index.js:
|
|
|
591
567
|
* High-precision focus management utility with full composed tree support.
|
|
592
568
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
593
569
|
*
|
|
594
|
-
* @version 4.3.
|
|
570
|
+
* @version 4.3.30
|
|
595
571
|
* @author Yusuke Kamiyamane
|
|
596
572
|
* @license MIT
|
|
597
573
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -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]
|
|
90
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
91
91
|
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
92
|
-
}
|
|
92
|
+
}
|
|
93
93
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
94
94
|
this.#host.setAttribute("data-portaled", "");
|
|
95
95
|
}
|
|
@@ -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.6
|
|
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.6
|
|
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.6
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -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]
|
|
67
|
+
for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
|
|
68
68
|
sentinel.addEventListener("focus", this.#onFocus, { signal });
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
|
|
71
71
|
this.#host.setAttribute("data-portaled", "");
|
|
72
72
|
}
|
|
@@ -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.6
|
|
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.6",
|
|
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.10",
|
|
62
|
+
"power-focusable": "^4.3.30"
|
|
63
63
|
}
|
|
64
64
|
}
|