mirror of
https://github.com/hanzoai/site.git
synced 2026-11-21 01:07:08 +00:00
* Type model, templates, reviews and sms pages under strict Props, state, refs and handlers typed; null guards where the types showed a possible null. creativeData exports Slug. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type Kai/Mori/Koe/Uta, research, philosophy, press and risk pages under strict Props, state, refs and handlers typed; ref callbacks no longer return the element. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type x-tender, solutions, story, tag, startups, support, newsletter and mcp pages under strict Captured-page trees and docs get shared types. Null-safe reads where a figure has no source or a page has no siblings. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type open source, platform, products, operative, trust, sdks and o11y pages under strict Captured-page trees, product docs and org data get shared types. Null guards on refs and canvas contexts; product() throws a clear error for a captured page with no API section. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type post, pricing, team, slack, skills, security, tabs and proof pages under strict Live pricing uses the lib Rung/Group/Row types. Null guards on refs and canvas contexts. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type models, studio, university, science, referral, operator, network and module pages under strict Model and university data tables get explicit row types; the Opener shape is shared by ModelsPage and Studio. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Narrow the review entry in its test entry() returns Review | null under strict; the test asserts it is set before use. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the Newsletter send button ref as a button Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Fit the callers of the typed pages to their types Product, solutions and tabs-tree callers use the page types; the open-source snapshot reads lib/oss's own Summary and Activity; the O11y card ref is a list item ref. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
56 lines
2.6 KiB
TypeScript
56 lines
2.6 KiB
TypeScript
'use client';
|
|
/* The /models family's entrance triggers (docs/MOTION-MAP.md rule 7). Only the moment is shared here: each section's
|
|
way of arriving is its own CSS (ModelsPage.css for /models, models.css for /models/*). Once per section, when its
|
|
top passes 82% of the screen; reduced motion lands at once; with JavaScript off nothing waits (html:not(.js)). */
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
|
export const calmNow = () => typeof window !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
/* [ref, in]: `in` turns true once the element enters view (true at once under reduced motion) */
|
|
export function useEnter<T extends HTMLElement = HTMLElement>(margin = '0px 0px -18% 0px') {
|
|
const ref = useRef<T>(null);
|
|
const [on, setOn] = useState(false);
|
|
useEffect(() => {
|
|
const el = ref.current;
|
|
if (!el) return undefined;
|
|
if (calmNow()) { setOn(true); return undefined; }
|
|
const io = new IntersectionObserver(([e]) => { if (e.isIntersecting) { setOn(true); io.disconnect(); } }, { rootMargin: margin });
|
|
io.observe(el);
|
|
return () => io.disconnect();
|
|
}, [margin]);
|
|
return [ref, on] as const;
|
|
}
|
|
|
|
/* card-deal: a list's items wait in one deck on the first item's place, then are dealt out to their own places, one
|
|
after another. Measured in the browser (any grid or rail); items past `max` only fade. data-deal drives the CSS. */
|
|
export function useDeal(max = 10) {
|
|
const ref = useRef<HTMLUListElement>(null);
|
|
useEffect(() => {
|
|
const ul = ref.current;
|
|
if (!ul || calmNow()) return undefined;
|
|
ul.dataset.deal = 'wait';
|
|
let raf = 0;
|
|
const io = new IntersectionObserver(([e]) => {
|
|
if (!e.isIntersecting) return;
|
|
io.disconnect();
|
|
const items = ([...ul.children] as HTMLElement[]).filter((li) => !li.hidden);
|
|
if (!items.length) { ul.dataset.deal = 'done'; return; }
|
|
const a = items[0].getBoundingClientRect();
|
|
items.forEach((li, i) => {
|
|
const r = li.getBoundingClientRect();
|
|
const far = i > max;
|
|
li.style.setProperty('--dx', (far ? 0 : Math.round(a.left - r.left)) + 'px');
|
|
li.style.setProperty('--dy', (far ? 24 : Math.round(a.top - r.top)) + 'px');
|
|
li.style.setProperty('--i', String(Math.min(i, max)));
|
|
});
|
|
ul.dataset.deal = 'deck';
|
|
void ul.offsetWidth;
|
|
raf = requestAnimationFrame(() => { raf = requestAnimationFrame(() => { ul.dataset.deal = 'go'; }); });
|
|
setTimeout(() => { ul.dataset.deal = 'done'; }, 700 + 70 * max + 200);
|
|
}, { rootMargin: '0px 0px -15% 0px' });
|
|
io.observe(ul);
|
|
return () => { io.disconnect(); cancelAnimationFrame(raf); };
|
|
}, [max]);
|
|
return ref;
|
|
}
|