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: the finder's questions, draft answers for every card and the matching that ranks them, with tests that run the page's own code
matin6773990ee381
diff --git a/index.html b/index.htmlindex 53e8a558..ed551d4b 100644--- a/index.html+++ b/index.html@@ -1991,6 +1991,227 @@ const PLACES={'light-rays':['bg','intro'],'game-of-life':['bg']};+// Draft answers for the finder, from each card's first place and its category: the reviewed answers replace them.+const FIND={+ // 01+ 'parallax-depth-of-field':['card','scroll','slide'],+ 'parallax-scrolling':['card','scroll','slide'],+ 'reverse-scrolling-columns':['card','scroll','slide'],+ 'cover-card-to-fixed-header':['card','scroll','slide'],+ 'fly-in-fly-out-contact-list':['card','scroll','slide'],+ 'stacking-cards':['card','scroll','slide'],+ 'scroll-trigger':['card','scroll','slide'],+ 'scrub-animation':['card','scroll','slide'],+ 'pin-animation':['card','scroll','slide'],+ 'snap-scrolling':['card','scroll','slide'],+ 'scrollytelling':['card','scroll','slide'],+ 'reveal-on-scroll':['card','scroll','slide'],+ 'stagger-reveal':['card','scroll','slide'],+ 'horizontal-scroll':['card','scroll','slide'],+ 'sticky-section':['card','scroll','slide'],+ 'counter-animation':['card','scroll','slide'],+ 'progress-bar':['card','scroll','slide'],+ 'section-wipe':['card','scroll','slide'],+ 'zoom-into-image':['card','scroll','slide'],+ 'scroll-image-sequence':['card','scroll','slide'],+ 'smooth-scroll':['card','scroll','slide'],+ 'text-fill-on-scroll':['card','scroll','slide'],+ 'scroll-velocity-skew':['card','scroll','slide'],+ 'svg-line-draw':['card','scroll','slide'],+ 'scrollspy-nav':['card','scroll','slide'],+ 'scroll-background-color':['card','scroll','slide'],+ 'hide-on-scroll-header':['menu','scroll','slide'],+ // 02+ 'fade-in-out':['card','load','fade'],+ 'slide-in':['card','load','fade'],+ 'slide-up-reveal':['card','load','fade'],+ 'scale-in':['card','load','fade'],+ 'clip-path-reveal':['card','load','fade'],+ 'curtain-reveal':['card','load','fade'],+ 'split-text-reveal':['card','load','fade'],+ 'letter-by-letter-stagger':['card','load','fade'],+ 'word-by-word-reveal':['card','load','fade'],+ 'blur-in':['card','load','fade'],+ 'flip-in':['card','load','fade'],+ 'bounce-in':['card','load','fade'],+ 'rotate-in':['card','load','fade'],+ 'shatter-effect':['card','load','fade'],+ // 03+ 'view-transitions-api':['page','newpage','slide'],+ 'shared-element-transition':['page','newpage','slide'],+ 'morph-transition':['page','newpage','slide'],+ 'crossfade':['page','newpage','slide'],+ 'slide-transition':['page','newpage','slide'],+ 'zoom-transition':['page','newpage','slide'],+ 'flash-transition':['page','newpage','slide'],+ 'blur-transition':['page','newpage','slide'],+ 'elastic-transition':['page','newpage','slide'],+ 'portal-zoom':['page','newpage','slide'],+ 'dissolve':['page','newpage','slide'],+ 'flip-technique':['page','newpage','slide'],+ 'circle-reveal':['page','newpage','slide'],+ 'overlay-wipe':['page','newpage','slide'],+ 'page-curl':['page','newpage','slide'],+ 'cube-transition':['page','newpage','slide'],+ // 04+ 'hover-state':['button','click','grow'],+ 'click-ripple':['button','click','grow'],+ 'focus-ring':['menu','click','grow'],+ 'button-press-scale':['button','click','grow'],+ 'magnetic-button':['button','click','grow'],+ 'toggle-switch':['button','click','grow'],+ 'heart-burst':['button','click','grow'],+ 'success-confetti':['button','click','grow'],+ 'skeleton-loader':['loader','click','grow'],+ 'shimmer-effect':['loader','click','grow'],+ 'loading-spinner':['loader','click','grow'],+ 'progress-animation':['loader','click','grow'],+ 'checkmark-draw':['loader','click','grow'],+ 'form-field-morph':['menu','click','grow'],+ 'badge-pulse':['loader','click','grow'],+ 'tooltip-reveal':['button','click','grow'],+ 'drawer-slide':['menu','click','grow'],+ 'modal-expand':['card','click','grow'],+ 'accordion':['menu','click','grow'],+ 'cursor-follower':['background','click','grow'],+ 'error-shake':['menu','click','grow'],+ 'swipe-to-dismiss':['card','click','grow'],+ 'hamburger-menu-toggle':['menu','click','grow'],+ 'theme-toggle-morph':['button','click','grow'],+ 'copy-to-clipboard':['button','click','grow'],+ 'star-rating':['menu','click','grow'],+ 'toast-notification':['loader','click','grow'],+ 'segmented-control':['menu','click','grow'],+ 'pull-to-refresh':['loader','click','grow'],+ 'gradient-border':['button','click','grow'],+ 'spotlight-hover':['card','click','grow'],+ 'add-to-cart-fly':['button','click','grow'],+ 'drag-to-reorder':['menu','click','grow'],+ 'rolling-numbers':['text','click','grow'],+ 'typing-indicator':['loader','click','grow'],+ 'hold-to-confirm':['button','click','grow'],+ 'expanding-search':['menu','click','grow'],+ 'button-loading-states':['button','click','grow'],+ 'image-trail':['card','click','grow'],+ 'gooey-menu':['menu','click','grow'],+ 'dynamic-island':['loader','click','grow'],+ // 05+ 'kinetic-typography':['text','load','stagger'],+ 'typewriter-effect':['text','load','stagger'],+ 'scramble-text':['text','load','stagger'],+ 'variable-font-morph':['text','load','stagger'],+ 'text-clip-path-reveal':['text','load','stagger'],+ 'marquee-ticker':['text','load','stagger'],+ 'text-morphing':['text','load','stagger'],+ 'text-gradient-animation':['text','load','stagger'],+ 'outline-to-fill':['text','load','stagger'],+ 'enter-exit-typography':['text','load','stagger'],+ 'rotate-word-carousel':['text','load','stagger'],+ 'glitch-text':['text','load','stagger'],+ 'text-on-path':['text','load','stagger'],+ 'wavy-text':['text','load','stagger'],+ 'highlighter-sweep':['text','load','stagger'],+ 'split-flap-board':['text','load','stagger'],+ 'neon-flicker':['text','load','stagger'],+ 'handwriting-draw':['text','load','stagger'],+ 'text-particles':['text','load','stagger'],+ // 06+ '3d-model-orbit':['card','loop','turn'],+ 'scroll-driven-3d-rotation':['card','loop','turn'],+ 'parallax-3d-tilt':['card','loop','turn'],+ 'canvas-particle-effect':['background','loop','turn'],+ 'fluid-simulation':['background','loop','turn'],+ 'glassmorphism-animated':['card','loop','turn'],+ 'webgl-shader-animation':['background','loop','turn'],+ 'noise-based-motion':['background','loop','turn'],+ 'svg-path-animation':['card','loop','turn'],+ 'chromatic-aberration':['text','loop','turn'],+ '2-5d-pseudo-3d':['card','loop','turn'],+ 'ray-marching-sdf':['background','loop','turn'],+ 'gpgpu-particle-system':['background','loop','turn'],+ 'image-distortion-hover':['card','loop','turn'],+ 'cloth-simulation':['card','loop','turn'],+ 'volumetric-smoke':['background','loop','turn'],+ 'morphing-blob':['background','loop','turn'],+ 'flip-card-3d':['card','loop','turn'],+ 'carousel-3d':['card','loop','turn'],+ 'depth-map-photo':['card','loop','turn'],+ 'flocking':['background','loop','turn'],+ 'ascii-halftone':['card','loop','turn'],+ 'physics-2d':['card','loop','turn'],+ 'liquid-glass':['card','loop','turn'],+ 'holographic-card':['card','loop','turn'],+ 'infinite-zoom':['card','loop','turn'],+ // 07+ 'animated-gradient-background':['background','loop','drift'],+ 'mesh-gradient':['background','loop','drift'],+ 'aurora':['background','loop','drift'],+ 'grain-overlay':['background','loop','drift'],+ 'scanline':['background','loop','drift'],+ 'light-leak':['background','loop','drift'],+ 'starfield':['background','loop','drift'],+ 'breathing-glow':['background','loop','drift'],+ 'ambient-ripple':['background','loop','drift'],+ 'floating-elements':['background','loop','drift'],+ 'grid-dot-pattern-parallax':['background','loop','drift'],+ 'abstract-geometric-motion':['background','loop','drift'],+ 'particle-constellation':['background','loop','drift'],+ 'flow-field':['background','loop','drift'],+ 'synthwave-grid':['background','loop','drift'],+ 'matrix-rain':['background','loop','drift'],+ 'plasma':['background','loop','drift'],+ 'wave-layers':['background','loop','drift'],+ 'snow-rain':['background','loop','drift'],+ 'fireworks':['background','loop','drift'],+ 'topographic-lines':['background','loop','drift'],+ 'light-rays':['background','loop','drift'],+ 'game-of-life':['background','loop','drift']+};+// The finder's three questions in order (spec, section 2): each answer's key (in the address and in FIND), its words (which name+// it) and its picture: a still icon in the site's 24px line style for What and When, the class of a small moving picture for How+// (drawn at the end of the stylesheet). weight is what a question counts for in findScore. Not sure, at the end of each+// question, is no answer.+const FIND_Q=[+ {key:'what',title:'What moved?',weight:2,answers:[+ {key:'text',words:'Text or numbers',icon:'<path d="M5 7V4h14v3M12 4v16M9 20h6"/>'},+ {key:'card',words:'A picture or card',icon:'<rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="15.5" cy="9.5" r="1.5"/><path d="m3 16 5-5 4 4 3-3 6 6"/>'},+ {key:'button',words:'A button or icon',icon:'<rect x="3" y="7" width="18" height="10" rx="5"/><path d="M9 12h6"/>'},+ {key:'menu',words:'A menu or form',icon:'<path d="M4 6h16M4 12h16M4 18h10"/>'},+ {key:'loader',words:'A loading sign or message',icon:'<path d="M12 3a9 9 0 1 0 9 9"/>'},+ {key:'shape',words:'A line or shape',icon:'<circle cx="7.5" cy="7.5" r="3.5"/><path d="m13 20 4-7 4 7z"/><path d="M3 20 9 14"/>'},+ {key:'particles',words:'Dots or particles',icon:'<circle cx="6" cy="7" r="1.5" fill="currentColor"/><circle cx="17" cy="5" r="1.5" fill="currentColor"/><circle cx="12" cy="12" r="1.5" fill="currentColor"/><circle cx="5" cy="18" r="1.5" fill="currentColor"/><circle cx="18" cy="17" r="1.5" fill="currentColor"/>'},+ {key:'background',words:'The background',icon:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m3 12 8-8M3 20 19 4M11 20l10-10"/>'},+ {key:'page',words:'The whole page',icon:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 9h18M6.5 6.5h.01M9.5 6.5h.01"/>'}+ ]},+ {key:'when',title:'When did it move?',weight:1,answers:[+ {key:'scroll',words:'When I scrolled',icon:'<rect x="7" y="3" width="10" height="18" rx="5"/><path d="M12 7v4"/>'},+ {key:'hover',words:'When I pointed at it',icon:'<path d="m5 3 14 7-6 2-2 6z"/>'},+ {key:'click',words:'When I clicked or tapped',icon:'<path d="m9 9 11 4.5-4.5 1.5-1.5 4.5z"/><path d="m4 4 2 2M9 3v2M3 9h2"/>'},+ {key:'drag',words:'When I dragged or swiped',icon:'<path d="M3 12h18M7 8l-4 4 4 4M17 8l4 4-4 4"/>'},+ {key:'load',words:'When the page opened',icon:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 9h18M12 12v5M9.5 14.5h5"/>'},+ {key:'newpage',words:'When I went to another page',icon:'<rect x="3" y="5" width="10" height="14" rx="1.5"/><path d="M15 12h6M18 9l3 3-3 3"/>'},+ {key:'loop',words:'By itself, again and again',icon:'<path d="M20 12a8 8 0 1 1-2.3-5.7"/><path d="M20 4v5h-5"/>'}+ ]},+ {key:'how',title:'How did it move?',hint:'Pick the picture closest to what you saw.',weight:3,answers:[+ {key:'fade',words:'Faded or blurred',pic:'fd-fade'},+ {key:'slide',words:'Slid',pic:'fd-slide'},+ {key:'grow',words:'Grew or shrank',pic:'fd-grow'},+ {key:'turn',words:'Turned or flipped',pic:'fd-turn'},+ {key:'bounce',words:'Bounced or shook',pic:'fd-bounce'},+ {key:'stagger',words:'One after another',pic:'fd-stagger'},+ {key:'pieces',words:'Broke into pieces',pic:'fd-pieces'},+ {key:'follow',words:'Followed my pointer',pic:'fd-follow'},+ {key:'color',words:'Changed color or glowed',pic:'fd-color'},+ {key:'morph',words:'Changed into something else',pic:'fd-morph'},+ {key:'draw',words:'Drew or typed itself',pic:'fd-draw'},+ {key:'reveal',words:'Got uncovered',pic:'fd-reveal'},+ {key:'layers',words:'Moved in layers',pic:'fd-layers'},+ {key:'pin',words:'Stayed in place while I scrolled',pic:'fd-pin'},+ {key:'drift',words:'Drifted or floated',pic:'fd-drift'},+ {key:'wave',words:'Rippled or waved',pic:'fd-wave'},+ {key:'glitch',words:'Glitched or flickered',pic:'fd-glitch'}+ ]}+];// The eight cards of "Good places to start", in this order.const PICKS=['click-ripple','typewriter-effect','flip-card-3d','aurora','hamburger-menu-toggle','loading-spinner','parallax-scrolling','slide-up-reveal'];@@ -2413,6 +2634,48 @@ function search(text){if(!words.length)return [];return ALL.map(e=>({e,...score(e,words)})).filter(x=>x.s>0).sort((a,b)=>b.s-a.s||b.own-a.own||a.e.order-b.e.order).map(x=>x.e);}+// ---------- The finder's matching ----------+// The finder's part of an address: ?view=find, then what, when and how for each question answered (nothing, Not sure or an+// unknown key leaves the question out).+function findQuery(answers){+ return '?view=find'+FIND_Q.map(q=>q.answers.some(a=>a.key===answers[q.key])?'&'+q.key+'='+answers[q.key]:'').join('');+}+// The answers in words, Not sure for a question left out: "Text or numbers · When I scrolled · Drew or typed itself".+function findWords(answers){+ return FIND_Q.map(q=>{const a=q.answers.find(x=>x.key===answers[q.key]);return a?a.words:'Not sure';}).join(' · ');+}+// How one card fits the answers: for each question answered, the card's main (first) answer earns twice the question's weight+// (How 3, What 2, When 1), another of its answers once, and no answer of it is a miss. size counts all the card's answers.+function findScore(slug,answers){+ const lists=(FIND[slug]||['','','']).map(s=>s.split(' ').filter(Boolean));+ let points=0,misses=0;+ FIND_Q.forEach((q,i)=>{+ if(!q.answers.some(a=>a.key===answers[q.key]))return;+ const at=lists[i].indexOf(answers[q.key]);+ if(at<0)misses++;else points+=(at?1:2)*q.weight;+ });+ return {points,misses,size:lists.reduce((n,l)=>n+l.length,0)};+}+// The finder's matches as {best, close}; it never touches the page. Best fits every answer; Close misses exactly one, and only+// when two or more questions are answered. Each is ordered by points, then fewer answers in all (a card made for just this comes+// first), then home order. Nothing answered, or only Not sure: no cards.+function findMatches(answers){+ const asked=FIND_Q.filter(q=>q.answers.some(a=>a.key===answers[q.key])).length,best=[],close=[];+ if(!asked)return {best,close};+ for(const e of ALL){+ const s=findScore(e.slug,answers);+ if(!s.misses)best.push({e,...s});else if(s.misses===1&&asked>1)close.push({e,...s});+ }+ const order=(a,b)=>b.points-a.points||a.size-b.size||a.e.order-b.e.order;+ return {best:best.sort(order).map(x=>x.e),close:close.sort(order).map(x=>x.e)};+}+// The Not here? link: GitHub's form animation_not_here.yml with its title and its answers field filled in (GitHub fills an issue+// form's field from the address by its id): the answers in words, then the finder's live address with them. Nothing personal.+function findIssueURL(answers){+ const words=findWords(answers);+ return 'https://github.com/matinmonshizadeh/animation-handbook/issues/new?template=animation_not_here.yml&title='+encodeURIComponent('[not here] '+words)++ '&answers='+encodeURIComponent(words+' — https://matinmonshizadeh.github.io/animation-handbook/'+findQuery(answers));+}// All animations: a plain section per group, headed by an h3 (a section with no name adds no landmark). The card titles are// h3 too, so here they are set a level below the group headings; showCards() takes that away again.function showGroups(){diff --git a/tests/finder.test.js b/tests/finder.test.jsnew file mode 100644index 00000000..a1de9e66--- /dev/null+++ b/tests/finder.test.js@@ -0,0 +1,181 @@+// Static checks for the Animation finder on the home page (index.html): its questions (FIND_Q), each card's answers (FIND), the+// matching (findMatches), the finder's markup and pictures, the Not here? link and its GitHub form, and the finder's test set.+// The page's own code is read with vm, as tests/pages.test.js reads the search. 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 vm = require('node:vm');++const ROOT = path.resolve(__dirname, '..');+const read = f => fs.readFileSync(f, 'utf8');+const count = (s, sub) => s.split(sub).length - 1;+// The part of s from the first `from` up to the next `to` after it ('' when `from` is missing), as in tests/pages.test.js.+const between = (s, from, to) => {+ const start = s.indexOf(from);+ if (start < 0) return '';+ const end = s.indexOf(to, start + from.length);+ return s.slice(start, end < 0 ? undefined : end);+};+// A value made in a vm context, copied into plain arrays and objects that deepEqual accepts.+const plain = v => JSON.parse(JSON.stringify(v));+const HOME = read(path.join(ROOT, 'index.html'));++// As in tests/pages.test.js: where the bracket that opens at HOME[from] ('[' or '{') is closed, stepping over strings and //+// comments, and the value of `const NAME=` in the home page's script, read with vm.+function blockEnd(from) {+ const open = HOME[from], close = open === '[' ? ']' : '}';+ let depth = 0, i = from, quote = null;+ for (; i < HOME.length; i++) {+ const ch = HOME[i];+ if (quote) { if (ch === '\\') i++; else if (ch === quote) quote = null; continue; }+ if (ch === '/' && HOME[i + 1] === '/') { while (i < HOME.length && HOME[i] !== '\n') i++; continue; }+ if (ch === "'" || ch === '"' || ch === '`') quote = ch;+ else if (ch === open) depth++;+ else if (ch === close && --depth === 0) break;+ }+ return i;+}+function homeConst(name) {+ const start = HOME.indexOf(`const ${name}=`);+ assert.ok(start >= 0, `const ${name} in index.html`);+ const from = start + `const ${name}=`.length;+ return plain(vm.runInNewContext('(' + HOME.slice(from, blockEnd(from) + 1) + ')'));+}+const at = marker => { const i = HOME.indexOf(marker); assert.ok(i >= 0, `${marker} in index.html`); return i; };+const source = name => { const start = at(`function ${name}(`); return HOME.slice(start, blockEnd(HOME.indexOf('{', start)) + 1); };+// The finder as the page runs it: the cards in home order, built by the page's own code from PLACE_LIST up to BY_SLUG (as the+// search tests build them), with FIND_Q, FIND and the finder's functions in one context. `data` adds to the context or replaces+// CATS, PLACES or FIND with test data.+function finder(data = {}) {+ const context = vm.createContext({ CATS: homeConst('CATS'), PLACES: homeConst('PLACES'), FIND_Q: homeConst('FIND_Q'), FIND: homeConst('FIND'), ...data });+ vm.runInContext(HOME.slice(at('const PLACE_LIST=['), at('const BY_SLUG=')), context);+ for (const name of ['findQuery', 'findWords', 'findScore', 'findMatches', 'findIssueURL']) vm.runInContext(source(name), context);+ return context;+}+// The finder over test cards, one group in this order: each [slug, what, when, how], the answers written as FIND writes them.+function cards(rows) {+ const CATS = [{ name: 'Test', cat: 'c1-cat', dot: '#000000', n: '01', desc: 'Test cards.', folder: 'animations/01-test',+ entries: rows.map(([slug]) => [slug, slug, 'A test card. Best for tests.']) }];+ return finder({ CATS, PLACES: Object.fromEntries(rows.map(([slug]) => [slug, ['btn']])), FIND: Object.fromEntries(rows.map(([slug, ...answers]) => [slug, answers])) });+}+const slugs = list => Array.from(list, e => e.slug);++// ── The questions, the answers and the matching ──++const QUESTIONS = [+ ['what', 'What moved?', 2, [['text', 'Text or numbers'], ['card', 'A picture or card'], ['button', 'A button or icon'], ['menu', 'A menu or form'],+ ['loader', 'A loading sign or message'], ['shape', 'A line or shape'], ['particles', 'Dots or particles'], ['background', 'The background'],+ ['page', 'The whole page']]],+ ['when', 'When did it move?', 1, [['scroll', 'When I scrolled'], ['hover', 'When I pointed at it'], ['click', 'When I clicked or tapped'],+ ['drag', 'When I dragged or swiped'], ['load', 'When the page opened'], ['newpage', 'When I went to another page'], ['loop', 'By itself, again and again']]],+ ['how', 'How did it move?', 3, [['fade', 'Faded or blurred'], ['slide', 'Slid'], ['grow', 'Grew or shrank'], ['turn', 'Turned or flipped'],+ ['bounce', 'Bounced or shook'], ['stagger', 'One after another'], ['pieces', 'Broke into pieces'], ['follow', 'Followed my pointer'],+ ['color', 'Changed color or glowed'], ['morph', 'Changed into something else'], ['draw', 'Drew or typed itself'], ['reveal', 'Got uncovered'],+ ['layers', 'Moved in layers'], ['pin', 'Stayed in place while I scrolled'], ['drift', 'Drifted or floated'], ['wave', 'Rippled or waved'],+ ['glitch', 'Glitched or flickered']]]+];++test('FIND_Q holds the three questions in order, with the answers of the spec in their exact words', () => {+ const questions = homeConst('FIND_Q');+ assert.deepEqual(questions.map(q => [q.key, q.title, q.weight, q.answers.map(a => [a.key, a.words])]), QUESTIONS);+ assert.equal(questions[2].hint, 'Pick the picture closest to what you saw.');+ for (const q of questions.slice(0, 2)) {+ for (const a of q.answers) assert.match(a.icon || '', /^(<(path|rect|circle) [^<>]*\/>)+$/, `${a.key}: a still icon in the site's line style`);+ }+ for (const a of questions[2].answers) assert.equal(a.pic, `fd-${a.key}`, `${a.key}: the class of its moving picture`);+});++test('FIND lists every card once, in home order, with 1–3 What, 1–3 When and 1–4 How answers, all known, none twice', () => {+ const find = homeConst('FIND'), questions = homeConst('FIND_Q');+ const all = homeConst('CATS').flatMap(cat => cat.entries.map(e => e[0]));+ assert.deepEqual(Object.keys(find), all, 'FIND lists every card once, in home order');+ const problems = [];+ for (const slug of all) {+ const row = find[slug];+ if (!Array.isArray(row) || row.length !== 3) { problems.push(`${slug}: not three lists`); continue; }+ questions.forEach((q, i) => {+ const keys = String(row[i]).split(' '), most = q.key === 'how' ? 4 : 3;+ if (keys.length > most) problems.push(`${slug}: ${keys.length} ${q.key} answers, at most ${most}`);+ for (const key of keys) if (!q.answers.some(a => a.key === key)) problems.push(`${slug}: "${key}" is not a ${q.key} answer`);+ if (new Set(keys).size !== keys.length) problems.push(`${slug}: a ${q.key} answer twice`);+ });+ }+ assert.deepEqual(problems, []);+});++test('FIND sits right after PLACES', () => {+ const end = blockEnd(HOME.indexOf('{', at('const PLACES='))) + 1;+ assert.match(HOME.slice(end, at('const FIND=')), /^;\s*(\/\/[^\n]*\n\s*)*$/, 'only a comment line between PLACES and FIND');+});++test("a card's points: its main answer earns twice the question's weight, another answer once (the spec's example)", () => {+ const page = cards([['letters', 'text', 'load scroll', 'stagger fade'], ['typewriter', 'text', 'load loop', 'draw stagger'], ['fade', 'card text', 'load scroll click', 'fade']]);+ const answers = { what: 'text', when: 'load', how: 'stagger' };+ assert.deepEqual(plain(page.findScore('letters', answers)), { points: 12, misses: 0, size: 5 });+ assert.deepEqual(plain(page.findScore('typewriter', answers)), { points: 9, misses: 0, size: 5 });+ assert.deepEqual(plain(page.findScore('fade', answers)), { points: 4, misses: 1, size: 6 });+ const found = page.findMatches(answers);+ assert.deepEqual([slugs(found.best), slugs(found.close)], [['letters', 'typewriter'], ['fade']]);+});++test('no answer, or only Not sure, gives no cards, and an unknown key counts as Not sure', () => {+ const page = cards([['a', 'text', 'load', 'fade'], ['b', 'card', 'load', 'fade']]);+ for (const answers of [{}, { what: '', when: '', how: '' }, { what: 'unsure', when: 'unsure', how: 'unsure' }, { what: 'zebra' }]) {+ assert.deepEqual(plain(page.findMatches(answers)), { best: [], close: [] }, JSON.stringify(answers));+ }+ assert.deepEqual(plain(page.findMatches({ what: 'zebra', when: 'unsure', how: 'fade' })), plain(page.findMatches({ how: 'fade' })));+});++test('Best has no miss; Close has exactly one, and only when two or more questions are answered', () => {+ const page = cards([['a', 'text', 'load', 'fade'], ['b', 'card', 'load', 'fade'], ['c', 'card', 'scroll', 'slide']]);+ let found = page.findMatches({ what: 'text' });+ assert.deepEqual([slugs(found.best), slugs(found.close)], [['a'], []], 'one question answered: no Close matches');+ found = page.findMatches({ what: 'text', how: 'fade' });+ assert.deepEqual([slugs(found.best), slugs(found.close)], [['a'], ['b']], 'b misses What only, c misses both');+ found = page.findMatches({ what: 'text', when: 'load', how: 'fade' });+ assert.deepEqual([slugs(found.best), slugs(found.close)], [['a'], ['b']], 'c misses all three');+});++test('a main answer counts double', () => {+ const page = cards([['side', 'card text', 'load', 'fade'], ['main', 'text card', 'load', 'fade']]);+ assert.deepEqual(slugs(page.findMatches({ what: 'text' }).best), ['main', 'side']);+});++test('weights How 3, What 2, When 1: with the rest equal, a card missing When ranks above one missing What, above one missing How', () => {+ const page = cards([['no-how', 'text', 'load', 'slide'], ['no-what', 'card', 'load', 'fade'], ['no-when', 'text', 'scroll', 'fade']]);+ const found = page.findMatches({ what: 'text', when: 'load', how: 'fade' });+ assert.deepEqual([slugs(found.best), slugs(found.close)], [[], ['no-when', 'no-what', 'no-how']]);+});++test('ties go to fewer answers in all, then home order', () => {+ const page = cards([['many', 'text', 'load scroll', 'fade'], ['first', 'text', 'load', 'fade'], ['second', 'text', 'load', 'fade']]);+ assert.deepEqual(slugs(page.findMatches({ what: 'text', when: 'load', how: 'fade' }).best), ['first', 'second', 'many']);+});++test('the finder part of an address and the answers in words', () => {+ const page = finder();+ assert.equal(page.findQuery({ what: 'text', when: 'scroll', how: 'draw' }), '?view=find&what=text&when=scroll&how=draw');+ assert.equal(page.findQuery({ what: 'unsure', when: 'zebra', how: 'draw' }), '?view=find&how=draw');+ assert.equal(page.findQuery({}), '?view=find');+ assert.equal(page.findWords({ what: 'text', when: 'unsure', how: 'draw' }), 'Text or numbers · Not sure · Drew or typed itself');+});++test('the Not here? address opens the form animation_not_here.yml with its title and its answers field filled in', () => {+ const url = new URL(finder().findIssueURL({ what: 'text', when: 'scroll', how: 'draw' }));+ assert.equal(url.origin + url.pathname, 'https://github.com/matinmonshizadeh/animation-handbook/issues/new');+ assert.deepEqual([...url.searchParams.keys()], ['template', 'title', 'answers']);+ assert.equal(url.searchParams.get('template'), 'animation_not_here.yml');+ assert.equal(url.searchParams.get('title'), '[not here] Text or numbers · When I scrolled · Drew or typed itself');+ assert.equal(url.searchParams.get('answers'),+ 'Text or numbers · When I scrolled · Drew or typed itself — https://matinmonshizadeh.github.io/animation-handbook/?view=find&what=text&when=scroll&how=draw');+});++// ── The pictures of the How answers ──+// Each How answer moves in a small picture of its own, and reduced motion holds every picture still.++// ── The finder view, its ways in and Not here? ──+// The finder's markup and address, the Find button and the Finder link, and the Not here? panel with its GitHub form.++// ── Every card's answers and the test set ──+// The reviewed answers: every answer given to some card, the rules every page of a kind shares, and the spec's 28 described effects.