@pierre/diffs
Version:
27 lines (26 loc) • 1.06 kB
JavaScript
//#region src/utils/createWindowFromScrollPosition.ts
function createWindowFromScrollPosition({ scrollTop, scrollHeight, height, fitPerfectly = false, fitPerfectlyOverscroll = 0, overscrollSize }) {
const windowHeight = height + overscrollSize * 2;
const effectiveHeight = fitPerfectly ? height + fitPerfectlyOverscroll * 2 : windowHeight;
scrollHeight = Math.max(scrollHeight, effectiveHeight);
if (windowHeight >= scrollHeight || fitPerfectly) {
const top$1 = Math.max(scrollTop - fitPerfectlyOverscroll, 0);
const bottom$1 = Math.min(scrollTop + effectiveHeight, scrollHeight);
return {
top: top$1,
bottom: Math.max(bottom$1, top$1)
};
}
let top = scrollTop + height / 2 - windowHeight / 2;
let bottom = top + windowHeight;
if (top < 0) top = 0;
if (bottom > scrollHeight) bottom = scrollHeight;
top = Math.floor(Math.max(top, 0));
return {
top,
bottom: Math.ceil(Math.max(Math.min(bottom, scrollHeight), top))
};
}
//#endregion
export { createWindowFromScrollPosition };
//# sourceMappingURL=createWindowFromScrollPosition.js.map