0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 22:52:40 +00:00

utilize Infinity and reduce()

This commit is contained in:
Gazook89
2024-08-27 08:42:45 -05:00
parent e06611a90f
commit 7bc0af9a8c

View File

@@ -55,19 +55,9 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
} else if(mode == 'fit'){
// find the page with the largest single dim (height or width) so that zoom can be adapted to fit it.
let maxDimRatio = 0;
[...pages].forEach((page)=>{
const widthRatio = iframeWidth / page.offsetWidth;
const heightRatio = iframeHeight / page.offsetHeight;
const dimensionRatio = Math.min(widthRatio, heightRatio);
if(dimensionRatio < maxDimRatio || maxDimRatio == 0){
maxDimRatio = dimensionRatio;
}
});
desiredZoom = maxDimRatio * 100;
const minDimRatio = [...pages].reduce((minRatio, page) => Math.min(minRatio, iframeWidth / page.offsetWidth, iframeHeight / page.offsetHeight), Infinity);
desiredZoom = minDimRatio * 100;
}
const margin = 5; // extra space so page isn't edge to edge (not truly "to fill")