@pierre/diffs
Version:
18 lines (17 loc) • 715 B
JavaScript
//#region src/utils/roundToDevicePixel.ts
/**
* Snap a CSS-pixel value to the nearest device-pixel boundary. Browsers store
* scrollTop on the device-pixel grid on fractional-DPR displays (1.25x, 1.5x,
* etc.), so rounding computed scroll targets against that grid keeps delta
* math settling cleanly instead of hovering around fractional residuals.
*
* Reads window.devicePixelRatio fresh on each call so monitor-switching and
* zoom changes are picked up without needing to flush any cached value.
*/
function roundToDevicePixel(value) {
const dpr = window.devicePixelRatio ?? 1;
return Math.round(value * dpr) / dpr;
}
//#endregion
export { roundToDevicePixel };
//# sourceMappingURL=roundToDevicePixel.js.map