Open History to see the last commit
1import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2import { DETAILS_CARD_CLEARANCE } from "./chatCanvasLayout";
3
4export const THREAD_DETAILS_CARD_GAP = 12;
5
6export function resolveThreadDetailsCardDensity(
7 height: number,
8 content: { full: number; compact: number },
9) {
10 if (content.full === 0 || content.full <= height) return "full";
11 if (content.compact === 0 || content.compact <= height) return "compact";
12 return "essential";
13}
14
15export function resolveThreadDetailsCardLayout({
16 container,
17 narrowestWidth = container.width,
18 width,
19 lane,
20 frame,
21 overlapsDetailsCard = false,
22 topInset = 0,
23}: {
24 container: { width: number; height: number };
25 // While a panel animates the container, the card fits only if it fits at both ends.
26 narrowestWidth?: number;
27 /** The measured --thread-details-panel-width, which scales with the interface font size. */
28 width: number;
29 lane: { padding: number; minChatWidth: number };
30 frame: PreviewMiniPlayerFrame | null;
31 overlapsDetailsCard?: boolean;
32 topInset?: number;
33}) {
34 const gap = THREAD_DETAILS_CARD_GAP;
35 const x = container.width - width - gap;
36 // The transition ends are sampled once, so a resize mid-animation can leave them
37 // wider than the container is now.
38 const fitWidth = Math.min(narrowestWidth, container.width);
39 if (fitWidth - width - gap - DETAILS_CARD_CLEARANCE - lane.padding < lane.minChatWidth)
40 return null;
41 const y = gap + topInset;
42 const height =
43 overlapsDetailsCard && frame && frame.x + frame.width > x - gap && frame.x < x + width + gap
44 ? Math.min(container.height - y - gap, frame.y - y - gap)
45 : container.height - y - gap;
46 if (height < 160) return null;
47 return {
48 x,
49 right: gap,
50 width,
51 y,
52 height,
53 } as const;
54}