2979d06f1c
Align control/presentation with presentation screen rect and darkness z-order; sync window titles and session window cleanup. Pack Win/Mac/Linux with npmRebuild disabled and release-native-prep for classic-level and sharp. Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
693 B
TypeScript
23 lines
693 B
TypeScript
/** Вписать прямоугольник целевого аспекта в бокс (как object-fit: contain). */
|
|
export function fitAspectRect(
|
|
boxW: number,
|
|
boxH: number,
|
|
aspectW: number,
|
|
aspectH: number,
|
|
): { x: number; y: number; w: number; h: number } {
|
|
const bw = Math.max(1, boxW);
|
|
const bh = Math.max(1, boxH);
|
|
const aw = Math.max(1, aspectW);
|
|
const ah = Math.max(1, aspectH);
|
|
const boxAspect = bw / bh;
|
|
const targetAspect = aw / ah;
|
|
if (boxAspect > targetAspect) {
|
|
const h = bh;
|
|
const w = h * targetAspect;
|
|
return { x: (bw - w) / 2, y: 0, w, h };
|
|
}
|
|
const w = bw;
|
|
const h = w / targetAspect;
|
|
return { x: 0, y: (bh - h) / 2, w, h };
|
|
}
|