176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: the page check waits for the run a mode press starts, tries do-it pages from rest, counts rest as 750 ms unchanged, and checks every mode's labels, ids and control names and the picture's name
matin193f2bab9297
diff --git a/tools/check-pages.mjs b/tools/check-pages.mjsindex 8411b1dd..3344cc09 100644--- a/tools/check-pages.mjs+++ b/tools/check-pages.mjs@@ -25,20 +25,32 @@// takes screenshots and, on a page with the mode switch, tries the modes (below), and nothing more.// A page with the mode switch (Normal, See inside, Compare): at every setup each mode marks the stage, shows its own note// (one that is on show: rendered, not clipped away) and no other (Normal shows none) and overflows nothing, a mode change-// moves neither the page nor the keyboard focus (the pressed button itself may take it), and the whole Watch step (its-// heading, the switch, the stage, the player bar and the notes) is saved as a screenshot of See inside and of Compare-// (Normal's is the setup's own screenshot); a mode button the page lacks is named. At the desktop and reduced-motion-// setups, with the stage at rest (a scroll page with its box at the middle of its range, a loop paused, a plays-once page-// with Loop off and its replay over), the box does not scroll either, See inside and Compare must each change the stage and-// differ from each other, Normal must bring the first picture back, and on a scroll page Play must keep scrolling through a-// mode change. Each mode's screenshot is taken after that mode's own picture checks, by scrolling the page until the step shows-// and taking it with plain clips (in parts, joined, where it is taller than the window), so the window is not resized and no-// scroll box moves: the Normal check that follows sees the page as it was. Chrome's capture beyond the viewport, which resizes the-// window for a moment and sends every scroll box to the top (a page can redraw itself for that), is only the last resort for a-// step that cannot be made to show. Either way each of those two screenshots must show the stage as it was seen at rest in that-// mode (the stage is cut out of it and compared, and the screenshot taken again, after putting the box back, up to three more-// times if it differs). A stage that never comes to rest is a problem of its own, and nothing is compared with a frame taken in-// mid-movement.+// moves neither the page nor the keyboard focus (the pressed button itself may take it), and the box keeps its size and the+// player bar its place under it (a stage that grows with its text, hb-grow, aside). In each mode the labels and half names+// (data-hb-caption) on show must be inside the stage, at least 12px as drawn, clear of each other and at most six (four on+// phones); no id may be used twice (a copy that kept one); a control in the stage named with aria-label must say its visible+// words (text hidden from screen readers, see-through, hidden or clipped to nothing is not counted); and where the page names+// its picture (an aria-label on the stage, or on its canvas or picture), each mode must name it differently. A plays-once page+// is tried with Loop off and a do-it page from rest (Reset where it has one). On both, except under reduced motion, a press of+// See inside or Compare plays the demo once (the shared script presses Replay or Show me), and the check waits for that run to+// end (no timer of the page set for 6 s or less still waiting, no animation on the stage running apart from endless ones; up+// to 30 s, and at once where the press starts no run) and then for the stage to rest before it looks. Only setTimeout timers+// and animations are seen: a run driven by a frame loop or by setInterval shows only as a stage that changes, so a pause of+// 750 ms or more inside it would pass for rest (a run holds its pauses with setTimeout). The stage is at rest when it has not+// changed for 750 ms; every animation in it that never ends (a blinking caret, a loader) is held at its first frame while rest+// is judged and the rest pictures and mode screenshots are taken. The whole Watch step (its heading, the switch, the stage, the+// player bar and the notes) is saved as a screenshot of See inside and of Compare (Normal's is the setup's own screenshot); a+// mode button the page lacks is named. At the desktop and reduced-motion setups, with the stage at rest (a scroll page with its+// box at the middle of its range, a loop paused), the box does not scroll either (read before the run a press starts, which may+// scroll it), See inside and Compare must each change the stage and differ from each other, Normal must bring the first+// picture back, and on a scroll page Play must keep scrolling through a mode change. Each mode's screenshot is taken after+// that mode's own picture checks, by scrolling the page until the step shows and taking it with plain clips (in parts, joined,+// where it is taller than the window), so the window is not resized and no scroll box moves: the Normal check that follows sees+// the page as it was. Chrome's capture beyond the viewport, which resizes the window for a moment and sends every scroll box to+// the top (a page can redraw itself for that), is only the last resort for a step that cannot be made to show. Either way each of+// those two screenshots must show the stage as it was seen at rest in that mode (the stage is cut out of it and compared, and the+// screenshot taken again, after putting the box back, up to three more times if it differs). A stage that never comes to rest is+// a problem of its own, and nothing is compared with a frame taken in mid-movement.// Without --out every run writes into a new hb-check-<date>-<time>-<process id> folder (--out picks another one).// Nothing is emptied or removed, so runs going on at the same time, in other lanes or terminals, never wipe each// other's screenshots. The temporary Chrome profile (hb-chrome-* in the temp folder) is removed when the run ends, trying@@ -173,6 +185,21 @@ const STARS = `(() => {try { localStorage.setItem('gh-star-count', JSON.stringify({ count: 1234, ts: Date.now() })); } catch {}})()`;+// Runs at the start of every document, before the page's own scripts: keeps count of the page's timers that are still waiting+// (those set for 6 s or less: a longer one is not part of a run), so the mode check can tell when a run has ended.+const TIMERS = `(() => {+ const waiting = new Set(), set = window.setTimeout, clear = window.clearTimeout, clearI = window.clearInterval;+ window.setTimeout = function (fn, ms, ...rest) {+ if (typeof fn !== 'function') return set.apply(window, arguments);+ const id = set.call(window, function () { waiting.delete(id); return fn.apply(this, arguments); }, ms, ...rest);+ if (!(ms > 6000)) waiting.add(id);+ return id;+ };+ window.clearTimeout = function (id) { waiting.delete(id); return clear.call(window, id); };+ window.clearInterval = function (id) { waiting.delete(id); return clearI.call(window, id); };+ window.__hbWaiting = () => waiting.size;+})()`;+const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));const withTimeout = (promise, ms) => Promise.race([promise, sleep(ms).then(() => { throw new Error('timeout'); })]);@@ -269,17 +296,55 @@ async function stageShot() {return (await send('Page.captureScreenshot', { format: 'png', clip: { ...box, scale: 1 } })).data;}-// Waits 3 s for the demo to settle, then (for slower demos) until two captures 250ms apart match.-async function settledShot() {- await sleep(3000);- let shot = await stageShot();- for (let i = 0; i < 10; i++) {- await sleep(250);- const next = await stageShot();- if (next === shot) break;- shot = next;+// Animations in the stage that never end (iterations Infinity: a blinking caret, a loader) would keep the stage from ever coming+// to rest, and two pictures of the same moment would differ by where they happen to be. While the check judges rest and takes its+// rest pictures and the mode screenshots, holdEndless() pauses each one that runs at its first frame (each call also takes any+// that started since the last), and releaseEndless() puts each back where it was and lets it run on (one the page has dropped+// meanwhile is left alone). A loop the page has paused is not touched, and waitForRun never counts such an animation as a run.+const holdEndless = () => evaluate(`(() => {+ const stage = document.querySelector('.hb-page .stage'), held = window.__hbHeld || (window.__hbHeld = []);+ for (const a of document.getAnimations()) {+ const t = a.effect && a.effect.target;+ if (a.playState !== 'running' || !t || !stage.contains(t) || a.effect.getComputedTiming().iterations !== Infinity) continue;+ held.push({ a, time: a.currentTime });+ a.pause();+ a.currentTime = 0;+ }+})()`);+const releaseEndless = () => evaluate(`(() => {+ for (const { a, time } of window.__hbHeld || []) if (a.playState === 'paused') { a.currentTime = time; a.play(); }+ window.__hbHeld = [];+})()`);+// The stage as stageShot takes it, with the animations that never end held as for a rest picture, so that comparing it with+// one shows only a real change.+async function heldShot() {+ try {+ await holdEndless();+ return await stageShot();+ } finally {+ await releaseEndless();+ }+}++// The stage once it has come to rest: after waiting `wait` ms, captures 250 ms apart until the picture has stayed the same for+// 750 ms (four captures in a row), for up to 10 s, with the animations that never end held (see holdEndless). still says whether+// it did; when it did not, shot is only the last frame of a movement that goes on and is not worth comparing with anything.+async function restShot(wait = 0) {+ if (wait) await sleep(wait);+ try {+ await holdEndless();+ let shot = await stageShot(), same = 0;+ for (const end = Date.now() + 10000; Date.now() < end;) {+ await sleep(250);+ await holdEndless();+ const next = await stageShot();+ if (next !== shot) { shot = next; same = 0; continue; }+ if (++same === 3) return { shot, still: true };+ }+ return { shot, still: false };+ } finally {+ await releaseEndless();}- return shot;}// Plays-once pages: with Loop off and the demo settled, pressing Replay and changing a setting must each@@ -292,11 +357,11 @@ async function movementProblems() {})()`);if (!ready) return ['no stage or Replay button to check'];const problems = [];- const settled = await settledShot();+ const settled = (await restShot(3000)).shot;await evaluate(`document.querySelector('[data-hb-replay]').click()`);await sleep(120);- if (await stageShot() === settled) problems.push('Replay does not visibly move the stage');- const settledAgain = await settledShot();+ if (await heldShot() === settled) problems.push('Replay does not visibly move the stage');+ const settledAgain = (await restShot(3000)).shot;const clicked = await evaluate(`(() => {const choice = [...document.querySelectorAll('.hb-try .seg button')].find(b => b.getAttribute('aria-pressed') !== 'true' && b.getClientRects().length);@@ -305,7 +370,7 @@ async function movementProblems() {})()`);if (clicked) {await sleep(370);- if (await stageShot() === settledAgain) problems.push('changing a setting does not replay the stage');+ if (await heldShot() === settledAgain) problems.push('changing a setting does not replay the stage');}return problems;}@@ -320,19 +385,6 @@ async function stageChanges(ms) {return false;}-// The stage once it has stopped changing: captures 250 ms apart until two in a row match (up to 4 s). still says whether it-// did; when it did not, shot is only the last frame of a movement that goes on and is not worth comparing with anything.-async function stillShot() {- let shot = await stageShot();- for (let i = 0; i < 16; i++) {- await sleep(250);- const next = await stageShot();- if (next === shot) return { shot, still: true };- shot = next;- }- return { shot, still: false };-}-// What a scroll page moves: its own scroller where it has one, else the stage.const BOX = `(document.querySelector('[data-hb-scroller]') || document.querySelector('.hb-page .stage'))`;@@ -406,9 +458,113 @@ async function watchStepShot() {return { png, stage, ratio: g.ratio };}+// After a press that may start a run (Replay or Show me, pressed by the shared script after a mode press, or Reset): waits until+// no timer of the page set for 6 s or less is waiting (TIMERS counts them) and no animation on the stage runs (one that never+// ends, such as a blinking caret, does not count), three looks in a row 100 ms apart, for up to 30 s: a run as long as Kinetic+// Typography's (about 16 s, 26 s at Slow) is waited out, and where no run starts the wait ends at once. A run often holds still+// on a timer between two moves, so a stage that has not changed for a while is not yet a run that has ended. A frame loop or a+// setInterval is not seen here: such a run is waited for only by restShot, so its pauses must be setTimeout holds. Says whether+// it ended.+async function waitForRun() {+ const calm = () => evaluate(`(() => {+ const stage = document.querySelector('.hb-page .stage');+ const busy = document.getAnimations().some(a => {+ const t = a.effect && a.effect.target;+ return a.playState === 'running' && t && stage.contains(t) && a.effect.getComputedTiming().endTime !== Infinity;+ });+ return !busy && (window.__hbWaiting ? window.__hbWaiting() : 0) === 0;+ })()`);+ let quiet = 0;+ for (const end = Date.now() + 30000; Date.now() < end; await sleep(100)) {+ quiet = (await calm()) ? quiet + 1 : 0;+ if (quiet === 3) return true;+ }+ return false;+}++// The name the page gives its picture (the stage's aria-label, else its canvas's or picture's), or null where it gives none.+const pictureName = () => evaluate(`(() => {+ const stage = document.querySelector('.hb-page .stage');+ const named = stage.hasAttribute('aria-label') ? stage : stage.querySelector('canvas[aria-label], [role="img"][aria-label], svg[aria-label]');+ return named ? named.getAttribute('aria-label') : null;+})()`);++// The labels and half names (data-hb-caption) of the mode on show: every one that is drawn must be inside the stage, at least+// 12px as drawn (its smallest text, scaled as it is drawn) and clear of the others, and there are at most six (four on phones).+// No id may be used twice on the page (a copy that kept one), and a control in the stage that is named with aria-label must say+// its visible words (only the words it shows: see shownText). label names the mode in each problem.+async function captionProblems(label) {+ const found = await evaluate(`(() => {+ const stage = document.querySelector('.hb-page .stage'), s = stage.getBoundingClientRect(), out = [];+ const drawn = el => el.getClientRects().length > 0 &&+ el.checkVisibility({ opacityProperty: true, visibilityProperty: true, checkOpacity: true, checkVisibilityCSS: true });+ const words = el => (el.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 40);+ const size = el => {+ const texts = [el, ...el.querySelectorAll('*')].filter(n => [...n.childNodes].some(c => c.nodeType === 3 && c.textContent.trim()));+ return Math.min(...texts.map(n => {+ const r = n.getBoundingClientRect(), own = n instanceof SVGGraphicsElement ? n.getBBox().height : n.offsetHeight;+ return parseFloat(getComputedStyle(n).fontSize) * (own > 0 ? r.height / own : 1);+ }));+ };+ const caps = [...stage.querySelectorAll('[data-hb-caption]')].filter(drawn).map(el => ({ el, r: el.getBoundingClientRect() }));+ const most = innerWidth <= 600 ? 4 : 6;+ if (caps.length > most) out.push(caps.length + ' labels (at most ' + most + ' here)');+ for (const { el, r } of caps) {+ if (r.left < s.left - 1 || r.right > s.right + 1 || r.top < s.top - 1 || r.bottom > s.bottom + 1) out.push('the label "' + words(el) + '" is not inside the stage');+ const px = size(el);+ if (px < 11.95) out.push('the label "' + words(el) + '" is drawn at ' + px.toFixed(1) + 'px (at least 12px)');+ }+ for (let i = 0; i < caps.length; i++) for (let j = i + 1; j < caps.length; j++) {+ const a = caps[i], b = caps[j];+ if (a.el.contains(b.el) || b.el.contains(a.el)) continue;+ if (a.r.left < b.r.right - 1 && b.r.left < a.r.right - 1 && a.r.top < b.r.bottom - 1 && b.r.top < a.r.bottom - 1) out.push('the labels "' + words(a.el) + '" and "' + words(b.el) + '" overlap');+ }+ const ids = [...document.querySelectorAll('[id]')].map(e => e.id), twice = [...new Set(ids.filter((id, i) => ids.indexOf(id) !== i))];+ if (twice.length) out.push('ids used twice: ' + twice.join(', '));+ const wordsOf = t => (t || '').toLowerCase().replace(/[^\\p{L}\\p{N}]+/gu, ' ').trim();+ // The words a control shows, parted where innerText parts them (at the edge of a block and at a line break), leaving out+ // every text that is not drawn: inside an aria-hidden="true" part, see-through (opacity 0, on it or on a part around it),+ // hidden (visibility), with no box at all (not rendered, or scaled down to nothing), or clipped to nothing (inside a box under+ // 2px across that clips what overflows it, as a text kept for screen readers only is). So the closed cards a button holds out+ // of sight (Dynamic Island) or a second label waiting see-through (Copy to Clipboard's Copied!) are not its words.+ const shownText = c => {+ const blockOf = n => { for (let e = n.parentElement; e !== c; e = e.parentElement) if (!getComputedStyle(e).display.startsWith('inline')) return e; return c; };+ const clipped = n => {+ for (let e = n.parentElement; ; e = e.parentElement) {+ const st = getComputedStyle(e), r = e.getBoundingClientRect();+ if ((st.overflowX !== 'visible' || st.overflowY !== 'visible') && (r.width < 2 || r.height < 2)) return true;+ if (e === c) return false;+ }+ };+ const walk = document.createTreeWalker(c, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);+ let text = '', last = null;+ for (let n = walk.nextNode(); n; n = walk.nextNode()) {+ if (n.nodeType !== 3) { if (n.tagName === 'BR') text += ' '; continue; }+ const el = n.parentElement, range = document.createRange();+ range.selectNodeContents(n);+ if (el.closest('[aria-hidden="true"]') || !el.checkVisibility({ opacityProperty: true, visibilityProperty: true, checkOpacity: true, checkVisibilityCSS: true })+ || ![...range.getClientRects()].some(r => r.width > 0 && r.height > 0) || clipped(n)) continue;+ const block = blockOf(n);+ text += (last && block !== last ? ' ' : '') + n.textContent;+ last = block;+ }+ return text;+ };+ for (const c of stage.querySelectorAll('button, a[href], input, select, textarea, [role="button"], [role="link"], [role="switch"], [role="checkbox"], [role="tab"]')) {+ if (!c.getClientRects().length || c.closest('[inert], [aria-hidden="true"]')) continue;+ // a form field's value is not its label; only an input button shows its words as its value+ const shown = c.matches('input[type="button"], input[type="submit"], input[type="reset"]') ? c.value : c.matches('input, select, textarea') ? '' : shownText(c);+ const own = wordsOf(c.getAttribute('aria-label')), seen = wordsOf(shown);+ if (own && seen && !own.includes(seen)) out.push('the control "' + shown.replace(/\\s+/g, ' ').trim().slice(0, 40) + '" is named "' + c.getAttribute('aria-label') + '", which leaves out its visible words');+ }+ return out;+ })()`);+ return found.map(p => `${label}: ${p}`);+}+// Pages with the mode switch: see the header comment. name and setup name the screenshots; kind is the page kind. The page is-// left in Normal; at the desktop and reduced-motion setups a loop is also left paused, a plays-once page with Loop off and a-// scroll page with Play stopped and the box at the top.+// left in Normal and, on a plays-once page, with Loop off; at the desktop and reduced-motion setups a loop is also left paused+// and a scroll page with Play stopped and the box at the top.async function modeProblems(name, setup, kind) {if (!(await evaluate(`!!document.querySelector('[data-hb-modes]')`))) return [];// An earlier check may have left the pointer over the stage, and the page is scrolled to take the screenshots, which would end@@ -427,6 +583,9 @@ async function modeProblems(name, setup, kind) {if (!b) return false;const box = ${BOX};window.__hbBefore = { button: b, focus: document.activeElement, x: scrollX, y: scrollY, top: box ? box.scrollTop : 0 };+ // Where the box is once the page has drawn the mode (its own hb:mode listener came first) and before the run the shared+ // script then starts: look(true) reads the box from here.+ document.addEventListener('hb:mode', () => { window.__hbBefore.atMode = box ? box.scrollTop : 0; }, { once: true });b.click();return true;})()`);@@ -434,18 +593,26 @@ async function modeProblems(name, setup, kind) {return found;};// What the page shows now: the mark on the stage, the notes on show (by the mode each belongs to; a note counts only when the- // box around the notes is rendered, taller than 1px, not clipped away), any sideways overflow, and what the last press- // changed: the page's scroll, the box's scroll, and keyboard focus (named when it went anywhere but to the pressed button).- const look = () => evaluate(`(() => {+ // box around the notes is rendered, taller than 1px, not clipped away), any sideways overflow, the box's height and how far+ // below its top the player bar starts (and whether the box grows with its text, hb-grow), and what the last press changed: the+ // page's scroll, the box's scroll, and keyboard focus (named when it went anywhere but to the pressed button). With run (the+ // press may have started a run: Replay or Show me, pressed by the shared script), the box is read as it was when the page had+ // drawn the mode, before that run began, since a run may scroll its box (the Scroll it do-it pages do); without a hb:mode+ // heard, it is read now.+ const look = (run = false) => evaluate(`(() => {const was = window.__hbBefore, a = document.activeElement, wrap = document.querySelector('.hb-mode-notes'), box = ${BOX};+ const stage = document.querySelector('.hb-page .stage'), bar = document.querySelector('.hb-player'), s = stage.getBoundingClientRect();const name = el => el.tagName.toLowerCase() + (el.id ? '#' + el.id : '') + (el.getAttribute('class') ? '.' + el.getAttribute('class').split(' ')[0] : '');const rendered = !!wrap && wrap.getBoundingClientRect().height > 1;return {mode: document.querySelector('.hb-page .stage').getAttribute('data-hb-mode'),overflow: document.documentElement.scrollWidth > document.documentElement.clientWidth + 1,notes: rendered ? [...wrap.querySelectorAll('[data-hb-for]:not([hidden])')].map(n => n.getAttribute('data-hb-for')) : [],+ stageH: Math.round(s.height),+ barTop: bar ? Math.round(bar.getBoundingClientRect().top - s.top) : null,+ grow: stage.classList.contains('hb-grow'),page: !!was && (scrollX !== was.x || scrollY !== was.y),- box: !!was && !!box && Math.abs(box.scrollTop - was.top) >= 1,+ box: !!was && !!box && Math.abs((${run} && was.atMode !== undefined ? was.atMode : box.scrollTop) - was.top) >= 1,focus: was && a && a !== was.focus && a !== was.button ? name(a) : ''};})()`);@@ -460,28 +627,41 @@ async function modeProblems(name, setup, kind) {// The whole Watch step saved as the screenshot of a mode (see watchStepShot). expected is the stage's picture seen at rest in// this mode (none at the lighter setups, where the stage may be moving): the stage cut out of the screenshot must be that// picture. If it is not, the box is put back, the page given a moment, and the screenshot taken again, up to three more times;- // a screenshot that never shows the stage as it was seen is a problem of its own.+ // a screenshot that never shows the stage as it was seen is a problem of its own. With a picture to show, animations that never+ // end are held as they were for it (see holdEndless).const capture = async (mode, expected) => {let png = '', shows = !expected;- for (let attempt = 0; attempt === 0 || (!shows && attempt < 4); attempt++) {- if (attempt) await sleep(300);- await settleBox();- const got = await watchStepShot();- png = got.png;- if (expected) shows = await stageInShot(png, expected, got.stage, got.ratio);+ try {+ for (let attempt = 0; attempt === 0 || (!shows && attempt < 4); attempt++) {+ if (attempt) await sleep(300);+ await settleBox();+ if (expected) await holdEndless();+ const got = await watchStepShot();+ png = got.png;+ if (expected) shows = await stageInShot(png, expected, got.stage, got.ratio);+ }+ } finally {+ await releaseEndless();}writeFileSync(join(OUT, `${name}-${setup.name}-${mode}.png`), Buffer.from(png, 'base64'));if (!shows) problems.push(`the ${labels[mode]} screenshot does not show the stage as checked`);};const deep = !!(setup.moves || setup.reduce);+ // A press of See inside or Compare on a plays-once or do-it page also plays the demo once (the shared script presses Replay or+ // Show me), except under reduced motion: at every setup the check then waits for that run to end and for the stage to rest.+ const runs = (kind === 'once' || kind === 'do') && !setup.reduce;// The pictures are compared at the deep setups, except for a scroll page with no Back to top button: its box cannot be// brought to the top, so nothing is compared there (the Play check below names the missing button).let pictures = deep;if (deep) {if (kind === 'scroll') pictures = await evaluate(`(() => { const t = document.querySelector('[data-hb-top]'); if (t) t.click(); return !!t; })()`);if (kind === 'loop') await evaluate(`(() => { const p = document.querySelector('[data-hb-pause]'); if (p && p.getAttribute('data-state') !== 'paused') p.click(); })()`);- if (kind === 'once') await evaluate(`(() => { const l = document.querySelector('[data-hb-loop]'); if (l && l.checked) l.click(); })()`);}+ // A plays-once page is tried with Loop off at every setup, so each play ends; a do-it page from rest, with Reset where it has+ // one. Whatever still runs then (the last play, the run on arrival, a result that goes back on a timer) is waited for.+ if (kind === 'once') await evaluate(`(() => { const l = document.querySelector('[data-hb-loop]'); if (l && l.checked) l.click(); })()`);+ if (kind === 'do') await evaluate(`(() => { const r = document.querySelector('[data-hb-reset]'); if (r) r.click(); })()`);+ if ((kind === 'once' || kind === 'do') && !(await waitForRun())) problems.push('the demo does not come to rest before the modes are tried (a timer or an animation of the page keeps going for 30 s)');// A scroll page is tried with its box at the middle of its range: there a scroll-driven effect shows something, a mode change// that sends the box back to the top or draws for the top is seen, and Compare shows its difference in the screenshot.if (pictures && kind === 'scroll') await evaluate(`(() => { const b = ${BOX}; b.scrollTo({ top: (b.scrollHeight - b.clientHeight) / 2, behavior: 'instant' }); })()`);@@ -491,36 +671,46 @@ async function modeProblems(name, setup, kind) {if (pictures && now.box) problems.push(`${label}: the box scrolled`);if (now.focus) problems.push(`${label}: keyboard focus moved to ${now.focus}`);};- // The first picture is the stage at rest. A plays-once page can still be replaying after the Replay and setting checks, so- // it waits for that to end first. A stage that never comes to rest is said so, and then no picture is compared with it.+ // The first picture is the stage at rest. A stage that never comes to rest is said so, and then no picture is compared with it.let first = null;if (pictures) {- if (kind === 'once') await settledShot();- const rest = await stillShot();+ const rest = await restShot();if (rest.still) first = rest.shot;else problems.push('the stage does not come to rest before the modes are tried');restTop = await evaluate(`(() => { const b = ${BOX}; return b ? b.scrollTop : 0; })()`);}- const shots = {};+ // Normal before any press: the box's size and where the player bar starts below it. No mode may change either (ruling 4: the+ // box keeps its size and nothing under it moves); a stage that grows with its text (hb-grow) is left out.+ const normal = await look();+ const sized = (label, now) => {+ if (normal.grow) return;+ if (now.stageH !== normal.stageH) problems.push(`${label}: the box changes size (${now.stageH}px, not ${normal.stageH}px)`);+ else if (now.barTop !== normal.barTop) problems.push(`${label}: the player bar moves (${now.barTop}px below the top of the box, not ${normal.barTop}px)`);+ };+ const shots = {}, named = {};for (const mode of ['inside', 'compare']) {const label = labels[mode];await settleBox();if (!(await press(mode))) continue;await sleep(700);- const now = await look();+ const now = await look(runs);if (now.mode !== mode) problems.push(`${label}: the stage is not marked data-hb-mode="${mode}"`);if (now.overflow) problems.push(`${label}: horizontal overflow`);if (!now.notes.includes(mode)) problems.push(`${label}: its note is not shown`);if (now.notes.some(n => n !== mode)) problems.push(`${label}: the other note is still shown`);unmoved(label, now);- if (pictures) {- const rest = await stillShot();+ sized(label, now);+ if (runs && !(await waitForRun())) problems.push(`${label}: the run it started does not end within 30 s`);+ if (pictures || runs) {+ const rest = await restShot();if (!rest.still) problems.push(`the stage does not come to rest in ${label}`);- else {+ else if (pictures) {shots[mode] = rest.shot;if (first && await samePicture(rest.shot, first)) problems.push(`${label} does not change the stage`);}}+ problems.push(...await captionProblems(label));+ named[mode] = await pictureName();await capture(mode, shots[mode]);}if (shots.inside && shots.compare && await samePicture(shots.inside, shots.compare)) problems.push('See inside and Compare show the same picture');@@ -533,11 +723,20 @@ async function modeProblems(name, setup, kind) {if (now.overflow) problems.push('Normal: horizontal overflow');if (now.notes.length) problems.push('Normal: a note is still shown');unmoved('Normal', now);+ sized('Normal', now);if (pictures) {- const rest = await stillShot();+ const rest = await restShot();if (!rest.still) problems.push('the stage does not come to rest in Normal');else if (first && !(await samePicture(rest.shot, first))) problems.push('Normal does not bring the first picture back');}+ problems.push(...await captionProblems('Normal'));+ named.normal = await pictureName();+ }+ // Where the page names its picture, each mode names it differently, so a screen reader hears what each one shows.+ if (typeof named.normal === 'string') {+ for (const [a, b] of [['normal', 'inside'], ['normal', 'compare'], ['inside', 'compare']]) {+ if (typeof named[a] === 'string' && named[a] === named[b]) problems.push(`the picture's name is the same in ${labels[a]} and ${labels[b]}: "${named[a]}"`);+ }}// Play keeps scrolling when the mode changes (Play still works under reduced motion, so this runs there too).if (deep && kind === 'scroll') {@@ -1237,6 +1436,7 @@ try {await send('Page.enable');await send('Runtime.enable');await send('Log.enable');+ await send('Page.addScriptToEvaluateOnNewDocument', { source: TIMERS });await send('Page.addScriptToEvaluateOnNewDocument', { source: RECORD });if (pages.includes('home')) await send('Page.addScriptToEvaluateOnNewDocument', { source: STARS });