UNPKG

@visactor/vtable

Version:

canvas table width high performance

12 lines (11 loc) 546 B
export function calcKeepAspectRatioSize(width, height, maxWidth, maxHeight) { const rectRatio = width / height; let newWidth, newHeight, offsetX, offsetY; return rectRatio > maxWidth / maxHeight ? (newWidth = maxWidth, newHeight = newWidth / rectRatio, offsetX = 0, offsetY = (maxHeight - newHeight) / 2) : (newHeight = maxHeight, newWidth = newHeight * rectRatio, offsetY = 0, offsetX = (maxWidth - newWidth) / 2), { width: newWidth, height: newHeight }; } //# sourceMappingURL=keep-aspect-ratio.js.map