@y14e/portal 1.4.0 → 1.4.2

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.2';
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.2/+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.2';
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,61 +507,14 @@ 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;
516
+ return { noInlineStyle };
524
517
  }
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;
532
- }
533
- return { noInlineStyle };
534
- }
535
- /**
536
- * Portal
537
- * Lightweight DOM portal (teleport) utility with fully focus management.
538
- * Designed for accessible dialogs, menus, overlays, popovers.
539
- *
540
- * @version 1.4.0
541
- * @author Yusuke Kamiyamane
542
- * @license MIT
543
- * @copyright Copyright (c) Yusuke Kamiyamane
544
- * @see {@link https://github.com/y14e/portal}
545
- */
546
- /*! Bundled license information:
547
-
548
- @y14e/attribute-utils/dist/index.js:
549
- (**
550
- * Attribute Utils
551
- *
552
- * @version 2.0.11
553
- * @author Yusuke Kamiyamane
554
- * @license MIT
555
- * @copyright Copyright (c) Yusuke Kamiyamane
556
- * @see {@link https://github.com/y14e/attribute-utils}
557
- *)
558
-
559
- power-focusable/dist/index.js:
560
- (**
561
- * Power Focusable
562
- * High-precision focus management utility with full composed tree support.
563
- * Handles complex focus rules including tabindex ordering, radio groups, inert.
564
- *
565
- * @version 4.3.33
566
- * @author Yusuke Kamiyamane
567
- * @license MIT
568
- * @copyright Copyright (c) Yusuke Kamiyamane
569
- * @see {@link https://github.com/y14e/power-focusable}
570
- *)
571
- */
518
+ };
572
519
 
573
520
  exports.createPortal = createPortal;
@@ -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,61 +505,14 @@ 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;
514
+ return { noInlineStyle };
522
515
  }
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;
530
- }
531
- return { noInlineStyle };
532
- }
533
- /**
534
- * Portal
535
- * Lightweight DOM portal (teleport) utility with fully focus management.
536
- * Designed for accessible dialogs, menus, overlays, popovers.
537
- *
538
- * @version 1.4.0
539
- * @author Yusuke Kamiyamane
540
- * @license MIT
541
- * @copyright Copyright (c) Yusuke Kamiyamane
542
- * @see {@link https://github.com/y14e/portal}
543
- */
544
- /*! Bundled license information:
545
-
546
- @y14e/attribute-utils/dist/index.js:
547
- (**
548
- * Attribute Utils
549
- *
550
- * @version 2.0.11
551
- * @author Yusuke Kamiyamane
552
- * @license MIT
553
- * @copyright Copyright (c) Yusuke Kamiyamane
554
- * @see {@link https://github.com/y14e/attribute-utils}
555
- *)
556
-
557
- power-focusable/dist/index.js:
558
- (**
559
- * Power Focusable
560
- * High-precision focus management utility with full composed tree support.
561
- * Handles complex focus rules including tabindex ordering, radio groups, inert.
562
- *
563
- * @version 4.3.33
564
- * @author Yusuke Kamiyamane
565
- * @license MIT
566
- * @copyright Copyright (c) Yusuke Kamiyamane
567
- * @see {@link https://github.com/y14e/power-focusable}
568
- *)
569
- */
516
+ };
570
517
 
571
518
  export { createPortal };
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,35 +167,14 @@ 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
- }
189
- /**
190
- * Portal
191
- * Lightweight DOM portal (teleport) utility with fully focus management.
192
- * Designed for accessible dialogs, menus, overlays, popovers.
193
- *
194
- * @version 1.4.0
195
- * @author Yusuke Kamiyamane
196
- * @license MIT
197
- * @copyright Copyright (c) Yusuke Kamiyamane
198
- * @see {@link https://github.com/y14e/portal}
199
- */
178
+ };
200
179
 
201
180
  exports.createPortal = createPortal;
package/dist/index.d.cts CHANGED
@@ -1,14 +1,3 @@
1
- /**
2
- * Portal
3
- * Lightweight DOM portal (teleport) utility with fully focus management.
4
- * Designed for accessible dialogs, menus, overlays, popovers.
5
- *
6
- * @version 1.4.0
7
- * @author Yusuke Kamiyamane
8
- * @license MIT
9
- * @copyright Copyright (c) Yusuke Kamiyamane
10
- * @see {@link https://github.com/y14e/portal}
11
- */
12
1
  interface PortalOptions {
13
2
  noInlineStyle: boolean;
14
3
  }
package/dist/index.d.ts CHANGED
@@ -1,14 +1,3 @@
1
- /**
2
- * Portal
3
- * Lightweight DOM portal (teleport) utility with fully focus management.
4
- * Designed for accessible dialogs, menus, overlays, popovers.
5
- *
6
- * @version 1.4.0
7
- * @author Yusuke Kamiyamane
8
- * @license MIT
9
- * @copyright Copyright (c) Yusuke Kamiyamane
10
- * @see {@link https://github.com/y14e/portal}
11
- */
12
1
  interface PortalOptions {
13
2
  noInlineStyle: boolean;
14
3
  }
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,35 +165,14 @@ 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
- }
187
- /**
188
- * Portal
189
- * Lightweight DOM portal (teleport) utility with fully focus management.
190
- * Designed for accessible dialogs, menus, overlays, popovers.
191
- *
192
- * @version 1.4.0
193
- * @author Yusuke Kamiyamane
194
- * @license MIT
195
- * @copyright Copyright (c) Yusuke Kamiyamane
196
- * @see {@link https://github.com/y14e/portal}
197
- */
176
+ };
198
177
 
199
178
  export { createPortal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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.13",
62
+ "power-focusable": "^4.4.4"
63
63
  }
64
64
  }