@y14e/portal 1.4.0 → 1.4.1

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 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.4.0';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.4.1';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.4.0/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.4.1/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.4.0';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.4.1';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -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 e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
7
- const snapshot = snapshots.get(e);
6
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
7
+ const snapshot = snapshots.get(element);
8
8
  if (!snapshot) {
9
9
  continue;
10
10
  }
11
- for (const [n, v] of snapshot.entries()) {
12
- v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
11
+ for (const [name, value] of snapshot.entries()) {
12
+ value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
13
13
  }
14
- snapshots.delete(e);
14
+ snapshots.delete(element);
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 e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
20
- let snapshot = snapshots.get(e);
19
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
20
+ let snapshot = snapshots.get(element);
21
21
  if (!snapshot) {
22
22
  snapshot = /* @__PURE__ */ new Map();
23
- snapshots.set(e, snapshot);
23
+ snapshots.set(element, snapshot);
24
24
  }
25
- for (const n of names) {
26
- snapshot.set(n, e.getAttribute(n));
25
+ for (const name of names) {
26
+ snapshot.set(name, element.getAttribute(name));
27
27
  }
28
28
  }
29
29
  }
@@ -194,31 +194,25 @@ function normalizeRadioGroup(elements) {
194
194
  map = /* @__PURE__ */ new Map();
195
195
  }
196
196
  const root = element.getRootNode();
197
- let groups = map.get(root);
197
+ const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
198
198
  if (!groups) {
199
- groups = /* @__PURE__ */ new Map();
200
- map.set(root, groups);
201
- }
202
- let group = groups.get(element.form);
203
- if (!group) {
204
- group = /* @__PURE__ */ new Map();
205
- groups.set(element.form, group);
199
+ continue;
206
200
  }
207
- let radios = group.get(element.name);
201
+ const { form, name } = element;
202
+ const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
208
203
  if (!radios) {
209
- radios = [];
210
- group.set(element.name, radios);
204
+ continue;
211
205
  }
212
- radios.push(element);
206
+ (radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
213
207
  }
214
208
  if (!map) {
215
209
  return elements;
216
210
  }
217
211
  const placeholder = /* @__PURE__ */ new Set();
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];
212
+ for (const v of map.values()) {
213
+ for (const w of v.values()) {
214
+ for (const x of w.values()) {
215
+ const radio = x.find((r) => r.checked) ?? x[0];
222
216
  radio && placeholder.add(radio);
223
217
  }
224
218
  }
@@ -362,7 +356,7 @@ function createPortal(host, container = document.body, options = {}) {
362
356
  return () => {
363
357
  };
364
358
  }
365
- if (containsComposed2(host, container)) {
359
+ if (containsComposed(host, container)) {
366
360
  console.warn("Host element cannot contain the container element");
367
361
  return () => {
368
362
  };
@@ -386,7 +380,7 @@ var Portal = class {
386
380
  container = document.body;
387
381
  }
388
382
  this.#container = container;
389
- this.#settings = resolveOptions2(options);
383
+ this.#settings = this.#resolveOptions(options);
390
384
  this.#entranceSentinel = this.#createSentinel();
391
385
  this.#exitSentinel = this.#createSentinel();
392
386
  this.#initialize();
@@ -513,31 +507,21 @@ var Portal = class {
513
507
  const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
514
508
  focusable && focusElement(focusable);
515
509
  }
516
- };
517
- function containsComposed2(container, element) {
518
- let current = element;
519
- while (current) {
520
- if (current === container) {
521
- return true;
510
+ #resolveOptions(options) {
511
+ let { noInlineStyle = false } = options;
512
+ if (typeof noInlineStyle !== "boolean") {
513
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
514
+ noInlineStyle = false;
522
515
  }
523
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
524
- }
525
- return false;
526
- }
527
- function resolveOptions2(options) {
528
- let { noInlineStyle = false } = options;
529
- if (typeof noInlineStyle !== "boolean") {
530
- console.warn("Invalid noInlineStyle option. Fallback: false.");
531
- noInlineStyle = false;
516
+ return { noInlineStyle };
532
517
  }
533
- return { noInlineStyle };
534
- }
518
+ };
535
519
  /**
536
520
  * Portal
537
521
  * Lightweight DOM portal (teleport) utility with fully focus management.
538
522
  * Designed for accessible dialogs, menus, overlays, popovers.
539
523
  *
540
- * @version 1.4.0
524
+ * @version 1.4.1
541
525
  * @author Yusuke Kamiyamane
542
526
  * @license MIT
543
527
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -549,7 +533,7 @@ function resolveOptions2(options) {
549
533
  (**
550
534
  * Attribute Utils
551
535
  *
552
- * @version 2.0.11
536
+ * @version 2.0.12
553
537
  * @author Yusuke Kamiyamane
554
538
  * @license MIT
555
539
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -562,7 +546,7 @@ power-focusable/dist/index.js:
562
546
  * High-precision focus management utility with full composed tree support.
563
547
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
564
548
  *
565
- * @version 4.3.33
549
+ * @version 4.4.3
566
550
  * @author Yusuke Kamiyamane
567
551
  * @license MIT
568
552
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -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 e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
5
- const snapshot = snapshots.get(e);
4
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
5
+ const snapshot = snapshots.get(element);
6
6
  if (!snapshot) {
7
7
  continue;
8
8
  }
9
- for (const [n, v] of snapshot.entries()) {
10
- v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
9
+ for (const [name, value] of snapshot.entries()) {
10
+ value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
11
11
  }
12
- snapshots.delete(e);
12
+ snapshots.delete(element);
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 e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
18
- let snapshot = snapshots.get(e);
17
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
18
+ let snapshot = snapshots.get(element);
19
19
  if (!snapshot) {
20
20
  snapshot = /* @__PURE__ */ new Map();
21
- snapshots.set(e, snapshot);
21
+ snapshots.set(element, snapshot);
22
22
  }
23
- for (const n of names) {
24
- snapshot.set(n, e.getAttribute(n));
23
+ for (const name of names) {
24
+ snapshot.set(name, element.getAttribute(name));
25
25
  }
26
26
  }
27
27
  }
@@ -192,31 +192,25 @@ function normalizeRadioGroup(elements) {
192
192
  map = /* @__PURE__ */ new Map();
193
193
  }
194
194
  const root = element.getRootNode();
195
- let groups = map.get(root);
195
+ const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
196
196
  if (!groups) {
197
- groups = /* @__PURE__ */ new Map();
198
- map.set(root, groups);
199
- }
200
- let group = groups.get(element.form);
201
- if (!group) {
202
- group = /* @__PURE__ */ new Map();
203
- groups.set(element.form, group);
197
+ continue;
204
198
  }
205
- let radios = group.get(element.name);
199
+ const { form, name } = element;
200
+ const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
206
201
  if (!radios) {
207
- radios = [];
208
- group.set(element.name, radios);
202
+ continue;
209
203
  }
210
- radios.push(element);
204
+ (radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
211
205
  }
212
206
  if (!map) {
213
207
  return elements;
214
208
  }
215
209
  const placeholder = /* @__PURE__ */ new Set();
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];
210
+ for (const v of map.values()) {
211
+ for (const w of v.values()) {
212
+ for (const x of w.values()) {
213
+ const radio = x.find((r) => r.checked) ?? x[0];
220
214
  radio && placeholder.add(radio);
221
215
  }
222
216
  }
@@ -360,7 +354,7 @@ function createPortal(host, container = document.body, options = {}) {
360
354
  return () => {
361
355
  };
362
356
  }
363
- if (containsComposed2(host, container)) {
357
+ if (containsComposed(host, container)) {
364
358
  console.warn("Host element cannot contain the container element");
365
359
  return () => {
366
360
  };
@@ -384,7 +378,7 @@ var Portal = class {
384
378
  container = document.body;
385
379
  }
386
380
  this.#container = container;
387
- this.#settings = resolveOptions2(options);
381
+ this.#settings = this.#resolveOptions(options);
388
382
  this.#entranceSentinel = this.#createSentinel();
389
383
  this.#exitSentinel = this.#createSentinel();
390
384
  this.#initialize();
@@ -511,31 +505,21 @@ var Portal = class {
511
505
  const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
512
506
  focusable && focusElement(focusable);
513
507
  }
514
- };
515
- function containsComposed2(container, element) {
516
- let current = element;
517
- while (current) {
518
- if (current === container) {
519
- return true;
508
+ #resolveOptions(options) {
509
+ let { noInlineStyle = false } = options;
510
+ if (typeof noInlineStyle !== "boolean") {
511
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
512
+ noInlineStyle = false;
520
513
  }
521
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
522
- }
523
- return false;
524
- }
525
- function resolveOptions2(options) {
526
- let { noInlineStyle = false } = options;
527
- if (typeof noInlineStyle !== "boolean") {
528
- console.warn("Invalid noInlineStyle option. Fallback: false.");
529
- noInlineStyle = false;
514
+ return { noInlineStyle };
530
515
  }
531
- return { noInlineStyle };
532
- }
516
+ };
533
517
  /**
534
518
  * Portal
535
519
  * Lightweight DOM portal (teleport) utility with fully focus management.
536
520
  * Designed for accessible dialogs, menus, overlays, popovers.
537
521
  *
538
- * @version 1.4.0
522
+ * @version 1.4.1
539
523
  * @author Yusuke Kamiyamane
540
524
  * @license MIT
541
525
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -547,7 +531,7 @@ function resolveOptions2(options) {
547
531
  (**
548
532
  * Attribute Utils
549
533
  *
550
- * @version 2.0.11
534
+ * @version 2.0.12
551
535
  * @author Yusuke Kamiyamane
552
536
  * @license MIT
553
537
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -560,7 +544,7 @@ power-focusable/dist/index.js:
560
544
  * High-precision focus management utility with full composed tree support.
561
545
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
562
546
  *
563
- * @version 4.3.33
547
+ * @version 4.4.3
564
548
  * @author Yusuke Kamiyamane
565
549
  * @license MIT
566
550
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ function createPortal(host, container = document.body, options = {}) {
16
16
  return () => {
17
17
  };
18
18
  }
19
- if (containsComposed(host, container)) {
19
+ if (powerFocusable.containsComposed(host, container)) {
20
20
  console.warn("Host element cannot contain the container element");
21
21
  return () => {
22
22
  };
@@ -40,7 +40,7 @@ var Portal = class {
40
40
  container = document.body;
41
41
  }
42
42
  this.#container = container;
43
- this.#settings = resolveOptions(options);
43
+ this.#settings = this.#resolveOptions(options);
44
44
  this.#entranceSentinel = this.#createSentinel();
45
45
  this.#exitSentinel = this.#createSentinel();
46
46
  this.#initialize();
@@ -167,31 +167,21 @@ var Portal = class {
167
167
  const focusable = direction === "previous" ? powerFocusable.getPreviousFocusable(document.body, options) : powerFocusable.getNextFocusable(document.body, options);
168
168
  focusable && powerFocusable.focusElement(focusable);
169
169
  }
170
- };
171
- function containsComposed(container, element) {
172
- let current = element;
173
- while (current) {
174
- if (current === container) {
175
- return true;
170
+ #resolveOptions(options) {
171
+ let { noInlineStyle = false } = options;
172
+ if (typeof noInlineStyle !== "boolean") {
173
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
174
+ noInlineStyle = false;
176
175
  }
177
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
178
- }
179
- return false;
180
- }
181
- function resolveOptions(options) {
182
- let { noInlineStyle = false } = options;
183
- if (typeof noInlineStyle !== "boolean") {
184
- console.warn("Invalid noInlineStyle option. Fallback: false.");
185
- noInlineStyle = false;
176
+ return { noInlineStyle };
186
177
  }
187
- return { noInlineStyle };
188
- }
178
+ };
189
179
  /**
190
180
  * Portal
191
181
  * Lightweight DOM portal (teleport) utility with fully focus management.
192
182
  * Designed for accessible dialogs, menus, overlays, popovers.
193
183
  *
194
- * @version 1.4.0
184
+ * @version 1.4.1
195
185
  * @author Yusuke Kamiyamane
196
186
  * @license MIT
197
187
  * @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.4.0
6
+ * @version 1.4.1
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.4.0
6
+ * @version 1.4.1
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/attribute-utils';
2
- import { focusElement, getActiveElement, getFocusables, getPreviousFocusable, getNextFocusable } from 'power-focusable';
2
+ import { containsComposed, 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;";
@@ -38,7 +38,7 @@ var Portal = class {
38
38
  container = document.body;
39
39
  }
40
40
  this.#container = container;
41
- this.#settings = resolveOptions(options);
41
+ this.#settings = this.#resolveOptions(options);
42
42
  this.#entranceSentinel = this.#createSentinel();
43
43
  this.#exitSentinel = this.#createSentinel();
44
44
  this.#initialize();
@@ -165,31 +165,21 @@ var Portal = class {
165
165
  const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
166
166
  focusable && focusElement(focusable);
167
167
  }
168
- };
169
- function containsComposed(container, element) {
170
- let current = element;
171
- while (current) {
172
- if (current === container) {
173
- return true;
168
+ #resolveOptions(options) {
169
+ let { noInlineStyle = false } = options;
170
+ if (typeof noInlineStyle !== "boolean") {
171
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
172
+ noInlineStyle = false;
174
173
  }
175
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
176
- }
177
- return false;
178
- }
179
- function resolveOptions(options) {
180
- let { noInlineStyle = false } = options;
181
- if (typeof noInlineStyle !== "boolean") {
182
- console.warn("Invalid noInlineStyle option. Fallback: false.");
183
- noInlineStyle = false;
174
+ return { noInlineStyle };
184
175
  }
185
- return { noInlineStyle };
186
- }
176
+ };
187
177
  /**
188
178
  * Portal
189
179
  * Lightweight DOM portal (teleport) utility with fully focus management.
190
180
  * Designed for accessible dialogs, menus, overlays, popovers.
191
181
  *
192
- * @version 1.4.0
182
+ * @version 1.4.1
193
183
  * @author Yusuke Kamiyamane
194
184
  * @license MIT
195
185
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
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.11",
62
- "power-focusable": "^4.3.33"
61
+ "@y14e/attribute-utils": "^2.0.12",
62
+ "power-focusable": "^4.4.3"
63
63
  }
64
64
  }