176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: add a migration tool for moving demos to the shared layout
matinf4f9235cb56c
diff --git a/tests/fixtures/legacy-demo.html b/tests/fixtures/legacy-demo.htmlnew file mode 100644index 00000000..60230ca0--- /dev/null+++ b/tests/fixtures/legacy-demo.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <title>Sample Demo — Animation Handbook</title>+ <style>+ @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}+ @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}+ :root{--bg:#0b0b0d;--ui-accent:#5fd88a;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px}+ body{padding:24px}+ </style>+<style id="ah-inject">+.ah-bar{position:fixed}+</style>+</head>+<body>+<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../a/" rel="prev" title="Previous">‹ Prev</a><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button></span></div>+<header>+ <h1>Sample Demo</h1>+ <p>Uses `code` words in its summary.</p>+</header>+<div class="layout">+ <div class="stage"><div class="card" id="card">Card</div></div>+ <aside>+ <p class="note">A technical note that now lives in the README.</p>+ <div><div class="lbl" id="dur-lbl">Duration</div>+ <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="2000" value="600"><span class="sv" id="dur-v">600ms</span></div>+ </div>+ <label class="tog" for="loop-tog"><input type="checkbox" id="loop-tog"><span>Auto-loop</span></label>+ <div class="btn-row">+ <button class="act pri" id="btn-in">Play in</button>+ <button class="act" id="btn-rst">Reset</button>+ </div>+ </aside>+</div>+<script>+ document.getElementById('btn-in').addEventListener('click',()=>{});+</script>+<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;})();</script>+</body>+</html>diff --git a/tests/migrate.test.js b/tests/migrate.test.jsnew file mode 100644index 00000000..9c85596b--- /dev/null+++ b/tests/migrate.test.js@@ -0,0 +1,72 @@+// Tests for tools/migrate-demo.js. Run from the repo root: node --test "tests/*.test.js"+const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const path = require('node:path');+const { migrate } = require('../tools/migrate-demo.js');++const legacy = fs.readFileSync(path.join(__dirname, 'fixtures', 'legacy-demo.html'), 'utf8');+const cfg = { category: '02-entrance-and-exit', name: 'Entrance & Exit' };+const demo = {+ slug: 'sample-demo', number: '02.12',+ prev: { href: '../flip-in/', name: 'Flip In' }, next: null,+ autoplay: true,+ attrs: { 'btn-in': 'data-hb-replay', 'btn-rst': 'data-hb-reset', 'loop-tog': 'data-hb-skip data-hb-loop' },+ edits: [['<span>Auto-loop</span>', '<span>Loop it</span>']],+ lede: 'Moves a card into view.',+ prompt: 'Add a <b> & [x] prompt.'+};+const out = migrate(legacy, cfg, demo);++test('removes the legacy chrome, fonts and font variables', () => {+ for (const gone of ['ah-inject', 'ah-bar', 'ah-copy', 'Copy source', 'Bricolage', 'PlexMono', '--disp', '--mono', 'class="note"', 'class="layout"', '<header>']) {+ assert.ok(!out.includes(gone), `still contains ${gone}`);+ }+});++test('links the shared stylesheet and script at the end of <head>', () => {+ assert.ok(out.includes('<link rel="stylesheet" href="../../../assets/css/handbook.css">\n<script src="../../../assets/js/handbook.js" defer></script>\n</head>'));+});++test('marks the body and builds the top bar', () => {+ assert.ok(out.includes('<body class="hb" data-hb-autoplay>'));+ assert.ok(out.includes('<a class="hb-home" href="../../../">← <span>Animation Handbook</span></a>'));+ assert.ok(out.includes('<a href="../flip-in/" rel="prev" aria-label="Previous: Flip In">‹ <span class="hb-name">Flip In</span></a>'));+ assert.ok(!out.includes('rel="next"'));+});++test('moves the title into the side column with the number, category and plain lede', () => {+ assert.ok(out.includes('<main class="hb-view">'));+ assert.ok(out.includes('<aside class="hb-side">'));+ assert.ok(out.includes('<p class="hb-cat">02.12 · Entrance & Exit</p>'));+ assert.ok(out.includes('<h1>Sample Demo</h1>'));+ assert.ok(out.includes('<p class="hb-lede">Moves a card into view.</p>'));+ assert.ok(out.includes('<section class="hb-settings" aria-label="Settings">'));+ assert.ok(out.includes('</aside>\n</main>\n'));+});++test('adds the escaped prompt and keeps the controls and demo script', () => {+ assert.ok(out.includes('<p class="hb-prompt">Add a <b> & [x] prompt.</p>'));+ assert.ok(out.includes('id="dur-sl"'));+ assert.ok(out.includes("document.getElementById('btn-in').addEventListener"));+});++test('applies marker attributes and one-off edits', () => {+ assert.ok(out.includes('id="btn-in" data-hb-replay'));+ assert.ok(out.includes('id="btn-rst" data-hb-reset'));+ assert.ok(out.includes('id="loop-tog" data-hb-skip data-hb-loop'));+ assert.ok(out.includes('<span>Loop it</span>'));+});++test('keeps the original lede when none is given', () => {+ const kept = migrate(legacy, cfg, { ...demo, lede: undefined });+ assert.ok(kept.includes('<p class="hb-lede">Uses `code` words in its summary.</p>'));+});++test('refuses edits that do not match exactly once', () => {+ assert.throws(() => migrate(legacy, cfg, { ...demo, edits: [['<span>Nope</span>', 'x']] }), /edit/);+});++test('refuses to migrate a page twice', () => {+ assert.throws(() => migrate(out, cfg, demo), /already migrated/);+});diff --git a/tools/migrate-demo.js b/tools/migrate-demo.jsnew file mode 100644index 00000000..e7ea3f9b--- /dev/null+++ b/tools/migrate-demo.js@@ -0,0 +1,108 @@+#!/usr/bin/env node+// One-time migration of legacy demo pages to the shared demo layout.+// See docs/superpowers/specs/2026-09-25-demo-page-redesign-design.md.+// Usage (repo root): node tools/migrate-demo.js tools/migrations/<category>.json [slug ...]+'use strict';+const fs = require('node:fs');+const path = require('node:path');+const { escapeHtml } = require('../assets/js/handbook.js');++// Replace `find` exactly once; anything else means the page doesn't have the expected shape.+function replaceOnce(html, find, replacement, step) {+ const count = typeof find === 'string'+ ? html.split(find).length - 1+ : (html.match(new RegExp(find.source, find.flags.includes('g') ? find.flags : find.flags + 'g')) || []).length;+ if (count !== 1) throw new Error(`${step}: expected exactly 1 match, found ${count}`);+ return html.replace(find, typeof replacement === 'function' ? replacement : () => replacement);+}++function pagerLink(rel, target) {+ if (!target) return '';+ const label = rel === 'prev' ? 'Previous' : 'Next';+ const name = `<span class="hb-name">${escapeHtml(target.name)}</span>`;+ return `<a href="${target.href}" rel="${rel}" aria-label="${label}: ${escapeHtml(target.name)}">` ++ (rel === 'prev' ? `‹ ${name}` : `${name} ›`) + '</a>';+}++function topBar(demo) {+ return '<nav class="hb-bar" aria-label="Animation Handbook">' ++ '<a class="hb-home" href="../../../">← <span>Animation Handbook</span></a>' ++ `<span class="hb-pager">${pagerLink('prev', demo.prev)}${pagerLink('next', demo.next)}</span></nav>`;+}++function migrate(html, cfg, demo) {+ if (html.includes('class="hb-view"')) throw new Error('already migrated');+ let out = html.replace(/\r\n/g, '\n');++ // Legacy top bar styles, font files and font variables.+ out = replaceOnce(out, /\n<style id="ah-inject">[\s\S]*?<\/style>/, '', 'ah-inject style');+ const fontFace = /^[ \t]*@font-face\{font-family:'(?:Bricolage|PlexMono)'[^\n]*\n/gm;+ if (!fontFace.test(out)) throw new Error('font-face lines: none found');+ out = out.replace(fontFace, '');+ out = replaceOnce(out, /--disp:[^;}]*;?/, '', '--disp variable');+ out = replaceOnce(out, /--mono:[^;}]*;?/, '', '--mono variable');++ // Shared assets, body marker and the new top bar.+ out = replaceOnce(out, '</head>',+ '<link rel="stylesheet" href="../../../assets/css/handbook.css">\n' ++ '<script src="../../../assets/js/handbook.js" defer></script>\n</head>', '</head>');+ out = replaceOnce(out, '<body>', `<body class="hb"${demo.autoplay ? ' data-hb-autoplay' : ''}>`, '<body>');+ out = replaceOnce(out, /<div class="ah-bar"[^\n]*<\/div>\n/, topBar(demo) + '\n', 'ah-bar');+ out = replaceOnce(out, /\n<script>\(function\(\)\{var b=document\.getElementById\("ah-copy"\)[^\n]*<\/script>/, '', 'copy-source script');++ // The header moves into the side column; the note moves out (its content lives in the README).+ let title = '';+ let lede = '';+ out = replaceOnce(out, /<header>\s*<h1>([\s\S]*?)<\/h1>\s*<p>([\s\S]*?)<\/p>\s*<\/header>\n/,+ (m, h, p) => { title = h.trim(); lede = p.trim(); return ''; }, 'header');+ if (demo.lede) lede = escapeHtml(demo.lede);+ const head =+ ' <header class="hb-head">\n' ++ ` <p class="hb-cat">${demo.number} · ${escapeHtml(cfg.name)}</p>\n` ++ ` <h1>${title}</h1>\n` ++ ` <p class="hb-lede">${lede}</p>\n` ++ ' </header>\n' ++ ' <section class="hb-settings" aria-label="Settings">\n' ++ ' <h2 class="hb-label">Settings</h2>\n';+ out = replaceOnce(out, '<div class="layout">', '<main class="hb-view">', 'layout wrapper');+ out = replaceOnce(out, /(\n[ \t]*)<aside>\n/, (m, indent) => `${indent}<aside class="hb-side">\n${head}`, 'aside open');+ out = replaceOnce(out, /\n[ \t]*<p class="note">[\s\S]*?<\/p>/, '', 'note');+ const take =+ ' </section>\n' ++ ' <div class="hb-take">\n' ++ ' <section class="hb-prompt-box" aria-labelledby="hb-prompt-title">\n' ++ ' <h2 class="hb-label" id="hb-prompt-title">Prompt</h2>\n' ++ ` <p class="hb-prompt">${escapeHtml(demo.prompt)}</p>\n` ++ ' </section>\n' ++ ' </div>\n';+ out = replaceOnce(out, /([ \t]*)<\/aside>\n<\/div>\n/, (m, indent) => `${take}${indent}</aside>\n</main>\n`, 'aside close');++ // Markers the shared script looks for, then one-off edits.+ for (const [id, attrs] of Object.entries(demo.attrs || {})) {+ out = replaceOnce(out, `id="${id}"`, `id="${id}" ${attrs}`, `attrs for #${id}`);+ }+ for (const [find, replacement] of demo.edits || []) {+ out = replaceOnce(out, find, replacement, `edit "${find.slice(0, 40)}"`);+ }+ return out;+}++function main(argv) {+ const [configPath, ...only] = argv;+ if (!configPath) {+ console.error('Usage: node tools/migrate-demo.js <config.json> [slug ...]');+ process.exit(2);+ }+ const cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));+ const demos = cfg.demos.filter(d => !only.length || only.includes(d.slug));+ if (only.length && demos.length !== only.length) throw new Error(`unknown slug in: ${only.join(', ')}`);+ const root = path.resolve(__dirname, '..');+ for (const demo of demos) {+ const file = path.join(root, 'animations', cfg.category, demo.slug, 'index.html');+ fs.writeFileSync(file, migrate(fs.readFileSync(file, 'utf8'), cfg, demo));+ console.log('migrated', path.relative(root, file));+ }+}++if (require.main === module) main(process.argv.slice(2));+module.exports = { migrate, topBar, replaceOnce };