mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:14:28 +00:00
* Type scripts under strict Playwright's API the checks use is declared in host.ts (the package is the app repo's); caught errors read through why(). tabs-tree.test waits for the typed tabsTree. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the shared components under strict Window globals (__lenis, __hzHold, google) and the two react-dom calls are declared in components/*.d.ts, since @types/react-dom is not a dependency and the lockfile is frozen. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/v2 under strict Props, state, refs and DOM events in the 93 v2 files. A2Motion's easing tuples are as const. Two real bugs: x-archimedes/MaskLines imported a NoJs that does not exist, and x-hypatia/PinChapters returned the element from a ref callback, which React 19 reads as a cleanup. AppSheet no longer sets aria-label to a JSX label. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type components/home under strict The race, cost and frontier figures, the plan cards, the repository card and the product stories take Run, Models and Plan types from lib. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the hero devices and the app routes under strict HeroScene and its parts describe hero-scenes.json; the [slug] pages take params as a Promise, and metadata and viewport carry Next's types. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Give the integrations previews their Preview type Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Use the bench Card type for the closing cards Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
140 lines
7.8 KiB
TypeScript
140 lines
7.8 KiB
TypeScript
'use client';
|
|
/* The shell every page shares (mounted once in app/layout.jsx; pages import nothing from here except Marquee):
|
|
- Smooth: the site-wide reduced-motion policy (MotionConfig reducedMotion="user"), native scrolling,
|
|
[data-off] on any <main> section that is off screen (pause your CSS loops with `[data-off] .x { animation-play-state: paused }`),
|
|
and every new page starting at its top.
|
|
- Progress, Header, Footer: the scroll bar and the behaviour of Hanzo's own header and footer (their HTML is
|
|
rendered on the server by components/Shell.jsx, so it costs no JS). Mark a dark section with data-room="dark" and
|
|
the header turns dark over it.
|
|
- Marquee: <Marquee items={[{ name, src, href }]} label="Trusted by" reverse /> an endless logo strip (it stands still
|
|
under reduced motion and rests under the pointer or focus). An item with { w, h, hang } is a wordmark drawn at w x h px
|
|
and sat on the strip's one baseline: hang is how far the logo falls below its text (a smile, a descender, a mark).
|
|
`still` draws the list once in a row with its label beside it, where the screen holds them all (wide screens).
|
|
- After every in-site navigation, focus moves to the new page's <main> h1 (tabindex -1, no ring, no scroll). */
|
|
import { useEffect, useRef, type ReactNode } from 'react';
|
|
import { usePathname } from 'next/navigation';
|
|
import { MotionConfig } from 'motion/react';
|
|
import { animate, scroll } from 'motion';
|
|
import Nav from './Nav';
|
|
import HeaderTools from './HeaderTools';
|
|
import { onDomChange } from '../lib/domwatch';
|
|
import { lean } from '../lib/tilt';
|
|
|
|
/* One motion policy for the whole page. Scrolling is the browser's own: nothing sits between the wheel and the page. */
|
|
export function Smooth({ children }: { children?: ReactNode }) {
|
|
// every [data-tilt] card leans toward a mouse (or the phone's tilt) and a light follows it: one listener, lib/tilt.js
|
|
useEffect(() => lean(), []);
|
|
// every section pauses its animations while it is off screen
|
|
useEffect(() => {
|
|
const io = new IntersectionObserver((es) => es.forEach((e) => e.target.toggleAttribute('data-off', !e.isIntersecting)), { rootMargin: '10% 0px' });
|
|
const watch = () => document.querySelectorAll('main > section, main > div > section').forEach((s) => io.observe(s));
|
|
watch();
|
|
const off = onDomChange(watch); // new pages bring new sections; observing twice is harmless
|
|
return () => { io.disconnect(); off(); };
|
|
}, []);
|
|
// a new page starts at its top (the open and close transitions place the scroll themselves)
|
|
const path = usePathname();
|
|
const first = useRef(true);
|
|
useEffect(() => {
|
|
if (first.current) { first.current = false; return; }
|
|
if (window.__hzHold) return; // a close transition is restoring the previous scroll
|
|
if (window.__hzPop) { window.__hzPop = false; return; } // Back/Forward: the browser restores where you were
|
|
window.__lenis ? window.__lenis.scrollTo(0, { immediate: true, force: true }) : scrollTo(0, 0);
|
|
// focus moves to the new page's h1 (screen readers hear where they are; the next Tab starts in the page), unless
|
|
// something on the page already took focus
|
|
let n = 0;
|
|
const land = () => {
|
|
const a = document.activeElement;
|
|
if (a && a !== document.body && !a.closest('header, nav, .x-ask') && a.isConnected) return;
|
|
const h = document.querySelector<HTMLElement>('main h1');
|
|
if (!h) { if (n++ < 30) setTimeout(land, 100); return; }
|
|
if (!h.hasAttribute('tabindex')) h.setAttribute('tabindex', '-1');
|
|
h.focus({ preventScroll: true });
|
|
};
|
|
const t = setTimeout(land, 120);
|
|
return () => clearTimeout(t);
|
|
}, [path]);
|
|
// reduced motion: Motion skips transform and layout animations for people who ask for less movement (DESIGN rule 6).
|
|
// It decides when each element mounts, after hydration, so the server HTML and the first client render still match.
|
|
return <MotionConfig reducedMotion="user">{children}</MotionConfig>;
|
|
}
|
|
|
|
/* The scroll bar at the top: retired (the owner asked for the white scroll progress bar in the header to be hidden). */
|
|
export function Progress() {
|
|
return null;
|
|
}
|
|
|
|
// the server-rendered shell (components/Shell.jsx), read lazily so children's effects can use it on mount
|
|
const shell = (name: string) => ({ get current() { return typeof document === 'undefined' ? null : document.querySelector(`[data-x-shell="${name}"]`); } });
|
|
const HEADER = shell('header');
|
|
const FOOTER = shell('footer');
|
|
|
|
/* Hanzo's own header (its HTML comes from the server, components/Shell.jsx): it gains its hairline once the page
|
|
moves, turns dark over dark rooms, and its menus and tools come alive. */
|
|
export function Header() {
|
|
const ref = HEADER;
|
|
useEffect(() => {
|
|
const h = ref.current?.querySelector('header');
|
|
if (!h) return;
|
|
const on = () => h.setAttribute('data-scrolled', String(scrollY > 8));
|
|
on();
|
|
addEventListener('scroll', on, { passive: true });
|
|
// the header turns dark while it sits over a dark room, as Apple's does; watched by the browser, no layout reads on scroll
|
|
const seen = new Set();
|
|
const io = new IntersectionObserver((es) => {
|
|
es.forEach((e) => (e.isIntersecting ? seen.add(e.target) : seen.delete(e.target)));
|
|
h.setAttribute('data-x-dark', String(seen.size > 0));
|
|
}, { rootMargin: '-30px 0px -99% 0px' });
|
|
const watch = () => document.querySelectorAll('[data-room=dark]').forEach((r) => io.observe(r));
|
|
watch();
|
|
const off = onDomChange(watch); // new pages bring new rooms; observing twice is harmless
|
|
return () => { removeEventListener('scroll', on); io.disconnect(); off(); };
|
|
}, []);
|
|
return (
|
|
<>
|
|
<Nav headerRef={ref} />
|
|
<HeaderTools headerRef={ref} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
/* Hanzo's own footer (HTML from the server, components/Shell.jsx); its giant wordmark rises into place as the page ends. */
|
|
export function Footer() {
|
|
const ref = FOOTER;
|
|
useEffect(() => {
|
|
const f = ref.current?.querySelector('footer');
|
|
if (!f || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
const big = [...f.querySelectorAll<HTMLElement | SVGElement>('*')].filter((e) => parseFloat(getComputedStyle(e).fontSize) > 120 || (e.tagName === 'svg' && e.getBoundingClientRect().width > 300));
|
|
const el = big[0];
|
|
if (!el) return;
|
|
el.style.willChange = 'transform, opacity';
|
|
const stop = scroll(animate(el, { transform: ['translateY(36%)', 'translateY(0%)'], opacity: [0.2, 1] }, { ease: 'linear' }), { target: f, offset: ['start end', 'end end'] });
|
|
return () => stop && stop();
|
|
}, []);
|
|
return null;
|
|
}
|
|
|
|
/* An endless strip of logos. CSS drifts it (a transform on the compositor, nothing runs per frame in script); it rests under
|
|
the pointer and on focus, turns the other way with `reverse`, and stands still under reduced motion and off screen. */
|
|
export function Marquee({ items, label, reverse = false, view, still = false }: { items: { name: string; src: string; href?: string; w?: number; h?: number; hang?: number }[]; label: string; reverse?: boolean; view?: string; still?: boolean }) {
|
|
// each half holds the list twice so one half is always wider than the screen
|
|
const row = (k: number) => items.map((l) => {
|
|
const hidden = k > 0;
|
|
return (
|
|
<a key={k + l.name} href={l.href} className="x-logo" data-base={l.w ? '' : undefined} aria-hidden={hidden || undefined} tabIndex={hidden ? -1 : undefined} inert={hidden || undefined} title={l.name}>
|
|
<img src={l.src} alt={hidden ? '' : l.name} loading="lazy" width={l.w} height={l.h} style={l.w ? { marginBottom: -(l.hang ?? 0) } : undefined} />
|
|
</a>
|
|
);
|
|
});
|
|
return (
|
|
<section className={'x-marquee' + (still ? ' still' : '')} aria-label={label} data-hz-view={view}>
|
|
<p className="x-kicker">{label}</p>
|
|
<div className="x-mq-view">
|
|
<div className={'x-mq-track' + (reverse ? ' rev' : '')}>
|
|
{row(0)}{row(1)}{row(2)}{row(3)}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|