Skip to content

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.

feat: tools/make-famous.mjs copies the home page's previews (their rules, keyframes and markup) into two marked blocks of the Famous effects page, with tests on a stand-in home page

matin446abb68b10c
diff --git a/tests/famous.test.js b/tests/famous.test.js
new file mode 100644
index 00000000..28a05928
--- /dev/null
+++ b/tests/famous.test.js
@@ -0,0 +1,96 @@
+// Checks the Famous effects page (famous/index.html) and the tool that writes its previews (tools/make-famous.mjs), from
+// docs/superpowers/specs/2026-10-13-famous-effects-design.md: first the tool on a small stand-in home page, then the page.
+// 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 { pathToFileURL } = require('node:url');
+
+const ROOT = path.resolve(__dirname, '..');
+const TOOL = 'node tools/make-famous.mjs';
+const tool = () => import(pathToFileURL(path.join(ROOT, 'tools', 'make-famous.mjs')).href);
+
+// ---------- The tool, on a stand-in home page ----------
+// What the tool reads, in small: the accent classes and the base preview rules; a comment that holds a brace and a rule; a
+// @property; a preview with a data URI that holds url(…); a rule shared with a preview the page does not show; a preview whose
+// key only starts like a shown one; keyframes used and unused; a phone rule beside another page's rule; the reduced-motion
+// rule; and CATS, PV, pvMarkup(), engines and STILL.
+const FIXTURE_HOME = `<style>
+:root{--c1:#6ea8ff}
+.c1{--accent:var(--c1)}.c2{--accent:var(--c2)}.c3{--accent:var(--c3)}.c4{--accent:var(--c4)}.c5{--accent:var(--c5)}.c6{--accent:var(--c6)}.c7{--accent:var(--c7)}
+.pv{position:absolute;inset:0}
+/* a comment with a brace { and a rule .pv-aaa{color:red} inside */
+.pv *{will-change:transform}
+.card:not(.playing) .pv .anim,.card:not(.playing) .pv .anim::before,.card:not(.playing) .pv .anim::after{animation-play-state:paused!important}
+@property --p{syntax:'<percentage>';inherits:false;initial-value:0%}
+.pv-aaa{background:url("data:image/svg+xml,%3Csvg filter='url(%23m)'%3E")}
+.pv-aaa .x{animation:spin-a 2s linear infinite;--p:10%}
+.pv-aaab{background:#111}
+.pv-bbb,.pv-zzz{color:red}
+@keyframes spin-a{to{transform:rotate(360deg)}}
+@keyframes unused{to{opacity:0}}
+@media(max-width:600px){.pv-aaa .x{width:5px}.other{color:blue}}
+@media(prefers-reduced-motion:reduce){
+ .pv .anim,.pv .anim::before,.pv .anim::after{animation-play-state:paused!important}
+}
+</style>
+<script>
+const CATS=[{name:'One',cat:'c1-cat',n:'01',folder:'animations/01-one',entries:[['first','First','Line one.'],['second','Second','Line two.'],['third','Third','Line three.'],['fourth','Fourth','Line four.']]}];
+const PV={'first':'aaa','second':'bbb','third':'ccc'};
+function pvMarkup(k){
+ switch(k){
+ case 'aaa': return '<span class="x anim"></span>';
+ case 'bbb': return '<b class="anim">B</b>';
+ case 'ccc': return '';
+ default: return '';
+ }
+}
+const engines={ccc:pv=>make(pv,1,true)};
+const STILL={bbb:.7};
+</script>`;
+
+test('make-famous: the CSS block holds the base rules and, for each preview shown, its rules, its keyframes and the @property it uses', async () => {
+ const { previewBlocks } = await tool();
+ const lines = previewBlocks(FIXTURE_HOME, ['first', 'second']).css.split('\n');
+ for (const line of ['.c1{--accent:var(--c1)}', '.c7{--accent:var(--c7)}', '.pv{position:absolute;inset:0}', '.pv *{will-change:transform}',
+ '.card:not(.playing) .pv .anim,.card:not(.playing) .pv .anim::before,.card:not(.playing) .pv .anim::after{animation-play-state:paused!important}',
+ '@media(prefers-reduced-motion:reduce){.pv .anim,.pv .anim::before,.pv .anim::after{animation-play-state:paused!important}}',
+ "@property --p{syntax:'<percentage>';inherits:false;initial-value:0%}",
+ `.pv-aaa{background:url("data:image/svg+xml,%3Csvg filter='url(%23m)'%3E")}`, '.pv-aaa .x{animation:spin-a 2s linear infinite;--p:10%}',
+ '@keyframes spin-a{to{transform:rotate(360deg)}}', '@media(max-width:600px){.pv-aaa .x{width:5px}}', '.pv-bbb{color:red}']) {
+ assert.ok(lines.includes(line), `the CSS block has the line ${line}`);
+ }
+ const css = lines.join('\n');
+ for (const absent of ['.pv-aaab', '.pv-zzz', 'unused', '.other', '.pv-aaa{color:red}']) assert.ok(!css.includes(absent), `no ${absent}`);
+});
+
+test('make-famous: the PREVIEWS block gives each card once, in page order, with its preview key, still point and markup', async () => {
+ const { previewBlocks } = await tool();
+ assert.equal(previewBlocks(FIXTURE_HOME, ['first', 'second', 'first']).data, ['const PREVIEWS={',
+ '"first":{"pv":"aaa","still":0.5,"markup":"<span class=\\"x anim\\"><\\/span>"},',
+ '"second":{"pv":"bbb","still":0.7,"markup":"<b class=\\"anim\\">B<\\/b>"}',
+ '};'].join('\n'));
+ assert.equal(previewBlocks(FIXTURE_HOME, []).data, 'const PREVIEWS={\n};', 'no cards, an empty object');
+});
+
+test('make-famous: a card that is not on the home page, or whose preview needs a script or has no markup, stops the tool', async () => {
+ const { previewBlocks } = await tool();
+ assert.throws(() => previewBlocks(FIXTURE_HOME, ['third']), /needs a script engine/);
+ assert.throws(() => previewBlocks(FIXTURE_HOME, ['fourth']), /has no markup/);
+ assert.throws(() => previewBlocks(FIXTURE_HOME, ['nowhere']), /not a card on the home page/);
+});
+
+test('make-famous: the blocks go between their marker lines, a second run changes nothing, and a missing or doubled marker stops it', async () => {
+ const { buildFamousFrom, replaceBetween, CSS_START, CSS_END, JS_START, JS_END } = await tool();
+ const page = ['<style>', 'body{margin:0}', CSS_START, 'old css', CSS_END, '</style>', '<article class="card c1" data-slug="second">',
+ '<script>', JS_START, 'const PREVIEWS={};', JS_END, 'go();', '</script>'].join('\n');
+ const once = buildFamousFrom(FIXTURE_HOME, page);
+ assert.equal(buildFamousFrom(FIXTURE_HOME, once), once, 'a second run changes nothing');
+ assert.ok(once.includes(`${CSS_START}\n/* the base`), 'the CSS starts right after its first marker');
+ assert.ok(once.includes(`.pv-bbb{color:red}\n${CSS_END}`), 'and ends right before its last');
+ assert.ok(once.includes(`${JS_START}\nconst PREVIEWS={\n"second":`) && once.includes(`};\n${JS_END}\ngo();`), 'the data between its markers');
+ assert.ok(!once.includes('old css'), 'what was between the markers is gone');
+ assert.throws(() => replaceBetween('no markers here', CSS_START, CSS_END, 'x'), /must each be there once/);
+ assert.throws(() => replaceBetween(CSS_START + CSS_END + CSS_START, CSS_START, CSS_END, 'x'), /must each be there once/);
+});
diff --git a/tools/make-famous.mjs b/tools/make-famous.mjs
new file mode 100644
index 00000000..bafb1d7e
--- /dev/null
+++ b/tools/make-famous.mjs
@@ -0,0 +1,227 @@
+#!/usr/bin/env node
+// Writes the previews of the Famous effects page (famous/index.html) from the home page: a development tool, not part of the
+// site (docs/superpowers/specs/2026-10-13-famous-effects-design.md, section 4).
+// Run it from the repo root after changing the page's cards, or a preview they show on the home page: its key in PV, its case
+// in pvMarkup(), its rules or keyframes, or its STILL point. tests/famous.test.js fails until then.
+// Usage: node tools/make-famous.mjs
+// It reads the cards of famous/index.html (data-slug on <article class="card cN">, in page order) and, from index.html,
+// CATS, PV, STILL, pvMarkup() and engines (the previews a script draws, which this page has no room for) from its script,
+// and from its style the base preview rules (BASE below), every rule that names a preview the page shows (.pv-<key>, inside
+// @media too, keeping only the parts of a shared selector that name it), the @keyframes those rules and the preview's
+// markup name, and the @property rules they use. It rewrites the text between the two marker lines of each block in
+// famous/index.html: the CSS (CSS_START … CSS_END) and the PREVIEWS object (JS_START … JS_END), which gives each card its
+// preview key, markup and still point. It keeps the page's line endings, writes only when the text changed and prints what
+// it wrote; running it twice changes nothing. buildFamous(root), exported for the test, returns
+// { 'famous/index.html': text } with LF line endings and writes nothing.
+// Exit code 1 when a card is not on the home page, its preview needs a script, has no markup or animates in SVG, a base rule
+// or a preview's rules cannot be found, or a marker line is missing or written twice.
+import { existsSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import vm from 'node:vm';
+
+export const CSS_START = '/* ── previews: written by tools/make-famous.mjs from the home page; run it again, never edit by hand ── */';
+export const CSS_END = '/* ── end of previews ── */';
+export const JS_START = '// ── previews: written by tools/make-famous.mjs from the home page; run it again, never edit by hand ──';
+export const JS_END = '// ── end of previews ──';
+// The home page's rules every preview needs: each category's accent color, the preview box, and its animations paused unless
+// its card plays; and, under reduced motion, paused always.
+const BASE = ['.c1', '.c2', '.c3', '.c4', '.c5', '.c6', '.c7', '.pv', '.pv *',
+ '.card:not(.playing) .pv .anim,.card:not(.playing) .pv .anim::before,.card:not(.playing) .pv .anim::after'];
+const BASE_REDUCED = '.pv .anim,.pv .anim::before,.pv .anim::after';
+const REDUCED = '@media(prefers-reduced-motion:reduce)';
+
+// Where the bracket that opens at text[from] ('[' or '{') is closed, stepping over strings and // comments (as the tests
+// read the home page).
+function blockEnd(text, from) {
+ const open = text[from], close = open === '[' ? ']' : '}';
+ let depth = 0, i = from, quote = null;
+ for (; i < text.length; i++) {
+ const ch = text[i];
+ if (quote) { if (ch === '\\') i++; else if (ch === quote) quote = null; continue; }
+ if (ch === '/' && text[i + 1] === '/') { while (i < text.length && text[i] !== '\n') i++; continue; }
+ if (ch === "'" || ch === '"' || ch === '`') quote = ch;
+ else if (ch === open) depth++;
+ else if (ch === close && --depth === 0) break;
+ }
+ return i;
+}
+// The value of `const NAME=` in the home page's script: an array or object literal of plain data, read with vm.
+export function homeConst(home, name) {
+ const start = home.indexOf(`const ${name}=`);
+ if (start < 0) throw new Error(`index.html has no const ${name}=`);
+ const from = start + `const ${name}=`.length;
+ return vm.runInNewContext('(' + home.slice(from, blockEnd(home, from) + 1) + ')');
+}
+// A function of the home page's script, `function NAME(…){…}`, read with vm (pvMarkup uses no page state).
+function homeFunction(home, name) {
+ const start = home.indexOf(`function ${name}(`);
+ if (start < 0) throw new Error(`index.html has no function ${name}(`);
+ return vm.runInNewContext('(' + home.slice(start, blockEnd(home, home.indexOf('{', start)) + 1) + ')');
+}
+// The previews the home page draws with a script (its engines object): their keys, before each ":" at the top level.
+function engineKeys(home) {
+ const start = home.indexOf('const engines={');
+ if (start < 0) throw new Error('index.html has no const engines={');
+ const from = start + 'const engines='.length, keys = [];
+ let depth = 0, part = '';
+ for (const ch of home.slice(from + 1, blockEnd(home, from)) + ',') {
+ if ('({['.includes(ch)) depth++;
+ else if (')}]'.includes(ch)) depth--;
+ if (ch === ',' && depth === 0) { keys.push(part.split(':')[0].trim()); part = ''; } else part += ch;
+ }
+ return keys.filter(Boolean);
+}
+// The style without its comments; a comment mark inside a string (a data URI) does not count.
+function stripComments(css) {
+ let out = '', quote = null;
+ for (let i = 0; i < css.length; i++) {
+ const ch = css[i];
+ if (quote) { out += ch; if (ch === '\\') out += css[++i] ?? ''; else if (ch === quote) quote = null; continue; }
+ if (ch === '"' || ch === "'") { quote = ch; out += ch; continue; }
+ if (ch === '/' && css[i + 1] === '*') { const end = css.indexOf('*/', i + 2); i = end < 0 ? css.length : end + 1; continue; }
+ out += ch;
+ }
+ return out;
+}
+// Where the next of the characters in stops is, outside strings (css.length when there is none).
+function next(css, from, stops) {
+ let quote = null;
+ for (let i = from; i < css.length; i++) {
+ const ch = css[i];
+ if (quote) { if (ch === '\\') i++; else if (ch === quote) quote = null; continue; }
+ if (ch === '"' || ch === "'") quote = ch;
+ else if (stops.includes(ch)) return i;
+ }
+ return css.length;
+}
+const squeeze = s => s.replace(/\s*\n\s*/g, ' ').trim();
+// A style (comments already gone) as its top-level items: { kind: 'rule', selector, body } or { kind: 'at', name, head, inner,
+// items }, where items are the rules inside an @media or @supports block.
+function parseCss(css) {
+ const items = [];
+ for (let i = 0; i < css.length;) {
+ const open = next(css, i, '{;}');
+ if (open >= css.length) break;
+ const head = css.slice(i, open).trim().replace(/\s+/g, ' ');
+ if (css[open] !== '{') { i = open + 1; continue; }
+ let depth = 1, j = open + 1;
+ while (depth) {
+ j = next(css, j, '{}');
+ if (j >= css.length) throw new Error(`index.html: the style is not closed after "${head}"`);
+ depth += css[j] === '{' ? 1 : -1;
+ j++;
+ }
+ const inner = css.slice(open + 1, j - 1);
+ if (head.startsWith('@')) {
+ const name = head.slice(1).match(/^[\w-]+/)[0];
+ items.push({ kind: 'at', name, head, inner: squeeze(inner), items: name === 'media' || name === 'supports' ? parseCss(inner) : [] });
+ } else items.push({ kind: 'rule', selector: head, body: squeeze(inner) });
+ i = j;
+ }
+ return items;
+}
+// The parts of a selector list, split at its top-level commas.
+function parts(selector) {
+ const out = [];
+ let depth = 0, part = '';
+ for (const ch of selector + ',') {
+ if (ch === '(' || ch === '[') depth++;
+ else if (ch === ')' || ch === ']') depth--;
+ if (ch === ',' && depth === 0) { out.push(part.trim()); part = ''; } else part += ch;
+ }
+ return out;
+}
+// The parts of a selector list that name the preview key (".pv-mesh", not ".pv-meshy"), joined again; '' when none does.
+const picked = (selector, key) => parts(selector).filter(p => new RegExp(`\\.pv-${key}(?![\\w-])`).test(p)).join(',');
+
+// The two blocks for the cards with these slugs (in page order): { css, data }.
+export function previewBlocks(home, slugs) {
+ const CATS = homeConst(home, 'CATS'), PV = homeConst(home, 'PV'), STILL = homeConst(home, 'STILL');
+ const pvMarkup = homeFunction(home, 'pvMarkup'), engines = engineKeys(home);
+ const previews = [];
+ for (const slug of new Set(slugs)) {
+ const cat = CATS.find(c => c.entries.some(e => e[0] === slug));
+ if (!cat) throw new Error(`famous/index.html: ${slug} is not a card on the home page`);
+ const pv = PV[slug] || 'sig' + parseInt(cat.n, 10);
+ if (engines.includes(pv)) throw new Error(`famous/index.html: ${slug} shows the preview ${pv}, which needs a script engine this page does not have`);
+ const markup = pvMarkup(pv);
+ if (!markup) throw new Error(`famous/index.html: ${slug} shows the preview ${pv}, which has no markup`);
+ if (/<animate\b/.test(markup)) throw new Error(`famous/index.html: ${slug} shows the preview ${pv}, which animates in SVG (the home page takes that out under reduced motion; this page does not)`);
+ previews.push({ slug, pv, still: STILL[pv] ?? 0.5, markup, name: cat.entries.find(e => e[0] === slug)[1] });
+ }
+ const items = parseCss(stripComments([...home.matchAll(/<style>([\s\S]*?)<\/style>/g)].map(m => m[1]).join('\n')));
+ const one = (list, selector, where) => {
+ const found = list.filter(it => it.kind === 'rule' && it.selector === selector);
+ if (found.length !== 1) throw new Error(`index.html: ${found.length} rules for ${selector}${where}, not 1`);
+ return `${selector}{${found[0].body}}`;
+ };
+ const named = name => items.filter(it => it.kind === 'at' && it.name === name).map(it => ({ id: it.head.split(' ')[1], text: `${it.head}{${it.inner}}` }));
+ const keyframes = named('keyframes'), properties = named('property');
+ const reduced = items.filter(it => it.kind === 'at' && it.head.replace(/\s+/g, '') === REDUCED).flatMap(it => it.items);
+ // Each preview: a comment naming it, its rules (inside @media too, only the parts of the selector that name it), and the
+ // keyframes that its rules or its markup name.
+ const drawn = [...new Set(previews.map(p => p.pv))].map(key => {
+ const own = [];
+ for (const it of items) {
+ if (it.kind === 'rule') { const sel = picked(it.selector, key); if (sel) own.push(`${sel}{${it.body}}`); }
+ else if (it.name === 'media' || it.name === 'supports') {
+ const inner = it.items.filter(r => r.kind === 'rule' && picked(r.selector, key)).map(r => `${picked(r.selector, key)}{${r.body}}`);
+ if (inner.length) own.push(`${it.head}{${inner.join('')}}`);
+ }
+ }
+ if (!own.length) throw new Error(`index.html: no rule draws the preview ${key}`);
+ const words = new Set((own.join(' ') + ' ' + previews.find(p => p.pv === key).markup).split(/[\s,:;(){}"'=]+/));
+ const who = previews.filter(p => p.pv === key).map(p => p.name).join(', ');
+ return [`/* ${key}: ${who} */`, ...own, ...keyframes.filter(k => words.has(k.id)).map(k => k.text)];
+ });
+ const all = drawn.flat().join('\n') + previews.map(p => p.markup).join('\n');
+ const css = ["/* the base: each category's accent color, the preview box, and its animations paused unless its card plays */",
+ ...BASE.map(selector => one(items, selector, '')),
+ `${REDUCED}{${one(reduced, BASE_REDUCED, ' under reduced motion')}}`,
+ ...properties.filter(p => new RegExp(`${p.id}(?![\\w-])`).test(all)).map(p => p.text),
+ ...drawn.flat()].join('\n');
+ const data = ['const PREVIEWS={',
+ ...previews.map((p, i) => JSON.stringify(p.slug) + ':' + JSON.stringify({ pv: p.pv, still: p.still, markup: p.markup }).replace(/<\//g, '<\\/') + (i < previews.length - 1 ? ',' : '')),
+ '};'].join('\n');
+ return { css, data };
+}
+
+// The text with what lies between the start and end marker lines replaced by inner (each marker there once, in that order).
+export function replaceBetween(text, start, end, inner) {
+ const a = text.indexOf(start), b = a < 0 ? -1 : text.indexOf(end, a + start.length);
+ if (a < 0 || b < 0 || text.indexOf(start, a + start.length) >= 0) throw new Error(`famous/index.html: the lines "${start}" and "${end}" must each be there once, in that order`);
+ return text.slice(0, a + start.length) + '\n' + inner + '\n' + text.slice(b);
+}
+// The slugs of the page's cards, in page order.
+export const cardSlugs = page => [...page.matchAll(/<article class="card c[1-7]" data-slug="([a-z0-9-]+)">/g)].map(m => m[1]);
+// The page with both blocks written from the home page.
+export function buildFamousFrom(home, page) {
+ const { css, data } = previewBlocks(home, cardSlugs(page));
+ return replaceBetween(replaceBetween(page, CSS_START, CSS_END, css), JS_START, JS_END, data);
+}
+export function buildFamous(root) {
+ const file = join(root, 'famous', 'index.html');
+ if (!existsSync(file)) throw new Error('famous/index.html is missing');
+ const home = readFileSync(join(root, 'index.html'), 'utf8').replace(/\r\n/g, '\n');
+ return { 'famous/index.html': buildFamousFrom(home, readFileSync(file, 'utf8').replace(/\r\n/g, '\n')) };
+}
+
+// Run as a command, not imported by the test. The command's path is compared with its real path, so a run through a junction
+// or a link counts too.
+const self = (() => { try { return realpathSync(process.argv[1]); } catch { return ''; } })();
+if (self.toLowerCase() === fileURLToPath(import.meta.url).toLowerCase()) {
+ const ROOT = fileURLToPath(new URL('..', import.meta.url));
+ try {
+ const file = join(ROOT, 'famous', 'index.html');
+ const text = buildFamous(ROOT)['famous/index.html'];
+ const old = readFileSync(file, 'utf8');
+ const out = old.includes('\r\n') ? text.replace(/\n/g, '\r\n') : text;
+ if (out !== old) writeFileSync(file, out);
+ const previews = (text.match(/^"[a-z0-9-]+":\{"pv":/gm) || []).length;
+ console.log(`famous/index.html: ${cardSlugs(text).length} cards, ${previews} previews${out === old ? '' : ' (written)'}`);
+ } catch (err) {
+ console.error(err.message);
+ process.exitCode = 1;
+ }
+}