| 1 | export interface ComposerContentSizing { |
| 2 | inputHeight: number; |
| 3 | logicalHeight: number | null; |
| 4 | overflow: boolean; |
| 5 | } |
| 6 | |
| 7 | export function resolveComposerContentSizing({ |
| 8 | contentHeight, |
| 9 | manualLogicalHeight, |
| 10 | maxLogicalHeight, |
| 11 | reservedHeight, |
| 12 | minInputHeight = 32, |
| 13 | }: { |
| 14 | contentHeight: number; |
| 15 | manualLogicalHeight: number | null; |
| 16 | maxLogicalHeight: number; |
| 17 | reservedHeight: number; |
| 18 | minInputHeight?: number; |
| 19 | }): ComposerContentSizing { |
| 20 | const safeContentHeight = Math.max(0, contentHeight); |
| 21 | const maxInputHeight = Math.max(minInputHeight, maxLogicalHeight - reservedHeight); |
| 22 | const manualInputHeight = manualLogicalHeight === null |
| 23 | ? 0 |
| 24 | : Math.max(minInputHeight, manualLogicalHeight - reservedHeight); |
| 25 | const inputHeight = Math.min(Math.max(safeContentHeight, manualInputHeight), maxInputHeight); |
| 26 | const logicalHeight = manualLogicalHeight === null |
| 27 | ? null |
| 28 | : Math.min(maxLogicalHeight, Math.max(manualLogicalHeight, inputHeight + reservedHeight)); |
| 29 | |
| 30 | return { |
| 31 | inputHeight, |
| 32 | logicalHeight, |
| 33 | overflow: safeContentHeight > maxInputHeight + 1, |
| 34 | }; |
| 35 | } |
| 36 |