UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

29 lines (28 loc) 861 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SCROLL_EDGE_TOLERANCE_PX = void 0; exports.normalizeScrollOffset = normalizeScrollOffset; var _clamp = require("../../utils/clamp"); const SCROLL_EDGE_TOLERANCE_PX = exports.SCROLL_EDGE_TOLERANCE_PX = 1; function normalizeScrollOffset(value, max) { if (max <= 0) { return 0; } const clamped = (0, _clamp.clamp)(value, 0, max); const startDistance = clamped; const endDistance = max - clamped; const withinStartTolerance = startDistance <= SCROLL_EDGE_TOLERANCE_PX; const withinEndTolerance = endDistance <= SCROLL_EDGE_TOLERANCE_PX; if (withinStartTolerance && withinEndTolerance) { return startDistance <= endDistance ? 0 : max; } if (withinStartTolerance) { return 0; } if (withinEndTolerance) { return max; } return clamped; }