Compare commits

...

2 commits

Author SHA1 Message Date
312dc5ed3c Merge pull request 'Public site: smoother scrolling' (#24) from smoother-scrolling into main
Reviewed-on: #24
2026-10-27 09:37:31 +01:00
a6f9e6c6e3 Public site: smoother scrolling
Scrolling the home page dropped frames on a desktop-sized window. Measured
in Firefox and Chromium, the cost came from blocks fading in while scrolling
and from the blurred (frosted) header and calendar cards, which are redrawn
on every frame.

- Header and upcoming-calendar cards: nearly solid background, no blur.
- Fade-in animations are shorter (0.4s / 0.5s, a smaller slide).
- They are off for people whose device asks for reduced motion, and on
  devices that can't keep up: very few cores / little memory straight
  away, otherwise when more than 1 in 10 of the first scrolled frames run
  late (scrollReveal.ts adds `plain-motion` to <html>, remembered for
  the visit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
2026-10-27 08:36:03 +00:00
7 changed files with 144 additions and 14 deletions

View file

@ -143,6 +143,7 @@ To add an email block type: add to `EmailBlockType` in `packages/shared/src/type
### Styling
- **Public site**: Custom theme via `@theme` in `app.css` — colors: `warm`, `charcoal`, `sage`, `sage-dark`, `terracotta`. Fonts: `font-sans` (body), `font-serif` (headings), chosen in Site design → Style (default DM Sans / Playfair Display).
- **Site design → Style** (`style` global: fonts, corners, text size, shadows, page width) becomes `--site-*` variables (`siteStyleVars` in `$shared/theme`) that the `@theme` tokens in both `app.css` files scale. So in public-site markup use the tokens — `rounded-xl`/`rounded-2xl`/`rounded-card`/`rounded-panel`, `shadow-sm`…`shadow-xl`, `max-w-3xl`/`6xl`/`7xl` — never `rounded-[2rem]` or an arbitrary `shadow-[…]`, which ignore the settings. Buttons, chips and icon buttons are `rounded-button` (a pill when Round, square when Sharp); only dots, avatars and badges stay `rounded-full`.
- Keep scrolling smooth: no `backdrop-blur` on public pages (it is redrawn on every scrolled frame; use a nearly solid background), and keep animations short. The `.reveal` / `.animate-fade-in` animations are switched off for people who ask for reduced motion and, by `scrollReveal.ts`, on devices that stutter (`plain-motion` on `<html>`, rules in both `app.css` files).
- Fonts are bundled `@fontsource-variable/*` packages, imported in each app's `src/lib/fonts.ts` and listed in `SITE_FONTS`; a new one goes in all three places.
- **Admin area**: DaisyUI **5** (no `form-control` / `label-text` / `*-bordered` — those are v4). Colours come from Site design via `$shared/theme`, rendered as a `<style>` in `<head>` (SSR, no flash): the admin gets only DaisyUI primary (= site Primary) and secondary (= site Accent) with auto-contrast text; `/preview` and the public site get all site colour variables. Never use `text-primary`/`text-secondary` for text — a light brand colour is unreadable as text; mark state with a tint/bar instead. Conventions:
- Section card: `rounded-box bg-base-100 p-5 shadow` with an `h2.text-2xl.font-bold` title (see Site design / globals).

View file

@ -167,12 +167,13 @@ h4 {
}
/* ── Scroll-reveal animations ── */
/* Kept short: blocks fading in while someone scrolls are what slows scrolling down. */
.reveal {
opacity: 0;
transform: translateY(30px);
transform: translateY(16px);
transition:
opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1),
transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1);
opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1),
transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.reveal-visible {
@ -183,8 +184,8 @@ h4 {
/* ── Hero fade-in stagger ── */
.animate-fade-in {
opacity: 0;
transform: translateY(20px);
animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
transform: translateY(12px);
animation: fadeInUp 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}
@keyframes fadeInUp {
@ -199,6 +200,30 @@ html {
scroll-behavior: smooth;
}
/* No animations on devices that can't keep up (scrollReveal.ts adds .plain-motion
to <html>) or for people whose device asks for less motion. */
html.plain-motion .reveal,
html.plain-motion .animate-fade-in {
opacity: 1;
transform: none;
transition: none;
animation: none;
}
@media (prefers-reduced-motion: reduce) {
.reveal,
.animate-fade-in {
opacity: 1;
transform: none;
transition: none;
animation: none;
}
html {
scroll-behavior: auto;
}
}
/* Visual editor (RichTextEditor): roughly how the site shows text, sized for the sidebar. */
.rich-text h2 { font-size: 1.5rem; font-weight: 700; margin: 0.75rem 0 0.25rem; }
.rich-text h3 { font-size: 1.2rem; font-weight: 700; margin: 0.75rem 0 0.25rem; }

View file

@ -157,12 +157,13 @@ h4 {
}
/* ── Scroll-reveal animations ── */
/* Kept short: blocks fading in while someone scrolls are what slows scrolling down. */
.reveal {
opacity: 0;
transform: translateY(30px);
transform: translateY(16px);
transition:
opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1),
transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1);
opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1),
transform 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.reveal-visible {
@ -173,8 +174,8 @@ h4 {
/* ── Hero fade-in stagger ── */
.animate-fade-in {
opacity: 0;
transform: translateY(20px);
animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
transform: translateY(12px);
animation: fadeInUp 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}
@keyframes fadeInUp {
@ -188,3 +189,27 @@ h4 {
html {
scroll-behavior: smooth;
}
/* No animations on devices that can't keep up (scrollReveal.ts adds .plain-motion
to <html>) or for people whose device asks for less motion. */
html.plain-motion .reveal,
html.plain-motion .animate-fade-in {
opacity: 1;
transform: none;
transition: none;
animation: none;
}
@media (prefers-reduced-motion: reduce) {
.reveal,
.animate-fade-in {
opacity: 1;
transform: none;
transition: none;
animation: none;
}
html {
scroll-behavior: auto;
}
}

View file

@ -40,7 +40,7 @@
</svg>
{/snippet}
<header class="sticky top-0 z-40 border-b border-charcoal/5 bg-warm/90 backdrop-blur">
<header class="sticky top-0 z-40 border-b border-charcoal/5 bg-warm/95">
<div class="mx-auto flex max-w-6xl items-center justify-between gap-3 px-4 py-3 sm:px-6 md:gap-4 md:py-4">
<a class="flex min-w-0 items-center gap-3" href="/" aria-label="Home">
{#if header.logo?.url}

View file

@ -18,12 +18,12 @@
{data.heading || 'Holistic and Experiential Learning about Happiness'}
</h1>
{#if data.subheading}
<p class="animate-fade-in mx-auto mt-6 max-w-2xl text-lg leading-relaxed text-fg-subheading/70 md:text-xl" style="animation-delay: 0.15s;">
<p class="animate-fade-in mx-auto mt-6 max-w-2xl text-lg leading-relaxed text-fg-subheading/70 md:text-xl" style="animation-delay: 0.1s;">
{data.subheading}
</p>
{/if}
{#if data.buttonLabel}
<div class="animate-fade-in mt-10" style="animation-delay: 0.3s;">
<div class="animate-fade-in mt-10" style="animation-delay: 0.2s;">
<a class="btn rounded-button border-0 bg-sage px-10 py-3 text-lg text-primary-content shadow-lg transition hover:bg-sage-dark hover:shadow-xl" href={data.buttonUrl || shopLinks(page.data.header).booking}>
{data.buttonLabel}
</a>

View file

@ -71,7 +71,7 @@
{:else}
<div class="isolate grid gap-8 lg:grid-cols-2">
{#each months as month}
<div class="relative z-0 overflow-visible rounded-panel border border-sage/15 bg-white/80 p-3 shadow-sm sm:p-5 backdrop-blur hover:z-[9000] focus-within:z-[9000]">
<div class="relative z-0 overflow-visible rounded-panel border border-sage/15 bg-white/90 p-3 shadow-sm sm:p-5 hover:z-[9000] focus-within:z-[9000]">
<h3 class="font-display mb-5 text-center text-3xl text-charcoal">{month.label}</h3>
<div class="mb-2 grid grid-cols-7 gap-1 text-center text-xs font-semibold uppercase tracking-wide text-charcoal/45">
{#each weekdays as weekday}<div>{weekday}</div>{/each}

View file

@ -2,9 +2,88 @@
* Scroll reveal Svelte action — applies a CSS class when the element enters the viewport.
* Usage: <div use:scrollReveal class="reveal">...</div>
* The `reveal` class is hidden initially; `reveal-visible` is added on intersection.
*
* On a device that can't keep up, the animations are switched off for the rest
* of the visit (`plain-motion` on <html>, see app.css): one with very few cores
* or little memory straight away, any other once scrolling is seen to stutter.
*/
const PLAIN = 'plain-motion';
const STORAGE_KEY = 'plain-motion';
/** Scrolled frames to look at before deciding, and how many may run late. */
const SAMPLE_FRAMES = 120;
const LATE_SHARE = 0.1;
/** A frame this long missed at least one refresh of a 60 Hz screen. */
const LATE_MS = 25;
let watching = false;
function usePlainMotion() {
document.documentElement.classList.add(PLAIN);
try {
sessionStorage.setItem(STORAGE_KEY, '1');
} catch {
// Storage blocked: decided again on the next page.
}
}
function weakHardware() {
const memory = (navigator as Navigator & { deviceMemory?: number }).deviceMemory;
return (navigator.hardwareConcurrency || 8) <= 2 || (memory !== undefined && memory <= 2);
}
/** Times frames while the page scrolls; too many late ones switch the animations off. */
function watchScrolling() {
if (watching || typeof window === 'undefined') return;
watching = true;
let stored = false;
try {
stored = sessionStorage.getItem(STORAGE_KEY) === '1';
} catch {
// Storage blocked: measure instead.
}
if (stored || weakHardware()) {
usePlainMotion();
return;
}
let frames = 0;
let late = 0;
let last = 0;
let lastScroll = 0;
let running = false;
function tick(now: number) {
if (last) {
frames++;
if (now - last > LATE_MS) late++;
}
last = now;
if (frames >= SAMPLE_FRAMES) {
window.removeEventListener('scroll', onScroll);
if (late / frames > LATE_SHARE) usePlainMotion();
return;
}
// Only frames while scrolling count; stop shortly after it ends.
if (now - lastScroll < 300) requestAnimationFrame(tick);
else running = false;
}
function onScroll() {
lastScroll = performance.now();
if (running) return;
running = true;
last = 0;
requestAnimationFrame(tick);
}
window.addEventListener('scroll', onScroll, { passive: true });
}
export function scrollReveal(node: HTMLElement, delay: number = 0) {
watchScrolling();
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {