HEL-822: land HEL-821 A1+A2 source onto PR#4 base (db571ba)
- 13 modified / 8 added / 1 deleted per CHANGES.json (author package 76bc120b) - docs/requirements v1.10 + prototypes/hel-799 + PROVENANCE from bundle, verified byte-identical to63799f0- AGENTS.md + scripts/check_requirements.py restored from governance commit63799f0Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
import { useLayoutEffect, useRef, useState } from 'react';
|
||||
|
||||
// Identity is a turn, not a token or a database id. Finalizing a stream keeps
|
||||
// its DOM and animation. Only a replacement retains/fades out the old sentence.
|
||||
export function SoftText({ identity, text }: { identity: string; text: string }) {
|
||||
const current = useRef<HTMLSpanElement>(null), outgoing = useRef<HTMLSpanElement>(null);
|
||||
const previous = useRef({ identity, text });
|
||||
const [leaving, setLeaving] = useState<{ identity: string; text: string } | null>(null);
|
||||
useLayoutEffect(() => {
|
||||
if (previous.current.identity !== identity && previous.current.text) setLeaving(previous.current);
|
||||
previous.current = { identity, text };
|
||||
}, [identity, text]);
|
||||
useLayoutEffect(() => {
|
||||
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches || document.documentElement.classList.contains('reduced');
|
||||
const easing = getComputedStyle(document.documentElement).getPropertyValue('--ease-out').trim();
|
||||
const animation = current.current?.animate([
|
||||
{ opacity: 0, transform: reduced ? 'none' : 'translateY(3px)' },
|
||||
{ opacity: 1, transform: 'none' },
|
||||
], { duration: reduced ? 120 : 200, easing });
|
||||
return () => animation?.cancel();
|
||||
}, [identity]);
|
||||
useLayoutEffect(() => {
|
||||
if (!leaving || !outgoing.current) return;
|
||||
const animation = outgoing.current.animate([{ opacity: 1 }, { opacity: 0 }], {
|
||||
duration: 160, easing: getComputedStyle(document.documentElement).getPropertyValue('--ease-out').trim(), fill: 'forwards',
|
||||
});
|
||||
void animation.finished.then(() => setLeaving(null)).catch(() => {});
|
||||
return () => animation.cancel();
|
||||
}, [leaving]);
|
||||
return <span className="soft-text"><span key={identity} ref={current} className="current-text">{text}</span>{leaving && <span ref={outgoing} className="outgoing-text" aria-hidden="true">{leaving.text}</span>}</span>;
|
||||
}
|
||||
@@ -2,23 +2,29 @@ import { useLayoutEffect, type ReactNode } from 'react';
|
||||
|
||||
export function Viewport({ children }: { children: ReactNode }) {
|
||||
useLayoutEffect(() => {
|
||||
const viewport = window.visualViewport, style = document.documentElement.style;
|
||||
const viewport = window.visualViewport, html = document.documentElement, style = html.style;
|
||||
let settle: ReturnType<typeof setTimeout>;
|
||||
const update = () => {
|
||||
// Keyboard/browser-bar geometry must follow the viewport immediately;
|
||||
// a decorative stage transition would cover the dialogue in between.
|
||||
document.documentElement.classList.add('viewport-resizing');
|
||||
html.classList.add('viewport-resizing');
|
||||
clearTimeout(settle);
|
||||
settle = setTimeout(() => document.documentElement.classList.remove('viewport-resizing'), 200);
|
||||
settle = setTimeout(() => html.classList.remove('viewport-resizing'), 200);
|
||||
const height = viewport?.height ?? innerHeight, top = viewport?.offsetTop ?? 0;
|
||||
style.setProperty('--view-h', `${height}px`);
|
||||
style.setProperty('--view-top', `${top}px`);
|
||||
style.setProperty('--view-bottom', `${Math.max(0, innerHeight - height - top)}px`);
|
||||
// Short visual viewport = keyboard open or a squat window. Her face yields first, the words never do.
|
||||
html.classList.toggle('compact', height < 610);
|
||||
html.classList.toggle('micro', height < 420);
|
||||
};
|
||||
update();
|
||||
// Hidden page: ambient loops and the reading clock pause; they resume where they were.
|
||||
const visibility = () => html.classList.toggle('paused', document.hidden);
|
||||
update(); visibility();
|
||||
viewport?.addEventListener('resize', update); viewport?.addEventListener('scroll', update);
|
||||
window.addEventListener('resize', update);
|
||||
return () => { clearTimeout(settle); viewport?.removeEventListener('resize', update); viewport?.removeEventListener('scroll', update); window.removeEventListener('resize', update); };
|
||||
document.addEventListener('visibilitychange', visibility);
|
||||
return () => { clearTimeout(settle); viewport?.removeEventListener('resize', update); viewport?.removeEventListener('scroll', update); window.removeEventListener('resize', update); document.removeEventListener('visibilitychange', visibility); };
|
||||
}, []);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Keyboard shortcuts are frequent, deliberate jumps: land on the target state at once. CSS transitions are
|
||||
// suspended for two frames and any finite animation already under way jumps to its end; ambient loops keep running.
|
||||
export function snap() {
|
||||
const html = document.documentElement;
|
||||
html.classList.add('snap');
|
||||
for (const a of document.getAnimations()) if (a.effect && a.effect.getTiming().iterations !== Infinity) a.finish();
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => html.classList.remove('snap')));
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useLayoutEffect, useRef } from 'react';
|
||||
import type { SpaceMode } from '../stage/roomScene';
|
||||
|
||||
// Which place in the shared room an app area belongs to. Panels (days/settings/creation) step the room back.
|
||||
export function spaceFor(area: string, record: boolean, creating: boolean): SpaceMode {
|
||||
if (creating) return 'pane';
|
||||
if (area === 'talk') return record ? 'record' : 'talk';
|
||||
return area === 'now' ? 'home' : 'pane';
|
||||
}
|
||||
|
||||
// Publishes the space on <html data-mode> for CSS and keyboard handlers, and keeps focus where a keyboard user
|
||||
// expects it: into a panel when it opens, back to whatever opened it when you return to the room.
|
||||
export function useSpace(area: string, space: SpaceMode) {
|
||||
const trigger = useRef<HTMLElement | null>(null), previous = useRef(area);
|
||||
useLayoutEffect(() => { document.documentElement.dataset.mode = space; }, [space]);
|
||||
useLayoutEffect(() => () => { delete document.documentElement.dataset.mode; }, []);
|
||||
useLayoutEffect(() => {
|
||||
const from = previous.current; previous.current = area;
|
||||
if (from === area) return;
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
if (from === 'now' && active && active !== document.body) trigger.current = active;
|
||||
if (area === 'days' || area === 'settings') {
|
||||
// Opened from the navigation: stay on the navigation so the next area is one key away.
|
||||
if (active?.closest('.nav')) return;
|
||||
requestAnimationFrame(() => document.querySelector<HTMLElement>('.pane.open > header button[aria-label^="关闭"]')?.focus({ preventScroll: true }));
|
||||
} else if (area === 'now') {
|
||||
const lost = !active || active === document.body || !active.isConnected || !!active.closest('.pane,.conversation,.record');
|
||||
if (!lost) return;
|
||||
const t = trigger.current, usable = t && t.isConnected && !t.closest('[hidden],[inert]') && !(t as HTMLButtonElement).disabled;
|
||||
requestAnimationFrame(() => (usable ? t : document.querySelector<HTMLElement>('.home .cta .btn-primary'))?.focus({ preventScroll: true }));
|
||||
}
|
||||
}, [area]);
|
||||
}
|
||||
Reference in New Issue
Block a user