16 lines
618 B
TypeScript
16 lines
618 B
TypeScript
export function getUploadedMediaNodeSize(
|
|
intrinsicWidth: number,
|
|
intrinsicHeight: number,
|
|
mediaType: "image" | "video",
|
|
) {
|
|
if (!(intrinsicWidth > 0) || !(intrinsicHeight > 0)) return null;
|
|
|
|
// The node has a 24px title and an 8px gap above the media viewport.
|
|
const maxWidth = mediaType === "video" ? 560 : 420;
|
|
const maxHeight = 560;
|
|
const scale = Math.min(maxWidth / intrinsicWidth, maxHeight / intrinsicHeight);
|
|
const width = Math.max(1, Math.round(intrinsicWidth * scale));
|
|
const mediaHeight = Math.max(1, Math.round(intrinsicHeight * scale));
|
|
return { width, height: mediaHeight + 32 };
|
|
}
|