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

threadDetailsCardLayout.ts

54 lines1.8 KB

1import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2import { DETAILS_CARD_CLEARANCE } from "./chatCanvasLayout";
3​
4export const THREAD_DETAILS_CARD_GAP = 12;
5// Keep in sync with --thread-details-panel-width.
6const THREAD_DETAILS_CARD_WIDTH = 280;
7​
8export function resolveThreadDetailsCardDensity(
9 height: number,
10 content: { full: number; compact: number },
11) {
12 if (content.full === 0 || content.full <= height) return "full";
13 if (content.compact === 0 || content.compact <= height) return "compact";
14 return "essential";
16​
17export function resolveThreadDetailsCardLayout({
18 container,
19 narrowestWidth = container.width,
20 lane,
21 frame,
22 overlapsDetailsCard = false,
23 topInset = 0,
24}: {
25 container: { width: number; height: number };
26 // While a panel animates the container, the card fits only if it fits at both ends.
27 narrowestWidth?: number;
28 lane: { padding: number; minChatWidth: number };
29 frame: PreviewMiniPlayerFrame | null;
30 overlapsDetailsCard?: boolean;
31 topInset?: number;
32}) {
33 const gap = THREAD_DETAILS_CARD_GAP;
34 const width = THREAD_DETAILS_CARD_WIDTH;
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;