power-focusable 3.1.0 → 3.1.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/dist/index.cjs CHANGED
@@ -9,9 +9,7 @@ function createFocusTrap(container) {
9
9
  focus(container);
10
10
  if (getActiveElement() !== container) {
11
11
  const first = getFocusables(container, { composed: true })[0];
12
- if (first) {
13
- focus(first);
14
- }
12
+ first && focus(first);
15
13
  }
16
14
  function onKeyDown(event) {
17
15
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
@@ -121,9 +119,7 @@ function inertOutside(element) {
121
119
  if (!(node instanceof Element)) {
122
120
  return;
123
121
  }
124
- if (applyInert(node)) {
125
- elements.push(node);
126
- }
122
+ applyInert(node) && elements.push(node);
127
123
  });
128
124
  return () => {
129
125
  elements.forEach((element2) => {
@@ -335,9 +331,7 @@ function applyInert(element) {
335
331
  }
336
332
  const count = inertRefCounts.get(element) ?? 0;
337
333
  inertRefCounts.set(element, count + 1);
338
- if (count === 0) {
339
- setInert(element, true);
340
- }
334
+ count === 0 && element.toggleAttribute("inert", true);
341
335
  return true;
342
336
  }
343
337
  function restoreInert(element) {
@@ -347,15 +341,13 @@ function restoreInert(element) {
347
341
  }
348
342
  if (count === 1) {
349
343
  inertRefCounts.delete(element);
350
- setInert(element, false);
344
+ element.toggleAttribute("inert", false);
351
345
  return;
352
346
  }
353
347
  inertRefCounts.set(element, count - 1);
354
348
  }
355
349
  function focus(element) {
356
- if ("focus" in element && typeof element.focus === "function") {
357
- element.focus();
358
- }
350
+ "focus" in element && typeof element.focus === "function" && element.focus();
359
351
  }
360
352
  function getActiveElement() {
361
353
  let current = document.activeElement;
@@ -400,20 +392,13 @@ function isInert(element) {
400
392
  function isUngroupedRadio(element) {
401
393
  return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
402
394
  }
403
- function setInert(element, boolean) {
404
- if (boolean) {
405
- element.setAttribute("inert", "");
406
- } else {
407
- element.removeAttribute("inert");
408
- }
409
- }
410
395
  /**
411
396
  * Power Focusable
412
397
  * High-precision focus management utility with full composed tree support.
413
398
  * Handles complex focus rules including tabindex ordering, radio groups, inert,
414
399
  * and shadow DOM.
415
400
  *
416
- * @version 3.1.0
401
+ * @version 3.1.1
417
402
  * @author Yusuke Kamiyamane
418
403
  * @license MIT
419
404
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert,
5
5
  * and shadow DOM.
6
6
  *
7
- * @version 3.1.0
7
+ * @version 3.1.1
8
8
  * @author Yusuke Kamiyamane
9
9
  * @license MIT
10
10
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert,
5
5
  * and shadow DOM.
6
6
  *
7
- * @version 3.1.0
7
+ * @version 3.1.1
8
8
  * @author Yusuke Kamiyamane
9
9
  * @license MIT
10
10
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -7,9 +7,7 @@ function createFocusTrap(container) {
7
7
  focus(container);
8
8
  if (getActiveElement() !== container) {
9
9
  const first = getFocusables(container, { composed: true })[0];
10
- if (first) {
11
- focus(first);
12
- }
10
+ first && focus(first);
13
11
  }
14
12
  function onKeyDown(event) {
15
13
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
@@ -119,9 +117,7 @@ function inertOutside(element) {
119
117
  if (!(node instanceof Element)) {
120
118
  return;
121
119
  }
122
- if (applyInert(node)) {
123
- elements.push(node);
124
- }
120
+ applyInert(node) && elements.push(node);
125
121
  });
126
122
  return () => {
127
123
  elements.forEach((element2) => {
@@ -333,9 +329,7 @@ function applyInert(element) {
333
329
  }
334
330
  const count = inertRefCounts.get(element) ?? 0;
335
331
  inertRefCounts.set(element, count + 1);
336
- if (count === 0) {
337
- setInert(element, true);
338
- }
332
+ count === 0 && element.toggleAttribute("inert", true);
339
333
  return true;
340
334
  }
341
335
  function restoreInert(element) {
@@ -345,15 +339,13 @@ function restoreInert(element) {
345
339
  }
346
340
  if (count === 1) {
347
341
  inertRefCounts.delete(element);
348
- setInert(element, false);
342
+ element.toggleAttribute("inert", false);
349
343
  return;
350
344
  }
351
345
  inertRefCounts.set(element, count - 1);
352
346
  }
353
347
  function focus(element) {
354
- if ("focus" in element && typeof element.focus === "function") {
355
- element.focus();
356
- }
348
+ "focus" in element && typeof element.focus === "function" && element.focus();
357
349
  }
358
350
  function getActiveElement() {
359
351
  let current = document.activeElement;
@@ -398,20 +390,13 @@ function isInert(element) {
398
390
  function isUngroupedRadio(element) {
399
391
  return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
400
392
  }
401
- function setInert(element, boolean) {
402
- if (boolean) {
403
- element.setAttribute("inert", "");
404
- } else {
405
- element.removeAttribute("inert");
406
- }
407
- }
408
393
  /**
409
394
  * Power Focusable
410
395
  * High-precision focus management utility with full composed tree support.
411
396
  * Handles complex focus rules including tabindex ordering, radio groups, inert,
412
397
  * and shadow DOM.
413
398
  *
414
- * @version 3.1.0
399
+ * @version 3.1.1
415
400
  * @author Yusuke Kamiyamane
416
401
  * @license MIT
417
402
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "High-precision focus management utility with full composed tree support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",