@y14e/disclosure-css 1.3.6 → 1.3.7

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-css
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import Disclosure from '@y14e/disclosure-css@1.3.6';
13
+ import Disclosure from '@y14e/disclosure-css@1.3.7';
14
14
 
15
15
  // CDNs
16
- import Disclosure from 'https://esm.sh/@y14e/disclosure-css@1.3.6';
16
+ import Disclosure from 'https://esm.sh/@y14e/disclosure-css@1.3.7';
17
17
  // or
18
- import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@1.3.6/+esm';
18
+ import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure-css@1.3.7/+esm';
19
19
  // or
20
- import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure-css@1.3.6';
20
+ import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure-css@1.3.7';
21
21
  ```
22
22
 
23
23
  ## Usage
package/dist/index.cjs CHANGED
@@ -28,13 +28,13 @@ function saveAttributes(elements, attributes) {
28
28
  }
29
29
 
30
30
  // node_modules/@y14e/roving-tabindex/dist/index.js
31
- var defaultParser = (value) => value.split(/\s+/);
32
- var defaultSerializer = (tokens) => tokens.join(" ");
31
+ var DEFAULT_PARSER = (value) => value.split(/\s+/);
32
+ var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
33
33
  function addTokenToAttribute(element, attribute, token, options = {}) {
34
34
  const {
35
35
  caseInsensitive = false,
36
- parse = defaultParser,
37
- serialize = defaultSerializer
36
+ parse = DEFAULT_PARSER,
37
+ serialize = DEFAULT_SERIALIZER
38
38
  } = options;
39
39
  const value = element.getAttribute(attribute)?.trim();
40
40
  const tokens = value ? parse(value).filter(Boolean) : [];
@@ -44,11 +44,11 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
44
44
  tokens.push(token);
45
45
  element.setAttribute(attribute, serialize(tokens));
46
46
  }
47
- return;
47
+ } else {
48
+ const set = new Set(tokens);
49
+ set.add(token);
50
+ element.setAttribute(attribute, serialize([...set]));
48
51
  }
49
- const set = new Set(tokens);
50
- set.add(token);
51
- element.setAttribute(attribute, serialize([...set]));
52
52
  }
53
53
  var snapshots2 = /* @__PURE__ */ new WeakMap();
54
54
  function restoreAttributes2(elements) {
@@ -115,21 +115,16 @@ function getFocusables(container = document.body, options = {}) {
115
115
  const elements = [];
116
116
  if (composed || include) {
117
117
  let traverse2 = function(node) {
118
- if (node instanceof Element) {
119
- if (isFocusable(node, {
120
- skipNegativeTabIndexCheck,
121
- skipVisibilityCheck
122
- }) || include?.(node)) {
123
- elements[elements.length] = node;
124
- }
118
+ if (!(node instanceof Element)) {
119
+ return;
120
+ }
121
+ if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
122
+ elements[elements.length] = node;
125
123
  }
126
124
  const children = getComposedChildren(node);
127
125
  for (let i = 0, l = children.length; i < l; i++) {
128
126
  const child = children[i];
129
- if (!child) {
130
- continue;
131
- }
132
- traverse2(child);
127
+ child && traverse2(child);
133
128
  }
134
129
  };
135
130
  traverse2(container);
@@ -137,10 +132,7 @@ function getFocusables(container = document.body, options = {}) {
137
132
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
138
133
  for (let i = 0, l = candidates.length; i < l; i++) {
139
134
  const candidate = candidates[i];
140
- if (!(candidate instanceof Element)) {
141
- continue;
142
- }
143
- if (isFocusable(candidate, {
135
+ if (candidate && isFocusable(candidate, {
144
136
  skipNegativeTabIndexCheck,
145
137
  skipVisibilityCheck
146
138
  })) {
@@ -243,23 +235,19 @@ function normalizeRadioGroup(elements) {
243
235
  for (const group of map.values()) {
244
236
  placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
245
237
  }
246
- return elements.filter((element) => {
247
- if (isUngroupedRadio(element)) {
248
- return placeholder.has(element);
249
- }
250
- return true;
251
- });
238
+ return elements.filter(
239
+ (element) => isUngroupedRadio(element) ? placeholder.has(element) : true
240
+ );
252
241
  }
253
242
  function sortByTabIndex(elements) {
254
243
  const ordered = [];
255
244
  const natural = [];
256
245
  for (let i = 0, l = elements.length; i < l; i++) {
257
246
  const element = elements[i];
258
- if (!element) {
259
- continue;
247
+ if (element) {
248
+ const target = getTabIndex(element) > 0 ? ordered : natural;
249
+ target[target.length] = element;
260
250
  }
261
- const target = getTabIndex(element) > 0 ? ordered : natural;
262
- target[target.length] = element;
263
251
  }
264
252
  ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
265
253
  let count = 0;
@@ -416,11 +404,7 @@ var RovingTabIndex = class {
416
404
  return;
417
405
  }
418
406
  const isFocusable22 = this.#focusables.has(target);
419
- if (this.#options.noMemory && !isFocusable22) {
420
- this.#update(null);
421
- return;
422
- }
423
- isFocusable22 && this.#update(target);
407
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
424
408
  };
425
409
  #onKeyDown = (event) => {
426
410
  if (!event.composedPath().includes(this.#container)) {
@@ -453,8 +437,7 @@ var RovingTabIndex = class {
453
437
  }
454
438
  event.preventDefault();
455
439
  const currentIndex = current.indexOf(active);
456
- let rawIndex;
457
- let newIndex = currentIndex;
440
+ let newIndex;
458
441
  let target = current;
459
442
  switch (key) {
460
443
  case "End":
@@ -464,15 +447,17 @@ var RovingTabIndex = class {
464
447
  newIndex = 0;
465
448
  break;
466
449
  case "ArrowLeft":
467
- case "ArrowUp":
468
- rawIndex = currentIndex - 1;
450
+ case "ArrowUp": {
451
+ const rawIndex = currentIndex - 1;
469
452
  newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
470
453
  break;
454
+ }
471
455
  case "ArrowRight":
472
- case "ArrowDown":
473
- rawIndex = currentIndex + 1;
456
+ case "ArrowDown": {
457
+ const rawIndex = currentIndex + 1;
474
458
  newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
475
459
  break;
460
+ }
476
461
  default: {
477
462
  target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
478
463
  const foundIndex = target.findIndex(
@@ -487,15 +472,14 @@ var RovingTabIndex = class {
487
472
  #update(active) {
488
473
  const current = new Set(this.#getFocusables());
489
474
  for (const focusable of this.#focusables) {
490
- if (current.has(focusable)) {
491
- continue;
475
+ if (!current.has(focusable)) {
476
+ focusable.isConnected && restoreAttributes2([focusable]);
477
+ this.#focusables.delete(focusable);
478
+ this.#focusablesByFirstChar.forEach((focusables) => {
479
+ const index = focusables.indexOf(focusable);
480
+ index >= 0 && focusables.splice(index, 1);
481
+ });
492
482
  }
493
- focusable.isConnected && restoreAttributes2([focusable]);
494
- this.#focusables.delete(focusable);
495
- this.#focusablesByFirstChar.forEach((focusables) => {
496
- const index = focusables.indexOf(focusable);
497
- index >= 0 && focusables.splice(index, 1);
498
- });
499
483
  }
500
484
  const { navigationOnly, noStart, typeahead } = this.#options;
501
485
  for (const focusable of current) {
@@ -528,18 +512,17 @@ var RovingTabIndex = class {
528
512
  this.#focusablesByFirstChar.set(key, focusables);
529
513
  });
530
514
  }
531
- if (navigationOnly) {
532
- return;
533
- }
534
- if (active && this.#focusables.has(active)) {
535
- this.#focusables.forEach((focusable) => {
536
- focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
537
- });
538
- return;
515
+ if (!navigationOnly) {
516
+ if (active && this.#focusables.has(active)) {
517
+ this.#focusables.forEach((focusable) => {
518
+ focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
519
+ });
520
+ } else {
521
+ [...this.#focusables].forEach((focusable, i) => {
522
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
523
+ });
524
+ }
539
525
  }
540
- [...this.#focusables].forEach((focusable, i) => {
541
- focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
542
- });
543
526
  }
544
527
  #createSelectorFilter() {
545
528
  const { selector } = this.#options;
@@ -693,7 +676,7 @@ function isFocusable2(element) {
693
676
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
694
677
  * Using the <details> and <summary> element.
695
678
  *
696
- * @version 1.3.6
679
+ * @version 1.3.7
697
680
  * @author Yusuke Kamiyamane
698
681
  * @license MIT
699
682
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -705,7 +688,7 @@ function isFocusable2(element) {
705
688
  (**
706
689
  * Attributes Utils
707
690
  *
708
- * @version 1.1.1
691
+ * @version 1.1.2
709
692
  * @author Yusuke Kamiyamane
710
693
  * @license MIT
711
694
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -718,7 +701,7 @@ function isFocusable2(element) {
718
701
  * Lightweight roving tabindex utility with fully focus management.
719
702
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
720
703
  *
721
- * @version 3.0.0
704
+ * @version 3.0.2
722
705
  * @author Yusuke Kamiyamane
723
706
  * @license MIT
724
707
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -730,7 +713,7 @@ function isFocusable2(element) {
730
713
  (**
731
714
  * Attributes Utils
732
715
  *
733
- * @version 1.1.1
716
+ * @version 1.1.2
734
717
  * @author Yusuke Kamiyamane
735
718
  * @license MIT
736
719
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -743,7 +726,7 @@ function isFocusable2(element) {
743
726
  * High-precision focus management utility with full composed tree support.
744
727
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
745
728
  *
746
- * @version 4.3.2
729
+ * @version 4.3.3
747
730
  * @author Yusuke Kamiyamane
748
731
  * @license MIT
749
732
  * @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.6
6
+ * @version 1.3.7
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.6
6
+ * @version 1.3.7
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -26,13 +26,13 @@ function saveAttributes(elements, attributes) {
26
26
  }
27
27
 
28
28
  // node_modules/@y14e/roving-tabindex/dist/index.js
29
- var defaultParser = (value) => value.split(/\s+/);
30
- var defaultSerializer = (tokens) => tokens.join(" ");
29
+ var DEFAULT_PARSER = (value) => value.split(/\s+/);
30
+ var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
31
31
  function addTokenToAttribute(element, attribute, token, options = {}) {
32
32
  const {
33
33
  caseInsensitive = false,
34
- parse = defaultParser,
35
- serialize = defaultSerializer
34
+ parse = DEFAULT_PARSER,
35
+ serialize = DEFAULT_SERIALIZER
36
36
  } = options;
37
37
  const value = element.getAttribute(attribute)?.trim();
38
38
  const tokens = value ? parse(value).filter(Boolean) : [];
@@ -42,11 +42,11 @@ function addTokenToAttribute(element, attribute, token, options = {}) {
42
42
  tokens.push(token);
43
43
  element.setAttribute(attribute, serialize(tokens));
44
44
  }
45
- return;
45
+ } else {
46
+ const set = new Set(tokens);
47
+ set.add(token);
48
+ element.setAttribute(attribute, serialize([...set]));
46
49
  }
47
- const set = new Set(tokens);
48
- set.add(token);
49
- element.setAttribute(attribute, serialize([...set]));
50
50
  }
51
51
  var snapshots2 = /* @__PURE__ */ new WeakMap();
52
52
  function restoreAttributes2(elements) {
@@ -113,21 +113,16 @@ function getFocusables(container = document.body, options = {}) {
113
113
  const elements = [];
114
114
  if (composed || include) {
115
115
  let traverse2 = function(node) {
116
- if (node instanceof Element) {
117
- if (isFocusable(node, {
118
- skipNegativeTabIndexCheck,
119
- skipVisibilityCheck
120
- }) || include?.(node)) {
121
- elements[elements.length] = node;
122
- }
116
+ if (!(node instanceof Element)) {
117
+ return;
118
+ }
119
+ if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
120
+ elements[elements.length] = node;
123
121
  }
124
122
  const children = getComposedChildren(node);
125
123
  for (let i = 0, l = children.length; i < l; i++) {
126
124
  const child = children[i];
127
- if (!child) {
128
- continue;
129
- }
130
- traverse2(child);
125
+ child && traverse2(child);
131
126
  }
132
127
  };
133
128
  traverse2(container);
@@ -135,10 +130,7 @@ function getFocusables(container = document.body, options = {}) {
135
130
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
136
131
  for (let i = 0, l = candidates.length; i < l; i++) {
137
132
  const candidate = candidates[i];
138
- if (!(candidate instanceof Element)) {
139
- continue;
140
- }
141
- if (isFocusable(candidate, {
133
+ if (candidate && isFocusable(candidate, {
142
134
  skipNegativeTabIndexCheck,
143
135
  skipVisibilityCheck
144
136
  })) {
@@ -241,23 +233,19 @@ function normalizeRadioGroup(elements) {
241
233
  for (const group of map.values()) {
242
234
  placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
243
235
  }
244
- return elements.filter((element) => {
245
- if (isUngroupedRadio(element)) {
246
- return placeholder.has(element);
247
- }
248
- return true;
249
- });
236
+ return elements.filter(
237
+ (element) => isUngroupedRadio(element) ? placeholder.has(element) : true
238
+ );
250
239
  }
251
240
  function sortByTabIndex(elements) {
252
241
  const ordered = [];
253
242
  const natural = [];
254
243
  for (let i = 0, l = elements.length; i < l; i++) {
255
244
  const element = elements[i];
256
- if (!element) {
257
- continue;
245
+ if (element) {
246
+ const target = getTabIndex(element) > 0 ? ordered : natural;
247
+ target[target.length] = element;
258
248
  }
259
- const target = getTabIndex(element) > 0 ? ordered : natural;
260
- target[target.length] = element;
261
249
  }
262
250
  ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
263
251
  let count = 0;
@@ -414,11 +402,7 @@ var RovingTabIndex = class {
414
402
  return;
415
403
  }
416
404
  const isFocusable22 = this.#focusables.has(target);
417
- if (this.#options.noMemory && !isFocusable22) {
418
- this.#update(null);
419
- return;
420
- }
421
- isFocusable22 && this.#update(target);
405
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
422
406
  };
423
407
  #onKeyDown = (event) => {
424
408
  if (!event.composedPath().includes(this.#container)) {
@@ -451,8 +435,7 @@ var RovingTabIndex = class {
451
435
  }
452
436
  event.preventDefault();
453
437
  const currentIndex = current.indexOf(active);
454
- let rawIndex;
455
- let newIndex = currentIndex;
438
+ let newIndex;
456
439
  let target = current;
457
440
  switch (key) {
458
441
  case "End":
@@ -462,15 +445,17 @@ var RovingTabIndex = class {
462
445
  newIndex = 0;
463
446
  break;
464
447
  case "ArrowLeft":
465
- case "ArrowUp":
466
- rawIndex = currentIndex - 1;
448
+ case "ArrowUp": {
449
+ const rawIndex = currentIndex - 1;
467
450
  newIndex = wrap ? rawIndex : Math.max(rawIndex, 0);
468
451
  break;
452
+ }
469
453
  case "ArrowRight":
470
- case "ArrowDown":
471
- rawIndex = currentIndex + 1;
454
+ case "ArrowDown": {
455
+ const rawIndex = currentIndex + 1;
472
456
  newIndex = wrap ? rawIndex % current.length : Math.min(rawIndex, current.length - 1);
473
457
  break;
458
+ }
474
459
  default: {
475
460
  target = this.#focusablesByFirstChar.get(key.toUpperCase()) ?? [];
476
461
  const foundIndex = target.findIndex(
@@ -485,15 +470,14 @@ var RovingTabIndex = class {
485
470
  #update(active) {
486
471
  const current = new Set(this.#getFocusables());
487
472
  for (const focusable of this.#focusables) {
488
- if (current.has(focusable)) {
489
- continue;
473
+ if (!current.has(focusable)) {
474
+ focusable.isConnected && restoreAttributes2([focusable]);
475
+ this.#focusables.delete(focusable);
476
+ this.#focusablesByFirstChar.forEach((focusables) => {
477
+ const index = focusables.indexOf(focusable);
478
+ index >= 0 && focusables.splice(index, 1);
479
+ });
490
480
  }
491
- focusable.isConnected && restoreAttributes2([focusable]);
492
- this.#focusables.delete(focusable);
493
- this.#focusablesByFirstChar.forEach((focusables) => {
494
- const index = focusables.indexOf(focusable);
495
- index >= 0 && focusables.splice(index, 1);
496
- });
497
481
  }
498
482
  const { navigationOnly, noStart, typeahead } = this.#options;
499
483
  for (const focusable of current) {
@@ -526,18 +510,17 @@ var RovingTabIndex = class {
526
510
  this.#focusablesByFirstChar.set(key, focusables);
527
511
  });
528
512
  }
529
- if (navigationOnly) {
530
- return;
531
- }
532
- if (active && this.#focusables.has(active)) {
533
- this.#focusables.forEach((focusable) => {
534
- focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
535
- });
536
- return;
513
+ if (!navigationOnly) {
514
+ if (active && this.#focusables.has(active)) {
515
+ this.#focusables.forEach((focusable) => {
516
+ focusable.setAttribute("tabindex", focusable === active ? "0" : "-1");
517
+ });
518
+ } else {
519
+ [...this.#focusables].forEach((focusable, i) => {
520
+ focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
521
+ });
522
+ }
537
523
  }
538
- [...this.#focusables].forEach((focusable, i) => {
539
- focusable.setAttribute("tabindex", i || noStart ? "-1" : "0");
540
- });
541
524
  }
542
525
  #createSelectorFilter() {
543
526
  const { selector } = this.#options;
@@ -691,7 +674,7 @@ function isFocusable2(element) {
691
674
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
692
675
  * Using the <details> and <summary> element.
693
676
  *
694
- * @version 1.3.6
677
+ * @version 1.3.7
695
678
  * @author Yusuke Kamiyamane
696
679
  * @license MIT
697
680
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -703,7 +686,7 @@ function isFocusable2(element) {
703
686
  (**
704
687
  * Attributes Utils
705
688
  *
706
- * @version 1.1.1
689
+ * @version 1.1.2
707
690
  * @author Yusuke Kamiyamane
708
691
  * @license MIT
709
692
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -716,7 +699,7 @@ function isFocusable2(element) {
716
699
  * Lightweight roving tabindex utility with fully focus management.
717
700
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
718
701
  *
719
- * @version 3.0.0
702
+ * @version 3.0.2
720
703
  * @author Yusuke Kamiyamane
721
704
  * @license MIT
722
705
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -728,7 +711,7 @@ function isFocusable2(element) {
728
711
  (**
729
712
  * Attributes Utils
730
713
  *
731
- * @version 1.1.1
714
+ * @version 1.1.2
732
715
  * @author Yusuke Kamiyamane
733
716
  * @license MIT
734
717
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -741,7 +724,7 @@ function isFocusable2(element) {
741
724
  * High-precision focus management utility with full composed tree support.
742
725
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
743
726
  *
744
- * @version 4.3.2
727
+ * @version 4.3.3
745
728
  * @author Yusuke Kamiyamane
746
729
  * @license MIT
747
730
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure-css",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
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-css#readme",
45
45
  "devDependencies": {
46
- "@y14e/attributes-utils": "^1.1.1",
47
- "@y14e/roving-tabindex": "^3.0.0",
46
+ "@y14e/attributes-utils": "^1.1.2",
47
+ "@y14e/roving-tabindex": "^3.0.2",
48
48
  "bun-types": "latest",
49
49
  "tsup": "^8.0.0",
50
50
  "typescript": "^5.6.0"