@absolutejs/beacon 0.6.7 → 0.6.8

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.js CHANGED
@@ -1799,6 +1799,40 @@ var createBeacon = (options) => {
1799
1799
  };
1800
1800
  visit(body, null);
1801
1801
  };
1802
+ const clipsAxis = (overflow) => overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "clip";
1803
+ const visibleControlRect = (control, rect, viewportWidth, viewportHeight) => {
1804
+ const visible = {
1805
+ bottom: Math.min(rect.bottom, viewportHeight),
1806
+ left: Math.max(rect.left, 0),
1807
+ right: Math.min(rect.right, viewportWidth),
1808
+ top: Math.max(rect.top, 0)
1809
+ };
1810
+ for (let ancestor = control.parentElement;ancestor; ancestor = ancestor.parentElement) {
1811
+ const style = window.getComputedStyle(ancestor);
1812
+ const clipX = clipsAxis(style.overflowX);
1813
+ const clipY = clipsAxis(style.overflowY);
1814
+ if (!clipX && !clipY)
1815
+ continue;
1816
+ const ancestorRect = ancestor.getBoundingClientRect();
1817
+ if (clipX) {
1818
+ visible.left = Math.max(visible.left, ancestorRect.left);
1819
+ visible.right = Math.min(visible.right, ancestorRect.right);
1820
+ }
1821
+ if (clipY) {
1822
+ visible.top = Math.max(visible.top, ancestorRect.top);
1823
+ visible.bottom = Math.min(visible.bottom, ancestorRect.bottom);
1824
+ }
1825
+ if (visible.left >= visible.right || visible.top >= visible.bottom) {
1826
+ return null;
1827
+ }
1828
+ }
1829
+ const centerX = (rect.left + rect.right) / 2;
1830
+ const centerY = (rect.top + rect.bottom) / 2;
1831
+ if (centerX < visible.left || centerX > visible.right || centerY < visible.top || centerY > visible.bottom) {
1832
+ return null;
1833
+ }
1834
+ return visible;
1835
+ };
1802
1836
  const scanForOcclusion = () => {
1803
1837
  if (typeof document.elementFromPoint !== "function")
1804
1838
  return;
@@ -1816,18 +1850,18 @@ var createBeacon = (options) => {
1816
1850
  const rect = control.getBoundingClientRect();
1817
1851
  if (rect.width === 0 || rect.height === 0)
1818
1852
  continue;
1819
- if (rect.left < 0 || rect.top < 0 || rect.right > viewportWidth || rect.bottom > viewportHeight) {
1853
+ const visibleRect = visibleControlRect(control, rect, viewportWidth, viewportHeight);
1854
+ if (visibleRect === null)
1820
1855
  continue;
1821
- }
1822
1856
  sampled += 1;
1823
- const top = document.elementFromPoint((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2);
1857
+ const top = document.elementFromPoint((visibleRect.left + visibleRect.right) / 2, (visibleRect.top + visibleRect.bottom) / 2);
1824
1858
  if (top === null || top === control || control.contains(top) || top.contains(control)) {
1825
1859
  continue;
1826
1860
  }
1827
1861
  const topRect = top.getBoundingClientRect();
1828
- const overlapX = Math.min(rect.right, topRect.right) - Math.max(rect.left, topRect.left);
1829
- const overlapY = Math.min(rect.bottom, topRect.bottom) - Math.max(rect.top, topRect.top);
1830
- const coverage = Math.max(overlapX, 0) * Math.max(overlapY, 0) / (rect.width * rect.height);
1862
+ const overlapX = Math.min(visibleRect.right, topRect.right) - Math.max(visibleRect.left, topRect.left);
1863
+ const overlapY = Math.min(visibleRect.bottom, topRect.bottom) - Math.max(visibleRect.top, topRect.top);
1864
+ const coverage = Math.max(overlapX, 0) * Math.max(overlapY, 0) / ((visibleRect.right - visibleRect.left) * (visibleRect.bottom - visibleRect.top));
1831
1865
  if (coverage < OCCLUSION_COVERAGE_MIN)
1832
1866
  continue;
1833
1867
  reportScanIssue(control, BEACON_SIGNAL.OCCLUDED_CONTROL, `Occluded control — ${describeElement(control)} is covered by ${describeElement(top)}`, { coveredBy: describeElement(top) });
@@ -3583,5 +3617,5 @@ export {
3583
3617
  BEACON_ATTRIBUTE
3584
3618
  };
3585
3619
 
3586
- //# debugId=1C509449025A90CB64756E2164756E21
3620
+ //# debugId=875797C6E48C710C64756E2164756E21
3587
3621
  //# sourceMappingURL=index.js.map