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
Merge branch 'feat/home-views' into int/home
matinc5659de76fe4
diff --cc index.htmlindex c4e6c51d,9a5d4780..f3ee77dd--- a/index.html+++ b/index.html@@@ -1736,68 -1865,6 +1867,66 @@@ if(startCat){const g=$('cat-'+startCat)(function(){const btn=$('theme-toggle');if(!btn)return;btn.addEventListener('click',()=>{const next=document.documentElement.dataset.theme==='light'?'dark':'light';document.documentElement.dataset.theme=next;try{localStorage.setItem('ah-theme',next);}catch(e){}});})();- addEventListener('keydown',e=>{const t=document.activeElement&&document.activeElement.tagName;- if(e.key==='/'&&t!=='INPUT'&&t!=='TEXTAREA'){e.preventDefault();$('q').focus();}});++// ---------- Copy prompt on the cards ----------+// The text is the page's own: the home page reads the page's HTML and builds the text with the shared page script+// (DemoPage), every setting at its default. Nothing on a fetched page is laid out, so no control counts as hidden by style.+const pageTexts=new Map(),NO_STYLE={getComputedStyle:()=>({display:''})};+function promptFor(url){+ let text=pageTexts.get(url);+ if(!text){+ text=fetch(url).then(r=>{if(!r.ok)throw new Error('HTTP '+r.status);return r.text();}).then(html=>{+ if(!window.DemoPage)throw new Error('the page script has not loaded');+ const t=DemoPage.pageCopyText(new DOMParser().parseFromString(html,'text/html'),NO_STYLE);+ if(!t)throw new Error('no prompt on the page');+ return t;+ });+ text.catch(()=>pageTexts.delete(url));+ pageTexts.set(url,text);+ }+ return text;+}+// Safari only writes the clipboard while the press is fresh, so the text goes in as a promise where the browser allows it.+async function writeClipboard(text){+ const clip=navigator.clipboard;+ if(!clip)throw new Error('no clipboard');+ if(window.ClipboardItem&&clip.write){+ try{await clip.write([new ClipboardItem({'text/plain':text.then(t=>new Blob([t],{type:'text/plain'}))})]);return;}+ catch(err){if(err&&err.name==='NotAllowedError')throw err;}+ }+ await clip.writeText(await text);+}+const toastEl=$('toast');let toastTimer=0;+function toast(message){+ toastEl.querySelector('.toast-t').textContent=message;+ toastEl.classList.add('show');+ clearTimeout(toastTimer);toastTimer=setTimeout(()=>toastEl.classList.remove('show'),2400);+}+function copyState(btn,kind){+ const name=btn.closest('.card').querySelector('.title a').textContent;+ clearTimeout(btn._timer);+ btn.classList.toggle('done',kind==='done');btn.classList.toggle('fail',kind==='fail');+ if(kind==='done'){+ btn.innerHTML=ICON_DONE+'<span class="copy-l">Copied</span>';btn.setAttribute('aria-label','Prompt copied for '+name);+ btn._timer=setTimeout(()=>copyState(btn,''),1800);+ }else if(kind==='fail'){+ btn.innerHTML=ICON_OPEN+'<span class="copy-l">Open to copy</span>';btn.setAttribute('aria-label','Open the page to copy the prompt for '+name);+ }else{+ btn.innerHTML=ICON_COPY+'<span class="copy-l">Copy prompt</span>';btn.setAttribute('aria-label','Copy prompt for '+name);+ }+}+const urlOf=card=>card.querySelector('.title a').getAttribute('href');+cardsBox.addEventListener('click',e=>{+ const btn=e.target.closest('.copy');+ if(!btn)return;+ const url=urlOf(btn.closest('.card'));+ if(btn.classList.contains('fail')){location.href=url+'#hb-prompt-title';return;}+ writeClipboard(promptFor(url)).then(()=>{copyState(btn,'done');toast('Prompt copied. Paste it into your AI assistant.');},()=>copyState(btn,'fail'));+});+// Reading the page starts when the pointer rests on a card or a card gets focus, so the copy is quick.+const warm=e=>{const card=e.target.closest&&e.target.closest('.card');if(card)promptFor(urlOf(card)).catch(()=>{});};+cardsBox.addEventListener('pointerover',warm);+cardsBox.addEventListener('focusin',warm);</script></body></html>diff --cc tools/check-pages.mjsindex e23accbb,b90b9e51..1e4fb7db--- a/tools/check-pages.mjs+++ b/tools/check-pages.mjs@@@ -434,36 -434,132 +434,162 @@@ async function scrollProblems(reduced)return problems;}+// Home page, desktop run: the Copy prompt button puts a page's text on the clipboard and says so (the clipboard is stubbed:+// a headless run cannot grant it), then, for every page, the home page's text equals what the page's own Copy prompt gives+// before any change. Leaves the home page.+async function homeCopyProblems() {+ const problems = [];+ const wiring = await evaluate(`(async () => {+ let got = null;+ navigator.clipboard.write = async items => { got = await (await items[0].getType('text/plain')).text(); };+ navigator.clipboard.writeText = async text => { got = text; };+ const btn = document.querySelector('#cards .card .copy');+ btn.click();+ for (let i = 0; i < 60 && got === null; i++) await new Promise(r => setTimeout(r, 50));+ await new Promise(r => setTimeout(r, 50));+ const url = btn.closest('.card').querySelector('.title a').getAttribute('href');+ return { same: got === await promptFor(url), label: btn.textContent.trim(), toast: document.getElementById('toast').classList.contains('show') };+ })()`);+ if (!wiring.same || wiring.label !== 'Copied' || !wiring.toast) problems.push(`Copy prompt button: ${JSON.stringify(wiring)}`);+ const items = await evaluate(`Promise.all(ALL.map(e => promptFor(e.url).then(text => ({ url: e.url, text }), err => ({ url: e.url, text: 'ERROR ' + err.message }))))`);+ for (const { url, text } of items) {+ let onLoad;+ const loaded = new Promise(resolve => { onLoad = msg => { if (msg.method === 'Page.loadEventFired') resolve(); }; listeners.add(onLoad); });+ await send('Page.navigate', { url: `${BASE}/${url}` });+ try { await withTimeout(loaded, LOAD_TIMEOUT); } catch { problems.push(`${url} did not load`); }+ listeners.delete(onLoad);+ const own = await evaluate(`DemoPage.pageCopyText(document, window)`);+ if (own !== text) problems.push(`Copy prompt text differs for ${url}`);+ }+ return problems;+}++ // Home page, desktop run: a tile press shows that place and changes the address, Show all shows the rest, Back returns to+ // the start, a plain sentence finds the right animations, a word with no match says so, All animations lists every card+ // under its seven headings, and the old ?q= and ?cat= links still work. Keyboard focus is not dropped or left behind when a+ // pressed button hides or the page scrolls away: Show all puts it on the first new card; Clear, a suggestion in the+ // Nothing-found panel and Browse all (the button and the link) put it on the results heading. Leaves the home page on+ // ?cat=micro-interactions.+ async function homeViewProblems() {+ const problems = [];+ const view = () => evaluate(`({ title: document.getElementById('results-title').textContent, cards: document.querySelectorAll('#cards .card').length,+ more: document.getElementById('more').hidden ? '' : document.getElementById('more-label').textContent, search: location.search })`);+ const type = text => evaluate(`(() => { const q = document.getElementById('q'); q.value = ${JSON.stringify(text)}; q.dispatchEvent(new Event('input', { bubbles: true })); })()`);+ // Where keyboard focus is: an id, "card link N" for a card's title link, or the tag name.+ const focused = () => evaluate(`(() => { const a = document.activeElement, links = [...document.querySelectorAll('#cards .card .title a')];+ return a.id || (links.includes(a) ? 'card link ' + (links.indexOf(a) + 1) : a.tagName.toLowerCase()); })()`);+ // A press as the keyboard makes it: the control has focus, then it is activated.+ const press = selector => evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); el.focus(); el.click(); })()`);+ await evaluate(`document.querySelector('.place[data-place="btn"]').click()`);+ await sleep(300);+ let v = await view();+ if (v.title !== 'Buttons' || v.cards !== 8 || v.more !== 'Show all 15' || v.search !== '?place=buttons') problems.push(`Buttons tile: ${JSON.stringify(v)}`);+ await press('#more-btn');+ await sleep(300);+ v = await view();+ if (v.cards !== 15 || v.more !== '' || v.search !== '?place=buttons&all=1') problems.push(`Show all: ${JSON.stringify(v)}`);+ let on = await focused();+ if (on !== 'card link 9') problems.push(`Show all: keyboard focus is on ${on}, not on the ninth card's link`);+ await evaluate(`history.back()`);+ await sleep(500);+ v = await view();+ if (v.title !== 'Good places to start' || v.cards !== 8 || v.search !== '') problems.push(`Back: ${JSON.stringify(v)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(300);+ await press('#clear-view');+ await sleep(300);+ v = await view();+ on = await focused();+ if (v.title !== 'Good places to start' || v.cards !== 8 || on !== 'results-title') problems.push(`Clear: ${JSON.stringify(v)}, keyboard focus is on ${on}`);+ await type('a button that bounces when clicked');+ await sleep(300);+ const found = await evaluate(`[...document.querySelectorAll('#cards .card .title a')].map(a => a.textContent)`);+ if (found[0] !== 'Click / Tap Ripple' || !found.slice(0, 4).includes('Bounce In')) problems.push(`search order: ${found.slice(0, 5).join(', ')}`);+ await type('zebra');+ await sleep(300);+ const empty = await evaluate(`!document.getElementById('empty').hidden && document.getElementById('empty-title').textContent`);+ if (empty !== 'Nothing matches “zebra” yet') problems.push(`nothing found: ${empty}`);+ await press('#empty [data-q]');+ await sleep(300);+ v = await view();+ on = await focused();+ if (!v.title.startsWith('Results for') || v.cards === 0 || on !== 'results-title') problems.push(`Nothing-found suggestion: ${JSON.stringify(v)}, keyboard focus is on ${on}`);+ await type('zebra');+ await sleep(300);+ await press('#more-btn');+ await sleep(500);+ v = await view();+ on = await focused();+ if (v.title !== 'All animations' || on !== 'results-title') problems.push(`Browse all button: ${JSON.stringify(v)}, keyboard focus is on ${on}`);+ await press('#nav-all');+ await sleep(500);+ const all = await evaluate(`({ groups: document.querySelectorAll('#cards .group').length, cards: document.querySelectorAll('#cards .card').length, search: location.search })`);+ if (all.groups !== 7 || all.cards !== 129 || all.search !== '?view=all') problems.push(`All animations: ${JSON.stringify(all)}`);+ on = await focused();+ if (on !== 'results-title') problems.push(`Browse all link: keyboard focus is on ${on}, not on the results heading`);+ // Old links keep working: ?q= opens the search, ?cat= opens All animations at that category's heading.+ for (const [query, want] of [['?q=fade', 'Results for “fade”'], ['?cat=micro-interactions', 'All animations']]) {+ let onLoad;+ const loaded = new Promise(resolve => { onLoad = msg => { if (msg.method === 'Page.loadEventFired') resolve(); }; listeners.add(onLoad); });+ await send('Page.navigate', { url: `${BASE}/${query}` });+ try { await withTimeout(loaded, LOAD_TIMEOUT); } catch { problems.push(`${query} did not load`); }+ listeners.delete(onLoad);+ await sleep(300);+ const got = await evaluate(`({ title: document.getElementById('results-title').textContent,+ top: (() => { const g = document.getElementById('cat-micro-interactions'); return g ? Math.round(g.getBoundingClientRect().top) : null; })() })`);+ if (got.title !== want) problems.push(`${query}: heading "${got.title}"`);+ if (query.startsWith('?cat=') && (got.top === null || Math.abs(got.top - 12) > 24)) problems.push(`${query}: the category heading is at ${got.top}px, not at the top`);+ }+ return problems;+ }++ // Home page, phone run: a tile press scrolls to the results, and the slim bar sticks to the top with that place pressed.+ // Emptying the bar's own search box keeps the bar, and the focus in the box, until the box is left. A chip pressed again and+ // the back arrow go away with the bar, so keyboard focus moves to the results heading (the arrow also scrolls to the top).+ async function homePhoneProblems() {+ const now = () => evaluate(`({ title: document.getElementById('results-title').textContent, focus: document.activeElement.id || document.activeElement.tagName.toLowerCase(),+ shown: getComputedStyle(document.getElementById('pinbar')).display !== 'none', scrolled: Math.round(scrollY) })`);+ const press = selector => evaluate(`(() => { const el = document.querySelector(${JSON.stringify(selector)}); el.focus(); el.click(); })()`);+ const typeInBar = text => evaluate(`(() => { const box = document.getElementById('q2'); box.value = ${JSON.stringify(text)}; box.dispatchEvent(new Event('input', { bubbles: true })); })()`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(900);+ const v = await evaluate(`(() => { const bar = document.getElementById('pinbar');+ return { title: document.getElementById('results-title').textContent, shown: getComputedStyle(bar).display !== 'none',+ top: Math.round(bar.getBoundingClientRect().top), pressed: [...bar.querySelectorAll('[aria-pressed="true"]')].map(b => b.textContent) }; })()`);+ const problems = v.title === 'Text' && v.shown && Math.abs(v.top) <= 1 && v.pressed.join() === 'Text' ? [] : [`phone, Text tile: ${JSON.stringify(v)}`];+ // This headless Chrome never has its page in focus, so a script's focus() and blur() send no focus events, and the bar+ // listens for one (leaving its box). The page counts as focused for the rest of this run, as it does for a visitor.+ await send('Emulation.setFocusEmulationEnabled', { enabled: true });+ try {+ await evaluate(`document.getElementById('q2').focus()`);+ await typeInBar('fade');+ await sleep(200);+ await typeInBar('');+ await sleep(200);+ let b = await now();+ if (b.title !== 'Good places to start' || !b.shown || b.focus !== 'q2') problems.push(`phone, search box in the bar emptied: ${JSON.stringify(b)}`);+ await evaluate(`document.getElementById('q2').blur()`);+ await sleep(200);+ b = await now();+ if (b.shown) problems.push(`phone, the bar stays after its emptied search box is left: ${JSON.stringify(b)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(900);+ await press('.pchip[data-place="text"]');+ await sleep(300);+ b = await now();+ if (b.title !== 'Good places to start' || b.shown || b.focus !== 'results-title') problems.push(`phone, pressed chip pressed again: ${JSON.stringify(b)}`);+ await evaluate(`document.querySelector('.place[data-place="text"]').click()`);+ await sleep(900);+ await press('#pin-back');+ await sleep(1300);+ b = await now();+ if (b.title !== 'Good places to start' || b.shown || b.focus !== 'results-title' || b.scrolled > 1) problems.push(`phone, back arrow: ${JSON.stringify(b)}`);+ } finally {+ await send('Emulation.setFocusEmulationEnabled', { enabled: false });+ }+ return problems;+ }+// The end of the run, done once: after the last page, after Ctrl+C and after an error outside the main flow.let cleaning = null;function cleanUp() {@@@ -561,8 -657,8 +687,9 @@@ tryif (result.kind === 'scroll' && (setup.moves || setup.reduce)) problems.push(...await scrollProblems(!!setup.reduce));}if (home) {- // Task 5 and Task 6 add the home page's interaction checks here.+ if (setup.moves) problems.push(...await homeViewProblems());+ if (setup.name === 'phone') problems.push(...await homePhoneProblems());+ if (setup.moves) problems.push(...await homeCopyProblems());}} catch (err) {problems.push(`check failed: ${err.message}`);