// Assembles deck/slides.mjs into one HyperFrames composition at // public/deck/index.html (the file the player loads and `hyperframes check` // validates). Slide times are local in slides.mjs; this lays them end to end // and writes absolute times into the scenes, the timeline, and the slideshow // island. import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath, pathToFileURL } from 'node:url' import { AGENT_POOL, WAYFIND_BADGE } from '../deck/lib.mjs' import { DEFAULTS, layoutSlide, measureSteps } from '../deck/timing.mjs' const root = join(dirname(fileURLToPath(import.meta.url)), '..') const deckDir = join(root, 'deck') const outDir = join(root, 'public', 'deck') const round = (n) => Math.round(n * 1000) / 1000 function symbolFrom(file, id) { const svg = readFileSync(join(outDir, 'assets', 'agents', file), 'utf8') const viewBox = svg.match(/viewBox="([^"]+)"/)[1] const inner = svg .replace(/^[\s\S]*?]*>/, '') .replace(/<\/svg>\s*$/, '') .replace(/[\s\S]*?<\/title>/, '') return `<symbol id="${id}" viewBox="${viewBox}" fill="currentColor">${inner}</symbol>` } export async function buildDeck() { // cache-bust so `vite` dev picks up edits to the slide modules const bust = `?t=${Date.now()}` const { slides } = await import(pathToFileURL(join(deckDir, 'slides.mjs')).href + bust) mkdirSync(join(outDir, 'vendor'), { recursive: true }) copyFileSync( join(root, 'node_modules/@hyperframes/core/dist/hyperframe.runtime.iife.js'), join(outDir, 'vendor/hyperframe.runtime.iife.js'), ) copyFileSync(join(root, 'node_modules/gsap/dist/gsap.min.js'), join(outDir, 'vendor/gsap.min.js')) let t = 0 const scenes = [] const anims = [] const island = { slides: [] } for (const [i, s] of slides.entries()) { const T = t / 1000 const next = slides[i + 1] const topicClass = s.topic ? ` t-${s.topic}` : '' const wipeTopic = s.exit === 'wipe' ? (s.wipeColor ?? s.nextTopic ?? next?.topic) : s.enter === 'wipe' ? s.topic : null const wipe = wipeTopic ? `<div class="wipe t-${wipeTopic}"></div>` : '' const sceneInner = (dur) => `<div class="scene${topicClass}" id="s-${s.id}" data-composition-id="${s.id}" data-start="${T}" data-duration="${dur}" data-label="${s.label.replace(/"/g, '"')}" data-width="1920" data-height="1080"> <section class="clip stage${s.tinted ? ' tinted' : ''}${s.connect ? ' connect' : ''}" data-start="0" data-duration="${dur}" data-track-index="1"> <div class="inner">${s.html}</div>${wipe} </section> </div>` // Time comes from the steps themselves (see deck/timing.mjs). const { starts, stops, dur, exitAt } = layoutSlide(s, measureSteps(s, sceneInner(0))) scenes.push(`\n<!-- ${i + 1}. ${s.label} -->\n${sceneInner(dur)}`) s.steps.forEach((step, k) => { anims.push(`// ${s.id}, step ${k}\n(${step.toString()})(H.at(${round(T + starts[k])}, ${JSON.stringify(s.id)}), ${JSON.stringify(s.id)});`) }) if (s.enter === 'wipe') { const [x, y] = s.wipeTo ?? WAYFIND_BADGE anims.push(`H.wipeOut(${JSON.stringify(s.id)}, ${T}, ${x}, ${y});`) } if (s.exit === 'wipe') { const [x, y] = s.wipeFrom ?? [960, 540] anims.push(`H.wipeIn(${JSON.stringify(s.id)}, ${round(T + exitAt)}, ${x}, ${y});`) anims.push(`H.out(${JSON.stringify(s.id)}, ${round(T + exitAt + 0.3)});`) } else if (s.exit !== 'none') { anims.push(`H.out(${JSON.stringify(s.id)}, ${round(T + exitAt)});`) } island.slides.push({ sceneId: s.id, notes: s.notes, fragments: stops.map((h) => round(T + h)), }) t += dur * 1000 } const total = t / 1000 const symbols = [ ...AGENT_POOL.map((name) => symbolFrom(`${name}.svg`, `ag-${name}`)), symbolFrom('cloudflare.svg', 'ag-cloudflare'), `<symbol id="g-person" viewBox="0 0 24 24"><circle cx="12" cy="8" r="4.2" fill="#fff"/><path d="M3.5 21c.8-4.6 4.2-7 8.5-7s7.7 2.4 8.5 7z" fill="#fff"/></symbol>`, ].join('\n') const css = readFileSync(join(deckDir, 'deck.css'), 'utf8') const page = readFileSync(join(deckDir, 'page.js'), 'utf8') const out = `<!doctype html> <!-- GENERATED by scripts/build-deck.mjs from deck/. Edit deck/slides.mjs, not this file. --> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=1920, height=1080" /> <title>I Built Your Personal Software Ecosystem
${scenes.join('\n')}
` writeFileSync(join(outDir, 'index.html'), out) return { island, total, count: slides.length } } if (import.meta.url === pathToFileURL(process.argv[1]).href) { const { total, count } = await buildDeck() console.log(`deck: ${count} slides, ${total}s timeline → public/deck/index.html`) }