@y14e/disclosure 2.2.1 → 2.2.4

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.
@@ -344,6 +344,7 @@ function isFocusable(element, options = {}) {
344
344
  }
345
345
 
346
346
  // node_modules/@y14e/roving-tabindex/dist/index.js
347
+ var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
347
348
  function getCellCoords(cell) {
348
349
  const { left, top, width, height } = cell.getBoundingClientRect();
349
350
  return { x: left + width / 2, y: top + height / 2 };
@@ -402,7 +403,6 @@ function getNextCell(cells, key, wrap) {
402
403
  }
403
404
  return result;
404
405
  }
405
- var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
406
406
  function resolveOptions3(options) {
407
407
  let {
408
408
  direction = "both",
@@ -416,7 +416,7 @@ function resolveOptions3(options) {
416
416
  if (typeof direction === "string") {
417
417
  direction = direction.toLowerCase();
418
418
  }
419
- if (!DIRECTIONS.includes(direction)) {
419
+ if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
420
420
  console.warn("Invalid direction option. Fallback: 'both'.");
421
421
  direction = "both";
422
422
  }
@@ -516,7 +516,7 @@ var RovingTabIndex = class _RovingTabIndex {
516
516
  (!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
517
517
  };
518
518
  #onKeyDown = (event) => {
519
- const { direction, typeahead, wrap = false } = this.#settings;
519
+ const direction = this.#getDirection();
520
520
  const isGrid = direction === "grid";
521
521
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
522
522
  if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
@@ -524,6 +524,7 @@ var RovingTabIndex = class _RovingTabIndex {
524
524
  }
525
525
  const isBoth = direction === "both";
526
526
  const isHorizontal = direction === "horizontal";
527
+ const { typeahead, wrap = false } = this.#settings;
527
528
  if (![
528
529
  "End",
529
530
  "Home",
@@ -662,6 +663,14 @@ var RovingTabIndex = class _RovingTabIndex {
662
663
  #getCellsOfActiveRow() {
663
664
  return getCellsOfActiveRow(this.#getFocusables());
664
665
  }
666
+ #getDirection() {
667
+ const { direction } = this.#settings;
668
+ if (typeof direction === "string") {
669
+ return direction;
670
+ }
671
+ const d = direction();
672
+ return DIRECTIONS.includes(d) ? d : "both";
673
+ }
665
674
  #getFocusables() {
666
675
  return getFocusables(this.#container, {
667
676
  composed: true,
@@ -743,7 +752,9 @@ var Disclosure = class _Disclosure {
743
752
  resolveOptions4(defaults, _Disclosure.defaults),
744
753
  options
745
754
  );
746
- matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
755
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
756
+ this.#settings.animation.duration = 0;
757
+ }
747
758
  const NOT_NESTED = ":not(:scope summary + * *)";
748
759
  this.#detailsElements = [
749
760
  ...this.#rootElement.querySelectorAll(
@@ -779,9 +790,9 @@ var Disclosure = class _Disclosure {
779
790
  return;
780
791
  }
781
792
  const binding = this.#createBinding(details, summary, content);
782
- this.#bindings.set(details, binding);
783
- this.#bindings.set(summary, binding);
784
- this.#bindings.set(content, binding);
793
+ [details, summary, content].forEach((element) => {
794
+ this.#bindings.set(element, binding);
795
+ });
785
796
  });
786
797
  this.#initialize();
787
798
  }
@@ -878,19 +889,11 @@ var Disclosure = class _Disclosure {
878
889
  if (!(summary instanceof HTMLElement)) {
879
890
  return;
880
891
  }
881
- const binding = this.#bindings.get(summary);
882
- if (!binding) {
883
- return;
884
- }
885
- const { details } = binding;
886
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
892
+ const details = this.#bindings.get(summary)?.details;
893
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
887
894
  };
888
895
  #onContentAnimationFinish(content) {
889
- const binding = this.#bindings.get(content);
890
- if (!binding) {
891
- return;
892
- }
893
- const details = binding.details;
896
+ const details = this.#bindings.get(content)?.details;
894
897
  if (!details) {
895
898
  return;
896
899
  }
@@ -342,6 +342,7 @@ function isFocusable(element, options = {}) {
342
342
  }
343
343
 
344
344
  // node_modules/@y14e/roving-tabindex/dist/index.js
345
+ var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
345
346
  function getCellCoords(cell) {
346
347
  const { left, top, width, height } = cell.getBoundingClientRect();
347
348
  return { x: left + width / 2, y: top + height / 2 };
@@ -400,7 +401,6 @@ function getNextCell(cells, key, wrap) {
400
401
  }
401
402
  return result;
402
403
  }
403
- var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
404
404
  function resolveOptions3(options) {
405
405
  let {
406
406
  direction = "both",
@@ -414,7 +414,7 @@ function resolveOptions3(options) {
414
414
  if (typeof direction === "string") {
415
415
  direction = direction.toLowerCase();
416
416
  }
417
- if (!DIRECTIONS.includes(direction)) {
417
+ if (typeof direction === "string" && !DIRECTIONS.includes(direction) || typeof direction === "function" && !DIRECTIONS.includes(direction())) {
418
418
  console.warn("Invalid direction option. Fallback: 'both'.");
419
419
  direction = "both";
420
420
  }
@@ -514,7 +514,7 @@ var RovingTabIndex = class _RovingTabIndex {
514
514
  (!(target instanceof Element) || !this.#focusables.has(target)) && this.#update();
515
515
  };
516
516
  #onKeyDown = (event) => {
517
- const { direction, typeahead, wrap = false } = this.#settings;
517
+ const direction = this.#getDirection();
518
518
  const isGrid = direction === "grid";
519
519
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
520
520
  if (!(isGrid && ["End", "Home"].includes(key)) && ctrlKey || altKey || metaKey || shiftKey) {
@@ -522,6 +522,7 @@ var RovingTabIndex = class _RovingTabIndex {
522
522
  }
523
523
  const isBoth = direction === "both";
524
524
  const isHorizontal = direction === "horizontal";
525
+ const { typeahead, wrap = false } = this.#settings;
525
526
  if (![
526
527
  "End",
527
528
  "Home",
@@ -660,6 +661,14 @@ var RovingTabIndex = class _RovingTabIndex {
660
661
  #getCellsOfActiveRow() {
661
662
  return getCellsOfActiveRow(this.#getFocusables());
662
663
  }
664
+ #getDirection() {
665
+ const { direction } = this.#settings;
666
+ if (typeof direction === "string") {
667
+ return direction;
668
+ }
669
+ const d = direction();
670
+ return DIRECTIONS.includes(d) ? d : "both";
671
+ }
663
672
  #getFocusables() {
664
673
  return getFocusables(this.#container, {
665
674
  composed: true,
@@ -741,7 +750,9 @@ var Disclosure = class _Disclosure {
741
750
  resolveOptions4(defaults, _Disclosure.defaults),
742
751
  options
743
752
  );
744
- matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
753
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
754
+ this.#settings.animation.duration = 0;
755
+ }
745
756
  const NOT_NESTED = ":not(:scope summary + * *)";
746
757
  this.#detailsElements = [
747
758
  ...this.#rootElement.querySelectorAll(
@@ -777,9 +788,9 @@ var Disclosure = class _Disclosure {
777
788
  return;
778
789
  }
779
790
  const binding = this.#createBinding(details, summary, content);
780
- this.#bindings.set(details, binding);
781
- this.#bindings.set(summary, binding);
782
- this.#bindings.set(content, binding);
791
+ [details, summary, content].forEach((element) => {
792
+ this.#bindings.set(element, binding);
793
+ });
783
794
  });
784
795
  this.#initialize();
785
796
  }
@@ -876,19 +887,11 @@ var Disclosure = class _Disclosure {
876
887
  if (!(summary instanceof HTMLElement)) {
877
888
  return;
878
889
  }
879
- const binding = this.#bindings.get(summary);
880
- if (!binding) {
881
- return;
882
- }
883
- const { details } = binding;
884
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
890
+ const details = this.#bindings.get(summary)?.details;
891
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
885
892
  };
886
893
  #onContentAnimationFinish(content) {
887
- const binding = this.#bindings.get(content);
888
- if (!binding) {
889
- return;
890
- }
891
- const details = binding.details;
894
+ const details = this.#bindings.get(content)?.details;
892
895
  if (!details) {
893
896
  return;
894
897
  }
package/dist/index.cjs CHANGED
@@ -73,7 +73,9 @@ var Disclosure = class _Disclosure {
73
73
  resolveOptions(defaults, _Disclosure.defaults),
74
74
  options
75
75
  );
76
- matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
76
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
77
+ this.#settings.animation.duration = 0;
78
+ }
77
79
  const NOT_NESTED = ":not(:scope summary + * *)";
78
80
  this.#detailsElements = [
79
81
  ...this.#rootElement.querySelectorAll(
@@ -109,9 +111,9 @@ var Disclosure = class _Disclosure {
109
111
  return;
110
112
  }
111
113
  const binding = this.#createBinding(details, summary, content);
112
- this.#bindings.set(details, binding);
113
- this.#bindings.set(summary, binding);
114
- this.#bindings.set(content, binding);
114
+ [details, summary, content].forEach((element) => {
115
+ this.#bindings.set(element, binding);
116
+ });
115
117
  });
116
118
  this.#initialize();
117
119
  }
@@ -208,19 +210,11 @@ var Disclosure = class _Disclosure {
208
210
  if (!(summary instanceof HTMLElement)) {
209
211
  return;
210
212
  }
211
- const binding = this.#bindings.get(summary);
212
- if (!binding) {
213
- return;
214
- }
215
- const { details } = binding;
216
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
213
+ const details = this.#bindings.get(summary)?.details;
214
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
217
215
  };
218
216
  #onContentAnimationFinish(content) {
219
- const binding = this.#bindings.get(content);
220
- if (!binding) {
221
- return;
222
- }
223
- const details = binding.details;
217
+ const details = this.#bindings.get(content)?.details;
224
218
  if (!details) {
225
219
  return;
226
220
  }
package/dist/index.js CHANGED
@@ -71,7 +71,9 @@ var Disclosure = class _Disclosure {
71
71
  resolveOptions(defaults, _Disclosure.defaults),
72
72
  options
73
73
  );
74
- matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, { duration: 0 });
74
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
75
+ this.#settings.animation.duration = 0;
76
+ }
75
77
  const NOT_NESTED = ":not(:scope summary + * *)";
76
78
  this.#detailsElements = [
77
79
  ...this.#rootElement.querySelectorAll(
@@ -107,9 +109,9 @@ var Disclosure = class _Disclosure {
107
109
  return;
108
110
  }
109
111
  const binding = this.#createBinding(details, summary, content);
110
- this.#bindings.set(details, binding);
111
- this.#bindings.set(summary, binding);
112
- this.#bindings.set(content, binding);
112
+ [details, summary, content].forEach((element) => {
113
+ this.#bindings.set(element, binding);
114
+ });
113
115
  });
114
116
  this.#initialize();
115
117
  }
@@ -206,19 +208,11 @@ var Disclosure = class _Disclosure {
206
208
  if (!(summary instanceof HTMLElement)) {
207
209
  return;
208
210
  }
209
- const binding = this.#bindings.get(summary);
210
- if (!binding) {
211
- return;
212
- }
213
- const { details } = binding;
214
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
211
+ const details = this.#bindings.get(summary)?.details;
212
+ details && this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
215
213
  };
216
214
  #onContentAnimationFinish(content) {
217
- const binding = this.#bindings.get(content);
218
- if (!binding) {
219
- return;
220
- }
221
- const details = binding.details;
215
+ const details = this.#bindings.get(content)?.details;
222
216
  if (!details) {
223
217
  return;
224
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure",
3
- "version": "2.2.1",
3
+ "version": "2.2.4",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "keywords": [
6
6
  "a11y",
@@ -54,7 +54,7 @@
54
54
  "esbuild": true
55
55
  },
56
56
  "dependencies": {
57
- "@y14e/attribute-utils": "^2.0.16",
58
- "@y14e/roving-tabindex": "^3.4.1"
57
+ "@y14e/attribute-utils": "^2.0.18",
58
+ "@y14e/roving-tabindex": "^3.5.1"
59
59
  }
60
60
  }