ConstReadonlyALIGNMENT_BASE: 10Alignment baseline — perfect alignment scores this.
ReadonlyALIGNMENT_DECAY_PX: 50Alignment decay rate (px). Larger = more forgiving.
ReadonlyCONE_TOLERANCE_BASE_PX: 4Off-axis spread allowed inside the navigation cone, base value (px).
ReadonlyCONE_TOLERANCE_RATIO: 3Off-axis spread is also bounded by primary * CONE_TOLERANCE_RATIO.
ReadonlyDIFFERENT_SCROLL_PENALTY: 75Penalty (added) when candidate is in a different scroll container.
ReadonlyEDGE_EPS_BASE: 4Allowed overlap when checking strict-edge containment (px, before adding overlapThreshold).
ReadonlyEPSILON: 1Tiny epsilon for float comparisons (px).
ReadonlyFORWARD_OVERLAP_TOLERANCE_PX: 12When allowOverlap is true, candidates may overlap the current element by this many
pixels in the navigation axis (before adding overlapThreshold).
ReadonlyGRID_BONUS: 500Bonus (subtracted from score) when a grid-aligned candidate is found in grid mode.
ReadonlyGROUP_ENTER_LAST_BONUS: 1000Bonus (subtracted) when entering a group via its remembered last-focused element.
ReadonlyOFFSCREEN_PENALTY: 120Penalty (added) when candidate is off-screen.
ReadonlyPRIMARY_WEIGHT: 1000Score weight applied to primary-axis distance — dominant factor in the linear score.
ReadonlyPROJECTED_SECONDARY_WEIGHT: 0.5Projected-distance secondary axis weight (lower = strongly prefer aligned candidates).
ReadonlySAME_GROUP_BONUS: 2000Bonus (subtracted) when candidate is in the same focus group as the current element.
ReadonlySAME_SCROLL_BONUS: 150Bonus (subtracted) when candidate shares the current element's scroll container.
Score-weight constants used by the scoring algorithm.
The implicit hierarchy is intentional:
SAME_GROUP_BONUS (2000) > GROUP_ENTER_LAST_BONUS (1000) > GRID_BONUS (500) > SAME_SCROLL_BONUS (150) > OFFSCREEN_PENALTY (120) > DIFFERENT_SCROLL_PENALTY (75)
"Stay in the same focus group" outranks every other consideration so users don't spuriously jump out of a logical region (sidebar, modal, list). Inside the same group, grid alignment beats scroll-container co-location, and the smaller scroll-related nudges only act as tiebreakers between otherwise equivalent candidates.
If you tune these, the test suite in
__tests__/scoring.test.tsexercises the boundaries — keep that suite green.