// The brand intro's composition (`render.intro`, intro.mjs): one full-frame // HyperFrames page -- "Archilyzer" built in on the first sound, "media" under // it on the chime, after the Game Boy Advance boot screen. // // PURE, like chrome-teaser.mjs: a style, a ground, a size and the brand kit in, // an HTML string out. intro.mjs writes it beside GSAP, renders it and encodes // the frames with the intro's sound. // // The letters are the brand's own drawing, not a font: the lockup's glyph // paths (brands/archilyzer-media.json, drawn by common/lib/brandMedia.ts), // each wrapped in its own group so it can tumble, drop or be wiped in. So the // intro lands on exactly the wordmark the title card, the end card and the // sites carry -- "Archi" heavy, "lyzer" light, MEDIA spread to its width -- and // no face has to load in the render browser. // // The motion is a cue list computed here (the deck's and the teaser's reason: // a render is a seek per frame, from parallel workers, in any order). Every // cue is a fromTo whose FROM is stated; the page is a dumb interpreter of // `introCues`, so the tests read every time it uses. import { fileURLToPath } from "node:url"; import { INTRO_BEATS, INTRO_PROJECT_URL, INTRO_SITE_DEFAULTS, INTRO_STYLE_MARK, INTRO_SUFFIX, introSitePrefix, introUrlText, } from "yt-dlp-transcript-common/lib/report/intro.mjs"; import { pageDuration } from "./deck.mjs"; import { INTRO_GLYPHS, INTRO_GLYPH_CAP, INTRO_GLYPH_UPEM } from "./intro-glyphs.mjs"; const r3 = (v) => Math.round(v * 1000) / 1000; /** * The words' face (`title`, `lines`): Archivo, the face the wordmark's letters * were drawn from (intro-glyphs.mjs), copied in beside the page as * `assets/IntroDisplay.ttf` under a private name -- only when the page draws * words, so a page without them loads no face, as it never did. */ export const INTRO_FONT_FILE = (() => { // chrome-deck.mjs assetFile's rule, inline (chrome-deck imports this module): chrome-deck brings this module into // build-video's static chain, and in umtool's server bundle the asset URL is the bundler's own, which // fileURLToPath refuses at module load (docs/quirks.md) -- its string is kept there. const url = new URL("./fonts/Archivo[wdth,wght].ttf", import.meta.url); try { return fileURLToPath(url); } catch { return String(url); } })(); export const INTRO_FONT_ASSET = "assets/IntroDisplay.ttf"; const esc = (s) => String(s ?? "") .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); /** A small seeded PRNG (mulberry32): the tumble is the same on every seek of every render. */ function seeded(seed) { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } // The accents (common/lib/brand.ts ACCENTS, picker order): the tumble paints // one site's accent per letter, as the GBA's letters come in five colours. // Each ground takes the accent's value for it -- the on-light values are the // contrast-corrected ones. const ACCENTS = [ { id: "signal", dark: "#5fa8a0", light: "#2e7b73" }, { id: "brass", dark: "#e3b15c", light: "#95661a" }, { id: "vermilion", dark: "#ec7a52", light: "#b3431f" }, { id: "violet", dark: "#b49cf2", light: "#6a4bc4" }, { id: "sakura", dark: "#ee8fb5", light: "#a83a6a" }, { id: "blue", dark: "#74a9f2", light: "#2d5fb8" }, { id: "green", dark: "#7cc46a", light: "#3f7a2c" }, ]; const accent = (id, ground) => ACCENTS.find((a) => a.id === id)[ground]; /** * The colours of each ground. Dark is the video preset's palette (the report * videos' own); light is the sites' light base (#f3f6f7) with the dark * ground's slate as the ink. */ export function introPalette(ground, kit) { if (ground === "dark") { return { ground: kit.palette.bg, lead: kit.palette.fg, suffix: kit.palette.muted, media: kit.palette.accent, dim: kit.palette.dim, lit: kit.palette.accent, tumble: ACCENTS.map((a) => a.dark), shimmer: [accent("signal", "dark"), "#ffffff"], // The mark's square on its own ground would vanish: a step above it // (common/lib/brandMedia.ts MEDIA_FIELD_LINE, the banner's field). markGround: "#1e262d", }; } return { ground: "#f3f6f7", lead: kit.palette.bg, suffix: kit.palette.dim, media: accent("signal", "light"), dim: "#9aa8b2", lit: accent("signal", "light"), tumble: ACCENTS.map((a) => a.light), shimmer: [accent("signal", "light"), accent("violet", "light")], markGround: kit.palette.bg, }; } // --------------------------------------------------------------------------- // The lockup, read back off the kit's SVG. // --------------------------------------------------------------------------- const PATH_RE = //g; /** A glyph path's extent in its own units: every absolute coordinate pair (M L Q), H's x and V's y. */ function glyphBox(d) { const xs = []; const ys = []; for (const m of d.matchAll(/([MLQHVZ])([^MLQHVZ]*)/g)) { const nums = (m[2].match(/-?\d*\.?\d+/g) ?? []).map(Number); if (m[1] === "H") xs.push(...nums); else if (m[1] === "V") ys.push(...nums); else for (let i = 0; i + 1 < nums.length; i += 2) { xs.push(nums[i]); ys.push(nums[i + 1]); } } return { x0: Math.min(...xs), x1: Math.max(...xs), y0: Math.min(...ys), y1: Math.max(...ys) }; } /** * The lockup's pieces in lockup units (its `px`, 100): the mark's shapes, and * the letters of "Archi" (lead), "lyzer" (suffix) and "MEDIA" (media), each * with its path, its transform and its box. Text x is measured from the text's * own left edge (the mark sits to its left, `markRight` units). */ export function lockupParts(kit) { const svg = kit.lockup.svg; const groups = [...svg.matchAll(/(.*?)<\/g>/g)]; if (groups.length !== 3) throw new Error(`the brand kit's lockup has ${groups.length} glyph groups, expected 3 (lead, suffix, MEDIA)`); const roles = ["lead", "suffix", "media"]; const letters = []; let left = Infinity; groups.forEach((g, gi) => { for (const m of g[2].matchAll(PATH_RE)) { const [tx, ty, s] = [Number(m[1]), Number(m[2]), Number(m[3])]; const b = glyphBox(m[4]); const box = { x0: tx + s * b.x0, x1: tx + s * b.x1, y0: ty + s * b.y0, y1: ty + s * b.y1 }; left = Math.min(left, box.x0, tx); letters.push({ role: roles[gi], tx, ty, s, d: m[4], box }); } }); const shift = (l) => ({ ...l, tx: r3(l.tx - left), box: { ...l.box, x0: r3(l.box.x0 - left), x1: r3(l.box.x1 - left) }, }); const out = letters.map(shift); const markSvg = /(.*?)<\/svg>/.exec(svg); const mark = markSvg ? { x: Number(markSvg[1]) - left, y: Number(markSvg[2]), size: Number(markSvg[3]), body: markSvg[5] } : null; const text = out.filter((l) => l.role !== "media"); const media = out.filter((l) => l.role === "media"); return { letters: out, mark, width: r3(Math.max(...out.map((l) => l.box.x1))), top: r3(Math.min(...out.map((l) => l.box.y0))), bottom: r3(Math.max(...out.map((l) => l.box.y1))), wordBottom: r3(Math.max(...text.map((l) => l.box.y1))), mediaTop: r3(Math.min(...media.map((l) => l.box.y0))), }; } // --------------------------------------------------------------------------- // The site swap (`render.intro.site`). // --------------------------------------------------------------------------- /** * The project's own URL, as the intro writes it: common/lib/project.ts * PROJECT_URL without its scheme -- the default; `render.intro.projectUrl` * sets another brand's (or false: none). */ export const PROJECT_URL_TEXT = INTRO_PROJECT_URL; /** The weights the swap draws in (intro-glyphs.mjs): the wordmark's lead and suffix, and the URLs. */ const W_LEAD = 720; const W_SUFFIX = 380; const W_URL = 600; /** The swap's beat: how long the prefix takes to change, from the chime. */ export const SWAP_SECONDS = 0.35; /** A portrait intro's vertical centre, as a fraction of the height: the middle of the Shorts safe area (8 % top, 20 % bottom). */ export const PORTRAIT_SAFE_CENTRE = (0.08 + (1 - 0.2)) / 2; /** A portrait intro's widest drawing, as a fraction of the width: inside 12 % of either side. */ export const PORTRAIT_SAFE_WIDTH = 1 - 2 * 0.12; // The contrast rule (common/lib/brand.ts): an accent reads at 4.5:1 on its ground. const MIN_CONTRAST = 4.5; function luminance(hex) { const n = parseInt(hex.slice(1, 7), 16); const ch = (c) => { const v = c / 255; return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; }; return 0.2126 * ch((n >> 16) & 255) + 0.7152 * ch((n >> 8) & 255) + 0.0722 * ch(n & 255); } /** WCAG contrast of two "#rrggbb". */ export function contrast(a, b) { const [x, y] = [luminance(a), luminance(b)]; return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); } /** A custom hex fitted to a ground: mixed toward white (dark ground) or black (light) in 1 % steps until it reads (common/lib/accent.ts fitAccent's way). */ function fitTo(hex, ground) { if (contrast(hex, ground) >= MIN_CONTRAST) return hex.toLowerCase(); const n = parseInt(hex.slice(1), 16); const rgb = [(n >> 16) & 255, (n >> 8) & 255, n & 255]; const target = luminance(ground) < 0.2 ? 255 : 0; for (let step = 1; step <= 100; step++) { const out = `#${rgb.map((c) => Math.round(c + (target - c) * (step / 100)).toString(16).padStart(2, "0")).join("")}`; if (contrast(out, ground) >= MIN_CONTRAST) return out; } return target ? "#ffffff" : "#000000"; } /** * A site's accent on the intro's ground: `{ ink, mark }` -- the letters' and * URLs' colour on this ground (a named accent's value for it, the base×accent * rule; a custom hex fitted to it), and the mark's lit line, which sits on the * mark's own dark square on either ground (a child site's icon: the on-dark value). */ export function introAccent(accent, ground, palette) { const id = typeof accent === "string" ? accent.trim().toLowerCase() : ""; const named = ACCENTS.find((a) => a.id === (id || "signal")); if (named) return { ink: named[ground], mark: named.dark }; const hex = /^#[0-9a-f]{6}$/i.test(id) ? id : ACCENTS[0][ground]; return { ink: fitTo(hex, palette.ground), mark: fitTo(hex, palette.markGround) }; } /** * One run of text in the swap's glyph table: each character's path, origin * and ink box, in lockup units (`size` units per em), kerned within a weight * (a browser kerns inside one span, not across two), `track` units added at * every gap. `weightOf(i)` picks each letter's weight. */ export function setRun(text, { size, track = 0, weightOf = () => W_URL, x = 0, baseline = 0 }) { const s = size / INTRO_GLYPH_UPEM; const chars = [...text]; const out = []; let pen = x; chars.forEach((ch, i) => { const w = weightOf(i); const g = INTRO_GLYPHS[w].glyphs[ch]; if (!g) throw new Error(`render.intro.site: the intro cannot draw ${JSON.stringify(ch)} (in ${JSON.stringify(text)})`); out.push({ ch, w, tx: r3(pen), ty: r3(baseline), s: r3(s), d: g.d, box: { x0: r3(pen + g.l * s), x1: r3(pen + g.r * s), y0: r3(baseline + g.t * s), y1: r3(baseline + g.b * s) }, }); const next = chars[i + 1]; if (next !== undefined) { const kern = weightOf(i + 1) === w ? (INTRO_GLYPHS[w].kern[ch + next] ?? 0) : 0; pen += (g.a + kern) * s + track; } else pen += g.a * s; }); return { glyphs: out, end: r3(pen), x0: Math.min(...out.map((g) => g.box.x0)), x1: Math.max(...out.map((g) => g.box.x1)) }; } /** * What the swap changes, from the site and the lockup: the old letters that * go (`out`, indexes into the wordmark), the new ones (`glyphs`, right-aligned * to the letters that stay), the shift that re-centres the word (`recenter`), * MEDIA re-spread to the new word's width, the mark's new place, and the URL * lines with the lift that keeps the whole drawing centred. * * The name keeps what it shares of "lyzer" (introSitePrefix): "Jeralyzer" * swaps "Archi" for "Jera" and keeps "lyzer"; its lead ("Jer", the site's * wordmarkLead) is heavy and the rest light, as the site's own header splits * it. A lead that runs into "lyzer" (Bonnell|yzer) takes those letters too; a * name not ending in "lyzer" swaps the whole word. */ export function swapPlan({ parts, site, url = INTRO_SITE_DEFAULTS.url, urlPlace = INTRO_SITE_DEFAULTS.urlPlace, markX = null, suffix = INTRO_SUFFIX, projectUrl = PROJECT_URL_TEXT, }) { const word = parts.letters.filter((l) => l.role !== "media"); const media = parts.letters.filter((l) => l.role === "media"); const nW = word.length; const name = String(site.name); let prefix = introSitePrefix(name, suffix); const lead = typeof site.lead === "string" && name.startsWith(site.lead) && site.lead.length < name.length ? site.lead : null; if (lead && lead.length > prefix.length) prefix = name.slice(0, lead.length); const keep = name.length - prefix.length; const heavy = lead ? Math.min(lead.length, prefix.length) : prefix.length; const out = [...Array(nW - keep).keys()]; const kept = word.slice(nW - keep); const s = word[0].s; // The wordmark's own tracking per gap, read back off the lockup ("A" to "r"). const A = INTRO_GLYPHS[W_LEAD].glyphs.A; if (word[0].d !== A.d) throw new Error("the brand kit's wordmark does not open with intro-glyphs.mjs's \"A\" — regenerate one of them"); const track = r3(word[1].tx - word[0].tx - (A.a + (INTRO_GLYPHS[W_LEAD].kern.Ar ?? 0)) * s); const size = s * INTRO_GLYPH_UPEM; const weightOf = (i) => (i < heavy ? W_LEAD : W_SUFFIX); const run = setRun(prefix, { size, track, weightOf, baseline: word[0].ty }); // Right-aligned to the first kept letter (its gap before it, and the kerning // when the last new letter is light, the same run as "lyzer"); a whole-word // swap starts where the old word did. let shift = 0; if (kept.length) { const last = [...prefix].at(-1); const lastW = weightOf(prefix.length - 1); const kern = lastW === W_SUFFIX ? (INTRO_GLYPHS[W_SUFFIX].kern[last + name[prefix.length]] ?? 0) * s : 0; shift = kept[0].tx - (run.end + kern + track); } else { shift = word[0].tx - run.glyphs[0].tx; } const glyphs = run.glyphs.map((g, j) => ({ ...g, role: j < heavy ? "lead" : "suffix", tx: r3(g.tx + shift), box: { ...g.box, x0: r3(g.box.x0 + shift), x1: r3(g.box.x1 + shift) }, })); const oldL = Math.min(...word.map((l) => l.box.x0)); const oldR = Math.max(...word.map((l) => l.box.x1)); const newL = Math.min(...glyphs.map((g) => g.box.x0), ...kept.map((l) => l.box.x0)); const newR = Math.max(...glyphs.map((g) => g.box.x1), ...kept.map((l) => l.box.x1)); const recenter = r3((oldL + oldR) / 2 - (newL + newR) / 2); const centre = (oldL + oldR) / 2; const span = newR - newL; // MEDIA, spread to the new word's width (its gaps all change by the same // amount, never closer than 0.06 em), centred under it. const mL = Math.min(...media.map((l) => l.box.x0)); const mR = Math.max(...media.map((l) => l.box.x1)); const gaps = media.slice(1).map((l, j) => l.box.x0 - media[j].box.x1); let per = (span - (mR - mL)) / (media.length - 1); per = Math.max(per, 6 - Math.min(...gaps)); const mWidth = mR - mL + per * (media.length - 1); const mShift = centre - mWidth / 2 - mL; const mediaTx = media.map((l, j) => r3(l.tx + mShift + j * per)); const mediaBox = { x0: r3(mL + mShift), x1: r3(mL + mShift + mWidth) }; // The swap's line: what a prefix slides within, clipped (old and new ink, a // little room, never down into MEDIA). // Only the letters that move count: a "y" that stays would leave room for // a going letter's top to show through under the baseline. const moving = [...out.map((i) => word[i].box), ...glyphs.map((g) => g.box)]; const inkTop = Math.min(...moving.map((b) => b.y0)); const inkBottom = Math.max(...moving.map((b) => b.y1)); const line = { y0: r3(inkTop - 6), y1: r3(Math.min(inkBottom + 4, (inkBottom + parts.mediaTop) / 2)) }; // The URLs: the site's first, then the project's. const siteUrl = typeof site.url === "string" && site.url ? site.url : null; const texts = []; if ((url === "both" || url === "site") && siteUrl) texts.push({ text: siteUrl, tone: "site" }); const project = projectUrl === false ? null : introUrlText(projectUrl) || null; if ((url === "both" || url === "project") && project) texts.push({ text: project, tone: "project" }); const urls = []; const cap = INTRO_GLYPH_CAP / INTRO_GLYPH_UPEM; let bottom = parts.bottom; if (texts.length) { const unit = (t) => setRun(t, { size: 100, track: 2 }); if (urlPlace === "under") { // One row under MEDIA, side by side, a wide space between: centred // under the whole drawing (the mark too, when there is one) and as wide // as it at most. const sep = 100; const nat = texts.map((t) => unit(t.text)); const natW = nat.reduce((a, r) => a + (r.x1 - r.x0), 0) + sep * (texts.length - 1); const wide = Math.max(span, mWidth); const room = markX === null ? wide : wide + (oldL - markX); const mid = markX === null ? centre : centre + (markX - oldL) / 2; const u = Math.min(34, (room * 100) / natW); const k = u / 100; const baseline = r3(parts.bottom + 30 + cap * u); let x = mid - (natW * k) / 2; texts.forEach((t, j) => { const r = setRun(t.text, { size: u, track: 2 * k, x: 0, baseline }); const dx = x - r.x0; urls.push({ ...t, glyphs: r.glyphs.map((g) => ({ ...g, tx: r3(g.tx + dx), box: { ...g.box, x0: r3(g.box.x0 + dx), x1: r3(g.box.x1 + dx) } })) }); x += r.x1 - r.x0 + sep * k; }); bottom = Math.max(...urls.flatMap((l) => l.glyphs.map((g) => g.box.y1))); } else { // In MEDIA's place: one line each, the same size, each centred, fitting the word's width. const nat = texts.map((t) => unit(t.text)); const natW = Math.max(...nat.map((r) => r.x1 - r.x0)); const u = Math.min(texts.length > 1 ? 48 : 60, (span * 100) / natW); const k = u / 100; let baseline = parts.mediaTop + cap * u; texts.forEach((t) => { const r = setRun(t.text, { size: u, track: 2 * k, x: 0, baseline: r3(baseline) }); const dx = centre - (r.x0 + r.x1) / 2; urls.push({ ...t, glyphs: r.glyphs.map((g) => ({ ...g, tx: r3(g.tx + dx), box: { ...g.box, x0: r3(g.box.x0 + dx), x1: r3(g.box.x1 + dx) } })) }); baseline += u * 1.18; }); bottom = Math.max(...urls.flatMap((l) => l.glyphs.map((g) => g.box.y1)), parts.wordBottom); } } return { prefix, keep, heavy, out, glyphs, recenter, oldL, newL, newR, mediaTx, mediaBox, line, urls, bottom: r3(bottom), hideMedia: urls.length > 0 && urlPlace === "replace", }; } // --------------------------------------------------------------------------- // The cues. // --------------------------------------------------------------------------- /** * Everything the intro's timeline does, as data: `{ init, cues }`. Keys name * elements by `data-k`: `stage` (the whole drawing: the fade), `w` / `f` * (letter i's group -- its motion -- and its path -- its fill), `wipe` / * `edge` (the wipe's clip and its leading line), `mwipe` (MEDIA's), * `m` (the mark's shapes, `mark: "draw"`), and `mark` / `slide` (the * whole mark and the whole text, `mark: "chime"`). Letter indexes run over * the wordmark's ten letters, then MEDIA's five. * * Beats (INTRO_BEATS): the wordmark is built inside the first sound, MEDIA * lands on the chime, and the last `fade` seconds fade to the ground. The * mark (`mark`, the style's own when absent) is drawn during the first sound * or pops in on the chime. */ export function introCues({ style, ground, mark = INTRO_STYLE_MARK[style] ?? "none", seconds, parts, palette, swap = null, words = null }) { const B = INTRO_BEATS; const init = {}; const cues = []; const cue = (k, at, dur, from, to, ease = "power2.out") => cues.push({ k, at: r3(at), dur: r3(dur), from, to, ease }); const word = parts.letters.filter((l) => l.role !== "media"); const media = parts.letters.filter((l) => l.role === "media"); const nW = word.length; const fin = (l) => (l.role === "lead" ? palette.lead : l.role === "suffix" ? palette.suffix : palette.media); const rand = seeded(0xa2c41); // title-card's lockup moves as boot-mark's does (the wordmark sliding out // of the mark, MEDIA on the chime): the words over it carry the card. const motion = style === "boot-dark" ? "boot" : style === "title-card" ? "boot-mark" : style; const build = B.build; const chime = B.chime.from; // Every letter at rest, in its colour, unless the style says otherwise. parts.letters.forEach((l, i) => { init[`w${i}`] = { x: 0, y: 0, rotation: 0, scale: 1, opacity: 1, transformOrigin: "50% 50%" }; init[`f${i}`] = { fill: fin(l) }; }); init.stage = { opacity: 1 }; // The mark drawn: the square first, then its found lines left to right one // after another (the accent one with its arrow) -- boot-mark's opening. if (mark === "draw") { const bars = parts.markShapes ?? []; bars.forEach((s, j) => { if (s.kind === "ground") { init[`m${j}`] = { scale: 0.82, opacity: 0, transformOrigin: "50% 50%" }; cue(`m${j}`, build.from, 0.45, { scale: 0.82, opacity: 0 }, { scale: 1, opacity: 1 }, "power3.out"); return; } const at = build.from + 0.12 * j; if (s.kind === "arrow") { init[`m${j}`] = { scale: 0, opacity: 0, transformOrigin: "0% 50%" }; cue(`m${j}`, at, 0.3, { scale: 0, opacity: 0 }, { scale: 1, opacity: 1 }, "back.out(2)"); } else { init[`m${j}`] = { scaleX: 0, transformOrigin: "0% 50%" }; cue(`m${j}`, at, 0.5, { scaleX: 0 }, { scaleX: 1 }, "power3.out"); } }); } // The mark popped: nothing of it until the chime, then the whole mark at // once, from nothing past its size and back, turning upright as it lands. if (mark === "chime") { init.mark = { scale: 0, rotation: -14, opacity: 0, transformOrigin: "50% 50%" }; cue("mark", chime, 0.07, { opacity: 0 }, { opacity: 1 }, "none"); cue("mark", chime, 0.5, { scale: 0, rotation: -14 }, { scale: 1, rotation: 0 }, "back.out(2.4)"); if (parts.mark) { // The text stands centred on its own until then, and slides over as // the mark arrives: the lockup's centre is the frame's at the end. // (Tried against laying the build out with the mark's room already // left: that tumbles the whole wordmark in off-centre, beside nothing.) const x = r3(parts.mark.x / 2); init.slide = { x }; cue("slide", chime, 0.42, { x }, { x: 0 }, "power3.out"); } } // MEDIA, on the chime: each letter rises a little into place, one after // another, in the accent -- the same in every style but the wipe's. const mediaIn = (lift = 26) => { media.forEach((l, j) => { const i = nW + j; init[`w${i}`] = { ...init[`w${i}`], opacity: 0, y: lift }; cue(`w${i}`, chime + j * 0.035, 0.34, { opacity: 0, y: lift }, { opacity: 1, y: 0 }, "power3.out"); }); }; // The shimmer: a colour passing across the wordmark, letter by letter, left // to right -- the GBA's pink-to-purple sweep, in the brand's accents. const shimmer = (from, step) => { word.forEach((l, i) => { const at = from + i * step; cue(`f${i}`, at, 0.12, { fill: fin(l) }, { fill: palette.shimmer[0] }, "sine.inOut"); cue(`f${i}`, at + 0.12, 0.12, { fill: palette.shimmer[0] }, { fill: palette.shimmer[1] }, "sine.inOut"); cue(`f${i}`, at + 0.24, 0.3, { fill: palette.shimmer[1] }, { fill: fin(l) }, "sine.out"); }); }; if (motion === "boot") { // The tumble: each letter comes in huge, turned and in a site's accent, // from up and to the right, overlapping the ones before it, and settles // into place; then into the wordmark's own colours, then the shimmer. const step = 0.08; const fly = 0.8; word.forEach((l, i) => { const at = build.from + i * step; const from = { x: r3(220 + (nW - i) * 18 + rand() * 120), y: r3(-170 - rand() * 120), rotation: r3((rand() - 0.5) * 80), scale: r3(4.2 + rand() * 2.2), opacity: 0, }; init[`w${i}`] = { ...from, transformOrigin: "50% 50%" }; const color = palette.tumble[(i * 3) % palette.tumble.length]; init[`f${i}`] = { fill: color }; cue(`w${i}`, at, 0.1, { opacity: 0 }, { opacity: 0.9 }, "none"); cue(`w${i}`, at, fly, { x: from.x, y: from.y, rotation: from.rotation, scale: from.scale }, { x: 0, y: 0, rotation: 0, scale: 1 }, "power2.out"); cue(`w${i}`, at + fly * 0.5, fly * 0.5, { opacity: 0.9 }, { opacity: 1 }, "none"); cue(`f${i}`, at + fly * 0.75, 0.38, { fill: color }, { fill: fin(l) }, "sine.inOut"); }); shimmer(1.95, 0.05); mediaIn(); } else if (motion === "boot-cascade") { // One letter after another, evenly across the build: each drops in from // above in its accent and lands with a small settle, then takes the // wordmark's colour. const step = (build.to - 0.42 - build.from) / (nW - 1); word.forEach((l, i) => { const at = build.from + i * step; const color = palette.tumble[(i * 3) % palette.tumble.length]; init[`w${i}`] = { ...init[`w${i}`], y: -230, opacity: 0 }; init[`f${i}`] = { fill: color }; cue(`w${i}`, at, 0.1, { opacity: 0 }, { opacity: 1 }, "none"); cue(`w${i}`, at, 0.42, { y: -230 }, { y: 0 }, "back.out(1.7)"); cue(`f${i}`, at + 0.36, 0.34, { fill: color }, { fill: fin(l) }, "sine.inOut"); }); media.forEach((l, j) => { const i = nW + j; // From below, against the wordmark's fall: a drop from above would // pass through the letters already standing. init[`w${i}`] = { ...init[`w${i}`], opacity: 0, y: 70 }; cue(`w${i}`, chime + j * 0.05, 0.12, { opacity: 0 }, { opacity: 1 }, "none"); cue(`w${i}`, chime + j * 0.05, 0.4, { y: 70 }, { y: 0 }, "back.out(1.7)"); }); } else if (motion === "boot-wipe") { // Linear, left to right, over the whole first sound: the wordmark in its // own colours behind a clip that opens at a constant rate, a line of the // accent riding its edge. MEDIA wipes in the same way, quickly, on the chime. const x0 = -4; const x1 = parts.width + 4; init.wipe = { attr: { width: 0 } }; cue("wipe", build.from, build.to - build.from, { attr: { width: 0 } }, { attr: { width: x1 - x0 } }, "none"); // The edge's line over the letters, its glow under them (a light over the // glyphs would wash out the letter being revealed). for (const k of ["edge", "glow"]) { init[k] = { x: x0, opacity: 0 }; cue(k, build.from, build.to - build.from, { x: x0 }, { x: x1 }, "none"); cue(k, build.from, 0.12, { opacity: 0 }, { opacity: 1 }, "none"); cue(k, build.to - 0.05, 0.3, { opacity: 1 }, { opacity: 0 }, "power1.out"); } init.mwipe = { attr: { width: 0 } }; cue("mwipe", chime, 0.36, { attr: { width: 0 } }, { attr: { width: x1 - x0 } }, "power2.out"); shimmer(build.to + 0.04, 0.03); } else if (motion === "boot-mark") { // The mark first (drawn, above, by its default `mark: "draw"`), then the // wordmark slides out of it, then the shimmer, and MEDIA on the chime. word.forEach((l, i) => { const at = 1.0 + i * 0.07; init[`w${i}`] = { ...init[`w${i}`], x: -40, opacity: 0 }; cue(`w${i}`, at, 0.5, { x: -40, opacity: 0 }, { x: 0, opacity: 1 }, "power3.out"); }); shimmer(1.9, 0.04); mediaIn(); } else { throw new Error(`no intro style "${style}"`); } if (swap) siteSwapCues({ swap, init, cues, cue, parts, palette, mark, nW, word, media, fin }); // THE WORDS (`title`, `lines`; `words`: { title, lines } -- whether there is // a title, how many lines). On title-card they are the card: the title // rises in on the first sound, each line after it, before the brand under // them lands on the chime. Under a boot style's wordmark they come in after // the chime. They fade with the drawing. if (words) { const card = style === "title-card"; const t0 = card ? build.from : chime + 0.3; if (words.title) { init.tt = { opacity: 0, y: 28 }; cue("tt", t0, 0.7, { opacity: 0, y: 28 }, { opacity: 1, y: 0 }, "power3.out"); } for (let j = 0; j < words.lines; j++) { const at = t0 + (words.title ? (card ? 0.5 : 0.18) : 0) + j * (card ? 0.18 : 0.12); init[`tl${j}`] = { opacity: 0, y: 18 }; cue(`tl${j}`, at, 0.55, { opacity: 0, y: 18 }, { opacity: 1, y: 0 }, "power3.out"); } init.words = { opacity: 1 }; cue("words", seconds - B.fade, B.fade, { opacity: 1 }, { opacity: 0 }, "power1.in"); } // The fade to the ground, over the last beat. cue("stage", seconds - B.fade, B.fade, { opacity: 1 }, { opacity: 0 }, "power1.in"); return { init, cues: cues.sort((a, b) => a.at - b.at || a.k.localeCompare(b.k)) }; } /** * The site swap's cues, on the chime (`swap`: { plan: swapPlan's, kind, accent }). * Keys: `n` / `nf` (the new prefix's letter j: its motion, its fill), * `swapclip` / `swapin` (the old prefix's clip and the new one's), `bar` (the * wipe's line), `recenter` (the word, re-centred), `mshift` (the mark, moved * to the new word's edge), `u` (URL line j) and `lift` (the drawing, * raised to keep it centred with the URLs under it). * * A cue never starts on an element's property while an earlier one is still * running on it, and starts from where that one ended: a seek from anywhere * lands on the same pixels. */ function siteSwapCues({ swap, init, cues, cue, parts, palette, mark, nW, word, media, fin }) { const T = INTRO_BEATS.chime.from; const D = SWAP_SECONDS; const { plan, kind, accent } = swap; const lineH = r3(plan.line.y1 - plan.line.y0); const newFill = (g) => (g.role === "lead" ? accent.ink : palette.suffix); const lastEnd = (k, prop) => Math.max(-1, ...cues.filter((c) => c.k === k && prop in c.to).map((c) => c.at + c.dur)); let swapEnd = T + D; // The old prefix's colour cross-fades to the accent as it goes (where nothing // else is still colouring that letter: boot-wipe's shimmer runs late). const fadeOld = (i, dur) => { const l = word[i]; if (l.role !== "lead" || lastEnd(`f${i}`, "fill") > T + 1e-9) return; cue(`f${i}`, T, dur, { fill: fin(l) }, { fill: accent.ink }, "sine.inOut"); }; if (kind === "swipe-down") { // The old letters slide down out of the line as the new slide down into // it, like one drum turning; a hair of stagger, left to right. const st = 0.015; const n = Math.max(plan.out.length, plan.glyphs.length); const dur = r3(D - st * (n - 1) > 0.22 ? D - st * (n - 1) : 0.22); init.swapclip = { attr: { y: -5000, height: 10000 } }; cue("swapclip", T, 0.001, { attr: { y: -5000, height: 10000 } }, { attr: { y: plan.line.y0, height: lineH } }, "none"); plan.out.forEach((i, o) => { cue(`w${i}`, T + o * st, dur, { y: 0 }, { y: lineH }, "power3.inOut"); fadeOld(i, D); }); plan.glyphs.forEach((g, j) => { init[`n${j}`] = { y: -lineH, transformOrigin: "50% 50%" }; cue(`n${j}`, T + j * st, dur, { y: -lineH }, { y: 0 }, "power3.inOut"); if (g.role === "lead") { init[`nf${j}`] = { fill: palette.lead }; cue(`nf${j}`, T, D, { fill: palette.lead }, { fill: accent.ink }, "sine.inOut"); } else init[`nf${j}`] = { fill: palette.suffix }; }); swapEnd = T + Math.max(D, st * (n - 1) + dur); } else if (kind === "roll") { // A split-flap board: each old letter folds shut, top to middle, one after // another, and the new letter in its place unfolds already in the accent. // At most ~0.3 s from the first fold to the last, however many letters. const st = r3(Math.min(0.045, 0.3 / Math.max(1, Math.max(plan.out.length, plan.glyphs.length) - 1))); const fold = 0.1; const open = 0.13; plan.out.forEach((i, o) => { cue(`w${i}`, T + o * st, fold, { scaleY: 1 }, { scaleY: 0 }, "power2.in"); }); plan.glyphs.forEach((g, j) => { init[`n${j}`] = { scaleY: 0, transformOrigin: "50% 50%" }; init[`nf${j}`] = { fill: newFill(g) }; cue(`n${j}`, T + j * st + fold, open, { scaleY: 0 }, { scaleY: 1 }, "back.out(1.6)"); }); swapEnd = T + st * (Math.max(plan.out.length, plan.glyphs.length) - 1) + fold + open; } else if (kind === "wipe") { // A line of the accent sweeps down the prefix: above it the new letters, // below it what is left of the old. init.swapclip = { attr: { y: -5000, height: 10000 } }; cue("swapclip", T, 0.001, { attr: { y: -5000, height: 10000 } }, { attr: { y: plan.line.y0, height: lineH } }, "none"); cue("swapclip", T + 0.001, D - 0.001, { attr: { y: plan.line.y0, height: lineH } }, { attr: { y: plan.line.y1, height: 0 } }, "power2.inOut"); init.swapin = { attr: { height: 0 } }; cue("swapin", T, D, { attr: { height: 0 } }, { attr: { height: lineH } }, "power2.inOut"); init.bar = { y: 0, opacity: 0 }; cue("bar", T, D, { y: 0 }, { y: lineH }, "power2.inOut"); cue("bar", T, 0.05, { opacity: 0 }, { opacity: 1 }, "none"); cue("bar", T + D * 0.7, 0.14, { opacity: 1 }, { opacity: 0 }, "power1.out"); plan.out.forEach((i) => fadeOld(i, D)); plan.glyphs.forEach((g, j) => { init[`nf${j}`] = { fill: newFill(g) }; }); } else { throw new Error(`no intro swap "${kind}"`); } const span = r3(swapEnd - T); // The word re-centres over the swap: a narrower name draws "lyzer" in. init.recenter = { x: 0 }; if (plan.recenter) cue("recenter", T, span, { x: 0 }, { x: plan.recenter }, "power2.inOut"); // The mark keeps its gap to the word: moved with it (drawn), or popped in // at its new place (chime). const mx = r3(plan.newL + plan.recenter - plan.oldL); if (mark === "chime") init.mshift = { x: mx }; else if (mark === "draw") { init.mshift = { x: 0 }; if (mx) cue("mshift", T, span, { x: 0 }, { x: mx }, "power2.inOut"); (parts.markShapes ?? []).forEach((m, j) => { if (!m.lit) return; cue(`m${j}`, T, D, { fill: m.fill }, { fill: accent.mark }, "sine.inOut"); }); } // boot-wipe's MEDIA wipe opens over MEDIA where it now stands. const mw = cues.find((c) => c.k === "mwipe"); if (mw) mw.to = { attr: { width: r3(plan.mediaBox.x1 - plan.mediaBox.x0 + 8) } }; // MEDIA, in the site's accent; or, with the URLs in its place, not at all. media.forEach((l, j) => { const i = nW + j; init[`f${i}`] = { fill: accent.ink }; }); if (plan.hideMedia) { const mk = new Set(media.map((l, j) => `w${nW + j}`).concat(media.map((l, j) => `f${nW + j}`), ["mwipe"])); for (let c = cues.length - 1; c >= 0; c--) if (mk.has(cues[c].k)) cues.splice(c, 1); media.forEach((l, j) => { init[`w${nW + j}`] = { ...init[`w${nW + j}`], opacity: 0 }; }); } // The URLs rise in after the swap has begun, the site's first. plan.urls.forEach((u, j) => { init[`u${j}`] = { opacity: 0, y: 16 }; cue(`u${j}`, T + 0.14 + j * 0.1, 0.36, { opacity: 0, y: 16 }, { opacity: 1, y: 0 }, "power3.out"); }); if (swap.lift) { init.lift = { y: 0 }; cue("lift", T, 0.42, { y: 0 }, { y: swap.lift }, "power3.out"); } } // --------------------------------------------------------------------------- // The page. // --------------------------------------------------------------------------- /** The mark's shapes (`mark: "draw"`), each with the origin it grows from, in lockup units. */ function markShapes(mark) { if (!mark) return []; const k = mark.size / 512; const shapes = []; for (const m of mark.body.matchAll(/<(rect|polygon)([^>]*)\/>/g)) { const a = Object.fromEntries([...m[2].matchAll(/(\w+)="([^"]*)"/g)].map((x) => [x[1], x[2]])); if (m[1] === "rect" && Number(a.width) === 512) { shapes.push({ kind: "ground", fill: a.fill, el: ``, origin: "256 256" }); continue; } if (m[1] === "polygon") { const pts = a.points.split(/\s+/).map((p) => p.split(",").map(Number)); const ox = Math.min(...pts.map((p) => p[0])); const oy = pts.reduce((s, p) => s + p[1], 0) / pts.length; shapes.push({ kind: "arrow", fill: a.fill, el: ``, origin: `${r3(ox)} ${r3(oy)}` }); continue; } const x = Number(a.x); const y = Number(a.y) + Number(a.height) / 2; shapes.push({ kind: "bar", fill: a.fill, el: ``, origin: `${r3(x)} ${r3(y)}`, }); } return shapes.map((s) => ({ ...s, k })); } /** title-card's lockup, as a fraction of the plain intro's size: the brand small, under the words. */ export const TITLE_CARD_LOCKUP = 0.46; /** * Where the words go, as fractions of the frame's height: the block's top and * height (the words centred in it) and, on title-card, the lockup's centre. * title-card: the words over the upper part, the brand under them. A boot * style: the words under the wordmark (lower still when a site's URLs hang * under it). A portrait frame keeps both inside the Shorts safe area. */ export function wordsLayout({ card, portrait, swapped = false }) { if (card) return portrait ? { top: 0.16, height: 0.4, lockup: 0.66 } : { top: 0.16, height: 0.44, lockup: 0.7 }; if (portrait) return { top: swapped ? 0.6 : 0.56, height: 0.18 }; return { top: swapped ? 0.72 : 0.66, height: 0.26 }; } /** * The intro's page. * `site` (`{ name, lead?, accent?, url? }`, intro.mjs resolveIntroSite's) turns * on the swap, with `swap`, `url` and `urlPlace`; absent, the page is exactly * the plain intro's, byte for byte, so its cache key does not move. * @param {{ style: string, ground: "light" | "dark", mark?: "none" | "draw" | "chime", seconds: number, * width?: number, height?: number, fps?: number, kit: any, gsapSrc?: string, * site?: null | { name: string, lead?: string, accent?: string, url?: string | false }, * swap?: "swipe-down" | "roll" | "wipe", url?: "both" | "site" | "project" | "none", urlPlace?: "under" | "replace", * suffix?: string, projectUrl?: string | false, title?: string | null, lines?: string[] | null, font?: string }} o */ export function introHtml({ style, ground, mark = INTRO_STYLE_MARK[style] ?? "none", seconds, width = 1920, height = 1080, fps = 30, kit, gsapSrc = "assets/gsap.min.js", site = null, swap = INTRO_SITE_DEFAULTS.swap, url = INTRO_SITE_DEFAULTS.url, urlPlace = INTRO_SITE_DEFAULTS.urlPlace, suffix = INTRO_SUFFIX, projectUrl = PROJECT_URL_TEXT, title = null, lines = null, font = INTRO_FONT_ASSET, }) { const W = width; const H = height; const palette = introPalette(ground, kit); const parts = lockupParts(kit); const withMark = mark !== "none" && !!parts.mark; const popped = withMark && mark === "chime"; const shapes = withMark ? markShapes(parts.mark).map((m) => (site ? { ...m, lit: m.fill.toLowerCase() === kit.palette.accent.toLowerCase() } : m)) : []; // The drawing's extent in lockup units, and the scale that sets it in the // frame: the wordmark ~61% of the width (the lockup with its mark ~70%). const x0 = withMark ? parts.mark.x : 0; const x1 = parts.width; const y0 = Math.min(parts.top, withMark ? parts.mark.y : Infinity); const y1 = Math.max(parts.bottom, withMark ? parts.mark.y + parts.mark.size : -Infinity); // The words (`title`, `lines`): drawn only when written, so a page without // them is the page it always was, byte for byte. const wordTitle = typeof title === "string" && title.trim() ? title.trim() : null; const wordLines = (Array.isArray(lines) ? lines : []).filter((l) => typeof l === "string" && l.trim()).map((l) => l.trim()); const words = wordTitle || wordLines.length ? { title: !!wordTitle, lines: wordLines.length } : null; // title-card with words: the brand small, under them (WORDS_LAYOUT). const card = !!words && style === "title-card"; const shrink = card ? TITLE_CARD_LOCKUP : 1; const k = H > W ? r3((shrink * Math.min(W * (withMark ? 0.7 : 0.61), W * PORTRAIT_SAFE_WIDTH)) / (x1 - x0)) : r3((shrink * W * (withMark ? 0.7 : 0.61)) / (x1 - x0)); const ox = r3(W / 2 - ((x0 + x1) / 2) * k); // The site swap: what changes on the chime. The lockup is centred exactly as // the plain intro centres it, and the URLs hang below it, left out of the // centring -- so on the chime it only ever moves sideways, never a vertical // lift (operator, 2026-10-26). // A portrait frame (a Short, 9:16) centres the drawing in the platform's safe // area -- below the top 8 %, above the bottom 20 % (the player's own text) -- // and keeps it inside 12 % of either side (the right 12 % carries its buttons). // A landscape frame is centred exactly as it always was. const portrait = H > W; const layout = words ? wordsLayout({ card, portrait, swapped: !!site }) : null; const oy = card ? r3(H * layout.lockup - ((y0 + y1) / 2) * k) : portrait ? r3(H * PORTRAIT_SAFE_CENTRE - ((y0 + y1) / 2) * k) : r3(H / 2 - ((y0 + y1) / 2) * k); const plan = site ? swapPlan({ parts, site, url, urlPlace, markX: withMark ? parts.mark.x : null, suffix, projectUrl }) : null; const accent = site ? introAccent(site.accent, ground, palette) : null; const lift = 0; const { init, cues } = introCues({ style, ground, mark: withMark ? mark : "none", seconds, parts: { ...parts, markShapes: shapes }, palette, ...(plan ? { swap: { plan, kind: swap, accent, lift } } : {}), ...(words ? { words } : {}), }); const dur = pageDuration(seconds, fps); const nW = parts.letters.filter((l) => l.role !== "media").length; const glyph = (l, i) => ``; const outSet = new Set(plan?.out ?? []); const wordGlyphs = plan ? ` ${parts.letters.slice(0, nW).filter((l, i) => outSet.has(i)).map((l) => glyph(l, parts.letters.indexOf(l))).join("\n ")} ${parts.letters.slice(0, nW).filter((l, i) => !outSet.has(i)).map((l) => glyph(l, parts.letters.indexOf(l))).join("\n ")}` : parts.letters.slice(0, nW).map(glyph).join("\n "); const mediaGlyphs = parts.letters.slice(nW).map((l, j) => glyph(plan ? { ...l, tx: plan.mediaTx[j] } : l, nW + j)).join("\n "); const lineH = plan ? r3(plan.line.y1 - plan.line.y0) : 0; // The wipe's line spans the prefix, old and new, and stops short of the // mark beside it (the mark's right edge, in the word's own coordinates). let barL = 0; let barR = 0; if (plan) { barL = Math.min(plan.newL, parts.letters[0].box.x0) - 14; barR = Math.max(...plan.glyphs.map((g) => g.box.x1), ...plan.out.map((i) => parts.letters[i].box.x1)) + 14; if (withMark) barL = Math.max(barL, plan.newL - plan.oldL + parts.mark.x + parts.mark.size - plan.recenter + 12); barL = r3(barL); barR = r3(barR); } const newGlyphs = plan ? ` ${plan.glyphs.map((g, j) => ``).join("\n ")} ${swap === "wipe" ? ` ` : ""}` : ""; const urlGlyphs = plan ? plan.urls.map((u, j) => ` ${u.glyphs.map((g) => ``).join("")}`).join("") : ""; const swapDefs = plan ? ` ` : ""; const wiped = style === "boot-wipe"; const pad = 40; const wordClip = wiped ? ` ` : ""; const markEls = withMark ? `${popped ? '' : ""} ${shapes.map((s, j) => `${s.el}`).join("\n ")} ${popped ? "" : ""}` : ""; const edgeH = r3(parts.wordBottom - parts.top + 24); // The words' sizes: px at 1080p, scaled with the frame (a portrait frame by its width). const u = portrait ? W / 1080 : Math.min(W / 1920, H / 1080); const ty = words ? { title: Math.round((card ? 92 : 54) * u), line: Math.round((card ? 40 : 32) * u), gap: Math.round((card ? 18 : 10) * u) } : null; const maxW = Math.round(W * (portrait ? PORTRAIT_SAFE_WIDTH : 0.86)); const data = { init, cues, ...(words ? { words: { maxW, floor: Math.round(24 * u) } } : {}) }; const json = JSON.stringify(data).replace(/${wordTitle ? `
${esc(wordTitle)}
` : ""}${wordLines.map((l, j) => `
${esc(l)}
`).join("")} ` : ""; // The fit (the teaser's): a line wider than the frame allows shrinks a pixel // at a time, once the face is in; the renderer waits on document.fonts.ready. const wordsJs = words ? ` function fit(row) { let s = parseFloat(getComputedStyle(row).fontSize); while (s > D.words.floor && row.scrollWidth > D.words.maxW + 0.5) { s -= 1; row.style.fontSize = s + "px"; } } const ready = Promise.all([document.fonts.load("720 90px IntroDisplay"), document.fonts.load("480 40px IntroDisplay")]).catch(() => {}).then(() => { document.querySelectorAll("#intro-words > div").forEach(fit); document.documentElement.dataset.fit = "1"; });` : ""; return `
${wordClip}${swapDefs} ${plan ? ` ` : ""} ${plan && withMark ? `${markEls}` : markEls}${popped ? ` ` : ""}${plan ? ` ` : ""} ${wiped ? ` ` : ""} ${wordGlyphs} ${wiped ? ` ` : ""}${newGlyphs}${plan ? ` ` : ""} ${mediaGlyphs} ${urlGlyphs}${popped ? ` ` : ""}${plan ? ` ` : ""} ${wordsEls}
`; }