// The intro's words and its title card (lane intro-play, 9 Nov 2026): `title`, `lines`, the // `title-card` style (the project's title and date over the brand), and the page that draws them. import { test } from "node:test"; import assert from "node:assert/strict"; import { INTRO_LINE_MAX, INTRO_LINES_MAX, INTRO_SECONDS, INTRO_SECONDS_MAX, INTRO_SECONDS_MIN, INTRO_STYLES, INTRO_TITLE_MAX, introErrors, introOf, } from "yt-dlp-transcript-common/lib/report/intro.mjs"; import { introDateWords, introEntry, introManifest, introPageHtml, introWords } from "./intro.mjs"; import { INTRO_FONT_ASSET, introCues, introHtml, introPalette, lockupParts, wordsLayout } from "./chrome-intro.mjs"; import { brandKit } from "./brand.mjs"; const kit = brandKit("archilyzer-media"); test("title-card is a style; the brand sting stays first, and a new intro's default", async () => { assert.ok(INTRO_STYLES.includes("title-card")); assert.equal(INTRO_STYLES[0], "boot"); const { INTRO_STYLE_DEFAULT } = await import("yt-dlp-transcript-common/lib/report/intro.mjs"); assert.equal(INTRO_STYLE_DEFAULT, "boot-dark"); assert.deepEqual(introErrors("title-card"), []); const o = introOf({ intro: "title-card" }); assert.deepEqual([o.ground, o.mark], ["dark", "chime"], "title-card: dark, the mark on the chime"); }); test("title and lines: one line each, the title at most 80, at most 3 lines; each refused by its name", () => { assert.deepEqual(introErrors({ style: "boot-dark", title: "In her own words", lines: ["29 October 2026"] }), []); assert.deepEqual(introErrors({ style: "title-card", lines: [] }), [], "no lines is a list"); assert.match(introErrors({ style: "boot", title: "" }).join(), /render\.intro\.title must be one line of 1 to 80/); assert.match(introErrors({ style: "boot", title: "x".repeat(INTRO_TITLE_MAX + 1) }).join(), /render\.intro\.title/); assert.deepEqual(introErrors({ style: "boot", title: "x".repeat(INTRO_TITLE_MAX) }), []); assert.match(introErrors({ style: "boot", title: "two\nlines" }).join(), /render\.intro\.title must be one line/); assert.match(introErrors({ style: "boot", title: 7 }).join(), /render\.intro\.title/); assert.match(introErrors({ style: "boot", lines: "29 October" }).join(), /render\.intro\.lines must be a list of at most 3/); assert.match(introErrors({ style: "boot", lines: Array(INTRO_LINES_MAX + 1).fill("a") }).join(), /at most 3/); assert.match(introErrors({ style: "boot", lines: ["ok", ""] }).join(), /render\.intro\.lines\[1\] must be one line/); assert.match(introErrors({ style: "boot", lines: ["y".repeat(INTRO_LINE_MAX + 1)] }).join(), /render\.intro\.lines\[0\]/); assert.match(introErrors({ style: "boot", subtitle: "x" }).join(), /render\.intro\.subtitle is not a key \(.*title, lines\)/); }); test("seconds: 3.5 to 8, inclusive", () => { assert.equal(INTRO_SECONDS_MIN, 3.5); assert.equal(INTRO_SECONDS_MAX, 8); assert.deepEqual(introErrors({ style: "title-card", seconds: 3.5 }), []); assert.deepEqual(introErrors({ style: "title-card", seconds: 8 }), []); for (const s of [3.49, 8.01, "5", Number.NaN]) assert.match(introErrors({ style: "title-card", seconds: s }).join(), /render\.intro\.seconds must be a number from 3\.5 to 8/, String(s)); }); test("introOf carries the words only when written, trimmed", () => { assert.ok(!("title" in introOf({ intro: "boot" }))); assert.ok(!("lines" in introOf({ intro: "boot" }))); const o = introOf({ intro: { style: "boot", title: " A title ", lines: [" one ", "two"] } }); assert.equal(o.title, "A title"); assert.deepEqual(o.lines, ["one", "two"]); }); test("title-card's words default to the project's title and its date; written words win; a boot style draws none unless written", () => { const m = { title: "EmberParadox, in her own words", generatedOn: "2026-10-29" }; assert.equal(introDateWords("2026-10-29"), "29 October 2026"); assert.equal(introDateWords("2026-13-01"), null); assert.equal(introDateWords(undefined), null); assert.deepEqual(introWords({ style: "title-card" }, m), { title: m.title, lines: ["29 October 2026"] }); assert.deepEqual(introWords({ style: "title-card", title: "Mine", lines: [] }, m), { title: "Mine" }, "lines: [] is none"); assert.deepEqual(introWords({ style: "title-card" }, {}), {}, "nothing to draw: the brand alone"); // A manifest title over two lines (or longer than a line) is ONE line of at most 80, which the build accepts. const two = introWords({ style: "title-card" }, { title: "Part 1\nThe long version" }); assert.equal(two.title, "Part 1 The long version"); assert.deepEqual(introErrors({ style: "title-card", title: two.title }), []); const long = introWords({ style: "title-card" }, { title: `${"é".repeat(78)}\n🎬🎬 tail` }); assert.equal(Array.from(long.title).length, 80); assert.deepEqual(introErrors({ style: "title-card", title: long.title }), []); assert.deepEqual(introWords({ style: "boot-dark" }, m), {}); assert.deepEqual(introWords({ style: "boot-dark", title: "T" }, m), { title: "T" }); // The entry the cut opens with carries them; selectVariant's door (introManifest) passes the manifest. const cut = introManifest({ ...m, render: { intro: "title-card" }, timeline: [{ id: "c1", type: "clip" }] }); assert.equal(cut.timeline[0].title, m.title); assert.deepEqual(cut.timeline[0].lines, ["29 October 2026"]); const plain = introEntry({ intro: "boot" }, { manifest: m }); assert.ok(!("title" in plain) && !("lines" in plain), "a plain intro's entry is what it was"); }); test("the page: no words, no face and no words block (byte for byte the old page); words, the face linked and each line drawn", async () => { const plain = introHtml({ style: "boot-dark", ground: "dark", seconds: INTRO_SECONDS, kit }); assert.ok(!plain.includes("IntroDisplay")); assert.ok(!plain.includes("intro-words")); const page = introHtml({ style: "title-card", ground: "dark", mark: "chime", seconds: INTRO_SECONDS, kit, title: "A title", lines: ["29 October 2026"] }); assert.ok(page.includes(`url('${INTRO_FONT_ASSET}')`)); assert.match(page, /