@y14e/portal 1.3.6 → 1.3.8
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 +37 -44
- package/dist/index.bundle.js +37 -44
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +3 -3
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.8';
|
|
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.8/+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.8';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.bundle.cjs
CHANGED
|
@@ -3,27 +3,27 @@
|
|
|
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
|
-
for (const
|
|
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
|
-
for (const
|
|
26
|
-
snapshot.set(
|
|
25
|
+
for (const n of names) {
|
|
26
|
+
snapshot.set(n, e.getAttribute(n));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -53,11 +53,11 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
53
53
|
skipNegativeTabIndexCheck,
|
|
54
54
|
skipVisibilityCheck
|
|
55
55
|
}) || include?.(node)) {
|
|
56
|
-
candidates
|
|
56
|
+
candidates.push(node);
|
|
57
57
|
}
|
|
58
|
-
(composed ? getComposedChildren(node) :
|
|
58
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
59
59
|
};
|
|
60
|
-
(composed ? getComposedChildren(container) :
|
|
60
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
61
61
|
traverse2
|
|
62
62
|
);
|
|
63
63
|
} else {
|
|
@@ -194,31 +194,31 @@ function normalizeRadioGroup(elements) {
|
|
|
194
194
|
map = /* @__PURE__ */ new Map();
|
|
195
195
|
}
|
|
196
196
|
const root = element.getRootNode();
|
|
197
|
-
let
|
|
198
|
-
if (!
|
|
199
|
-
|
|
200
|
-
map.set(root,
|
|
197
|
+
let groups = map.get(root);
|
|
198
|
+
if (!groups) {
|
|
199
|
+
groups = /* @__PURE__ */ new Map();
|
|
200
|
+
map.set(root, groups);
|
|
201
201
|
}
|
|
202
|
-
let
|
|
203
|
-
if (!
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
let group = groups.get(element.form);
|
|
203
|
+
if (!group) {
|
|
204
|
+
group = /* @__PURE__ */ new Map();
|
|
205
|
+
groups.set(element.form, group);
|
|
206
206
|
}
|
|
207
|
-
let
|
|
208
|
-
if (!
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
let radios = group.get(element.name);
|
|
208
|
+
if (!radios) {
|
|
209
|
+
radios = [];
|
|
210
|
+
group.set(element.name, radios);
|
|
211
211
|
}
|
|
212
|
-
|
|
212
|
+
radios.push(element);
|
|
213
213
|
}
|
|
214
214
|
if (!map) {
|
|
215
215
|
return elements;
|
|
216
216
|
}
|
|
217
217
|
const placeholder = /* @__PURE__ */ new Set();
|
|
218
|
-
for (const
|
|
219
|
-
for (const
|
|
220
|
-
for (const
|
|
221
|
-
const radio =
|
|
218
|
+
for (const groups of map.values()) {
|
|
219
|
+
for (const group of groups.values()) {
|
|
220
|
+
for (const radios of group.values()) {
|
|
221
|
+
const radio = radios.find((r) => r.checked) ?? radios[0];
|
|
222
222
|
radio && placeholder.add(radio);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -251,7 +251,7 @@ function containsComposed(container, element) {
|
|
|
251
251
|
}
|
|
252
252
|
function getComposedChildren(node) {
|
|
253
253
|
if (node instanceof ShadowRoot) {
|
|
254
|
-
return
|
|
254
|
+
return [...node.children];
|
|
255
255
|
}
|
|
256
256
|
if (!(node instanceof Element)) {
|
|
257
257
|
return [];
|
|
@@ -263,9 +263,9 @@ function getComposedChildren(node) {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
266
|
-
return
|
|
266
|
+
return [...node.shadowRoot.children];
|
|
267
267
|
}
|
|
268
|
-
return
|
|
268
|
+
return [...node.children];
|
|
269
269
|
}
|
|
270
270
|
function focusElement(element) {
|
|
271
271
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -277,13 +277,6 @@ function getActiveElement() {
|
|
|
277
277
|
}
|
|
278
278
|
return current;
|
|
279
279
|
}
|
|
280
|
-
function getChildren(node) {
|
|
281
|
-
const elements = [];
|
|
282
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
283
|
-
elements[elements.length] = child;
|
|
284
|
-
}
|
|
285
|
-
return elements;
|
|
286
|
-
}
|
|
287
280
|
function getTabIndex(element) {
|
|
288
281
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
289
282
|
}
|
|
@@ -357,7 +350,7 @@ function resolveOptions(options) {
|
|
|
357
350
|
}
|
|
358
351
|
|
|
359
352
|
// src/index.ts
|
|
360
|
-
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;";
|
|
361
354
|
function createPortal(host, container = document.body, options = {}) {
|
|
362
355
|
if (!(host instanceof Element)) {
|
|
363
356
|
console.warn("Invalid host element");
|
|
@@ -544,7 +537,7 @@ function resolveOptions2(options) {
|
|
|
544
537
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
545
538
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
546
539
|
*
|
|
547
|
-
* @version 1.3.
|
|
540
|
+
* @version 1.3.8
|
|
548
541
|
* @author Yusuke Kamiyamane
|
|
549
542
|
* @license MIT
|
|
550
543
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -556,7 +549,7 @@ function resolveOptions2(options) {
|
|
|
556
549
|
(**
|
|
557
550
|
* Attribute Utils
|
|
558
551
|
*
|
|
559
|
-
* @version 2.0.
|
|
552
|
+
* @version 2.0.11
|
|
560
553
|
* @author Yusuke Kamiyamane
|
|
561
554
|
* @license MIT
|
|
562
555
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -569,7 +562,7 @@ power-focusable/dist/index.js:
|
|
|
569
562
|
* High-precision focus management utility with full composed tree support.
|
|
570
563
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
571
564
|
*
|
|
572
|
-
* @version 4.3.
|
|
565
|
+
* @version 4.3.33
|
|
573
566
|
* @author Yusuke Kamiyamane
|
|
574
567
|
* @license MIT
|
|
575
568
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.bundle.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
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
|
-
for (const
|
|
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
|
-
for (const
|
|
24
|
-
snapshot.set(
|
|
23
|
+
for (const n of names) {
|
|
24
|
+
snapshot.set(n, e.getAttribute(n));
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -51,11 +51,11 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
51
51
|
skipNegativeTabIndexCheck,
|
|
52
52
|
skipVisibilityCheck
|
|
53
53
|
}) || include?.(node)) {
|
|
54
|
-
candidates
|
|
54
|
+
candidates.push(node);
|
|
55
55
|
}
|
|
56
|
-
(composed ? getComposedChildren(node) :
|
|
56
|
+
(composed ? getComposedChildren(node) : [...node.children]).map(traverse2);
|
|
57
57
|
};
|
|
58
|
-
(composed ? getComposedChildren(container) :
|
|
58
|
+
(composed ? getComposedChildren(container) : [...container.children]).map(
|
|
59
59
|
traverse2
|
|
60
60
|
);
|
|
61
61
|
} else {
|
|
@@ -192,31 +192,31 @@ function normalizeRadioGroup(elements) {
|
|
|
192
192
|
map = /* @__PURE__ */ new Map();
|
|
193
193
|
}
|
|
194
194
|
const root = element.getRootNode();
|
|
195
|
-
let
|
|
196
|
-
if (!
|
|
197
|
-
|
|
198
|
-
map.set(root,
|
|
195
|
+
let groups = map.get(root);
|
|
196
|
+
if (!groups) {
|
|
197
|
+
groups = /* @__PURE__ */ new Map();
|
|
198
|
+
map.set(root, groups);
|
|
199
199
|
}
|
|
200
|
-
let
|
|
201
|
-
if (!
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
let group = groups.get(element.form);
|
|
201
|
+
if (!group) {
|
|
202
|
+
group = /* @__PURE__ */ new Map();
|
|
203
|
+
groups.set(element.form, group);
|
|
204
204
|
}
|
|
205
|
-
let
|
|
206
|
-
if (!
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
let radios = group.get(element.name);
|
|
206
|
+
if (!radios) {
|
|
207
|
+
radios = [];
|
|
208
|
+
group.set(element.name, radios);
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
radios.push(element);
|
|
211
211
|
}
|
|
212
212
|
if (!map) {
|
|
213
213
|
return elements;
|
|
214
214
|
}
|
|
215
215
|
const placeholder = /* @__PURE__ */ new Set();
|
|
216
|
-
for (const
|
|
217
|
-
for (const
|
|
218
|
-
for (const
|
|
219
|
-
const radio =
|
|
216
|
+
for (const groups of map.values()) {
|
|
217
|
+
for (const group of groups.values()) {
|
|
218
|
+
for (const radios of group.values()) {
|
|
219
|
+
const radio = radios.find((r) => r.checked) ?? radios[0];
|
|
220
220
|
radio && placeholder.add(radio);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
@@ -249,7 +249,7 @@ function containsComposed(container, element) {
|
|
|
249
249
|
}
|
|
250
250
|
function getComposedChildren(node) {
|
|
251
251
|
if (node instanceof ShadowRoot) {
|
|
252
|
-
return
|
|
252
|
+
return [...node.children];
|
|
253
253
|
}
|
|
254
254
|
if (!(node instanceof Element)) {
|
|
255
255
|
return [];
|
|
@@ -261,9 +261,9 @@ function getComposedChildren(node) {
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
|
|
264
|
-
return
|
|
264
|
+
return [...node.shadowRoot.children];
|
|
265
265
|
}
|
|
266
|
-
return
|
|
266
|
+
return [...node.children];
|
|
267
267
|
}
|
|
268
268
|
function focusElement(element) {
|
|
269
269
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
@@ -275,13 +275,6 @@ function getActiveElement() {
|
|
|
275
275
|
}
|
|
276
276
|
return current;
|
|
277
277
|
}
|
|
278
|
-
function getChildren(node) {
|
|
279
|
-
const elements = [];
|
|
280
|
-
for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
|
|
281
|
-
elements[elements.length] = child;
|
|
282
|
-
}
|
|
283
|
-
return elements;
|
|
284
|
-
}
|
|
285
278
|
function getTabIndex(element) {
|
|
286
279
|
return "tabIndex" in element ? Number(element.tabIndex) : 0;
|
|
287
280
|
}
|
|
@@ -355,7 +348,7 @@ function resolveOptions(options) {
|
|
|
355
348
|
}
|
|
356
349
|
|
|
357
350
|
// src/index.ts
|
|
358
|
-
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;";
|
|
359
352
|
function createPortal(host, container = document.body, options = {}) {
|
|
360
353
|
if (!(host instanceof Element)) {
|
|
361
354
|
console.warn("Invalid host element");
|
|
@@ -542,7 +535,7 @@ function resolveOptions2(options) {
|
|
|
542
535
|
* Lightweight DOM portal (teleport) utility with fully focus management.
|
|
543
536
|
* Designed for accessible dialogs, menus, overlays, popovers.
|
|
544
537
|
*
|
|
545
|
-
* @version 1.3.
|
|
538
|
+
* @version 1.3.8
|
|
546
539
|
* @author Yusuke Kamiyamane
|
|
547
540
|
* @license MIT
|
|
548
541
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -554,7 +547,7 @@ function resolveOptions2(options) {
|
|
|
554
547
|
(**
|
|
555
548
|
* Attribute Utils
|
|
556
549
|
*
|
|
557
|
-
* @version 2.0.
|
|
550
|
+
* @version 2.0.11
|
|
558
551
|
* @author Yusuke Kamiyamane
|
|
559
552
|
* @license MIT
|
|
560
553
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -567,7 +560,7 @@ power-focusable/dist/index.js:
|
|
|
567
560
|
* High-precision focus management utility with full composed tree support.
|
|
568
561
|
* Handles complex focus rules including tabindex ordering, radio groups, inert.
|
|
569
562
|
*
|
|
570
|
-
* @version 4.3.
|
|
563
|
+
* @version 4.3.33
|
|
571
564
|
* @author Yusuke Kamiyamane
|
|
572
565
|
* @license MIT
|
|
573
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");
|
|
@@ -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.8
|
|
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.8
|
|
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.8
|
|
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");
|
|
@@ -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.8
|
|
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.8",
|
|
4
4
|
"description": "Lightweight DOM portal (teleport) utility with fully focus management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"esbuild": true
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@y14e/attribute-utils": "^2.0.
|
|
62
|
-
"power-focusable": "^4.3.
|
|
61
|
+
"@y14e/attribute-utils": "^2.0.11",
|
|
62
|
+
"power-focusable": "^4.3.33"
|
|
63
63
|
}
|
|
64
64
|
}
|