Skip to content
← Public packages

@kentcdodds/invisible-software-talk

Invisible Software: Kent C. Dodds's AI Coding Summit NYC 2026 talk deck. Agents become software's next billion users.

FollowForkOpen app

Files

build-demo.mjs

56 lines · 3.8 KB · JavaScript
// Composes Kent's invisible software phone demo (from @kentcdodds/invisible-software, sources in
// demo/) into one HTML document with the shared CSS and JS inlined. Images and fonts are either
// data: URIs (asset = undefined: the offline dist/index.html embeds the document as an iframe srcdoc)
// or URLs returned by asset(rel) (the hosted deck serves the document and each asset as separate
// content-hashed files; see scripts/build.mjs and src/c/demo.js).
//
// Embedded, the page is transparent, never touches the URL, and ignores its own keys and clicks:
// the deck drives it through window.__slideshow (hold, play, seekScene).
import { readdirSync, readFileSync } from 'node:fs'
import { join, extname } from 'node:path'

const root = new URL('..', import.meta.url).pathname
const dir = join(root, 'demo')
const types = { '.png': 'image/png', '.svg': 'image/svg+xml', '.woff2': 'font/woff2', '.webp': 'image/webp', '.jpg': 'image/jpeg' }
const dataUri = (rel) => {
	const type = types[extname(rel)]
	if (!type) throw new Error(`demo: no content type for ${rel}`)
	return `data:${type};base64,${readFileSync(join(dir, 'c', rel)).toString('base64')}`
}

export function buildDemo(asset) {
	const ref = (rel) => (asset ? asset(rel) : dataUri(rel))
	const slideFiles = readdirSync(join(dir, 'slides')).filter((f) => f.endsWith('.html')).sort()
	let page = readFileSync(join(dir, 'deck.html'), 'utf8')
		.replace(/<script>\s*\/\/ Kody may serve this page[\s\S]*?<\/script>/, '')
		.replace(/<link rel="(?:icon|apple-touch-icon)"[^>]*>\n?/g, '')
		.replace(/<link rel="stylesheet" href="([\w.-]+)">/g, (_, f) => `<style>\n${readFileSync(join(dir, 'c', f), 'utf8').trim()}\n</style>`)
		.replace(/<script src="([\w.-]+)"><\/script>/g, (_, f) => `<script>\n${readFileSync(join(dir, 'c', f), 'utf8').trim()}\n</script>`)
		.replace('<!-- slides -->', () => slideFiles.map((f) => readFileSync(join(dir, 'slides', f), 'utf8').trim()).join('\n'))
	page = page
		.replace(/url\('((?:fonts|assets)\/[\w./-]+)'\)/g, (_, p) => `url('${ref(p)}')`)
		.replace(/(["'])(assets\/[\w.-]+\.(?:png|svg|jpg|webp))\1/g, (_, q, p) => `${q}${ref(p)}${q}`)
	// Embedded in the deck: transparent, no URL changes, no own input handling.
	page = page.replace('</head>', `<script>window.__embedded = true; document.documentElement.classList.add('embedded')</script>
<style>html.embedded, html.embedded body { background: transparent !important; }</style>
</head>`)
	const patches = [
		['function syncUrl(push = true) {', 'function syncUrl(push = true) {\n\treturn'],
		["addEventListener('keydown', (e) => {", "addEventListener('keydown', (e) => {\n\treturn"],
		["addEventListener('click', (e) => {", "addEventListener('click', (e) => {\n\treturn"],
		["addEventListener('popstate', restoreFromUrl)", ''],
		["addEventListener('hashchange', restoreFromUrl)", ''],
		// The deck owns the start frame: the demo holds its first frame once ready.
		['hold(parseHash(location.hash), false)', 'hold(-1, false); window.__demoReady = true; window.dispatchEvent(new Event(\'demoready\'))'],
		// seekScene(label): a scene's first frame, for slides that open on a scene before its first step.
		['window.__slideshow = { SLIDES,', "function seekScene(label) { cancelAnimationFrame(raf); state.playing = false; const si = SLIDES.findIndex((s) => s.label === label); seek(si, SLIDES[si].segs[0][0]) }\nwindow.__slideshow = { seekScene, play, SLIDES,"],
	]
	for (const [from, to] of patches) {
		if (!page.includes(from)) throw new Error(`demo: patch target missing: ${from}`)
		page = page.replace(from, to)
	}
	const allowed = asset ? `data:|#|demo/` : `data:|#`
	const leftover = page.match(new RegExp(`(?:src|href)="(?!${allowed})[^"$]*"|url\\((?!['"]?(?:${allowed}))[^)]*\\)`))
	if (leftover) throw new Error(`demo: external reference left: ${leftover[0].slice(0, 100)}`)
	return page
}