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

333 lines
20 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
/* /support. V2: 8/10 One question at a time on Hanzo's deck: the h1 and its lede, then the help-finder (left: one
question per screen, sliding; right: the answer card, the summary that builds), a closing Band with its email ask.
Persona: a customer or developer who needs help now. Goal: reach the right door in one step.
CTA: "Open Help Center" (https://hanzo.help), data-cta support.answer.1; metric: the one contact click.
Signature: one-question. Screen 1 asks the h1's question with the search pill (free text, still answering as you
type: each finished word, a space or 300ms, re-ranks the six ways and the best rises into the answer card, its
words marked). Under it, the six ways sit in Hanzo's order and light up
in place as your words match them (best outlined); Enter or the arrow focuses the best, arrow keys move, Enter or a
tap picks one. The answer card on the right is the summary as it builds: your
words, the way, its one action. The demo still types "support ticket", then "uptime".
Entrances: 1 card-deal on the h1 (its words dealt from a deck at the line's end), 2 cursor-lens on the lede (a
lens opens from the pointer and the words settle from magnified), 3 fold-out on the question screens (unfold from a
top hinge), 4 tile-flip on the answer card (a grid of tiles flips in to form it), 5 tilt-3d-hover on the closing
Band (arrives tilted back and levels, then leans toward a fine pointer, at most 2.5deg).
Beyond: whatever you typed becomes the subject line of a ready-to-send email to [email protected]; when a finished
word matches nothing on the page, the answer itself turns into that email, your words shown as its subject. */
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import type { CSSProperties, KeyboardEvent, PointerEvent } from 'react';
import { motion, useInView, useReducedMotion } from 'motion/react';
import { A, Go, Band } from '../kit';
import useArrived from './company/useArrived';
import '../v2/vc-type.css';
import './company/deck.css';
import './Support.css';
const EM = [0.16, 1, 0.3, 1] as const; // deck ease-emphasis
const IO = [0.4, 0, 0.2, 1] as const; // deck ease-in-out
const DOORS = [
{ t: 'Help Center', d: 'Search answers, browse guides, and open a support ticket. The fastest path to a resolution.', go: 'Open Help Center', to: 'https://hanzo.help' },
{ t: 'Documentation', d: 'Guides, API references, and quickstarts for every product across the Hanzo Cloud.', go: 'Read the docs', to: 'https://docs.hanzo.ai' },
{ t: 'System Status', d: 'Live uptime and incident history for every Hanzo service. Check here first if something feels off.', go: 'View status', to: 'https://status.hanzo.ai' },
{ t: 'Community', d: 'Ask questions and share what you build with other developers on the Hanzo Discord and Community.', go: 'Join the community', to: 'https://discord.gg/XthHQQj' },
{ t: 'GitHub', d: 'Report a bug, request a feature, or contribute — our SDKs and tooling are open source.', go: 'Open an issue', to: 'https://github.com/hanzoai' },
{ t: 'Email us', d: 'Prefer email? Reach the team directly and we’ll get back to you.', go: '[email protected]', to: 'mailto:[email protected]' },
];
const H1 = 'How can we help?';
const DEMO = 'support ticket'; // Hanzo's own words, from the Help Center's line: the ask stays Open Help Center
const DEMO2 = 'uptime'; // from System Status's own line: System Status rises into the answer
// JS off: every answer readable in order, the first question only, nothing waiting on an entrance
const NOJS = { __html: '<style>.xsp-panes{display:flex!important;flex-direction:column;gap:40px}.xsp-pane{opacity:1!important;transform:none!important;visibility:visible!important;pointer-events:auto!important}.xsp-pause,.xsp-next,.xsp-q2,.xsp-tiles{display:none!important}.xsp-rail{transform:none!important}</style>' };
const words = (s: string) => s.toLowerCase().match(/[a-z0-9]+/g) || [];
const terms = (q: string) => words(q).filter((w) => w.length > 2); // one letter or two is not a search yet
// a query word matches a page word that starts with it, or (4+ letters) one it starts with: "tickets" finds "ticket"
const hits = (w: string, h: string) => h.startsWith(w) || (w.length >= 4 && h.length >= 4 && w.startsWith(h));
interface Rank { i: number; score: number }
function rank(q: string): Rank[] {
const qs = terms(q);
return DOORS.map((d, i) => {
const hay = words(d.t + ' ' + d.d + ' ' + d.go);
const score = qs.reduce((n, w) => n + (hay.some((h) => hits(w, h)) ? 1 : 0), 0);
return { i, score };
}).sort((a, b) => b.score - a.score || a.i - b.i);
}
/* A description with the words the query matched marked (the mark is drawn, so no word moves). */
function Lit({ text, q }: { text: string; q: string }) {
const qs = terms(q);
if (!qs.length) return text;
return text.split(/(\s+)/).map((p, k) => {
const w = p.toLowerCase().replace(/[^a-z0-9]/g, '');
return w && qs.some((x) => hits(x, w)) ? <mark key={k}>{p}</mark> : p;
});
}
const Arrow = ({ back }: { back?: boolean }) => <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" style={back ? { transform: 'scaleX(-1)' } : undefined}><path d="M3 8h9M8.5 4.5 12 8l-3.5 3.5" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>;
const Mail = () => <svg viewBox="0 0 20 20" width="18" height="18" aria-hidden="true"><rect x="2.5" y="4.5" width="15" height="11" rx="2" fill="none" stroke="currentColor" strokeWidth="1.5" /><path d="m3 5.5 7 5.5 7-5.5" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" /></svg>;
const Lens = ({ size = 18 }: { size?: number }) => <svg viewBox="0 0 20 20" width={size} height={size} aria-hidden="true"><circle cx="9" cy="9" r="6" fill="none" stroke="currentColor" strokeWidth="1.5" /><path d="m13.5 13.5 4 4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" /></svg>;
function mailTo(subject: string) { return 'mailto:[email protected]' + (subject ? '?subject=' + encodeURIComponent(subject) : ''); }
/* go: at once on a return visit; 550ms after the arrival curtain starts lifting on a first visit (the top is clear). */
function useGo() {
const [curtain] = useState(() => typeof document !== 'undefined' && document.documentElement.classList.contains('x-arriving'));
const ok = useArrived();
const [go, setGo] = useState(false);
useEffect(() => {
if (!ok) return;
const t = setTimeout(() => setGo(true), curtain ? 550 : 0);
return () => clearTimeout(t);
}, [ok, curtain]);
return go;
}
/* Page-local entrance: marks the section data-in the first time a quarter of it is on screen (after `gate`); the CSS
under html.js plays that section's own entrance from there. before(el) runs just before, to aim it. */
const ptr = { x: -1, y: -1 };
function useEnter<T extends HTMLElement = HTMLElement>(gate = true, before?: (el: HTMLElement) => void) {
const ref = useRef<T>(null);
useEffect(() => {
const el = ref.current;
if (!el || !gate || el.hasAttribute('data-in')) return;
const io = new IntersectionObserver(([e]) => {
if (!e.isIntersecting) return;
before?.(el);
el.setAttribute('data-in', '');
io.disconnect();
}, { threshold: 0.25 });
// watch the section, not the element: an element hidden by its own clip-path (the lens) never reads as on screen
io.observe(el.closest('section') || el);
return () => io.disconnect();
}, [gate]); // eslint-disable-line react-hooks/exhaustive-deps
return ref;
}
/* 2. cursor-lens: the lens opens where the pointer last was (clamped into the lede), else at its start */
function aimLens(el: HTMLElement) {
const r = el.getBoundingClientRect();
const x = ptr.x < 0 ? 0 : Math.min(Math.max(ptr.x - r.left, 0), r.width);
const y = ptr.y < 0 ? r.height / 2 : Math.min(Math.max(ptr.y - r.top, 0), r.height);
el.style.setProperty('--lx', x + 'px');
el.style.setProperty('--ly', y + 'px');
}
export default function Support() {
const [q, setQ] = useState(''); // what is in the pill
const [dq, setDq] = useState(''); // the settled query: finished words only
const [mine, setMine] = useState(false);
const [done, setDone] = useState(false); // the demo has played, or was stopped
const [peek, setPeek] = useState(-1); // a way the pointer or focus is on
const [pick, setPick] = useState(-1); // the way chosen on screen 2
const [hyd, setHyd] = useState(false);
const go = useGo();
const input = useRef<HTMLInputElement>(null);
const form = useRef<HTMLFormElement>(null);
const btn = useRef<HTMLAnchorElement | null>(null);
const ways = useRef<(HTMLButtonElement | null)[]>([]);
const seen = useInView(form, { amount: 0.6 });
const calm = useReducedMotion();
useEffect(() => setHyd(true), []);
useEffect(() => {
const m = (e: globalThis.PointerEvent) => { ptr.x = e.clientX; ptr.y = e.clientY; };
addEventListener('pointermove', m, { passive: true });
return () => removeEventListener('pointermove', m);
}, []);
// the five entrances, in page order
const e1 = useEnter<HTMLHeadingElement>(go);
const e2 = useEnter<HTMLParagraphElement>(go, aimLens);
const e3 = useEnter<HTMLDivElement>(go);
const e4 = useEnter<HTMLDivElement>(go);
const e5 = useEnter<HTMLDivElement>(true);
// 1. card-deal: each word starts on the deck at the line's end and is dealt to its place
useLayoutEffect(() => {
const h = e1.current;
if (!h) return;
const cards = [...h.querySelectorAll<HTMLElement>('.xsp-card')];
const end = cards[cards.length - 1];
if (!end) return;
cards.forEach((c, k) => {
c.style.setProperty('--dx', end.offsetLeft - c.offsetLeft + 'px');
c.style.setProperty('--dy', end.offsetTop - c.offsetTop + 'px');
c.style.setProperty('--r', (k % 2 ? 7 : -9) + 'deg');
});
}, []); // eslint-disable-line react-hooks/exhaustive-deps
// 5. tilt-3d-hover: after it has levelled, the Band leans toward a fine pointer (2.5deg at most)
const tilt = (e: PointerEvent<HTMLDivElement>) => {
if (e.pointerType !== 'mouse' && e.pointerType !== 'pen') return;
const el = e5.current;
if (!el || calm) return;
const r = el.getBoundingClientRect();
const px = (e.clientX - r.left) / r.width - 0.5, py = (e.clientY - r.top) / r.height - 0.5;
el.style.setProperty('--ry', (px * 5).toFixed(2) + 'deg');
el.style.setProperty('--rx', (-py * 5).toFixed(2) + 'deg');
};
const level = () => { const el = e5.current; if (el) { el.style.setProperty('--ry', '0deg'); el.style.setProperty('--rx', '0deg'); } };
// a word is finished at a space, or after 300ms without typing
useEffect(() => {
if (/\s$/.test(q) || !q) { setDq(q); return; }
const t = setTimeout(() => setDq(q), 300);
return () => clearTimeout(t);
}, [q]);
const ranked = useMemo(() => rank(dq), [dq]);
const typed = terms(dq).length > 0;
const hit = typed && ranked[0].score > 0;
const subject = q.trim();
// the summary: a way you point at; else the one you picked; else the best match; with words that match nothing, email
const best = peek >= 0 ? peek : pick >= 0 ? pick : hit ? ranked[0].i : mine && typed ? 5 : 0;
// the six ways keep Hanzo's order; your words light the matches in place (nothing jumps while you type)
const order = DOORS.map((_, i) => ranked.find((r) => r.i === i) as Rank); // rank lists every way
// the demo, once, after the headline has landed: type Hanzo's phrase, hold, clear, rest
useEffect(() => {
if (mine || calm || !seen || done || !go) return;
let alive = true, timer: ReturnType<typeof setTimeout> | undefined;
const el = input.current;
if (!el) return;
const sleep = (ms: number) => new Promise<void>((r) => { timer = setTimeout(r, ms); });
(async () => {
await sleep(1600);
for (let c = 1; c <= DEMO.length && alive; c++) {
el.value = DEMO.slice(0, c);
if (DEMO[c] === ' ' || c === DEMO.length) { setQ(el.value); setDq(el.value); }
await sleep(60 + (c % 4) * 18);
}
if (!alive) return;
await sleep(2400);
for (let c = DEMO.length; c >= 0 && alive; c--) { el.value = DEMO.slice(0, c); await sleep(14); }
for (let c = 1; c <= DEMO2.length && alive; c++) {
el.value = DEMO2.slice(0, c);
if (c === DEMO2.length) { setQ(el.value); setDq(el.value); }
await sleep(70 + (c % 3) * 20);
}
if (!alive) return;
await sleep(2600);
for (let c = DEMO2.length; c >= 0 && alive; c--) { el.value = DEMO2.slice(0, c); await sleep(16); }
if (alive) { setQ(''); setDq(''); setDone(true); }
})();
return () => { alive = false; clearTimeout(timer); };
}, [mine, calm, seen, done, go]);
const stop = () => { if (done || mine) return; setDone(true); if (input.current) input.current.value = ''; setQ(''); setDq(''); };
const take = () => { if (!mine) { stop(); setMine(true); setDone(true); } };
const playing = !mine && !done && !calm;
const live = (mine && typed) || pick >= 0 ? DOORS[best].t : '';
// Enter or the arrow: the best way for your words takes focus, right under the question
const next = () => {
take();
setDq(q); setPeek(-1);
const k = hit ? ranked[0].i : mine && typed ? 5 : 0;
requestAnimationFrame(() => ways.current[k]?.focus({ preventScroll: true }));
};
const back = () => { setPeek(-1); requestAnimationFrame(() => input.current?.focus({ preventScroll: true })); };
const choose = (i: number) => { setPick(i); setPeek(-1); requestAnimationFrame(() => btn.current?.focus({ preventScroll: true })); };
const keys = (e: KeyboardEvent<HTMLButtonElement>, k: number) => {
const n = DOORS.length;
const to = ({ ArrowRight: k + 1, ArrowLeft: k - 1, ArrowDown: k + 2, ArrowUp: k - 2, Home: 0, End: n - 1 } as Record<string, number | undefined>)[e.key];
if (to === undefined) { if (e.key === 'Escape') back(); return; }
e.preventDefault();
ways.current[Math.min(Math.max(to, 0), n - 1)]?.focus({ preventScroll: true });
};
return (
<main className="vc xsp" style={{ '--acc': '#0a0a0a' } as CSSProperties} data-ask-name="Support" data-go={go || undefined}>
<section className="xsp-hero" aria-labelledby="xsp-h1">
<div className="vc-grid xsp-hero-g" onFocusCapture={stop}>
<h1 id="xsp-h1" ref={e1} className="vc-display xsp-h1 xsp-deal">
{H1.split(' ').map((w, k, a) => <span key={k}><span className="xsp-card" style={{ '--i': k } as CSSProperties}>{w}</span>{k < a.length - 1 ? ' ' : ''}</span>)}
</h1>
<p ref={e2} className="vc-lede xsp-lede xsp-lens">Answers, docs, live status, and a direct line to the team.</p>
{/* the page's ask lives on the whole help-finder (both screens and the summary), never on a pane that swaps */}
<div className="xsp-room" onPointerEnter={stop} onPointerLeave={() => setPeek(-1)} data-thumb="Open Help Center" data-href="https://hanzo.help">
<div ref={e3} className="xsp-ask xsp-fold">
<div className="xsp-track">
<div className="xsp-rail">
<div className="xsp-q xsp-q1">
<form role="search" aria-label="Support" ref={form} className="xsp-search" onSubmit={(e) => { e.preventDefault(); next(); }}>
<label htmlFor="xsp-q" className="x-sr">{H1}</label>
<Lens size={24} />
<input id="xsp-q" ref={input} type="search" autoComplete="off" spellCheck="false" enterKeyHint="next" placeholder={DEMO}
onPointerDown={take} onFocus={take} onKeyDown={take}
onChange={(e) => { setMine(true); setDone(true); setPick(-1); setQ(e.target.value); }} />
{playing ? (
<button type="button" className="xsp-pause" aria-label="Pause" onClick={stop}>
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M5 3.5v9M11 3.5v9" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /></svg>
</button>
) : (
<button type="submit" className="xsp-next" aria-label="Next"><Arrow /></button>
)}
</form>
</div>
<div className="xsp-q xsp-q2">
<ol className="xsp-ways" aria-label="Support">
{order.map(({ i, score }, k) => (
<motion.li key={DOORS[i].t} layout transition={{ duration: 0.3, ease: IO }}>
<button type="button" ref={(el) => { ways.current[k] = el; }} aria-pressed={pick === i}
className={'xsp-way' + (pick === i ? ' picked' : '') + (i === best ? ' best' : typed && score ? ' match' : '')}
onClick={() => choose(i)} onKeyDown={(e) => keys(e, k)}
onPointerEnter={() => setPeek(i)} onFocus={() => setPeek(i)} onBlur={() => setPeek(-1)}>
<span>{DOORS[i].t}</span><Arrow />
</button>
</motion.li>
))}
</ol>
</div>
</div>
</div>
</div>
{/* the summary as it builds: your words, the way, its one action */}
<div ref={e4} className="xsp-answer xsp-flip">
<p className="x-sr" aria-live={mine || pick >= 0 ? 'polite' : 'off'}>{live}</p>
<p className={'xsp-said' + (mine && typed ? ' on' : '')} aria-hidden={!(mine && typed)}>
{best === 5 ? <Mail /> : <Lens />}<span>“{subject}”</span>
</p>
<div className="xsp-panes">
{DOORS.map((d, i) => {
const on = i === best;
const mail = i === 5;
const href = mail ? mailTo(mine ? subject : '') : d.to;
return (
<motion.div key={d.t} className={'xsp-pane' + (on ? ' on' : '')} initial={false}
animate={on ? { opacity: 1, y: 0 } : { opacity: 0, y: 12 }}
transition={{ duration: on ? 0.3 : 0.15, ease: EM, delay: on ? 0.05 : 0 }}
{...(hyd && !on ? { 'aria-hidden': true, inert: true } : {})}>
<h2 className="xsp-answer-t">{d.t}</h2>
<p className="xsp-answer-d"><Lit text={d.d} q={dq} /></p>
<div className="xsp-answer-a">
<span className="xsp-go" data-cta={'support.answer.' + (i + 1)} ref={on ? (el) => { btn.current = el?.querySelector('a') ?? null; } : undefined}>
<Go to={href} solid className="xsp-big">{mail && mine && typed ? 'Email [email protected]' : d.go}</Go>
</span>
</div>
</motion.div>
);
})}
</div>
<div className="xsp-tiles" aria-hidden="true">{Array.from({ length: 24 }, (_, k) => <i key={k} style={{ '--d': (k % 6) + Math.floor(k / 6) } as CSSProperties} />)}</div>
</div>
</div>
<noscript dangerouslySetInnerHTML={NOJS} />
</div>
</section>
<div ref={e5} className="xsp-tilt" onPointerMove={tilt} onPointerLeave={level}>
<Band title="On an enterprise plan or need a dedicated channel?" action="Email [email protected]" to="mailto:[email protected]"
note={<>
<span className="xsp-note">and we’ll route you to your team.</span>
{/* the room's object: Hanzo's six doors as one quiet row, each its own destination */}
<span className="xsp-band-doors">{DOORS.map((d) => <A key={d.t} to={d.to}>{d.t}</A>)}</span>
</>} />
</div>
</main>
);
}