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: the chips under Good places to start are the seven groups

matinaf8ce4830227
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72af0c05..107da103 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,7 +35,8 @@ The main steps of Animation Handbook, newest first, with the number of animation
- Famous effects becomes a gallery: each effect opens in a pop-up with our own working version of it, and its address
opens it directly. The page is linked from the home page's top bar too.
- Every card preview on the home page is drawn again in one bright, consistent style, with one color for each category.
-- The home page: a row of place chips under Good places to start, a Famous effects band, and How it works in new words
+- The home page: a row of chips under Good places to start for the seven groups (press one to see that group's
+ animations; its address is `?cat=` and the group's name), a Famous effects band, and How it works in new words
(Pick an animation, See it move, Copy the prompt).
- New README pictures: a wall of six animations, three of them new, and a recording of today's home page.
- The home page's search knows more everyday words: other names for an animation (lightbox, snackbar, navbar, tabs), common
diff --git a/CLAUDE.md b/CLAUDE.md
index a1c92d24..190eb9d8 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -197,6 +197,10 @@ animations need a server: a page shows a README link in place of What it is and
6. 3D & Advanced — WebGL, shaders, particles, 3D transforms (folder: 06-3d-advanced)
7. Ambient & Background — passive looping effects (folder: 07-ambient-background)
+The home page calls them groups and shows the seven as chips under Good places to start (All, then one chip a group, written
+in the page's markup in `CATS` order; a test compares them). A chip shows its group's cards, and the address is `?cat=` and
+the group's name as a slug (`?cat=micro-interactions`).
+
## Distinction: technique vs tool
This handbook catalogs **techniques**, not libraries. GSAP, Framer Motion,
Lottie, Three.js are tools that *implement* techniques. They get mentioned
@@ -355,8 +359,8 @@ Run both before calling a page done. They need Node 22 or later (the `--test` gl
of the page's kind. It skips controls inside `.stage` when it measures touch targets, so check buttons and
handles a demo draws there by hand.
- **Home page:** `node tools/check-pages.mjs --base http://127.0.0.1:<port> home` checks the home page at the same
- six setups (six `ok` lines). Its desktop run also tries the tiles, the search and Show all, and compares
- Copy prompt on the home page with every page's own; its phone run tries a tile and the slim bar, and its
+ six setups (six `ok` lines). Its desktop run also tries the tiles, the group chips, the search and Show all, and compares
+ Copy prompt on the home page with every page's own; its phone run tries a tile, the slim bar and a group chip, and its
reduced-motion run checks that nothing moves. Every setup also opens the finder (`?view=find`): its desktop run works the answers, See N matches,
Start over, Show all, the Not here? link and the ways in, and its reduced-motion run checks that every How picture holds a still.
Run it after changing any page's settings or prompt.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 1a4eefa6..759fcbee 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -305,9 +305,10 @@ control with no label or value is left out and the console warns). It skips cont
The home page has a check of its own:
`node tools/check-pages.mjs --base http://127.0.0.1:<port> home`. It checks the layout at the
-six setups. Its desktop run also tries the tiles, the search and Show all, and compares Copy
-prompt on the home page with every page's own prompt and default settings; its phone run tries
-a tile and the slim bar, and its reduced-motion run checks that nothing moves.
+six setups. Its desktop run also tries the tiles, the group chips, the search and Show all, and
+compares Copy prompt on the home page with every page's own prompt and default settings; its
+phone run tries a tile, the slim bar and a group chip, and its reduced-motion run checks that
+nothing moves.
Every setup also opens the finder (`?view=find`): its desktop run works the answers, See N
matches, Start over, Show all, the Not here? link and the ways in, and its reduced-motion run
checks that every How picture holds a still.
diff --git a/index.html b/index.html
index 821dca52..3ccd3b83 100644
--- a/index.html
+++ b/index.html
@@ -204,11 +204,11 @@ button,input{font:inherit;color:inherit}
.rtitle{font-size:clamp(24px,2.6vw,32px);font-weight:800;letter-spacing:-.02em;line-height:1.1}
.rsub{margin-top:6px;font-size:16px;color:var(--muted)}
.pillbtn{display:inline-flex;align-items:center;gap:8px;min-height:44px;padding:0 18px;border-radius:999px;border:1px solid var(--line);background:var(--surface);font-size:15px;font-weight:600;cursor:pointer}
-/* the place chips under the heading, as in the place tiles: All (Start) and the nine places, each with its tile's color as a dot.
- They show at Start and on a place; a search, the finder and All animations hide them. */
+/* the group chips under the heading: All (Start) and the seven groups, each with its group's color (the deep end of its cards' gradient) as a dot.
+ They show at Start and on a group; a search, a place, the finder and All animations hide them. */
.spots{display:flex;flex-wrap:wrap;gap:6px;margin:-8px 0 24px}
.spot{display:inline-flex;align-items:center;gap:5px;flex:none;min-height:40px;padding:0 11px;border-radius:999px;border:1px solid var(--line);background:var(--surface);font-size:13.5px;font-weight:600;color:var(--ink-2);white-space:nowrap;cursor:pointer}
-.spot i{width:8px;height:8px;flex:none;border-radius:50%;background:var(--pa)}
+.spot i{width:8px;height:8px;flex:none;border-radius:50%;background:var(--g2)}
.spot[aria-pressed="true"]{border-color:var(--ink);background:var(--ink);color:var(--bg)}
@media(hover:hover){.spot:hover{border-color:var(--ink)}}
.grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:24px}
@@ -339,7 +339,7 @@ button,input{font:inherit;color:inherit}
.pchip[aria-pressed="true"]{background:var(--ink);border-color:var(--ink);color:var(--surface)}
.spots{flex-wrap:nowrap;margin:-4px calc(-1 * var(--gut)) 16px;padding:2px var(--gut) 4px;overflow-x:auto;scrollbar-width:none}
.spot{min-width:44px;min-height:44px;justify-content:center}
- .results.filtered .spots{display:none} /* the slim bar at the top holds the places then */
+ .results.filtered .spots{display:none} /* the slim bar at the top is the way around then */
.group{scroll-margin-top:136px}
.rhead{margin-bottom:16px}
.grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
@@ -3195,20 +3195,18 @@ button,input{font:inherit;color:inherit}
</div>
</div>
<div class="rhead">
- <div><h2 class="rtitle" id="results-title" tabindex="-1">Good places to start</h2><p class="rsub" id="results-sub" aria-live="polite">Eight favorites from different places. Type above, or pick a place.</p></div>
+ <div><h2 class="rtitle" id="results-title" tabindex="-1">Good places to start</h2><p class="rsub" id="results-sub" aria-live="polite">Eight favorites from different groups. Type above, or pick a group.</p></div>
<button type="button" class="pillbtn" id="clear-view" hidden><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>Clear</button>
</div>
- <div class="spots" id="spots" role="group" aria-label="Places">
- <button type="button" class="spot" data-place="" aria-pressed="true">All</button>
- <button type="button" class="spot" data-place="btn" aria-pressed="false"><i class="p-btn" aria-hidden="true"></i>Buttons</button>
- <button type="button" class="spot" data-place="text" aria-pressed="false"><i class="p-text" aria-hidden="true"></i>Text</button>
- <button type="button" class="spot" data-place="imgcard" aria-pressed="false"><i class="p-img" aria-hidden="true"></i>Images &amp; cards</button>
- <button type="button" class="spot" data-place="bg" aria-pressed="false"><i class="p-bg" aria-hidden="true"></i>Backgrounds</button>
- <button type="button" class="spot" data-place="menu" aria-pressed="false"><i class="p-menu" aria-hidden="true"></i>Menus &amp; forms</button>
- <button type="button" class="spot" data-place="load" aria-pressed="false"><i class="p-load" aria-hidden="true"></i>Loading &amp; messages</button>
- <button type="button" class="spot" data-place="intro" aria-pressed="false"><i class="p-intro" aria-hidden="true"></i>Page intros</button>
- <button type="button" class="spot" data-place="scroll" aria-pressed="false"><i class="p-scroll" aria-hidden="true"></i>Scrolling</button>
- <button type="button" class="spot" data-place="page" aria-pressed="false"><i class="p-page" aria-hidden="true"></i>Page changes</button>
+ <div class="spots" id="spots" role="group" aria-label="Groups">
+ <button type="button" class="spot" data-cat="" aria-pressed="true">All</button>
+ <button type="button" class="spot" data-cat="scroll-based" aria-pressed="false"><i class="c1" aria-hidden="true"></i>Scroll-Based</button>
+ <button type="button" class="spot" data-cat="entrance-exit" aria-pressed="false"><i class="c2" aria-hidden="true"></i>Entrance &amp; Exit</button>
+ <button type="button" class="spot" data-cat="page-transitions" aria-pressed="false"><i class="c3" aria-hidden="true"></i>Page Transitions</button>
+ <button type="button" class="spot" data-cat="micro-interactions" aria-pressed="false"><i class="c4" aria-hidden="true"></i>Micro-Interactions</button>
+ <button type="button" class="spot" data-cat="text-typography" aria-pressed="false"><i class="c5" aria-hidden="true"></i>Text &amp; Typography</button>
+ <button type="button" class="spot" data-cat="3d-advanced" aria-pressed="false"><i class="c6" aria-hidden="true"></i>3D &amp; Advanced</button>
+ <button type="button" class="spot" data-cat="ambient-background" aria-pressed="false"><i class="c7" aria-hidden="true"></i>Ambient &amp; Background</button>
</div>
<div id="cards"></div>
<div class="empty" id="empty" hidden>
@@ -4688,6 +4686,7 @@ const PLACE_LIST=[
const PLACE=Object.fromEntries(PLACE_LIST.map(p=>[p.key,p]));
const esc=s=>String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
const slugify=x=>x.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'');
+const CAT=Object.fromEntries(CATS.map(c=>[slugify(c.name),c])); // the seven groups by the key their chip and the address (?cat=) use: the name as a slug
const wordsOf=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,' ').trim().split(' ').filter(Boolean);
// Small words that say nothing about an animation, left out of what is typed and of the cards' own words. "best" is one: every
// description ends "Best for …", so it (like "for") would match every card, and a first "b" or "f" would find them all.
@@ -4999,14 +4998,14 @@ function showGroups(){
cardsBox.replaceChildren(...boxes);
place(cards);
}
-const state={q:'',place:'',view:'',all:false,what:'',when:'',how:''};
-const isFiltered=()=>!!(state.q||state.place||state.view);
+const state={q:'',place:'',cat:'',view:'',all:false,what:'',when:'',how:''};
+const isFiltered=()=>!!(state.q||state.place||state.cat||state.view);
const q=$('q'),q2=$('q2'),qClear=$('q-clear'),titleEl=$('results-title'),subEl=$('results-sub'),clearBtn=$('clear-view'),
emptyEl=$('empty'),emptyTitle=$('empty-title'),emptyGh=$('empty-gh'),moreBox=$('more'),moreLabel=$('more-label');
let moreAction='all';
const pinbar=$('pinbar'),spotsEl=$('spots');
-// The phone bar is there while a view other than Start or the finder is open and while its own search box has focus, so emptying the box does not take the box away; never in the finder.
-const syncBar=()=>resultsEl.classList.toggle('filtered',state.view!=='find'&&(isFiltered()||document.activeElement===q2));
+// The phone bar is there while a search, a place or All animations is open and while its own search box has focus, so emptying the box does not take the box away; never in the finder, and not on a group, whose chips stay under the heading.
+const syncBar=()=>resultsEl.classList.toggle('filtered',state.view!=='find'&&(!!(state.q||state.place||state.view)||document.activeElement===q2));
// A pressed button that goes away with the view hands keyboard focus to the results heading. No scrolling: the callers that move the page scroll it themselves.
const toTitle=()=>titleEl.focus({preventScroll:true});
const gone=el=>!el.getClientRects().length;
@@ -5019,12 +5018,14 @@ function render(answered){
sub=list.length===1?'1 animation matches.':list.length+' animations match.';
}else if(state.place){
list=ALL.filter(e=>e.places.includes(state.place));title=PLACE[state.place].name;sub=list.length+' animations';tags=false;
+ }else if(state.cat){
+ list=ALL.filter(e=>e.cat===CAT[state.cat]);title=CAT[state.cat].name;sub=list.length+' animations';
}else if(finding){
found=findMatches(state);title='Your matches';sub=findLine(found);
}else if(state.view==='all'){
title='All animations';sub=ALL.length+' animations in '+CATS.length+' groups.';
}else{
- list=PICKS.map(s=>BY_SLUG[s]);title='Good places to start';sub='Eight favorites from different places. Type above, or pick a place.';
+ list=PICKS.map(s=>BY_SLUG[s]);title='Good places to start';sub='Eight favorites from different groups. Type above, or pick a group.';
}
titleEl.textContent=title;say(sub,finding&&answered);
showFinder(finding,found);
@@ -5032,7 +5033,7 @@ function render(answered){
syncBar();
resultsEl.classList.toggle('no-tags',!tags);
clearBtn.hidden=!filtered||finding;
- spotsEl.hidden=!!(state.q||state.view);
+ spotsEl.hidden=!!(state.q||state.place||state.view);
if(found)showFound(found);else if(list)showCards(state.all||!filtered?list:list.slice(0,PAGE));else showGroups();
const empty=!!list&&!list.length,matched=found?found.best.length+found.close.length:0;
emptyEl.hidden=!empty;
@@ -5042,9 +5043,12 @@ function render(answered){
else if(list&&!state.all&&list.length>PAGE){moreAction='expand';moreLabel.textContent='Show all '+list.length;moreBox.hidden=false;}
else moreBox.hidden=true;
document.querySelectorAll('[data-place]').forEach(b=>b.setAttribute('aria-pressed',String(!state.q&&b.dataset.place===state.place)));
- // The picked chip is scrolled fully into the phone bar's row, clear of the row's edge margin; only the row moves, never the page.
- const chip=pinbar.querySelector('.pchip[aria-pressed="true"]');
- if(chip&&chip.getClientRects().length){
+ // A group's chip is pressed on its group, All at Start (the chips are hidden everywhere else).
+ document.querySelectorAll('[data-cat]').forEach(b=>b.setAttribute('aria-pressed',String(!spotsEl.hidden&&b.dataset.cat===state.cat)));
+ // The picked chip is scrolled fully into its row (a place in the phone bar, a group under the heading), clear of the row's
+ // edge margin; only the row moves, never the page.
+ for(const chip of [pinbar.querySelector('.pchip[aria-pressed="true"]'),spotsEl.querySelector('.spot[aria-pressed="true"]')]){
+ if(!chip||!chip.getClientRects().length)continue;
const row=chip.parentElement,r=row.getBoundingClientRect(),b=chip.getBoundingClientRect(),edge=parseFloat(getComputedStyle(row).paddingLeft)||0;
if(b.left<r.left+edge)row.scrollLeft-=r.left+edge-b.left;
else if(b.right>r.right-edge)row.scrollLeft+=b.right-(r.right-edge);
@@ -5059,26 +5063,29 @@ function writeURL(push){
const p=[];
if(state.q)p.push('q='+encodeURIComponent(state.q));
else if(state.place)p.push('place='+PLACE[state.place].url);
+ else if(state.cat)p.push('cat='+state.cat);
else if(state.view==='find')p.push(findQuery(state).slice(1));
else if(state.view)p.push('view=all');
- if(state.all&&(state.q||state.place||state.view==='find'))p.push('all=1');
+ if(state.all&&(state.q||state.place||state.cat||state.view==='find'))p.push('all=1');
const query=p.length?'?'+p.join('&'):'';
const moved=String(new URLSearchParams(query))!==String(new URLSearchParams(location.search));
try{history[push&&moved?'pushState':'replaceState'](null,'',query||location.pathname);}catch(e){}
}
-// The view the address shows, and the category of an old ?cat= link (to scroll to).
+// The view the address shows. ?cat= names a group (its name as a slug) and opens that group; an old ?cat= link whose name is
+// no group opens All animations, as every ?cat= link once did.
function fromURL(){
const p=new URLSearchParams(location.search),found=PLACE_LIST.find(x=>x.url===p.get('place')),cat=p.get('cat')||'';
- const next={q:(p.get('q')||'').trim(),place:'',view:'',all:p.get('all')==='1',what:'',when:'',how:''};
+ const next={q:(p.get('q')||'').trim(),place:'',cat:'',view:'',all:p.get('all')==='1',what:'',when:'',how:''};
if(!next.q&&found)next.place=found.key;
else if(!next.q&&p.get('view')==='find'){next.view='find';FIND_Q.forEach(qu=>{if(qu.answers.some(a=>a.key===p.get(qu.key)))next[qu.key]=p.get(qu.key);});}
+ else if(!next.q&&Object.prototype.hasOwnProperty.call(CAT,cat))next.cat=cat;
else if(!next.q&&(p.get('view')==='all'||cat))next.view='all';
- return {next,cat};
+ return next;
}
-// Takes the view from the address. Returns the category of an old ?cat= link, to scroll to.
-function readURL(){const {next,cat}=fromURL();Object.assign(state,next);q.value=q2.value=state.q;return cat;}
+// Takes the view from the address.
+function readURL(){Object.assign(state,fromURL());q.value=q2.value=state.q;}
// go() never runs while typing, so both boxes take the new view's words even when one keeps focus (a tap on iOS leaves it there).
-function go(next,push){Object.assign(state,{q:'',place:'',view:'',all:false,what:'',when:'',how:''},next);q.value=q2.value=state.q;render();writeURL(push);}
+function go(next,push){Object.assign(state,{q:'',place:'',cat:'',view:'',all:false,what:'',when:'',how:''},next);q.value=q2.value=state.q;render();writeURL(push);}
const toResults=()=>resultsEl.scrollIntoView({behavior:reduce?'auto':'smooth',block:'start'});
// A picked place or suggestion brings the results into view at every width, unless their heading already shows in the top 60%
// of the window (below the phone bar). When the page scrolls, the heading takes keyboard focus, so focus never stays on a
@@ -5096,12 +5103,19 @@ document.addEventListener('click',e=>{
if(!(state.place&&showResults())&&gone(tile))toTitle();
return;
}
+ const chip=e.target.closest('[data-cat]');
+ if(chip){
+ const key=chip.dataset.cat;
+ go(state.cat===key?{}:{cat:key},true); // the picked group pressed again, and All, go back to Start, where the page is
+ if(state.cat)showResults();
+ return;
+ }
const pick=e.target.closest('[data-q]');
if(pick){go({q:pick.dataset.q},true);if(!showResults()&&gone(pick))toTitle();}
});
function typed(input){
(input===q?q2:q).value=input.value;
- Object.assign(state,{q:input.value.trim(),place:'',view:'',all:false,what:'',when:'',how:''});
+ Object.assign(state,{q:input.value.trim(),place:'',cat:'',view:'',all:false,what:'',when:'',how:''});
render();writeURL(false);
}
q.addEventListener('input',()=>typed(q));
@@ -5128,7 +5142,7 @@ $('nav-all').addEventListener('click',e=>{if(e.button||e.ctrlKey||e.metaKey||e.s
// A view they change can take away the control that had keyboard focus (the ninth card after Show all): the heading gets it,
// the finder's heading in the finder.
addEventListener('popstate',()=>{
- const {next}=fromURL();
+ const next=fromURL();
if(Object.keys(next).every(k=>next[k]===state[k]||next[k]===''&&state[k]==='unsure'))return;
readURL();render();const a=document.activeElement;
if(!a||a===document.body||gone(a)){if(state.view==='find')findTitle.focus({preventScroll:true});else toTitle();}
@@ -5218,10 +5232,9 @@ function showNotHere(finding,found){
findGh.href=findIssueURL(state);
}
$('find-words').addEventListener('click',()=>{go({},true);scrollTo({top:0,behavior:reduce?'auto':'smooth'});q.focus({preventScroll:true});});
-const startCat=readURL();
+readURL();
render();
document.documentElement.classList.remove('fd-direct'); // the view is drawn: the page under the top bar shows
-if(startCat){const g=$('cat-'+startCat);if(g)g.scrollIntoView();}
(function(){const btn=$('theme-toggle');if(!btn)return;
btn.addEventListener('click',()=>{const next=document.documentElement.dataset.theme==='dark'?'light':'dark';
diff --git a/sitemap.xml b/sitemap.xml
index 6a601ccd..b7ed8c5d 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
- <url><loc>https://matinmonshizadeh.github.io/animation-handbook/</loc><lastmod>2026-11-20</lastmod><changefreq>weekly</changefreq><priority>1.0</priority></url>
+ <url><loc>https://matinmonshizadeh.github.io/animation-handbook/</loc><lastmod>2026-11-21</lastmod><changefreq>weekly</changefreq><priority>1.0</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/famous/</loc><lastmod>2026-11-03</lastmod><changefreq>monthly</changefreq><priority>0.8</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-depth-of-field/</loc><lastmod>2026-11-20</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
<url><loc>https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/parallax-scrolling/</loc><lastmod>2026-11-20</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
diff --git a/tests/finder.test.js b/tests/finder.test.js
index 2193522a..9dafe38f 100644
--- a/tests/finder.test.js
+++ b/tests/finder.test.js
@@ -238,8 +238,8 @@ test('the address keeps the finder and its answers: ?view=find, then what, when
const page = finder({ URLSearchParams, location: { search: '', pathname: '/animation-handbook/' },
history: { pushState: (s, t, url) => calls.push(['push', url]), replaceState: (s, t, url) => calls.push(['replace', url]) } });
for (const name of ['fromURL', 'writeURL']) vm.runInContext(source(name), page);
- const open = search => { page.location.search = search; return plain(page.fromURL().next); };
- const none = { q: '', place: '', view: '', all: false, what: '', when: '', how: '' };
+ const open = search => { page.location.search = search; return plain(page.fromURL()); };
+ const none = { q: '', place: '', cat: '', view: '', all: false, what: '', when: '', how: '' };
assert.deepEqual(open('?view=find&what=text&when=scroll&how=draw'), { ...none, view: 'find', what: 'text', when: 'scroll', how: 'draw' });
assert.deepEqual(open('?view=find&what=zebra&how=fade&all=1'), { ...none, view: 'find', all: true, how: 'fade' });
assert.deepEqual(open('?q=fade&view=find&what=text'), { ...none, q: 'fade' });
@@ -262,7 +262,7 @@ test("a step that changes only the fragment (How it works, Back to top, the skip
for (const name of ['fromURL', 'readURL']) vm.runInContext(source(name), page);
const start = at("addEventListener('popstate',");
vm.runInContext(HOME.slice(start, blockEnd(HOME.indexOf('{', start)) + 1) + ')', page);
- const none = { q: '', place: '', view: '', all: false, what: '', when: '', how: '' };
+ const none = { q: '', place: '', cat: '', view: '', all: false, what: '', when: '', how: '' };
page.state = { ...none, view: 'find', what: 'text', when: 'unsure' };
page.location.search = '?view=find&what=text';
page.popstate();
@@ -351,7 +351,7 @@ const listener = from => { const start = at(from); return HOME.slice(start, bloc
const SLUGS = homeConst('CATS').flatMap(cat => cat.entries.map(e => e[0]));
// Matches made of the first cards in home order: `best` of them, then `close` more.
const someMatches = (best, close) => ({ best: SLUGS.slice(0, best).map(slug => ({ slug })), close: SLUGS.slice(best, best + close).map(slug => ({ slug })) });
-const NONE = { q: '', place: '', view: '', all: false, what: '', when: '', how: '' };
+const NONE = { q: '', place: '', cat: '', view: '', all: false, what: '', when: '', how: '' };
function finderView() {
const els = {}, calls = [], listeners = {};
const $ = id => els[id] ??= fakeEl(id === 'places' ? { closest: () => els.placesSection ??= fakeEl() } : {});
@@ -491,7 +491,7 @@ test('an address that opens the finder shows only the top bar from the first pai
document: { documentElement: { classList: { add: name => added.push(name), remove: name => removed.push(name) } } } });
page.location.search = search;
const where = search || 'the start page';
- assert.deepEqual(added, page.fromURL().next.view === 'find' ? ['fd-direct'] : [], `${where}: as the page reads the address`);
+ assert.deepEqual(added, page.fromURL().view === 'find' ? ['fd-direct'] : [], `${where}: as the page reads the address`);
read.forEach(fn => fn());
assert.deepEqual(removed, added, `${where}: the class goes once the page is read, so a script that failed still leaves the page to see`);
}
@@ -499,7 +499,7 @@ test('an address that opens the finder shows only the top bar from the first pai
for (const part of ['<section class="wrap home-hero"', '<section class="wrap" aria-labelledby="places-title">', '<section class="wrap finder" id="finder"',
'<section class="wrap results" id="results"', '<section class="how" id="how"']) assert.ok(main.includes(part), `${part}… sits in <main>`);
assert.ok(STYLE.includes('.fd-direct main,.fd-direct .foot{visibility:hidden}'), 'the class hides everything under the top bar and keeps its room');
- assert.match(HOME, /\nconst startCat=readURL\(\);\r?\nrender\(\);\r?\ndocument\.documentElement\.classList\.remove\('fd-direct'\);/, 'the first render takes the class away');
+ assert.match(HOME, /\nreadURL\(\);\r?\nrender\(\);\r?\ndocument\.documentElement\.classList\.remove\('fd-direct'\);/, 'the first render takes the class away');
});
test("the page check's patterns for See N matches and the results line take each number only with its own word, as the page writes it", () => {
diff --git a/tests/pages.test.js b/tests/pages.test.js
index 6f34def4..15950079 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -1252,26 +1252,87 @@ test('the home page head gives search engines and social sites one title, one de
assert.match(head, /<link rel="canonical" href="[^"]*">\r?\n<link rel="sitemap" type="application\/xml" title="Sitemap" href="sitemap\.xml">\r?\n/, 'the sitemap link, right after the canonical link');
});
-test('every place has one tile, one phone-bar chip, one chip under the results heading and one count, and the markup names no other place', () => {
- // The opening tags of the page's markup: scripts, styles and comments left out.
- const tags = HOME.replace(/<script\b[\s\S]*?<\/script>|<style\b[\s\S]*?<\/style>|<!--[\s\S]*?-->/g, '').match(/<[a-z][^>]*>/g);
- const attr = (tag, name) => (tag.match(new RegExp(`\\s${name}="([^"]*)"`)) || [])[1];
- const hasClass = (tag, name) => (attr(tag, 'class') || '').split(/\s+/).includes(name);
- const placed = tags.filter(tag => attr(tag, 'data-place') !== undefined), counted = tags.filter(tag => attr(tag, 'data-count') !== undefined);
- // All, the first chip under the results heading, names no place: it goes back to Start.
- const all = placed.filter(tag => attr(tag, 'data-place') === '');
- assert.equal(all.length, 1, 'one button names no place: All');
- assert.ok(hasClass(all[0], 'spot'), 'All is a chip under the results heading');
- for (const tag of placed) if (tag !== all[0]) assert.ok(PLACE_KEYS.includes(attr(tag, 'data-place')), `unknown place: ${tag}`);
- for (const tag of counted) assert.ok(PLACE_KEYS.includes(attr(tag, 'data-count')), `unknown place: ${tag}`);
+// The opening tags of the home page's markup: scripts, styles and comments left out.
+const homeTags = () => HOME.replace(/<script\b[\s\S]*?<\/script>|<style\b[\s\S]*?<\/style>|<!--[\s\S]*?-->/g, '').match(/<[a-z][^>]*>/g);
+const tagAttr = (tag, name) => (tag.match(new RegExp(`\\s${name}="([^"]*)"`)) || [])[1];
+const tagHasClass = (tag, name) => (tagAttr(tag, 'class') || '').split(/\s+/).includes(name);
+
+test('every place has one tile, one phone-bar chip and one count, and the markup names no other place', () => {
+ const tags = homeTags();
+ const placed = tags.filter(tag => tagAttr(tag, 'data-place') !== undefined), counted = tags.filter(tag => tagAttr(tag, 'data-count') !== undefined);
+ for (const tag of placed) assert.ok(PLACE_KEYS.includes(tagAttr(tag, 'data-place')), `unknown place: ${tag}`);
+ for (const tag of counted) assert.ok(PLACE_KEYS.includes(tagAttr(tag, 'data-count')), `unknown place: ${tag}`);
for (const key of PLACE_KEYS) {
- assert.equal(placed.filter(tag => attr(tag, 'data-place') === key && hasClass(tag, 'place')).length, 1, `one ${key} tile`);
- assert.equal(placed.filter(tag => attr(tag, 'data-place') === key && hasClass(tag, 'pchip')).length, 1, `one ${key} chip in the phone bar`);
- assert.equal(placed.filter(tag => attr(tag, 'data-place') === key && hasClass(tag, 'spot')).length, 1, `one ${key} chip under the results heading`);
- assert.equal(counted.filter(tag => attr(tag, 'data-count') === key).length, 1, `one ${key} count`);
+ assert.equal(placed.filter(tag => tagAttr(tag, 'data-place') === key && tagHasClass(tag, 'place')).length, 1, `one ${key} tile`);
+ assert.equal(placed.filter(tag => tagAttr(tag, 'data-place') === key && tagHasClass(tag, 'pchip')).length, 1, `one ${key} chip in the phone bar`);
+ assert.equal(placed.filter(tag => tagAttr(tag, 'data-place') === key).length, 2, `${key}: its tile and its phone-bar chip, nothing else`);
+ assert.equal(counted.filter(tag => tagAttr(tag, 'data-count') === key).length, 1, `one ${key} count`);
}
});
+// A group's key, in its chip and in the address (?cat=): its name in small letters, every run of other characters a hyphen.
+const groupKey = name => name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
+
+test('the chips under the results heading are All and the seven groups in home order, each with its group color', () => {
+ const cats = homeConst('CATS');
+ const row = between(HOME, '<div class="spots" id="spots"', '</div>');
+ assert.match(row, /^<div class="spots" id="spots" role="group" aria-label="Groups">/, 'the row is a group named Groups');
+ assert.equal(count(row, '<button'), cats.length + 1, 'All and one chip for each group, nothing else');
+ const chips = [...row.matchAll(/<button type="button" class="spot" data-cat="([^"]*)" aria-pressed="(true|false)">(?:<i class="(c\d)" aria-hidden="true"><\/i>)?([^<]*)<\/button>/g)]
+ .map(m => ({ key: m[1], pressed: m[2], dot: m[3] || '', name: decode(m[4]) }));
+ // All, the first chip, names no group and starts pressed: it is Start.
+ assert.deepEqual(chips, [{ key: '', pressed: 'true', dot: '', name: 'All' },
+ ...cats.map(cat => ({ key: groupKey(cat.name), pressed: 'false', dot: cat.cat.replace('-cat', ''), name: cat.name }))]);
+ const tags = homeTags();
+ assert.equal(tags.filter(tag => tagAttr(tag, 'data-cat') !== undefined).length, cats.length + 1, 'no other button names a group');
+ assert.equal(tags.filter(tag => tagHasClass(tag, 'spot') && tagAttr(tag, 'data-place') !== undefined).length, 0, 'no chip under the results heading names a place');
+ // The dot takes the deep end of its group's gradient, the color of that group's cards.
+ const css = [...HOME.matchAll(/<style>([\s\S]*?)<\/style>/g)].map(m => m[1]).join('\n');
+ assert.ok(cssRules(css).some(rule => rule.selector === '.spot i' && /(^|;)\s*background:\s*var\(--g2\)/.test(rule.body)), 'the dot is drawn in the group color (--g2)');
+});
+
+// The address of a view, as the page reads it: the page's own slugify, CAT and fromURL() run with the page's CATS and places.
+function homeAddress(search) {
+ const line = marker => { const at = HOME.indexOf(marker); assert.ok(at >= 0, `${marker} in index.html`); return HOME.slice(at, HOME.indexOf('\n', at)); };
+ const start = HOME.indexOf('function fromURL(');
+ assert.ok(start >= 0, 'function fromURL in index.html');
+ const code = `${line('const slugify=')}\n${line('const CAT=')}\n${HOME.slice(start, blockEnd(HOME.indexOf('{', start)) + 1)}\nfromURL()`;
+ const next = vm.runInNewContext(code, { CATS: homeConst('CATS'), PLACE_LIST: homeConst('PLACE_LIST'), FIND_Q: [], URLSearchParams, location: { search } });
+ return JSON.parse(JSON.stringify(next));
+}
+
+test('an address with ?cat= opens that group; a search or a place wins over it, and a name that is no group opens All animations', () => {
+ const cats = homeConst('CATS');
+ for (const cat of cats) {
+ const key = groupKey(cat.name), next = homeAddress('?cat=' + key);
+ assert.deepEqual({ cat: next.cat, view: next.view, place: next.place, q: next.q, all: next.all }, { cat: key, view: '', place: '', q: '', all: false }, `?cat=${key}`);
+ }
+ assert.equal(homeAddress('?cat=micro-interactions&all=1').all, true, 'all=1 shows the whole group');
+ assert.equal(homeAddress('').cat, '', 'Start names no group');
+ let next = homeAddress('?q=fade&cat=micro-interactions');
+ assert.deepEqual([next.q, next.cat, next.view], ['fade', '', ''], 'a search wins');
+ next = homeAddress('?place=buttons&cat=micro-interactions');
+ assert.deepEqual([next.place, next.cat, next.view], ['btn', '', ''], 'a place wins');
+ // An old link with a name that is no group (and names every object has, such as constructor) opens All animations, as before.
+ for (const name of ['nothing', 'constructor', 'toString']) {
+ next = homeAddress('?cat=' + name);
+ assert.deepEqual([next.cat, next.view], ['', 'all'], `?cat=${name}`);
+ }
+});
+
+test('the home page shows a group by the same paging, heading and address rules as a place', () => {
+ const script = HOME.slice(HOME.indexOf('const state={'), HOME.indexOf('// ---------- The finder (?view=find) ----------'));
+ assert.ok(script.includes("const state={q:'',place:'',cat:'',view:'',all:false,what:'',when:'',how:''};"), 'the view names its group (cat)');
+ assert.ok(script.includes('const isFiltered=()=>!!(state.q||state.place||state.cat||state.view);'), 'a group counts as a picked view (Clear shows, the first eight cards)');
+ assert.ok(script.includes("list=ALL.filter(e=>e.cat===CAT[state.cat]);title=CAT[state.cat].name;sub=list.length+' animations';"), 'its cards, its name as the heading, its count');
+ assert.ok(script.includes('spotsEl.hidden=!!(state.q||state.place||state.view);'), 'the chips show at Start and on a group only');
+ assert.ok(script.includes("else if(state.cat)p.push('cat='+state.cat);"), 'the address names the group');
+ assert.ok(script.includes("if(state.all&&(state.q||state.place||state.cat||state.view==='find'))p.push('all=1');"), 'and Show all adds all=1');
+ // Every place that sets the whole view names cat, so a view never keeps the group of the one before it.
+ assert.equal(count(script, "place:'',cat:'',view:''"), 4, 'the view at boot, from the address, in go() and while typing');
+ assert.equal(count(script, "place:'',view:''"), 0, 'no view is written without its group');
+});
+
test('the home page keeps its GitHub button on phones as a round star, and leaves it out only below 360px', () => {
assert.equal(count(HOME, '</svg><span class="gh-t">GitHub</span> <span class="gh-c" id="gh-star-count"></span></a>'), 1,
'the word GitHub has a span of its own, so small screens can hide it from sight and still read it out');
diff --git a/tools/check-pages.mjs b/tools/check-pages.mjs
index b7793093..0176d9f2 100644
--- a/tools/check-pages.mjs
+++ b/tools/check-pages.mjs
@@ -1143,11 +1143,13 @@ async function homeCopyProblems() {
// animations lists every card under its group headings with the card titles a level below them, Browse all pressed there
// adds no history step, an address opened directly shows its view, "/" puts keyboard focus in the search box and Escape on
// the empty box keeps the picked place, a tile or Popular suggestion press brings the results heading into view with
-// keyboard focus (the picked tile pressed again does not scroll), and the old ?q= and ?cat= links still work. Keyboard
+// keyboard focus (the picked tile pressed again does not scroll), and the old ?q= and ?cat= links still work. A group chip
+// under the heading shows its group with the chip pressed, its first eight cards, Show all and its own address (?cat=); the
+// picked chip pressed again and All go back to Start; a place hides the chips and Clear brings them back. 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, Browse all (the button and the link) and Back after Show all
// put it on the results heading. A tile pressed while a search box keeps focus (a tap on iOS leaves it there) empties both
-// boxes. Leaves the home page on ?cat=micro-interactions.
+// boxes. Leaves the home page in All animations (?cat=nothing).
async function homeViewProblems() {
const problems = [];
const view = () => evaluate(`({ title: document.getElementById('results-title').textContent, cards: document.querySelectorAll('#cards .card').length,
@@ -1204,6 +1206,50 @@ async function homeViewProblems() {
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}`);
+ // The group chips under the heading. The group pressed is the biggest one (more than a page of cards, for Show all); the
+ // other is the first group that is not it. Both come from the page's data, as the totals do.
+ const chips = () => evaluate(`(() => { const row = document.getElementById('spots');
+ return { shown: !row.hidden && row.getClientRects().length > 0, pressed: [...row.querySelectorAll('.spot[aria-pressed="true"]')].map(b => b.dataset.cat || 'All').join() }; })()`);
+ const [group, other] = await evaluate(`(() => { const big = CATS.reduce((a, b) => b.entries.length > a.entries.length ? b : a), next = CATS.find(c => c !== big);
+ return [big, next].map(c => ({ key: slugify(c.name), name: c.name, cards: c.entries.length })); })()`);
+ if (group.cards <= 8) problems.push(`the page's own data: the biggest group has ${group.cards} cards (the group steps need more than one page of cards)`);
+ let c = await chips();
+ if (!c.shown || c.pressed !== 'All') problems.push(`group chips at Start: ${JSON.stringify(c)}`);
+ await press(`.spot[data-cat="${group.key}"]`);
+ await sleep(300);
+ v = await view(); c = await chips(); on = await focused();
+ if (v.title !== group.name || v.cards !== 8 || v.more !== `Show all ${group.cards}` || v.search !== `?cat=${group.key}` || v.pressed || !c.shown || c.pressed !== group.key || on === 'body') {
+ problems.push(`${group.name} chip: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}, keyboard focus is on ${on}`);
+ }
+ const groupCards = await evaluate(`({ here: [...document.querySelectorAll('#cards .card')].map(card => card.dataset.slug).join(), want: CAT[${JSON.stringify(group.key)}].entries.slice(0, 8).map(e => e[0]).join(),
+ tags: [...document.querySelectorAll('#cards .card .tag')].filter(t => t.getClientRects().length).length })`);
+ if (groupCards.here !== groupCards.want || groupCards.tags !== 8) problems.push(`${group.name} chip: the cards are ${groupCards.here}, not ${groupCards.want}; ${groupCards.tags} of 8 place labels show`);
+ await press('#more-btn');
+ await sleep(300);
+ v = await view(); on = await focused();
+ if (v.cards !== group.cards || v.more !== '' || v.search !== `?cat=${group.key}&all=1` || on !== 'card link 9') problems.push(`${group.name} chip, Show all: ${JSON.stringify(v)}, keyboard focus is on ${on}`);
+ await press(`.spot[data-cat="${group.key}"]`);
+ await sleep(300);
+ v = await view(); c = await chips();
+ if (v.title !== 'Good places to start' || v.cards !== 8 || v.search !== '' || c.pressed !== 'All') problems.push(`the picked group chip pressed again: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
+ await press(`.spot[data-cat="${other.key}"]`);
+ await sleep(300);
+ v = await view(); c = await chips();
+ if (v.title !== other.name || v.search !== `?cat=${other.key}` || c.pressed !== other.key) problems.push(`${other.name} chip: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
+ await press('.spot[data-cat=""]');
+ await sleep(300);
+ v = await view(); c = await chips();
+ if (v.title !== 'Good places to start' || v.search !== '' || c.pressed !== 'All') problems.push(`All chip: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
+ await press(`.spot[data-cat="${group.key}"]`);
+ await sleep(300);
+ await evaluate(`document.querySelector('.place[data-place="btn"]').click()`);
+ await sleep(300);
+ v = await view(); c = await chips();
+ if (v.title !== 'Buttons' || v.pressed !== 'btn' || c.shown || c.pressed) problems.push(`a place picked on a group: ${JSON.stringify(v)}, chips ${JSON.stringify(c)} (the chips hide on a place)`);
+ await press('#clear-view');
+ await sleep(300);
+ v = await view(); c = await chips();
+ if (v.title !== 'Good places to start' || !c.shown || c.pressed !== 'All') problems.push(`Clear after a place: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
await evaluate(`document.getElementById('q').focus()`);
await type('fade');
await sleep(300);
@@ -1304,11 +1350,32 @@ async function homeViewProblems() {
on = await focused();
if (v.title !== 'Buttons' || v.search !== '?place=buttons' || v.pressed !== 'btn' || on === 'q') problems.push(`Escape in the empty search box: ${JSON.stringify(v)}, keyboard focus is on ${on}`);
for (const [query, want] of [['?view=all', { title: 'All animations', groups: total.groups, cards: total.cards, pressed: '' }],
- ['?place=buttons&all=1', { title: 'Buttons', cards: total.buttons, more: '', pressed: 'btn' }]]) {
+ ['?place=buttons&all=1', { title: 'Buttons', cards: total.buttons, more: '', pressed: 'btn' }],
+ [`?cat=${group.key}`, { title: group.name, cards: 8, more: `Show all ${group.cards}`, pressed: '' }],
+ [`?cat=${group.key}&all=1`, { title: group.name, cards: group.cards, more: '', pressed: '' }]]) {
await load(query);
v = await view();
if (Object.keys(want).some(k => v[k] !== want[k])) problems.push(`${query}: ${JSON.stringify(v)}`);
+ if (query.startsWith('?cat=') && (c = await chips()).pressed !== group.key) problems.push(`${query}: chips ${JSON.stringify(c)}`);
}
+ // Back and Forward walk the views: Start, a group, another group, and back again.
+ await load('');
+ await press(`.spot[data-cat="${group.key}"]`);
+ await sleep(300);
+ await press(`.spot[data-cat="${other.key}"]`);
+ await sleep(300);
+ await evaluate(`history.back()`);
+ await sleep(500);
+ v = await view(); c = await chips();
+ if (v.title !== group.name || v.search !== `?cat=${group.key}` || c.pressed !== group.key) problems.push(`Back from ${other.name} to ${group.name}: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
+ await evaluate(`history.back()`);
+ await sleep(500);
+ v = await view(); c = await chips();
+ if (v.title !== 'Good places to start' || v.search !== '' || c.pressed !== 'All') problems.push(`Back from ${group.name} to Start: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
+ await evaluate(`history.forward()`);
+ await sleep(500);
+ v = await view(); c = await chips();
+ if (v.title !== group.name || c.pressed !== group.key) problems.push(`Forward to ${group.name}: ${JSON.stringify(v)}, chips ${JSON.stringify(c)}`);
// The results come into view at every width: a tile press that picks a place and a Popular suggestion press bring the
// results heading into the top 60% of the window and give it keyboard focus, so focus is not left on a control that
// scrolled away. The picked tile pressed again goes back to Start where the page is, without scrolling. Each reading
@@ -1331,13 +1398,12 @@ async function homeViewProblems() {
if (again.title !== 'Good places to start' || Math.abs(again.scrolled - seen.scrolled) > 1) problems.push(`the picked tile pressed again: heading "${again.title}", the page scrolled from ${seen.scrolled}px to ${again.scrolled}px`);
}
}
- // 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']]) {
+ // Old links keep working: ?q= opens the search; ?cat= with a group's name opens that group (above), and with a name that is
+ // no group All animations, as every ?cat= link once did.
+ for (const [query, want] of [['?q=fade', 'Results for “fade”'], ['?cat=nothing', 'All animations']]) {
await load(query);
- 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`);
+ const got = await evaluate(`document.getElementById('results-title').textContent`);
+ if (got !== want) problems.push(`${query}: heading "${got}"`);
}
return problems;
}
@@ -1348,8 +1414,9 @@ async function homeViewProblems() {
// page does not move. 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 goes away with the bar, so keyboard focus moves to the results heading. The back arrow goes away too
// and scrolls to the top, so keyboard focus moves to the first place tile, which is on screen there. The keyboard's Search
-// key in the bar's box takes keyboard focus out of the box (the keyboard closes) and keeps the bar. A 45-letter word in ?q=
-// does not make the page wider than the window.
+// key in the bar's box takes keyboard focus out of the box (the keyboard closes) and keeps the bar. The group chips scroll
+// sideways in their row: the last one, pressed, shows its group without the slim bar and is scrolled fully into the row, also
+// when its address (?cat=) is opened. A 45-letter word in ?q= does not make the page wider than the window.
async function homePhoneProblems() {
const now = () => evaluate(`(() => { const a = document.activeElement;
return { title: document.getElementById('results-title').textContent, focus: a.id || (a.matches('.place') ? 'tile ' + a.dataset.place : a.tagName.toLowerCase()),
@@ -1437,13 +1504,45 @@ async function homePhoneProblems() {
} finally {
await send('Emulation.setFocusEmulationEnabled', { enabled: false });
}
- // A 45-letter word in the address: the headings that repeat it break inside the word, so the page is no wider than the window.
- let onLoad;
- const loaded = new Promise(resolve => { onLoad = msg => { if (msg.method === 'Page.loadEventFired') resolve(); }; listeners.add(onLoad); });
- await send('Page.navigate', { url: `${BASE}/?q=pneumonoultramicroscopicsilicovolcanoconiosis` });
- try { await withTimeout(loaded, LOAD_TIMEOUT); } catch { problems.push('phone, ?q= with a 45-letter word did not load'); }
- listeners.delete(onLoad);
+ // Opens an address as a new visit would.
+ const open = async (query, what) => {
+ 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(`phone, ${what} did not load`); }
+ listeners.delete(onLoad);
+ await sleep(300);
+ };
+ // The group chips: at Start their row scrolls sideways under the heading. The last chip lies past the right edge of the row:
+ // pressed, its group shows without the slim bar, the chips stay with that chip pressed and scrolled fully into the row, and
+ // the page is no wider than the window. Pressed again it goes back to Start. Opened by its address (?cat=), the pressed chip
+ // is scrolled into the row as well.
+ const groupChip = () => evaluate(`(() => { const chips = [...document.querySelectorAll('#spots .spot')], c = chips[chips.length - 1], row = c.parentElement;
+ const b = c.getBoundingClientRect(), r = row.getBoundingClientRect();
+ return { key: c.dataset.cat, name: c.textContent, title: document.getElementById('results-title').textContent, pressed: c.getAttribute('aria-pressed'),
+ chips: !row.hidden && row.getClientRects().length > 0, bar: getComputedStyle(document.getElementById('pinbar')).display !== 'none',
+ inside: b.left >= r.left - .5 && b.right <= r.right + .5, wide: document.documentElement.scrollWidth > document.documentElement.clientWidth + 1, search: location.search }; })()`);
+ await open('', 'the start page');
+ let g = await groupChip();
+ if (g.title !== 'Good places to start' || !g.chips || g.pressed !== 'false' || g.inside || g.wide) {
+ problems.push(`phone, group chips at Start: ${JSON.stringify(g)}${g.inside ? ' (the last chip is expected past the edge of its row, which scrolls)' : ''}`);
+ }
+ await press(`.spot[data-cat="${g.key}"]`);
+ await sleep(700);
+ g = await groupChip();
+ if (g.title !== g.name || g.pressed !== 'true' || !g.chips || g.bar || !g.inside || g.wide || g.search !== `?cat=${g.key}`) {
+ problems.push(`phone, ${g.name} chip: ${JSON.stringify(g)}${g.bar ? ' (the slim bar shows)' : ''}${g.inside ? '' : ' (the pressed chip is not fully inside its row)'}`);
+ }
+ problems.push(...await fit(g.name));
+ await press(`.spot[data-cat="${g.key}"]`);
await sleep(300);
+ g = await groupChip();
+ if (g.title !== 'Good places to start' || g.pressed !== 'false' || g.search !== '') problems.push(`phone, the picked group chip pressed again: ${JSON.stringify(g)}`);
+ await open(`?cat=${g.key}`, `?cat=${g.key}`);
+ g = await groupChip();
+ if (g.title !== g.name || g.pressed !== 'true' || !g.inside || g.bar) problems.push(`phone, ?cat=${g.key}: ${JSON.stringify(g)}${g.inside ? '' : ' (the pressed chip is not fully inside its row)'}`);
+ // A 45-letter word in the address: the headings that repeat it break inside the word, so the page is no wider than the window.
+ await open('?q=pneumonoultramicroscopicsilicovolcanoconiosis', '?q= with a 45-letter word');
const wide = await evaluate(`({ page: document.documentElement.scrollWidth, window: document.documentElement.clientWidth })`);
if (wide.page > wide.window + 1) problems.push(`phone, ?q= with a 45-letter word: the page is ${wide.page}px wide in a ${wide.window}px window`);
return problems;