Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadDetailsCardLayout.ts

41 lines1.3 KB

1import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2​
3export function resolveThreadDetailsCardDensity(
4 height: number,
5 content: { full: number; compact: number },
6) {
7 if (content.full === 0 || content.full <= height) return "full";
8 if (content.compact === 0 || content.compact <= height) return "compact";
9 return "essential";
11​
12/** The card uses leftover space. It never changes the conversation's width. */
13export function resolveThreadDetailsCardLayout({
14 container,
15 chat,
16 frame,
17 overlapsDetailsCard = false,
18}: {
19 container: { width: number; height: number };
20 chat: { left: number; width: number };
21 frame: PreviewMiniPlayerFrame | null;
22 overlapsDetailsCard?: boolean;
23}) {
24 const gap = 12;
25 const width = Math.min(312, container.width - chat.left - chat.width - gap * 2);
26 if (width < 240) return null;
27 const x = container.width - width - gap;
28 // Resizing consumes the height above the player. Dragging first tries to
29 // clear the full card and folds it only when there is no readable placement.
30 const height =
31 overlapsDetailsCard && frame && frame.x + frame.width > x - gap && frame.x < x + width + gap
32 ? Math.min(container.height - gap * 2, frame.y - gap * 2)
33 : container.height - gap * 2;
34 if (height < 160) return null;
35 return {
36 x,
37 width,
38 y: gap,
39 height,
40 } as const;