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

threadDetailsCardLayout.ts

53 lines1.8 KB

1import type { PreviewMiniPlayerFrame } from "../preview/previewMiniPlayerLayout";
2import { DETAILS_CARD_CLEARANCE } from "./chatCanvasLayout";
3​
4/** Inset of the card from the canvas edges; the find bar shares it to line up. */
5export const THREAD_DETAILS_CARD_GAP = 12;
6​
7export function resolveThreadDetailsCardDensity(
8 height: number,
9 content: { full: number; compact: number },
10) {
11 if (content.full === 0 || content.full <= height) return "full";
12 if (content.compact === 0 || content.compact <= height) return "compact";
13 return "essential";
15​
16/**
17 * The card pins to the top right while a readable chat lane fits beside it.
18 * The chat canvas decides whether chat moves over to make room.
19 */
20export function resolveThreadDetailsCardLayout({
21 container,
22 lane,
23 frame,
24 overlapsDetailsCard = false,
25 topInset = 0,
26}: {
27 container: { width: number; height: number };
28 lane: { padding: number; minChatWidth: number };
29 frame: PreviewMiniPlayerFrame | null;
30 overlapsDetailsCard?: boolean;
31 /** Space taken above the card, such as the open find bar. */
32 topInset?: number;
33}) {
34 const gap = THREAD_DETAILS_CARD_GAP;
35 // Keep in sync with --thread-details-panel-width, which sizes the popover.
36 const width = 280;
37 const x = container.width - width - gap;
38 if (x - DETAILS_CARD_CLEARANCE - lane.padding < lane.minChatWidth) return null;
39 const y = gap + topInset;
40 // Resizing consumes the height above the player. Dragging first tries to
41 // clear the full card and folds it only when there is no readable placement.
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 width,
50 y,
51 height,
52 } as const;