Files
patriothacks/e2e/openmotion/buildComposition.mjs
T
OmO Orchestrator 171f6d46ab feat(demo): rewrite promo video copy to pair problem with solution
Every chapter tagline and per-mini-app chip now explicitly states the real
Hollow problem (drawn from the actual PatriotHacks Fall 2026 'Life
Underground' problem doc, not a paraphrase) immediately followed by what
that mini-app concretely does about it - replacing the prior internal-
proof-style copy (e.g. commit/reveal details) that explained the mechanism
without ever stating the problem it solves.

Also fixes a real usability issue: the captured interactions (typing,
form-filling) played back too fast to follow. The fix is targeted, not
uniform - simple taps/toggles stay near-normal speed, and the real
slowdown goes into character-by-character typing on the form-heavy beats
(Assembly's proposal, Farms, Health Post, The Climb), which is where the
complaint actually applied. An earlier attempt that slowed every
interaction uniformly produced a 161s video (more than double); this
version lands at 89.9s, a reasonable increase that keeps every click
readable without losing a viewer's attention.

README's opening now leads with the doc's own framing of the premise and
what the project answers, instead of a generic project description.

Independently verified (fresh reproduction, including an independent
fetch of the source doc): every problem statement matches the doc's actual
numbered items, every solution statement matches what the mini-app
actually does, all 15 chips plus 5 chapter cards are legible on screen,
and a direct before/after frame comparison confirms the click-speed fix
(instant-fill in the old render vs visible character-by-character typing
in the new one). Every existing protection re-verified: 1920x1080/30fps,
zero white-flash frames across all 2696 frames, audio in the proven band
with no clipping, zero generic/town references.
2026-11-19 22:52:18 -05:00

648 lines
36 KiB
JavaScript

// STAGE-2/REDESIGN-3 OpenMotion full main-tour: composition builder.
//
// THIRD-REDESIGN GOAL (structure, not paint): the first two versions both
// read as "the same video" because they shared ONE structural skeleton -
// one dark background for the whole runtime, one centered same-size phone
// for every beat, and identical dark centered title cards between acts. This
// build changes the STRUCTURE, grounded in two real OpenMotion templates:
// - Cash App (motion-55c5fe84): the full-screen BACKGROUND COLOR itself
// switches per chapter (black / gray / neon green), bold capsule
// typography on solid color, phone present on only SOME beats.
// - Emergent (motion-ffaef2b8): opens with PURE DATA (no device) for the
// first ~18s, then a device beat, and ENDS on a wall of many outputs
// fanning out - focus -> richness.
//
// Concretely this composition is now a RHYTHM of distinct shapes:
// 1. DATA OPEN - bold brand-blue full screen, NO phone: a counting
// "4,200 residents" + animated real resource bars + a
// capsule hook line. (Emergent data-first open.)
// 2. CHAPTER cards - full-screen SOLID bold color, a DIFFERENT color per
// act (azure / amber / teal / violet), kinetic capsule
// typography. (Cash App color-switch chapters.)
// 3. ACT footage - the real captured phone footage, but with a DIFFERENT
// phone framing + field color per act: Act I phone
// right-anchored on deep ocean (claim left), Act II
// centered & larger on charcoal, Act III left-anchored on
// indigo (result chips right), Epilogue centered on plum.
// 4. ASSEMBLY - the real two-device WebRTC clip, full canvas.
// 5. RESULT WALL - 13 real app screenshots fan in to fill the frame, then
// a bold "THE COMMONS" lockup. (Emergent output wall.)
//
// Everything on screen is still real: real captured footage clips, real
// seed-fixture numbers, real captured per-mini-app screenshots, the real
// in-universe copy from tour.mjs. Nothing is fabricated; the only thing that
// changed is the COMPOSITION / motion structure.
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, existsSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import ffmpegStatic from "ffmpeg-static";
import { TITLE_CARDS, WAVE1_FIX_CALLOUTS } from "./tour.mjs";
import { HOLLOW_DEMO_FIXTURE } from "../../src/admin/seedEvents.ts";
const __dirname = dirname(fileURLToPath(import.meta.url));
const OM_DIR = __dirname;
const MANIFEST = resolve(OM_DIR, "capture-manifest.json");
const ASSEMBLY_MANIFEST = resolve(OM_DIR, "assembly-manifest.json");
const COMPOSITIONS_DIR = resolve(OM_DIR, "compositions");
const ASSETS_DIR = resolve(OM_DIR, "assets");
const WALL_DIR = resolve(ASSETS_DIR, "wall");
// Real per-mini-app Playwright screenshots captured by the same real-app run
// (one still per mini-app). Used only in the closing result wall.
const SHOT_SRC = resolve(OM_DIR, "..", "..", ".omo", "evidence", "full-feature-demo");
const FFMPEG_BIN = ffmpegStatic;
const CANVAS_W = 1920;
const CANVAS_H = 1080;
const FPS = 30;
const BEZEL = 8; // thin modern device frame around the real screen footage
// --- ambient audio (unchanged proven approach) ---
// Three sine oscillators C3/E3/G3 amixed 1/0.8/0.7, slow tremolo, baked
// fades. Raw track ~-27.9 dB mean; data-volume 0.30 lands the final mix at
// ~-38 dB mean (in the proven -37..-40 dB band, max well below 0).
const AMBIENT_SRC = "assets/ambient.mp3";
const AMBIENT_VOLUME = 0.3;
const esc = (s) => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const r3 = (n) => Number(Number(n).toFixed(3));
// ---------------------------------------------------------------------
// Palette: a COLOR JOURNEY (the whole point of the redesign). Bold
// saturated chapter colors punctuate darker tinted act fields, so the
// background visibly changes shape over the runtime instead of one dark
// blue the whole time. No pure white anywhere (keeps the luma scan clean -
// no white-flash ambiguity).
// ---------------------------------------------------------------------
const BRAND = "#1677FF";
const COLORS = {
data: "linear-gradient(150deg,#1a7bff 0%,#0f62d8 55%,#0a46a6 100%)",
chapter1: "linear-gradient(150deg,#1657c8 0%,#0c346f 100%)", // azure
chapter2: "linear-gradient(150deg,#ffb020 0%,#f58a10 100%)", // amber (dark text)
chapter3: "linear-gradient(150deg,#13a085 0%,#0a5f50 100%)", // teal
chapterE: "linear-gradient(150deg,#7a52e8 0%,#4b2fb0 100%)", // violet
fieldAct1: "radial-gradient(1200px 820px at 70% 30%,#123a6b 0%,#081c3a 60%,#05101f 100%)", // deep ocean
fieldAct2: "radial-gradient(1200px 820px at 50% 24%,#1a2330 0%,#0d1117 62%,#06080c 100%)", // charcoal
fieldAct3: "radial-gradient(1200px 820px at 30% 30%,#1b2a66 0%,#10163a 60%,#080b22 100%)", // indigo
fieldEpi: "radial-gradient(1200px 820px at 50% 28%,#2c1a56 0%,#1a1030 60%,#0d0820 100%)", // plum
wall: "linear-gradient(160deg,#1a7bff 0%,#0e55c0 55%,#0a327e 100%)",
};
// ---------------------------------------------------------------------
// Result-wall tiles: one real captured screenshot per mini-app (13).
// ---------------------------------------------------------------------
const WALL_TILES = [
{ file: "main-03-waterwatch-no-false-alert.png", label: "Water Watch" },
{ file: "main-07-fairshare-water.png", label: "Fair Share" },
{ file: "main-11-farms-forecast.png", label: "Farms" },
{ file: "main-13-housing.png", label: "Housing" },
{ file: "main-16-mentor.png", label: "Mentor" },
{ file: "main-18-healthpost-triage.png", label: "Health Post" },
{ file: "main-20-lightclock-manual-fallback.png", label: "Light Clock" },
{ file: "main-22-theclimb.png", label: "The Climb" },
{ file: "main-08-tunnelsafety.png", label: "Tunnel Safety" },
{ file: "main-09-findfamily.png", label: "Find Family" },
{ file: "main-28-assembly-qv-tally.png", label: "Assembly" },
{ file: "main-30-fairdraw-reveal.png", label: "Fair Draw" },
{ file: "main-33-sky-post.png", label: "Sky" },
];
// ---------------------------------------------------------------------
// Timeline builder. A single running cursor lays out ordered SEGMENTS with
// a small crossfade overlap. Two layer classes:
// - overlay segments (data open, chapter cards, wall): full-screen panels
// that crossfade OVER the phone stage.
// - stage segments (act footage, assembly): the phone/field beneath.
// ---------------------------------------------------------------------
const XF = 0.5; // crossfade overlap between consecutive segments
const DATA_DUR = 7.0;
const CH_DUR = 2.6; // chapter card window
const WALL_DUR = 7.0;
function clipDur(clips, name) {
const v = clips.find((c) => c.name === name)?.durationS;
if (!v) throw new Error(`clip ${name} missing/zero duration in manifest`);
return v;
}
function buildTimeline(clips, assemblyDur) {
const seg = [];
let t = 0;
const push = (s) => {
s.start = r3(t);
s.end = r3(t + s.dur);
seg.push(s);
t = s.end - XF; // next segment crossfades in over this one's tail
return s;
};
push({ id: "data", kind: "data", dur: DATA_DUR });
// Act I: intro clip (cold-start/home/admin) + act1 clip, phone right-anchored.
push({ id: "ch-act1", kind: "chapter", dur: CH_DUR, card: "act1", color: COLORS.chapter1, cap: BRAND, capFg: "#fff", keyword: "Verified Twice" });
push({
id: "act1", kind: "stage", dur: clipDur(clips, "intro") + clipDur(clips, "act1"),
field: COLORS.fieldAct1, frame: { x: 332, y: 0, scale: 0.9 }, textSide: "left", card: "act1",
clips: [{ key: "intro" }, { key: "act1" }],
chips: [
{ p: "The taps are making people sick.", s: "Water Watch waits for two sensors to agree before it alerts." },
{ p: "Blackouts hit with no warning, and the deep levels lose.", s: "Fair Share warns before the cut, then splits what's left by need." },
{ p: "One flooded tunnel cuts off a whole neighborhood.", s: "Tunnel Safety logs the hazard and reroutes you around it." },
{ p: "A blackout splits families across levels.", s: "Find Family matches them privately, on-device." },
],
});
push({ id: "ch-act2", kind: "chapter", dur: CH_DUR, card: "act2", color: COLORS.chapter2, cap: "#101418", capFg: "#ffcf4d", dark: true, keyword: "Alive" });
push({
id: "act2", kind: "stage", dur: clipDur(clips, "act2"),
field: COLORS.fieldAct2, frame: { x: -300, y: 0, scale: 0.84 }, textSide: "right", card: "act2",
clips: [{ key: "act2" }],
chips: [
{ p: "Cut off, a neighborhood has days of food left.", s: "Farms forecasts the grow-light yield so a level can feed itself." },
{ p: "Families are packed into rooms meant for one.", s: "Housing surfaces idle space and reruns a fair assignment cycle." },
{ p: "Lung sickness spreads; medicine runs out deep first.", s: "Health Post triages by WHO-IMCI and routes a signed referral." },
{ p: "A life with no sunlight, and no one measuring it.", s: "Light Clock logs sleep and computes your circadian status." },
{ p: "If the surface is safe, millions want up at once.", s: "The Climb schedules who climbs when, shaft by shaft." },
{ p: "A skill with one teacher left is nearly lost.", s: "Mentor finds at-risk skills and matches apprentices to them." },
],
});
push({ id: "ch-act3", kind: "chapter", dur: CH_DUR, card: "act3", color: COLORS.chapter3, cap: "#063f36", capFg: "#9bffe6", keyword: "Decides" });
push({
id: "act3", kind: "stage", dur: clipDur(clips, "act3"),
field: COLORS.fieldAct3, frame: { x: 332, y: 0, scale: 0.9 }, textSide: "left", card: "act3",
clips: [{ key: "act3" }],
chips: [
{ p: "The Directorate controls the network and can shut it down.", s: "Assembly keeps the roster, proposals and quadratic vote running when it's severed." },
{ p: "One slot, six hopefuls - someone will cry foul.", s: "Fair Draw commits the result before it's revealed, so no one can re-roll." },
{ p: "No one can see how the Hollow really feels.", s: "Sky posts a shared memory wall and an honest, signed mood pulse." },
],
});
push({ id: "ch-epi", kind: "chapter", dur: CH_DUR, card: "epilogue", color: COLORS.chapterE, cap: "#2e1a63", capFg: "#d8c6ff", keyword: "Verifiable" });
push({
id: "epilogue", kind: "stage", dur: clipDur(clips, "epilogue"),
field: COLORS.fieldEpi, frame: { x: -300, y: 0, scale: 0.84 }, textSide: "right", card: "epilogue",
clips: [{ key: "epilogue" }],
chips: [
{ p: "A wallet with no bank is only worth its trust.", s: "Every balance re-checks its own Ed25519 signature - nothing on faith." },
{ p: "A locked platform can't answer new problems.", s: "Any resident can ship a mini-app by QR - no gatekeeper." },
],
});
// Assembly two-device clip plays full-canvas (it is a pre-composited
// 1920x1080 scene with its own baked fades).
push({ id: "assembly", kind: "assembly", dur: assemblyDur });
// Result wall + brand lockup.
const wall = push({ id: "wall", kind: "wall", dur: WALL_DUR });
// Absolute end: wall end + a short dark tail so the film closes on black
// (clean stop, no white flash) arriving from a completely new scene.
const total = r3(wall.end + 0.2);
return { seg, total };
}
// Assign each stage segment's clip windows (absolute film time) from the
// segment start, back-to-back.
function layoutClips(seg, clips) {
const out = [];
for (const s of seg) {
if (s.kind !== "stage") continue;
let c = s.start;
for (const clip of s.clips) {
const dur = clipDur(clips, clip.key);
out.push({ seg: s.id, key: clip.key, start: r3(c), duration: r3(dur) });
c = r3(c + dur);
}
}
return out;
}
function generateAmbientTrack(outPath, durationSeconds) {
mkdirSync(dirname(outPath), { recursive: true });
const fadeOutStart = Math.max(0, durationSeconds - 4);
execFileSync(
FFMPEG_BIN,
[
"-y",
"-f", "lavfi", "-i", `sine=frequency=130.81:duration=${durationSeconds}`,
"-f", "lavfi", "-i", `sine=frequency=164.81:duration=${durationSeconds}`,
"-f", "lavfi", "-i", `sine=frequency=196.00:duration=${durationSeconds}`,
"-filter_complex",
`[0][1][2]amix=inputs=3:duration=longest:weights=1 0.8 0.7[mix];` +
`[mix]tremolo=f=0.15:d=0.3,afade=t=in:st=0:d=3,afade=t=out:st=${fadeOutStart}:d=4[out]`,
"-map", "[out]",
"-c:a", "libmp3lame", "-b:a", "128k",
outPath,
],
{ stdio: ["ignore", "pipe", "pipe"] },
);
return outPath;
}
// Split a title into a lead and a keyword phrase so the keyword can sit in a
// bold capsule pill (Cash App technique). Returns { lead, key }.
function splitKeyword(title, keyword) {
const idx = title.indexOf(keyword);
if (idx === -1) return { lead: title, key: "" };
return { lead: title.slice(0, idx).trim(), key: keyword };
}
function main() {
const manifest = JSON.parse(readFileSync(MANIFEST, "utf8"));
const { videoSize, clips } = manifest;
if (!existsSync(ASSEMBLY_MANIFEST)) throw new Error(`assembly manifest not found at ${ASSEMBLY_MANIFEST}`);
const assemblyDur = JSON.parse(readFileSync(ASSEMBLY_MANIFEST, "utf8")).clip?.durationS;
if (!assemblyDur) throw new Error("assembly clip missing/zero duration");
const { seg, total } = buildTimeline(clips, assemblyDur);
const clipWins = layoutClips(seg, clips);
generateAmbientTrack(resolve(ASSETS_DIR, "ambient.mp3"), total);
// Copy the real per-mini-app screenshots into assets/wall for the wall.
mkdirSync(WALL_DIR, { recursive: true });
for (const tile of WALL_TILES) {
const src = resolve(SHOT_SRC, tile.file);
if (!existsSync(src)) throw new Error(`wall screenshot not found: ${src}`);
copyFileSync(src, resolve(WALL_DIR, tile.file));
}
// Phone geometry (aspect-exact so object-fit crops nothing). Base size is
// modest; per-act scale makes some acts larger/flatter.
const PHONE_H = 860;
const phoneW = r3((PHONE_H * videoSize.width) / videoSize.height);
const deviceW = r3(phoneW + BEZEL * 2);
const deviceH = PHONE_H + BEZEL * 2;
const deviceLeft = r3((CANVAS_W - deviceW) / 2);
const deviceTop = r3((CANVAS_H - deviceH) / 2 - 8);
const stages = seg.filter((s) => s.kind === "stage");
const chapters = seg.filter((s) => s.kind === "chapter");
const dataSeg = seg.find((s) => s.kind === "data");
const asmSeg = seg.find((s) => s.kind === "assembly");
const wallSeg = seg.find((s) => s.kind === "wall");
// ---- markup ----
// Field panels: one per stage (+ data/wall carry their own bg in their
// section). Crossfaded to create the color journey behind the phone.
const fieldEls = stages
.map((s) => ` <div class="field" id="field-${s.id}" style="background:${s.field};opacity:0;"></div>`)
.join("\n");
// Phone rig: one bezel, all stage clips stacked (each visible only in its
// own data-start window), a contact shadow that transforms with the rig.
const screenVideoEls = clipWins
.map(
(w) =>
` <video class="screen-vid" id="vid-${w.key}" src="assets/${w.key}.mp4" data-start="${w.start.toFixed(3)}" data-media-start="0" data-duration="${w.duration.toFixed(3)}" muted playsinline></video>`,
)
.join("\n");
// Per-act side text + chips (positioned opposite the phone).
const stageTextEls = stages
.map((s) => {
const card = TITLE_CARDS[s.card];
const chips = s.chips
.map(
(c) =>
` <div class="chip"><div class="chip-p">${esc(c.p)}</div><div class="chip-s">${esc(c.s)}</div></div>`,
)
.join("\n");
return ` <div class="stagetext ${s.textSide}" id="text-${s.id}" style="opacity:0;">
<div class="st-eyebrow">${esc(card.eyebrow)}</div>
<div class="st-title">${esc(card.title)}</div>
<div class="st-chips">
${chips}
</div>
</div>`;
})
.join("\n");
// Chapter cards: full-screen solid bold color + kinetic capsule headline.
const chapterEls = chapters
.map((s) => {
const card = TITLE_CARDS[s.card];
const { lead, key } = splitKeyword(card.title, s.keyword);
const leadWords = lead
.split(" ")
.filter(Boolean)
.map((w) => `<span class="cw">${esc(w)}</span>`)
.join(" ");
return ` <div class="chapter${s.dark ? " dark" : ""}" id="${s.id}" style="background:${s.color};opacity:0;">
<div class="ch-eyebrow">${esc(card.eyebrow)}</div>
<div class="ch-head">
<span class="ch-lead">${leadWords}</span>
${key ? `<span class="ch-cap" style="background:${s.cap};color:${s.capFg};">${esc(key)}</span>` : ""}
</div>
<div class="ch-sub">${esc(card.tagline)}</div>
</div>`;
})
.join("\n");
// Data-open section: no phone. Count-up + real resource bars + hook line.
const f = HOLLOW_DEMO_FIXTURE;
const resMax = Math.max(...Object.values(f.resources));
const bars = Object.entries(f.resources)
.map(
([k, v]) =>
` <div class="bar"><div class="bar-top"><span class="bar-k">${esc(k[0].toUpperCase() + k.slice(1))}</span><span class="bar-v" data-to="${v}">0</span></div><div class="bar-track"><div class="bar-fill" style="transform:scaleX(0);width:${((v / resMax) * 100).toFixed(2)}%;"></div></div></div>`,
)
.join("\n");
const dataEl = ` <div class="section" id="data" style="background:${COLORS.data};opacity:0;">
<div class="data-kicker">The Hollow &middot; live seed data</div>
<div class="data-num"><span id="data-count" data-to="${f.population}">0</span></div>
<div class="data-sub">residents in one shelter &mdash; two billion live beneath a dead surface</div>
<div class="bars">
${bars}
</div>
<div class="data-hook">Their systems are failing. The Commons is how they <span class="hook-cap">fight back</span>.</div>
</div>`;
// Assembly full-canvas clip.
const asmEl = ` <video class="assembly" id="vid-assembly" src="assets/assembly.mp4" data-start="${asmSeg.start.toFixed(3)}" data-media-start="0" data-duration="${assemblyDur.toFixed(3)}" muted playsinline></video>`;
// Result wall: real screenshots fan in, then a brand lockup.
const tileEls = WALL_TILES.map(
(t, i) =>
` <div class="tile" id="tile-${i}" style="opacity:0;"><img src="assets/wall/${t.file}" alt=""><span class="tile-label">${esc(t.label)}</span></div>`,
).join("\n");
const outro = TITLE_CARDS.outro;
const wallEl = ` <div class="section wall" id="wall" style="background:${COLORS.wall};opacity:0;">
<div class="wall-kicker" id="wall-kicker">One answer. More than one problem.</div>
<div class="wall-grid">
${tileEls}
</div>
<div class="lockup" id="lockup" style="opacity:0;">
<div class="lock-eyebrow">${esc(outro.eyebrow)}</div>
<div class="lock-title">${esc(outro.title)}</div>
<div class="lock-sub">${esc(outro.tagline)}</div>
</div>
</div>`;
const audioEl = ` <audio id="ambient" src="${AMBIENT_SRC}" data-start="0" data-media-start="0" data-duration="${total}" data-volume="${AMBIENT_VOLUME}"></audio>`;
// ---- serialized configs for the GSAP builder ----
const stageCfg = JSON.stringify(
stages.map((s) => ({ id: s.id, start: s.start, end: s.end, frame: s.frame, textSide: s.textSide })),
);
const chapterCfg = JSON.stringify(chapters.map((s) => ({ id: s.id, start: s.start, end: s.end })));
const clipCfg = JSON.stringify(clipWins.map((w) => ({ key: w.key, start: w.start, duration: w.duration })));
const promoHtml = `<template>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
#root { position:absolute; inset:0; overflow:hidden; background:#05070d;
font-family:-apple-system,'Helvetica Neue','Segoe UI',Arial,sans-serif; color:#fff; }
/* ---- Field panels: the color journey behind the phone (crossfaded). ---- */
.field { position:absolute; inset:0; z-index:5; }
#fieldwrap { position:absolute; inset:0; z-index:5; }
/* ---- Phone stage ---- */
#stage { position:absolute; inset:0; z-index:10; }
#phoneRig { position:absolute; left:${deviceLeft}px; top:${deviceTop}px; width:${deviceW}px; height:${deviceH}px;
transform-origin:50% 50%; will-change:transform; }
#phoneShadow { position:absolute; left:50%; top:${deviceH - 20}px; width:${r3(deviceW * 1.15)}px; height:70px;
transform:translateX(-50%); background:radial-gradient(ellipse at center, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.22) 46%, transparent 72%); filter:blur(8px); }
#device { position:absolute; inset:0; border-radius:40px;
background:linear-gradient(155deg,#2a3346 0%,#141b29 48%,#0a0f18 100%);
box-shadow:0 2px 2px rgba(255,255,255,0.10) inset, 0 -2px 6px rgba(0,0,0,0.5) inset,
0 50px 100px rgba(0,0,0,0.6), 0 14px 36px rgba(0,0,0,0.5), 0 0 0 1px rgba(130,160,210,0.14); }
.screen { position:absolute; inset:${BEZEL}px; border-radius:30px; overflow:hidden; background:#000; }
.screen-vid { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; display:block; }
/* ---- Per-act side text + chips (opposite the phone). ---- */
.stagetext { position:absolute; top:0; bottom:0; z-index:12; display:flex; flex-direction:column; justify-content:center;
width:720px; padding:0 70px; will-change:opacity,transform; }
.stagetext.left { left:0; align-items:flex-start; text-align:left; }
.stagetext.right { right:0; align-items:flex-start; text-align:left; }
.stagetext.top { left:50%; top:54px; bottom:auto; transform:translateX(-50%); width:1100px; align-items:center; text-align:center; padding:0; }
.st-eyebrow { color:#8fb6ff; letter-spacing:0.42em; font-size:19px; font-weight:700; text-transform:uppercase; }
.st-title { color:#f5f8ff; font-size:46px; font-weight:800; letter-spacing:-0.02em; line-height:1.06; margin-top:14px; text-shadow:0 2px 24px rgba(5,15,40,0.6); }
.stagetext.top .st-title { font-size:38px; }
.st-chips { margin-top:26px; display:flex; flex-direction:column; gap:12px; }
.stagetext.top .st-chips { flex-direction:row; justify-content:center; gap:16px; margin-top:16px; }
.chip { background:rgba(10,18,32,0.74); backdrop-filter:blur(8px); -webkit-backdrop-filter:blur(8px);
border:1px solid rgba(120,170,255,0.28); border-left:3px solid ${BRAND}; border-radius:12px;
padding:11px 18px; color:#e7eefb; max-width:640px; box-shadow:0 16px 40px rgba(0,0,0,0.45);
display:flex; flex-direction:column; gap:3px; }
.chip-p { color:#ffcf96; font-size:17px; font-weight:600; letter-spacing:-0.005em; }
.chip-s { color:#f2f7ff; font-size:18px; font-weight:700; letter-spacing:-0.01em; }
.chip-s::before { content:"\\2192 "; color:#5aa6ff; font-weight:800; }
.stagetext.top .chip { max-width:440px; }
/* ---- Chapter cards: full-screen solid bold color + capsule headline. ---- */
.chapter { position:absolute; inset:0; z-index:30; display:flex; flex-direction:column; align-items:center; justify-content:center;
text-align:center; padding:0 80px; pointer-events:none; will-change:opacity; }
.chapter .ch-eyebrow { color:rgba(255,255,255,0.82); letter-spacing:0.5em; font-size:22px; font-weight:700; text-transform:uppercase; }
.chapter.dark .ch-eyebrow { color:rgba(20,20,24,0.72); }
.ch-head { margin-top:26px; max-width:1400px; display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:16px 20px; }
.ch-lead { display:inline-flex; flex-wrap:wrap; gap:0 22px; }
.ch-lead .cw { color:#fff; font-size:96px; font-weight:800; letter-spacing:-0.03em; line-height:1.0; }
.chapter.dark .ch-lead .cw { color:#17181c; }
.ch-cap { display:inline-block; font-size:96px; font-weight:800; letter-spacing:-0.03em; line-height:1.0;
padding:4px 36px 12px; border-radius:999px; box-shadow:0 22px 54px rgba(0,0,0,0.35); }
.ch-sub { margin-top:40px; max-width:1040px; color:rgba(255,255,255,0.92); font-size:27px; font-weight:500; line-height:1.45; }
.chapter.dark .ch-sub { color:rgba(20,20,24,0.8); }
/* ---- Full-screen sections (data open, wall). ---- */
.section { position:absolute; inset:0; z-index:34; display:flex; flex-direction:column; align-items:center; justify-content:center;
text-align:center; padding:0 80px; will-change:opacity; }
.data-kicker { color:rgba(255,255,255,0.86); letter-spacing:0.46em; font-size:22px; font-weight:700; text-transform:uppercase; }
.data-num { margin-top:6px; }
#data-count { font-size:260px; font-weight:800; letter-spacing:-0.04em; line-height:0.98; color:#fff; text-shadow:0 10px 60px rgba(0,30,90,0.45); }
.data-sub { margin-top:4px; color:rgba(255,255,255,0.92); font-size:30px; font-weight:500; }
.bars { margin-top:44px; width:640px; display:flex; flex-direction:column; gap:16px; }
.bar-top { display:flex; justify-content:space-between; align-items:baseline; margin-bottom:7px; }
.bar-k { color:rgba(255,255,255,0.92); font-size:20px; font-weight:700; letter-spacing:0.04em; }
.bar-v { color:#fff; font-size:22px; font-weight:800; }
.bar-track { height:14px; border-radius:999px; background:rgba(255,255,255,0.18); overflow:hidden; }
.bar-fill { height:100%; border-radius:999px; background:#fff; transform-origin:left center; }
.data-hook { margin-top:46px; color:#fff; font-size:40px; font-weight:700; }
.hook-cap { display:inline-block; background:#05070d; color:#6fb0ff; padding:2px 22px 8px; border-radius:999px; }
/* ---- Result wall ---- */
.wall { justify-content:center; }
.wall-kicker { color:#fff; letter-spacing:0.08em; font-size:40px; font-weight:800; margin-bottom:26px; text-shadow:0 6px 30px rgba(0,20,70,0.4); }
.wall-grid { display:flex; flex-wrap:wrap; justify-content:center; align-items:flex-start; gap:18px; max-width:1180px; }
.tile { position:relative; width:206px; height:296px; border-radius:16px; overflow:hidden; background:#0b1322;
box-shadow:0 20px 44px rgba(0,0,0,0.4); border:1px solid rgba(255,255,255,0.14); will-change:opacity,transform; }
.tile img { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; object-position:top center; display:block; }
.tile-label { position:absolute; left:0; right:0; bottom:0; padding:22px 10px 9px; font-size:15px; font-weight:800; color:#fff;
background:linear-gradient(to top, rgba(3,8,20,0.98) 0%, rgba(3,8,20,0.9) 42%, rgba(3,8,20,0) 100%); text-shadow:0 1px 4px rgba(0,0,0,0.8); text-align:center; }
.lockup { position:absolute; inset:0; z-index:2; display:flex; flex-direction:column; align-items:center; justify-content:center;
background:radial-gradient(900px 620px at 50% 46%, rgba(8,40,110,0.62) 0%, rgba(8,40,110,0) 70%); }
.lock-eyebrow { color:#bcd6ff; letter-spacing:0.5em; font-size:22px; font-weight:700; text-transform:uppercase; }
.lock-title { color:#fff; font-size:150px; font-weight:800; letter-spacing:-0.03em; line-height:1.0; margin-top:14px; text-shadow:0 12px 60px rgba(0,20,80,0.5); }
.lock-sub { color:rgba(255,255,255,0.94); font-size:28px; font-weight:500; margin-top:22px; max-width:1040px; line-height:1.45; }
.assembly { position:absolute; inset:0; z-index:20; width:100%; height:100%; object-fit:cover; display:block; background:#000; opacity:0; }
</style>
<div id="root" data-composition-id="promo" data-width="${CANVAS_W}" data-height="${CANVAS_H}" data-duration="${total}">
<div id="fieldwrap">
${fieldEls}
</div>
<div id="stage">
<div id="phoneRig">
<div id="phoneShadow"></div>
<div id="device">
<div class="screen">
${screenVideoEls}
</div>
</div>
</div>
</div>
${stageTextEls}
${asmEl}
${dataEl}
${chapterEls}
${wallEl}
${audioEl}
</div>
<script>
const tl = gsap.timeline({ paused: true });
const F = 0.5; // crossfade length
// Count-up helper driven by the paused timeline (fires on seek-scrub).
function countUp(sel, to, at, dur) {
const node = document.querySelector(sel);
const proxy = { v: 0 };
tl.to(proxy, { v: to, duration: dur, ease: 'power2.out',
onUpdate: () => { node.textContent = Math.round(proxy.v).toLocaleString('en-US'); } }, at);
}
// ---------- DATA OPEN ----------
const D = { start: ${dataSeg.start}, end: ${dataSeg.end} };
// Data section is opaque from the very first frame (clean blue opener, no
// black/phone peek), then crossfades out into chapter 1.
tl.set('#data', { opacity: 1 }, 0);
tl.to('#data', { opacity: 0, duration: F, ease: 'power2.in' }, D.end - F);
// Slow continuous breath so no hold is a frame-identical run.
tl.fromTo('#data', { scale: 1 }, { scale: 1.02, duration: D.end, ease: 'sine.inOut' }, 0);
tl.fromTo('#data .data-kicker', { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.5, ease: 'power2.out' }, D.start + 0.2);
tl.fromTo('#data-count', { opacity: 0, scale: 0.9 }, { opacity: 1, scale: 1, duration: 0.5, ease: 'back.out(1.6)' }, D.start + 0.45);
countUp('#data-count', ${f.population}, D.start + 0.5, 1.7);
tl.fromTo('#data .data-sub', { opacity: 0, y: 12 }, { opacity: 1, y: 0, duration: 0.5, ease: 'power2.out' }, D.start + 1.7);
tl.fromTo('#data .bar', { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.45, stagger: 0.12, ease: 'power2.out' }, D.start + 2.3);
tl.fromTo('#data .bar-fill', { scaleX: 0 }, { scaleX: 1, duration: 0.8, stagger: 0.12, ease: 'power3.out' }, D.start + 2.4);
document.querySelectorAll('#data .bar-v').forEach((el) => {
countUp('#data .bar-v[data-to="' + el.getAttribute('data-to') + '"]', Number(el.getAttribute('data-to')), D.start + 2.4, 0.9);
});
tl.fromTo('#data .data-hook', { opacity: 0, y: 16 }, { opacity: 1, y: 0, duration: 0.6, ease: 'power2.out' }, D.start + 4.3);
tl.fromTo('#data .hook-cap', { scale: 0.5, opacity: 0 }, { scale: 1, opacity: 1, duration: 0.5, ease: 'back.out(2)' }, D.start + 4.8);
// ---------- FIELD PANELS (color journey) ----------
const STAGES = ${stageCfg};
for (const s of STAGES) {
tl.fromTo('#field-' + s.id, { opacity: 0 }, { opacity: 1, duration: F, ease: 'power1.out' }, s.start - F);
tl.to('#field-' + s.id, { opacity: 0, duration: F, ease: 'power1.in' }, s.end - F);
}
// ---------- PHONE STAGE (per-act framing) ----------
const CLIPS = ${clipCfg};
// The phone stage stays mounted the whole time; opaque overlays (chapters
// z30, sections z34, assembly z20) cover it except during the acts, so no
// per-act show/hide juggling is needed - just reposition the rig while the
// covering chapter card is still opaque.
for (const s of STAGES) {
tl.set('#phoneRig', { x: s.frame.x, y: s.frame.y, scale: s.frame.scale }, Math.max(0, s.start - 0.25));
// Gentle camera push across the act so no footage frame is static.
tl.fromTo('#phoneRig', { scale: s.frame.scale }, { scale: s.frame.scale * 1.03, duration: s.end - s.start, ease: 'none' }, s.start);
// Side text + chips.
const dx = s.textSide === 'right' ? 40 : (s.textSide === 'left' ? -40 : 0);
const dy = s.textSide === 'top' ? -18 : 0;
tl.fromTo('#text-' + s.id, { opacity: 0, x: dx, y: dy }, { opacity: 1, x: 0, y: 0, duration: 0.6, ease: 'power2.out' }, s.start + 0.1);
tl.to('#text-' + s.id, { opacity: 0, duration: 0.45, ease: 'power2.in' }, s.end - F);
tl.fromTo('#text-' + s.id + ' .chip', { opacity: 0, y: 12 }, { opacity: 1, y: 0, duration: 0.45, stagger: 0.5, ease: 'power2.out' }, s.start + 0.5);
}
// ---------- CHAPTER CARDS ----------
const CHAPTERS = ${chapterCfg};
for (const c of CHAPTERS) {
tl.fromTo('#' + c.id, { opacity: 0 }, { opacity: 1, duration: F, ease: 'power2.out' }, c.start);
tl.to('#' + c.id, { opacity: 0, duration: F, ease: 'power2.in' }, c.end - F);
tl.fromTo('#' + c.id + ' .ch-eyebrow', { opacity: 0, y: 16 }, { opacity: 1, y: 0, duration: 0.5, ease: 'power2.out' }, c.start + 0.15);
tl.fromTo('#' + c.id + ' .ch-lead .cw', { opacity: 0, y: 30 }, { opacity: 1, y: 0, duration: 0.5, stagger: 0.09, ease: 'power3.out' }, c.start + 0.3);
tl.fromTo('#' + c.id + ' .ch-cap', { opacity: 0, scale: 0.4 }, { opacity: 1, scale: 1, duration: 0.55, ease: 'back.out(2.2)' }, c.start + 0.62);
tl.fromTo('#' + c.id + ' .ch-sub', { opacity: 0, y: 16 }, { opacity: 1, y: 0, duration: 0.55, ease: 'power2.out' }, c.start + 0.9);
tl.fromTo('#' + c.id, { scale: 1 }, { scale: 1.02, duration: c.end - c.start, ease: 'sine.inOut' }, c.start);
}
// ---------- ASSEMBLY (full canvas) ----------
const A = { start: ${asmSeg.start}, end: ${asmSeg.end} };
tl.fromTo('#vid-assembly', { opacity: 0 }, { opacity: 1, duration: F, ease: 'power1.out' }, A.start - F);
tl.to('#vid-assembly', { opacity: 0, duration: F, ease: 'power1.in' }, A.end - F);
// ---------- RESULT WALL + LOCKUP ----------
const W = { start: ${wallSeg.start}, end: ${wallSeg.end} };
tl.fromTo('#wall', { opacity: 0 }, { opacity: 1, duration: F, ease: 'power2.out' }, W.start - F);
tl.to('#wall', { opacity: 0, duration: F, ease: 'power2.in' }, W.end - F + 0.2);
// Slow continuous push on the whole wall/lockup so the closing hold is
// never a frame-identical run.
tl.fromTo('#wall', { scale: 1 }, { scale: 1.03, duration: W.end - (W.start - F), ease: 'sine.inOut' }, W.start - F);
tl.fromTo('#wall-kicker', { opacity: 0, y: -16 }, { opacity: 1, y: 0, duration: 0.5, ease: 'power2.out' }, W.start);
tl.fromTo('#wall .tile', { opacity: 0, y: 40, scale: 0.8 }, { opacity: 1, y: 0, scale: 1, duration: 0.5, stagger: 0.06, ease: 'back.out(1.5)' }, W.start + 0.3);
// Tiles settle back and dim as the brand lockup takes over.
tl.to('#wall .wall-grid', { opacity: 0.22, scale: 0.96, duration: 0.6, ease: 'power2.inOut' }, W.start + 3.3);
tl.to('#wall-kicker', { opacity: 0, duration: 0.4, ease: 'power2.in' }, W.start + 3.3);
tl.fromTo('#lockup', { opacity: 0 }, { opacity: 1, duration: 0.5, ease: 'power2.out' }, W.start + 3.5);
tl.fromTo('#lockup .lock-eyebrow', { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.5, ease: 'power2.out' }, W.start + 3.6);
tl.fromTo('#lockup .lock-title', { opacity: 0, scale: 0.86 }, { opacity: 1, scale: 1, duration: 0.6, ease: 'back.out(1.6)' }, W.start + 3.8);
tl.fromTo('#lockup .lock-sub', { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.55, ease: 'power2.out' }, W.start + 4.3);
window.__timelines = window.__timelines || {};
window.__timelines.promo = tl;
</script>
</template>
`;
const indexHtml = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The Commons &middot; OpenMotion promo (redesign 3)</title>
<script src="assets/gsap.min.js"></script>
<style>body{margin:0;background:#000}#main{position:relative;width:${CANVAS_W}px;height:${CANVAS_H}px;overflow:hidden}</style>
</head>
<body>
<div id="main" data-composition-id="main" data-start="0" data-duration="${total}" data-width="${CANVAS_W}" data-height="${CANVAS_H}" data-fps="${FPS}">
<div id="promo" class="clip"
data-composition-id="promo"
data-composition-src="compositions/promo.html"
data-start="0" data-duration="${total}" data-track-index="0"
data-width="${CANVAS_W}" data-height="${CANVAS_H}"></div>
</div>
<script>
window.__timelines = window.__timelines || {};
window.__timelines.main = gsap.timeline({ paused: true });
</script>
</body>
</html>
`;
mkdirSync(COMPOSITIONS_DIR, { recursive: true });
mkdirSync(ASSETS_DIR, { recursive: true });
writeFileSync(resolve(COMPOSITIONS_DIR, "promo.html"), promoHtml);
writeFileSync(resolve(OM_DIR, "index.html"), indexHtml);
const gsapSrc = resolve(OM_DIR, "..", "openmotion-poc", "assets", "gsap.min.js");
const gsapDst = resolve(ASSETS_DIR, "gsap.min.js");
if (!existsSync(gsapDst)) copyFileSync(gsapSrc, gsapDst);
console.log("Composition built (redesign 3).");
console.log(` total duration : ${total}s (${Math.round(total * FPS)} frames @ ${FPS}fps)`);
console.log(` phone box : ${phoneW}x${PHONE_H} (video ${videoSize.width}x${videoSize.height}, aspect-exact)`);
console.log(" segments :", seg.map((s) => `${s.id}[${s.start.toFixed(1)}-${s.end.toFixed(1)}]`).join(" "));
console.log(` wall tiles : ${WALL_TILES.length}`);
console.log(` ambient : ${AMBIENT_SRC} @ ${AMBIENT_VOLUME} over ${total}s`);
}
main();