Skip to content
← Public packages

@kentcdodds/cloudflare-connect-pse-hyperframes

I Built Your Personal Software Ecosystem: Kent C. Dodds's Cloudflare Connect 2026 talk deck, built with HyperFrames. How Kody gives every user one of everything on Cloudflare.

FollowForkOpen app

Files

flows.js

868 lines · 28.7 KB · JavaScript
// Per-slide motion, read by runtime.js. FLOWS build one looping timeline for a slide's
// stage at a fragment step; STEPS run when a slide enters or changes step.
;(function () {
	'use strict'
	var FLOWS = (window.__deckFlows = {})
	var STEPS = (window.__deckSteps = {})
	// Seeded mulberry32, so the composition stays deterministic for HyperFrames renders.
	var seed = 0x2f6b9d1
	function rand() {
		seed = (seed + 0x6d2b79f5) | 0
		var t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
		t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
		return ((t ^ (t >>> 14)) >>> 0) / 4294967296
	}

	FLOWS['write-once'] = function (f) {
		var badge = f.stage.querySelector('.badge')
		var oks = f.stage.querySelectorAll('[data-ok]')
		f.tl.set(oks, { opacity: 0 }, 0)
		f.text(badge, 'draft', 0.001)
		f.attr(badge, 'data-v', 'draft', 0.001)
		f.attr('.diff', 'data-on', '0', 0.001)
		oks.forEach(function (o) {
			f.text(o, 'v1.3', 0.001)
		})

		f.lit('editor', 0.2, 1.6)
		var t = f.send('publish', 'publish', 0.8, { dur: 1 })
		f.text(badge, 'v1.3', t).attr(badge, 'data-v', '1.3', t)
		f.tl.fromTo(badge, { scale: 1.5 }, { scale: 1, duration: 0.5, ease: 'back.out(2)' }, t)
		f.lit('pkg', t, 1)

		var callers = ['claude', 'cursor', 'chatgpt']
		callers.forEach(function (c, i) {
			var at = t + 1 + i * 1.7
			f.lit(c, at, 1.4)
			var arrive = f.send(c, 'run', at, { dur: 0.7 })
			f.lit('pkg', arrive, 0.4)
			var back = f.send(c, '\u2713 briefing', arrive + 0.15, { dur: 0.7, reverse: true, cls: 'back' })
			f.tl.to(oks[i], { opacity: 1, duration: 0.3 }, back)
		})

		var change = t + 1 + 3 * 1.7 + 0.6
		f.lit('editor', change, 2)
		f.attr('.diff', 'data-on', '1', change)
		var t2 = f.send('publish', 'publish', change + 0.8, { dur: 1 })
		f.text(badge, 'v1.4', t2).attr(badge, 'data-v', '1.4', t2)
		f.tl.fromTo(badge, { scale: 1.6 }, { scale: 1, duration: 0.6, ease: 'back.out(2)' }, t2)
		f.lit('pkg', t2, 2.4)
		f.tl.to(oks, { opacity: 0, duration: 0.3 }, t2)
		var all = t2 + 0.8
		callers.forEach(function (c, i) {
			f.lit(c, all, 2.6)
			var arrive = f.send(c, 'run', all, { dur: 0.7 })
			var back = f.send(c, 'v1.4', arrive + 0.15, { dur: 0.7, reverse: true, cls: 'back' })
			f.text(oks[i], 'v1.4', back)
			f.tl.to(oks[i], { opacity: 1, duration: 0.3 }, back)
		})
		f.still(all + 2)
	}

	// Each kody: import resolves to its published bundle, then everything loads into one Dynamic Worker.
	FLOWS['how-import'] = function (f) {
		var lines = f.stage.querySelectorAll('[data-line]')
		var slots = f.stage.querySelectorAll('[data-slot]')
		lines.forEach(function (l) {
			f.attr(l, 'data-hot', '0', 0.001)
		})
		slots.forEach(function (s) {
			f.attr(s, 'data-in', '0', 0.001)
		})
		f.lit('module', 0.2, 1)
		f.attr(lines[0], 'data-hot', '1', 0.5)
		var r1 = f.send('r1', 'resolve', 0.6, { dur: 0.9 })
		f.lit('b1', r1, 2.6)
		f.attr(lines[0], 'data-hot', '0', r1 + 0.3)
		f.attr(lines[1], 'data-hot', '1', r1 + 0.4)
		var r2 = f.send('r2', 'resolve', r1 + 0.5, { dur: 0.9 })
		f.lit('b2', r2, 1.6)
		f.attr(lines[1], 'data-hot', '0', r2 + 0.3)

		var go = r2 + 0.7
		f.lit('module', go, 1)
		var inM = f.send('m-dw', 'module', go, { dur: 0.9 })
		var inB1 = f.send('b1-dw', 'bundle', go + 0.1, { dur: 1, cls: 'cf' })
		var inB2 = f.send('b2-dw', 'bundle', go + 0.2, { dur: 1, cls: 'cf' })
		f.attr(slots[0], 'data-in', '1', inM)
		f.attr(slots[1], 'data-in', '1', inB1)
		f.attr(slots[2], 'data-in', '1', inB2)
		f.lit('dw', inM, 2.6)
		var back = f.send('result', 'result', inB2 + 0.8, { dur: 1.3, cls: 'back' })
		f.lit('module', back, 1.2)
		f.still(inB2 + 0.6)
	}

	// Three ways in, one package; only the flaky run wakes an agent.
	FLOWS['triggers'] = function (f) {
		var runs = f.stage.querySelector('[data-runs]')
		var say = f.stage.querySelector('[data-say]')
		f.text(runs, '12', 0.001).text(say, 'waiting', 0.001)
		var events = [
			['webhook', 'POST', 'github: push synced'],
			['schedule', '04:00', 'scan, no model: clean'],
			['email', 'mail', 'receipt filed'],
			['schedule', '04:00', 'flaky test found'],
		]
		var at = 0.3
		events.forEach(function (e, i) {
			f.lit(e[0], at, 1)
			var arrive = f.send(e[0], e[1], at + 0.1, { dur: 0.9 })
			f.lit('pkg', arrive, 0.9)
			f.text(runs, String(13 + i), arrive).text(say, e[2], arrive)
			at = arrive + 1.1
		})
		var woke = f.send('wake', 'wake', at - 0.6, { dur: 0.6, cls: 'back' })
		f.lit('agent', woke, 1.6)
		f.text(say, 'agent investigates', woke)
		f.still(woke + 0.4)
	}

	// The flow steps back and the manifest takes the stage at full size.
	STEPS['triggers'] = function (el, step, o) {
		var box = el.querySelector('[data-flowbox]')
		gsap.killTweensOf(box)
		var pose = step >= 1 ? { scale: 0.92, opacity: 0 } : { scale: 1, opacity: 1 }
		if (o.entering || o.still) gsap.set(box, pose)
		else gsap.to(box, { scale: pose.scale, opacity: pose.opacity, duration: o.soft ? 0.9 : 0.6, ease: 'power3.inOut' })
	}

	FLOWS['cloudflare-runtime'] = function (f) {
		var label = f.stage.querySelector('[data-src-label]')
		var icon = f.stage.querySelector('[data-src-icon]')
		var paths = [
			['Your agent', 1, 'execute', 'loaders', 'LOADER.get'],
			['Your agent', 1, 'workflows.create', 'workflows', 'start'],
			['A webhook', 0, 'POST', 'queues', 'enqueue'],
			['An email', 0, 'to you@', 'email', 'route'],
		]
		var at = 0.3
		paths.forEach(function (p) {
			f.text(label, p[0], at)
			f.tl.to(icon, { opacity: p[1], duration: 0.2 }, at)
			f.lit('src', at, 1)
			var hit = f.send('in', p[2], at + 0.2, { dur: 0.9 })
			f.lit('fleet', hit, 1)
			var done = f.send(p[3], p[4], hit + 0.1, { dur: 0.9, cls: 'cf' })
			f.lit(p[3], done, 1.2)
			at = done + 1
		})
		f.text(label, 'Your agent', 0.001)
		f.tl.set(icon, { opacity: 1 }, 0.001)
		f.still(2.6)
	}

	FLOWS['how-execute'] = function (f) {
		var result = f.stage.querySelector('[data-result]')
		f.text(result, ' ', 0.001)
		f.lit('agent', 0.2, 1)
		var a = f.send('code', 'code', 0.4, { dur: 1 })
		f.lit('loader', a, 1.2)
		var b = f.send('mint', 'module', a + 0.2, { dur: 1, cls: 'cf' })
		f.lit('dw', b, 1.8)
		f.text(result, 'runs once', b)
		var c = f.send('mint', 'result', b + 0.9, { dur: 1, reverse: true, cls: 'back' })
		var d = f.send('code', 'result', c + 0.1, { dur: 1, reverse: true, cls: 'back' })
		f.lit('agent', d, 1.2)
		f.text(result, ' ', d + 0.6)
		f.still(b + 0.5)
	}

	// Approved host: the key is added at the boundary. Unapproved host: nothing leaves.
	FLOWS['secret-gateway'] = function (f, step) {
		var blocked = step >= 1
		f.stage.closest('section').setAttribute('data-blocked', blocked ? '1' : '0')
		f.stage.querySelector('[data-host]').textContent = blocked ? 'paste.example' : 'api.github.com'
		var rule = f.stage.querySelector(blocked ? '[data-rule="no"]' : '[data-rule="ok"]')
		f.stage.querySelectorAll('[data-rule]').forEach(function (r) {
			r.setAttribute('data-hot', '0')
		})
		f.attr(rule, 'data-hot', '0', 0.001)

		f.lit('agent', 0.2, 1)
		var a = f.send('a-dw', 'execute', 0.4, { dur: 0.9 })
		f.lit('dw', a, 1.2)
		var b = f.send('dw-gw', 'github.fetch', a + 0.2, { dur: 0.9, cls: 'key' })
		f.lit('gw', b, blocked ? 1.6 : 2.4)
		f.attr(rule, 'data-hot', '1', b + 0.1)
		f.attr(rule, 'data-hot', '0', b + 2)
		if (!blocked) {
			var c = f.send('gw-host', 'Bearer ••••9f3c', b + 0.5, { dur: 1, cls: 'key' })
			f.lit('host', c, 1.4)
			var d = f.send('gw-host', '200 OK', c + 0.4, { dur: 0.9, reverse: true, cls: 'back' })
			var e = f.send('dw-gw', '5 repos', d + 0.1, { dur: 0.9, reverse: true, cls: 'back' })
			var g = f.send('a-dw', '5 repos', e + 0.1, { dur: 0.9, reverse: true, cls: 'back' })
			f.lit('agent', g, 1)
			f.still(c + 0.2)
			return
		}
		var wire = f.wire('gw-host')
		var rest = getComputedStyle(wire).stroke
		f.tl.to(wire, { stroke: '#ff7a6b', duration: 0.2 }, b + 0.5)
		f.tl.to(wire, { stroke: rest, duration: 0.6 }, b + 2.2)
		var e2 = f.send('dw-gw', 'host_not_allowed', b + 0.7, { dur: 0.9, reverse: true, cls: 'err' })
		var g2 = f.send('a-dw', 'host_not_allowed', e2 + 0.1, { dur: 0.9, reverse: true, cls: 'err' })
		f.lit('agent', g2, 1)
		f.still(b + 0.6)
	}

	// Two users, the same six products, never the same rows.
	FLOWS['cloudflare-data'] = function (f) {
		var cells = ['art', 'do', 'd1', 'r2', 'vec', 'kv']
		var end = 0.5 + cells.length * 0.7 + 1.4
		f.lit('ha', 0.2, end - 0.4).lit('hb', 0.2, end - 0.4)
		cells.forEach(function (c, i) {
			var at = 0.5 + i * 0.7
			var x = f.send('a' + (i + 1), 'u_8f2c', at, { dur: 0.7 })
			f.send('b' + (i + 1), 'u_31d7', at, { dur: 0.7, cls: 'back' })
			f.lit('a-' + c, x, end - x)
			f.lit('b-' + c, x, end - x)
		})
		f.still(end - 0.6)
	}

	FLOWS['this-talk'] = function (f) {
		f.lit('repo', 0.2, 1.2)
		var a = f.send('push', 'git push', 0.4, { dur: 1 })
		f.lit('pkg', a, 1.4)
		var b = f.send('serve', 'publish', a + 0.3, { dur: 1, cls: 'cf' })
		f.lit('app', b, 1.6)
		f.still(b + 0.3)
	}

	// Opening homes. Timers, not the held composition clock, so the motion plays while a slide sits.
	var homeRun = 0
	function bindHome(id, story) {
		STEPS[id] = function (el, step, o) {
			var gen = ++homeRun
			var yard = el.querySelector('.yard')
			if (!yard) return
			function later(ms, fn) {
				window.setTimeout(function () {
					if (gen !== homeRun || el.style.visibility === 'hidden') return
					fn()
				}, ms * (o.soft ? 1.5 : 1))
			}
			function at(sel) {
				return yard.querySelector(sel)
			}
			var api = {
				place: function (sel, x, y, mood) {
					var n = at(sel)
					if (!n) return
					n.style.setProperty('--x', x)
					n.style.setProperty('--y', y)
					if (mood) n.setAttribute('data-mood', mood)
				},
				show: function (sel) {
					var n = at(sel)
					if (n) n.style.opacity = '1'
				},
				hide: function (sel) {
					var n = at(sel)
					if (n) n.style.opacity = '0'
				},
				phase: function (name) {
					if (name) yard.setAttribute('data-phase', name)
					else yard.removeAttribute('data-phase')
				},
				later: later,
				all: function (sel) {
					return Array.prototype.slice.call(yard.querySelectorAll(sel))
				},
				glide: function (n, x, y, ms) {
					if (!n) return
					var dur = Math.round((ms || 1100) * (o.soft ? 1.5 : 1))
					n.style.transitionDuration = dur + 'ms, ' + dur + 'ms, 0.65s, 0.8s, 0.6s'
					n.style.setProperty('--x', x)
					n.style.setProperty('--y', y)
				},
				pin: function (n, x, y, show) {
					if (!n) return
					n.style.setProperty('--move', '0ms')
					n.style.setProperty('--x', x)
					n.style.setProperty('--y', y)
					if (show === true) n.style.opacity = '1'
					else if (show === false) n.style.opacity = '0'
				},
			}
			if (o.still) story.still(api)
			else story.play(api)
		}
	}
	var orbKinds = ['memory', 'packages', 'triggers', 'credentials', 'apps']
	var orbHomes = {
		memory: ['40%', '66%'],
		packages: ['64%', '68%'],
		triggers: ['46%', '80%'],
		credentials: ['60%', '84%'],
		apps: ['52%', '72%'],
	}
	function settleOrbs(a) {
		var pool = a.all('.orb')
		var agent = a.all('[data-actor="claude"]')[0]
		pool.forEach(function (n) {
			a.pin(n, '50%', '76%', false)
		})
		orbKinds.forEach(function (kind) {
			for (var i = 0; i < pool.length; i++) {
				if (pool[i].getAttribute('data-kind') === kind) {
					a.pin(pool[i], orbHomes[kind][0], orbHomes[kind][1], true)
					break
				}
			}
		})
		a.pin(agent, '50%', '70%', true)
	}
	bindHome('one-home', {
		still: function (a) {
			settleOrbs(a)
		},
		play: function (a) {
			var agent = a.all('[data-actor="claude"]')[0]
			var pool = a.all('.orb')
			var cap = 8
			function num(v) {
				return parseFloat(v) || 0
			}
			function read(n) {
				return [num(n.style.getPropertyValue('--x')), num(n.style.getPropertyValue('--y'))]
			}
			function clamp(x, y) {
				x = Math.min(68, Math.max(38, x))
				y = Math.min(86, Math.max(62, y))
				return [Math.round(x * 10) / 10 + '%', Math.round(y * 10) / 10 + '%']
			}
			function spot() {
				return clamp(38 + rand() * 30, 62 + rand() * 24)
			}
			function shift(pt, dx, dy) {
				return clamp(num(pt[0]) + dx, num(pt[1]) + dy)
			}
			function pace(from, to) {
				var len = Math.hypot(num(to[0]) - from[0], num(to[1]) - from[1]) || 1
				return Math.max(1100, Math.min(1900, len * 70))
			}
			function shown(n) {
				return n.style.opacity !== '0'
			}
			function visible() {
				return pool.filter(shown)
			}
			function hidden(kind) {
				return pool.filter(function (n) {
					return !shown(n) && (!kind || n.getAttribute('data-kind') === kind)
				})
			}
			function count(kind) {
				var n = 0
				for (var i = 0; i < pool.length; i++) {
					if (pool[i].getAttribute('data-kind') === kind && shown(pool[i])) n++
				}
				return n
			}
			function missing() {
				for (var i = 0; i < orbKinds.length; i++) {
					if (count(orbKinds[i]) < 1) return orbKinds[i]
				}
				return ''
			}
			function carry(orb, done) {
				var approach = shift(read(orb), -2.4, -2.8)
				var ms = pace(read(agent), approach)
				a.glide(agent, approach[0], approach[1], ms)
				a.later(ms + 160, function () {
					var dest = spot()
					var trip = pace(read(agent), dest)
					var grip = shift(dest, 2.4, 2.8)
					a.glide(agent, dest[0], dest[1], trip)
					a.glide(orb, grip[0], grip[1], trip)
					a.later(trip, done)
				})
			}
			function create(kind, done) {
				var free = hidden(kind)
				if (!free.length) return done()
				var dest = spot()
				var ms = pace(read(agent), dest)
				a.glide(agent, dest[0], dest[1], ms)
				a.later(ms, function () {
					var node = free[Math.floor(rand() * free.length)]
					var at = shift(read(agent), 2.4, 2.8)
					node.style.setProperty('--move', '0ms')
					node.style.setProperty('--x', at[0])
					node.style.setProperty('--y', at[1])
					node.style.opacity = '0'
					a.later(40, function () {
						node.style.opacity = '1'
						a.later(520, done)
					})
				})
			}
			function clearOrb(done) {
				var loose = visible().filter(function (n) {
					return count(n.getAttribute('data-kind')) > 1
				})
				if (!loose.length) return done()
				var orb = loose[Math.floor(rand() * loose.length)]
				var approach = shift(read(orb), -2.4, -2.8)
				var ms = pace(read(agent), approach)
				a.glide(agent, approach[0], approach[1], ms)
				a.later(ms, function () {
					if (count(orb.getAttribute('data-kind')) < 2) return done()
					orb.style.opacity = '0'
					a.later(480, done)
				})
			}
			function stride() {
				var next = function () {
					a.later(280 + rand() * 320, stride)
				}
				var gap = missing()
				if (gap) return create(gap, next)
				var vis = visible()
				var removable = vis.filter(function (n) {
					return count(n.getAttribute('data-kind')) > 1
				})
				if (vis.length >= cap && removable.length) return clearOrb(next)
				if (hidden('').length && rand() < 0.34) return create('', next)
				if (removable.length && vis.length >= 6 && rand() < 0.45) return clearOrb(next)
				if (vis.length) return carry(vis[Math.floor(rand() * vis.length)], next)
				if (hidden('').length) return create('', next)
				a.later(700, stride)
			}
			settleOrbs(a)
			a.later(700, stride)
		},
	})
	bindHome('roommate', {
		still: function (a) {
			a.show('.house.codex')
			a.phase('stuck')
			a.place('[data-actor="user"]', '50%', '80%', 'sad')
			a.place('[data-orb="memory"]', '40%', '48%')
			a.place('[data-orb="packages"]', '41%', '58%')
			a.place('[data-orb="triggers"]', '39%', '68%')
			a.place('[data-orb="credentials"]', '40%', '78%')
			a.place('[data-orb="apps"]', '38%', '88%')
		},
		play: function (a) {
			a.later(700, function () {
				a.show('.house.codex')
			})
			a.later(1600, function () {
				a.place('[data-actor="user"]', '34%', '72%')
			})
			a.later(2500, function () {
				a.phase('stuck')
				a.place('[data-orb="memory"]', '40%', '48%')
				a.place('[data-orb="packages"]', '41%', '58%')
				a.place('[data-orb="triggers"]', '39%', '68%')
				a.place('[data-orb="credentials"]', '40%', '78%')
				a.place('[data-orb="apps"]', '38%', '88%')
			})
			a.later(3600, function () {
				a.place('[data-actor="user"]', '50%', '80%', 'sad')
			})
		},
	})
	function stackHome(a, home, spots) {
		orbKinds.forEach(function (kind) {
			a.place('[data-home="' + home + '"][data-orb="' + kind + '"]', spots[kind][0], spots[kind][1])
		})
	}
	var claudeWall = {
		memory: ['40%', '48%'],
		packages: ['38%', '58%'],
		triggers: ['41%', '68%'],
		credentials: ['37%', '78%'],
		apps: ['39%', '88%'],
	}
	var codexWall = {
		memory: ['60%', '48%'],
		packages: ['62%', '58%'],
		triggers: ['59%', '68%'],
		credentials: ['63%', '78%'],
		apps: ['61%', '88%'],
	}
	bindHome('two-homes', {
		still: function (a) {
			a.phase('stuck')
			a.place('[data-actor="user"]', '34%', '74%', 'sad')
			a.place('[data-actor="teammate"]', '66%', '72%', 'sad')
			stackHome(a, 'claude', claudeWall)
			stackHome(a, 'codex', codexWall)
		},
		play: function (a) {
			a.later(800, function () {
				a.place('[data-actor="user"]', '34%', '74%', 'reach')
				a.place('[data-actor="teammate"]', '66%', '72%', 'reach')
			})
			a.later(1700, function () {
				a.phase('stuck')
				a.place('[data-actor="user"]', '34%', '74%', 'sad')
				a.place('[data-actor="teammate"]', '66%', '72%', 'sad')
				stackHome(a, 'claude', claudeWall)
				stackHome(a, 'codex', codexWall)
			})
		},
	})
	// Agents carry orbs inside one box. A claim keeps two agents off the same orb.
	function carryBox(a, agents, orbs, box, scale) {
		agents = Array.prototype.slice.call(agents)
		orbs = Array.prototype.slice.call(orbs)
		function num(v) {
			return parseFloat(v) || 0
		}
		function read(n) {
			return [num(n.style.getPropertyValue('--x')), num(n.style.getPropertyValue('--y'))]
		}
		function fit(x, y) {
			x = Math.min(box.x1, Math.max(box.x0, x))
			y = Math.min(box.y1, Math.max(box.y0, y))
			return [Math.round(x * 10) / 10 + '%', Math.round(y * 10) / 10 + '%']
		}
		function spot() {
			return fit(box.x0 + rand() * (box.x1 - box.x0), box.y0 + rand() * (box.y1 - box.y0))
		}
		function shift(pt, dx, dy) {
			return fit(num(pt[0]) + dx, num(pt[1]) + dy)
		}
		function pace(from, to) {
			var len = Math.hypot(num(to[0]) - from[0], num(to[1]) - from[1]) || 1
			return Math.max(900, Math.min(1700, len * scale))
		}
		agents.forEach(function (agent, i) {
			function loop() {
				var open = orbs.filter(function (n) {
					return n.getAttribute('data-hold') !== '1'
				})
				if (!open.length) return a.later(360, loop)
				var orb = open[Math.floor(rand() * open.length)]
				orb.setAttribute('data-hold', '1')
				var approach = shift(read(orb), -5, -6)
				var ms = pace(read(agent), approach)
				a.glide(agent, approach[0], approach[1], ms)
				a.later(ms + 120, function () {
					var dest = spot()
					var trip = pace(read(agent), dest)
					var grip = shift(dest, 5, 6)
					a.glide(agent, dest[0], dest[1], trip)
					a.glide(orb, grip[0], grip[1], trip)
					a.later(trip + 160, function () {
						orb.removeAttribute('data-hold')
						a.later(200 + rand() * 280, loop)
					})
				})
			}
			a.later(280 + i * 420, loop)
		})
	}
	var kodyFolks = [
		{ sel: '[data-actor="user"]', home: ['17.4%', '54%'], out: ['17.4%', '82%'], wait: 900 },
		{ sel: '[data-actor="mate-1"]', home: ['38.2%', '54%'], out: ['38.2%', '84%'], wait: 1700 },
		{ sel: '[data-actor="mate-2"]', home: ['59%', '54%'], out: ['59%', '82%'], wait: 2500 },
		{ sel: '[data-actor="mate-3"]', home: ['79.8%', '54%'], out: ['79.8%', '80%'], wait: 3300 },
	]
	bindHome('shared-home', {
		still: function (a) {
			a.place(kodyFolks[0].sel, kodyFolks[0].home[0], kodyFolks[0].home[1])
			a.place(kodyFolks[1].sel, kodyFolks[1].out[0], kodyFolks[1].out[1])
			a.place(kodyFolks[2].sel, kodyFolks[2].home[0], kodyFolks[2].home[1])
			a.place(kodyFolks[3].sel, kodyFolks[3].out[0], kodyFolks[3].out[1])
			a.place('[data-actor="claude"]', '36%', '76%')
			a.place('[data-actor="cursor"]', '54%', '84%')
			a.place('[data-actor="chatgpt"]', '72%', '76%')
		},
		play: function (a) {
			a.all('.room').forEach(function (room) {
				carryBox(a, a.all('[data-room="' + room.getAttribute('data-room') + '"] .agent'), room.querySelectorAll('.orb'), { x0: 22, x1: 78, y0: 42, y1: 84 }, 22)
			})
			carryBox(
				a,
				a.all('[data-actor="claude"], [data-actor="cursor"], [data-actor="chatgpt"]'),
				a.all('[data-zone="common"]'),
				{ x0: 18, x1: 84, y0: 72, y1: 90 },
				36,
			)
			kodyFolks.forEach(function (folk) {
				var node = a.all(folk.sel)[0]
				var outside = false
				function step() {
					outside = !outside
					var dest = outside ? folk.out : folk.home
					a.glide(node, dest[0], dest[1], 1500)
					a.later(2800 + rand() * 800, step)
				}
				a.later(folk.wait, step)
			})
		},
	})

	// Title subtitle: type a line, hold it, backspace it, type the next. Runs on the window
	// timer because the player holds this scene still while the room waits.
	var titleTyper = 0
	STEPS['title'] = function (el, step, o) {
		var gen = ++titleTyper
		var node = el.querySelector('[data-typer]')
		var caret = el.querySelector('.cx-caret')
		if (!node) return
		var lines = Array.prototype.map.call(el.querySelectorAll('.cx-lines li'), function (li) {
			var fix = li.getAttribute('data-fix')
			return fix ? [li.textContent, fix] : li.textContent
		})
		var still = el.querySelector('.cx-lines [data-still]')
		var word = el.querySelector('[data-swap]')
		if (o.still) {
			node.textContent = still ? still.textContent : lines[0] || ''
			if (caret) caret.remove()
			if (word) {
				word.textContent = 'Personal'
				word.setAttribute('data-text', 'Personal')
				word.removeAttribute('data-glitch')
				word.removeAttribute('data-drop')
			}
			return
		}
		var soft = o.soft
		var scale = soft ? 1.7 : 1
		var frame = el
		var burst = 0
		function alive() {
			return gen === titleTyper && frame.style.visibility !== 'hidden'
		}
		function later(ms, fn) {
			window.setTimeout(function () {
				if (!alive()) return
				fn()
			}, ms)
		}
		function charDelay(ch) {
			var ms
			if (ch === ' ') {
				burst = 3
				ms = 78 + rand() * 55
			} else if (ch === ',' || ch === '.' || ch === '!' || ch === '?') {
				burst = 0
				ms = 170 + rand() * 90
			} else if (burst > 0) {
				burst -= 1
				ms = 26 + rand() * 24
			} else {
				ms = 38 + rand() * 46
				if (rand() < 0.12) ms += 100 + rand() * 140
			}
			return ms * scale
		}
		function typeFrom(text, i, done) {
			if (i >= text.length) return done()
			node.textContent = text.slice(0, i + 1)
			later(charDelay(text[i]), function () {
				typeFrom(text, i + 1, done)
			})
		}
		function eraseTo(keep, done, stepN) {
			var cur = node.textContent
			if (cur.length <= keep) return done()
			node.textContent = cur.slice(0, -1)
			var ms = (stepN < 2 ? 90 + rand() * 36 : 34 + rand() * 16) * scale
			later(ms, function () {
				eraseTo(keep, done, stepN + 1)
			})
		}
		function play(line, done) {
			var drafts = Array.isArray(line) ? line : [line]
			var n = 0
			function draft() {
				var target = drafts[n]
				var cur = node.textContent
				var keep = 0
				while (keep < cur.length && keep < target.length && cur[keep] === target[keep]) keep += 1
				eraseTo(keep, function () {
					typeFrom(target, keep, function () {
						n += 1
						if (n < drafts.length) later(680 * scale, draft)
						else later((2000 + target.length * 22 + rand() * 500) * (soft ? 1.25 : 1), done)
					})
				}, 0)
			}
			draft()
		}
		var index = 0
		function cycle() {
			play(lines[index], function () {
				eraseTo(0, function () {
					index = (index + 1) % lines.length
					later(360 * scale, cycle)
				}, 0)
			})
		}
		for (var s = lines.length - 1; s > 0; s--) {
			var pick = Math.floor(rand() * (s + 1))
			var swap = lines[s]
			lines[s] = lines[pick]
			lines[pick] = swap
		}
		node.textContent = ''
		later(soft ? 980 : 700, cycle)

		// The title word tears between Personal and Team: a few scrambled frames, a
		// dropout, then the other word. The h1 itself stays put.
		if (!word) return
		var words = ['Personal', 'Team']
		var which = 0
		var firstHold = true
		function paint(text) {
			word.textContent = text
			word.setAttribute('data-text', text)
		}
		function band(prefix) {
			var top = Math.floor(rand() * 68)
			var height = 16 + Math.floor(rand() * 36)
			word.style.setProperty(prefix + '-t', top + '%')
			word.style.setProperty(prefix + '-b', Math.max(0, 100 - top - height) + '%')
			word.style.setProperty(prefix + '-x', (rand() * 24 - 12).toFixed(1) + 'px')
			word.style.setProperty(prefix + '-y', (rand() * 8 - 4).toFixed(1) + 'px')
		}
		function clearGlitch() {
			word.removeAttribute('data-glitch')
			word.removeAttribute('data-drop')
			word.style.removeProperty('--w-x')
			word.style.removeProperty('--w-y')
		}
		function glitchTo(next, done) {
			var from = words[which]
			var to = words[next]
			var frames = soft ? 5 : 8
			var i = 0
			word.setAttribute('data-glitch', '1')
			function frame() {
				var mid = Math.floor(frames / 2)
				if (!soft && (i === 0 || i === mid)) word.setAttribute('data-drop', '1')
				else word.removeAttribute('data-drop')
				var p = (i + 1) / frames
				var len = Math.max(to.length, Math.round(from.length + (to.length - from.length) * p))
				var alphabet = from + to
				var src = p > 0.7 ? to : from
				var out = ''
				for (var c = 0; c < len; c++) {
					var locked = c < src.length && rand() < p * 0.8
					out += locked ? src[c] : alphabet[Math.floor(rand() * alphabet.length)]
				}
				paint(out)
				if (!soft) {
					band('--a')
					band('--b')
					word.style.setProperty('--w-x', (rand() * 10 - 5).toFixed(1) + 'px')
					word.style.setProperty('--w-y', (rand() * 6 - 3).toFixed(1) + 'px')
				}
				i += 1
				if (i < frames) later(soft ? 90 : 46, frame)
				else {
					paint(to)
					which = next
					clearGlitch()
					if (soft) return done()
					later(160, function () {
						word.setAttribute('data-glitch', '1')
						band('--a')
						band('--b')
						later(80, function () {
							clearGlitch()
							done()
						})
					})
				}
			}
			frame()
		}
		function holdThenSwap() {
			var hold = (firstHold ? 2800 : which === 0 ? 4600 : 3000) + rand() * 500
			firstHold = false
			if (soft) hold *= 1.35
			later(hold, function () {
				glitchTo((which + 1) % words.length, holdThenSwap)
			})
		}
		paint('Personal')
		holdThenSwap()
	}

	// Search: the path plays on its own. Arrow steps zoom the pills, then open the index.
	var searchRun = 0
	STEPS['search-execute'] = function (el, step, o) {
		var cam = el.querySelector('[data-cam]')
		var flow = el.querySelector('[data-flow]')
		var ask = el.querySelector('[data-pill="ask"]')
		var out = el.querySelector('[data-pill="out"]')
		var back = el.querySelector('[data-pill="back"]')
		var dur = o.soft ? 1.15 : 0.7
		function lit(name) {
			var n = el.querySelector('[data-node="' + name + '"]')
			if (n) n.setAttribute('data-lit', '1')
		}
		function park() {
			gsap.killTweensOf([ask, out, back])
			gsap.set(ask, { opacity: 1, left: '23%', top: '13%' })
			gsap.set(out, { opacity: 1, left: '57%', top: '13%' })
			gsap.set(back, { opacity: 1, left: '60%', top: '73%' })
			lit('you')
			lit('agent')
			lit('kody')
		}
		el.setAttribute('data-search-step', String(step))
		if (o.entering) {
			var gen = ++searchRun
			function later(ms, fn) {
				window.setTimeout(function () {
					if (gen !== searchRun || el.style.visibility === 'hidden') return
					if (el.getAttribute('data-search-step') !== '0') return
					fn()
				}, ms * (o.soft ? 1.5 : 1))
			}
			if (o.still || step > 0) park()
			else {
				gsap.set(ask, { opacity: 0, left: '16%', top: '13%' })
				gsap.set(out, { opacity: 0, left: '42%', top: '13%' })
				gsap.set(back, { opacity: 0, left: '78%', top: '73%' })
				later(400, function () {
					lit('you')
					gsap.to(ask, { opacity: 1, left: '23%', top: '13%', duration: dur, ease: 'power2.inOut' })
				})
				later(1500, function () {
					lit('agent')
				})
				later(1900, function () {
					gsap.to(out, { opacity: 1, left: '57%', top: '13%', duration: dur + 0.2, ease: 'power2.inOut' })
				})
				later(3200, function () {
					lit('kody')
					gsap.to(back, { opacity: 1, left: '60%', top: '73%', duration: dur + 0.2, ease: 'power2.inOut' })
				})
			}
		}
		if (step > 0) park()
		var target = step === 1 ? out : step === 3 ? back : null
		gsap.killTweensOf(cam)
		var pose = { scale: 1, x: 0, y: 0, transformOrigin: '0 0' }
		if (target && cam.offsetWidth) {
			var scale = Math.min(cam.offsetWidth * 0.94 / target.offsetWidth, cam.offsetHeight * 0.94 / target.offsetHeight)
			var cx = target.offsetLeft
			var cy = target.offsetTop
			pose.scale = scale
			pose.x = cam.offsetWidth / 2 - cx * scale
			pose.y = cam.offsetHeight / 2 - cy * scale
		}
		var fade = o.entering || o.still ? 0 : o.soft ? 0.6 : 0.35
		gsap.to(el.querySelectorAll('.sf-node, .sf-wires'), { opacity: target ? 0 : 1, duration: fade, overwrite: 'auto' })
		if (step > 0) {
			;[ask, out, back].forEach(function (pill) {
				gsap.to(pill, { opacity: !target || pill === target ? 1 : 0, duration: fade, overwrite: 'auto' })
			})
		}
		cam.setAttribute('data-zoom', String(Math.round(pose.scale * 100) / 100))
		if (o.entering || o.still) gsap.set(cam, pose)
		else gsap.to(cam, { scale: pose.scale, x: pose.x, y: pose.y, duration: o.soft ? 0.95 : 0.55, ease: 'power3.inOut', overwrite: 'auto' })
		gsap.to(flow, { opacity: step >= 5 ? 0 : 1, duration: o.entering ? 0 : o.soft ? 0.7 : 0.4, overwrite: 'auto' })
	}
})()