Files
songs2vid/lib/preview-typography.ts
T
Atakan Doğan ÖzbanandCursor 56880256e5 Enlarge watermark badge for preview/encode parity and document video title fields.
Fix double-scaled badge preview, bump default watermark to 42% frame width, and update OSS docs/API for title vs songTitle separation and shared typography.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 18:28:07 +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 } 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 "Arial, Helvetica, sans-serif";
}
if (fontKey === "custom") {
return "'S2VIDCustomWm', Arial, sans-serif";
}
const meta = CURATED_FONTS.find((f) => f.key === fontKey);
return meta ? `'S2VIDPreview-${meta.key}', Arial, sans-serif` : "Arial, 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;