kpranav022's picture
Claude Opus 5.5 (1M context)
Stop paying twice, measure every run, and make the picture, voice and props hold up
13354e2
Raw History Blame Contribute Delete
3.07 kB
/** The caption look: one object instead of twelve setters, so the state, the
* save, the export payload and "Start fresh" all read the same fields and can't
* drift apart. Pure — see captionLook.check.ts. */
import type { Cue } from "./preview";
import type { CaptionSource } from "./model";
export type CaptionLook = {
captionSource: CaptionSource;
captionColor: string;
captionSize: number;
captionPosition: string;
captionX: number | null;
captionY: number | null;
captionFont: string;
captionBg: string;
captionBgOpacity: number;
captionAnimation: string;
captionKaraoke: boolean;
// "karaoke" is our own renderer; anything else is a social-native style key
// (see CAPTION_STYLES) drawn server-side in headless Chromium.
captionStyle: string;
};
/** Every style knob's starting value — the initial state AND what "Start fresh"
* restores, so the two can't drift apart. */
export const DEFAULTS: CaptionLook & { musicVolume: number } = {
captionSource: "script",
captionColor: "#FFFFFF",
captionSize: 52,
captionPosition: "bottom",
captionX: null,
captionY: null,
captionFont: "",
captionBg: "#000000",
captionBgOpacity: 0.45,
captionAnimation: "pop",
captionKaraoke: true,
captionStyle: "capcut-bounce",
musicVolume: 0.25,
};
const KEYS = [
"captionSource", "captionColor", "captionSize", "captionPosition", "captionX", "captionY",
"captionFont", "captionBg", "captionBgOpacity", "captionAnimation", "captionKaraoke",
"captionStyle",
] as const satisfies readonly (keyof CaptionLook)[];
/** Every knob from a save — or, from `{}`, back to its default. A key the save
* lacks (or holds null for) takes its default, as the per-setter version did. */
export function lookFrom(s: Partial<CaptionLook>): CaptionLook {
const out = {} as Record<string, unknown>;
for (const k of KEYS) out[k] = s[k] ?? DEFAULTS[k];
return out as CaptionLook;
}
export type LookAction =
| { type: "set"; patch: Partial<CaptionLook> }
| { type: "reset"; from?: Partial<CaptionLook> };
export function lookReducer(s: CaptionLook, a: LookAction): CaptionLook {
return a.type === "set" ? { ...s, ...a.patch } : lookFrom(a.from ?? {});
}
/** The caption half of the export request. Script cues only travel with the
* script source: AI transcription times itself at export. */
export function lookPayload(look: CaptionLook, cues: Cue[]) {
return {
captions: look.captionSource !== "none",
captionSource: look.captionSource,
captionCues:
look.captionSource === "script"
? cues.map((c) => ({ text: c.text, start: c.start, end: c.end }))
: [],
captionColor: look.captionColor,
captionSize: look.captionSize,
captionPosition: look.captionPosition,
captionX: look.captionX,
captionY: look.captionY,
captionFont: look.captionFont || null,
captionBgColor: look.captionBg,
captionBgOpacity: look.captionBgOpacity,
captionAnimation: look.captionAnimation,
captionKaraoke: look.captionKaraoke,
captionStyle: look.captionStyle,
};
}