diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 86999cb..5e56ad8 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,18 +1,21 @@ name: Deploy to GitHub Pages +# Pull requests get the same checks and build, without the deploy on: push: branches: ["main"] + pull_request: workflow_dispatch: +# Read-only by default; only the deploy job can write to Pages permissions: contents: read - pages: write - id-token: write +# One run per branch or pull request. A new push replaces a pull request's +# run, but never cancels a deploy that is under way. concurrency: - group: "pages" - cancel-in-progress: true + group: pages-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: build: @@ -55,11 +58,16 @@ jobs: # artifact as-is, without a Jekyll pass to hide _next/ from, and # upload-pages-artifact v5 drops dotfiles by default anyway. - name: Upload artifact + if: github.event_name != 'pull_request' uses: actions/upload-pages-artifact@v5 with: path: ./out deploy: + if: github.event_name != 'pull_request' + permissions: + pages: write + id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/README.md b/README.md index 5fe37cc..4221f8d 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ npm run dev ``` src/ - app/ # App Router: root layout, global styles, shared metadata - (site)/ # The site's chrome (nav, deadline, footer) and its pages + app/ # App Router: the pages, the root layout with the site's + # chrome (nav, deadline, footer), styles and metadata components/ # UI components lib/ # Framework-free logic public/ # Served as-is, including CNAME - media/brand/ # Logo + media/brand/ # Logo: light and dark PNGs, and the mark as SVG assets/fonts/ # Fonts for the link-preview image (OFL) ``` diff --git a/assets/fonts/IBMPlexMono-Medium.ttf b/assets/fonts/ibm-plex-mono-medium.ttf similarity index 100% rename from assets/fonts/IBMPlexMono-Medium.ttf rename to assets/fonts/ibm-plex-mono-medium.ttf diff --git a/assets/fonts/IBMPlexMono-OFL.txt b/assets/fonts/ibm-plex-mono-ofl.txt similarity index 100% rename from assets/fonts/IBMPlexMono-OFL.txt rename to assets/fonts/ibm-plex-mono-ofl.txt diff --git a/assets/fonts/InterTight-Medium.ttf b/assets/fonts/inter-tight-medium.ttf similarity index 100% rename from assets/fonts/InterTight-Medium.ttf rename to assets/fonts/inter-tight-medium.ttf diff --git a/assets/fonts/InterTight-OFL.txt b/assets/fonts/inter-tight-ofl.txt similarity index 100% rename from assets/fonts/InterTight-OFL.txt rename to assets/fonts/inter-tight-ofl.txt diff --git a/assets/fonts/InterTight-SemiBold.ttf b/assets/fonts/inter-tight-semibold.ttf similarity index 100% rename from assets/fonts/InterTight-SemiBold.ttf rename to assets/fonts/inter-tight-semibold.ttf diff --git a/package-lock.json b/package-lock.json index 28a4798..1cfeb6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "website", "version": "0.1.0", "dependencies": { + "katex": "^0.19.1", "next": "16.4.3", "react": "19.3.0", "react-dom": "19.3.0" @@ -3163,6 +3164,15 @@ "dev": true, "license": "MIT" }, + "node_modules/commander": { + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz", + "integrity": "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg==", + "license": "MIT", + "engines": { + "node": ">=22.12.0" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -5214,6 +5224,22 @@ "node": ">=4.0" } }, + "node_modules/katex": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.19.1.tgz", + "integrity": "sha512-jG8uKntjSEcm2EpQOh0XturpPuuC9r3Sq5HLHdsFdWZT27E672SF19QEi+of0/YeOy15lDgRhKvr5614uRrEfA==", + "funding": [ + "https://opencollective.com/katex", + "https://github.com/sponsors/katex" + ], + "license": "MIT", + "dependencies": { + "commander": "^15.0.0" + }, + "bin": { + "katex": "cli.js" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", diff --git a/package.json b/package.json index 543852f..fc1a633 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "format": "prettier --write ." }, "dependencies": { + "katex": "^0.19.1", "next": "16.4.3", "react": "19.3.0", "react-dom": "19.3.0" diff --git a/public/media/brand/logo-dark.png b/public/media/brand/ml3-logo-dark.png similarity index 100% rename from public/media/brand/logo-dark.png rename to public/media/brand/ml3-logo-dark.png diff --git a/public/media/brand/logo.png b/public/media/brand/ml3-logo-light.png similarity index 100% rename from public/media/brand/logo.png rename to public/media/brand/ml3-logo-light.png diff --git a/public/media/brand/logo-traced.svg b/public/media/brand/ml3-mark.svg similarity index 100% rename from public/media/brand/logo-traced.svg rename to public/media/brand/ml3-mark.svg diff --git a/src/app/(site)/contact/page.tsx b/src/app/(site)/contact/page.tsx deleted file mode 100644 index f9d915a..0000000 --- a/src/app/(site)/contact/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { EmptySection } from "@/components/EmptySection"; - -import { sectionMetadata } from "../../shared-metadata"; - -export const metadata = sectionMetadata("contact"); - -export default function ContactPage() { - return ; -} diff --git a/src/app/(site)/get-involved/page.tsx b/src/app/(site)/get-involved/page.tsx deleted file mode 100644 index 4d57d67..0000000 --- a/src/app/(site)/get-involved/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { EmptySection } from "@/components/EmptySection"; - -import { sectionMetadata } from "../../shared-metadata"; - -export const metadata = sectionMetadata("get-involved"); - -export default function GetInvolvedPage() { - return ; -} diff --git a/src/app/(site)/layout.tsx b/src/app/(site)/layout.tsx deleted file mode 100644 index 3a42be2..0000000 --- a/src/app/(site)/layout.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import type { Metadata } from "next"; -import { IBM_Plex_Mono, Inter_Tight } from "next/font/google"; -import type { ReactNode } from "react"; - -import { Footer } from "@/components/Footer"; -import { Late } from "@/components/Grid"; -import { Nav } from "@/components/Nav"; - -import styles from "./layout.module.css"; - -// Inter Tight for the wordmark and text: a neo-grotesk with tight default -// spacing that holds up at 100px+. Its italic is for the variables (d, θ) -// in the cart-pole's captions. IBM Plex Mono for labels, figure captions -// and buttons, like a datasheet. -const sans = Inter_Tight({ - subsets: ["latin"], - style: ["normal", "italic"], - variable: "--font-inter-tight", - display: "swap", -}); - -const mono = IBM_Plex_Mono({ - subsets: ["latin"], - weight: ["400", "500"], - variable: "--font-plex-mono", - display: "swap", -}); - -// Pages give a short title ("Team"); the landing page keeps the default -export const metadata: Metadata = { - title: { - default: "ML³ Labs", - template: "%s · ML³ Labs", - }, -}; - -// The site's chrome: fonts, nav, the deadline line and the footer. The -// root layout stays bare, so a page outside this route group can bring its -// own. -export default function SiteLayout({ children }: { children: ReactNode }) { - return ( -
- - Skip to content - -
-
-
- ); -} diff --git a/src/app/(site)/projects/page.tsx b/src/app/(site)/projects/page.tsx deleted file mode 100644 index 424058a..0000000 --- a/src/app/(site)/projects/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { EmptySection } from "@/components/EmptySection"; - -import { sectionMetadata } from "../../shared-metadata"; - -export const metadata = sectionMetadata("projects"); - -export default function ProjectsPage() { - return ; -} diff --git a/src/app/(site)/sponsors/page.tsx b/src/app/(site)/sponsors/page.tsx deleted file mode 100644 index 96cf707..0000000 --- a/src/app/(site)/sponsors/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { EmptySection } from "@/components/EmptySection"; - -import { sectionMetadata } from "../../shared-metadata"; - -export const metadata = sectionMetadata("sponsors"); - -export default function SponsorsPage() { - return ; -} diff --git a/src/app/(site)/team/page.tsx b/src/app/(site)/team/page.tsx deleted file mode 100644 index c95ffe5..0000000 --- a/src/app/(site)/team/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { EmptySection } from "@/components/EmptySection"; - -import { sectionMetadata } from "../../shared-metadata"; - -export const metadata = sectionMetadata("team"); - -export default function TeamPage() { - return ; -} diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx new file mode 100644 index 0000000..3391402 --- /dev/null +++ b/src/app/contact/page.tsx @@ -0,0 +1,20 @@ +import { SectionPage } from "@/components/SectionPage"; +import { CONTACTS, EMAIL } from "@/components/siteData"; + +import { sectionMetadata } from "../shared-metadata"; + +export const metadata = sectionMetadata("contact"); + +// The one nav page with content already: the email, then the other ways to +// reach the club +export default function ContactPage() { + return ( + + ); +} diff --git a/src/app/favicon.ico b/src/app/favicon.ico index 48f9ce9..fbcb055 100644 Binary files a/src/app/favicon.ico and b/src/app/favicon.ico differ diff --git a/src/app/get-involved/page.tsx b/src/app/get-involved/page.tsx new file mode 100644 index 0000000..bddd9fa --- /dev/null +++ b/src/app/get-involved/page.tsx @@ -0,0 +1,17 @@ +import { SectionPage } from "@/components/SectionPage"; +import { EMAIL } from "@/components/siteData"; + +import { sectionMetadata } from "../shared-metadata"; + +export const metadata = sectionMetadata("get-involved"); + +export default function GetInvolvedPage() { + // The landing page's calls to action lead here, so until the page has + // content it still offers a way to reach the club + return ( + + ); +} diff --git a/src/app/globals.css b/src/app/globals.css index 393f65f..18a88df 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -1,4 +1,8 @@ -@import "tailwindcss"; +/* Tailwind for its preflight reset. Class detection is off, so words in + comments and copy can't generate utilities; antialiased, on , is + the one utility in use. */ +@import "tailwindcss" source(none); +@source inline("antialiased"); /* Light only. The colors come from the logo. Its PNG has the background baked in, so whatever sits behind the logo must stay #f9f7f3. */ @@ -9,13 +13,11 @@ --ink: #11151b; --accent: #8b2145; --text: #3a3a3a; - --text-strong: var(--ink); - --text-muted: rgba(17, 21, 27, 0.55); /* The site's drawing language: ink at fixed alphas over --bg, so a hairline is the same weight in the nav, a figure and the footer. - --text-muted is too light for the 10-12px mono labels (about 4:1); - --ink-muted clears 4.5:1. --ink-faint never carries text. */ + --ink-muted is 0.66 because the 10-12px mono labels need 4.5:1, which + 0.55 misses (about 4:1). --ink-faint never carries text. */ --ink-muted: rgba(17, 21, 27, 0.66); --ink-soft: rgba(17, 21, 27, 0.5); --ink-faint: rgba(17, 21, 27, 0.3); diff --git a/src/app/icon.svg b/src/app/icon.svg new file mode 100644 index 0000000..f6659e6 --- /dev/null +++ b/src/app/icon.svg @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/src/app/(site)/layout.module.css b/src/app/layout.module.css similarity index 97% rename from src/app/(site)/layout.module.css rename to src/app/layout.module.css index d139c0c..3b65d57 100644 --- a/src/app/(site)/layout.module.css +++ b/src/app/layout.module.css @@ -7,9 +7,7 @@ --mono: var(--font-plex-mono), ui-monospace, Menlo, monospace; --gutter: 12px; - min-height: 100vh; padding: 0 var(--gutter); - background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index dd44495..60cddee 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,29 +1,79 @@ import type { Metadata, Viewport } from "next"; +import { IBM_Plex_Mono, Inter_Tight } from "next/font/google"; -import { description, openGraph, twitter } from "./shared-metadata"; +import { Footer } from "@/components/Footer"; +import { Late } from "@/components/Grid"; +import { Nav } from "@/components/Nav"; + +import styles from "./layout.module.css"; +import { + SITE_NAME, + description, + openGraph, + titleFor, + twitter, +} from "./shared-metadata"; import "./globals.css"; +// Inter Tight for the wordmark and text: a neo-grotesk with tight default +// spacing that holds up at 100px+. IBM Plex Mono for labels, figure +// captions and buttons, like a datasheet. Math is typeset by KaTeX (Tex). +const sans = Inter_Tight({ + subsets: ["latin"], + variable: "--font-inter-tight", + display: "swap", +}); + +const mono = IBM_Plex_Mono({ + subsets: ["latin"], + weight: ["400", "500"], + variable: "--font-plex-mono", + display: "swap", +}); + export const viewport: Viewport = { width: "device-width", initialScale: 1, }; -// metadataBase turns relative metadata paths into the absolute URLs that -// link-preview crawlers need +// What every page shares. metadataBase turns relative metadata paths into +// the absolute URLs that link-preview crawlers need. Pages give a short +// title ("Team") and their own URL; the landing page keeps the default +// title. export const metadata: Metadata = { metadataBase: new URL("https://ml3labs.com"), - title: "ML³ Labs", + title: { + default: SITE_NAME, + template: titleFor("%s"), + }, description, - alternates: { canonical: "/" }, - openGraph: { ...openGraph, url: "/", title: "ML³ Labs" }, - twitter: { ...twitter, title: "ML³ Labs" }, + openGraph, + twitter, }; +// The site's chrome around every page, the 404 included: the fonts, the +// nav, the deadline down
and the footer export default function RootLayout({ children }: LayoutProps<"/">) { return ( - {children} + +
+ + Skip to content + +
+
+
+ ); } diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx new file mode 100644 index 0000000..98b69cc --- /dev/null +++ b/src/app/not-found.tsx @@ -0,0 +1,27 @@ +import type { Metadata } from "next"; + +import { PageFrame } from "@/components/SectionPage"; +import { href } from "@/components/siteData"; + +export const metadata: Metadata = { + title: "Page not found", +}; + +// Any URL with no page. The export writes it to 404.html, which GitHub +// Pages serves for every path it has no file for. +export default function NotFound() { + return ( + + ); +} diff --git a/src/app/og.png/route.tsx b/src/app/og.png/route.tsx index 373ea29..50ec3c3 100644 --- a/src/app/og.png/route.tsx +++ b/src/app/og.png/route.tsx @@ -32,9 +32,9 @@ const font = (file: string) => export async function GET() { const [medium, semibold, mono] = await Promise.all([ - font("InterTight-Medium.ttf"), - font("InterTight-SemiBold.ttf"), - font("IBMPlexMono-Medium.ttf"), + font("inter-tight-medium.ttf"), + font("inter-tight-semibold.ttf"), + font("ibm-plex-mono-medium.ttf"), ]); return new ImageResponse( @@ -160,8 +160,7 @@ export async function GET() { height: OG_IMAGE.height, fonts: [ { name: "Inter Tight", data: medium, weight: 500 }, - // The file is the 650 cut, the weight the site sets the name in; - // Satori only takes the standard steps, so it is filed under 600 + // SemiBold (600), the weight the hero sets the name in { name: "Inter Tight", data: semibold, weight: 600 }, { name: "IBM Plex Mono", data: mono, weight: 500 }, ], diff --git a/src/app/(site)/page.tsx b/src/app/page.tsx similarity index 89% rename from src/app/(site)/page.tsx rename to src/app/page.tsx index bed0d46..e7861fb 100644 --- a/src/app/(site)/page.tsx +++ b/src/app/page.tsx @@ -2,6 +2,10 @@ import { ControlSection } from "@/components/ControlSection"; import { Hero } from "@/components/Hero"; import { TimingStrip } from "@/components/TimingStrip"; +import { pageMetadata } from "./shared-metadata"; + +export const metadata = pageMetadata("/"); + // The thesis, then the proof: a handshake that meets its deadline, a // control loop you can make late, and the same handshake missing it export default function Home() { diff --git a/src/app/projects/page.tsx b/src/app/projects/page.tsx new file mode 100644 index 0000000..d5ed2c5 --- /dev/null +++ b/src/app/projects/page.tsx @@ -0,0 +1,9 @@ +import { SectionPage } from "@/components/SectionPage"; + +import { sectionMetadata } from "../shared-metadata"; + +export const metadata = sectionMetadata("projects"); + +export default function ProjectsPage() { + return ; +} diff --git a/src/app/shared-metadata.ts b/src/app/shared-metadata.ts index 83581e4..4fb0e98 100644 --- a/src/app/shared-metadata.ts +++ b/src/app/shared-metadata.ts @@ -2,15 +2,21 @@ import type { Metadata } from "next"; import { href, section, type Section } from "@/components/siteData"; +export const SITE_NAME = "ML³ Labs"; + export const description = "McMaster Low Latency Labs. A deadline is a correctness condition."; +// "Team · ML³ Labs", or the site name alone +export const titleFor = (title?: string) => + title ? `${title} · ${SITE_NAME}` : SITE_NAME; + // The preview card, built by og.png/route.tsx export const OG_IMAGE = { url: "/og.png", width: 1200, height: 630, - alt: "ML³ Labs: McMaster Low Latency Labs. A deadline is a correctness condition.", + alt: `${SITE_NAME}: ${description}`, } as const; export const twitter = { @@ -23,24 +29,27 @@ export const twitter = { // into it, so every page spreads these in export const openGraph = { type: "website", - siteName: "ML³ Labs", + siteName: SITE_NAME, description, images: OG_IMAGE, locale: "en_US", } as const; -// Without its own canonical and og:url, a section page would inherit the -// root's "/" and tell crawlers it is a copy of the landing page -export function sectionMetadata(slug: Section["slug"]): Metadata { - const { title } = section(slug); - const url = href(slug); - // The tab title gets " · ML³ Labs" from the (site) layout's template; - // og and twitter titles are not templated, so they carry it themselves - const full = `${title} · ML³ Labs`; +// A page's canonical URL and link-preview titles. Without its own +// canonical and og:url, a page would inherit the root's "/" and tell +// crawlers it is a copy of the landing page. The og and twitter titles +// are not templated like the tab title, so they carry the site name. +export function pageMetadata(url: string, title?: string): Metadata { + const full = titleFor(title); return { - title, alternates: { canonical: url }, openGraph: { ...openGraph, url, title: full }, twitter: { ...twitter, title: full }, }; } + +// The tab title gets the site name from the root layout's template +export function sectionMetadata(slug: Section["slug"]): Metadata { + const { title } = section(slug); + return { title, ...pageMetadata(href(slug), title) }; +} diff --git a/src/app/sponsors/page.tsx b/src/app/sponsors/page.tsx new file mode 100644 index 0000000..9e08971 --- /dev/null +++ b/src/app/sponsors/page.tsx @@ -0,0 +1,17 @@ +import { SectionPage } from "@/components/SectionPage"; +import { EMAIL } from "@/components/siteData"; + +import { sectionMetadata } from "../shared-metadata"; + +export const metadata = sectionMetadata("sponsors"); + +export default function SponsorsPage() { + // The landing page's calls to action lead here, so until the page has + // content it still offers a way to reach the club + return ( + + ); +} diff --git a/src/app/team/page.tsx b/src/app/team/page.tsx new file mode 100644 index 0000000..8e1ebaa --- /dev/null +++ b/src/app/team/page.tsx @@ -0,0 +1,9 @@ +import { SectionPage } from "@/components/SectionPage"; + +import { sectionMetadata } from "../shared-metadata"; + +export const metadata = sectionMetadata("team"); + +export default function TeamPage() { + return ; +} diff --git a/src/components/CartPoleDrawings.tsx b/src/components/CartPoleDrawings.tsx new file mode 100644 index 0000000..e0c2616 --- /dev/null +++ b/src/components/CartPoleDrawings.tsx @@ -0,0 +1,316 @@ +import type { Ref } from "react"; + +import { MODEL, SCENARIO_MS } from "@/lib/cartpole"; + +import { + type MechFrame, + type MechGeom, + SCOPE_H, + type ScopeFrame, + type ScopeGeom, + signed, +} from "./cartpolePaint"; +import styles from "./ControlToy.module.css"; + +// The cart-pole figure's two drawings, as their first frame. ControlToy +// animates them afterwards through the nodes marked data-k, which +// mechNodes() and scopeNodes() in cartpolePaint.ts look up by those names: +// rename one here and rename it there. + +export function Mechanism({ + ref, + g, + f0, + hatchId, +}: { + ref: Ref; + g: MechGeom; + f0: MechFrame; + hatchId: string; +}) { + return ( + + + + + + + + {/* The floor runs on past both ends, so it stays put + while the rest pans */} + + + + {/* Track and end stops */} + + + + + + + {/* What the controller sees: the state d ms ago */} + + + + + + + + + + + + + + + + {[-1, 1].map((side) => ( + + + + + ))} + + {g.showMass && ( + + {MODEL.cartMass.toFixed(1)} kg + + )} + + + + + + + + + + + {f0.th.text} + + + {f0.u.text || " "} + + + {f0.x.text} + + + + + + + ); +} + +export function Scope({ + ref, + sg, + sc0, + reduced, + clipId, + traceId, +}: { + ref: Ref; + sg: ScopeGeom; + sc0: ScopeFrame; + reduced: boolean; + clipId: string; + traceId: string; +}) { + const secTicks: number[] = []; + for (let k = 0; k <= SCENARIO_MS / 1000; k++) secTicks.push(k); + const yOf = (deg: number) => sg.mid - deg * sg.degPx; + + return ( + + + + + + + + {[-20, -10, 10, 20].map((d) => ( + + ))} + + {[20, 0, -20].map((d) => ( + + {signed(d, 0, "°")} + + ))} + {secTicks.map((k) => ( + + ))} + {(reduced + ? (["0 s", "4 s", "8 s"] as const) + : (["−8 s", "−4 s", "now"] as const) + ).map((t, i) => ( + + {t} + + ))} + + + + + + + + + ); +} diff --git a/src/components/ControlSection.tsx b/src/components/ControlSection.tsx index bc4b5e3..92dc74f 100644 --- a/src/components/ControlSection.tsx +++ b/src/components/ControlSection.tsx @@ -3,6 +3,8 @@ import { findDeadline, linearDelayMargin } from "@/lib/cartpole"; import styles from "./ControlSection.module.css"; import { ControlToy } from "./ControlToy"; import { Crosses, VRule } from "./Grid"; +import { ModelDetails } from "./ModelDetails"; +import { Tex } from "./Tex"; export function ControlSection() { // Bisection over the same simulation the toy runs (about 10 ms of @@ -27,12 +29,18 @@ export function ControlSection() { Make the controller late.

- It sees the pole d ms late. Push d past{" "} - {deadline} ms and it falls. + It sees the pole d ms late. Past {deadline}{" "} + ms it can no longer settle. Push further and it falls.

- + d, theta: {"\\theta"} }} + details={ + + } + /> ); } diff --git a/src/components/ControlToy.module.css b/src/components/ControlToy.module.css index 9224537..9831d77 100644 --- a/src/components/ControlToy.module.css +++ b/src/components/ControlToy.module.css @@ -37,28 +37,13 @@ /* ----------------------------------------------------------------- header */ .meta { - composes: row from "./Grid.module.css"; - display: flex; + composes: figHead from "./Grid.module.css"; flex-wrap: wrap; - align-items: center; - justify-content: space-between; - gap: 10px 16px; - min-height: 44px; - padding: 10px calc(var(--late) + var(--pad)) 10px var(--pad); - font-family: var(--mono); - font-size: 11px; - font-weight: 500; - letter-spacing: 0.08em; - text-transform: uppercase; - color: var(--ink-muted); + padding-top: 10px; + padding-bottom: 10px; } .metaFig { - color: var(--ink); - white-space: nowrap; -} -.metaFig span { - margin-left: 10px; - color: var(--ink-muted); + composes: figNo from "./Grid.module.css"; } /* Phones: the figure name and tag on one line, the readouts under them */ @@ -79,25 +64,18 @@ .readouts dt { font-size: 10.5px; } -.readouts dt i { - font: italic 400 13px/1 var(--sans); - letter-spacing: 0; - text-transform: none; -} .readouts dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; +} +.readouts dd:not(.status) { letter-spacing: 0.02em; text-transform: none; } .readouts dd[data-late="true"] { color: var(--accent); } -.readouts .status { - letter-spacing: 0.14em; - text-transform: uppercase; -} /* Missed snaps to a filled maroon chip, like a pressed button */ .readouts .status[data-late="true"] { border-color: var(--accent); @@ -107,9 +85,6 @@ @media (min-width: 900px) { .meta { - display: grid; - grid-template-columns: calc(var(--c3) - var(--pad)) 1fr auto; - gap: 0; padding-top: 0; padding-bottom: 0; } @@ -366,6 +341,7 @@ } .scopeHead { + composes: numbered from "./Grid.module.css"; display: flex; flex-wrap: wrap; justify-content: space-between; @@ -376,22 +352,15 @@ font-size: 10.5px; line-height: 1.5; } -.scopeHead b { - margin-right: 10px; - color: var(--ink); - font-weight: 500; - letter-spacing: 0.08em; - text-transform: uppercase; -} .scopeKey { display: flex; flex-wrap: wrap; gap: 2px 12px; } +/* Its height is SCOPE_H, set inline */ .scopeBox { position: relative; - height: 112px; margin: 0 var(--pad); } .scope { @@ -464,14 +433,10 @@ /* ---------------------------------------------------------------- caption */ .caption { - composes: row split from "./Grid.module.css"; + composes: row split caption from "./Grid.module.css"; row-gap: 12px; padding-top: 16px; padding-bottom: 32px; - color: var(--ink-muted); - font-family: var(--mono); - font-size: 11px; - line-height: 1.55; } .capLabel { composes: label from "./Grid.module.css"; @@ -484,88 +449,12 @@ max-width: 62em; margin: 0; } -.capText b { - margin-right: 10px; - color: var(--ink); - font-weight: 500; - letter-spacing: 0.08em; - text-transform: uppercase; -} .capText .tag { display: inline-block; margin-left: 4px; vertical-align: 1px; } -.caption i { - font: italic 400 12.5px/1 var(--sans); -} - -/* Closed by default; the summary is a quiet mono toggle */ -.more { - margin-top: 12px; -} -.more summary { - width: fit-content; - cursor: pointer; - list-style: none; - color: var(--ink); - letter-spacing: 0.08em; - text-transform: uppercase; -} -.more summary::-webkit-details-marker { - display: none; -} -.more summary::before { - content: "+"; - display: inline-block; - width: 2ch; - color: var(--accent); -} -.more[open] summary::before { - content: "−"; -} -.more summary:hover { - color: var(--accent); -} -.more summary:focus-visible { - outline: 1px solid var(--accent); - outline-offset: 3px; -} - -/* Each entry under its own hairline, two to a row on wide screens */ -.model { - display: grid; - grid-template-columns: minmax(0, 1fr); - gap: 14px 32px; - margin: 14px 0 0; -} -.model > div { - padding-top: 8px; - border-top: 1px solid var(--rule); -} -.model dt { - margin-bottom: 4px; - color: var(--ink-muted); - font-size: 10px; - font-weight: 500; - letter-spacing: 0.1em; - text-transform: uppercase; -} -.model dd { - margin: 0; -} -.model b { - color: var(--ink); - font-weight: 500; -} - -@media (min-width: 600px) { - .model { - grid-template-columns: repeat(2, minmax(0, 1fr)); - } -} - @media (min-width: 900px) { .caption { padding-top: 22px; diff --git a/src/components/ControlToy.tsx b/src/components/ControlToy.tsx index 694ef9b..c5b64bc 100644 --- a/src/components/ControlToy.tsx +++ b/src/components/ControlToy.tsx @@ -2,7 +2,9 @@ import { type MouseEvent, + type ReactNode, useEffect, + useLayoutEffect, useId, useMemo, useRef, @@ -11,17 +13,15 @@ import { } from "react"; import { - AUTO_NUDGE_MS, type CartPole, DEG, - GAINS, MAX_DELAY_MS, MODEL, - NUDGE, SCENARIO_MS, runScenario, } from "@/lib/cartpole"; import { onFrame } from "@/lib/frameLoop"; +import { prefersReducedMotion, subscribeReducedMotion } from "@/lib/motion"; import { applyMech, @@ -38,28 +38,26 @@ import { scopeNodes, } from "./cartpolePaint"; import styles from "./ControlToy.module.css"; +import { Mechanism, Scope } from "./CartPoleDrawings"; import { Crosses, VRule } from "./Grid"; import { LatencyKnob } from "./LatencyKnob"; const INITIAL_DELAY_MS = 30; const CATCH_TILT = 0.5 * DEG; -const RM = "(prefers-reduced-motion: reduce)"; -function subscribeRM(cb: () => void) { - const mq = window.matchMedia(RM); - mq.addEventListener("change", cb); - return () => mq.removeEventListener("change", cb); -} -const getRM = () => window.matchMedia(RM).matches; -const getRMServer = () => false; - type Props = { deadlineMs: number; // from findDeadline(), run at build time - marginMs: number; // from linearDelayMargin() + // Typeset by the server (Tex), so KaTeX never ships to the browser + math: { d: ReactNode; theta: ReactNode }; + details: ReactNode; }; -export function ControlToy({ deadlineMs, marginMs }: Props) { - const reduced = useSyncExternalStore(subscribeRM, getRM, getRMServer); +export function ControlToy({ deadlineMs, math, details }: Props) { + const reduced = useSyncExternalStore( + subscribeReducedMotion, + prefersReducedMotion, + () => false, + ); const [delay, setDelay] = useState(INITIAL_DELAY_MS); const [liveFall, setLiveFall] = useState(null); const [size, setSize] = useState({ w: 640, h: 320, sw: 640 }); @@ -80,8 +78,8 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { const shown = useMemo(() => runScenario(scenarioDelay), [scenarioDelay]); const mg = useMemo(() => mechGeom(size.w, size.h), [size.w, size.h]); const sg = useMemo(() => scopeGeom(size.sw), [size.sw]); - const f0 = mechFrame(shown, mg); - const sc0 = scopeFrame(shown, sg); + const f0 = useMemo(() => mechFrame(shown, mg), [shown, mg]); + const sc0 = useMemo(() => scopeFrame(shown, sg), [shown, sg]); const fall = reduced ? shown.fallen @@ -123,7 +121,8 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { const mech = mechRef.current; const scope = scopeRef.current; if (!stage || !box || !mech || !scope) return; - if (!simRef.current) simRef.current = runScenario(INITIAL_DELAY_MS); + // Live, the still frame is the 8 s warm-up: carry on from a copy + if (!simRef.current) simRef.current = shown.clone(); const sim = simRef.current; const mn = mechNodes(mech); const sn = scopeNodes(scope); @@ -202,15 +201,18 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { document.removeEventListener("visibilitychange", onVisibility); wakeRef.current = null; }; - }, [reduced]); + }, [reduced, shown]); + // Also when the live loop starts, so a simulation created after the + // knob has moved runs at the knob's delay useEffect(() => { if (simRef.current) simRef.current.delay = delay; - }, [delay]); + }, [delay, reduced]); // A React render re-applies the first-frame attributes only when they - // change (a resize). Put the live pose back straight away. - useEffect(() => { + // change: a resize, or the drawings remounting. Put the live pose back + // before the browser paints. + useLayoutEffect(() => { if (reduced) return; const sim = simRef.current; const mech = mechRef.current; @@ -218,7 +220,7 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { if (!sim || !mech || !scope) return; applyMech(mechNodes(mech), mechFrame(sim, mg), true); applyScope(scopeNodes(scope), scopeFrame(sim, sg)); - }); + }, [reduced, mg, sg]); function nudge(dir: 1 | -1) { const sim = simRef.current; @@ -239,10 +241,9 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { function onStageClick(e: MouseEvent) { if ((e.target as Element).closest("[data-overlay]")) return; const sim = simRef.current; - const g = geomRef.current?.mg; - if (reduced || !sim || !g || sim.fallen) return; + if (reduced || !sim || sim.fallen) return; const rect = e.currentTarget.getBoundingClientRect(); - const bobX = rect.left + (bobScreenX(sim, g) * rect.width) / g.w; + const bobX = rect.left + (bobScreenX(sim, mg) * rect.width) / mg.w; nudge(e.clientX < bobX ? 1 : -1); } @@ -252,9 +253,6 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { const clipId = `${uid}-clip`; const traceId = `${uid}-trace`; const capId = `${uid}-cap`; - const secTicks: number[] = []; - for (let k = 0; k <= SCENARIO_MS / 1000; k++) secTicks.push(k); - const yOf = (deg: number) => sg.mid - deg * sg.degPx; return (
@@ -270,9 +268,7 @@ export function ControlToy({ deadlineMs, marginMs }: Props) {
1 kHz
-
- d -
+
{math.d}
{delay} ms
@@ -298,212 +294,13 @@ export function ControlToy({ deadlineMs, marginMs }: Props) { data-reduced={reduced} onClick={onStageClick} > - - - - - - - - {/* The floor runs on past both ends, so it stays put - while the rest pans */} - - - - {/* Track and end stops */} - - - - - - - {/* What the controller sees: the state d ms ago */} - - - - - - - - - - - - - - - - {[-1, 1].map((side) => ( - - - - - ))} - - {g.showMass && ( - - {MODEL.cartMass.toFixed(1)} kg - - )} - - - - - - - - - - - {f0.th.text} - - - {f0.u.text || " "} - - - {f0.x.text} - - - - - - + g={g} + f0={f0} + hatchId={hatchId} + /> {fall === null ? ( -
+

Model

-

+

Fig. 3A cart-pole under state feedback, read{" "} - d ms late.{" "} + {math.d} ms late.{" "} Simulated

- {/* The model's parameters, collapsed under the figure */} -
- Model details -
-
-
Plant
-
- Cart {MODEL.cartMass.toFixed(1)} kg on a ± - {MODEL.trackHalf} m track. Pole:{" "} - {MODEL.poleMass} kg point mass on a{" "} - {MODEL.poleLength} m massless rod. -
-
-
-
Controller
-
- u = {GAINS.th}θ + {GAINS.om}ω + {GAINS.x}x +{" "} - {GAINS.v}v, clipped to ±{MODEL.forceLimit}{" "} - N. LQR gains, rounded. It reads the state - from a ring buffer, d steps back. -
-
-
-
Physics
-
- RK4, fixed {MODEL.stepMs} ms step. The - controller runs every step (1 kHz). Test - nudge: {NUDGE} rad/s every{" "} - {AUTO_NUDGE_MS / 1000} s, alternating sides. -
-
-
-
Deadline
-
- {deadlineMs} ms: the largest d{" "} - at which a 1 µrad tilt still dies out, found - by bisection on this simulation at build - time. The linearised loop's delay - margin, {marginMs.toFixed(1)} ms, agrees to - within a step. -
-
-
-
+ {details}
diff --git a/src/components/EmptySection.tsx b/src/components/EmptySection.tsx deleted file mode 100644 index 185c166..0000000 --- a/src/components/EmptySection.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { ButtonLink } from "./Button"; -import styles from "./EmptySection.module.css"; -import { Crosses, VRule } from "./Grid"; -import { CONTACTS, EMAIL, SECTIONS, type Section } from "./siteData"; -import { TimingStrip } from "./TimingStrip"; - -const two = (n: number) => String(n).padStart(2, "0"); - -// Every nav page until it has content: its name, an undefined ACK, and a -// line on what will go there. Contact is the exception: it already has its -// content, the ways to reach the club. -export function EmptySection({ slug }: { slug: Section["slug"] }) { - const i = SECTIONS.findIndex((s) => s.slug === slug); - const page = SECTIONS[i]; - const contact = slug === "contact"; - - return ( - <> -
- - -

- {two(i + 1)} / {two(SECTIONS.length)} -

-

- {page.title} -

-
- - - -
- - -

- {contact ? "Reach us" : "Status"} -

-
- {contact ? ( - - {EMAIL} - - ) : ( -

Nothing here yet.

- )} -

{page.line}

- {contact && ( -
- {CONTACTS.slice(1).map((c) => ( - - {c.label} - - ))} -
- )} -
-
- - ); -} diff --git a/src/components/Footer.module.css b/src/components/Footer.module.css index ec39fa9..ffd0c2e 100644 --- a/src/components/Footer.module.css +++ b/src/components/Footer.module.css @@ -1,41 +1,65 @@ +/* Two ruled rows under the diagram. Phones: just the link columns, side + by side. Wide: the mark fills the label column, standing on the rule + below it, the page's load time takes the middle and the link columns + sit at the right, ending where the deadline would be. */ + .footer { - composes: row from "./Grid.module.css"; - display: grid; - grid-template-columns: 1fr; - row-gap: 14px; - padding: 28px var(--pad) 40px; color: var(--ink-muted); font-family: var(--mono); font-size: 12px; line-height: 1.6; } -.brand { - display: flex; - align-items: center; - gap: 10px; - color: var(--ink); - font-family: var(--sans); - font-size: 17px; - font-weight: 650; - letter-spacing: -0.02em; +/* Pages takes the width of its longest title; contact gets the rest, so + the email address fits beside it on a phone */ +.top { + composes: row from "./Grid.module.css"; + display: grid; + grid-template-columns: auto minmax(0, 1fr); + grid-template-areas: "pages contact"; + gap: 32px 40px; + padding: 28px var(--late) 32px 0; +} + +.pages { + grid-area: pages; + padding-left: var(--pad); +} + +.contact { + grid-area: contact; } +/* Wide screens only */ +.timing, .mark { - display: block; - width: 25px; - height: 18px; + display: none; } -.note { - margin: 0; +.timing { + grid-area: timing; } -.links { - display: flex; - flex-wrap: wrap; - gap: 6px 22px; +.mark { + grid-area: mark; justify-self: start; + align-self: end; + height: auto; + margin-left: var(--pad); +} + +.colLabel { + margin: 0 0 12px; + font-size: 11px; + font-weight: 500; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.list { + display: grid; + justify-items: start; + gap: 6px; margin: 0; padding: 0; list-style: none; @@ -45,34 +69,62 @@ display: inline-flex; align-items: center; gap: 8px; - justify-self: start; - padding: 2px 0; color: var(--ink); - text-decoration: underline; + font-family: var(--sans); + font-size: 15px; + font-weight: 500; + line-height: 1.5; + text-decoration: none; text-decoration-thickness: 1px; - text-underline-offset: 4px; - transition: none; + text-underline-offset: 5px; } -.link:hover, -.link:focus-visible { - background: var(--ink); - color: var(--bg); - text-decoration: none; +.link:hover { + text-decoration-line: underline; } .link:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; } +.base { + composes: row from "./Grid.module.css"; + display: flex; + flex-wrap: wrap; + justify-content: space-between; + gap: 4px 24px; + padding: 16px var(--pad) 28px; +} +.base p { + margin: 0; +} + @media (min-width: 900px) { - .footer { - grid-template-columns: var(--c3) 1fr auto; - align-items: center; - padding: 32px var(--late) 48px 0; + .top { + grid-template-columns: var(--c3) minmax(0, 1fr) auto auto; + grid-template-areas: "mark timing pages contact"; + column-gap: 0; + padding: 36px var(--late) 0 0; + } + .pages, + .contact, + .timing { + align-self: start; + padding: 0 var(--pad) 48px; + } + .timing { + padding-right: 56px; + } + .pages { + padding-right: 56px; + } + .timing, + .mark { + display: block; + } + .mark { + width: calc(var(--c3) - 2 * var(--pad)); } - .brand, - .note, - .links { - margin: 0 var(--pad); + .base { + padding: 18px calc(var(--late) + var(--pad)) 32px var(--pad); } } diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 0d68337..90fa315 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -1,33 +1,71 @@ +import Link from "next/link"; + import { Arrow } from "./Button"; import styles from "./Footer.module.css"; import { Crosses, VRule } from "./Grid"; -import { Mark, Name } from "./Mark"; -import { CONTACTS } from "./siteData"; +import { Mark } from "./Mark"; +import { PageLoad } from "./PageLoad"; +import { CONTACTS, SECTIONS, href } from "./siteData"; + +// The build's year. The site is rebuilt on every deploy. +const YEAR = new Date().getFullYear(); // Outside the diagram: the deadline stops at the footer's rule, on a -// maroon + mark +// maroon + mark. Below it the mark, large, this page's load time, a +// column of pages and a column of ways to reach the club. Then the fine +// print. export function Footer() { return (
- - -
+
+ + + +
+ + +
+
+

Load time

+ +
-
-

- Student-run. Not an official McMaster University entity. -

- +
+ +

© {YEAR} McMaster Low Latency Labs

+

Student-run. Not an official McMaster University entity.

+
); } diff --git a/src/components/Grid.module.css b/src/components/Grid.module.css index 8085c99..47534fe 100644 --- a/src/components/Grid.module.css +++ b/src/components/Grid.module.css @@ -1,7 +1,7 @@ /* The page is one timing diagram. Every row has a 1px rule on top, + marks where rules cross, a column rule at --c3 (wide screens) and the deadline at --D, with the late column after it. --pad, --late, --c3 and --D come - from the site frame (src/app/(site)/layout.module.css). */ + from the site frame (src/app/layout.module.css). */ .row { position: relative; @@ -119,6 +119,50 @@ padding: 0 var(--pad); } +/* A figure's header row: its number and name on the left, readouts or + controls on the right. Wide, the number fills the label column. */ +.figHead { + composes: row; + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px 16px; + min-height: 44px; + padding-right: calc(var(--late) + var(--pad)); + padding-left: var(--pad); + font-family: var(--mono); + font-size: 11px; + font-weight: 500; + letter-spacing: 0.08em; + text-transform: uppercase; + color: var(--ink-muted); +} +.figNo { + color: var(--ink); + white-space: nowrap; +} +.figNo span { + margin-left: 10px; + color: var(--ink-muted); +} + +/* Figure captions, led by the figure number in bold caps. .numbered gives + any other block the same number style. */ +.caption { + composes: numbered; + color: var(--ink-muted); + font-family: var(--mono); + font-size: 11px; + line-height: 1.55; +} +.numbered b { + margin-right: 10px; + color: var(--ink); + font-weight: 500; + letter-spacing: 0.08em; + text-transform: uppercase; +} + @media (min-width: 900px) { .split { grid-template-columns: var(--c3) 1fr; @@ -127,4 +171,9 @@ .vr { display: block; } + .figHead { + display: grid; + grid-template-columns: calc(var(--c3) - var(--pad)) 1fr auto; + gap: 0; + } } diff --git a/src/components/Hero.module.css b/src/components/Hero.module.css index 0afd3f7..ff26953 100644 --- a/src/components/Hero.module.css +++ b/src/components/Hero.module.css @@ -38,38 +38,16 @@ } .meta { - composes: row from "./Grid.module.css"; - display: flex; - align-items: center; - justify-content: space-between; - gap: 16px; - height: 44px; - padding: 0 calc(var(--late) + var(--pad)) 0 var(--pad); - font-family: var(--mono); - font-size: 11px; - font-weight: 500; - letter-spacing: 0.08em; - text-transform: uppercase; - color: var(--ink-muted); + composes: figHead from "./Grid.module.css"; } .metaFig { - color: var(--ink); - white-space: nowrap; -} -.metaFig span { - margin-left: 10px; - color: var(--ink-muted); + composes: figNo from "./Grid.module.css"; } .metaCap { display: none; } @media (min-width: 900px) { - .meta { - display: grid; - grid-template-columns: calc(var(--c3) - var(--pad)) 1fr auto; - gap: 0; - } .metaCap { display: block; overflow: hidden; @@ -91,10 +69,7 @@ } .stage { - composes: row from "./Grid.module.css"; - display: grid; - grid-template-columns: 1fr; - padding-right: var(--late); + composes: row split from "./Grid.module.css"; } .markCol { @@ -109,9 +84,6 @@ } @media (min-width: 900px) { - .stage { - grid-template-columns: var(--c3) 1fr; - } .markCol { padding: 56px 0 30px; } @@ -441,55 +413,55 @@ writing-mode: vertical-rl; } -/* Boot sequence. t0 = 300 ms after load, one tick per 120 ms: - t1 bar-1, t2 bar-2, t3 bar-3, t4 the ³ lands as the sweep arrives. - Every final keyframe equals the base style, so with no animation (or - reduced motion) the page shows the finished frame. */ - -.boot .sweep { - animation: sweep 480ms linear 300ms both; -} -.boot .clk { - animation: wipe 480ms linear 300ms both; -} -.boot .head { - animation: sweep 480ms linear 300ms both; -} -/* The label only snaps in once the line has landed */ -.boot .sweepTag { - animation: appear 780ms step-end both; -} -.boot .l1 { - animation: rise1 80ms steps(4, jump-start) 420ms both; -} -.boot .l2 { - animation: rise2 80ms steps(4, jump-start) 540ms both; -} -.boot .l3 { - animation: rise3 80ms steps(4, jump-start) 660ms both; -} -.boot .l4 { - animation: - appear 708ms step-end both, - land 72ms steps(3, jump-end) 708ms both; -} -.boot .lgRow[data-k] { - animation-name: lit; - animation-duration: var(--at); - animation-timing-function: step-end; - animation-fill-mode: both; -} -.boot .lgRow .hi { - animation-name: appear; - animation-duration: var(--at); - animation-timing-function: step-end; - animation-fill-mode: both; -} -.boot .lgRow .lo { - animation-name: vanish; - animation-duration: var(--at); - animation-timing-function: step-end; - animation-fill-mode: both; +/* Boot sequence, on the clock Hero.tsx sets from src/lib/motion.ts: --t0 + after load, then one --tick per step. t1 bar-1, t2 bar-2, t3 bar-3, t4 the + ³ lands as the sweep arrives. It only runs when motion is welcome. Every + final keyframe equals the base style, so otherwise the page shows the + finished frame. */ +@media (prefers-reduced-motion: no-preference) { + .boot .sweep, + .boot .head { + animation: sweep calc(4 * var(--tick)) linear var(--t0) both; + } + .boot .clk { + animation: wipe calc(4 * var(--tick)) linear var(--t0) both; + } + /* The label only snaps in once the line has landed */ + .boot .sweepTag { + animation: appear calc(var(--t0) + 4 * var(--tick)) step-end both; + } + /* Each bar rises in 80 ms, starting on its tick */ + .boot .l1 { + --top: 63.4%; + animation: rise 80ms steps(4, jump-start) calc(var(--t0) + var(--tick)) + both; + } + .boot .l2 { + --top: 40%; + animation: rise 80ms steps(4, jump-start) + calc(var(--t0) + 2 * var(--tick)) both; + } + .boot .l3 { + --top: 17.1%; + animation: rise 80ms steps(4, jump-start) + calc(var(--t0) + 3 * var(--tick)) both; + } + /* The ³ appears 72 ms early and drops in, landing on t4 */ + .boot .l4 { + --land-at: calc(var(--t0) + 4 * var(--tick) - 72ms); + animation: + appear var(--land-at) step-end both, + land 72ms steps(3, jump-end) var(--land-at) both; + } + .boot .lgRow[data-k] { + animation: lit var(--at) step-end both; + } + .boot .lgRow .hi { + animation: appear var(--at) step-end both; + } + .boot .lgRow .lo { + animation: vanish var(--at) step-end both; + } } @keyframes sweep { @@ -508,31 +480,15 @@ clip-path: inset(-4px -4px -4px -4px); } } -/* Each bar is revealed from the baseline up to its own top edge (bar-1 - 63.7%, bar-2 40.3%, bar-3 17.4% of the viewBox height), so the four steps - are four equal quarters of that bar */ -@keyframes rise1 { +/* Each bar is revealed from the baseline up to its own top edge, --top + (bar-1 63.7%, bar-2 40.3%, bar-3 17.4% of the viewBox height), so the + four steps are four equal quarters of that bar */ +@keyframes rise { from { clip-path: inset(calc(100% + 3px) -2px -2px -2px); } to { - clip-path: inset(63.4% -2px -2px -2px); - } -} -@keyframes rise2 { - from { - clip-path: inset(calc(100% + 3px) -2px -2px -2px); - } - to { - clip-path: inset(40% -2px -2px -2px); - } -} -@keyframes rise3 { - from { - clip-path: inset(calc(100% + 3px) -2px -2px -2px); - } - to { - clip-path: inset(17.1% -2px -2px -2px); + clip-path: inset(var(--top) -2px -2px -2px); } } @keyframes appear { @@ -592,11 +548,6 @@ } @media (prefers-reduced-motion: reduce) { - .boot *, - .boot *::before, - .boot *::after { - animation: none !important; - } .replay { display: none; } diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index e9f2e9b..d1daea3 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -4,6 +4,12 @@ import { useEffect, useRef } from "react"; import type { CSSProperties, PointerEvent } from "react"; import { onFrame } from "@/lib/frameLoop"; +import { + BOOT_SWEEP_MS, + BOOT_T0_MS, + BOOT_TICK_MS, + prefersReducedMotion, +} from "@/lib/motion"; import { ButtonLink } from "./Button"; import { Crosses, VRule } from "./Grid"; @@ -21,22 +27,17 @@ import { href } from "./siteData"; // This component only adds two controls on top: Replay, and scrubbing the // clock by dragging across the mark. -const SWEEP_MS = 480; // four ticks of 120 ms, as in the CSS - -// at: when each row flips, t0 (300 ms) + k ticks +// Each row flips at t0 + k ticks const LEGEND = [ - { k: 1, tick: "t1", signal: "bar-1", lo: "low", hi: "high", at: "420ms" }, - { k: 2, tick: "t2", signal: "bar-2", lo: "low", hi: "high", at: "540ms" }, - { k: 3, tick: "t3", signal: "bar-3", lo: "low", hi: "high", at: "660ms" }, - { - k: 4, - tick: "t4", - signal: "³", - lo: "pending", - hi: "on deadline", - at: "780ms", - }, -]; + { k: 1, signal: "bar-1", lo: "low", hi: "high" }, + { k: 2, signal: "bar-2", lo: "low", hi: "high" }, + { k: 3, signal: "bar-3", lo: "low", hi: "high" }, + { k: 4, signal: "³", lo: "pending", hi: "on deadline" }, +].map((row) => ({ + ...row, + tick: `t${row.k}`, + at: `${BOOT_T0_MS + row.k * BOOT_TICK_MS}ms`, +})); const LAYERS = [ { k: 1, d: MARK_BAR_1, cls: styles.l1, fill: styles.ink }, @@ -45,12 +46,15 @@ const LAYERS = [ { k: 4, d: MARK_THREE, cls: styles.l4, fill: styles.accent }, ]; +// The boot clock, for the CSS to time every step from +const CLOCK = { + "--t0": `${BOOT_T0_MS}ms`, + "--tick": `${BOOT_TICK_MS}ms`, +} as CSSProperties; + // Four clock periods across the mark; the last rising edge is the deadline const CLK = "M0 13V1H50V13H100V1H150V13H200V1H250V13H300V1H350V13H400V1"; -const reducedMotion = () => - window.matchMedia("(prefers-reduced-motion: reduce)").matches; - export function Hero() { const root = useRef(null); const mark = useRef(null); @@ -102,7 +106,7 @@ export function Hero() { // loop of its own. Reduced motion skips straight to the end. const finish = () => { cancelFinish(); - if (reducedMotion()) { + if (prefersReducedMotion()) { toStatic(); return; } @@ -110,7 +114,7 @@ export function Hero() { let t0 = -1; stopFinish.current = onFrame((now) => { if (t0 < 0) t0 = now; - const p = Math.min(1, from + (now - t0) / SWEEP_MS); + const p = Math.min(1, from + (now - t0) / BOOT_SWEEP_MS); setP(p); if (p >= 1) { cancelFinish(); @@ -139,6 +143,12 @@ export function Hero() { const st = drag.current; const el = root.current; if (e.pointerId !== st.id || !el) return; + // The press ended off the scrubber before a drag began, so onUp + // never heard about it: this is a hover, not a drag + if (!st.on && e.buttons === 0) { + st.id = -1; + return; + } if (!st.on) { // Only a sideways drag scrubs, so a vertical swipe still scrolls const dx = Math.abs(e.clientX - st.x); @@ -169,6 +179,7 @@ export function Hero() {