Files
songs2vid/lib/preview-typography.ts
Atakan Doğan Özban 848607f9e0 Add lower-corner layouts, custom blur backgrounds, and classic blur fill.
Ship composition families, optional background images for lower-corner templates, and an optional blurred cover fill for classic letterbox.
2026-08-07 00:51:37 +02:00

47 lines
1.6 KiB
TypeScript

/**
* Shared typography math for dashboard preview ↔ FFmpeg output parity.
* Preview container uses a fixed reference width; scale from target encode resolution.
*/
import type { WatermarkFontKey } from "./fonts";
import { CURATED_FONTS, SYSTEM_FONT } from "./fonts";
/** Matches LayoutStudio max preview width (tailwind max-w-xl ≈ 576px; use 576 for scaling). */
export const PREVIEW_REFERENCE_WIDTH = 576;
export function titleFontSizeForWidth(width: number): number {
return Math.max(22, Math.round(width * 0.032));
}
export function artistFontSizeForWidth(width: number): number {
return Math.max(16, Math.round(width * 0.02));
}
export function watermarkFontSizeForWidth(width: number): number {
return Math.max(22, Math.round(width * 0.028));
}
/** Scale encode-resolution px to preview container px. */
export function scaleFontToPreview(fontPx: number, encodeWidth: number): number {
const ref = encodeWidth > 0 ? encodeWidth : 1280;
return Math.max(8, Math.round((fontPx * PREVIEW_REFERENCE_WIDTH) / ref));
}
export function previewFontFamilyCss(fontKey: WatermarkFontKey | undefined): string {
if (!fontKey || fontKey === "system") {
return `'${SYSTEM_FONT.previewFamily}', sans-serif`;
}
if (fontKey === "custom") {
return "'S2VIDCustomWm', sans-serif";
}
const meta = CURATED_FONTS.find((f) => f.key === fontKey);
return meta ? `'S2VIDPreview-${meta.key}', sans-serif` : "sans-serif";
}
export function curatedFontApiUrl(key: string): string {
return `/api/fonts/${key}`;
}
/** Watermark overlay width as fraction of frame (matches encode.ts). */
export const WATERMARK_WIDTH_FRACTION = 0.42;