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.

fix: Famous pop-up keeps focus in view, survives double-clicks and reopens, fits short windows, shows the not-connected line, and the tests pin more of it

matin9787b232b78d
diff --git a/famous/index.html b/famous/index.html
index af8fd559..4ed60f40 100644
--- a/famous/index.html
+++ b/famous/index.html
@@ -270,10 +270,11 @@ button{font:inherit;color:inherit}
.gp-menu{background:radial-gradient(80% 100% at 50% 20%,#12162a,#08080a 70%)}
.mn-bar{position:absolute;left:8cqw;right:8cqw;top:22cqh;height:15cqh;border-radius:999px;background:#171a25;border:1px solid #2a2f40}
.mn-dot{left:4cqw;top:50%;width:5cqw;height:5cqw;margin-top:-2.5cqw;border-radius:50%;background:var(--c1)}
-.mn-btn{position:absolute;right:4.4cqw;top:50%;width:6cqw;height:4cqw;margin-top:-2cqw}
+.mn-btn{position:absolute;right:4.4cqw;top:50%;width:6cqw;height:4.4cqw;margin-top:-2.2cqw}
.mn-btn i{left:0;right:0;height:.8cqw;min-height:2px;border-radius:2px;background:#e9ebf3}
-.mn-btn i:nth-child(1){top:.6cqw;transform:translateY(1.05cqw) rotate(45deg)}
-.mn-btn i:nth-child(2){bottom:.6cqw;transform:translateY(-1.05cqw) rotate(-45deg)}
+.mn-btn i:nth-child(1){top:0;transform:translateY(1.8cqw) rotate(45deg)}
+.mn-btn i:nth-child(2){top:50%;margin-top:-.4cqw;opacity:0}
+.mn-btn i:nth-child(3){bottom:0;transform:translateY(-1.8cqw) rotate(-45deg)}
.mn-panel{position:absolute;left:8cqw;right:8cqw;top:41cqh;bottom:6cqh;border-radius:2.6cqw;background:#12141d;border:1px solid #232838}
.mn-panel i{left:6cqw;height:5.6cqh;border-radius:1cqh;background:#cdd2e0}
.mn-panel i:nth-child(1){top:6cqh;width:42cqw}
@@ -318,8 +319,8 @@ button{font:inherit;color:inherit}
.gp-cards .cd .t1{left:1.5cqw;top:26.4cqw;width:17cqw;height:1.9cqw;border-radius:1cqw;background:#d5d9e6}
.gp-cards .cd .t2{left:1.5cqw;top:29.8cqw;width:11cqw;height:1.6cqw;border-radius:1cqw;background:#5d6580}
.gp-cards .cb::before{content:"";position:absolute;inset:0;border-radius:inherit;background:rgba(255,255,255,.08)}
-.gp-cards .play{right:1.8cqw;bottom:1.8cqw;width:7.6cqw;height:7.6cqw;border-radius:50%;background:var(--c2)}
-.gp-cards .play::after{content:"";position:absolute;left:31%;top:24%;width:42%;height:52%;background:#07150d;clip-path:polygon(0 0,100% 50%,0 100%)}
+.gp-cards .play{right:1.8cqw;bottom:1.8cqw;width:7.6cqw;height:7.6cqw;border-radius:50%;background:var(--c1)}
+.gp-cards .play::after{content:"";position:absolute;left:31%;top:24%;width:42%;height:52%;background:#0b1226;clip-path:polygon(0 0,100% 50%,0 100%)}
/* gray shapes that fill in: a sheen passes over each, then the content takes their places */
.gp-load{background:#0a0b10}
@@ -382,8 +383,9 @@ button{font:inherit;color:inherit}
@keyframes g-blob{0%,100%{transform:translate(14cqw,14cqh)}25%{transform:translate(48cqw,8cqh)}50%{transform:translate(52cqw,30cqh)}75%{transform:translate(22cqw,32cqh)}}
@keyframes g-blob-i{0%,100%{transform:translate(-14cqw,-14cqh)}25%{transform:translate(-48cqw,-8cqh)}50%{transform:translate(-52cqw,-30cqh)}75%{transform:translate(-22cqw,-32cqh)}}
@keyframes g-line{0%,6%{opacity:0;transform:translateY(5cqh)}24%,80%{opacity:1;transform:none}92%,100%{opacity:0;transform:translateY(-2cqh)}}
-@keyframes g-x1{0%,14%{transform:none}28%,72%{transform:translateY(1.05cqw) rotate(45deg)}86%,100%{transform:none}}
-@keyframes g-x2{0%,14%{transform:none}28%,72%{transform:translateY(-1.05cqw) rotate(-45deg)}86%,100%{transform:none}}
+@keyframes g-x1{0%,14%{transform:none}28%,72%{transform:translateY(1.8cqw) rotate(45deg)}86%,100%{transform:none}}
+@keyframes g-x2{0%,14%{opacity:1}28%,72%{opacity:0}86%,100%{opacity:1}}
+@keyframes g-x3{0%,14%{transform:none}28%,72%{transform:translateY(-1.8cqw) rotate(-45deg)}86%,100%{transform:none}}
@keyframes g-panel{0%,14%{opacity:0;transform:translateY(-3cqh)}28%,72%{opacity:1;transform:none}86%,100%{opacity:0;transform:translateY(-2cqh)}}
@keyframes g-drop{0%,22%{opacity:0;transform:translateY(-4cqh)}36%,72%{opacity:1;transform:none}84%,100%{opacity:0;transform:translateY(-2cqh)}}
@keyframes g-ptr{0%,8%{transform:translate(30cqw,12cqh)}24%,80%{transform:none}94%,100%{transform:translate(30cqw,12cqh)}}
@@ -425,6 +427,7 @@ button{font:inherit;color:inherit}
.gp-menu{--x:2.6s}
.mn-btn i:nth-child(1){animation:g-x1 6s var(--ease) infinite backwards;animation-delay:calc(0s - var(--x))}
.mn-btn i:nth-child(2){animation:g-x2 6s var(--ease) infinite backwards;animation-delay:calc(0s - var(--x))}
+ .mn-btn i:nth-child(3){animation:g-x3 6s var(--ease) infinite backwards;animation-delay:calc(0s - var(--x))}
.mn-panel{animation:g-panel 6s var(--ease) infinite backwards;animation-delay:calc(0s - var(--x))}
.mn-panel i{animation:g-drop 6s var(--ease) infinite backwards;animation-delay:calc(var(--d,0s) - var(--x))}
.mn-panel i:nth-child(2){--d:.14s}
@@ -469,8 +472,9 @@ button{font:inherit;color:inherit}
.fx-chip{display:inline-flex;align-items:center;min-height:32px;padding:0 13px;border-radius:999px;background:var(--line-2);border:1px solid var(--line);font-size:14px;font-weight:600;color:var(--ink-2)}
.fx-version{display:none;margin-top:22px}
.js .fx-version{display:block}
-.fx-stage{position:relative;height:420px;border-radius:16px;overflow:hidden;background:#08080a;border:1px solid var(--line)}
+.fx-stage{position:relative;height:clamp(240px,calc(100vh - 420px),420px);height:clamp(240px,calc(100dvh - 420px),420px);border-radius:16px;overflow:hidden;background:#08080a;border:1px solid var(--line)}
.fx-stage iframe{position:absolute;inset:0;width:100%;height:100%;border:0;background:#08080a}
+.fx-stage.is-focused{outline:3px solid var(--brand);outline-offset:3px} /* the browser draws no focus ring inside a frame, so the stage does */
.fx-vlabel{position:absolute;z-index:2;left:12px;top:12px;padding:5px 11px;border-radius:999px;background:rgba(255,255,255,.94);color:#16161b;font-size:12px;font-weight:700;line-height:1.2;pointer-events:none}
.fx-player{display:flex;flex-wrap:wrap;align-items:center;gap:10px 16px;margin-top:12px}
.fx-pbtn{display:inline-flex;align-items:center;justify-content:center;min-width:44px;min-height:44px;padding:0 22px;border-radius:999px;border:1.5px solid var(--ink);background:none;color:var(--ink);font-size:15px;font-weight:700;cursor:pointer;transition:background .2s,color .2s}
@@ -492,17 +496,19 @@ button{font:inherit;color:inherit}
html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does not scroll behind the pop-up, and keeps its width where its scrollbar was */
.fx-dbar{position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:6px;padding:10px clamp(12px,2.4vw,20px);background:var(--surface);border-bottom:1px solid var(--line)}
.fx-dbtn{border:1px solid var(--line);background:var(--surface);color:var(--ink)}
+.fx-dnote{flex:1;min-width:0;margin:0 8px;font-size:12px;line-height:1.3;color:var(--muted);text-align:center;text-wrap:balance}
.fx-dclose{margin-left:auto}
.fx-dlg .fx h2{width:fit-content;max-width:100%}
.fx-dlg .fx{margin:0;padding:clamp(14px,2.2vw,24px) clamp(18px,4vw,40px) clamp(28px,4vw,44px);border-top:0;scroll-margin-top:65px}
@media(max-width:600px),(max-height:500px){
.fx-dlg{width:100%;height:100%;max-height:none;border:0;border-radius:0;box-shadow:none}
- .fx-stage{height:300px}
+ .fx-stage{height:min(300px,calc(100vh - 140px));height:min(300px,calc(100dvh - 140px))}
.fx-dlg .copy{position:sticky;bottom:12px;z-index:4;box-shadow:0 8px 20px rgba(22,22,27,.3)}
.fx-dlg .toast{bottom:76px}
.fx-dlg .fx-what a{padding-block:14px} /* a link inside a sentence: its touch area grows to 44px without moving the lines */
}
@media(max-width:600px){.fx-dlg .copy{box-shadow:0 0 0 12px var(--surface),0 -16px 16px 4px var(--surface)}} /* full width: the page's own color around it hides the text that scrolls past */
+@media(max-height:500px){.fx-dlg .copy{position:static;box-shadow:none}} /* a short window: the button stays at the end of the entry, where it cannot cover the stage */
@media(max-width:760px){.fx-know{grid-template-columns:minmax(0,1fr)}}
@media(prefers-reduced-motion:reduce){.fx-dlg[open],.fx-dlg[open]::backdrop{animation:none}}
@@ -740,7 +746,7 @@ html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does n
</li>
<li class="tile" data-fx-tile="apple-menu">
<div class="t-stage">
- <div class="gp gp-menu" aria-hidden="true"><div class="mn-bar"><i class="mn-dot"></i><div class="mn-btn"><i></i><i></i></div></div><div class="mn-panel"><i></i><i></i><i></i></div></div>
+ <div class="gp gp-menu" aria-hidden="true"><div class="mn-bar"><i class="mn-dot"></i><div class="mn-btn"><i></i><i></i><i></i></div></div><div class="mn-panel"><i></i><i></i><i></i></div></div>
<div class="t-tags"><span class="t-tag">Our version</span><span class="t-tag t-start">On press</span></div>
</div>
<div class="t-meta">
@@ -868,7 +874,7 @@ html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does n
<p class="fx-what">About two thirds of the way down the page, the headset stays in the middle of the screen while you scroll: its parts rise out of it layer by layer, then it tips up to show its lenses, and scrolling back puts it together.</p>
<h3 class="fx-sub">Good to know</h3>
<dl class="fx-know">
- <div><dt>Starts</dt><dd>Scrolling plays it, forward and back.</dd></div>
+ <div><dt>Starts</dt><dd>Scrolling through the section plays it, forward and back.</dd></div>
<div><dt>On phones</dt><dd>Touch scrolling drives it the same way.</dd></div>
<div><dt>Reduced motion</dt><dd>A few still pictures with their text are shown instead.</dd></div>
</dl>
@@ -916,8 +922,8 @@ html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does n
<h3 class="fx-sub">Good to know</h3>
<dl class="fx-know">
<div><dt>Starts</dt><dd>As the page opens. The whole opening is over in about a second.</dd></div>
- <div><dt>On phones</dt><dd>Less blur is used, because it costs more there.</dd></div>
- <div><dt>Reduced motion</dt><dd>Everything shows at once.</dd></div>
+ <div><dt>On phones</dt><dd>Less blur is used on phones, where it costs more.</dd></div>
+ <div><dt>Reduced motion</dt><dd>The opening is skipped: everything shows at once.</dd></div>
</dl>
<h3 class="fx-sub">Build it with these animations</h3>
<div class="fx-cards">
@@ -941,7 +947,7 @@ html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does n
<dl class="fx-know">
<div><dt>Starts</dt><dd>A tap on the menu button. On computers, pointing at a top item or reaching it with the keyboard.</dd></div>
<div><dt>On phones</dt><dd>A tap on the menu button opens the menu over the whole screen.</dd></div>
- <div><dt>Reduced motion</dt><dd>The menus show and hide at once.</dd></div>
+ <div><dt>Reduced motion</dt><dd>The menus show and hide at once, without opening in steps.</dd></div>
</dl>
<h3 class="fx-sub">Build it with these animations</h3>
<div class="fx-cards">
@@ -1102,6 +1108,7 @@ html.fx-open{overflow:hidden;padding-right:var(--fx-gap,0px)} /* the page does n
<div class="fx-dbar">
<button type="button" class="icon-btn fx-dbtn" data-fx-nav="prev" aria-label="Previous effect"><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M15 5l-7 7 7 7"/></svg></button>
<button type="button" class="icon-btn fx-dbtn" data-fx-nav="next" aria-label="Next effect"><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 5l7 7-7 7"/></svg></button>
+ <p class="fx-dnote">Not connected to the site. Everything shown is our own version.</p>
<button type="button" class="icon-btn fx-dbtn fx-dclose" data-fx-close aria-label="Close"><svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button>
</div>
<div class="fx-dbody"></div>
@@ -1267,8 +1274,9 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
// The pop-up. A press on a tile opens its entry in one native dialog: the entry's section is moved into the dialog and put back in the
// list when the dialog closes or another entry takes its place, so its Copy prompt and its prompt toggle keep working. Without scripts,
-// or in a browser with no dialog, the list stays on the page and a tile is a link to its entry (the head sets the js class).
-(function(){
+// or in a browser with no dialog, the list stays on the page and a tile is a link to its entry (the head sets the js class). If the
+// set-up or a press fails, the js class goes, the list shows and a tile still jumps to its entry.
+function popup(){
const root=document.documentElement;
if(!root.classList.contains('js'))return;
const holder=dlg.querySelector('.fx-dbody'),list=document.querySelector('.fx-list');
@@ -1276,6 +1284,7 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
const toastHome={parent:toastEl.parentNode,next:toastEl.nextSibling};
// An address this page pushed (not one the visitor arrived at) carries fxPushed, so Close can go back one step.
const pushed=()=>!!(history.state&&history.state.fxPushed);
+ const live=()=>root.classList.contains('js');
let current=null,fromHistory=false,downOnBackdrop=false;
// Under reduced motion each recipe card holds one clear frame. A card moved into the dialog starts again, so it is held again.
@@ -1285,7 +1294,8 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
}
// An entry's version loads only while its entry is open, in a fresh frame each time (a used frame keeps steps of history).
- function post(frame,cmd){frame.contentWindow.postMessage({fx:cmd},'*');}
+ // The frame is a file of this site, so a command goes to this site's own origin (a page opened from disk has none to name).
+ function post(frame,cmd){frame.contentWindow.postMessage({fx:cmd},location.protocol==='file:'?'*':location.origin);}
function command(frame,cmd){
if(frame.dataset.ready==='1')post(frame,cmd);
else if(frame.hasAttribute('src'))frame._queued=cmd;
@@ -1299,7 +1309,16 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
frame.addEventListener('load',()=>{
frame.dataset.ready='1';
if(frame._queued){post(frame,frame._queued);frame._queued=null;}
- try{frame.contentWindow.addEventListener('keydown',e=>{if(e.key==='Escape')dlg.close();});}catch(err){}
+ // Escape closes the pop-up from inside the frame too. The browser draws no focus ring inside a frame, so the stage draws one
+ // while the frame holds keyboard focus (not after a press of the pointer, as with :focus-visible).
+ try{
+ const win=frame.contentWindow,stage=frame.closest('.fx-stage');
+ let pointer=false;
+ win.addEventListener('pointerdown',()=>{pointer=true;},true);
+ win.addEventListener('keydown',e=>{pointer=false;if(e.key==='Escape')dlg.close();},true);
+ win.addEventListener('focus',()=>{if(!pointer)stage.classList.add('is-focused');});
+ win.addEventListener('blur',()=>{pointer=false;stage.classList.remove('is-focused');});
+ }catch(err){}
},{once:true});
frame.src=frame.dataset.src;
}
@@ -1308,6 +1327,8 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
if(!frame||!frame.hasAttribute('src'))return;
const fresh=frame.cloneNode(false);
fresh.removeAttribute('src');
+ fresh.removeAttribute('data-ready'); // a copy keeps the attributes of the frame that was loaded
+ frame.closest('.fx-stage').classList.remove('is-focused');
frame.replaceWith(fresh);
}
@@ -1351,12 +1372,23 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
const at=entries.indexOf(current);
openEntry(entries[(at+step+entries.length)%entries.length].id,'replace');
}
+ // If the pop-up cannot open, the page falls back to its list: the js class goes (the list shows) and the page jumps to the entry
+ // (the address may already name it, so the page does the jump itself).
+ function fail(id){
+ root.classList.remove('js','fx-open');
+ root.style.removeProperty('--fx-gap');
+ try{if(dlg.open)dlg.close();}catch(err){}
+ if(current){try{unmount(current);}catch(err){}current=null;}
+ toastHome.parent.insertBefore(toastEl,toastHome.next);
+ const entry=byId.get(id);
+ if(entry){entry.scrollIntoView();entry.querySelector('h2').focus({preventScroll:true});}
+ }
// Every way of closing (Close, Escape, a press on the backdrop, Back) ends here.
dlg.addEventListener('close',()=>{
const entry=current;
if(!entry)return;
- const goBack=pushed();
+ const goBack=pushed(),viaBack=goBack&&!fromHistory;
unmount(entry);
current=null;
root.classList.remove('fx-open');
@@ -1368,26 +1400,42 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
}
fromHistory=false;
const tile=document.querySelector('.fx-grid a[href="#'+entry.id+'"]');
- if(tile)tile.focus();
+ if(!tile)return;
+ tile.focus();
+ // history.back() puts the page back where it was when that step was left, and Chrome does that after the popstate: once it
+ // has, the tile is brought into view again and keeps focus.
+ if(viaBack){
+ const at=Date.now();
+ addEventListener('popstate',()=>setTimeout(()=>{
+ if(Date.now()-at>3000)return;
+ tile.closest('.tile').scrollIntoView({block:'nearest'});
+ if(document.activeElement!==tile)tile.focus({preventScroll:true});
+ },0),{once:true});
+ }
});
// The address decides what shows: an entry's name opens it, anything else closes the pop-up.
function sync(){
+ if(!live())return;
const id=location.hash.slice(1);
- if(byId.has(id)){if(byId.get(id)!==current){openEntry(id,'none');setTimeout(keepFocus,0);}}
- else if(dlg.open){fromHistory=true;dlg.close();}
+ try{
+ if(byId.has(id)){if(byId.get(id)!==current){openEntry(id,'none');setTimeout(keepFocus,0);}}
+ else if(dlg.open){fromHistory=true;dlg.close();}
+ }catch(err){fail(id);}
}
addEventListener('popstate',sync);
addEventListener('hashchange',sync);
// A plain press on a link to an entry opens it; a press with Ctrl, Cmd, Shift or Alt, or another button, is left to the browser.
document.addEventListener('click',e=>{
+ if(!live())return;
const a=e.target.closest('a[href^="#"]');
if(!a||e.button||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;
const id=a.getAttribute('href').slice(1);
if(!byId.has(id))return;
e.preventDefault();
- openEntry(id,location.hash==='#'+id?'none':'push');
+ try{openEntry(id,location.hash==='#'+id?'none':'push');}
+ catch(err){fail(id);}
});
const outside=e=>{const r=dlg.getBoundingClientRect();return e.clientX<r.left||e.clientX>r.right||e.clientY<r.top||e.clientY>r.bottom;};
@@ -1403,7 +1451,8 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
if(btn.closest('section.fx').dataset.fxStart==='loop')setToggle(btn,cmd==='pause'?'play':'pause');
return;
}
- if(e.target===dlg&&downOnBackdrop&&outside(e))dlg.close();
+ // the second click of a double-click on a tile lands on the backdrop of the pop-up the first one opened: it does not close it
+ if(e.target===dlg&&downOnBackdrop&&e.detail<2&&outside(e))dlg.close();
downOnBackdrop=false;
});
@@ -1412,7 +1461,8 @@ document.querySelectorAll('.fx .copy').forEach(btn=>btn.addEventListener('click'
function keepFocus(){if(current&&dlg.open&&!dlg.contains(document.activeElement))current.querySelector('h2').focus({preventScroll:true});}
sync();
if(document.readyState!=='complete')addEventListener('load',keepFocus,{once:true});
-})();
+}
+try{popup();}catch(err){document.documentElement.classList.remove('js');}
</script>
</body>
</html>
diff --git a/tests/famous.test.js b/tests/famous.test.js
index f3ba27d6..8aba70d4 100644
--- a/tests/famous.test.js
+++ b/tests/famous.test.js
@@ -415,6 +415,9 @@ test('the entries are all in one wrapper after the gallery, in page order, so th
});
const stems = s => new Set((s.toLowerCase().match(/[a-z]{5,}/g) || []).map(w => w.slice(0, 5)));
+const promptText = e => textOf(e.body.match(/<div class="fx-pbox"><p class="fx-prompt">([\s\S]*?)<\/p><\/div>/)[1]);
+// The word stems every prompt has (visitor, reduced, motion, turned): they say nothing about one entry, so they do not count.
+const COMMON_STEMS = (sets => new Set([...sets[0]].filter(s => sets.every(set => set.has(s)))))(ENTRIES.map(e => stems(promptText(e))));
// The player of each kind of entry: its buttons as [data-fx-cmd, label]. A loop's one button swaps between Pause and Play.
const PLAYER = { loop: [['pause', 'Pause']], load: [['replay', 'Replay']], hover: [['show', 'Show me']], press: [['show', 'Show me']], scroll: [['play', 'Play'], ['top', 'Back to top']] };
for (const e of ENTRIES) {
@@ -442,7 +445,8 @@ for (const e of ENTRIES) {
for (const [, label, line] of pairs) {
const n = words(decode(line));
assert.ok(n >= 2 && n <= 20 && !/["“”`]/.test(line), `${label}: "${line}" is one short plain line`);
- assert.ok([...stems(line)].some(s => promptStems.has(s)), `${label}: "${line}" is taken from the entry's prompt`);
+ const shared = [...stems(line)].filter(s => promptStems.has(s) && !COMMON_STEMS.has(s));
+ assert.ok(shared.length >= 2, `${label}: "${line}" shares ${shared.length} word stems with the entry's prompt and needs two (not counting ${[...COMMON_STEMS].join(', ')}, which every prompt has)`);
}
const href = seenHref(e);
assert.ok(b.includes(`<a class="fx-real" href="${href}" target="_blank" rel="noopener">Watch the real one on ${hostOf(href)} <span aria-hidden="true">↗</span><span class="sr"> (opens in a new tab)</span></a>`),
@@ -636,8 +640,9 @@ test('the pop-up is a rounded card in the page\'s surface and line colors, dimme
const phone = inner(PHONE);
assert.match(rule(phone, '.fx-dlg'), /width:100%;height:100%;max-height:none;border:0;border-radius:0/, 'on phones it fills the screen');
assert.match(rule(phone, '.fx-dlg .copy'), /position:sticky;bottom:\d+px/, "on phones the entry's own Copy prompt sticks to the bottom");
- assert.match(rule(CSS_BLOCKS, '.fx-stage'), /height:420px/, 'Our version is 420px tall');
- assert.match(rule(phone, '.fx-stage'), /height:300px/, 'and 300px on phones');
+ assert.match(rule(CSS_BLOCKS, '.fx-stage'), /height:clamp\(240px,calc\(100dvh - 420px\),420px\)/, 'Our version is 420px tall, less in a short window, so it and its player fit the first screen');
+ assert.match(rule(phone, '.fx-stage'), /height:min\(300px,calc\(100dvh - 140px\)\)/, 'and 300px on phones, less in a short window');
+ assert.match(rule(inner('@media(max-height:500px)'), '.fx-dlg .copy'), /position:static/, 'in a short window Copy prompt does not stick (it would cover the stage)');
assert.match(rule(CSS_BLOCKS, '.fx-stage'), /background:#08080a/, 'always dark');
});
@@ -655,11 +660,37 @@ test('an entry\'s version loads from data-src only while its entry is open, in a
assert.ok(SCRIPT.includes('frame.src=frame.dataset.src'), 'the frame gets its src from data-src');
assert.ok(SCRIPT.includes('const fresh=frame.cloneNode(false)') && SCRIPT.includes("fresh.removeAttribute('src')") && SCRIPT.includes('frame.replaceWith(fresh)'), 'and is replaced by an empty one when its entry closes or changes');
assert.ok(/startVersion\(entry\)/.test(SCRIPT) && /unmount\(entry\)\{\s*stopVersion\(entry\)/.test(SCRIPT), 'started with its entry, stopped when it goes back to the list');
- assert.ok(SCRIPT.includes("frame.contentWindow.postMessage({fx:cmd},'*')"), 'a player button sends {fx: command} to the frame');
+ assert.ok(SCRIPT.includes("frame.contentWindow.postMessage({fx:cmd},location.protocol==='file:'?'*':location.origin)"), "a player button sends {fx: command} to the frame, naming this site's origin (a page opened from disk has none)");
+ assert.ok(SCRIPT.includes("fresh.removeAttribute('data-ready')"), 'the empty frame that replaces a used one is not marked ready (commands would go to a blank page and be lost)');
assert.ok(SCRIPT.includes('.fx-player [data-fx-cmd]') && SCRIPT.includes("dataset.fxStart==='loop'"), 'any player button works by its data-fx-cmd, and a loop\'s Pause and Play swap');
assert.ok(!/<iframe[^>]*\ssrc=/.test(PAGE), 'no frame has a src in the markup');
});
+test('closing after Previous and Next brings the tile back into view, a double-click does not close what it opened, and a failing set-up falls back to the list', () => {
+ assert.ok(SCRIPT.includes('viaBack=goBack&&!fromHistory'), 'a close that goes back in the history is told apart');
+ assert.ok(/addEventListener\('popstate',\(\)=>setTimeout\(\(\)=>\{[^]*?tile\.closest\('\.tile'\)\.scrollIntoView\(\{block:'nearest'\}\);[^]*?tile\.focus\(\{preventScroll:true\}\);?[^]*?\},0\),\{once:true\}\)/.test(SCRIPT),
+ "once the history has moved (the browser puts the page back where it was after that), the whole tile is scrolled into view and its link keeps focus");
+ assert.ok(SCRIPT.includes('e.target===dlg&&downOnBackdrop&&e.detail<2&&outside(e)'), 'the second click of a double-click, which lands on the backdrop, closes nothing');
+ assert.ok(SCRIPT.includes("try{popup();}catch(err){document.documentElement.classList.remove('js');}"), 'if the set-up throws, the js class goes and the list shows');
+ assert.ok(SCRIPT.includes('catch(err){fail(id);}') && SCRIPT.includes('entry.scrollIntoView();') && SCRIPT.includes('const live=()=>root.classList.contains(\'js\');'), 'a press (or an address) that fails falls back to the list too and jumps to the entry, and the handlers stand down');
+ assert.ok(SCRIPT.includes("stage.classList.add('is-focused')") && SCRIPT.includes("stage.classList.remove('is-focused')"), 'the stage shows when the frame holds keyboard focus');
+ assert.match(rule(CSS_BLOCKS, '.fx-stage.is-focused'), /outline:3px solid var\(--brand\);outline-offset:3px/, 'as a ring, since the browser draws none inside a frame');
+});
+
+test('without scripts Our version stays hidden, and the pop-up says once, in its own bar, that the page is not connected to the site', () => {
+ assert.match(rule(CSS_BLOCKS, '.fx-version'), /display:none/, 'hidden until scripts run (a script fills the frame)');
+ assert.match(rule(CSS_BLOCKS, '.js .fx-version'), /display:block/, 'and shown with them');
+ assert.equal(count(PAGE, 'class="fx-dnote"'), 1, 'one note');
+ assert.ok(between(PAGE, '<div class="fx-dbar">', '<div class="fx-dbody">').includes('<p class="fx-dnote">Not connected to the site. Everything shown is our own version.</p>'), 'in the bar of the pop-up, which stays on screen');
+ assert.ok(!ENTRIES.some(e => /fx-dnote|Not connected/.test(e.body)), 'not in each entry');
+ assert.match(rule(CSS_BLOCKS, '.fx-dnote'), /font-size:12px;[^}]*color:var\(--muted\)/, 'small and muted');
+});
+
+test('the tile pictures do not repeat the look of a site: the round play button is a palette color, not green, and the menu button has three lines', () => {
+ assert.match(rule(CSS_BLOCKS, '.gp-cards .play'), /background:var\(--c1\)/, 'the play button is the palette blue');
+ assert.ok(GALLERY.includes('<div class="mn-btn"><i></i><i></i><i></i></div>'), 'a plain three-line menu button');
+});
+
// ---------- Our version: the frames of the entries and the files they load ----------
const VERSIONS = ENTRIES.filter(e => e.body.includes('<div class="fx-version">'));
// The words a version shows: its markup without scripts and styles, with the words of its labels (title, aria-label, alt, data-alt).
@@ -701,6 +732,11 @@ for (const e of VERSIONS) {
assert.ok(!/\b(fetch|XMLHttpRequest|sendBeacon|EventSource|WebSocket|importScripts|import)\s*\(|new\s+(Worker|SharedWorker)\b/.test(script), 'its script makes no request');
assert.ok(/@media\s*\(\s*prefers-reduced-motion\s*:\s*reduce\s*\)/.test(html) || /matchMedia\(\s*['"]\(prefers-reduced-motion\s*:\s*reduce\)['"]/.test(script), 'a reduced-motion rule');
assert.ok(/@media\s*\(\s*prefers-reduced-motion\s*:\s*reduce\s*\)/.test(html), 'in its style');
+ assert.ok(/matchMedia\(\s*['"]\(prefers-reduced-motion\s*:\s*reduce\)['"]\s*\)/.test(script), 'it asks matchMedia about reduced motion');
+ assert.ok(/overscroll-behavior\s*:\s*contain/.test(html), 'its scroller keeps the scroll to itself (overscroll-behavior: contain)');
+ if (/requestAnimationFrame/.test(script)) {
+ assert.ok(/\bFRAME\s*=\s*1000\s*\/\s*60\b/.test(script) && /Math\.min\(\s*ts\s*-\s*lastT\s*,\s*50\s*\)/.test(script) && /\bdt\s*\)?\s*\/\s*FRAME\b/.test(script), 'its frame loop steps by elapsed time (dt / FRAME), not by a fixed amount a frame');
+ }
assert.ok(/addEventListener\(\s*['"]message['"]/.test(script), 'a message listener');
assert.ok(/\.source\s*(?:!==|===|!=|==)\s*(?:window\.)?parent\b/.test(script) || /\b(?:window\.)?parent\s*(?:!==|===|!=|==)\s*\w+\.source\b/.test(script), 'that checks the message comes from its parent');
const text = versionText(html);