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: rebuild the Rotate In page as the guided-steps pilot

matinb7c7f60fccf7
diff --git a/animations/02-entrance-and-exit/rotate-in/README.md b/animations/02-entrance-and-exit/rotate-in/README.md
index b0e11f67..0afaedab 100644
--- a/animations/02-entrance-and-exit/rotate-in/README.md
+++ b/animations/02-entrance-and-exit/rotate-in/README.md
@@ -11,50 +11,51 @@ Rotate In spins an element around its center as it enters, usually while it grow
- Anywhere the resting shape is symmetric enough that a mid-spin frame still looks intentional
## How it works
-The element starts rotated and scaled down, then transitions both back to their resting values on `.in`. A springy easing gives the spin a slight overshoot so it feels like it lands:
+The element starts rotated and scaled down, then transitions both back to their resting values when the `.in` class is added. A springy easing gives the spin a slight overshoot so it feels like it lands:
```css
.icon{
opacity:0;
transform:rotate(var(--rot-start)) scale(var(--scale-start));
transition:transform var(--dur) var(--ease),
- opacity var(--opacity-dur,var(--dur)) var(--ease)}
+ opacity var(--opacity-dur) var(--ease)}
.icon.in{opacity:1;transform:rotate(0deg) scale(1)}
```
-The starting angle combines a base rotation with any extra full turns, and the direction flips the sign so the spin runs clockwise or counter-clockwise:
+Every setting only changes a custom property. The starting angle is the chosen amount of turn, signed by the direction, and switching the bounce off swaps the springy curve for a smooth one:
```js
-const base=+rotSl.value;
-const extra=extraRot*(dir==='ccw'?-360:360);
-const total=base+extra;
-document.documentElement.style.setProperty('--rot-start',total+'deg');
-document.documentElement.style.setProperty('--scale-start',scaleTog.checked?'0':'1');
+function apply(){
+ vars.setProperty('--rot-start',dir*turn+'deg');
+ vars.setProperty('--dur',dur()+'ms');
+ vars.setProperty('--ease',bounceTog.checked?SPRINGY:SMOOTH);
+ vars.setProperty('--scale-start',scaleTog.checked?'0':'1');
+ vars.setProperty('--opacity-dur',fadeTog.checked?'var(--dur)':'0s');
+}
```
-Extra `±360°` turns don't change the resting frame — the element always lands at `rotate(0deg)` — but they add complete revolutions to the journey, turning a subtle tilt into a full spin.
+A negative starting angle spins clockwise into place and a positive one counter-clockwise; either way the element lands at `rotate(0deg)`. Each play first snaps the icon back to its starting pose with the transition switched off, so a replay always spins in from the beginning. Slow motion multiplies the duration by three.
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Starting rotation | -180° | The angle it starts from; a larger angle means more spin |
-| Extra full rotations | 0× | Adds whole extra turns without changing where it lands |
-| Direction | Counter-clockwise | Which way it spins |
-| Duration | 600ms | Time for the whole spin |
-| Easing | Springy | The overshoot makes the spin land rather than glide to a stop |
-| Combine with scale | on | Growing from small turns a spin into an arrival |
-| Combine with fade | on | Fades it in as it spins |
+| How much it spins | ½ turn | How far it turns on the way in: a quarter turn, half a turn or a full turn |
+| Speed | Normal | How long the spin takes: slow is 1000ms, normal 600ms and fast 350ms |
+| Spin direction | Clockwise | Which way it turns as it lands |
+| Bounce at the end | on | Goes slightly past its resting angle and settles back, so the spin lands instead of gliding to a stop |
+| Grows from small | on | Starts tiny and grows while it spins, which turns a spin into an arrival |
+| Fades in | on | Fades in as it spins instead of appearing at once |
## Production notes
- **Symmetry matters**: rotating text or a rectangle looks like it fell over, not like it entered. The demo deliberately uses a symmetric icon so every intermediate frame reads correctly.
- **Scale sells the arrival**: rotation alone spins the element where it already is; adding `scale(0) → scale(1)` makes it feel like it travels in from nothing. The two combined are what create the "landing" quality.
-- **Decouple opacity timing**: the demo lets fade run on its own duration (`--opacity-dur`) so you can, for example, fade in quickly while the spin continues — a fully-transparent spin start can otherwise look like a glitch.
-- **Reduced motion**: the icon drops to a plain 300ms opacity fade with no rotation or scale when `prefers-reduced-motion` is set.
+- **Decouple opacity timing**: the demo gives the fade its own duration (`--opacity-dur`), so you can, for example, fade in quickly while the spin continues — a fully-transparent spin start can otherwise look like a glitch.
+- **Reduced motion**: the icon drops to a plain 300ms opacity fade with no rotation or scale when `prefers-reduced-motion` is set, and the demo does not loop.
- **Framer Motion**: animate `rotate` and `scale` together in a variant, with a spring transition for the landing overshoot.
- **GSAP**: tween `rotation` and `scale` with a `back.out` ease; `back` provides the overshoot in one keyword.
## See also
-- [Flip In](../flip-in/) — 3D hinge rotation rather than a flat 2D spin
-- [Scale In](../scale-in/) — the scale channel this effect leans on, on its own
-- [Bounce In](../bounce-in/) — another springy, personality-forward entrance
+- [Flip In](../flip-in/) — swings in like a card turning over
+- [Scale In](../scale-in/) — grows from small, with no spin
+- [Bounce In](../bounce-in/) — lands with a springy bounce
diff --git a/animations/02-entrance-and-exit/rotate-in/index.html b/animations/02-entrance-and-exit/rotate-in/index.html
index 69d5bc7a..b9d2b2d5 100644
--- a/animations/02-entrance-and-exit/rotate-in/index.html
+++ b/animations/02-entrance-and-exit/rotate-in/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rotate In — Animation Handbook</title>
- <meta name="description" content="Spins while entering — best on radially-symmetric shapes like icons, stars, and gears.">
+ <meta name="description" content="Spins into place while it grows. Best for icons, stars and badges.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/rotate-in/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,180 +12,201 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Rotate In — Animation Handbook">
- <meta property="og:description" content="Spins while entering — best on radially-symmetric shapes like icons, stars, and gears.">
+ <meta property="og:description" content="Spins into place while it grows. Best for icons, stars and badges.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/rotate-in/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Rotate In — Animation Handbook">
- <meta name="twitter:description" content="Spins while entering — best on radially-symmetric shapes like icons, stars, and gears.">
+ <meta name="twitter:description" content="Spins into place while it grows. Best for icons, stars and badges.">
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Rotate In", "name": "Rotate In", "description": "Spins while entering — best on radially-symmetric shapes like icons, stars, and gears.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/rotate-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Rotate In"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Rotate In", "name": "Rotate In", "description": "Spins into place while it grows. Best for icons, stars and badges.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/rotate-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Rotate In"}</script>
<style>
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#5fd88a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--dur:600ms;--ease:cubic-bezier(.34,1.56,.64,1);--rot-start:-180deg;--scale-start:0}
+ :root{--ui-accent:#5fd88a;--dur:600ms;--ease:cubic-bezier(.34,1.56,.64,1);--rot-start:-180deg;--scale-start:0;--opacity-dur:var(--dur)}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
- header{margin-bottom:20px}
- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(16px,2.2vw,22px);letter-spacing:-.01em}
- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:var(--bg);display:flex;align-items:center;justify-content:center;overflow:hidden}
- .icon-wrap{display:flex;flex-direction:column;align-items:center;gap:24px}
- .icon{width:120px;height:120px;display:flex;align-items:center;justify-content:center;
+ .stage{display:flex;align-items:center;justify-content:center;background:#0b0b0d}
+ .icon{width:150px;height:150px;display:flex;align-items:center;justify-content:center;
opacity:0;transform:rotate(var(--rot-start)) scale(var(--scale-start));
- transition:transform var(--dur) var(--ease),opacity var(--opacity-dur,var(--dur)) var(--ease);will-change:transform,opacity}
+ transition:transform var(--dur) var(--ease),opacity var(--opacity-dur) var(--ease);will-change:transform,opacity}
.icon.in{opacity:1;transform:rotate(0deg) scale(1)}
.icon svg{width:100%;height:100%}
- .icon-label{font-size:11px;color:var(--ui-muted);opacity:0;transition:opacity var(--dur) var(--ease)}
- .icon.in~.icon-label{opacity:1}
- .rot-val-display{font-size:clamp(18px,2.5vw,24px);font-weight:bold;color:var(--ui-accent);opacity:0;transition:opacity var(--dur) var(--ease)}
- .icon.in~.rot-val-display{opacity:1}
@media(prefers-reduced-motion:reduce){.icon{transition:opacity 300ms linear!important;transform:none!important}}
- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}
- .kv .v{color:var(--ui-text)}
- .div{height:1px;background:var(--ui-border)}
- .sr{display:flex;align-items:center;gap:6px;font-size:10px}
- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
- .sv{width:42px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- .seg{display:flex;gap:3px;flex-wrap:wrap}
- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}
- .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}
- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}
- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}
- .btn-row{display:flex;gap:6px}
- button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}
- button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}
- @media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}
- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}}
</style>
-<link rel="stylesheet" href="../../../assets/css/handbook.css">
-<script src="../../../assets/js/handbook.js" defer></script>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css">
+ <script src="../../../assets/js/demo-page.js" defer></script>
</head>
<body class="hb" data-hb-autoplay>
-<nav class="hb-bar" aria-label="Animation Handbook"><a class="hb-home" href="../../../">← <span>Animation Handbook</span></a><span class="hb-pager"><a href="../bounce-in/" rel="prev" aria-label="Previous: Bounce In">‹ <span class="hb-name">Bounce In</span></a></span></nav>
-<main class="hb-view">
- <div class="stage">
- <div class="icon-wrap">
- <div class="icon" id="icon" aria-label="Animated icon">
- <svg viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
+<nav class="hb-bar" aria-label="Animation Handbook">
+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
+ <span class="hb-pager"><a href="../bounce-in/" rel="prev" aria-label="Previous: Bounce In"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span class="hb-dir">Previous:</span> <span class="hb-name">Bounce In</span></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">02.13 · Entrance &amp; Exit</p>
+ <h1>Rotate In</h1>
+ <p class="hb-lede">Spins into place while it grows. Best for icons, stars and badges.</p>
+ </header>
+
+ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">1</span>
+ <div><h2 id="hb-watch-title">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div>
+ </div>
+ <div class="stage hb-dots">
+ <div class="icon" id="icon" role="img" aria-label="A round icon spinning into place">
+ <svg viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle cx="50" cy="50" r="18" fill="#58a6ff" opacity=".9"/>
<circle cx="50" cy="50" r="28" stroke="#58a6ff" stroke-width="3" opacity=".4"/>
<path d="M50 14 L54 22 L63 20 L60 29 L68 33 L60 37 L63 46 L54 44 L50 52 L46 44 L37 46 L40 37 L32 33 L40 29 L37 20 L46 22Z" fill="#58a6ff" opacity=".7"/>
</svg>
</div>
- <div class="icon-label">Landed</div>
</div>
- </div>
- <aside class="hb-side">
- <header class="hb-head">
- <p class="hb-cat">02.13 · Entrance &amp; Exit</p>
- <h1>Rotate In</h1>
- <p class="hb-lede">Spins into place while growing, best for icons, stars and badges.</p>
- </header>
- <section class="hb-settings" aria-label="Settings">
- <h2 class="hb-label">Settings</h2>
- <div class="lbl">State</div>
- <div class="kv"><span>Status</span><span class="v" id="st">hidden</span></div>
- <div class="kv"><span>Rotation</span><span class="v" id="rot-display">-180°</span></div>
- <div class="div"></div>
- <div><div class="lbl" id="rot-lbl">Starting rotation</div>
- <div class="sr"><input type="range" id="rot-sl" aria-labelledby="rot-lbl" min="-720" max="720" value="-180" step="15"><span class="sv" id="rot-v">-180°</span></div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop><span>Loop</span></label>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo><span>Slow motion</span></label>
</div>
- <div class="lbl">Extra full rotations</div>
- <div class="seg" id="extra-seg">
- <button data-x="0" class="on" aria-label="No extra turns">0×</button>
- <button data-x="1" aria-label="One extra turn">+1×</button>
- <button data-x="2" aria-label="Two extra turns">+2×</button>
+ </section>
+
+ <section class="hb-step hb-try" aria-labelledby="hb-try-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">2</span>
+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and the animation plays again.</p></div>
</div>
- <div class="lbl">Direction</div>
- <div class="seg" id="dir-seg">
- <button data-d="ccw" class="on" aria-label="Counter-clockwise">↺ CCW</button>
- <button data-d="cw" aria-label="Clockwise">↻ CW</button>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="spin-lbl">How much it spins</p>
+ <div class="seg" id="spin-seg" role="group" aria-labelledby="spin-lbl">
+ <button type="button" data-turn="90" aria-pressed="false">¼ turn</button>
+ <button type="button" data-turn="180" class="on" aria-pressed="true">½ turn</button>
+ <button type="button" data-turn="360" aria-pressed="false">Full turn</button>
+ </div>
+ <p class="hb-hint">A bigger spin feels more playful.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-ms="1000" aria-pressed="false">Slow</button>
+ <button type="button" data-ms="600" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-ms="350" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">Slow is easy to follow. Fast feels snappy.</p>
+ </div>
</div>
- <div><div class="lbl" id="dur-lbl">Duration</div>
- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="2000" value="600" step="50"><span class="sv" id="dur-v">600ms</span></div>
+ <details class="hb-options">
+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="dir-lbl">Spin direction</p>
+ <div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">
+ <button type="button" data-dir="-1" class="on" aria-pressed="true">Clockwise</button>
+ <button type="button" data-dir="1" aria-pressed="false">Counter-clockwise</button>
+ </div>
+ <p class="hb-hint">Which way it turns as it lands.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Bounce at the end</span><input class="hb-switch" type="checkbox" role="switch" id="bounce-tog" checked></label>
+ <p class="hb-hint">Goes slightly too far, then settles.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Grows from small</span><input class="hb-switch" type="checkbox" role="switch" id="scale-tog" checked></label>
+ <p class="hb-hint">Makes the spin look like an arrival.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-switch-row"><span>Fades in</span><input class="hb-switch" type="checkbox" role="switch" id="fade-tog" checked></label>
+ <p class="hb-hint">Softens the first moment.</p>
+ </div>
+ </div>
+ </details>
+ </section>
+
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
</div>
- <div><div class="lbl">Easing</div>
- <select id="ease-sel">
- <option value="linear">Linear</option>
- <option value="ease-out">Ease out</option>
- <option value="cubic-bezier(.34,1.56,.64,1)" selected>Springy</option>
- <option value="cubic-bezier(.2,.7,.3,1)">Smooth</option>
- </select>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a rotate-in entrance to [the icon or badge you want to animate]. It should spin around its center as it appears. Growing from small at the same time makes it look like it is arriving rather than just turning, and a slight overshoot at the end makes the spin land instead of gliding to a stop. Use this on round or symmetric shapes like icons, stars, gears and badges; it looks wrong on text or wide rectangles. If the visitor has reduced motion turned on, show it in place without spinning. Match the settings listed below.</p>
+ <div class="hb-chips-box" hidden>
+ <p class="hb-chips-title">Your settings</p>
+ <ul class="hb-chips"></ul>
+ </div>
+ <div class="hb-copy-row">
+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
+ </div>
</div>
- <label class="tog" for="scale-tog"><input type="checkbox" id="scale-tog" checked><span>Combine with scale</span></label>
- <label class="tog" for="fade-tog"><input type="checkbox" id="fade-tog" checked><span>Combine with fade</span></label>
- <div class="div"></div>
- <label class="tog" for="loop-tog"><input type="checkbox" id="loop-tog" data-hb-skip data-hb-loop><span>Auto-loop</span></label>
- <div class="btn-row">
- <button class="act pri" id="btn-in" data-hb-replay aria-label="Play rotate in">Play in</button>
- <button class="act" id="btn-out" aria-label="Play out">Play out</button>
- <button class="act" id="btn-rst" data-hb-reset aria-label="Reset">Reset</button>
+ </section>
+
+ <section class="hb-about" aria-labelledby="hb-what-title">
+ <div class="hb-what">
+ <h2 id="hb-what-title">What it is</h2>
+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
</div>
- </section>
- <div class="hb-take">
- <section class="hb-prompt-box" aria-labelledby="hb-prompt-title">
- <h2 class="hb-label" id="hb-prompt-title">Prompt</h2>
- <p class="hb-prompt">Add a rotate-in entrance to [the icon or badge you want to animate]. It should spin around its center as it appears, growing from small to full size at the same time, so it looks like it is arriving rather than just turning. Let it overshoot slightly and settle, so the spin lands instead of gliding to a stop. Use this on round or symmetric shapes like icons, stars, gears and badges; it looks wrong on text or wide rectangles. If the visitor has reduced motion turned on, show it in place without spinning. Match the settings listed below.</p>
- </section>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Icons</li><li>Badges and stars</li><li>Logos</li><li>Small decorations</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Text</li><li>Wide boxes and cards</li></ul>
</div>
- </aside>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
<script>
const icon=document.getElementById('icon');
- const stEl=document.getElementById('st'),rotDisplay=document.getElementById('rot-display');
- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');
- const rotSl=document.getElementById('rot-sl'),rotV=document.getElementById('rot-v');
- const easeSel=document.getElementById('ease-sel');
- const scaleTog=document.getElementById('scale-tog'),fadeTog=document.getElementById('fade-tog'),loopTog=document.getElementById('loop-tog');
+ const vars=document.documentElement.style;
+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
+ const bounceTog=document.getElementById('bounce-tog'),scaleTog=document.getElementById('scale-tog'),fadeTog=document.getElementById('fade-tog');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
- let dur=600,extraRot=0,dir='ccw',looping=false,loopTimer=null,animTimer=null;
+ const SPRINGY='cubic-bezier(.34,1.56,.64,1)',SMOOTH='cubic-bezier(.2,.7,.3,1)';
+ let turn=180,ms=600,dir=-1,timers=[];
- function applyRot(){
- const base=+rotSl.value;
- const extra=extraRot*(dir==='ccw'?-360:360);
- const total=base+extra;
- document.documentElement.style.setProperty('--rot-start',total+'deg');
- document.documentElement.style.setProperty('--scale-start',scaleTog.checked?'0':'1');
- document.documentElement.style.setProperty('--opacity-dur',fadeTog.checked?'var(--dur)':'0s');
- rotV.textContent=rotSl.value+'°';rotDisplay.textContent=total+'°';
+ function dur(){return slowTog.checked?ms*3:ms}
+ function apply(){
+ vars.setProperty('--rot-start',dir*turn+'deg');
+ vars.setProperty('--dur',dur()+'ms');
+ vars.setProperty('--ease',bounceTog.checked?SPRINGY:SMOOTH);
+ vars.setProperty('--scale-start',scaleTog.checked?'0':'1');
+ vars.setProperty('--opacity-dur',fadeTog.checked?'var(--dur)':'0s');
}
-
- function _trigger(cls){
- clearTimeout(animTimer);applyRot();
- if(cls==='in'){
- // snap to the hidden pose without transitioning so a replay always spins in from the start
- icon.style.setProperty('transition','none','important');icon.classList.remove('in');void icon.offsetWidth;
- icon.style.removeProperty('transition');icon.classList.add('in');
- }else icon.classList.remove('in');
- stEl.textContent=cls==='in'?'playing in':'playing out';
- animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);
+ function later(fn,wait){timers.push(setTimeout(fn,wait))}
+ function spinIn(){
+ // snap back to the starting pose without a transition so every play starts from the beginning
+ icon.style.setProperty('transition','none','important');
+ icon.classList.remove('in');void icon.offsetWidth;
+ icon.style.removeProperty('transition');
+ icon.classList.add('in');
+ }
+ // One play spins in. While Loop is on it then waits, spins out, waits and plays again;
+ // switching Loop off lets the icon finish landed. Slow motion stretches the spins, not the waits.
+ function cycle(){
+ apply();spinIn();
+ if(!loopTog.checked||!motionOk)return;
+ later(()=>{
+ if(!loopTog.checked)return;
+ icon.classList.remove('in');
+ later(cycle,dur()+500);
+ },dur()+900);
}
- function stopLoop(){looping=false;clearTimeout(loopTimer);clearTimeout(animTimer);loopTog.checked=false}
- function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+800)}
+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}
- document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});
- document.getElementById('btn-out').addEventListener('click',()=>{stopLoop();_trigger('out')});
- document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);icon.classList.remove('in','out');stEl.textContent='hidden'});
- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});
- document.querySelectorAll('#extra-seg button').forEach(b=>b.addEventListener('click',()=>{
- document.querySelectorAll('#extra-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- extraRot=+b.dataset.x;applyRot();
- }));
- document.querySelectorAll('#dir-seg button').forEach(b=>b.addEventListener('click',()=>{
- document.querySelectorAll('#dir-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
- dir=b.dataset.d;
- rotSl.value=dir==='cw'?Math.abs(+rotSl.value):-Math.abs(+rotSl.value);
- applyRot();
- }));
- rotSl.addEventListener('input',applyRot);
- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});
- easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));
- scaleTog.addEventListener('change',applyRot);fadeTog.addEventListener('change',applyRot);
- applyRot();
+ document.getElementById('btn-play').addEventListener('click',play);
+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});
+ function choices(id,pick){
+ const buttons=document.querySelectorAll('#'+id+' button');
+ buttons.forEach(b=>b.addEventListener('click',()=>{
+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
+ pick(b.dataset);
+ }));
+ }
+ choices('spin-seg',d=>{turn=+d.turn});
+ choices('speed-seg',d=>{ms=+d.ms});
+ choices('dir-seg',d=>{dir=+d.dir});
+ apply();
</script>
</body>
</html>
diff --git a/assets/css/demo-page.css b/assets/css/demo-page.css
new file mode 100644
index 00000000..65ae5146
--- /dev/null
+++ b/assets/css/demo-page.css
@@ -0,0 +1,163 @@
+/* Animation Handbook — page chrome for the guided-steps demo pages.
+ Linked after each demo's own <style>, so these rules win where they overlap.
+ The animation keeps its own styles; this file lays out the page around it:
+ top bar, header, the three steps, About, related cards and footer. */
+
+@font-face{font-family:'Schibsted Grotesk';src:url('../fonts/schibsted-latin-ext.woff2') format('woff2');font-weight:400 900;font-style:normal;font-display:swap;
+ unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}
+@font-face{font-family:'Schibsted Grotesk';src:url('../fonts/schibsted-latin.woff2') format('woff2');font-weight:400 900;font-style:normal;font-display:swap;
+ unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
+
+:root{
+ --hb-font:'Schibsted Grotesk',system-ui,-apple-system,'Segoe UI',sans-serif;
+ --disp:var(--hb-font);--mono:var(--hb-font);
+ --hb-bg:#0b0b0d;--hb-panel:#111114;
+ --hb-ink:#f4f4f2;--hb-text:#e6e6e8;--hb-soft:#d6d6da;--hb-dim:#adadb2;--hb-muted:#8a8a92;
+ --hb-line:rgba(255,255,255,.085);--hb-edge:rgba(255,255,255,.16);--hb-edge-2:rgba(255,255,255,.36);
+ --hb-accent:var(--ui-accent,#6ea8ff);--hb-bar:56px;
+}
+
+body.hb{margin:0;padding:0;background:var(--hb-bg);color:var(--hb-ink);font-family:var(--hb-font);-webkit-font-smoothing:antialiased}
+body.hb :focus-visible{outline:2px solid var(--hb-accent);outline-offset:3px}
+/* Demo styles often set display on their own classes; keep the hidden attribute authoritative. */
+body.hb [hidden]{display:none!important}
+.hb-ic{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
+
+/* Top bar */
+.hb-bar{position:sticky;top:0;z-index:50;box-sizing:border-box;height:var(--hb-bar);display:flex;align-items:center;justify-content:space-between;gap:12px;
+ padding:0 clamp(8px,3vw,40px);background:rgba(11,11,13,.9);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-bottom:1px solid var(--hb-line)}
+.hb-bar a{display:inline-flex;align-items:center;gap:8px;min-height:44px;min-width:44px;padding:0 8px;border-radius:8px;color:var(--hb-dim);
+ text-decoration:none;font:500 15px/1 var(--hb-font)}
+.hb-bar .hb-home{color:var(--hb-ink);font-weight:700;font-size:16px;letter-spacing:-.01em}
+.hb-mark{width:26px;height:26px;flex:none}
+.hb-mark .g{fill:var(--hb-bg);stroke:var(--hb-ink);stroke-width:1.8}
+.hb-mark .b{fill:var(--hb-ink)}
+.hb-pager{display:flex;gap:4px}
+.hb-bar .hb-ic{width:16px;height:16px}
+
+/* The page: one centred column */
+.hb-page{box-sizing:border-box;width:100%;max-width:1040px;margin:0 auto;
+ padding:clamp(24px,4vw,40px) clamp(16px,4vw,40px) clamp(40px,6vw,64px);display:flex;flex-direction:column;gap:clamp(32px,4vw,40px)}
+.hb-head{margin:0;display:flex;flex-direction:column;gap:8px}
+.hb-cat{margin:0;font:600 14px/1.3 var(--hb-font);letter-spacing:.04em;color:var(--hb-accent)}
+.hb-page h1{margin:0;font:800 clamp(40px,6vw,64px)/1 var(--hb-font);letter-spacing:-.035em;color:var(--hb-ink)}
+.hb-lede{margin:0;font:400 clamp(17px,2vw,20px)/1.5 var(--hb-font);color:var(--hb-dim)}
+
+/* Steps */
+.hb-step{display:flex;flex-direction:column;gap:clamp(16px,2.4vw,24px)}
+.hb-step+.hb-step{padding-top:clamp(28px,4vw,36px);border-top:1px solid var(--hb-line)}
+.hb-watch{gap:16px}
+.hb-step-head{display:flex;align-items:flex-start;gap:14px}
+.hb-num{flex:none;display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:50%;
+ background:var(--hb-accent);color:#0b0b0d;font:800 16px/1 var(--hb-font)}
+.hb-step-head h2{margin:0;font:700 clamp(22px,2.6vw,26px)/1.2 var(--hb-font);letter-spacing:-.015em;color:var(--hb-ink)}
+.hb-step-head p{margin:4px 0 0;font:400 16px/1.5 var(--hb-font);color:var(--hb-dim)}
+
+/* Step 1: stage and player bar. 420px is roughly everything above and below the stage on the
+ first screen, so on a laptop the stage and the player bar are both visible on arrival. */
+.hb-page .stage{box-sizing:border-box;width:100%;min-width:0;min-height:0;margin:0;flex:none;
+ height:clamp(300px,calc(100vh - 420px),440px);height:clamp(300px,calc(100svh - 420px),440px);
+ border:1px solid rgba(255,255,255,.1);border-radius:12px;overflow:hidden}
+.hb-page .stage.hb-dots{background-image:radial-gradient(rgba(255,255,255,.075) 1px,transparent 1.5px);background-size:24px 24px;background-position:center}
+.hb-player{display:flex;flex-wrap:wrap;align-items:center;gap:10px}
+.hb-play,.hb-toggle{box-sizing:border-box;display:inline-flex;align-items:center;gap:10px;min-height:44px;padding:0 18px;
+ border:1px solid rgba(255,255,255,.18);border-radius:8px;background:none;color:var(--hb-ink);font:500 15px/1 var(--hb-font);cursor:pointer}
+
+/* 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;
+ background:radial-gradient(circle at 10px 50%,var(--hb-ink) 6.5px,transparent 7px) rgba(255,255,255,.22)}
+.hb-switch:checked{background:radial-gradient(circle at 22px 50%,#0b0b0d 6.5px,transparent 7px) var(--hb-accent)}
+.hb-toggle:has(:focus-visible),.hb-switch-row:has(:focus-visible){outline:2px solid var(--hb-accent);outline-offset:3px}
+.hb-toggle .hb-switch:focus-visible,.hb-switch-row .hb-switch:focus-visible{outline:none}
+
+/* Step 2: settings */
+.hb-settings{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:24px 32px}
+.hb-setting{display:flex;flex-direction:column;gap:10px;min-width:0}
+.hb-setting-name{margin:0;font:600 17px/1.3 var(--hb-font);color:var(--hb-ink)}
+.hb-hint{margin:0;font:400 14px/1.45 var(--hb-font);color:var(--hb-muted)}
+.hb-page .seg{display:flex;flex-wrap:wrap;gap:8px}
+.hb-page .seg button{box-sizing:border-box;min-height:44px;padding:0 16px;border:1px solid var(--hb-edge);border-radius:8px;background:none;
+ color:var(--hb-soft);font:500 15px/1.2 var(--hb-font);cursor:pointer;transition:background-color .15s,border-color .15s,color .15s}
+.hb-page .seg button.on,.hb-page .seg button[aria-pressed="true"]{border-color:var(--hb-accent);color:var(--hb-accent);
+ background:color-mix(in srgb,var(--hb-accent) 12%,transparent)}
+.hb-switch-row{box-sizing:border-box;display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:52px;padding:0 16px;
+ border:1px solid rgba(255,255,255,.14);border-radius:8px;font:500 15px/1.3 var(--hb-font);color:var(--hb-ink);cursor:pointer}
+.hb-options>summary{display:inline-flex;align-items:center;gap:6px;min-height:44px;list-style:none;cursor:pointer;
+ font:600 15px/1 var(--hb-font);color:var(--hb-accent)}
+.hb-options>summary::-webkit-details-marker{display:none}
+.hb-options>summary .hb-ic{transition:transform .2s}
+.hb-options[open]>summary .hb-ic{transform:rotate(180deg)}
+.hb-options .hb-less,.hb-options[open] .hb-more-label{display:none}
+.hb-options[open] .hb-less{display:inline}
+.hb-options>.hb-settings{margin-top:16px}
+
+/* Step 3: the prompt card */
+.hb-card{display:flex;flex-direction:column;gap:20px;padding:clamp(18px,3vw,28px);border:1px solid rgba(255,255,255,.12);border-radius:12px;background:var(--hb-panel)}
+.hb-prompt{margin:0;font:400 17px/1.65 var(--hb-font);color:var(--hb-text)}
+.hb-fill{padding:1px 5px;border-radius:4px;background:rgba(255,255,255,.1);color:var(--hb-ink)}
+.hb-prompt-more{display:none;align-self:flex-start;min-height:44px;margin-top:-12px;padding:0;border:0;background:none;
+ color:var(--hb-accent);font:600 15px/1 var(--hb-font);cursor:pointer}
+.hb-chips-box{display:flex;flex-direction:column;gap:10px}
+.hb-chips-title{margin:0;font:400 14px/1.4 var(--hb-font);color:var(--hb-muted)}
+.hb-chips{display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0;list-style:none}
+.hb-chips li{padding:6px 12px;border-radius:999px;background:color-mix(in srgb,var(--hb-accent) 12%,transparent);color:var(--hb-accent);
+ font:500 14px/1.3 var(--hb-font)}
+.hb-copy-row{display:flex;flex-wrap:wrap;align-items:center;gap:12px 20px}
+.hb-copy-row .hb-hint{flex:1 1 260px}
+.hb-copy{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:10px;min-height:52px;padding:0 26px;border:0;
+ border-radius:8px;background:var(--hb-ink);color:#0b0b0d;font:700 16px/1 var(--hb-font);cursor:pointer}
+.hb-copy .hb-i-done,.hb-copy.is-done .hb-i-copy{display:none}
+.hb-copy.is-done .hb-i-done{display:inline}
+
+/* About and related animations */
+.hb-about{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:clamp(24px,5vw,48px);padding-top:clamp(28px,4vw,36px);
+ border-top:1px solid var(--hb-line)}
+.hb-about h2,.hb-related h2{margin:0 0 12px;font:700 22px/1.2 var(--hb-font);letter-spacing:-.01em;color:var(--hb-ink)}
+.hb-about h3{margin:20px 0 12px;font:600 16px/1.3 var(--hb-font);color:var(--hb-dim)}
+.hb-what-text p{margin:0;font:400 16px/1.7 var(--hb-font);color:var(--hb-dim)}
+.hb-what-text p+p{margin-top:12px}
+.hb-what-text a{color:var(--hb-ink)}
+.hb-tags{display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0;list-style:none}
+.hb-tags li{padding:8px 14px;border:1px solid rgba(255,255,255,.14);border-radius:999px;font:400 15px/1.2 var(--hb-font);color:var(--hb-soft)}
+.hb-avoid li{border-style:dashed;color:var(--hb-muted)}
+.hb-rel-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px}
+.hb-rel{display:flex;flex-direction:column;gap:6px;padding:18px 20px;border:1px solid rgba(255,255,255,.12);border-radius:10px;text-decoration:none}
+.hb-rel b{font:700 18px/1.25 var(--hb-font);color:var(--hb-ink)}
+.hb-rel span{font:400 14px/1.45 var(--hb-font);color:var(--hb-muted)}
+
+/* Footer */
+.hb-foot{box-sizing:border-box;display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px;
+ padding:16px clamp(16px,4vw,40px) 24px;border-top:1px solid var(--hb-line);font:400 14px/1.4 var(--hb-font);color:var(--hb-muted)}
+.hb-foot a{display:inline-flex;align-items:center;min-height:44px;color:var(--hb-dim);text-decoration:none}
+
+@media(hover:hover){
+ .hb-bar a:hover{color:var(--hb-ink)}
+ .hb-play:hover,.hb-toggle:hover,.hb-switch-row:hover{border-color:var(--hb-edge-2)}
+ .hb-page .seg button:hover{border-color:rgba(255,255,255,.34);color:var(--hb-ink)}
+ .hb-page .seg button.on:hover,.hb-page .seg button[aria-pressed="true"]:hover{border-color:var(--hb-accent);color:var(--hb-accent)}
+ .hb-options>summary:hover,.hb-prompt-more:hover{color:color-mix(in srgb,var(--hb-accent) 70%,#fff)}
+ .hb-copy:hover{background:#fff}
+ .hb-rel:hover{border-color:color-mix(in srgb,var(--hb-accent) 55%,transparent)}
+ .hb-foot a:hover{color:var(--hb-ink)}
+}
+
+@media(max-width:759px){
+ .hb-settings,.hb-about{grid-template-columns:minmax(0,1fr)}
+}
+@media(max-width:600px){
+ .hb-bar .hb-dir{display:none}
+ .hb-page .stage{height:300px}
+ .hb-step-head{gap:12px}
+ .hb-num{width:30px;height:30px;font-size:15px}
+ .hb-step-head p{font-size:15px}
+ .hb-player{gap:8px}
+ .hb-play,.hb-toggle{gap:8px;padding:0 12px;font-size:14px}
+ .hb-page .seg button{flex:1 1 0;min-width:0;padding:0 8px}
+ .hb-prompt{font-size:16px;line-height:1.6}
+ .hb-prompt.is-clamped{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical;overflow:hidden}
+ .hb-prompt-more{display:inline-flex;align-items:center}
+ .hb-copy{width:100%}
+}
+@media(prefers-reduced-motion:reduce){
+ .hb-page .seg button,.hb-options>summary .hb-ic{transition:none}
+}
diff --git a/tests/pages.test.js b/tests/pages.test.js
index c0f8a5ba..057870a2 100644
--- a/tests/pages.test.js
+++ b/tests/pages.test.js
@@ -1,9 +1,10 @@
-// Static checks for demo pages that use the shared layout, their READMEs and the home page.
+// Static checks for demo pages that use the shared layouts, their READMEs and the home page.
// Run from the repo root: node --test "tests/*.test.js"
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
+const { sections, table } = require('../assets/js/handbook.js');
const ROOT = path.resolve(__dirname, '..');
const ANIM = path.join(ROOT, 'animations');
@@ -11,24 +12,37 @@ const read = f => fs.readFileSync(f, 'utf8');
const count = (s, sub) => s.split(sub).length - 1;
const words = s => s.trim().split(/\s+/).length;
const isDemoDir = dir => fs.existsSync(path.join(dir, 'index.html'));
+// The part of s from the first `from` up to the next `to` after it ('' when `from` is missing).
+const between = (s, from, to) => {
+ const start = s.indexOf(from);
+ if (start < 0) return '';
+ const end = s.indexOf(to, start + from.length);
+ return s.slice(start, end < 0 ? undefined : end);
+};
const demos = fs.readdirSync(ANIM, { withFileTypes: true }).filter(c => c.isDirectory()).flatMap(c =>
fs.readdirSync(path.join(ANIM, c.name), { withFileTypes: true }).filter(d => d.isDirectory())
.map(d => ({ cat: c.name, slug: d.name, dir: path.join(ANIM, c.name, d.name) })));
-const converted = demos.filter(d => read(path.join(d.dir, 'index.html')).includes('<main class="hb-view">'));
+const pageOf = d => read(path.join(d.dir, 'index.html'));
+const converted = demos.filter(d => pageOf(d).includes('<main class="hb-view">'));
+const steps = demos.filter(d => pageOf(d).includes('<main class="hb-page">'));
const PILOT = '02-entrance-and-exit';
const PILOT_AUTOPLAY = new Set(['fade-in-out', 'slide-in', 'slide-up-reveal', 'scale-in', 'clip-path-reveal',
'split-text-reveal', 'letter-by-letter-stagger', 'word-by-word-reveal', 'blur-in', 'flip-in', 'bounce-in', 'rotate-in']);
-test('every Entrance & Exit demo uses the shared layout', () => {
- const left = demos.filter(d => d.cat === PILOT && !converted.includes(d)).map(d => d.slug);
+test('every Entrance & Exit demo uses one of the shared layouts', () => {
+ const left = demos.filter(d => d.cat === PILOT && !converted.includes(d) && !steps.includes(d)).map(d => d.slug);
assert.deepEqual(left, []);
});
+test('Rotate In uses the guided-steps page', () => {
+ assert.ok(steps.some(d => d.cat === PILOT && d.slug === 'rotate-in'));
+});
+
for (const d of converted) {
test(`${d.cat}/${d.slug} uses the shared layout correctly`, () => {
- const html = read(path.join(d.dir, 'index.html'));
+ const html = pageOf(d);
assert.ok(html.includes('<link rel="stylesheet" href="../../../assets/css/handbook.css">'), 'shared stylesheet');
assert.ok(html.includes('<script src="../../../assets/js/handbook.js" defer></script>'), 'shared script');
assert.match(html, /<body class="hb"( data-hb-autoplay)?>/);
@@ -52,7 +66,60 @@ for (const d of converted) {
});
}
-const { sections, table } = require('../assets/js/handbook.js');
+for (const d of steps) {
+ test(`${d.cat}/${d.slug} uses the guided-steps page correctly`, () => {
+ const html = pageOf(d);
+ assert.ok(html.includes('<link rel="stylesheet" href="../../../assets/css/demo-page.css">'), 'page stylesheet');
+ assert.ok(html.includes('<script src="../../../assets/js/demo-page.js" defer></script>'), 'page script');
+ assert.match(html, /<body class="hb"( data-hb-autoplay)?>/);
+ for (const old of ['handbook.css', 'handbook.js', 'hb-view', 'hb-side', 'hb-take', 'ah-bar', 'Copy source', 'Read more',
+ 'class="note"', 'class="kv"', 'class="lbl"', 'class="btn-row"', 'Bricolage', 'PlexMono']) {
+ assert.ok(!html.includes(old), `old markup left: ${old}`);
+ }
+ for (const part of ['<nav class="hb-bar"', '<main class="hb-page">', '<header class="hb-head">',
+ '<section class="hb-step hb-watch"', '<div class="hb-player">', '<section class="hb-step hb-try"',
+ '<section class="hb-step hb-prompt-step"', '<p class="hb-prompt">', '<ul class="hb-chips">',
+ '<button class="hb-copy" type="button">', '<section class="hb-about"', '<ul class="hb-tags hb-good">',
+ '<ul class="hb-tags hb-avoid">', '<section class="hb-related"', '<footer class="hb-foot">']) {
+ assert.equal(count(html, part), 1, `exactly one ${part}`);
+ }
+ assert.match(html, /<p class="hb-cat">\d{2}\.\d{2} · [^<]+<\/p>/);
+ const prompt = html.match(/<p class="hb-prompt">([^<]*)<\/p>/)[1];
+ assert.ok(words(prompt) >= 60 && words(prompt) <= 130, `prompt has ${words(prompt)} words`);
+ assert.ok(prompt.trim().endsWith('Match the settings listed below.'), 'prompt ending');
+ assert.ok(!prompt.includes('`'), 'prompt contains no code');
+ const player = between(html, '<div class="hb-player">', '</div>');
+ assert.equal(count(html, 'data-hb-replay'), 1, 'one Replay control');
+ assert.ok(player.includes('data-hb-replay'), 'Replay is in the player bar');
+ 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`);
+ }
+ const tryIt = between(html, '<section class="hb-step hb-try"', '<section class="hb-step hb-prompt-step"');
+ const main = between(tryIt, '<div class="hb-settings">', '<details class="hb-options">');
+ const mainCount = count(main, 'class="hb-setting"');
+ assert.ok(mainCount >= 1 && mainCount <= 3, `${mainCount} main settings`);
+ assert.equal(count(tryIt, 'class="hb-hint"'), count(tryIt, 'class="hb-setting"'), 'every setting has one hint');
+ const good = count(between(html, '<ul class="hb-tags hb-good">', '</ul>'), '<li>');
+ const avoid = count(between(html, '<ul class="hb-tags hb-avoid">', '</ul>'), '<li>');
+ assert.ok(good >= 3 && good <= 5, `${good} Good for tags`);
+ assert.ok(avoid >= 1 && avoid <= 3, `${avoid} Avoid on tags`);
+ for (const [, href] of html.matchAll(/<a href="([^"]+)" rel="(?:prev|next)"/g)) {
+ assert.ok(isDemoDir(path.resolve(d.dir, href)), `pager link ${href}`);
+ }
+ });
+
+ test(`${d.slug}: every Key parameters name is a setting in Try it`, () => {
+ const tryIt = between(pageOf(d), '<section class="hb-step hb-try"', '<section class="hb-step hb-prompt-step"')
+ .replace(/<[^>]+>/g, ' ');
+ const rows = sections(read(path.join(d.dir, 'README.md')))['Key parameters'].split('\n').slice(2);
+ for (const row of rows) {
+ const name = (row.split('|')[1] || '').trim();
+ if (name) assert.ok(tryIt.includes(name), `setting "${name}"`);
+ }
+ });
+}
+
const PILOT_SLUGS = ['fade-in-out', 'slide-in', 'slide-up-reveal', 'scale-in', 'clip-path-reveal', 'curtain-reveal',
'split-text-reveal', 'letter-by-letter-stagger', 'word-by-word-reveal', 'blur-in', 'flip-in', 'bounce-in', 'rotate-in'];
@@ -72,7 +139,7 @@ for (const slug of PILOT_SLUGS) {
for (const d of converted.filter(c => c.cat === PILOT)) {
test(`${d.slug}: every Key parameters name is a control on the page`, () => {
- const html = read(path.join(d.dir, 'index.html'));
+ const html = pageOf(d);
const panel = html.slice(html.indexOf('<section class="hb-settings"'), html.indexOf('<div class="hb-take">')).replace(/<[^>]+>/g, ' ');
const rows = sections(read(path.join(d.dir, 'README.md')))['Key parameters'].split('\n').slice(2);
for (const row of rows) {