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
74 lines
4.0 KiB
TypeScript
74 lines
4.0 KiB
TypeScript
'use client';
|
|
/* A2Chapters — Apple-style sticky chapters for the Apps 2 pages (owned by the Apps 2 chat; styles in A2.css).
|
|
Usage:
|
|
<A2Chapters items={[{ k: 'Observe', t: 'Catch the failure', d: 'Reads the stack trace…' }, …]}
|
|
visual={(i, live) => <Thing step={i} live={live} />} flip={false} dark={false} label="The loop" />
|
|
Desktop: the section is one screen per chapter. A sticky stage pins the text on one side and the picture on the other;
|
|
as you scroll, one chapter comes in as the last goes out and visual(i, true) redraws for the active chapter. The small
|
|
numbered index jumps to a chapter (keyboard too). Phones: a plain vertical story, each chapter with its own picture,
|
|
visual(k, false). Reduced motion: the same states, no slide. Every chapter's words stay in the HTML, and with
|
|
JavaScript off a <noscript> rule lays the chapters out as that phone story. */
|
|
import { useRef, useState } from 'react';
|
|
import type { CSSProperties, ReactNode } from 'react';
|
|
import { useScroll, useMotionValueEvent } from 'motion/react';
|
|
import NoJs from '../NoJs';
|
|
|
|
interface Chapter { k?: string; t: string; d: ReactNode }
|
|
|
|
interface A2ChaptersProps {
|
|
items: readonly Chapter[];
|
|
visual: (i: number, live: boolean) => ReactNode;
|
|
flip?: boolean;
|
|
dark?: boolean;
|
|
label?: string;
|
|
className?: string;
|
|
head?: ReactNode;
|
|
}
|
|
|
|
export default function A2Chapters({ items, visual, flip, dark, label, className = '', head }: A2ChaptersProps) {
|
|
const ref = useRef<HTMLElement>(null);
|
|
const [on, setOn] = useState(0);
|
|
const { scrollYProgress } = useScroll({ target: ref, offset: ['start start', 'end end'] });
|
|
useMotionValueEvent(scrollYProgress, 'change', (v) => {
|
|
setOn(Math.min(items.length - 1, Math.max(0, Math.floor(v * items.length * 0.9999))));
|
|
});
|
|
const go = (k: number) => {
|
|
const el = ref.current;
|
|
if (!el) return;
|
|
const top = el.getBoundingClientRect().top + window.scrollY;
|
|
const span = el.offsetHeight - window.innerHeight;
|
|
const y = top + span * ((k + 0.5) / items.length);
|
|
if (window.__lenis) window.__lenis.scrollTo(y, { duration: 1.1 }); else window.scrollTo({ top: y, behavior: 'smooth' });
|
|
};
|
|
return (
|
|
<>
|
|
<NoJs css={'.a2-ch{height:auto!important;padding:120px 0 40px}.a2-ch-stick{position:static!important;height:auto!important;display:block!important}.a2-ch-nav,.a2-ch>.a2-ch-stick .a2-ch-vis{display:none!important}.a2-ch-items{gap:88px}.a2-ch-item{grid-area:auto!important;opacity:1!important;transform:none!important}.a2-ch-pv{display:block!important;margin-bottom:32px}'} />
|
|
<section ref={ref} className={'a2-ch' + (flip ? ' flip' : '') + (dark ? ' a2-dark' : '') + ' ' + className} style={{ '--n': items.length } as CSSProperties} aria-label={label} {...(dark ? { 'data-room': 'dark' } : {})}>
|
|
<div className="a2-ch-stick">
|
|
<div className="a2-wrap a2-ch-grid">
|
|
<div className="a2-ch-copy">
|
|
{head}
|
|
<div className="a2-ch-nav" role="group" aria-label={label ? label + ': chapters' : 'Chapters'}>
|
|
{items.map((c, k) => (
|
|
<button key={k} type="button" aria-current={k === on ? 'step' : undefined} aria-label={c.t} onClick={() => go(k)}>{String(k + 1).padStart(2, '0')}</button>
|
|
))}
|
|
</div>
|
|
<div className="a2-ch-items">
|
|
{items.map((c, k) => (
|
|
<article key={k} className={'a2-ch-item' + (k === on ? ' on' : '')} style={{ '--dy': (k < on ? -28 : 28) + 'px' } as CSSProperties}>
|
|
<div className="a2-ch-pv" aria-hidden="true">{visual(k, false)}</div>
|
|
{c.k && <p className="a2-kick">{c.k}</p>}
|
|
<h3 className="a2-headline">{c.t}</h3>
|
|
{typeof c.d === 'string' ? <p className="a2-body">{c.d}</p> : c.d}
|
|
</article>
|
|
))}
|
|
</div>
|
|
</div>
|
|
<div className="a2-ch-vis" aria-hidden="true">{visual(on, true)}</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</>
|
|
);
|
|
}
|