HEL-824: land verified fixes on 4321aeb (small-screen first-press, real-time reading clock)
- 6 modified + handoff JSON per CHANGES-HEL-824.json, all hashes verified against git 4321aeb and package bytes
- rework_browser_check: skip full-text sheet at micro height (<420px design hides the control); migrate stale 返回日子 selector to 结束交谈 · 回到日子
- fresh run evidence: web build 25/25 unit tests, backend 142/142 (py3.12), all four browser checks PASS incl. new compact first-press and 700ms slow-frame sections (slow_frames_new_turn_to_reply_s=2.32s), layout regression 320/390/1024/1600 both themes
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
+11
-14
@@ -8,7 +8,7 @@ import { Icon, Modal } from '../shared/ui';
|
||||
import { snap } from '../shared/motion';
|
||||
import { motionOff } from '../stage/roomScene';
|
||||
import { LineStage, type PresentHow } from './lineStage';
|
||||
import { anchorOf, cursorAt, dwellFor, groupTurns, pagesOf, type Anchor, type Metrics, type ShownMessage } from './reading';
|
||||
import { anchorOf, cursorAt, groupTurns, pagesOf, ReadingClock, type Anchor, type Metrics, type ShownMessage } from './reading';
|
||||
|
||||
const START: Anchor = { mi: 0, offset: 0 };
|
||||
const metricsFor = (width: number): Metrics => { const compact = document.documentElement.classList.contains('compact'); return { width, font: compact ? 16 : innerWidth <= 720 ? 18 : 23, compact }; };
|
||||
@@ -62,7 +62,7 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
const cursor = cursorAt(pages, anchor), page = pages[cursor], atEnd = cursor >= pages.length - 1;
|
||||
const headIndex = cursorAt(pages, head.current);
|
||||
if (cursor > headIndex) head.current = anchor;
|
||||
const held = useRef(new Set<string>()), clock = useRef({ key: '', dwell: 0, total: 0 });
|
||||
const held = useRef(new Set<string>()), clock = useRef(new ReadingClock());
|
||||
const reading = useRef({ pages, cursor, flow }); reading.current = { pages, cursor, flow };
|
||||
|
||||
function stop() { gate.current.cancel(); if (replyLive.current) setInterrupted({ text: replyLive.current, turn: turnLive.current }); replyLive.current = ''; setBusy(false); setReply(''); onPresence('停下来了'); change(live.current.map(m => m.status === 'pending' ? { ...m, status: 'cancelled' } : m)); }
|
||||
@@ -108,20 +108,17 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
|
||||
// ── Reading clock. Holds (hover, selection, open sheets, hidden page) freeze it without changing your choice. ──
|
||||
useEffect(() => {
|
||||
let raf = 0, last = 0;
|
||||
let raf = 0;
|
||||
const c = clock.current, away = () => c.pause();
|
||||
const tick = (now: number) => {
|
||||
const dt = last ? Math.min(100, now - last) : 0; last = now;
|
||||
const { pages: list, cursor: at, flow: on } = reading.current, cur = list[at], c = clock.current;
|
||||
if (cur && cur.key !== c.key) { c.key = cur.key; c.dwell = 0; c.total = dwellFor(cur); }
|
||||
if (cur && on && !held.current.size && !document.hidden) {
|
||||
if (c.dwell < c.total) c.dwell += dt;
|
||||
if (c.dwell >= c.total && at < list.length - 1) { how.current = 'advance'; setAnchor(anchorOf(list, at + 1) || START); }
|
||||
}
|
||||
if (meter.current) meter.current.style.transform = `scaleX(${c.total ? Math.min(1, c.dwell / c.total) : 0})`;
|
||||
const { pages: list, cursor: at, flow: on } = reading.current;
|
||||
if (c.tick(now, list[at], on && !held.current.size && !document.hidden) && at < list.length - 1) { how.current = 'advance'; setAnchor(anchorOf(list, at + 1) || START); }
|
||||
if (meter.current) meter.current.style.transform = `scaleX(${c.progress})`;
|
||||
raf = requestAnimationFrame(tick);
|
||||
};
|
||||
raf = requestAnimationFrame(tick);
|
||||
return () => cancelAnimationFrame(raf);
|
||||
document.addEventListener('visibilitychange', away);
|
||||
return () => { cancelAnimationFrame(raf); document.removeEventListener('visibilitychange', away); };
|
||||
}, []);
|
||||
const [holding, setHolding] = useState(false);
|
||||
const hold = useCallback((why: string, on: boolean) => { if (on) held.current.add(why); else held.current.delete(why); setHolding(held.current.size > 0); }, []);
|
||||
@@ -132,8 +129,8 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
return () => document.removeEventListener('selectionchange', selection);
|
||||
}, [hold]);
|
||||
|
||||
const goTo = (index: number, mode: PresentHow) => { const to = Math.max(0, Math.min(index, pages.length - 1)); if (to === cursor) return; how.current = mode; clock.current.key = ''; setAnchor(anchorOf(pages, to) || START); };
|
||||
const setFlow = (on: boolean, quiet = false) => { setFlowState(on); clock.current.dwell = 0; if (!quiet) setFlash(on ? '继续自动呈现' : '已暂停 · 可以慢慢回看'); };
|
||||
const goTo = (index: number, mode: PresentHow) => { const to = Math.max(0, Math.min(index, pages.length - 1)); if (to === cursor) return; how.current = mode; clock.current.forget(); setAnchor(anchorOf(pages, to) || START); };
|
||||
const setFlow = (on: boolean, quiet = false) => { setFlowState(on); clock.current.restart(); if (!quiet) setFlash(on ? '继续自动呈现' : '已暂停 · 可以慢慢回看'); };
|
||||
const back = (instant = false) => { if (flow) setFlow(false, true); goTo(cursor - 1, instant ? 'instant' : 'jump'); };
|
||||
const forward = (instant = false) => goTo(cursor + 1, instant ? 'instant' : 'advance');
|
||||
const toLatest = () => { how.current = 'jump'; setAnchor(head.current); setFlow(true, true); };
|
||||
|
||||
@@ -62,6 +62,30 @@ export function dwellFor(page: Page) {
|
||||
return page.message.role === 'user' ? Math.min(3000, Math.max(1400, 900 + n * 60)) : Math.min(8000, Math.max(2400, 1500 + n * 150));
|
||||
}
|
||||
|
||||
// How long the current line has stayed. It counts real time, not frames: busy frames (a new turn's crossfade,
|
||||
// ink, the room) never stretch a stay. One frame counts at most STALL, so a stall (sleep, debugger) is not
|
||||
// reading; a hidden page restarts the count from its return.
|
||||
export const STALL = 1000;
|
||||
export class ReadingClock {
|
||||
key = ''; dwell = 0; total = 0;
|
||||
private last = 0;
|
||||
// True once the line on screen has stayed its time while reading runs. Same key = same line: a growing stream
|
||||
// or a re-render never restarts it.
|
||||
tick(now: number, page: Page | undefined, running: boolean): boolean {
|
||||
const dt = this.last ? Math.min(STALL, Math.max(0, now - this.last)) : 0; this.last = now;
|
||||
if (!page) return false;
|
||||
if (page.key !== this.key) { this.key = page.key; this.dwell = 0; this.total = dwellFor(page); }
|
||||
if (running && this.dwell < this.total) this.dwell = Math.min(this.total, this.dwell + dt);
|
||||
return running && this.dwell >= this.total;
|
||||
}
|
||||
get progress() { return this.total ? this.dwell / this.total : 0; }
|
||||
// You moved or resumed: the line you land on gets its full time.
|
||||
restart() { this.dwell = 0; }
|
||||
forget() { this.key = ''; }
|
||||
// Page hidden: the gap until it is seen again is not reading time.
|
||||
pause() { this.last = 0; }
|
||||
}
|
||||
|
||||
// Reading position as a character offset inside one message, so a re-chunk (resize, keyboard) keeps your place.
|
||||
export interface Anchor { mi: number; offset: number }
|
||||
export function anchorOf(pages: Page[], cursor: number): Anchor | null {
|
||||
|
||||
@@ -3,13 +3,8 @@ import { useLayoutEffect, type ReactNode } from 'react';
|
||||
export function Viewport({ children }: { children: ReactNode }) {
|
||||
useLayoutEffect(() => {
|
||||
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.
|
||||
html.classList.add('viewport-resizing');
|
||||
clearTimeout(settle);
|
||||
settle = setTimeout(() => html.classList.remove('viewport-resizing'), 200);
|
||||
// Keyboard/browser-bar geometry follows the viewport at once; the dialogue has no position transition.
|
||||
const height = viewport?.height ?? innerHeight, top = viewport?.offsetTop ?? 0;
|
||||
style.setProperty('--view-h', `${height}px`);
|
||||
style.setProperty('--view-top', `${top}px`);
|
||||
@@ -24,7 +19,7 @@ export function Viewport({ children }: { children: ReactNode }) {
|
||||
viewport?.addEventListener('resize', update); viewport?.addEventListener('scroll', update);
|
||||
window.addEventListener('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 () => { viewport?.removeEventListener('resize', update); viewport?.removeEventListener('scroll', update); window.removeEventListener('resize', update); document.removeEventListener('visibilitychange', visibility); };
|
||||
}, []);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -788,7 +788,8 @@ html.compact .line p{font-size:16px;line-height:1.55}
|
||||
html.compact .reader-bar{margin:0 0 4px}
|
||||
html.compact .nav-item{height:36px}
|
||||
html.compact .record{top:calc(var(--view-top) + 48px);height:calc(var(--view-h) - 104px - var(--safe-bottom))}
|
||||
html.compact.typing{--nav-space:6px}
|
||||
/* Typing only lets the navigation step aside; the dialogue keeps its place, so a press that blurs the input
|
||||
(send, full text, pause, review) is released on the same button it started on. */
|
||||
html.compact.typing[data-mode="talk"] .nav{transform:translate(-50%,150%);opacity:0;pointer-events:none}
|
||||
html.compact .home .eyebrow,html.compact .home .meta,html.compact .home .away,html.compact .home .letter p,html.compact .home .first-note,html.compact .home .demo-label{display:none}
|
||||
html.compact .home .whisper{font-size:18px}
|
||||
|
||||
Reference in New Issue
Block a user