@y14e/portal 1.2.4 → 1.2.5
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 +48 -28
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +48 -28
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
4
4
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
function restoreAttributes(elements) {
|
|
6
|
-
|
|
6
|
+
for (const element of elements) {
|
|
7
7
|
const snapshot = snapshots.get(element);
|
|
8
8
|
if (!snapshot) {
|
|
9
|
-
|
|
9
|
+
continue;
|
|
10
10
|
}
|
|
11
11
|
for (const [attribute, value] of snapshot.entries()) {
|
|
12
12
|
if (value === null) {
|
|
@@ -16,7 +16,7 @@ function restoreAttributes(elements) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
snapshots.delete(element);
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
}
|
|
21
21
|
function saveAttributes(elements, attributes) {
|
|
22
22
|
elements.forEach((element) => {
|
|
@@ -38,14 +38,17 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
38
38
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
39
39
|
container = document.body;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
let { composed = false, filter, include } = options;
|
|
42
|
+
if (typeof composed !== "boolean") {
|
|
43
|
+
console.warn("Invalid composed. Fallback: false.");
|
|
44
|
+
composed = false;
|
|
45
|
+
}
|
|
46
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
47
|
+
console.warn("Invalid filter. Fallback: no filter function (undefined).");
|
|
45
48
|
filter = void 0;
|
|
46
49
|
}
|
|
47
|
-
if (include && typeof include !== "function") {
|
|
48
|
-
console.warn("Invalid include function");
|
|
50
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
51
|
+
console.warn("Invalid include. Fallback: no include function (undefined).");
|
|
49
52
|
include = void 0;
|
|
50
53
|
}
|
|
51
54
|
const elements = [];
|
|
@@ -82,17 +85,9 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
82
85
|
return filter ? unfiltered.filter(filter) : unfiltered;
|
|
83
86
|
}
|
|
84
87
|
function getNextFocusable(container = document.body, options = {}) {
|
|
85
|
-
if (!(container instanceof Element)) {
|
|
86
|
-
console.warn("Invalid container element. Fallback: <body> element.");
|
|
87
|
-
container = document.body;
|
|
88
|
-
}
|
|
89
88
|
return getRelativeFocusable(container, 1, options);
|
|
90
89
|
}
|
|
91
90
|
function getPreviousFocusable(container = document.body, options = {}) {
|
|
92
|
-
if (!(container instanceof Element)) {
|
|
93
|
-
console.warn("Invalid container element. Fallback: <body> element.");
|
|
94
|
-
container = document.body;
|
|
95
|
-
}
|
|
96
91
|
return getRelativeFocusable(container, -1, options);
|
|
97
92
|
}
|
|
98
93
|
function isFocusable(element) {
|
|
@@ -122,8 +117,17 @@ function isFocusable(element) {
|
|
|
122
117
|
return true;
|
|
123
118
|
}
|
|
124
119
|
function getRelativeFocusable(container, offset, options) {
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
if (!(container instanceof Element)) {
|
|
121
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
122
|
+
container = document.body;
|
|
123
|
+
}
|
|
124
|
+
let {
|
|
125
|
+
anchor = getActiveElement(),
|
|
126
|
+
composed = false,
|
|
127
|
+
filter,
|
|
128
|
+
include,
|
|
129
|
+
wrap = false
|
|
130
|
+
} = options;
|
|
127
131
|
if (!(anchor instanceof Element)) {
|
|
128
132
|
const active = getActiveElement();
|
|
129
133
|
if (active instanceof Element) {
|
|
@@ -138,6 +142,22 @@ function getRelativeFocusable(container, offset, options) {
|
|
|
138
142
|
console.warn("Anchor (active) element not within container");
|
|
139
143
|
return null;
|
|
140
144
|
}
|
|
145
|
+
if (typeof composed !== "boolean") {
|
|
146
|
+
console.warn("Invalid composed. Fallback: false.");
|
|
147
|
+
composed = false;
|
|
148
|
+
}
|
|
149
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
150
|
+
console.warn("Invalid filter. Fallback: no filter function (undefined).");
|
|
151
|
+
filter = void 0;
|
|
152
|
+
}
|
|
153
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
154
|
+
console.warn("Invalid include. Fallback: no include function (undefined).");
|
|
155
|
+
include = void 0;
|
|
156
|
+
}
|
|
157
|
+
if (typeof wrap !== "boolean") {
|
|
158
|
+
console.warn("Invalid wrap. Fallback: false.");
|
|
159
|
+
wrap = false;
|
|
160
|
+
}
|
|
141
161
|
const focusables = getFocusables(container, { composed, filter, include });
|
|
142
162
|
const { length } = focusables;
|
|
143
163
|
if (!length) {
|
|
@@ -427,23 +447,23 @@ var Portal = class {
|
|
|
427
447
|
...this.#getFocusables(),
|
|
428
448
|
...getFocusables(this.#host, { composed: true })
|
|
429
449
|
]);
|
|
430
|
-
this.#focusables
|
|
450
|
+
for (const focusable of this.#focusables) {
|
|
431
451
|
if (current.has(focusable)) {
|
|
432
|
-
|
|
452
|
+
continue;
|
|
433
453
|
}
|
|
434
454
|
if (focusable.isConnected) {
|
|
435
455
|
restoreAttributes([focusable]);
|
|
436
456
|
}
|
|
437
457
|
this.#focusables.delete(focusable);
|
|
438
|
-
}
|
|
439
|
-
|
|
458
|
+
}
|
|
459
|
+
for (const c of current) {
|
|
440
460
|
if (this.#focusables.has(c)) {
|
|
441
|
-
|
|
461
|
+
continue;
|
|
442
462
|
}
|
|
443
463
|
this.#focusables.add(c);
|
|
444
464
|
saveAttributes([c], ["tabindex"]);
|
|
445
465
|
c.setAttribute("tabindex", "-1");
|
|
446
|
-
}
|
|
466
|
+
}
|
|
447
467
|
}
|
|
448
468
|
#createSentinel() {
|
|
449
469
|
const sentinel = document.createElement("span");
|
|
@@ -498,7 +518,7 @@ function getActiveElement2() {
|
|
|
498
518
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
499
519
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
500
520
|
*
|
|
501
|
-
* @version 1.2.
|
|
521
|
+
* @version 1.2.5
|
|
502
522
|
* @author Yusuke Kamiyamane
|
|
503
523
|
* @license MIT
|
|
504
524
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -510,7 +530,7 @@ function getActiveElement2() {
|
|
|
510
530
|
(**
|
|
511
531
|
* Attributes Utils
|
|
512
532
|
*
|
|
513
|
-
* @version 1.0.
|
|
533
|
+
* @version 1.0.2
|
|
514
534
|
* @author Yusuke Kamiyamane
|
|
515
535
|
* @license MIT
|
|
516
536
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -523,7 +543,7 @@ power-focusable/dist/index.js:
|
|
|
523
543
|
* High-precision focus management utility with full composed tree support.
|
|
524
544
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
525
545
|
*
|
|
526
|
-
* @version 4.1.
|
|
546
|
+
* @version 4.1.7
|
|
527
547
|
* @author Yusuke Kamiyamane
|
|
528
548
|
* @license MIT
|
|
529
549
|
* @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.2.
|
|
6
|
+
* @version 1.2.5
|
|
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.2.
|
|
6
|
+
* @version 1.2.5
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// node_modules/@y14e/attributes-utils/dist/index.js
|
|
2
2
|
var snapshots = /* @__PURE__ */ new WeakMap();
|
|
3
3
|
function restoreAttributes(elements) {
|
|
4
|
-
|
|
4
|
+
for (const element of elements) {
|
|
5
5
|
const snapshot = snapshots.get(element);
|
|
6
6
|
if (!snapshot) {
|
|
7
|
-
|
|
7
|
+
continue;
|
|
8
8
|
}
|
|
9
9
|
for (const [attribute, value] of snapshot.entries()) {
|
|
10
10
|
if (value === null) {
|
|
@@ -14,7 +14,7 @@ function restoreAttributes(elements) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
snapshots.delete(element);
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
function saveAttributes(elements, attributes) {
|
|
20
20
|
elements.forEach((element) => {
|
|
@@ -36,14 +36,17 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
36
36
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
37
37
|
container = document.body;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
let { composed = false, filter, include } = options;
|
|
40
|
+
if (typeof composed !== "boolean") {
|
|
41
|
+
console.warn("Invalid composed. Fallback: false.");
|
|
42
|
+
composed = false;
|
|
43
|
+
}
|
|
44
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
45
|
+
console.warn("Invalid filter. Fallback: no filter function (undefined).");
|
|
43
46
|
filter = void 0;
|
|
44
47
|
}
|
|
45
|
-
if (include && typeof include !== "function") {
|
|
46
|
-
console.warn("Invalid include function");
|
|
48
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
49
|
+
console.warn("Invalid include. Fallback: no include function (undefined).");
|
|
47
50
|
include = void 0;
|
|
48
51
|
}
|
|
49
52
|
const elements = [];
|
|
@@ -80,17 +83,9 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
80
83
|
return filter ? unfiltered.filter(filter) : unfiltered;
|
|
81
84
|
}
|
|
82
85
|
function getNextFocusable(container = document.body, options = {}) {
|
|
83
|
-
if (!(container instanceof Element)) {
|
|
84
|
-
console.warn("Invalid container element. Fallback: <body> element.");
|
|
85
|
-
container = document.body;
|
|
86
|
-
}
|
|
87
86
|
return getRelativeFocusable(container, 1, options);
|
|
88
87
|
}
|
|
89
88
|
function getPreviousFocusable(container = document.body, options = {}) {
|
|
90
|
-
if (!(container instanceof Element)) {
|
|
91
|
-
console.warn("Invalid container element. Fallback: <body> element.");
|
|
92
|
-
container = document.body;
|
|
93
|
-
}
|
|
94
89
|
return getRelativeFocusable(container, -1, options);
|
|
95
90
|
}
|
|
96
91
|
function isFocusable(element) {
|
|
@@ -120,8 +115,17 @@ function isFocusable(element) {
|
|
|
120
115
|
return true;
|
|
121
116
|
}
|
|
122
117
|
function getRelativeFocusable(container, offset, options) {
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
if (!(container instanceof Element)) {
|
|
119
|
+
console.warn("Invalid container element. Fallback: <body> element.");
|
|
120
|
+
container = document.body;
|
|
121
|
+
}
|
|
122
|
+
let {
|
|
123
|
+
anchor = getActiveElement(),
|
|
124
|
+
composed = false,
|
|
125
|
+
filter,
|
|
126
|
+
include,
|
|
127
|
+
wrap = false
|
|
128
|
+
} = options;
|
|
125
129
|
if (!(anchor instanceof Element)) {
|
|
126
130
|
const active = getActiveElement();
|
|
127
131
|
if (active instanceof Element) {
|
|
@@ -136,6 +140,22 @@ function getRelativeFocusable(container, offset, options) {
|
|
|
136
140
|
console.warn("Anchor (active) element not within container");
|
|
137
141
|
return null;
|
|
138
142
|
}
|
|
143
|
+
if (typeof composed !== "boolean") {
|
|
144
|
+
console.warn("Invalid composed. Fallback: false.");
|
|
145
|
+
composed = false;
|
|
146
|
+
}
|
|
147
|
+
if (typeof filter !== "undefined" && typeof filter !== "function") {
|
|
148
|
+
console.warn("Invalid filter. Fallback: no filter function (undefined).");
|
|
149
|
+
filter = void 0;
|
|
150
|
+
}
|
|
151
|
+
if (typeof include !== "undefined" && typeof include !== "function") {
|
|
152
|
+
console.warn("Invalid include. Fallback: no include function (undefined).");
|
|
153
|
+
include = void 0;
|
|
154
|
+
}
|
|
155
|
+
if (typeof wrap !== "boolean") {
|
|
156
|
+
console.warn("Invalid wrap. Fallback: false.");
|
|
157
|
+
wrap = false;
|
|
158
|
+
}
|
|
139
159
|
const focusables = getFocusables(container, { composed, filter, include });
|
|
140
160
|
const { length } = focusables;
|
|
141
161
|
if (!length) {
|
|
@@ -425,23 +445,23 @@ var Portal = class {
|
|
|
425
445
|
...this.#getFocusables(),
|
|
426
446
|
...getFocusables(this.#host, { composed: true })
|
|
427
447
|
]);
|
|
428
|
-
this.#focusables
|
|
448
|
+
for (const focusable of this.#focusables) {
|
|
429
449
|
if (current.has(focusable)) {
|
|
430
|
-
|
|
450
|
+
continue;
|
|
431
451
|
}
|
|
432
452
|
if (focusable.isConnected) {
|
|
433
453
|
restoreAttributes([focusable]);
|
|
434
454
|
}
|
|
435
455
|
this.#focusables.delete(focusable);
|
|
436
|
-
}
|
|
437
|
-
|
|
456
|
+
}
|
|
457
|
+
for (const c of current) {
|
|
438
458
|
if (this.#focusables.has(c)) {
|
|
439
|
-
|
|
459
|
+
continue;
|
|
440
460
|
}
|
|
441
461
|
this.#focusables.add(c);
|
|
442
462
|
saveAttributes([c], ["tabindex"]);
|
|
443
463
|
c.setAttribute("tabindex", "-1");
|
|
444
|
-
}
|
|
464
|
+
}
|
|
445
465
|
}
|
|
446
466
|
#createSentinel() {
|
|
447
467
|
const sentinel = document.createElement("span");
|
|
@@ -496,7 +516,7 @@ function getActiveElement2() {
|
|
|
496
516
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
497
517
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
498
518
|
*
|
|
499
|
-
* @version 1.2.
|
|
519
|
+
* @version 1.2.5
|
|
500
520
|
* @author Yusuke Kamiyamane
|
|
501
521
|
* @license MIT
|
|
502
522
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -508,7 +528,7 @@ function getActiveElement2() {
|
|
|
508
528
|
(**
|
|
509
529
|
* Attributes Utils
|
|
510
530
|
*
|
|
511
|
-
* @version 1.0.
|
|
531
|
+
* @version 1.0.2
|
|
512
532
|
* @author Yusuke Kamiyamane
|
|
513
533
|
* @license MIT
|
|
514
534
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -521,7 +541,7 @@ power-focusable/dist/index.js:
|
|
|
521
541
|
* High-precision focus management utility with full composed tree support.
|
|
522
542
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
523
543
|
*
|
|
524
|
-
* @version 4.1.
|
|
544
|
+
* @version 4.1.7
|
|
525
545
|
* @author Yusuke Kamiyamane
|
|
526
546
|
* @license MIT
|
|
527
547
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/portal",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/y14e/portal#readme",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@y14e/attributes-utils": "^1.0.
|
|
50
|
+
"@y14e/attributes-utils": "^1.0.2",
|
|
51
51
|
"bun-types": "latest",
|
|
52
|
-
"power-focusable": "^4.1.
|
|
52
|
+
"power-focusable": "^4.1.7",
|
|
53
53
|
"tsup": "^8.0.0",
|
|
54
54
|
"typescript": "^5.6.0"
|
|
55
55
|
},
|