@tbox.cn/app-agent-ui-kit 1.0.0-alpha.1 → 1.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +56 -3
  2. package/package.json +22 -7
  3. package/src/ChatPage.tsx +115 -20
  4. package/src/card/action-list-pending.test.tsx +91 -0
  5. package/src/card/define-card.test.ts +25 -0
  6. package/src/card/define-card.ts +47 -0
  7. package/src/card/primitives.test.tsx +157 -0
  8. package/src/card/primitives.tsx +717 -0
  9. package/src/card/use-card-actions.ts +86 -0
  10. package/src/card/view-card-inline.test.tsx +42 -0
  11. package/src/card/view-card.test.tsx +79 -0
  12. package/src/card/view-card.tsx +250 -0
  13. package/src/chat-config.test.ts +35 -71
  14. package/src/chat-config.ts +29 -7
  15. package/src/components/ActionBar/DebugButton.test.tsx +3 -0
  16. package/src/components/ActionBar/DebugButton.tsx +5 -10
  17. package/src/components/ActionBar/index.tsx +13 -14
  18. package/src/components/BottomSheet/index.test.tsx +97 -0
  19. package/src/components/BottomSheet/index.tsx +49 -0
  20. package/src/components/ChatHeader/index.tsx +19 -17
  21. package/src/components/ChatInput/index.test.tsx +2 -2
  22. package/src/components/ChatInput/index.tsx +44 -33
  23. package/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
  24. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
  25. package/src/components/ChatInput/voice/useVoicePress.ts +1 -1
  26. package/src/components/HistoryEntry/index.tsx +4 -4
  27. package/src/components/MediaList/index.tsx +42 -28
  28. package/src/components/MessageBubble/index.tsx +59 -28
  29. package/src/components/PullDownIndicator/index.tsx +3 -4
  30. package/src/components/QuickCommands/index.test.tsx +3 -1
  31. package/src/components/QuickCommands/index.tsx +33 -10
  32. package/src/components/ReasoningBlock/index.tsx +14 -9
  33. package/src/components/ScrollToBottomButton/index.tsx +7 -5
  34. package/src/components/ToolCallBlock/index.tsx +58 -38
  35. package/src/icons.ts +39 -0
  36. package/src/index.ts +75 -1
  37. package/src/overlay/Overlay.tsx +154 -0
  38. package/src/overlay/focus.ts +53 -0
  39. package/src/overlay/index.ts +16 -0
  40. package/src/overlay/inert.ts +27 -0
  41. package/src/overlay/layers.ts +21 -0
  42. package/src/overlay/overlay.ssr.test.tsx +27 -0
  43. package/src/overlay/overlay.test.tsx +209 -0
  44. package/src/overlay/presence.ts +86 -0
  45. package/src/overlay/scroll-lock.ts +62 -0
  46. package/src/overlay/stack.ts +111 -0
  47. package/src/overlay/use-overlay.ts +80 -0
  48. package/src/preview-provider.tsx +47 -0
  49. package/src/shell.contract.json +75 -0
  50. package/src/shell.test.ts +72 -0
  51. package/src/shell.ts +60 -0
  52. package/src/surface.test.tsx +35 -0
  53. package/src/surface.tsx +44 -0
  54. package/src/theme/base.css +167 -0
  55. package/src/theme/contract.json +123 -2
  56. package/src/theme/theme-contract.test.ts +19 -3
  57. package/src/theme/{tokens.less → tokens.css} +19 -20
  58. package/src/utils/image-preview-host.tsx +95 -0
  59. package/src/utils/imagePreview.test.ts +32 -0
  60. package/src/utils/imagePreview.ts +14 -5
  61. package/src/utils/toast.test.ts +64 -0
  62. package/src/utils/toast.ts +100 -7
  63. package/src/ChatPage.less +0 -62
  64. package/src/components/ActionBar/index.less +0 -123
  65. package/src/components/ChatHeader/index.less +0 -148
  66. package/src/components/ChatInput/index.less +0 -394
  67. package/src/components/HistoryEntry/index.less +0 -49
  68. package/src/components/MediaList/index.less +0 -241
  69. package/src/components/MessageBubble/index.less +0 -325
  70. package/src/components/PullDownIndicator/index.less +0 -32
  71. package/src/components/QuickCommands/index.less +0 -63
  72. package/src/components/ReasoningBlock/index.less +0 -90
  73. package/src/components/ScrollToBottomButton/index.less +0 -32
  74. package/src/components/ToolCallBlock/index.less +0 -312
  75. package/src/theme/global.less +0 -99
  76. /package/src/theme/{motion.less → motion.css} +0 -0
@@ -11,13 +11,8 @@ import { Bug } from '@phosphor-icons/react';
11
11
  */
12
12
  function shouldShow(): boolean {
13
13
  if (typeof window === 'undefined') return false;
14
- if (import.meta.env.DEV) return true;
15
- if (new URLSearchParams(window.location.search).get('debug') === '1') return true;
16
- try {
17
- return window.self !== window.top;
18
- } catch {
19
- return true;
20
- }
14
+ // 只在显式调试请求下显示:dev 构建与 iframe 预览都不再触发(B5)。
15
+ return new URLSearchParams(window.location.search).get('debug') === '1';
21
16
  }
22
17
 
23
18
  export function DebugButton({
@@ -45,9 +40,9 @@ export function DebugButton({
45
40
  };
46
41
 
47
42
  return (
48
- <div className="tbox-debug-btn" onClick={onClick}>
49
- <Bug className="tbox-debug-btn__icon" size={22} />
50
- <span className="tbox-debug-btn__text">调试</span>
43
+ <div className="tbox-debug-btn inline-flex h-[26px] items-center justify-center gap-1 rounded-full bg-white px-[11px] text-secondary-foreground transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] active:scale-[0.97] active:bg-muted" onClick={onClick}>
44
+ <Bug className="tbox-debug-btn__icon size-[14px] shrink-0" size={22} />
45
+ <span className="tbox-debug-btn__text text-xs leading-none">调试</span>
51
46
  </div>
52
47
  );
53
48
  }
@@ -10,7 +10,6 @@ import type { ChatMessage } from '../../types';
10
10
  import { copyText } from '../../utils/copyText';
11
11
  import { toast } from '../../utils/toast';
12
12
  import { DebugButton } from './DebugButton';
13
- import './index.less';
14
13
 
15
14
  /**
16
15
  * 跨所有 ActionBar 实例共享的"正在朗读的消息 id"(对齐原模板 useTTS 的 _playingId)。
@@ -45,8 +44,8 @@ export function CopyButton({ text }: { text: string }) {
45
44
  };
46
45
 
47
46
  return (
48
- <button type="button" className="tbox-action-btn" onClick={copy} aria-label="复制">
49
- <span className="tbox-action-btn__icon-wrap">
47
+ <button type="button" className="tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-white p-0 text-muted-foreground transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted" onClick={copy} aria-label="复制">
48
+ <span className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
50
49
  <Copy size={22} />
51
50
  </span>
52
51
  </button>
@@ -108,17 +107,17 @@ export function ActionBar({ message }: { message: ChatMessage }) {
108
107
  const canFeedback = !!message.requestId;
109
108
 
110
109
  return (
111
- <div className="tbox-action-bar">
110
+ <div className="tbox-action-bar flex items-center gap-2">
112
111
  {enableTTS && tts && (
113
- <div className={`tbox-action-btn${wave ? ' tbox-tts-btn--playing' : ''}`} onClick={onTts}>
112
+ <div className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${wave ? ' tbox-tts-btn--playing bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`} onClick={onTts}>
114
113
  {wave ? (
115
- <div className="tbox-tts-wave">
116
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--1" />
117
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--2" />
118
- <div className="tbox-tts-wave__bar tbox-tts-wave__bar--3" />
114
+ <div className="tbox-tts-wave flex size-[14px] items-center justify-center gap-[1.5px]">
115
+ <div className="tbox-tts-wave__bar tbox-tts-wave__bar--1 h-[7px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0s]" />
116
+ <div className="tbox-tts-wave__bar tbox-tts-wave__bar--2 h-[9px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.15s]" />
117
+ <div className="tbox-tts-wave__bar tbox-tts-wave__bar--3 h-[6px] w-[1.5px] origin-bottom rounded-full bg-primary animate-[tbox-tts-wave_0.8s_ease-in-out_infinite] [animation-delay:0.3s]" />
119
118
  </div>
120
119
  ) : (
121
- <div className="tbox-action-btn__icon-wrap">
120
+ <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
122
121
  <SpeakerHigh size={22} />
123
122
  </div>
124
123
  )}
@@ -130,18 +129,18 @@ export function ActionBar({ message }: { message: ChatMessage }) {
130
129
  {canFeedback && (
131
130
  <>
132
131
  <div
133
- className={`tbox-action-btn${message.feedbackState === 'like' ? ' tbox-action-btn--active' : ''}`}
132
+ className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${message.feedbackState === 'like' ? ' tbox-action-btn--active bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`}
134
133
  onClick={() => onFeedback('like')}
135
134
  >
136
- <div className="tbox-action-btn__icon-wrap">
135
+ <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
137
136
  <ThumbsUp size={22} />
138
137
  </div>
139
138
  </div>
140
139
  <div
141
- className={`tbox-action-btn${message.feedbackState === 'dislike' ? ' tbox-action-btn--active' : ''}`}
140
+ className={`tbox-action-btn flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 transition-[background-color,transform] duration-[var(--tbox-motion-duration-fast)] ease-[ease] [font-family:inherit] active:scale-[0.97] active:bg-muted ${message.feedbackState === 'dislike' ? ' tbox-action-btn--active bg-primary-foreground text-primary' : ' bg-white text-muted-foreground'}`}
142
141
  onClick={() => onFeedback('dislike')}
143
142
  >
144
- <div className="tbox-action-btn__icon-wrap">
143
+ <div className="tbox-action-btn__icon-wrap flex size-[14px] shrink-0 items-center justify-center">
145
144
  <ThumbsDown size={22} />
146
145
  </div>
147
146
  </div>
@@ -0,0 +1,97 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, describe, expect, it, vi } from 'vitest';
3
+ import { act } from 'react';
4
+ import { createRoot } from 'react-dom/client';
5
+ import type { Root } from 'react-dom/client';
6
+ import { BottomSheet, preloadBottomSheet } from './index';
7
+
8
+ let root: Root | undefined;
9
+ afterEach(async () => {
10
+ await act(async () => root?.unmount());
11
+ root = undefined;
12
+ document.body.innerHTML = '';
13
+ document.body.style.overflow = '';
14
+ });
15
+
16
+ async function renderSheet(open: boolean, onClose = vi.fn()) {
17
+ if (!root) {
18
+ const container = document.createElement('div');
19
+ document.body.append(container);
20
+ root = createRoot(container);
21
+ }
22
+ await act(async () => {
23
+ root!.render(<BottomSheet open={open} title="奖品详情" onClose={onClose}>
24
+ <button type="button">内容操作</button>
25
+ </BottomSheet>);
26
+ });
27
+ return onClose;
28
+ }
29
+
30
+ describe('BottomSheet', () => {
31
+ it('关闭态不挂载内容;打开通过 portal 展示命名对话框和业务内容', async () => {
32
+ await renderSheet(false);
33
+ expect(document.querySelector('[role="dialog"]')).toBeNull();
34
+ await renderSheet(true);
35
+ const dialog = document.querySelector('[role="dialog"]') as HTMLElement;
36
+ expect(dialog).not.toBeNull();
37
+ expect(dialog.getAttribute('aria-modal')).toBe('true');
38
+ // portal 到 body 直接子节点(不在 React 容器里)
39
+ expect(document.body.contains(dialog)).toBe(true);
40
+ expect(document.getElementById(dialog.getAttribute('aria-labelledby')!)?.textContent).toBe('奖品详情');
41
+ expect(dialog.textContent).toContain('内容操作');
42
+ });
43
+
44
+ it('关闭按钮与 Escape 请求受控关闭,卸载后恢复触发按钮焦点并清理监听', async () => {
45
+ const trigger = document.createElement('button');
46
+ document.body.append(trigger);
47
+ trigger.focus();
48
+ const onClose = await renderSheet(true);
49
+ await act(async () => {
50
+ (document.querySelector('[aria-label="关闭奖品详情"]') as HTMLButtonElement).click();
51
+ });
52
+ expect(onClose).toHaveBeenCalledTimes(1);
53
+ await act(async () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' })));
54
+ expect(onClose).toHaveBeenCalledTimes(2);
55
+ await act(async () => root?.unmount());
56
+ root = undefined;
57
+ expect(document.activeElement).toBe(trigger);
58
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
59
+ expect(onClose).toHaveBeenCalledTimes(2);
60
+ });
61
+
62
+ it('Tab 与 Shift+Tab 在弹层内循环,不落到背景页面', async () => {
63
+ await renderSheet(true);
64
+ const close = document.querySelector('[aria-label="关闭奖品详情"]') as HTMLButtonElement;
65
+ const last = document.querySelector('.tbox-bottom-sheet__body button') as HTMLButtonElement;
66
+ last.focus();
67
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', cancelable: true }));
68
+ expect(document.activeElement).toBe(close);
69
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', shiftKey: true, cancelable: true }));
70
+ expect(document.activeElement).toBe(last);
71
+ });
72
+
73
+ it('遮罩点击请求关闭,内容点击不关闭;打开时锁背景滚动', async () => {
74
+ const onClose = await renderSheet(true);
75
+ expect(document.body.style.overflow).toBe('hidden');
76
+ await act(async () => (document.querySelector('.tbox-bottom-sheet__body button') as HTMLButtonElement).click());
77
+ expect(onClose).not.toHaveBeenCalled();
78
+ await act(async () => (document.querySelector('[data-tbox-overlay-mask]') as HTMLElement).click());
79
+ expect(onClose).toHaveBeenCalledTimes(1);
80
+ });
81
+
82
+ it('关闭后播完退出动画再卸载,且退出期间不再是对话框', async () => {
83
+ await renderSheet(true);
84
+ await renderSheet(false);
85
+ const rootEl = document.querySelector('[data-tbox-overlay]') as HTMLElement;
86
+ expect(rootEl.getAttribute('data-state')).toBe('closed');
87
+ expect(document.querySelector('[role="dialog"]')).toBeNull();
88
+ await act(async () => {
89
+ rootEl.dispatchEvent(new Event('animationend', { bubbles: true }));
90
+ });
91
+ expect(document.querySelector('[data-tbox-overlay]')).toBeNull();
92
+ });
93
+
94
+ it('预热入口保留为空操作(旧模块的 typeof 守卫仍需可用)', async () => {
95
+ await expect(preloadBottomSheet()).resolves.toBeUndefined();
96
+ });
97
+ });
@@ -0,0 +1,49 @@
1
+ import { useId, useRef } from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import { Overlay } from '../../overlay';
4
+
5
+ export interface BottomSheetProps {
6
+ open: boolean;
7
+ title: string;
8
+ onClose: () => void;
9
+ children: ReactNode;
10
+ /** 内容容器的业务样式;弹层外壳由组件统一管理。 */
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * 兼容旧宿主的预热入口:弹层已无第三方运行时,恒立即完成。
16
+ * 保留导出是为了让已发布的旧模块(`typeof preloadBottomSheet === 'function'` 守卫)不报错。
17
+ * @deprecated 弹层不再懒加载,无需预热。
18
+ */
19
+ export async function preloadBottomSheet(): Promise<void> {}
20
+
21
+ /** 受控底部弹层:业务只提供内容与开关,不自行处理遮罩、滚动和焦点。 */
22
+ export function BottomSheet({ open, title, onClose, children, className }: BottomSheetProps) {
23
+ const titleId = useId();
24
+ const closeRef = useRef<HTMLButtonElement>(null);
25
+
26
+ return (
27
+ <Overlay
28
+ open={open}
29
+ onDismiss={onClose}
30
+ placement="bottom"
31
+ labelledBy={titleId}
32
+ initialFocus={closeRef}
33
+ exitMs={200}
34
+ rootClassName="tbox-bottom-sheet-root group"
35
+ panelClassName="tbox-bottom-sheet tbox-bottom-sheet__panel flex max-h-[65vh] w-full max-w-content flex-col overflow-hidden rounded-t-[14px] bg-card text-foreground supports-[height:100dvh]:max-h-[65dvh] animate-[tbox-sheet-in_200ms_ease-out] group-data-[state=closed]:animate-[tbox-sheet-out_200ms_ease-in_both] motion-reduce:animate-none"
36
+ maskClassName="bg-scrim animate-[tbox-fade-in_200ms_ease-out] group-data-[state=closed]:animate-[tbox-fade-out_200ms_ease-in_both] motion-reduce:animate-none"
37
+ >
38
+ <header className="tbox-bottom-sheet__header flex shrink-0 items-center justify-between gap-3 px-3.5 py-3">
39
+ <h2 id={titleId} className="m-0 text-base font-semibold leading-[21px]">{title}</h2>
40
+ <button className="flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-1.5 text-inherit focus-visible:outline-2 focus-visible:outline-primary" ref={closeRef} type="button" aria-label={`关闭${title}`} onClick={onClose}>
41
+ <svg className="size-4.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
42
+ <path d="m6 6 12 12M6 18 18 6" />
43
+ </svg>
44
+ </button>
45
+ </header>
46
+ <div className={['tbox-bottom-sheet__body min-h-0 overflow-y-auto overscroll-contain px-3.5 pt-0 pb-[calc(16px+env(safe-area-inset-bottom))] text-sm leading-[19px]', className].filter(Boolean).join(' ')}>{children}</div>
47
+ </Overlay>
48
+ );
49
+ }
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { CaretDown, SpeakerHigh, SpeakerSlash, Trash } from '@phosphor-icons/react';
3
3
  import { useChatConfigStore } from '../../chat-config';
4
4
  import { useChatStore } from '../../store-context';
5
- import './index.less';
6
5
 
7
6
  interface ChatHeaderProps {
8
7
  ttsAutoPlay: boolean;
@@ -14,8 +13,10 @@ export default function ChatHeader({ ttsAutoPlay, onToggleTTS, onClearChat }: Ch
14
13
  const [isExpanded, setIsExpanded] = useState(false);
15
14
  const headerRef = useRef<HTMLDivElement>(null);
16
15
  const enableTTS = useChatConfigStore((s) => s.enableTTS);
17
- // 014 T7:mall 品牌名 = 服务端 HELLO_ACK.mallScope.mallName(模板 buildScope 回显);非 mall 部署无 mallScope → 不渲染品牌区
16
+ // 品牌名三级来源:chat.json identity.name → HELLO_ACK 的 mallName(商圈部署回显)→ 不渲染
17
+ const identity = useChatConfigStore((s) => s.identity);
18
18
  const mallName = useChatStore((s) => s.helloAck?.mallScope?.mallName);
19
+ const brandName = identity?.name ?? mallName;
19
20
 
20
21
  const handleClear = useCallback(() => {
21
22
  onClearChat();
@@ -36,37 +37,38 @@ export default function ChatHeader({ ttsAutoPlay, onToggleTTS, onClearChat }: Ch
36
37
  }, [isExpanded]);
37
38
 
38
39
  return (
39
- <div className="chat-header" ref={headerRef}>
40
- {mallName ? (
41
- <div className="chat-header__brand" aria-label={mallName}>
42
- <span className="chat-header__brand-mark" aria-hidden="true" />
43
- <span className="chat-header__brand-name">{mallName}</span>
40
+ <div className="chat-header pointer-events-none absolute left-1/2 top-[calc(5px+env(safe-area-inset-top,0px))] z-[100] flex w-full max-w-content -translate-x-1/2 flex-col items-end px-4" ref={headerRef}>
41
+ {brandName ? (
42
+ <div className="chat-header__brand absolute left-4 top-[2px] inline-flex min-h-[22px] items-center text-foreground" aria-label={brandName}>
43
+ <span className="chat-header__brand-mark mr-[7px] h-[17px] w-[3.5px] rounded-[1px] bg-primary" aria-hidden="true" />
44
+ <span className="chat-header__brand-name text-xs font-[760] leading-none tracking-normal">{brandName}</span>
45
+ {identity?.tagline ? <span className="chat-header__brand-tagline ml-[6px] overflow-hidden text-ellipsis whitespace-nowrap text-xs leading-none text-muted-foreground">{identity.tagline}</span> : null}
44
46
  </div>
45
47
  ) : null}
46
- <div className={`chat-header__group${!isExpanded ? ' chat-header__group--collapsed' : ''}`}>
47
- <button type="button" className="chat-header__btn" onClick={handleClear}>
48
- <Trash size={22} className="chat-header__btn-icon" />
49
- <span className="chat-header__btn-text">清空</span>
48
+ <div className={`chat-header__group flex items-center gap-[2px] overflow-hidden rounded-[6px] border-[0.5px] border-border bg-[rgba(255,255,255,0.96)] shadow-sm transition-[opacity,transform] motion-reduce:transition-none ${!isExpanded ? ' chat-header__group--collapsed pointer-events-none mb-0 max-h-0 px-[3px] py-0 opacity-0 [transform:translateY(-4px)]' : ' pointer-events-auto mb-[3px] max-h-10 px-[3px] py-[3px] opacity-100 [transform:translateY(0)]'}`}>
49
+ <button type="button" className="chat-header__btn inline-flex min-h-[26px] appearance-none items-center justify-center gap-[3.5px] rounded-[4px] border-0 bg-transparent px-[7.5px] py-0 text-secondary-foreground [font-family:inherit] active:bg-muted focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1px] focus-visible:outline-[rgba(9,107,250,0.24)]" onClick={handleClear}>
50
+ <Trash size={22} className="chat-header__btn-icon size-[11px] shrink-0 text-primary" />
51
+ <span className="chat-header__btn-text text-inherit text-xs font-[560] leading-none whitespace-nowrap">清空</span>
50
52
  </button>
51
53
  {enableTTS && (
52
- <button type="button" className="chat-header__btn" onClick={onToggleTTS}>
54
+ <button type="button" className="chat-header__btn inline-flex min-h-[26px] appearance-none items-center justify-center gap-[3.5px] rounded-[4px] border-0 bg-transparent px-[7.5px] py-0 text-secondary-foreground [font-family:inherit] active:bg-muted focus-visible:outline-[1.5px] focus-visible:outline-offset-[-1px] focus-visible:outline-[rgba(9,107,250,0.24)]" onClick={onToggleTTS}>
53
55
  {ttsAutoPlay ? (
54
- <SpeakerHigh size={22} className="chat-header__btn-icon" />
56
+ <SpeakerHigh size={22} className="chat-header__btn-icon size-[11px] shrink-0 text-primary" />
55
57
  ) : (
56
- <SpeakerSlash size={22} className="chat-header__btn-icon" />
58
+ <SpeakerSlash size={22} className="chat-header__btn-icon size-[11px] shrink-0 text-primary" />
57
59
  )}
58
- <span className="chat-header__btn-text">{ttsAutoPlay ? '关闭' : '播放'}</span>
60
+ <span className="chat-header__btn-text text-inherit text-xs font-[560] leading-none whitespace-nowrap">{ttsAutoPlay ? '关闭' : '播放'}</span>
59
61
  </button>
60
62
  )}
61
63
  </div>
62
64
  <button
63
- className="chat-header__toggle"
65
+ className="chat-header__toggle pointer-events-auto flex h-[22px] w-7 appearance-none items-center justify-center rounded-[4px] border-[0.5px] border-border bg-[rgba(255,255,255,0.92)] text-muted-foreground shadow-sm [font-family:inherit] active:bg-muted focus-visible:outline-[1.5px] focus-visible:outline-offset-[1px] focus-visible:outline-[rgba(9,107,250,0.24)]"
64
66
  type="button"
65
67
  aria-label={isExpanded ? '收起对话工具' : '展开对话工具'}
66
68
  aria-expanded={isExpanded}
67
69
  onClick={() => setIsExpanded((p) => !p)}
68
70
  >
69
- <span className={`chat-header__arrow${isExpanded ? ' chat-header__arrow--up' : ''}`}>
71
+ <span className={`chat-header__arrow flex items-center justify-center transition-transform duration-[var(--tbox-motion-duration-base)] ease-[var(--tbox-motion-easing-standard)] motion-reduce:transition-none ${isExpanded ? ' chat-header__arrow--up rotate-180' : ''}`}>
70
72
  <CaretDown size={14} />
71
73
  </span>
72
74
  </button>
@@ -83,9 +83,9 @@ describe('ChatInput 语音活动状态', () => {
83
83
  });
84
84
 
85
85
  describe('ChatInput 派生模式(服务端 defaultInputMode 水合)', () => {
86
- /** voice 态投影:录音模式显示"键盘"切换图标;text 态显示"语音"切换图标 */
86
+ /** voice 态投影:录音模式的可访问名为「切换到键盘输入」;text 态为「切换到语音输入」 */
87
87
  const inVoiceMode = (container: HTMLElement) =>
88
- container.querySelector('img[alt="键盘"]') !== null;
88
+ container.querySelector('.tbox-voice-toggle[aria-label="切换到键盘输入"]') !== null;
89
89
 
90
90
  const renderInput = async (root: ReturnType<typeof createRoot>) => {
91
91
  await act(async () => root.render(<ChatInput onSend={vi.fn()} />));
@@ -14,7 +14,6 @@ import keyboardIcon from '../../../assets/keyboard-circle.svg';
14
14
  import sendIcon from '../../../assets/send-gradient.svg';
15
15
  import stopIcon from '../../../assets/stop@2x.png';
16
16
  import moreIcon from '../../../assets/more-circle.svg';
17
- import './index.less';
18
17
 
19
18
  type PickKind = 'image' | 'camera' | 'video';
20
19
 
@@ -27,6 +26,13 @@ const OPTION_ICONS: Record<PickKind, { icon: string; label: string }> = {
27
26
 
28
27
  const MENU_ANIMATION_MS = 250;
29
28
 
29
+ /** 菜单展开时选项的错峰入场延迟(旧 less 的 `:nth-child(n)` transition-delay)。 */
30
+ const MENU_OPTION_DELAY_CLASS: Record<number, string> = {
31
+ 0: '[.tbox-media-picker-menu--visible_&]:[transition-delay:0.05s]',
32
+ 1: '[.tbox-media-picker-menu--visible_&]:[transition-delay:0.1s]',
33
+ 2: '[.tbox-media-picker-menu--visible_&]:[transition-delay:0.15s]',
34
+ };
35
+
30
36
  /** 连接终态阻断(登录失败/scope 拒绝):提示条 + 输入禁用 + 可选重试入口 */
31
37
  export interface ChatBlocked {
32
38
  message: string;
@@ -169,7 +175,7 @@ export function ChatInput({
169
175
  };
170
176
 
171
177
  return (
172
- <div className="tbox-chat-input">
178
+ <div className="tbox-chat-input relative z-[1] mx-auto w-full max-w-content bg-transparent px-page pt-2 pb-[calc(8px+env(safe-area-inset-bottom,0px))]">
173
179
  <MediaList
174
180
  items={items}
175
181
  onRemove={removeItem}
@@ -182,14 +188,14 @@ export function ChatInput({
182
188
  isWebPc={isWebPc}
183
189
  />
184
190
 
185
- <div className="tbox-chat-input__row">
191
+ <div className="tbox-chat-input__row flex flex-wrap items-end gap-2">
186
192
  {onNewChat && (
187
- <div className="tbox-new-chat-btn" onClick={onNewChat}>
188
- <img className="tbox-new-chat-btn__icon" src={newChatIcon} alt="新对话" />
189
- </div>
193
+ <button type="button" data-tbox-control="new-chat" aria-label="新建对话" className="tbox-new-chat-btn flex size-11 shrink-0 cursor-pointer appearance-none items-center justify-center rounded-full border-0 bg-[rgba(255,255,255,0.5)] p-0 shadow-[0_1px_10px_rgba(110,139,180,0.24)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={onNewChat}>
194
+ <img className="tbox-new-chat-btn__icon size-[22px]" src={newChatIcon} alt="" />
195
+ </button>
190
196
  )}
191
197
 
192
- <div className="tbox-chat-input__wrapper">
198
+ <div className="tbox-chat-input__wrapper flex min-w-0 flex-1 items-end gap-[14px] rounded-[var(--tbox-input-radius)] border border-border bg-[var(--tbox-input-bg)] p-[var(--tbox-input-padding)] shadow-[0_1px_10px_rgba(110,139,180,0.24)] transition-[border-color,box-shadow] duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] focus-within:border-primary focus-within:shadow-[0_0_0_1.5px_rgba(9,107,250,0.12)]">
193
199
  <input ref={imageRef} type="file" accept="image/*" multiple hidden onChange={onPickFiles} />
194
200
  <input ref={cameraRef} type="file" accept="image/*" capture="environment" hidden onChange={onPickFiles} />
195
201
  <input ref={videoRef} type="file" accept="video/*" hidden onChange={onPickFiles} />
@@ -202,7 +208,7 @@ export function ChatInput({
202
208
  />
203
209
  ) : (
204
210
  <textarea
205
- className="tbox-chat-input__field"
211
+ className="tbox-chat-input__field min-h-11 min-w-0 flex-1 resize-none border-0 bg-transparent p-0 text-base leading-[24px] text-foreground outline-none max-h-[100px] [font-family:inherit] placeholder:text-muted-foreground disabled:opacity-[0.45]"
206
212
  value={text}
207
213
  placeholder={blocked?.message ?? '有什么需要问我的吗'}
208
214
  rows={1}
@@ -218,39 +224,44 @@ export function ChatInput({
218
224
  )}
219
225
 
220
226
  {enableVoice && (
221
- <div className="tbox-voice-toggle" onClick={toggleMode}>
227
+ <button type="button" data-tbox-control="voice-toggle" aria-label={inputMode === 'voice' ? '切换到键盘输入' : '切换到语音输入'} aria-pressed={inputMode === 'voice'} className="tbox-voice-toggle flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={toggleMode}>
222
228
  <img
223
- className="tbox-voice-toggle__icon"
229
+ className="tbox-voice-toggle__icon size-[22px]"
224
230
  src={inputMode === 'voice' ? keyboardIcon : voiceIcon}
225
- alt={inputMode === 'voice' ? '键盘' : '语音'}
231
+ alt=""
226
232
  />
227
- </div>
233
+ </button>
228
234
  )}
229
235
 
230
236
  {blocked ? null : generating ? (
231
- <div className="tbox-chat-input__send tbox-chat-input__send--active" onClick={onCancel}>
232
- <img className="tbox-chat-input__send-img" src={stopIcon} alt="停止" />
233
- </div>
237
+ <button type="button" data-tbox-control="stop" aria-label="停止生成" className="tbox-chat-input__send tbox-chat-input__send--active flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={onCancel}>
238
+ <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={stopIcon} alt="" />
239
+ </button>
234
240
  ) : canSend ? (
235
- <div className="tbox-chat-input__send tbox-chat-input__send--active" onClick={submit}>
236
- <img className="tbox-chat-input__send-img" src={sendIcon} alt="发送" />
237
- </div>
241
+ <button type="button" data-tbox-control="send" aria-label="发送" className="tbox-chat-input__send tbox-chat-input__send--active flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" onClick={submit}>
242
+ <img className="tbox-chat-input__send-img block size-[var(--tbox-send-btn-size)]" src={sendIcon} alt="" />
243
+ </button>
238
244
  ) : menuOptions.length > 0 ? (
239
- <div className="tbox-media-picker">
240
- <div
241
- className={`tbox-media-picker__trigger${menuVisible ? ' tbox-media-picker__trigger--open' : ''}`}
245
+ <div className="tbox-media-picker relative shrink-0">
246
+ <button
247
+ type="button"
248
+ data-tbox-control="media-add"
249
+ aria-label="添加图片或视频"
250
+ aria-haspopup="menu"
251
+ aria-expanded={menuVisible}
252
+ className={`tbox-media-picker__trigger flex size-11 -m-[11px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0 transition-transform duration-[var(--tbox-motion-duration-base)] ease-[ease] ${menuVisible ? ' tbox-media-picker__trigger--open rotate-45' : ''}`}
242
253
  onClick={onPlus}
243
254
  >
244
- <img className="tbox-media-picker__trigger-icon" src={moreIcon} alt="更多" />
245
- </div>
255
+ <img className="tbox-media-picker__trigger-icon size-[var(--tbox-send-btn-size)]" src={moreIcon} alt="" />
256
+ </button>
246
257
  </div>
247
258
  ) : null}
248
259
  </div>
249
260
  {blocked && (
250
- <div className="tbox-chat-input__blocked">
251
- <span className="tbox-chat-input__blocked-msg">{blocked.message}</span>
261
+ <div className="tbox-chat-input__blocked flex basis-full items-center gap-[6px] rounded-[6px] bg-[rgba(255,241,241,0.9)] px-[10px] py-[6px] text-xs leading-[16.8px] text-destructive">
262
+ <span className="tbox-chat-input__blocked-msg min-w-0 flex-1">{blocked.message}</span>
252
263
  {blocked.onRetry && (
253
- <button type="button" className="tbox-chat-input__blocked-retry" onClick={blocked.onRetry}>
264
+ <button type="button" className="tbox-chat-input__blocked-retry shrink-0 rounded-full border-0 bg-primary px-[10px] py-[3px] text-xs leading-[normal] text-white [font-family:inherit]" onClick={blocked.onRetry}>
254
265
  重试
255
266
  </button>
256
267
  )}
@@ -259,19 +270,19 @@ export function ChatInput({
259
270
  </div>
260
271
 
261
272
  {menuVisible && (
262
- <div className={`tbox-media-picker-menu${menuAnimating ? ' tbox-media-picker-menu--visible' : ''}`}>
263
- {menuOptions.map((o) => (
264
- <div key={o.type} className="tbox-media-picker-menu__option" onClick={() => onMenuSelect(o.type)}>
265
- <div className="tbox-media-picker-menu__option-content">
266
- <img className="tbox-media-picker-menu__option-icon" src={o.icon} alt="" />
267
- <span className="tbox-media-picker-menu__option-label">{o.label}</span>
273
+ <div className={`tbox-media-picker-menu mt-3 flex h-[66px] flex-row overflow-hidden transition-all will-change-[opacity,transform] ${menuAnimating ? ' tbox-media-picker-menu--visible [transform:translateY(0)] opacity-100 duration-[var(--tbox-motion-duration-base)] ease-out' : ' [transform:translateY(5px)] opacity-0 duration-[var(--tbox-motion-duration-fast)] ease-in'}`}>
274
+ {menuOptions.map((o, index) => (
275
+ <div key={o.type} className={`tbox-media-picker-menu__option flex h-[66px] w-28 shrink-0 items-center justify-center overflow-hidden rounded-[10px] bg-[rgba(0,0,0,0.04)] opacity-0 transition-all duration-[var(--tbox-motion-duration-base)] ease-out will-change-[opacity,transform] [.tbox-media-picker-menu--visible_&]:opacity-100 [.tbox-media-picker-menu--visible_&]:[transform:translateY(0)] ${MENU_OPTION_DELAY_CLASS[index] ?? ''} ${index > 0 ? ' ml-[7.5px]' : ''}`} onClick={() => onMenuSelect(o.type)}>
276
+ <div className="tbox-media-picker-menu__option-content flex h-6 flex-row items-center">
277
+ <img className="tbox-media-picker-menu__option-icon size-6 shrink-0" src={o.icon} alt="" />
278
+ <span className="tbox-media-picker-menu__option-label ml-1 text-sm font-normal leading-[18.5px] text-secondary-foreground">{o.label}</span>
268
279
  </div>
269
280
  </div>
270
281
  ))}
271
282
  </div>
272
283
  )}
273
284
 
274
- {disclaimer && <div className="tbox-chat-input__disclaimer">{disclaimer}</div>}
285
+ {disclaimer && <div className="tbox-chat-input__disclaimer mt-[5px] text-center text-xs leading-[15px] text-muted-foreground">{disclaimer}</div>}
275
286
 
276
287
  <VoiceRecordingOverlay
277
288
  visible={voice.overlayVisible}
@@ -1,6 +1,15 @@
1
1
  import type { VoiceInteractionState } from './machine';
2
2
  import type { VoicePressHandlers } from './useVoicePress';
3
3
 
4
+ /** 各交互态的按压条底色(旧 less 的 `--pressing` / `--recording-*` / `--processing` 规则)。 */
5
+ const FIELD_STATE_CLASS: Record<VoiceInteractionState, string> = {
6
+ idle: '',
7
+ pressing: 'bg-[#eef4ff]',
8
+ 'recording-active': 'bg-[#eef4ff]',
9
+ 'recording-cancel': 'bg-[#fff1f1]',
10
+ processing: 'bg-[#f5f7fb]',
11
+ };
12
+
4
13
  function fieldText(s: VoiceInteractionState): string {
5
14
  if (s === 'recording-cancel') return '松开取消';
6
15
  if (s === 'processing') return '识别中...';
@@ -20,14 +29,14 @@ export function VoicePressField({
20
29
  }) {
21
30
  return (
22
31
  <div
23
- className={`tbox-voice-press-field tbox-voice-press-field--${interactionState}${disabled ? ' tbox-voice-press-field--disabled' : ''}`}
32
+ className={`tbox-voice-press-field tbox-voice-press-field--${interactionState} flex h-6 min-w-0 flex-1 touch-none select-none items-center justify-center overflow-hidden rounded-[25px] [-webkit-touch-callout:none] ${FIELD_STATE_CLASS[interactionState]} ${disabled ? ' tbox-voice-press-field--disabled opacity-[0.35]' : ''}`}
24
33
  onTouchStart={disabled ? undefined : handlers.onTouchStart}
25
34
  onTouchMove={disabled ? undefined : handlers.onTouchMove}
26
35
  onTouchEnd={disabled ? undefined : handlers.onTouchEnd}
27
36
  onTouchCancel={disabled ? undefined : handlers.onTouchCancel}
28
37
  >
29
- <div className="tbox-voice-press-field__content">
30
- <span className="tbox-voice-press-field__text">{fieldText(interactionState)}</span>
38
+ <div className="tbox-voice-press-field__content flex w-full items-center justify-center px-[10px]">
39
+ <span className="tbox-voice-press-field__text text-base font-semibold leading-[24px] text-foreground">{fieldText(interactionState)}</span>
31
40
  </div>
32
41
  </div>
33
42
  );
@@ -23,26 +23,26 @@ export function VoiceRecordingOverlay({
23
23
  const isCancel = interactionState === 'recording-cancel';
24
24
 
25
25
  return (
26
- <div className="tbox-voice-overlay">
27
- <div className="tbox-voice-overlay__mask" />
26
+ <div className="tbox-voice-overlay fixed inset-0 z-[300] touch-none select-none [-webkit-touch-callout:none]">
27
+ <div className="tbox-voice-overlay__mask absolute inset-0 bg-[rgba(255,255,255,0.01)]" />
28
28
  <div
29
- className="tbox-voice-overlay__capture"
29
+ className="tbox-voice-overlay__capture absolute inset-0 flex touch-none select-none items-end justify-center px-page pb-[calc(28px+env(safe-area-inset-bottom,8px))] [-webkit-touch-callout:none]"
30
30
  onTouchStart={handlers.onTouchStart}
31
31
  onTouchMove={handlers.onTouchMove}
32
32
  onTouchEnd={handlers.onTouchEnd}
33
33
  onTouchCancel={handlers.onTouchCancel}
34
34
  >
35
- <div className="tbox-voice-overlay__panel">
35
+ <div className="tbox-voice-overlay__panel flex w-full max-w-content flex-col items-center">
36
36
  {countdown != null && interactionState === 'recording-active' && (
37
- <div className="tbox-voice-overlay__bubble">
38
- <span className="tbox-voice-overlay__bubble-text">{countdown}秒后自动停止录音</span>
37
+ <div className="tbox-voice-overlay__bubble mb-5 flex h-[41px] w-[134px] items-center justify-center bg-no-repeat [background-image:url('https://mdn.alipayobjects.com/huamei\_frp8ut/afts/img/A*O6TCSrNeWvwAAAAAQHAAAAgAet-KAQ/original')] [background-size:100%_100%]">
38
+ <span className="tbox-voice-overlay__bubble-text whitespace-nowrap text-xs font-medium leading-[31px] text-white">{countdown}秒后自动停止录音</span>
39
39
  </div>
40
40
  )}
41
- <span className={`tbox-voice-overlay__tip${isCancel ? ' tbox-voice-overlay__tip--cancel' : ''}`}>
41
+ <span className={`tbox-voice-overlay__tip mb-4 text-center text-xs font-medium leading-[24px] ${isCancel ? ' tbox-voice-overlay__tip--cancel text-destructive' : ' text-muted-foreground'}`}>
42
42
  {overlayTip(interactionState)}
43
43
  </span>
44
- <div className={`tbox-voice-overlay__button${isCancel ? ' tbox-voice-overlay__button--cancel' : ''}`}>
45
- <div className="tbox-voice-overlay__wave" />
44
+ <div className={`tbox-voice-overlay__button flex h-[50px] w-full items-center justify-center rounded-[26px] shadow-[0_6px_14px_rgba(80,111,255,0.24)] ${isCancel ? ' tbox-voice-overlay__button--cancel [background-image:linear-gradient(162deg,#fd3030_-22%,#f48686_108%)]' : ' [background-image:linear-gradient(162deg,var(--tbox-primary)_-22%,var(--tbox-primary-dark)_108%)]'}`}>
45
+ <div className="tbox-voice-overlay__wave pointer-events-none h-6 w-[242px] bg-no-repeat [background-image:url('https://mdn.alipayobjects.com/huamei\_frp8ut/afts/img/A*5PDvR4j7fBgAAAAAVBAAAAgAet-KAQ/original')] [background-size:100%_100%]" />
46
46
  </div>
47
47
  </div>
48
48
  </div>
@@ -20,7 +20,7 @@ const MAX_DURATION = 60; // 录音上限(秒)
20
20
  const COUNTDOWN_START = 10; // 剩余 10 秒起显示倒计时
21
21
 
22
22
  // 录音权限被拒/不可用时给用户的提示(补回旧模板丢失的“被拒反馈”——旧版会弹 modal / 触发
23
- // onPermissionDenied,新版此前是静默回 idle)。两端通用:toast 是 antd-mobile 的纯 H5 实现。
23
+ // onPermissionDenied,新版此前是静默回 idle)。两端通用:toast 是纯 DOM 实现,不依赖任何组件库。
24
24
  // 到这里的错误来自实际录音引擎(浏览器;或壳内桥失败降级后的 H5——见 FallbackASRAdapter),
25
25
  // 故 NotFoundError 可精确判“无设备”,其余(NotAllowedError/未知)用“检查录音权限 + 重试”兜底。
26
26
  const MIC_PERMISSION_MSG = '无法使用麦克风,请检查录音权限后重试';
@@ -1,7 +1,6 @@
1
1
  // 顶部历史入口胶囊:同时承载点击入口和轻量下拉状态反馈。
2
2
  // 常驻渲染是刻意的:运行时未就绪时只禁用,不隐藏——否则就绪后插入 DOM 会把下方欢迎区顶开。
3
3
  import type { PullStatus } from '../../utils/pull-down-machine';
4
- import './index.less';
5
4
 
6
5
  function labelOf(status: PullStatus, loading: boolean): string {
7
6
  if (loading || status === 'loading') return '加载中...';
@@ -27,14 +26,15 @@ export default function HistoryEntry({
27
26
  if (!visible) return null;
28
27
 
29
28
  return (
30
- <div className="history-entry">
29
+ <div className="history-entry flex justify-center p-0">
31
30
  <button
32
31
  type="button"
33
- className="history-entry__button"
32
+ data-tbox-control="history"
33
+ className="history-entry__button inline-flex min-h-11 appearance-none items-center gap-[5px] rounded-[25px] border-0 bg-muted px-4 py-1 text-sm font-normal leading-[18px] text-muted-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] active:bg-border disabled:cursor-default"
34
34
  disabled={disabled}
35
35
  onClick={onLoad}
36
36
  >
37
- {(loading || pullStatus === 'loading') && <span className="history-entry__spinner" />}
37
+ {(loading || pullStatus === 'loading') && <span className="history-entry__spinner size-[10px] rounded-full border-[1.5px] border-border border-t-primary animate-[history-entry-spin_0.6s_linear_infinite]" />}
38
38
  {labelOf(pullStatus, loading)}
39
39
  </button>
40
40
  </div>