Files
zeekayandGitHub 4b7a524989 Type pages (mcp to x-tender) under strict (#9)
* 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
2026-11-14 01:44:08 -08:00

69 lines
3.6 KiB
TypeScript

'use client';
/* The post's five entrances (docs/MOTION-MAP.md, /blog/*), each section its own way, in page order:
1. pendulum the hero's film card swings in from its top edge and settles (pure CSS from first paint, enter.css)
2. typewriter each chapter heading types itself out behind a caret
3. grid-wave the plate's facts (or, on a post with the Game of Life, its board) ripple in by distance from
the pointer (from the grid's top-left corner when there is no pointer)
4. page-curl each next-post card's cover curls away from its bottom-right corner to show the picture
5. underline-sweep the closing line: an underline sweeps under each word in turn
One IntersectionObserver plays each once when about a quarter is in view. Start states live only under
main.xbg-enter, a class added on mount, so server HTML, JS off and reduced motion show everything at rest. */
import { useEffect } from 'react';
export function useEnter() {
useEffect(() => {
const main = document.querySelector('main.xbg');
if (!main || typeof IntersectionObserver === 'undefined') return;
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
let px: number | null = null, py: number | null = null;
const track = (e: PointerEvent) => { px = e.clientX; py = e.clientY; };
addEventListener('pointermove', track, { passive: true });
const timers: ReturnType<typeof setTimeout>[] = [];
const type = (h: HTMLElement) => {
const text = h.textContent ?? '';
const tw = document.createElement('span');
tw.className = 'xbg-tw';
tw.setAttribute('aria-hidden', 'true');
h.appendChild(tw);
h.dataset.typing = '';
const per = Math.max(14, Math.min(36, 760 / text.length));
let n = 0;
const tick = () => {
n += 1;
tw.textContent = text.slice(0, n);
if (n < text.length) timers.push(setTimeout(tick, per));
else timers.push(setTimeout(() => { tw.remove(); delete h.dataset.typing; }, 420));
};
tick();
};
const wave = (g: HTMLElement) => {
const r = g.getBoundingClientRect();
const ox = px ?? r.left, oy = py ?? r.top;
const kids = [...g.children] as HTMLElement[];
const far = Math.max(1, ...kids.map((k) => { const b = k.getBoundingClientRect(); return Math.hypot(b.left + b.width / 2 - ox, b.top + b.height / 2 - oy); }));
kids.forEach((k) => {
const b = k.getBoundingClientRect();
k.style.setProperty('--d', Math.round((Math.hypot(b.left + b.width / 2 - ox, b.top + b.height / 2 - oy) / far) * 520) + 'ms');
});
timers.push(setTimeout(() => { g.dataset.in = 'done'; kids.forEach((k) => k.style.removeProperty('--d')); }, 1400));
};
const io = new IntersectionObserver((es) => {
es.forEach((e) => {
if (!e.isIntersecting) return;
const el = e.target as HTMLElement;
io.unobserve(el);
if (el.dataset.enter === 'grid-wave') wave(el);
el.dataset.in = el.dataset.in || '1';
if (el.dataset.enter === 'typewriter') type(el);
});
}, { threshold: 0.25 });
const els = [...main.querySelectorAll<HTMLElement>('[data-enter]:not([data-enter="pendulum"])')];
// anything already on screen at mount keeps its rest state (never hide what was being read)
els.forEach((el) => { const b = el.getBoundingClientRect(); if (b.top < innerHeight && b.bottom > 0) el.dataset.in = 'done'; else io.observe(el); });
main.classList.add('xbg-enter');
return () => { io.disconnect(); removeEventListener('pointermove', track); timers.forEach(clearTimeout); main.classList.remove('xbg-enter'); };
}, []);
}