Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 71x 2x 2x 2x 13x 5x 2x 2x 3x 3x 3x 3x 2x 1x 2x 2x 15x 15x 13x 13x 15x 24x 24x 24x 7x 7x 7x 7x 7x 24x 2x 24x 24x 24x 24x 24x 24x 24x 14x 14x 24x 49x 49x 49x 49x 49x 144x 15x 15x 15x 15x 15x 15x 15x 13x 13x 1x 1x 15x 7x 8x 9x | "use client";
/**
* A step's preview on the full-screen journeys page.
*
* A hub page is a full-page screenshot in a browser window that tours it: it
* starts at the top, then glides and zooms to each of the page's core
* features (a ring marks it), and back. The screenshots and the features'
* boxes come from __tests__/e2e/capture-journey-previews.spec.ts, through
* scripts/build-journey-previews.py, into src/content/journey-previews.json.
* The Klarbefund screens are a phone that crossfades through them. Several
* pages or screens take turns. Without motion (prefers-reduced-motion) the
* first view stands still.
*/
import {
useEffect,
useLayoutEffect,
useRef,
useState,
type CSSProperties,
} from "react";
import { BASE_PATH } from "@/lib/static-export";
import { guideScreenshotSrc } from "@/lib/guide-screenshots";
import { localizedImagePath } from "@/lib/i18n/localized-images";
import { useLanguage } from "@/lib/use-language";
import type { StepPreview as Preview } from "@/lib/journey-steps";
import previews from "@/content/journey-previews.json";
/** The browser window's view and the phone's screen, as height / width. */
const WEB_ASPECT = 750 / 1200;
const APP_ASPECT = 1434 / 660;
/** The browser window's title bar and the phone's bezel, in pixels. */
const WEB_CHROME = 28;
const PHONE_BEZEL = 8;
/** How long the view rests on a stop, and how long it takes to glide on. */
const REST_MS = 2600;
const GLIDE_MS = 1400;
const APP_FRAME_MS = 3800;
/** The closest the tour zooms in. */
const MAX_ZOOM = 2.4;
export interface Box {
x: number;
y: number;
w: number;
h: number;
}
export interface PageShot {
src: string;
width: number;
height: number;
/** The core features, as fractions of the image. */
focus: Box[];
}
const SHOTS = previews.pages as Record<string, PageShot>;
/** A page's full-page screenshot, or its guide screenshot when it has none. */
export function pageShot(page: string): PageShot {
return (
SHOTS[page] ?? {
src: guideScreenshotSrc(page) ?? "",
width: 1200,
height: 750,
focus: [],
}
);
}
/** One view of the tour: the image's offset and zoom, and the feature ringed. */
export interface Stop {
x: number;
y: number;
zoom: number;
ring: Box | null;
}
/**
* The tour of a page shown in a view of vw x vh pixels, the image fitted to
* the view's width: the top, each feature zoomed to fit (centred, never past
* the image's edge), then, when the page names fewer than three features,
* views further down so the tour still scrolls it.
*/
export function tourStops(shot: PageShot, vw: number, vh: number): Stop[] {
const W = vw;
const H = (vw * shot.height) / shot.width;
const clamp = (v: number, lo: number, hi: number) =>
Math.min(hi, Math.max(lo, v));
const view = (cx: number, cy: number, zoom: number, ring: Box | null) => ({
x: clamp(vw / 2 - cx * zoom, vw - W * zoom, 0),
y: H * zoom <= vh ? 0 : clamp(vh / 2 - cy * zoom, vh - H * zoom, 0),
zoom,
ring,
});
const stops: Stop[] = [{ x: 0, y: 0, zoom: 1, ring: null }];
for (const f of shot.focus) {
const bw = f.w * W;
const bh = f.h * H;
const zoom = clamp(
Math.min(vw / (bw * 1.12), vh / (bh * 1.12)),
1,
MAX_ZOOM,
);
stops.push(view((f.x + f.w / 2) * W, (f.y + f.h / 2) * H, zoom, f));
}
if (shot.focus.length < 3 && H > vh * 1.4) {
for (const part of [0.45, 0.85]) {
stops.push(view(W / 2, vh / 2 + part * (H - vh), 1, null));
}
}
return stops;
}
function useReducedMotion(): boolean {
const [reduced, setReduced] = useState(false);
useEffect(() => {
Eif (typeof window.matchMedia !== "function") return;
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
setReduced(mq.matches);
const on = () => setReduced(mq.matches);
mq.addEventListener?.("change", on);
return () => mq.removeEventListener?.("change", on);
}, []);
return reduced;
}
/** The width and height of an element, kept up to date. */
function useSize<T extends HTMLElement>() {
const ref = useRef<T>(null);
const [size, setSize] = useState({ w: 0, h: 0 });
useLayoutEffect(() => {
const el = ref.current;
Iif (!el) return;
const read = () => setSize({ w: el.clientWidth, h: el.clientHeight });
read();
Eif (typeof ResizeObserver === "undefined") return;
const ro = new ResizeObserver(read);
ro.observe(el);
return () => ro.disconnect();
}, []);
return [ref, size] as const;
}
const TOP: Stop = { x: 0, y: 0, zoom: 1, ring: null };
/** The browser window's view: the pages in turn, each toured. */
function PageTour({
pages,
label,
reduced,
onPage,
}: {
pages: readonly string[];
label: string;
reduced: boolean;
onPage: (page: string) => void;
}) {
const lang = useLanguage();
const [ref, { w, h }] = useSize<HTMLDivElement>();
const [at, setAt] = useState({ page: 0, stop: 0 });
const pagesKey = pages.join("|");
useEffect(() => setAt({ page: 0, stop: 0 }), [pagesKey]);
useEffect(() => onPage(pages[at.page] ?? pages[0]), [at.page, pages, onPage]);
useEffect(() => {
Eif (reduced || w === 0) return;
const count = tourStops(pageShot(pages[at.page]), w, h).length;
const id = window.setTimeout(
() =>
setAt(({ page, stop }) =>
stop + 1 < count
? { page, stop: stop + 1 }
: { page: (page + 1) % pages.length, stop: 0 },
),
at.stop === 0 ? REST_MS : REST_MS + GLIDE_MS,
);
return () => window.clearTimeout(id);
}, [at, reduced, w, h, pages]);
return (
<div
ref={ref}
className="absolute inset-0 overflow-hidden bg-white"
data-testid="journey-step-tour"
data-stop={at.stop}
>
{pages.map((page, i) => {
const shot = pageShot(page);
const stops = w ? tourStops(shot, w, h) : [];
// Before the view is measured, the top of the page.
const stop = (i === at.page ? stops[at.stop] : stops[0]) ?? TOP;
const H = w ? (w * shot.height) / shot.width : 0;
return (
<div
key={page}
className={`absolute inset-0 transition-opacity duration-700 ${
i === at.page ? "opacity-100" : "opacity-0"
}`}
aria-hidden={i === at.page ? undefined : true}
>
{stop && (
<div
className="absolute left-0 top-0 origin-top-left"
style={{
width: w || "100%",
height: H || undefined,
transform: `translate(${stop.x}px, ${stop.y}px) scale(${stop.zoom})`,
transition: reduced
? "none"
: `transform ${GLIDE_MS}ms cubic-bezier(0.45, 0, 0.25, 1)`,
}}
>
{/* eslint-disable-next-line @next/next/no-img-element -- a static export cannot optimise images */}
<img
src={`${BASE_PATH}${localizedImagePath(shot.src, lang)}`}
alt={i === at.page ? label : ""}
className="block h-full w-full"
decoding="async"
/>
{shot.focus.map((f, j) => (
<div
key={j}
className="absolute rounded-md transition-opacity duration-500"
style={{
left: `${f.x * 100}%`,
top: `${f.y * 100}%`,
width: `${f.w * 100}%`,
height: `${f.h * 100}%`,
boxShadow: "0 0 0 3px rgba(240,178,122,0.95)",
opacity: i === at.page && stop.ring === f ? 1 : 0,
}}
aria-hidden="true"
/>
))}
</div>
)}
</div>
);
})}
</div>
);
}
export function StepPreview({
preview,
label,
style,
className = "",
}: {
preview: Preview;
/** What the picture shows, for a screen reader: the step's title. */
label: string;
style?: CSSProperties;
className?: string;
}) {
const lang = useLanguage();
const reduced = useReducedMotion();
const [page, setPage] = useState(
preview.kind === "web" ? preview.pages[0] : "",
);
const [shown, setShown] = useState(0);
const screens = preview.kind === "app" ? preview.screens : [];
const screensKey = screens.join("|");
useEffect(() => {
setShown(0);
if (reduced || screens.length < 2) return;
const id = window.setInterval(
() => setShown((i) => (i + 1) % screens.length),
APP_FRAME_MS,
);
return () => window.clearInterval(id);
}, [reduced, screens.length, screensKey]);
if (preview.kind === "web") {
return (
<figure
className={`jp-pop m-0 flex flex-col overflow-hidden rounded-lg border border-white/25 bg-[#0d162b] shadow-2xl shadow-black/60 ${className}`}
style={style}
data-testid="journey-step-preview"
data-kind="web"
>
<div
className="flex shrink-0 items-center gap-1.5 border-b border-white/10 bg-[#15203a] px-2.5"
style={{ height: WEB_CHROME }}
aria-hidden="true"
>
<span className="h-2 w-2 rounded-full bg-[#e07a5f]" />
<span className="h-2 w-2 rounded-full bg-[#f0b27a]" />
<span className="h-2 w-2 rounded-full bg-[#58d68d]" />
<span
className="ml-2 truncate rounded bg-black/30 px-2 py-0.5 font-mono text-[10px] text-[#aab4bf]"
data-testid="journey-step-preview-url"
>
ehds.mabu.red{page}
</span>
</div>
<div
className="relative w-full"
style={{ aspectRatio: `${1 / WEB_ASPECT}` }}
>
<PageTour
pages={preview.pages}
label={label}
reduced={reduced}
onPage={setPage}
/>
</div>
</figure>
);
}
return (
<figure
className={`jp-pop m-0 rounded-[28px] border border-white/25 bg-[#05080f] shadow-2xl shadow-black/60 ${className}`}
style={{ padding: PHONE_BEZEL, ...style }}
data-testid="journey-step-preview"
data-kind="app"
>
<div
className="relative h-full w-full overflow-hidden rounded-[20px] bg-white"
style={{ aspectRatio: `${1 / APP_ASPECT}` }}
>
{screens.map((s, i) => (
// eslint-disable-next-line @next/next/no-img-element -- a static export cannot optimise images
<img
key={s}
src={`${BASE_PATH}${localizedImagePath(
`/published-docs/${s}.png`,
lang,
)}`}
alt={i === shown ? label : ""}
aria-hidden={i === shown ? undefined : true}
className={`absolute inset-0 h-full w-full object-cover object-top transition-opacity duration-700 ${
i === shown ? "opacity-100" : "opacity-0"
} ${reduced ? "" : "jp-drift"}`}
decoding="async"
/>
))}
</div>
</figure>
);
}
|