From 7992d4f46c12d051f3eeb8bcdea8913bb9345c28 Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sun, 8 Nov 2026 09:47:20 +0100 Subject: [PATCH] docs: walkthrough starts when it scrolls into view, also on phones The walkthrough only counted time while 35% of the section was on screen. A phone shows the section a screen at a time, so on short viewports or with large text that share is never reached and the steps never advance. Visibility is now any part of the section in the middle half of the viewport. The first step's browser animation and progress bar also started at page load, so by the time a reader scrolled down they had already finished and nothing moved for a few seconds. The stage now holds every animation at its first frame until the walkthrough first comes into view. --- packages/docs/src/app/home/_flow-browser.scss | 10 ++++++++++ .../docs/src/app/home/flow-walkthrough.html | 2 +- .../docs/src/app/home/flow-walkthrough.ts | 20 +++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/docs/src/app/home/_flow-browser.scss b/packages/docs/src/app/home/_flow-browser.scss index 4371d5ee..9611772c 100644 --- a/packages/docs/src/app/home/_flow-browser.scss +++ b/packages/docs/src/app/home/_flow-browser.scss @@ -564,6 +564,16 @@ } } +// Before the walkthrough first scrolls into view every animation waits at +// its first frame, so the opening step plays when the reader gets there. +.stage-idle { + .flow-browser *, + .flow-browser *::after, + .stepper-bar { + animation-play-state: paused; + } +} + @media (prefers-reduced-motion: reduce) { .stepper-bar { diff --git a/packages/docs/src/app/home/flow-walkthrough.html b/packages/docs/src/app/home/flow-walkthrough.html index 8b7bc5f7..9f723509 100644 --- a/packages/docs/src/app/home/flow-walkthrough.html +++ b/packages/docs/src/app/home/flow-walkthrough.html @@ -11,7 +11,7 @@

A flow is a few lines of TypeScript

-
+
order-coffee.uf.mts diff --git a/packages/docs/src/app/home/flow-walkthrough.ts b/packages/docs/src/app/home/flow-walkthrough.ts index 9bf3a2e5..1ef3a047 100644 --- a/packages/docs/src/app/home/flow-walkthrough.ts +++ b/packages/docs/src/app/home/flow-walkthrough.ts @@ -77,7 +77,8 @@ interface Step { * The flow file next to the page it drives. The collect command starts the * run, each step lights up its lines of code while the browser mock acts * them out, then the report comes together. It plays by itself while on - * screen, pauses under a mouse and lets the reader pick a step. + * screen, pauses under a mouse and lets the reader pick a step. Nothing + * moves until the reader scrolls to it. */ @Component({ selector: 'docs-flow-walkthrough', @@ -136,6 +137,12 @@ export class FlowWalkthrough { readonly lines = SOURCE.split('\n').map(highlightLine); readonly active = signal(0); + /** + * False until the walkthrough first scrolls into view. Until then the + * stage holds its animations at their first frame, so the first step plays + * from the start when the reader gets there instead of having run at load. + */ + readonly started = signal(false); /** True while a mouse hovers the walkthrough. Touch never pauses it. */ readonly paused = signal(false); /** Bumped on every step change so the progress bar restarts. */ @@ -169,16 +176,25 @@ export class FlowWalkthrough { private autoplay() { if (matchMedia('(prefers-reduced-motion: reduce)').matches) { + this.started.set(true); return; } let visible = false; let last = performance.now(); + // Visible means part of the walkthrough is in the middle half of the + // viewport. A share of the section's own height would not do: on a + // phone the section is several screens tall, so no scroll position + // ever shows enough of it at once and the walkthrough would never start. const observer = new IntersectionObserver( ([entry]) => { visible = entry.isIntersecting; last = performance.now(); + if (visible && !this.started()) { + this.started.set(true); + this.elapsed = 0; + } }, - { threshold: 0.35 }, + { rootMargin: '-25% 0px', threshold: 0 }, ); observer.observe(this.host.nativeElement); const timer = setInterval(() => {