Files
zeekayandGitHub ea43c5a975 Type lib, scripts, v2, home and app under strict (#8)
* 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
2026-11-14 01:34:34 -08:00

124 lines
5.9 KiB
TypeScript

'use client';
/* Chaptered: v2 sticky chapters (docs/VISION.md, motion 1), owned by the Wave 2 Programs chat.
The words pin on one side while the visual on the other changes; scrolling brings one chapter in as the last goes
out. Every chapter's words are in the HTML. On phones (≤ 900 px) it becomes a plain vertical story: each chapter
followed by its own still visual. Keyboard: tabbing into a chapter scrolls to it; the rail's dots jump to each.
Usage:
<Chaptered label="How it works" chapters={[{ kicker, title, body }]} stage={(i, still) => <Visual at={i} />} />
- stage(i, still): the visual for chapter i (still = true for the phone copies: draw the end state, no loops);
- head: a node shown above the pinned words (desktop) and above the story (phone);
- flip: the visual on the left; dark: the page's one dark room (sets data-room for the header);
- per: viewport heights of scroll per chapter (default 0.9);
- statement: chapter titles are whole sentences (Hanzo's own step text), set at a statement size, not a headline.
No kicker above a chapter title (JAMES.md bans eyebrows); the rail and the object's own counter carry the order.
Needs components/v2/ProgramScale.css. */
import { useRef, useState } from 'react';
import type { CSSProperties, ReactNode } from 'react';
import { motion, useScroll, useMotionValueEvent } from 'motion/react';
import './Chaptered.css';
const EASE = [0.16, 1, 0.3, 1] as const;
interface Chapter {
kicker?: string;
title: string;
body?: ReactNode;
}
type Stage = (i: number, still: boolean) => ReactNode;
interface ChapteredProps {
chapters: readonly Chapter[];
stage: Stage;
head?: ReactNode;
label?: string;
flip?: boolean;
dark?: boolean;
per?: number;
statement?: boolean;
id?: string;
className?: string;
}
export default function Chaptered({ chapters, stage, head, label, flip = false, dark = false, per = 0.9, statement = false, id, className = '' }: ChapteredProps) {
const ref = useRef<HTMLElement>(null);
const n = chapters.length;
const [at, setAt] = useState(0);
const { scrollYProgress } = useScroll({ target: ref, offset: ['start start', 'end end'] });
const fill = scrollYProgress;
useMotionValueEvent(scrollYProgress, 'change', (p) => {
const i = Math.max(0, Math.min(n - 1, Math.floor(p * n * 0.9999)));
if (i !== at) setAt(i);
});
const go = (i: number) => {
const el = ref.current;
if (!el || getComputedStyle(el).getPropertyValue('--pinned').trim() !== '1') return;
const top = el.getBoundingClientRect().top + window.scrollY;
const y = top + ((i + 0.5) / n) * (el.offsetHeight - window.innerHeight);
window.__lenis ? window.__lenis.scrollTo(y, { duration: 1.1 }) : window.scrollTo({ top: y, behavior: 'smooth' });
};
return (
<section ref={ref} id={id} className={'xpc' + (flip ? ' flip' : '') + (dark ? ' xp-dark' : '') + ' ' + className} style={{ '--n': n, '--per': per } as CSSProperties} aria-label={label} {...(dark ? { 'data-room': 'dark' } : {})}>
<div className="xpc-pin">
<div className="xp-wrap xpc-grid">
<div className="xpc-words">
{head && <div className="xpc-head">{head}</div>}
<div className="xpc-stack">
{chapters.map((c, i) => (
<motion.article key={i} className={'xpc-ch' + (i === at ? ' on' : '')} onFocusCapture={() => { if (i !== at) go(i); }}
initial={false} animate={i === at ? { opacity: 1, y: 0 } : { opacity: 0, y: i < at ? -16 : 24 }}
transition={i === at ? { duration: 0.4, ease: EASE, delay: 0.06 } : { duration: 0.15, ease: [0, 0, 0.2, 1] }}>
<h3 className={'xp-head xpc-t' + (statement ? ' st' : '')}>{c.title}</h3>
{c.body && <div className="xp-body xpc-b">{c.body}</div>}
</motion.article>
))}
</div>
<nav className="xpc-rail" aria-label={label}>
<span className="xpc-track" aria-hidden="true"><motion.i style={{ scaleY: fill }} /></span>
{chapters.map((c, i) => (
<button key={i} type="button" className={i <= at ? 'on' : ''} aria-current={i === at ? 'step' : undefined} onClick={() => go(i)}>
<span className="x-sr">{String(i + 1).padStart(2, '0')}</span>
</button>
))}
</nav>
</div>
<div className="xpc-stage" aria-hidden="true">
<div className="xpc-stage-in">{stage(at, false)}</div>
</div>
</div>
</div>
{/* phones: the same chapters as a rail you swipe, each card with its own still visual */}
<div className="xpc-story">
{head && <div className="xpc-head">{head}</div>}
<Swipe chapters={chapters} stage={stage} statement={statement} />
</div>
</section>
);
}
/* The phone rail: one card per chapter, snapping; the dots follow the card in view. */
function Swipe({ chapters, stage, statement }: { chapters: readonly Chapter[]; stage: Stage; statement: boolean }) {
const ref = useRef<HTMLDivElement>(null);
const [on, setOn] = useState(0);
const scroll = () => {
const el = ref.current;
if (!el || !el.firstElementChild) return;
const w = el.firstElementChild.getBoundingClientRect().width + 12;
setOn(Math.max(0, Math.min(chapters.length - 1, Math.round(el.scrollLeft / w))));
};
return (
<>
<div className="xpc-rail-p" ref={ref} onScroll={scroll} data-swipe-own>
{chapters.map((c, i) => (
<div className="xpc-sch" key={i}>
<div className="xpc-sstage" aria-hidden="true">{stage(i, true)}</div>
<h3 className={'xp-title' + (statement ? ' st' : '')}>{c.title}</h3>
{c.body && <div className="xp-body xpc-b">{c.body}</div>}
</div>
))}
</div>
<div className="xpc-dots" aria-hidden="true">{chapters.map((_, i) => <i key={i} className={i === on ? 'on' : ''} />)}</div>
</>
);
}