@y14e/portal 1.2.27 → 1.2.28
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 +4 -31
- package/dist/index.bundle.js +4 -31
- package/dist/index.cjs +4 -31
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -32
- package/package.json +1 -1
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.2.
|
|
16
|
+
import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.28';
|
|
17
17
|
// or
|
|
18
|
-
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.
|
|
18
|
+
import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.28/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.
|
|
20
|
+
import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.28';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -388,7 +388,6 @@ var Portal = class {
|
|
|
388
388
|
#exitSentinel;
|
|
389
389
|
#focusables = /* @__PURE__ */ new Set();
|
|
390
390
|
#controller = null;
|
|
391
|
-
#timer;
|
|
392
391
|
#isDestroyed = false;
|
|
393
392
|
constructor(host, container) {
|
|
394
393
|
this.#host = host;
|
|
@@ -408,10 +407,6 @@ var Portal = class {
|
|
|
408
407
|
this.#isDestroyed = true;
|
|
409
408
|
this.#controller?.abort();
|
|
410
409
|
this.#controller = null;
|
|
411
|
-
if (this.#timer !== void 0) {
|
|
412
|
-
cancelAnimationFrame(this.#timer);
|
|
413
|
-
this.#timer = void 0;
|
|
414
|
-
}
|
|
415
410
|
restoreAttributes([...this.#focusables]);
|
|
416
411
|
this.#focusables.clear();
|
|
417
412
|
this.#exitSentinel.after(this.#host);
|
|
@@ -448,15 +443,7 @@ var Portal = class {
|
|
|
448
443
|
}
|
|
449
444
|
this.#update();
|
|
450
445
|
const first = [...this.#focusables][0];
|
|
451
|
-
|
|
452
|
-
focusElement(first);
|
|
453
|
-
} else {
|
|
454
|
-
const next = getNextFocusable(document.body, {
|
|
455
|
-
anchor: this.#exitSentinel,
|
|
456
|
-
composed: true
|
|
457
|
-
});
|
|
458
|
-
next && focusElement(next);
|
|
459
|
-
}
|
|
446
|
+
first ? focusElement(first) : this.#moveFocus("next");
|
|
460
447
|
} else {
|
|
461
448
|
if (this.#host.contains(previous)) {
|
|
462
449
|
this.#moveFocus("next");
|
|
@@ -464,15 +451,7 @@ var Portal = class {
|
|
|
464
451
|
}
|
|
465
452
|
this.#update();
|
|
466
453
|
const last = [...this.#focusables].at(-1);
|
|
467
|
-
|
|
468
|
-
focusElement(last);
|
|
469
|
-
} else {
|
|
470
|
-
const previous2 = getPreviousFocusable(document.body, {
|
|
471
|
-
anchor: this.#entranceSentinel,
|
|
472
|
-
composed: true
|
|
473
|
-
});
|
|
474
|
-
previous2 && focusElement(previous2);
|
|
475
|
-
}
|
|
454
|
+
last ? focusElement(last) : this.#moveFocus("previous");
|
|
476
455
|
}
|
|
477
456
|
};
|
|
478
457
|
#onKeyDown = (event) => {
|
|
@@ -526,13 +505,7 @@ var Portal = class {
|
|
|
526
505
|
return sentinel;
|
|
527
506
|
}
|
|
528
507
|
#focusSentinel(isPrevious) {
|
|
529
|
-
|
|
530
|
-
if (isPrevious) {
|
|
531
|
-
sentinel.focus();
|
|
532
|
-
} else {
|
|
533
|
-
this.#timer && cancelAnimationFrame(this.#timer);
|
|
534
|
-
this.#timer = requestAnimationFrame(() => sentinel.focus());
|
|
535
|
-
}
|
|
508
|
+
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
536
509
|
}
|
|
537
510
|
#getFocusables() {
|
|
538
511
|
return getFocusables(this.#host, {
|
|
@@ -564,7 +537,7 @@ function containsComposed2(container, element) {
|
|
|
564
537
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
565
538
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
566
539
|
*
|
|
567
|
-
* @version 1.2.
|
|
540
|
+
* @version 1.2.28
|
|
568
541
|
* @author Yusuke Kamiyamane
|
|
569
542
|
* @license MIT
|
|
570
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -386,7 +386,6 @@ var Portal = class {
|
|
|
386
386
|
#exitSentinel;
|
|
387
387
|
#focusables = /* @__PURE__ */ new Set();
|
|
388
388
|
#controller = null;
|
|
389
|
-
#timer;
|
|
390
389
|
#isDestroyed = false;
|
|
391
390
|
constructor(host, container) {
|
|
392
391
|
this.#host = host;
|
|
@@ -406,10 +405,6 @@ var Portal = class {
|
|
|
406
405
|
this.#isDestroyed = true;
|
|
407
406
|
this.#controller?.abort();
|
|
408
407
|
this.#controller = null;
|
|
409
|
-
if (this.#timer !== void 0) {
|
|
410
|
-
cancelAnimationFrame(this.#timer);
|
|
411
|
-
this.#timer = void 0;
|
|
412
|
-
}
|
|
413
408
|
restoreAttributes([...this.#focusables]);
|
|
414
409
|
this.#focusables.clear();
|
|
415
410
|
this.#exitSentinel.after(this.#host);
|
|
@@ -446,15 +441,7 @@ var Portal = class {
|
|
|
446
441
|
}
|
|
447
442
|
this.#update();
|
|
448
443
|
const first = [...this.#focusables][0];
|
|
449
|
-
|
|
450
|
-
focusElement(first);
|
|
451
|
-
} else {
|
|
452
|
-
const next = getNextFocusable(document.body, {
|
|
453
|
-
anchor: this.#exitSentinel,
|
|
454
|
-
composed: true
|
|
455
|
-
});
|
|
456
|
-
next && focusElement(next);
|
|
457
|
-
}
|
|
444
|
+
first ? focusElement(first) : this.#moveFocus("next");
|
|
458
445
|
} else {
|
|
459
446
|
if (this.#host.contains(previous)) {
|
|
460
447
|
this.#moveFocus("next");
|
|
@@ -462,15 +449,7 @@ var Portal = class {
|
|
|
462
449
|
}
|
|
463
450
|
this.#update();
|
|
464
451
|
const last = [...this.#focusables].at(-1);
|
|
465
|
-
|
|
466
|
-
focusElement(last);
|
|
467
|
-
} else {
|
|
468
|
-
const previous2 = getPreviousFocusable(document.body, {
|
|
469
|
-
anchor: this.#entranceSentinel,
|
|
470
|
-
composed: true
|
|
471
|
-
});
|
|
472
|
-
previous2 && focusElement(previous2);
|
|
473
|
-
}
|
|
452
|
+
last ? focusElement(last) : this.#moveFocus("previous");
|
|
474
453
|
}
|
|
475
454
|
};
|
|
476
455
|
#onKeyDown = (event) => {
|
|
@@ -524,13 +503,7 @@ var Portal = class {
|
|
|
524
503
|
return sentinel;
|
|
525
504
|
}
|
|
526
505
|
#focusSentinel(isPrevious) {
|
|
527
|
-
|
|
528
|
-
if (isPrevious) {
|
|
529
|
-
sentinel.focus();
|
|
530
|
-
} else {
|
|
531
|
-
this.#timer && cancelAnimationFrame(this.#timer);
|
|
532
|
-
this.#timer = requestAnimationFrame(() => sentinel.focus());
|
|
533
|
-
}
|
|
506
|
+
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
534
507
|
}
|
|
535
508
|
#getFocusables() {
|
|
536
509
|
return getFocusables(this.#host, {
|
|
@@ -562,7 +535,7 @@ function containsComposed2(container, element) {
|
|
|
562
535
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
563
536
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
564
537
|
*
|
|
565
|
-
* @version 1.2.
|
|
538
|
+
* @version 1.2.28
|
|
566
539
|
* @author Yusuke Kamiyamane
|
|
567
540
|
* @license MIT
|
|
568
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ var Portal = class {
|
|
|
31
31
|
#exitSentinel;
|
|
32
32
|
#focusables = /* @__PURE__ */ new Set();
|
|
33
33
|
#controller = null;
|
|
34
|
-
#timer;
|
|
35
34
|
#isDestroyed = false;
|
|
36
35
|
constructor(host, container) {
|
|
37
36
|
this.#host = host;
|
|
@@ -51,10 +50,6 @@ var Portal = class {
|
|
|
51
50
|
this.#isDestroyed = true;
|
|
52
51
|
this.#controller?.abort();
|
|
53
52
|
this.#controller = null;
|
|
54
|
-
if (this.#timer !== void 0) {
|
|
55
|
-
cancelAnimationFrame(this.#timer);
|
|
56
|
-
this.#timer = void 0;
|
|
57
|
-
}
|
|
58
53
|
attributesUtils.restoreAttributes([...this.#focusables]);
|
|
59
54
|
this.#focusables.clear();
|
|
60
55
|
this.#exitSentinel.after(this.#host);
|
|
@@ -91,15 +86,7 @@ var Portal = class {
|
|
|
91
86
|
}
|
|
92
87
|
this.#update();
|
|
93
88
|
const first = [...this.#focusables][0];
|
|
94
|
-
|
|
95
|
-
powerFocusable.focusElement(first);
|
|
96
|
-
} else {
|
|
97
|
-
const next = powerFocusable.getNextFocusable(document.body, {
|
|
98
|
-
anchor: this.#exitSentinel,
|
|
99
|
-
composed: true
|
|
100
|
-
});
|
|
101
|
-
next && powerFocusable.focusElement(next);
|
|
102
|
-
}
|
|
89
|
+
first ? powerFocusable.focusElement(first) : this.#moveFocus("next");
|
|
103
90
|
} else {
|
|
104
91
|
if (this.#host.contains(previous)) {
|
|
105
92
|
this.#moveFocus("next");
|
|
@@ -107,15 +94,7 @@ var Portal = class {
|
|
|
107
94
|
}
|
|
108
95
|
this.#update();
|
|
109
96
|
const last = [...this.#focusables].at(-1);
|
|
110
|
-
|
|
111
|
-
powerFocusable.focusElement(last);
|
|
112
|
-
} else {
|
|
113
|
-
const previous2 = powerFocusable.getPreviousFocusable(document.body, {
|
|
114
|
-
anchor: this.#entranceSentinel,
|
|
115
|
-
composed: true
|
|
116
|
-
});
|
|
117
|
-
previous2 && powerFocusable.focusElement(previous2);
|
|
118
|
-
}
|
|
97
|
+
last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
|
|
119
98
|
}
|
|
120
99
|
};
|
|
121
100
|
#onKeyDown = (event) => {
|
|
@@ -169,13 +148,7 @@ var Portal = class {
|
|
|
169
148
|
return sentinel;
|
|
170
149
|
}
|
|
171
150
|
#focusSentinel(isPrevious) {
|
|
172
|
-
|
|
173
|
-
if (isPrevious) {
|
|
174
|
-
sentinel.focus();
|
|
175
|
-
} else {
|
|
176
|
-
this.#timer && cancelAnimationFrame(this.#timer);
|
|
177
|
-
this.#timer = requestAnimationFrame(() => sentinel.focus());
|
|
178
|
-
}
|
|
151
|
+
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
179
152
|
}
|
|
180
153
|
#getFocusables() {
|
|
181
154
|
return powerFocusable.getFocusables(this.#host, {
|
|
@@ -207,7 +180,7 @@ function containsComposed(container, element) {
|
|
|
207
180
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
208
181
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
209
182
|
*
|
|
210
|
-
* @version 1.2.
|
|
183
|
+
* @version 1.2.28
|
|
211
184
|
* @author Yusuke Kamiyamane
|
|
212
185
|
* @license MIT
|
|
213
186
|
* @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.28
|
|
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.28
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { restoreAttributes, saveAttributes } from '@y14e/attributes-utils';
|
|
2
|
-
import { focusElement,
|
|
2
|
+
import { focusElement, getActiveElement, getFocusables, getPreviousFocusable, getNextFocusable } from 'power-focusable';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
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;`;
|
|
@@ -29,7 +29,6 @@ var Portal = class {
|
|
|
29
29
|
#exitSentinel;
|
|
30
30
|
#focusables = /* @__PURE__ */ new Set();
|
|
31
31
|
#controller = null;
|
|
32
|
-
#timer;
|
|
33
32
|
#isDestroyed = false;
|
|
34
33
|
constructor(host, container) {
|
|
35
34
|
this.#host = host;
|
|
@@ -49,10 +48,6 @@ var Portal = class {
|
|
|
49
48
|
this.#isDestroyed = true;
|
|
50
49
|
this.#controller?.abort();
|
|
51
50
|
this.#controller = null;
|
|
52
|
-
if (this.#timer !== void 0) {
|
|
53
|
-
cancelAnimationFrame(this.#timer);
|
|
54
|
-
this.#timer = void 0;
|
|
55
|
-
}
|
|
56
51
|
restoreAttributes([...this.#focusables]);
|
|
57
52
|
this.#focusables.clear();
|
|
58
53
|
this.#exitSentinel.after(this.#host);
|
|
@@ -89,15 +84,7 @@ var Portal = class {
|
|
|
89
84
|
}
|
|
90
85
|
this.#update();
|
|
91
86
|
const first = [...this.#focusables][0];
|
|
92
|
-
|
|
93
|
-
focusElement(first);
|
|
94
|
-
} else {
|
|
95
|
-
const next = getNextFocusable(document.body, {
|
|
96
|
-
anchor: this.#exitSentinel,
|
|
97
|
-
composed: true
|
|
98
|
-
});
|
|
99
|
-
next && focusElement(next);
|
|
100
|
-
}
|
|
87
|
+
first ? focusElement(first) : this.#moveFocus("next");
|
|
101
88
|
} else {
|
|
102
89
|
if (this.#host.contains(previous)) {
|
|
103
90
|
this.#moveFocus("next");
|
|
@@ -105,15 +92,7 @@ var Portal = class {
|
|
|
105
92
|
}
|
|
106
93
|
this.#update();
|
|
107
94
|
const last = [...this.#focusables].at(-1);
|
|
108
|
-
|
|
109
|
-
focusElement(last);
|
|
110
|
-
} else {
|
|
111
|
-
const previous2 = getPreviousFocusable(document.body, {
|
|
112
|
-
anchor: this.#entranceSentinel,
|
|
113
|
-
composed: true
|
|
114
|
-
});
|
|
115
|
-
previous2 && focusElement(previous2);
|
|
116
|
-
}
|
|
95
|
+
last ? focusElement(last) : this.#moveFocus("previous");
|
|
117
96
|
}
|
|
118
97
|
};
|
|
119
98
|
#onKeyDown = (event) => {
|
|
@@ -167,13 +146,7 @@ var Portal = class {
|
|
|
167
146
|
return sentinel;
|
|
168
147
|
}
|
|
169
148
|
#focusSentinel(isPrevious) {
|
|
170
|
-
|
|
171
|
-
if (isPrevious) {
|
|
172
|
-
sentinel.focus();
|
|
173
|
-
} else {
|
|
174
|
-
this.#timer && cancelAnimationFrame(this.#timer);
|
|
175
|
-
this.#timer = requestAnimationFrame(() => sentinel.focus());
|
|
176
|
-
}
|
|
149
|
+
(isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
|
|
177
150
|
}
|
|
178
151
|
#getFocusables() {
|
|
179
152
|
return getFocusables(this.#host, {
|
|
@@ -205,7 +178,7 @@ function containsComposed(container, element) {
|
|
|
205
178
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
206
179
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
207
180
|
*
|
|
208
|
-
* @version 1.2.
|
|
181
|
+
* @version 1.2.28
|
|
209
182
|
* @author Yusuke Kamiyamane
|
|
210
183
|
* @license MIT
|
|
211
184
|
* @copyright Copyright (c) Yusuke Kamiyamane
|