@y14e/disclosure 1.3.8 → 1.3.9

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
@@ -10,14 +10,14 @@ npm i @y14e/disclosure
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import Disclosure from '@y14e/disclosure@1.3.8';
13
+ import Disclosure from '@y14e/disclosure@1.3.9';
14
14
 
15
15
  // CDNs
16
- import Disclosure from 'https://esm.sh/@y14e/disclosure@1.3.8';
16
+ import Disclosure from 'https://esm.sh/@y14e/disclosure@1.3.9';
17
17
  // or
18
- import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@1.3.8/+esm';
18
+ import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@1.3.9/+esm';
19
19
  // or
20
- import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@1.3.8';
20
+ import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@1.3.9';
21
21
  ```
22
22
 
23
23
  ## Usage
package/dist/index.cjs CHANGED
@@ -40,11 +40,10 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
40
40
  const tokens = value ? parse(value).filter(Boolean) : [];
41
41
  if (caseInsensitive) {
42
42
  const lower = token.toLowerCase();
43
- if (tokens.some((token2) => token2.toLowerCase() === lower)) {
44
- return;
43
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
44
+ tokens.push(token);
45
+ element.setAttribute(attribute, serialize(tokens));
45
46
  }
46
- tokens.push(token);
47
- element.setAttribute(attribute, serialize(tokens));
48
47
  return;
49
48
  }
50
49
  const set = new Set(tokens);
@@ -323,6 +322,8 @@ function createRovingTabIndex(container, options = {}) {
323
322
  let {
324
323
  direction,
325
324
  navigationOnly = false,
325
+ noMemory = false,
326
+ noStart = false,
326
327
  selector,
327
328
  typeahead = false,
328
329
  wrap = false
@@ -335,6 +336,14 @@ function createRovingTabIndex(container, options = {}) {
335
336
  console.warn("Invalid navigationOnly option. Fallback: false.");
336
337
  navigationOnly = false;
337
338
  }
339
+ if (typeof noMemory !== "boolean") {
340
+ console.warn("Invalid noMemory option. Fallback: false.");
341
+ noMemory = false;
342
+ }
343
+ if (typeof noStart !== "boolean") {
344
+ console.warn("Invalid noStart option. Fallback: false.");
345
+ noStart = false;
346
+ }
338
347
  if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
339
348
  console.warn(
340
349
  "Invalid selector. Fallback: all focusable elements (undefined)."
@@ -349,13 +358,15 @@ function createRovingTabIndex(container, options = {}) {
349
358
  console.warn("Invalid wrap option. Fallback: false.");
350
359
  wrap = false;
351
360
  }
352
- const settings = { navigationOnly, typeahead, wrap };
353
- if (direction) {
354
- Object.assign(settings, { direction });
355
- }
356
- if (selector) {
357
- Object.assign(settings, { selector });
358
- }
361
+ const settings = {
362
+ navigationOnly,
363
+ noMemory,
364
+ noStart,
365
+ typeahead,
366
+ wrap
367
+ };
368
+ direction && Object.assign(settings, { direction });
369
+ selector && Object.assign(settings, { selector });
359
370
  const roving = new RovingTabIndex(container, settings);
360
371
  return () => roving.destroy();
361
372
  }
@@ -388,12 +399,29 @@ var RovingTabIndex = class {
388
399
  #initialize() {
389
400
  this.#update(document.activeElement);
390
401
  this.#controller = new AbortController();
402
+ const { signal } = this.#controller;
403
+ document.addEventListener("focusin", this.#onFocusIn, {
404
+ capture: true,
405
+ signal
406
+ });
391
407
  document.addEventListener("keydown", this.#onKeyDown, {
392
408
  capture: true,
393
- signal: this.#controller.signal
409
+ signal
394
410
  });
395
411
  this.#container.setAttribute("data-roving-tabindex-initialized", "");
396
412
  }
413
+ #onFocusIn = (event) => {
414
+ const { target } = event;
415
+ if (!(target instanceof Element)) {
416
+ return;
417
+ }
418
+ const isFocusable22 = this.#focusables.has(target);
419
+ if (this.#options.noMemory && !isFocusable22) {
420
+ this.#update(null);
421
+ return;
422
+ }
423
+ isFocusable22 && this.#update(target);
424
+ };
397
425
  #onKeyDown = (event) => {
398
426
  if (!event.composedPath().includes(this.#container)) {
399
427
  return;
@@ -424,7 +452,6 @@ var RovingTabIndex = class {
424
452
  return;
425
453
  }
426
454
  event.preventDefault();
427
- event.stopPropagation();
428
455
  const currentIndex = current.indexOf(active);
429
456
  let rawIndex;
430
457
  let newIndex = currentIndex;
@@ -455,11 +482,7 @@ var RovingTabIndex = class {
455
482
  }
456
483
  }
457
484
  const focusable = target.at(newIndex);
458
- if (!focusable) {
459
- return;
460
- }
461
- this.#update(focusable);
462
- focusElement(focusable);
485
+ focusable && focusElement(focusable);
463
486
  };
464
487
  #update(active) {
465
488
  const current = new Set(this.#getFocusables());
@@ -474,7 +497,7 @@ var RovingTabIndex = class {
474
497
  index >= 0 && focusables.splice(index, 1);
475
498
  });
476
499
  }
477
- const { navigationOnly } = this.#options;
500
+ const { navigationOnly, noStart, typeahead } = this.#options;
478
501
  for (const focusable of current) {
479
502
  if (this.#focusables.has(focusable)) {
480
503
  continue;
@@ -484,7 +507,7 @@ var RovingTabIndex = class {
484
507
  saveAttributes2([focusable], ["tabindex"]);
485
508
  focusable.setAttribute("tabindex", "-1");
486
509
  }
487
- if (!this.#options.typeahead) {
510
+ if (!typeahead) {
488
511
  continue;
489
512
  }
490
513
  const value = focusable.ariaKeyShortcuts?.trim();
@@ -515,7 +538,7 @@ var RovingTabIndex = class {
515
538
  return;
516
539
  }
517
540
  [...this.#focusables].forEach((focusable, i) => {
518
- focusable.setAttribute("tabindex", i ? "-1" : "0");
541
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
519
542
  });
520
543
  }
521
544
  #createSelectorFilter() {
@@ -526,7 +549,8 @@ var RovingTabIndex = class {
526
549
  return getFocusables(this.#container, {
527
550
  composed: true,
528
551
  filter: this.#selectorFilter,
529
- skipNegativeTabIndexCheck: !this.#options.navigationOnly
552
+ skipNegativeTabIndexCheck: !this.#options.navigationOnly,
553
+ skipVisibilityCheck: true
530
554
  });
531
555
  }
532
556
  };
@@ -761,6 +785,9 @@ var Disclosure = class _Disclosure {
761
785
  animation.addEventListener(
762
786
  "finish",
763
787
  () => {
788
+ if (binding?.animation !== animation) {
789
+ return;
790
+ }
764
791
  this.#onAnimationFinish(content);
765
792
  cleanup();
766
793
  },
@@ -819,7 +846,7 @@ function waitAnimationFinish(animation) {
819
846
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
820
847
  * Using the <details> and <summary> element.
821
848
  *
822
- * @version 1.3.8
849
+ * @version 1.3.9
823
850
  * @author Yusuke Kamiyamane
824
851
  * @license MIT
825
852
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -831,7 +858,7 @@ function waitAnimationFinish(animation) {
831
858
  (**
832
859
  * Attributes Utils
833
860
  *
834
- * @version 1.1.0
861
+ * @version 1.1.1
835
862
  * @author Yusuke Kamiyamane
836
863
  * @license MIT
837
864
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -844,7 +871,7 @@ function waitAnimationFinish(animation) {
844
871
  * Lightweight roving tabindex utility with fully focus management.
845
872
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
846
873
  *
847
- * @version 2.0.4
874
+ * @version 3.0.0
848
875
  * @author Yusuke Kamiyamane
849
876
  * @license MIT
850
877
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -856,7 +883,7 @@ function waitAnimationFinish(animation) {
856
883
  (**
857
884
  * Attributes Utils
858
885
  *
859
- * @version 1.1.0
886
+ * @version 1.1.1
860
887
  * @author Yusuke Kamiyamane
861
888
  * @license MIT
862
889
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -869,7 +896,7 @@ function waitAnimationFinish(animation) {
869
896
  * High-precision focus management utility with full composed tree support.
870
897
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
871
898
  *
872
- * @version 4.3.1
899
+ * @version 4.3.2
873
900
  * @author Yusuke Kamiyamane
874
901
  * @license MIT
875
902
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.3.8
6
+ * @version 1.3.9
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
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.3.8
6
+ * @version 1.3.9
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -38,11 +38,10 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
38
38
  const tokens = value ? parse(value).filter(Boolean) : [];
39
39
  if (caseInsensitive) {
40
40
  const lower = token.toLowerCase();
41
- if (tokens.some((token2) => token2.toLowerCase() === lower)) {
42
- return;
41
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
42
+ tokens.push(token);
43
+ element.setAttribute(attribute, serialize(tokens));
43
44
  }
44
- tokens.push(token);
45
- element.setAttribute(attribute, serialize(tokens));
46
45
  return;
47
46
  }
48
47
  const set = new Set(tokens);
@@ -321,6 +320,8 @@ function createRovingTabIndex(container, options = {}) {
321
320
  let {
322
321
  direction,
323
322
  navigationOnly = false,
323
+ noMemory = false,
324
+ noStart = false,
324
325
  selector,
325
326
  typeahead = false,
326
327
  wrap = false
@@ -333,6 +334,14 @@ function createRovingTabIndex(container, options = {}) {
333
334
  console.warn("Invalid navigationOnly option. Fallback: false.");
334
335
  navigationOnly = false;
335
336
  }
337
+ if (typeof noMemory !== "boolean") {
338
+ console.warn("Invalid noMemory option. Fallback: false.");
339
+ noMemory = false;
340
+ }
341
+ if (typeof noStart !== "boolean") {
342
+ console.warn("Invalid noStart option. Fallback: false.");
343
+ noStart = false;
344
+ }
336
345
  if (typeof selector !== "undefined" && (typeof selector !== "string" || !selector.trim())) {
337
346
  console.warn(
338
347
  "Invalid selector. Fallback: all focusable elements (undefined)."
@@ -347,13 +356,15 @@ function createRovingTabIndex(container, options = {}) {
347
356
  console.warn("Invalid wrap option. Fallback: false.");
348
357
  wrap = false;
349
358
  }
350
- const settings = { navigationOnly, typeahead, wrap };
351
- if (direction) {
352
- Object.assign(settings, { direction });
353
- }
354
- if (selector) {
355
- Object.assign(settings, { selector });
356
- }
359
+ const settings = {
360
+ navigationOnly,
361
+ noMemory,
362
+ noStart,
363
+ typeahead,
364
+ wrap
365
+ };
366
+ direction && Object.assign(settings, { direction });
367
+ selector && Object.assign(settings, { selector });
357
368
  const roving = new RovingTabIndex(container, settings);
358
369
  return () => roving.destroy();
359
370
  }
@@ -386,12 +397,29 @@ var RovingTabIndex = class {
386
397
  #initialize() {
387
398
  this.#update(document.activeElement);
388
399
  this.#controller = new AbortController();
400
+ const { signal } = this.#controller;
401
+ document.addEventListener("focusin", this.#onFocusIn, {
402
+ capture: true,
403
+ signal
404
+ });
389
405
  document.addEventListener("keydown", this.#onKeyDown, {
390
406
  capture: true,
391
- signal: this.#controller.signal
407
+ signal
392
408
  });
393
409
  this.#container.setAttribute("data-roving-tabindex-initialized", "");
394
410
  }
411
+ #onFocusIn = (event) => {
412
+ const { target } = event;
413
+ if (!(target instanceof Element)) {
414
+ return;
415
+ }
416
+ const isFocusable22 = this.#focusables.has(target);
417
+ if (this.#options.noMemory && !isFocusable22) {
418
+ this.#update(null);
419
+ return;
420
+ }
421
+ isFocusable22 && this.#update(target);
422
+ };
395
423
  #onKeyDown = (event) => {
396
424
  if (!event.composedPath().includes(this.#container)) {
397
425
  return;
@@ -422,7 +450,6 @@ var RovingTabIndex = class {
422
450
  return;
423
451
  }
424
452
  event.preventDefault();
425
- event.stopPropagation();
426
453
  const currentIndex = current.indexOf(active);
427
454
  let rawIndex;
428
455
  let newIndex = currentIndex;
@@ -453,11 +480,7 @@ var RovingTabIndex = class {
453
480
  }
454
481
  }
455
482
  const focusable = target.at(newIndex);
456
- if (!focusable) {
457
- return;
458
- }
459
- this.#update(focusable);
460
- focusElement(focusable);
483
+ focusable && focusElement(focusable);
461
484
  };
462
485
  #update(active) {
463
486
  const current = new Set(this.#getFocusables());
@@ -472,7 +495,7 @@ var RovingTabIndex = class {
472
495
  index >= 0 && focusables.splice(index, 1);
473
496
  });
474
497
  }
475
- const { navigationOnly } = this.#options;
498
+ const { navigationOnly, noStart, typeahead } = this.#options;
476
499
  for (const focusable of current) {
477
500
  if (this.#focusables.has(focusable)) {
478
501
  continue;
@@ -482,7 +505,7 @@ var RovingTabIndex = class {
482
505
  saveAttributes2([focusable], ["tabindex"]);
483
506
  focusable.setAttribute("tabindex", "-1");
484
507
  }
485
- if (!this.#options.typeahead) {
508
+ if (!typeahead) {
486
509
  continue;
487
510
  }
488
511
  const value = focusable.ariaKeyShortcuts?.trim();
@@ -513,7 +536,7 @@ var RovingTabIndex = class {
513
536
  return;
514
537
  }
515
538
  [...this.#focusables].forEach((focusable, i) => {
516
- focusable.setAttribute("tabindex", i ? "-1" : "0");
539
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
517
540
  });
518
541
  }
519
542
  #createSelectorFilter() {
@@ -524,7 +547,8 @@ var RovingTabIndex = class {
524
547
  return getFocusables(this.#container, {
525
548
  composed: true,
526
549
  filter: this.#selectorFilter,
527
- skipNegativeTabIndexCheck: !this.#options.navigationOnly
550
+ skipNegativeTabIndexCheck: !this.#options.navigationOnly,
551
+ skipVisibilityCheck: true
528
552
  });
529
553
  }
530
554
  };
@@ -759,6 +783,9 @@ var Disclosure = class _Disclosure {
759
783
  animation.addEventListener(
760
784
  "finish",
761
785
  () => {
786
+ if (binding?.animation !== animation) {
787
+ return;
788
+ }
762
789
  this.#onAnimationFinish(content);
763
790
  cleanup();
764
791
  },
@@ -817,7 +844,7 @@ function waitAnimationFinish(animation) {
817
844
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
818
845
  * Using the <details> and <summary> element.
819
846
  *
820
- * @version 1.3.8
847
+ * @version 1.3.9
821
848
  * @author Yusuke Kamiyamane
822
849
  * @license MIT
823
850
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -829,7 +856,7 @@ function waitAnimationFinish(animation) {
829
856
  (**
830
857
  * Attributes Utils
831
858
  *
832
- * @version 1.1.0
859
+ * @version 1.1.1
833
860
  * @author Yusuke Kamiyamane
834
861
  * @license MIT
835
862
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -842,7 +869,7 @@ function waitAnimationFinish(animation) {
842
869
  * Lightweight roving tabindex utility with fully focus management.
843
870
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
844
871
  *
845
- * @version 2.0.4
872
+ * @version 3.0.0
846
873
  * @author Yusuke Kamiyamane
847
874
  * @license MIT
848
875
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -854,7 +881,7 @@ function waitAnimationFinish(animation) {
854
881
  (**
855
882
  * Attributes Utils
856
883
  *
857
- * @version 1.1.0
884
+ * @version 1.1.1
858
885
  * @author Yusuke Kamiyamane
859
886
  * @license MIT
860
887
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -867,7 +894,7 @@ function waitAnimationFinish(animation) {
867
894
  * High-precision focus management utility with full composed tree support.
868
895
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
869
896
  *
870
- * @version 4.3.1
897
+ * @version 4.3.2
871
898
  * @author Yusuke Kamiyamane
872
899
  * @license MIT
873
900
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "homepage": "https://github.com/y14e/disclosure#readme",
45
45
  "devDependencies": {
46
- "@y14e/attributes-utils": "^1.1.0",
47
- "@y14e/roving-tabindex": "^2.0.4",
46
+ "@y14e/attributes-utils": "^1.1.1",
47
+ "@y14e/roving-tabindex": "^3.0.0",
48
48
  "bun-types": "latest",
49
49
  "tsup": "^8.0.0",
50
50
  "typescript": "^5.6.0",