ouroboros / source /src /HeroScene.tsx
REXWind's picture
Publish the Ouroboros scientific showcase to CladeTeam
03677d0 verified
Raw History Blame Contribute Delete
4.78 kB
import {useEffect, useRef, useState} from 'react';
import type {CSSProperties} from 'react';
import {Molecule} from './Molecule';
import {useMotion} from './Motion';
import type {ProteinCase} from './types';
type Direction='joint'|'design'|'describe';
const captions={joint:'Two supervised directions. Connected through shared parameters.',design:'Functional language → amino-acid sequence',describe:'Amino-acid sequence → functional language'};
export function HeroScene({protein}:{protein:ProteinCase}){
const [direction,setDirection]=useState<Direction>('joint');
const [visible,setVisible]=useState(false);
const host=useRef<HTMLDivElement>(null);
const {enabled}=useMotion();
useEffect(()=>{
const observer=new IntersectionObserver(([entry])=>setVisible(entry.isIntersecting),{threshold:.08});
if(host.current)observer.observe(host.current);
const visibility=()=>{if(document.hidden)setVisible(false);else if(host.current){const r=host.current.getBoundingClientRect();setVisible(r.bottom>0&&r.top<innerHeight);}};
document.addEventListener('visibilitychange',visibility);
return()=>{observer.disconnect();document.removeEventListener('visibilitychange',visibility);};
},[]);
const running=enabled&&visible;
return <div ref={host} className="hero-scene" data-direction={direction} data-running={running} role="group" aria-label="Explore the two protein–language directions">
<div className="scene-topline"><span className="micro">PROTEIN–LANGUAGE INTERFACE</span><span className="scene-indicator"><i/> DUAL LEARNING</span></div>
<div className="scene-stage-art">
<div className="scene-grid" aria-hidden="true"/>
<svg className="scene-paths" viewBox="0 0 600 470" fill="none" aria-hidden="true">
<defs><linearGradient id="design-gradient" x1="70" y1="180" x2="500" y2="180" gradientUnits="userSpaceOnUse"><stop stopColor="#4286c5"/><stop offset="1" stopColor="#d66b40"/></linearGradient><linearGradient id="describe-gradient" x1="500" y1="345" x2="65" y2="345" gradientUnits="userSpaceOnUse"><stop stopColor="#d66b40"/><stop offset="1" stopColor="#4286c5"/></linearGradient></defs>
<ellipse cx="340" cy="238" rx="174" ry="160" className="scene-orbit"/>
<ellipse cx="340" cy="238" rx="194" ry="180" className="scene-orbit outer"/>
<g className="design-path"><path className="path-base" d="M100 193 C100 8 496 10 496 183" stroke="url(#design-gradient)"/><path className="path-stream" d="M100 193 C100 8 496 10 496 183" stroke="url(#design-gradient)"/><path d="m488 172 8 12 8-12" stroke="#d66b40" strokeWidth="1.5"/></g>
<g className="describe-path"><path className="path-base" d="M495 306 C495 467 100 465 100 313" stroke="url(#describe-gradient)"/><path className="path-stream" d="M495 306 C495 467 100 465 100 313" stroke="url(#describe-gradient)"/><path d="m92 325 8-12 8 12" stroke="#4286c5" strokeWidth="1.5"/></g>
<g className="orbit-ticks" stroke="#c8c9b9" strokeWidth="1"><path d="M340 49v10m0 358v10M146 238h10m368 0h10M202 102l7 7m262 258 7 7M202 374l7-7m262-258 7-7"/></g>
</svg>
<span className="path-caption design-caption">design <span>↗</span></span>
<span className="path-caption describe-caption"><span>↖</span> describe</span>
<div className="scene-molecule"><Molecule protein={protein} hero color="warm" spinning={running}/></div>
<div className="scene-language"><div className="scene-card-label"><span>Aa</span><span>FUNCTIONAL LANGUAGE</span></div><p>“Capable of<br/>degrading PET.”</p><div className="language-spectrum" aria-hidden="true"><i/><i/><i/><i/><i/><i/><i/></div><span className="scene-card-note">DESCRIBE A FUNCTION</span></div>
<div className="scene-sequence"><div className="scene-card-label"><span>⌁</span><span>PROTEIN SEQUENCE</span></div><div className="scene-residues" aria-label={`${protein.sequence.slice(0,18)}…`}>{protein.sequence.slice(0,18).split('').map((aa,i)=><span key={i} style={{'--residue-delay':`${i*.11}s`} as CSSProperties}>{aa}</span>)}<span>…</span></div><span className="scene-card-note">{protein.length} AA · DE2 PETASE</span></div>
<div className="scene-center-label"><span>⇄</span> SHARED PARAMETERS</div>
</div>
<div className="scene-controls" role="group" aria-label="Hero learning direction">{([['joint','Learn together'],['design','Design →'],['describe','← Describe']] as [Direction,string][]).map(([value,label])=><button key={value} aria-pressed={direction===value} onClick={()=>setDirection(value)}>{label}</button>)}</div>
<p className="scene-caption" aria-live="polite">{captions[direction]}</p>
<div className="scene-provenance"><span><i/> DE2 · predicted fold · drag to rotate</span><a href="#petase" aria-label="Explore the DE2 PETase evidence">Explore protein ↗</a></div>
</div>;
}