mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:21:13 +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
120 lines
5.3 KiB
TypeScript
120 lines
5.3 KiB
TypeScript
'use client';
|
|
/* Chapters (v2, owned by the Home chat): the Apple product-page pattern. The scene pins; the words hold on the left
|
|
while the pictures change on the right, each new one wiping up over the last as you scroll (one comes in as the
|
|
last goes out). An index beside it shows where you are and jumps to any chapter. On phones and with reduced motion
|
|
nothing pins: each chapter is its picture, then its words, one after another.
|
|
Usage:
|
|
import Chapters from '../v2/Chapters';
|
|
<Chapters label="Hanzo products" step={0.8} items={[
|
|
{ key: 'dev', title: 'Dev', to: '/dev', text: <p>…</p>, visual: <div>…</div> },
|
|
]} />
|
|
- title is a link to `to` and carries data-morph, so it opens into that page (Morph layer).
|
|
- a click on a picture (not on a link inside it) opens the same page.
|
|
- step: screens of scroll each chapter holds (default 0.8).
|
|
Every chapter is in the HTML; the hidden ones are inert. Needs components/v2/system.css. */
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import type { CSSProperties, ReactNode } from 'react';
|
|
import { motion, useMotionValueEvent, useReducedMotion, useScroll, useTransform } from 'motion/react';
|
|
import type { MotionValue } from 'motion/react';
|
|
import { A } from '../kit';
|
|
import './Chapters.css';
|
|
|
|
const pad = (n: number) => String(n).padStart(2, '0');
|
|
|
|
interface ChapterItem {
|
|
key: string;
|
|
title: string;
|
|
to: string;
|
|
text: ReactNode;
|
|
visual: ReactNode;
|
|
}
|
|
|
|
interface VisualProps {
|
|
i: number;
|
|
n: number;
|
|
p: MotionValue<number>;
|
|
pinned: boolean | null;
|
|
item: ChapterItem;
|
|
onOpen: () => void;
|
|
}
|
|
|
|
function Visual({ i, n, p, pinned, item, onOpen }: VisualProps) {
|
|
// chapter i wipes up over chapter i-1 in the last stretch before its turn
|
|
const q = useTransform(p, (v) => v * n);
|
|
const clip = useTransform(q, (v) => {
|
|
if (i === 0) return 'inset(0% 0% 0% 0% round 28px)';
|
|
const t = Math.max(0, Math.min(1, (v - i + 0.6) / 0.6));
|
|
const e = 1 - Math.pow(1 - t, 3);
|
|
return `inset(${((1 - e) * 100).toFixed(2)}% 0% 0% 0% round 28px)`;
|
|
});
|
|
// the one going out sinks back a little as the next arrives
|
|
const scale = useTransform(q, (v) => { const t = Math.max(0, Math.min(1, (v - i - 0.4) / 0.6)); return 1 - t * 0.06; });
|
|
const on = pinned !== false;
|
|
return (
|
|
<motion.div className="v2-ch-vis" style={on ? { clipPath: clip, scale } : { clipPath: 'none', scale: 1 }} onClick={(e) => { if (!(e.target as Element).closest("a, button")) onOpen(); }} data-cursor="">
|
|
{item.visual}
|
|
</motion.div>
|
|
);
|
|
}
|
|
|
|
interface ChaptersProps {
|
|
items: readonly ChapterItem[];
|
|
label?: string;
|
|
step?: number;
|
|
className?: string;
|
|
}
|
|
|
|
export default function Chapters({ items, label, step = 0.8, className = '' }: ChaptersProps) {
|
|
const n = items.length;
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
const calm = useReducedMotion();
|
|
const [pinned, setPinned] = useState<boolean | null>(null);
|
|
const [at, setAt] = useState(0);
|
|
useEffect(() => {
|
|
const m = matchMedia('(min-width: 900px)');
|
|
const f = () => setPinned(m.matches && !calm);
|
|
f();
|
|
m.addEventListener('change', f);
|
|
return () => m.removeEventListener('change', f);
|
|
}, [calm]);
|
|
const { scrollYProgress: p } = useScroll({ target: ref, offset: ['start start', 'end end'] });
|
|
useMotionValueEvent(p, 'change', (v) => { const k = Math.max(0, Math.min(n - 1, Math.floor(v * n + 0.3))); setAt((c) => (c === k ? c : k)); });
|
|
const fill = useTransform(p, [0, 1], [1 / n, 1]);
|
|
const jump = (i: number) => {
|
|
const el = ref.current;
|
|
if (!el) return;
|
|
const r = el.getBoundingClientRect();
|
|
const y = scrollY + r.top + ((i + 0.08) / n) * (el.offsetHeight - innerHeight);
|
|
window.__lenis ? window.__lenis.scrollTo(y, { duration: 1.1 }) : scrollTo({ top: y, behavior: 'smooth' });
|
|
};
|
|
const open = (i: number) => document.getElementById(`v2-ch-${items[i].key}`)?.click();
|
|
const live = pinned !== false;
|
|
|
|
return (
|
|
<div ref={ref} className={'v2-ch ' + className} data-pinned={pinned === null ? undefined : String(pinned)} style={{ '--v2-n': n, '--v2-step': step } as CSSProperties} role="group" aria-label={label}>
|
|
<div className="v2-ch-in v2-wrap">
|
|
<div className="v2-ch-grid">
|
|
{items.map((it, i) => (
|
|
<div className="v2-ch-item" key={it.key} data-on={!live || at === i} role="group" aria-label={`${i + 1} of ${n}: ${it.title}`}>
|
|
<div className="v2-ch-text" inert={live && pinned && at !== i ? true : undefined}>
|
|
<A id={`v2-ch-${it.key}`} to={it.to} className="v2-ch-title" data-morph="">{it.title}</A>
|
|
<p className="v2-kicker v2-ch-count"><span>{pad(i + 1)}</span> / {pad(n)}</p>
|
|
<div className="v2-ch-body">{it.text}</div>
|
|
</div>
|
|
<Visual i={i} n={n} p={p} pinned={pinned} item={it} onOpen={() => open(i)} />
|
|
</div>
|
|
))}
|
|
<nav className="v2-ch-index" aria-label={label + ': chapters'}>
|
|
<i className="v2-ch-track" aria-hidden="true"><motion.b style={{ scaleY: fill }} /></i>
|
|
<ol>
|
|
{items.map((it, i) => (
|
|
<li key={it.key}><button type="button" aria-current={at === i ? 'step' : undefined} onClick={() => jump(i)}>{it.title}</button></li>
|
|
))}
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|