react-native-zoom-toolkit
Version:
Smoothly zoom any image, video or component you want!
33 lines (32 loc) • 1.32 kB
JavaScript
import { getAspectRatioSize } from '../../utils/getAspectRatioSize';
export const getCropRotatedSize = options => {
'worklet';
const {
crop,
angle,
resolution
} = options;
const cropAspectRatio = crop.width / crop.height;
let base = crop;
const flipped = angle % Math.PI === 0;
const aspectRatio = resolution.width / resolution.height;
const inverseAspectRatio = resolution.height / resolution.width;
base = getAspectRatioSize({
aspectRatio: flipped ? aspectRatio : inverseAspectRatio,
width: cropAspectRatio >= 1 ? undefined : crop.width,
height: cropAspectRatio >= 1 ? crop.height : undefined
});
let sizeModifier = 1;
if (base.height < crop.height) sizeModifier = crop.height / base.height;
if (base.width < crop.width) sizeModifier = crop.width / base.width;
base.width = base.width * sizeModifier;
base.height = base.height * sizeModifier;
const maxWidth = Math.abs(base.height * Math.sin(angle)) + Math.abs(base.width * Math.cos(angle));
const maxHeight = Math.abs(base.height * Math.cos(angle)) + Math.abs(base.width * Math.sin(angle));
return getAspectRatioSize({
aspectRatio: aspectRatio,
width: aspectRatio >= 1 ? undefined : maxWidth,
height: aspectRatio >= 1 ? maxHeight : undefined
});
};
//# sourceMappingURL=getCropRotatedSize.js.map