@y14e/disclosure-css 2.2.0 → 2.2.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.
@@ -344,6 +344,64 @@ function isFocusable(element, options = {}) {
344
344
  }
345
345
 
346
346
  // node_modules/@y14e/roving-tabindex/dist/index.js
347
+ function getCellCoords(cell) {
348
+ const { left, top, width, height } = cell.getBoundingClientRect();
349
+ return { x: left + width / 2, y: top + height / 2 };
350
+ }
351
+ function getCellsOfActiveRow(cells) {
352
+ const active = getActiveElement();
353
+ if (!(active instanceof Element)) {
354
+ return [];
355
+ }
356
+ const activeRect = active.getBoundingClientRect();
357
+ return cells.filter((cell) => {
358
+ const cellRect = cell.getBoundingClientRect();
359
+ return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
360
+ });
361
+ }
362
+ function getNextCell(cells, key, wrap) {
363
+ const active = getActiveElement();
364
+ if (!(active instanceof Element)) {
365
+ return null;
366
+ }
367
+ const activeCoords = getCellCoords(active);
368
+ let min = Infinity;
369
+ let result = null;
370
+ for (const cell of cells) {
371
+ if (cell === active) {
372
+ continue;
373
+ }
374
+ const cellCoords = getCellCoords(cell);
375
+ const distances = {
376
+ x: Math.abs(cellCoords.x - activeCoords.x),
377
+ y: Math.abs(cellCoords.y - activeCoords.y)
378
+ };
379
+ if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
380
+ const distance = distances.x ** 2 + distances.y ** 2;
381
+ if (distance < min) {
382
+ min = distance;
383
+ result = cell;
384
+ }
385
+ }
386
+ }
387
+ if (!result && wrap) {
388
+ let max = -Infinity;
389
+ for (const cell of cells) {
390
+ if (cell === active) {
391
+ continue;
392
+ }
393
+ const cellCoords = getCellCoords(cell);
394
+ if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
395
+ const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
396
+ if (distance > max) {
397
+ max = distance;
398
+ result = cell;
399
+ }
400
+ }
401
+ }
402
+ }
403
+ return result;
404
+ }
347
405
  var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
348
406
  function resolveOptions3(options) {
349
407
  let {
@@ -601,20 +659,8 @@ var RovingTabIndex = class _RovingTabIndex {
601
659
  const { selector } = this.#settings;
602
660
  return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
603
661
  }
604
- #getCellCoords(cell) {
605
- const { left, top, width, height } = cell.getBoundingClientRect();
606
- return { x: left + width / 2, y: top + height / 2 };
607
- }
608
662
  #getCellsOfActiveRow() {
609
- const active = getActiveElement();
610
- if (!(active instanceof Element)) {
611
- return [];
612
- }
613
- const activeRect = active.getBoundingClientRect();
614
- return this.#getFocusables().filter((cell) => {
615
- const cellRect = cell.getBoundingClientRect();
616
- return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
617
- });
663
+ return getCellsOfActiveRow(this.#getFocusables());
618
664
  }
619
665
  #getFocusables() {
620
666
  return getFocusables(this.#container, {
@@ -625,48 +671,7 @@ var RovingTabIndex = class _RovingTabIndex {
625
671
  });
626
672
  }
627
673
  #getNextCell(key, wrap) {
628
- const cells = this.#getFocusables();
629
- const active = getActiveElement();
630
- if (!(active instanceof Element)) {
631
- return null;
632
- }
633
- const activeCoords = this.#getCellCoords(active);
634
- let min = Infinity;
635
- let result = null;
636
- for (const cell of cells) {
637
- if (cell === active) {
638
- continue;
639
- }
640
- const cellCoords = this.#getCellCoords(cell);
641
- const distances = {
642
- x: Math.abs(cellCoords.x - activeCoords.x),
643
- y: Math.abs(cellCoords.y - activeCoords.y)
644
- };
645
- if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
646
- const distance = distances.x ** 2 + distances.y ** 2;
647
- if (distance < min) {
648
- min = distance;
649
- result = cell;
650
- }
651
- }
652
- }
653
- if (!result && wrap) {
654
- let max = -Infinity;
655
- for (const cell of cells) {
656
- if (cell === active) {
657
- continue;
658
- }
659
- const cellCoords = this.#getCellCoords(cell);
660
- if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
661
- const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
662
- if (distance > max) {
663
- max = distance;
664
- result = cell;
665
- }
666
- }
667
- }
668
- }
669
- return result;
674
+ return getNextCell(this.#getFocusables(), key, wrap);
670
675
  }
671
676
  };
672
677
 
@@ -688,7 +693,6 @@ function resolveOptions4(defaults2, source) {
688
693
  var Disclosure = class _Disclosure {
689
694
  static defaults = {};
690
695
  #rootElement;
691
- #defaults = defaults;
692
696
  #settings;
693
697
  #detailsElements;
694
698
  #summaryElements;
@@ -706,8 +710,10 @@ var Disclosure = class _Disclosure {
706
710
  return;
707
711
  }
708
712
  this.#rootElement = root;
709
- this.#defaults = resolveOptions4(this.#defaults, _Disclosure.defaults);
710
- this.#settings = resolveOptions4(this.#defaults, options);
713
+ this.#settings = resolveOptions4(
714
+ resolveOptions4(defaults, _Disclosure.defaults),
715
+ options
716
+ );
711
717
  const NOT_NESTED = ":not(:scope summary + * *)";
712
718
  this.#detailsElements = [
713
719
  ...this.#rootElement.querySelectorAll(
@@ -342,6 +342,64 @@ function isFocusable(element, options = {}) {
342
342
  }
343
343
 
344
344
  // node_modules/@y14e/roving-tabindex/dist/index.js
345
+ function getCellCoords(cell) {
346
+ const { left, top, width, height } = cell.getBoundingClientRect();
347
+ return { x: left + width / 2, y: top + height / 2 };
348
+ }
349
+ function getCellsOfActiveRow(cells) {
350
+ const active = getActiveElement();
351
+ if (!(active instanceof Element)) {
352
+ return [];
353
+ }
354
+ const activeRect = active.getBoundingClientRect();
355
+ return cells.filter((cell) => {
356
+ const cellRect = cell.getBoundingClientRect();
357
+ return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
358
+ });
359
+ }
360
+ function getNextCell(cells, key, wrap) {
361
+ const active = getActiveElement();
362
+ if (!(active instanceof Element)) {
363
+ return null;
364
+ }
365
+ const activeCoords = getCellCoords(active);
366
+ let min = Infinity;
367
+ let result = null;
368
+ for (const cell of cells) {
369
+ if (cell === active) {
370
+ continue;
371
+ }
372
+ const cellCoords = getCellCoords(cell);
373
+ const distances = {
374
+ x: Math.abs(cellCoords.x - activeCoords.x),
375
+ y: Math.abs(cellCoords.y - activeCoords.y)
376
+ };
377
+ if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
378
+ const distance = distances.x ** 2 + distances.y ** 2;
379
+ if (distance < min) {
380
+ min = distance;
381
+ result = cell;
382
+ }
383
+ }
384
+ }
385
+ if (!result && wrap) {
386
+ let max = -Infinity;
387
+ for (const cell of cells) {
388
+ if (cell === active) {
389
+ continue;
390
+ }
391
+ const cellCoords = getCellCoords(cell);
392
+ if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
393
+ const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
394
+ if (distance > max) {
395
+ max = distance;
396
+ result = cell;
397
+ }
398
+ }
399
+ }
400
+ }
401
+ return result;
402
+ }
345
403
  var DIRECTIONS = ["both", "grid", "horizontal", "vertical"];
346
404
  function resolveOptions3(options) {
347
405
  let {
@@ -599,20 +657,8 @@ var RovingTabIndex = class _RovingTabIndex {
599
657
  const { selector } = this.#settings;
600
658
  return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
601
659
  }
602
- #getCellCoords(cell) {
603
- const { left, top, width, height } = cell.getBoundingClientRect();
604
- return { x: left + width / 2, y: top + height / 2 };
605
- }
606
660
  #getCellsOfActiveRow() {
607
- const active = getActiveElement();
608
- if (!(active instanceof Element)) {
609
- return [];
610
- }
611
- const activeRect = active.getBoundingClientRect();
612
- return this.#getFocusables().filter((cell) => {
613
- const cellRect = cell.getBoundingClientRect();
614
- return cellRect.top < activeRect.bottom && cellRect.bottom > activeRect.top;
615
- });
661
+ return getCellsOfActiveRow(this.#getFocusables());
616
662
  }
617
663
  #getFocusables() {
618
664
  return getFocusables(this.#container, {
@@ -623,48 +669,7 @@ var RovingTabIndex = class _RovingTabIndex {
623
669
  });
624
670
  }
625
671
  #getNextCell(key, wrap) {
626
- const cells = this.#getFocusables();
627
- const active = getActiveElement();
628
- if (!(active instanceof Element)) {
629
- return null;
630
- }
631
- const activeCoords = this.#getCellCoords(active);
632
- let min = Infinity;
633
- let result = null;
634
- for (const cell of cells) {
635
- if (cell === active) {
636
- continue;
637
- }
638
- const cellCoords = this.#getCellCoords(cell);
639
- const distances = {
640
- x: Math.abs(cellCoords.x - activeCoords.x),
641
- y: Math.abs(cellCoords.y - activeCoords.y)
642
- };
643
- if (key === "ArrowUp" && cellCoords.y < activeCoords.y && distances.x < distances.y || key === "ArrowDown" && cellCoords.y > activeCoords.y && distances.x < distances.y) {
644
- const distance = distances.x ** 2 + distances.y ** 2;
645
- if (distance < min) {
646
- min = distance;
647
- result = cell;
648
- }
649
- }
650
- }
651
- if (!result && wrap) {
652
- let max = -Infinity;
653
- for (const cell of cells) {
654
- if (cell === active) {
655
- continue;
656
- }
657
- const cellCoords = this.#getCellCoords(cell);
658
- if (Math.abs(cellCoords.x - activeCoords.x) < cell.getBoundingClientRect().width / 2) {
659
- const distance = key === "ArrowUp" ? cellCoords.y - activeCoords.y : activeCoords.y - cellCoords.y;
660
- if (distance > max) {
661
- max = distance;
662
- result = cell;
663
- }
664
- }
665
- }
666
- }
667
- return result;
672
+ return getNextCell(this.#getFocusables(), key, wrap);
668
673
  }
669
674
  };
670
675
 
@@ -686,7 +691,6 @@ function resolveOptions4(defaults2, source) {
686
691
  var Disclosure = class _Disclosure {
687
692
  static defaults = {};
688
693
  #rootElement;
689
- #defaults = defaults;
690
694
  #settings;
691
695
  #detailsElements;
692
696
  #summaryElements;
@@ -704,8 +708,10 @@ var Disclosure = class _Disclosure {
704
708
  return;
705
709
  }
706
710
  this.#rootElement = root;
707
- this.#defaults = resolveOptions4(this.#defaults, _Disclosure.defaults);
708
- this.#settings = resolveOptions4(this.#defaults, options);
711
+ this.#settings = resolveOptions4(
712
+ resolveOptions4(defaults, _Disclosure.defaults),
713
+ options
714
+ );
709
715
  const NOT_NESTED = ":not(:scope summary + * *)";
710
716
  this.#detailsElements = [
711
717
  ...this.#rootElement.querySelectorAll(
package/dist/index.cjs CHANGED
@@ -23,7 +23,6 @@ function resolveOptions(defaults2, source) {
23
23
  var Disclosure = class _Disclosure {
24
24
  static defaults = {};
25
25
  #rootElement;
26
- #defaults = defaults;
27
26
  #settings;
28
27
  #detailsElements;
29
28
  #summaryElements;
@@ -41,8 +40,10 @@ var Disclosure = class _Disclosure {
41
40
  return;
42
41
  }
43
42
  this.#rootElement = root;
44
- this.#defaults = resolveOptions(this.#defaults, _Disclosure.defaults);
45
- this.#settings = resolveOptions(this.#defaults, options);
43
+ this.#settings = resolveOptions(
44
+ resolveOptions(defaults, _Disclosure.defaults),
45
+ options
46
+ );
46
47
  const NOT_NESTED = ":not(:scope summary + * *)";
47
48
  this.#detailsElements = [
48
49
  ...this.#rootElement.querySelectorAll(
package/dist/index.js CHANGED
@@ -21,7 +21,6 @@ function resolveOptions(defaults2, source) {
21
21
  var Disclosure = class _Disclosure {
22
22
  static defaults = {};
23
23
  #rootElement;
24
- #defaults = defaults;
25
24
  #settings;
26
25
  #detailsElements;
27
26
  #summaryElements;
@@ -39,8 +38,10 @@ var Disclosure = class _Disclosure {
39
38
  return;
40
39
  }
41
40
  this.#rootElement = root;
42
- this.#defaults = resolveOptions(this.#defaults, _Disclosure.defaults);
43
- this.#settings = resolveOptions(this.#defaults, options);
41
+ this.#settings = resolveOptions(
42
+ resolveOptions(defaults, _Disclosure.defaults),
43
+ options
44
+ );
44
45
  const NOT_NESTED = ":not(:scope summary + * *)";
45
46
  this.#detailsElements = [
46
47
  ...this.#rootElement.querySelectorAll(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure-css",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "keywords": [
6
6
  "a11y",
@@ -55,6 +55,6 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@y14e/attribute-utils": "^2.0.16",
58
- "@y14e/roving-tabindex": "^3.4.0"
58
+ "@y14e/roving-tabindex": "^3.4.1"
59
59
  }
60
60
  }