sailfork / t3code-github / apps/ web/ src/ components/ device/ deviceFrameLayout.ts

export function fitDeviceFrame(aspect: number, width: number, height: number, rightInset: number) {
  const availableWidth = Math.max(0, width - rightInset);
  if (availableWidth === 0 || height === 0) return { width: 0, height: 0 };
  const byHeight = { width: height * aspect, height };
  return byHeight.width <= availableWidth
    ? byHeight
    : { width: availableWidth, height: availableWidth / aspect };
}