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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user