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: support looping demos with Pause and CSS slow motion

matina31d525eb9b9
diff --git a/animations/02-entrance-and-exit/blur-in/index.html b/animations/02-entrance-and-exit/blur-in/index.html
index eb384c1c..ff9b86d3 100644
--- a/animations/02-entrance-and-exit/blur-in/index.html
+++ b/animations/02-entrance-and-exit/blur-in/index.html
@@ -38,8 +38,8 @@
.card[data-mode="fade-only"].in{opacity:1}
@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important;filter:none!important;transform:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/bounce-in/index.html b/animations/02-entrance-and-exit/bounce-in/index.html
index 2d6c44bf..f61647c5 100644
--- a/animations/02-entrance-and-exit/bounce-in/index.html
+++ b/animations/02-entrance-and-exit/bounce-in/index.html
@@ -35,8 +35,8 @@
@media(prefers-reduced-motion:reduce){.card.in{animation:none!important;opacity:1;transform:none}.card.out{animation:none!important;opacity:0}}
</style>
<style id="kf-style"></style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/clip-path-reveal/index.html b/animations/02-entrance-and-exit/clip-path-reveal/index.html
index dbd5d52e..093c3231 100644
--- a/animations/02-entrance-and-exit/clip-path-reveal/index.html
+++ b/animations/02-entrance-and-exit/clip-path-reveal/index.html
@@ -34,8 +34,8 @@
.surface-title{font-size:clamp(22px,4vw,36px);font-weight:bold}
@media(prefers-reduced-motion:reduce){.surface{opacity:0;transition:opacity 400ms linear!important;clip-path:none!important}.surface.in{opacity:1}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/curtain-reveal/index.html b/animations/02-entrance-and-exit/curtain-reveal/index.html
index 07ae195a..9208ce7f 100644
--- a/animations/02-entrance-and-exit/curtain-reveal/index.html
+++ b/animations/02-entrance-and-exit/curtain-reveal/index.html
@@ -38,8 +38,8 @@
.curtain.c-out,.curtain-b.c-out{transform:var(--to)}
@media(prefers-reduced-motion:reduce){.curtain,.curtain-b{transition:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/fade-in-out/index.html b/animations/02-entrance-and-exit/fade-in-out/index.html
index d1b51871..bdaed542 100644
--- a/animations/02-entrance-and-exit/fade-in-out/index.html
+++ b/animations/02-entrance-and-exit/fade-in-out/index.html
@@ -32,8 +32,8 @@
.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}
@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/flip-in/index.html b/animations/02-entrance-and-exit/flip-in/index.html
index a5883b2a..e0a08080 100644
--- a/animations/02-entrance-and-exit/flip-in/index.html
+++ b/animations/02-entrance-and-exit/flip-in/index.html
@@ -33,8 +33,8 @@
.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}
@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important;transform:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
index 278b3f46..5d873a42 100644
--- a/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
+++ b/animations/02-entrance-and-exit/letter-by-letter-stagger/index.html
@@ -41,8 +41,8 @@
@keyframes blink{0%,50%{opacity:1}51%,100%{opacity:0}}
@media(prefers-reduced-motion:reduce){.char{transition:none!important;opacity:1!important;transform:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/rotate-in/index.html b/animations/02-entrance-and-exit/rotate-in/index.html
index b0f8b560..dab6378d 100644
--- a/animations/02-entrance-and-exit/rotate-in/index.html
+++ b/animations/02-entrance-and-exit/rotate-in/index.html
@@ -31,8 +31,8 @@
.icon svg{width:100%;height:100%}
@media(prefers-reduced-motion:reduce){.icon{transition:opacity 300ms linear!important;transform:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/scale-in/index.html b/animations/02-entrance-and-exit/scale-in/index.html
index 037850d8..2f00e677 100644
--- a/animations/02-entrance-and-exit/scale-in/index.html
+++ b/animations/02-entrance-and-exit/scale-in/index.html
@@ -33,8 +33,8 @@
.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}
@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important;transform:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/slide-in/index.html b/animations/02-entrance-and-exit/slide-in/index.html
index 0ca4610c..5ecf617d 100644
--- a/animations/02-entrance-and-exit/slide-in/index.html
+++ b/animations/02-entrance-and-exit/slide-in/index.html
@@ -33,8 +33,8 @@
.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}
@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/slide-up-reveal/index.html b/animations/02-entrance-and-exit/slide-up-reveal/index.html
index 2962e9c8..2d80dec7 100644
--- a/animations/02-entrance-and-exit/slide-up-reveal/index.html
+++ b/animations/02-entrance-and-exit/slide-up-reveal/index.html
@@ -33,8 +33,8 @@
.sub-line{font-size:clamp(13px,2vw,16px);color:var(--ui-muted);text-align:center}
@media(prefers-reduced-motion:reduce){.line{opacity:0;transition:opacity 300ms linear!important;transform:none!important;clip-path:none!important} .line.in{opacity:1!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/split-text-reveal/index.html b/animations/02-entrance-and-exit/split-text-reveal/index.html
index 13cf93c0..b6dfb92b 100644
--- a/animations/02-entrance-and-exit/split-text-reveal/index.html
+++ b/animations/02-entrance-and-exit/split-text-reveal/index.html
@@ -45,8 +45,8 @@
[data-mode="chars"] .unit{margin-right:0.01em}
@media(prefers-reduced-motion:reduce){.unit,.unit-inner{transition:opacity 300ms linear!important;transform:none!important}[data-mode="lines"] .unit{opacity:0}.splitting.in .unit{opacity:1}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/animations/02-entrance-and-exit/word-by-word-reveal/index.html b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
index d078849e..8852204a 100644
--- a/animations/02-entrance-and-exit/word-by-word-reveal/index.html
+++ b/animations/02-entrance-and-exit/word-by-word-reveal/index.html
@@ -36,8 +36,8 @@
.sent-break{display:block;height:0.4em}
@media(prefers-reduced-motion:reduce){.word{transition:opacity 300ms linear!important;transform:none!important;filter:none!important}}
</style>
- <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=2">
- <script src="../../../assets/js/demo-page.js?v=2" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
diff --git a/assets/css/demo-page.css b/assets/css/demo-page.css
index 7ef6a4cf..e7ec1f47 100644
--- a/assets/css/demo-page.css
+++ b/assets/css/demo-page.css
@@ -71,7 +71,14 @@ body.hb [hidden]{display:none!important}
/* Under reduced motion the shared script switches Loop and Slow motion off, greys them out and adds a note */
.hb-toggle.is-disabled{opacity:.45;cursor:not-allowed}
.hb-toggle.is-disabled .hb-switch{cursor:not-allowed}
-.hb-player-note{flex-basis:100%;margin:0;font:400 13px/1.4 var(--hb-font);color:var(--hb-muted)}
+/* The note sits beside the controls when there is room, so it does not push the page down */
+.hb-player-note{flex:1 1 240px;margin:0;font:400 13px/1.4 var(--hb-font);color:var(--hb-muted)}
+/* Pause on loop pages: a pause icon while the demo moves, a play icon while it is paused */
+[data-hb-pause] .hb-i-play,[data-hb-pause][data-state="paused"] .hb-i-pause{display:none}
+[data-hb-pause][data-state="paused"] .hb-i-play{display:inline}
+/* data-hb-pause="css": the shared script puts hb-paused on the stage, which holds every CSS animation on it */
+.hb-page .stage.hb-paused,.hb-page .stage.hb-paused::before,.hb-page .stage.hb-paused::after,
+.hb-page .stage.hb-paused *,.hb-page .stage.hb-paused *::before,.hb-page .stage.hb-paused *::after{animation-play-state:paused!important}
/* Switches: a checkbox drawn as a track and knob (gradients, so no pseudo-elements on the input) */
.hb-switch{appearance:none;-webkit-appearance:none;flex:none;width:32px;height:20px;margin:0;border-radius:999px;cursor:pointer;
@@ -190,9 +197,10 @@ textarea.hb-text{min-height:88px;padding:10px 12px;resize:vertical}
.hb-num{width:30px;height:30px;font-size:15px}
.hb-step-head p{font-size:15px}
/* Three controls do not fit on one line at phone widths: Replay takes the first row, the two switches share the
- second, and the reduced-motion note gets a row of its own */
+ second, and the reduced-motion note gets a row of its own. On a loop page Pause and Slow motion share one row. */
.hb-player{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.hb-play,.hb-player-note{grid-column:1/-1}
+ .hb-player:has(> [data-hb-pause] + .hb-toggle) > .hb-play{grid-column:auto}
.hb-play,.hb-toggle{justify-content:center;gap:8px;padding:0 12px;font-size:14px}
.hb-page .seg button{flex:1 0 auto;padding:0 10px}
.hb-prompt{font-size:16px;line-height:1.6}
diff --git a/assets/js/demo-page.js b/assets/js/demo-page.js
index 38fb5197..2119a952 100644
--- a/assets/js/demo-page.js
+++ b/assets/js/demo-page.js
@@ -1,7 +1,8 @@
/* Animation Handbook — shared behaviour for the guided-steps demo pages.
* Fills in "Your settings", Copy prompt, the README's "What it is" and "Similar
- * animations", plays the demo on arrival, replays it when a setting changes, and
- * greys out Loop and Slow motion under reduced motion.
+ * animations", plays the demo on arrival, replays it when a setting changes, runs
+ * Pause and CSS slow motion on loop pages, and follows reduced motion (Loop and
+ * Slow motion greyed out, loops start paused).
* The pure helpers are exported for tests/demo-page.test.js. */
(function (root, factory) {
var api = factory();
@@ -107,6 +108,16 @@
return s ? '"' + s + '"' : '';
}
+ // The reduced-motion note for the player bar, from what the bar holds ({ loop, slow, pause } as booleans);
+ // '' when reduced motion changes nothing there.
+ function motionNote(has) {
+ var off = [has.loop && 'Loop', has.slow && 'Slow motion'].filter(Boolean);
+ var parts = [];
+ if (has.pause) parts.push('It starts paused');
+ if (off.length) parts.push(off.join(' and ') + (off.length > 1 ? ' are' : ' is') + ' off');
+ return parts.length ? parts.join(' and ') + ' because your device is set to reduce motion.' : '';
+ }
+
/* ---------- Page behaviour ---------- */
var CONTROLS = 'input[type=range], input[type=checkbox], input[type=text], textarea, select, .seg, .swatches';
@@ -170,6 +181,9 @@
var replayCtl = page.querySelector('[data-hb-replay]');
var loopCtl = page.querySelector('[data-hb-loop]');
var slowCtl = page.querySelector('[data-hb-slowmo]');
+ var pauseCtl = page.querySelector('[data-hb-pause]');
+ var stage = page.querySelector('.stage');
+ var player = page.querySelector('.hb-player');
var reduce = win.matchMedia ? win.matchMedia('(prefers-reduced-motion: reduce)') : null;
var promptText = text(promptEl);
@@ -308,10 +322,32 @@
replayTimer = win.setTimeout(replay, 250);
}
- // While the device asks for reduced motion, Loop and Slow motion are switched off and cannot be switched
- // on, and a note in the player bar says why. Replay still plays the demo's gentle version.
+ // Loops: Pause stops the demo and Play starts it again. With data-hb-pause="css" a class on the stage holds its
+ // CSS animations; the "hb:pause" event goes out either way, so a page that runs its own timers can stop them.
+ var paused = false;
+ function setPaused(next) {
+ paused = next;
+ pauseCtl.setAttribute('data-state', paused ? 'paused' : 'playing');
+ var label = pauseCtl.querySelector('.hb-pause-label');
+ if (label) label.textContent = paused ? 'Play' : 'Pause';
+ if (stage && pauseCtl.getAttribute('data-hb-pause') === 'css') stage.classList.toggle('hb-paused', paused);
+ doc.dispatchEvent(new win.CustomEvent('hb:pause', { detail: { paused: paused } }));
+ }
+
+ // Slow motion with data-hb-slowmo="css": while it is on, every CSS animation and transition on the stage runs at a
+ // third of its speed, including ones that start later. Without the value, the page slows its own timings.
+ var slowing = false;
+ function slowStage() {
+ var rate = slowCtl.checked ? 1 / 3 : 1;
+ stage.getAnimations({ subtree: true }).forEach(function (a) { if (a.playbackRate !== rate) a.playbackRate = rate; });
+ slowing = slowCtl.checked;
+ if (slowing) win.requestAnimationFrame(slowStage);
+ }
+
+ // While the device asks for reduced motion, Loop and Slow motion are switched off and cannot be switched on, a
+ // loop starts paused, and a note in the player bar says why. Replay and Play still work.
var playerSwitches = [loopCtl, slowCtl].filter(Boolean);
- var motionNote = null;
+ var noteEl = null;
function followReducedMotion() {
var reduced = !!(reduce && reduce.matches);
playerSwitches.forEach(function (sw) {
@@ -320,17 +356,16 @@
var label = sw.closest('label.hb-toggle');
if (label) label.classList.toggle('is-disabled', reduced);
});
- if (reduced && !motionNote && playerSwitches.length) {
- var names = [loopCtl && 'Loop', slowCtl && 'Slow motion'].filter(Boolean);
- motionNote = doc.createElement('p');
- motionNote.className = 'hb-player-note';
- motionNote.textContent = names.join(' and ') + (names.length > 1 ? ' are' : ' is') +
- ' off because your device is set to reduce motion.';
- var last = playerSwitches[playerSwitches.length - 1];
- (last.closest('label.hb-toggle') || last).insertAdjacentElement('afterend', motionNote);
- } else if (!reduced && motionNote) {
- motionNote.parentNode.removeChild(motionNote);
- motionNote = null;
+ if (reduced && pauseCtl && !paused) setPaused(true);
+ var note = reduced ? motionNote({ loop: !!loopCtl, slow: !!slowCtl, pause: !!pauseCtl }) : '';
+ if (note && !noteEl && player) {
+ noteEl = doc.createElement('p');
+ noteEl.className = 'hb-player-note';
+ noteEl.textContent = note;
+ player.appendChild(noteEl);
+ } else if (!note && noteEl) {
+ noteEl.parentNode.removeChild(noteEl);
+ noteEl = null;
}
}
@@ -338,6 +373,10 @@
if (copyBtn) setUpCopy();
if (tryStep) ['input', 'change', 'click'].forEach(function (type) { tryStep.addEventListener(type, onSettingsChange); });
if (slowCtl) slowCtl.addEventListener('change', replay);
+ if (pauseCtl) pauseCtl.addEventListener('click', function () { setPaused(!paused); });
+ if (slowCtl && stage && stage.getAnimations && slowCtl.getAttribute('data-hb-slowmo') === 'css') {
+ slowCtl.addEventListener('change', function () { if (!slowing) slowStage(); });
+ }
followReducedMotion();
if (reduce && reduce.addEventListener) reduce.addEventListener('change', followReducedMotion);
else if (reduce && reduce.addListener) reduce.addListener(followReducedMotion);
@@ -360,6 +399,6 @@
return {
escapeHtml: escapeHtml, plain: plain, isSafeHref: isSafeHref, inline: inline, sections: sections,
paragraphs: paragraphs, seeAlso: seeAlso, settingsLine: settingsLine, markFill: markFill, shorten: shorten,
- quoteText: quoteText, readSettings: readSettings, boot: boot
+ quoteText: quoteText, motionNote: motionNote, readSettings: readSettings, boot: boot
};
});
diff --git a/tests/demo-page.test.js b/tests/demo-page.test.js
index 024e7df3..a4db01c0 100644
--- a/tests/demo-page.test.js
+++ b/tests/demo-page.test.js
@@ -91,3 +91,12 @@ test('quoteText wraps typed text in quotes and keeps the 40-character cut inside
assert.equal(long.length, 42);
assert.equal(DP.quoteText(' \n ', 40), '');
});
+
+test('motionNote says what reduced motion changes in the player bar', () => {
+ assert.equal(DP.motionNote({ loop: true, slow: true }), 'Loop and Slow motion are off because your device is set to reduce motion.');
+ assert.equal(DP.motionNote({ loop: true }), 'Loop is off because your device is set to reduce motion.');
+ assert.equal(DP.motionNote({ slow: true }), 'Slow motion is off because your device is set to reduce motion.');
+ assert.equal(DP.motionNote({ pause: true, slow: true }), 'It starts paused and Slow motion is off because your device is set to reduce motion.');
+ assert.equal(DP.motionNote({ pause: true }), 'It starts paused because your device is set to reduce motion.');
+ assert.equal(DP.motionNote({}), '');
+});
diff --git a/tests/pages.test.js b/tests/pages.test.js
index 593ff6b9..3da22d3c 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -73,6 +73,13 @@ for (const d of steps) {
assert.equal(count(html, 'data-hb-replay'), 1, 'one Replay control');
assert.ok(player.includes('data-hb-replay'), 'Replay is in the player bar');
}
+ if (kind === 'loop') {
+ assert.equal(count(html, 'data-hb-pause'), 1, 'one Pause control');
+ assert.match(player, /<button class="hb-play" type="button" id="btn-pause" data-hb-pause(?:="css")? data-state="playing">/,
+ 'Pause is in the player bar and starts in the playing state');
+ assert.equal(count(html, 'data-hb-replay') + count(html, 'data-hb-loop') + count(html, 'data-hb-autoplay'), 0,
+ 'a loop has no Replay, Loop or autoplay');
+ }
for (const marker of ['data-hb-loop', 'data-hb-slowmo']) {
assert.ok(count(html, marker) <= 1, `at most one ${marker}`);
assert.equal(count(player, marker), count(html, marker), `${marker} is in the player bar`);
@@ -174,6 +181,11 @@ for (const d of steps) {
});
}
+test('every guided-steps page links the same version of the shared files', () => {
+ const versions = new Set(steps.flatMap(d => [...pageOf(d).matchAll(/demo-page\.(?:css|js)\?v=(\d+)/g)].map(m => m[1])));
+ assert.equal(versions.size, 1, `versions in use: ${[...versions].join(', ')}`);
+});
+
test('the home page uses Schibsted Grotesk and the new intro line', () => {
assert.ok(HOME.includes("url('assets/fonts/schibsted-latin.woff2')"), 'Latin font file');
assert.ok(HOME.includes("url('assets/fonts/schibsted-latin-ext.woff2')"), 'Latin Extended font file');
diff --git a/tools/check-pages.mjs b/tools/check-pages.mjs
index e3e67cc0..33ae0ea2 100644
--- a/tools/check-pages.mjs
+++ b/tools/check-pages.mjs
@@ -7,7 +7,8 @@
// setups; problems are printed and screenshots saved, by default into hb-check in the temp folder (emptied at the
// start of each run). Console warnings count as problems too (the page script warns about settings that have no
// label or value). On plays-once pages the desktop run also checks that Replay and a setting change visibly move
-// the stage. Exit code 1 on any problem.
+// the stage; on loop pages it checks that the stage moves, that Pause stops it and Play starts it again, and the
+// reduced-motion run checks that the loop starts paused. Exit code 1 on any problem.
import { spawn } from 'node:child_process';
import { existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
@@ -189,6 +190,51 @@ async function movementProblems() {
return problems;
}
+// True when the stage shows something different from its first capture within ms milliseconds.
+async function stageChanges(ms) {
+ const first = await stageShot();
+ for (const end = Date.now() + ms; Date.now() < end;) {
+ await sleep(200);
+ if (await stageShot() !== first) return true;
+ }
+ return false;
+}
+
+// Loop pages: the stage keeps changing, holds still after Pause (a step already under way may finish first) and moves
+// again after Play. Under reduced motion the loop starts paused and Play still starts it. With data-hb-slowmo="css",
+// Slow motion must slow every animation on the stage and turning it off must restore the speed.
+async function loopProblems(reduced) {
+ if (!(await evaluate(`!!document.querySelector('[data-hb-pause]')`))) return ['no Pause button to check'];
+ const state = () => evaluate(`document.querySelector('[data-hb-pause]').getAttribute('data-state')`);
+ const press = () => evaluate(`document.querySelector('[data-hb-pause]').click()`);
+ const problems = [];
+ if (reduced) {
+ if (await state() !== 'paused') problems.push('the loop does not start paused under reduced motion');
+ else if (await stageChanges(1500)) problems.push('the stage moves while paused under reduced motion');
+ await press();
+ if (!(await stageChanges(4000))) problems.push('Play does not start the loop under reduced motion');
+ return problems;
+ }
+ if (!(await stageChanges(4000))) return ['the loop is not moving'];
+ await press();
+ await sleep(1500);
+ if (await stageChanges(1500)) problems.push('Pause does not stop the stage');
+ await press();
+ if (!(await stageChanges(4000))) problems.push('Play does not start the stage again');
+ if (await evaluate(`!!document.querySelector('[data-hb-slowmo="css"]')`)) {
+ const rates = () => evaluate(`document.querySelector('.hb-page .stage').getAnimations({ subtree: true }).map(a => a.playbackRate)`);
+ const toggle = () => evaluate(`document.querySelector('[data-hb-slowmo]').click()`);
+ await toggle();
+ await sleep(200);
+ const slow = await rates();
+ if (!slow.length || slow.some(r => r >= 1)) problems.push('Slow motion does not slow the stage');
+ await toggle();
+ await sleep(200);
+ if ((await rates()).some(r => r !== 1)) problems.push('turning Slow motion off does not restore the speed');
+ }
+ return problems;
+}
+
let failures = 0;
try {
ws = new WebSocket(await pageSocket());
@@ -253,6 +299,7 @@ try {
writeFileSync(join(OUT, `${name}-${setup.name}-full.png`), Buffer.from(full.data, 'base64'));
}
if (setup.moves && !setup.reduce && result.kind === 'once') problems.push(...await movementProblems());
+ if (result.kind === 'loop' && (setup.moves || setup.reduce)) problems.push(...await loopProblems(!!setup.reduce));
} catch (err) {
problems.push(`check failed: ${err.message}`);
}