Open History to see the last commit
1import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2import { DETAILS_CARD_CLEARANCE } from "./chatCanvasLayout";
3
4export function resolveThreadDetailsCardDensity(
5 height: number,
6 content: { full: number; compact: number },
7) {
8 if (content.full === 0 || content.full <= height) return "full";
9 if (content.compact === 0 || content.compact <= height) return "compact";
10 return "essential";
11}
12
13/**
14 * The card pins to the top right while a readable chat lane fits beside it.
15 * The chat canvas decides whether chat moves over to make room.
16 */
17export function resolveThreadDetailsCardLayout({
18 container,
19 lane,
20 frame,
21 overlapsDetailsCard = false,
22}: {
23 container: { width: number; height: number };
24 lane: { padding: number; minChatWidth: number };
25 frame: PreviewMiniPlayerFrame | null;
26 overlapsDetailsCard?: boolean;
27}) {
28 const gap = 12;
29 // Keep in sync with --thread-details-panel-width, which sizes the popover.
30 const width = 280;
31 const x = container.width - width - gap;
32 if (x - DETAILS_CARD_CLEARANCE - lane.padding < lane.minChatWidth) return null;
33 // Resizing consumes the height above the player. Dragging first tries to
34 // clear the full card and folds it only when there is no readable placement.
35 const height =
36 overlapsDetailsCard && frame && frame.x + frame.width > x - gap && frame.x < x + width + gap
37 ? Math.min(container.height - gap * 2, frame.y - gap * 2)
38 : container.height - gap * 2;
39 if (height < 160) return null;
40 return {
41 x,
42 width,
43 y: gap,
44 height,
45 } as const;
46}