import type { GeneratorInput, GeneratorOutput, TranslationFn, CharLimitWarning, TitleFormatConfig, } from "./types"; import { buildTitle, checkTitleWarning } from "./title-builder"; import { buildDescription, checkDescriptionWarning } from "./description-builder"; import { generateTags, formatTagString, youtubeTagsLength, type TagOptions } from "./tag-generator"; import { YT_LIMITS } from "./types"; /** * Every {@link RenderOptions} knob that comes from the user's Settings. * * Split out from the per-caller knobs deliberately. Before v0.35.0 each of the * three `renderAll` call sites hand-copied this list out of the settings store, * and BatchPage's copy was missing `splitContactEmail` and `showThirdPartyAds` * โ€” so a creator with the split-email toggle on saw all three contact lines on * the Output tab and only the old single "Business inquiries" line in Batch. * * Naming the set lets `buildRenderOptions` return `Required`, * which makes a forgotten key a compile error rather than a silent omission. * See `src/hooks/use-render-options.ts` and its parity test. */ export interface SettingsRenderOptions extends Omit { hashtagCount?: number; /** * When true, buildTitle appends a `[2K 60FPS]`-style badge to the * video-type segment whenever resolution/fps are above the defaults. * Defaults to true at the engine level; callers override with the * user's setting. */ showQualityBadge?: boolean; /** * Title formatting knobs (badge position, separator, badge case). * Partial โ€” any omitted sub-key falls back to the v0.6 default inside * buildTitle. Flowed from the user's Settings. */ titleFormat?: Partial; /** * When true (and channelName is non-empty), the description ends with * an auto-generated `ยฉ . All rights reserved.` line. */ showCopyright?: boolean; /** * When true, the description appends a localised "usage policy" block * (๐Ÿ“‹ USAGE POLICY) after the copyright line. */ showUsagePolicy?: boolean; /** * When true and both `sponsorName` and `sponsorPlatform` are set on * the input, the description emits a "๐ŸŽ Thanks to โ€ฆ" credit line * above the music / donate block. */ showSponsorCredit?: boolean; /** * When true and the active profile's `thirdPartyAdText` is non-empty, * the description emits a "๐Ÿค SPONSORS & PARTNERS" block above the * music section (v0.11). */ showThirdPartyAds?: boolean; /** * When true, the description's contact block splits into up to three * labeled lines by purpose (general / advertising / game keys & * playtest) instead of the single "๐Ÿ“ง Business inquiries" line. v0.34.0. */ splitContactEmail?: boolean; /** * When true and the editor's `pubDevName` is non-empty, the description * emits a `ยฉ {publisher}. All rights reserved.` line right after the * Store Links block (v0.21.0). Opt-in โ€” meant for games whose * dev/publisher contractually requires attribution in the description. */ showGameCopyright?: boolean; /** * When true, the description appends an AI-translation disclaimer block * for output languages outside the trusted set (English / Vietnamese). * v0.24.0. */ showTranslationQuality?: boolean; } /** * The knobs a *caller* decides, not the user. These vary by render surface โ€” * the Output tab wants bilingual content blocks, the multi-language tabs and * Batch do not โ€” so they are supplied per call site rather than read from * Settings. */ export interface RenderOptionOverrides { /** * Optional English-fixed translation function. Used by the v0.11 * unified content-warnings block to render bilingual lines * `EN ยท output-language`. When omitted, the warnings block falls back * to single-language output via `t`. */ tEn?: TranslationFn; /** * When false, the three "video" content blocks (content warnings, tech * notes, playthrough notes) render single-language even though `tEn` is * supplied โ€” used by the multi-language Output tabs, where each tab is * already a single target language. The AI-translation disclaimer is * unaffected and stays bilingual. Defaults to true. v0.29.3. */ bilingualContentBlocks?: boolean; /** * The year for the copyright line and the trending tags. Passed in so the * engine never reads the clock itself (and tests are deterministic); the * current year when omitted. */ year?: number; } export interface RenderOptions extends SettingsRenderOptions, RenderOptionOverrides {} export function renderAll( input: GeneratorInput, t: TranslationFn, options?: RenderOptions, ): GeneratorOutput { const title = buildTitle(input, t, { showQualityBadge: options?.showQualityBadge ?? true, badgePosition: options?.titleFormat?.badgePosition, separator: options?.titleFormat?.separator, badgeCase: options?.titleFormat?.badgeCase, order: options?.titleFormat?.order, }); const description = buildDescription(input, t, { hashtagCount: options?.hashtagCount, showCopyright: options?.showCopyright, showUsagePolicy: options?.showUsagePolicy, showSponsorCredit: options?.showSponsorCredit, showThirdPartyAds: options?.showThirdPartyAds, splitContactEmail: options?.splitContactEmail, showGameCopyright: options?.showGameCopyright, showTranslationQuality: options?.showTranslationQuality, tEn: options?.tEn, bilingualContentBlocks: options?.bilingualContentBlocks, year: options?.year, }); const tags = generateTags(input, options); const tagString = formatTagString(tags); // YouTube's own count (quotes around multi-word tags, one comma between // tags) โ€” not the length of the ", "-joined string we hand to the clipboard. const tagsLength = youtubeTagsLength(tags); const charCounts = { title: title.length, description: description.length, tags: tagsLength, }; const warnings: CharLimitWarning[] = []; const titleWarning = checkTitleWarning(title); if (titleWarning) warnings.push(titleWarning); const descWarning = checkDescriptionWarning(description); if (descWarning) warnings.push(descWarning); if (tagsLength > YT_LIMITS.TAGS_MAX) { warnings.push({ field: "tags", current: tagsLength, limit: YT_LIMITS.TAGS_MAX, message: `Tags exceed ${YT_LIMITS.TAGS_MAX} characters (${tagsLength}/${YT_LIMITS.TAGS_MAX})`, }); } return { title, description, tags, tagString, charCounts, warnings, }; }