@tbox.cn/app-agent-ui-kit 0.0.0-stage → 1.0.0-alpha.10

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -2
  3. package/assets/keyboard-circle.svg +12 -0
  4. package/assets/more-circle.svg +3 -0
  5. package/assets/new-chat.svg +3 -0
  6. package/assets/quick-command-star.svg +3 -0
  7. package/assets/send-gradient.svg +14 -0
  8. package/assets/stop@2x.png +0 -0
  9. package/assets/voice-circle.svg +3 -0
  10. package/package.json +70 -3
  11. package/src/ChatPage.tsx +400 -0
  12. package/src/card/action-list-pending.test.tsx +91 -0
  13. package/src/card/define-card.test.ts +25 -0
  14. package/src/card/define-card.ts +47 -0
  15. package/src/card/primitives.test.tsx +157 -0
  16. package/src/card/primitives.tsx +717 -0
  17. package/src/card/use-card-actions.ts +86 -0
  18. package/src/card/view-card-inline.test.tsx +42 -0
  19. package/src/card/view-card.test.tsx +79 -0
  20. package/src/card/view-card.tsx +250 -0
  21. package/src/chat-config.test.ts +46 -0
  22. package/src/chat-config.ts +84 -0
  23. package/src/components/ActionBar/DebugButton.test.tsx +87 -0
  24. package/src/components/ActionBar/DebugButton.tsx +48 -0
  25. package/src/components/ActionBar/index.test.tsx +83 -0
  26. package/src/components/ActionBar/index.tsx +158 -0
  27. package/src/components/BottomSheet/index.test.tsx +97 -0
  28. package/src/components/BottomSheet/index.tsx +49 -0
  29. package/src/components/CardRenderer.tsx +36 -0
  30. package/src/components/ChatHeader/index.test.tsx +74 -0
  31. package/src/components/ChatHeader/index.tsx +77 -0
  32. package/src/components/ChatInput/index.test.tsx +156 -0
  33. package/src/components/ChatInput/index.tsx +295 -0
  34. package/src/components/ChatInput/voice/VoicePressField.tsx +43 -0
  35. package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +51 -0
  36. package/src/components/ChatInput/voice/machine.ts +27 -0
  37. package/src/components/ChatInput/voice/useVoicePress.ts +207 -0
  38. package/src/components/HistoryEntry/index.tsx +42 -0
  39. package/src/components/MediaList/index.tsx +270 -0
  40. package/src/components/MessageBubble/index.test.tsx +134 -0
  41. package/src/components/MessageBubble/index.tsx +208 -0
  42. package/src/components/PullDownIndicator/index.tsx +31 -0
  43. package/src/components/QuickCommands/index.test.tsx +101 -0
  44. package/src/components/QuickCommands/index.tsx +75 -0
  45. package/src/components/ReasoningBlock/index.tsx +61 -0
  46. package/src/components/ScrollToBottomButton/index.tsx +12 -0
  47. package/src/components/ToolCallBlock/detail.test.ts +346 -0
  48. package/src/components/ToolCallBlock/detail.ts +204 -0
  49. package/src/components/ToolCallBlock/index.test.tsx +261 -0
  50. package/src/components/ToolCallBlock/index.tsx +232 -0
  51. package/src/components/ToolCallBlock/titles.ts +102 -0
  52. package/src/hooks/use-drag-gesture.test.ts +66 -0
  53. package/src/hooks/use-drag-gesture.ts +129 -0
  54. package/src/hooks/use-pull-down-history.ts +241 -0
  55. package/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
  56. package/src/hooks/useMediaUpload.ts +242 -0
  57. package/src/hooks/useTTSAutoPlay.ts +82 -0
  58. package/src/icons.ts +39 -0
  59. package/src/index.ts +143 -0
  60. package/src/overlay/Overlay.tsx +154 -0
  61. package/src/overlay/focus.ts +53 -0
  62. package/src/overlay/index.ts +16 -0
  63. package/src/overlay/inert.ts +27 -0
  64. package/src/overlay/layers.ts +21 -0
  65. package/src/overlay/overlay.ssr.test.tsx +27 -0
  66. package/src/overlay/overlay.test.tsx +209 -0
  67. package/src/overlay/presence.ts +86 -0
  68. package/src/overlay/scroll-lock.ts +62 -0
  69. package/src/overlay/stack.ts +111 -0
  70. package/src/overlay/use-overlay.ts +80 -0
  71. package/src/preview-provider.tsx +47 -0
  72. package/src/shell.contract.json +75 -0
  73. package/src/shell.test.ts +72 -0
  74. package/src/shell.ts +60 -0
  75. package/src/store-context.tsx +92 -0
  76. package/src/surface.test.tsx +35 -0
  77. package/src/surface.tsx +44 -0
  78. package/src/test/setup.ts +7 -0
  79. package/src/theme/base.css +167 -0
  80. package/src/theme/contract.json +193 -0
  81. package/src/theme/motion.css +19 -0
  82. package/src/theme/theme-contract.test.ts +85 -0
  83. package/src/theme/theme.ts +17 -0
  84. package/src/theme/tokens.css +78 -0
  85. package/src/types.ts +29 -0
  86. package/src/utils/copyText.ts +11 -0
  87. package/src/utils/haptics.test.ts +51 -0
  88. package/src/utils/haptics.ts +44 -0
  89. package/src/utils/image-preview-host.tsx +95 -0
  90. package/src/utils/imagePreview.test.ts +32 -0
  91. package/src/utils/imagePreview.ts +19 -0
  92. package/src/utils/pull-down-machine.test.ts +188 -0
  93. package/src/utils/pull-down-machine.ts +157 -0
  94. package/src/utils/session-error.ts +5 -0
  95. package/src/utils/toast.test.ts +64 -0
  96. package/src/utils/toast.ts +108 -0
  97. package/src/utils/tool-call-display.test.ts +240 -0
  98. package/src/utils/tool-call-display.ts +146 -0
  99. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,72 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { describe, expect, it } from 'vitest';
5
+ import { SHELL_CONTRACT, resolveBrandName } from './shell';
6
+
7
+ const here = path.dirname(fileURLToPath(import.meta.url));
8
+ const read = (rel: string) => readFileSync(path.join(here, rel), 'utf8');
9
+
10
+ /** 契约声明的选择器必须真的出现在源码里——「文档说有、代码没接」在这里失败。 */
11
+ const SELECTOR_SOURCES: Record<string, string[]> = {
12
+ '.chat-page__brand': ['ChatPage.tsx'],
13
+ '.chat-page__welcome': ['ChatPage.tsx'],
14
+ '.chat-page__body': ['ChatPage.tsx'],
15
+ '.history-entry': ['components/HistoryEntry/index.tsx'],
16
+ '.chat-page__home-slot': ['ChatPage.tsx'],
17
+ '.chat-page__conversation-overlay': ['ChatPage.tsx'],
18
+ '.quick-commands': ['components/QuickCommands/index.tsx'],
19
+ '.tbox-chat-input': ['components/ChatInput/index.tsx'],
20
+ };
21
+
22
+ describe('壳契约', () => {
23
+ it('区域 id 唯一且每个选择器都有源码出处', () => {
24
+ const ids = SHELL_CONTRACT.regions.map((region) => region.id);
25
+ expect(new Set(ids).size).toBe(ids.length);
26
+ for (const region of SHELL_CONTRACT.regions) {
27
+ const sources = SELECTOR_SOURCES[region.selector];
28
+ expect(sources, `壳契约新增选择器 ${region.selector} 时同步补源码映射`).toBeDefined();
29
+ const className = region.selector.replace(/^\./, '');
30
+ const found = sources.some((file) => read(file).includes(className));
31
+ expect(found, `${region.id}: ${region.selector} 在源码里不存在`).toBe(true);
32
+ }
33
+ });
34
+
35
+ it('可覆写区域只限壳层类名,内部结构排除在外', () => {
36
+ for (const region of SHELL_CONTRACT.regions.filter((item) => item.brandable)) {
37
+ expect(region.selector.startsWith('.chat-page__') || region.selector === '.quick-commands').toBe(true);
38
+ }
39
+ expect(SHELL_CONTRACT.internal.length).toBeGreaterThan(0);
40
+ });
41
+
42
+ it('每个区域都写明驱动来源', () => {
43
+ for (const region of SHELL_CONTRACT.regions) {
44
+ expect(region.drivenBy.length, `${region.id} 缺 drivenBy`).toBeGreaterThan(0);
45
+ }
46
+ });
47
+
48
+ it('控件契约的 data-tbox-control 都在源码里', () => {
49
+ const sources = ['components/ChatInput/index.tsx', 'components/HistoryEntry/index.tsx', 'components/ScrollToBottomButton/index.tsx'];
50
+ for (const control of SHELL_CONTRACT.controls ?? []) {
51
+ const attr = /data-tbox-control=['"]([^'"]+)['"]/.exec(control.selector)?.[1];
52
+ expect(attr, `控件 ${control.id} 的选择器必须用 data-tbox-control`).toBeTruthy();
53
+ expect(sources.some((file) => read(file).includes('data-tbox-control="' + attr + '"')), `控件 ${control.id} 在源码里不存在`).toBe(true);
54
+ expect(control.minHit).toBeGreaterThanOrEqual(44);
55
+ }
56
+ });
57
+ });
58
+
59
+ describe('品牌名三级来源', () => {
60
+ it('identity.name 优先', () => {
61
+ expect(resolveBrandName({ name: '悦享里', tagline: '商圈助手' }, '某商场')).toBe('悦享里');
62
+ });
63
+
64
+ it('缺 identity 时回落 HELLO_ACK 的 mallName', () => {
65
+ expect(resolveBrandName(undefined, '某商场')).toBe('某商场');
66
+ });
67
+
68
+ it('都没有则不渲染', () => {
69
+ expect(resolveBrandName(undefined, undefined)).toBeUndefined();
70
+ expect(resolveBrandName({ name: '' }, undefined)).toBeUndefined();
71
+ });
72
+ });
package/src/shell.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 对话壳契约:哪些区域由什么驱动、哪些选择器可以覆写。
3
+ *
4
+ * 数据在 `shell.contract.json`(`docs/agent/kit.md` 与 `shell.test.ts` 的共同来源);
5
+ * 本文件只做类型收口与品牌名解析。
6
+ *
7
+ * - `docs/agent/shell.md` 的「能改什么」表由契约数据生成,杜绝「文档说有、代码没接」;
8
+ * - `shell.test.ts` 断言每条声明在源码里真的成立,声明与实现漂移即失败。
9
+ *
10
+ * 只描述壳层(ChatPage 渲染的区域)。kit 内部组件(MessageBubble、ChatInput 的内部结构)
11
+ * 不承诺稳定;改样式请用契约里 `brandable: true` 的选择器。
12
+ */
13
+ import type { ChatIdentity } from './chat-config';
14
+ import contract from './shell.contract.json';
15
+
16
+ export type ShellArea = 'brand' | 'welcome' | 'messages' | 'history' | 'home' | 'quick-commands' | 'input' | 'conversation-overlay';
17
+
18
+ export interface ShellRegion {
19
+ /** 稳定 id(文档与测试引用) */
20
+ id: string;
21
+ /** 作用区域 */
22
+ area: ShellArea;
23
+ /** 根类名(应用可据此覆写) */
24
+ selector: string;
25
+ /** 由什么驱动:配置键、槽或 store 字段 */
26
+ drivenBy: string[];
27
+ /** 可覆写(`brand.css` 里改它算受支持用法) */
28
+ brandable: boolean;
29
+ }
30
+
31
+ export interface ShellControl {
32
+ /** 稳定 id(探针与文档引用) */
33
+ id: string;
34
+ /** 可定位的选择器(data-tbox-control) */
35
+ selector: string;
36
+ /** 可访问名 */
37
+ name: string;
38
+ /** 最小命中区(px) */
39
+ minHit: number;
40
+ /** 能力开关(关闭时控件可缺席) */
41
+ capability?: string | string[];
42
+ }
43
+
44
+ export interface ShellContract {
45
+ regions: ShellRegion[];
46
+ /** 交互控件契约:探针按它查,不按内部类名猜 */
47
+ controls?: ShellControl[];
48
+ /** 不承诺稳定、不要覆写的内部结构 */
49
+ internal: string[];
50
+ }
51
+
52
+ export const SHELL_CONTRACT: ShellContract = contract as ShellContract;
53
+
54
+ /**
55
+ * 品牌名三级来源:`chat.json identity.name` → `HELLO_ACK mallScope.mallName` → 无(不渲染品牌条)。
56
+ * 智能体身份是配置项,不是代码:应用只改 `config/chat.json`。
57
+ */
58
+ export function resolveBrandName(identity: ChatIdentity | undefined, mallName: string | undefined): string | undefined {
59
+ return identity?.name || mallName || undefined;
60
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * KitChatProvider:壳组件的 store 注入位(单一模板统一化 W2-1)。
3
+ *
4
+ * 壳组件不 import 应用 store——经 React context 读取注入的 store 与卡片注册表;
5
+ * 应用在 `<ChatPage store={useChatStore} cards={CHAT_REGISTRY} rawCards={CARD_REGISTRY}/>`
6
+ * 一处装配(或自组 KitChatProvider 树)。
7
+ *
8
+ * useChatStore 调用签名与 zustand 绑定 hook 逐字兼容(`useChatStore((s)=>s.x)`)——
9
+ * 组件代码从应用 store 迁移零改写(仅 import 来源变化)。
10
+ */
11
+ import { createContext, useContext, useMemo, type ReactNode } from 'react';
12
+ import type { CardComponent, TboxCardPayload } from '@tbox.cn/app-contracts';
13
+ import type { ClientSlotRegistry, CoreChatState, CoreChatStore } from '@tbox.cn/app-agent-sdk-client';
14
+
15
+ export interface KitChatContextValue {
16
+ /** 应用注入的 chat store(zustand 绑定 hook + API) */
17
+ readonly store: CoreChatStore;
18
+ /** 聊天入口卡片注册表(模块注册 + 组合层覆盖) */
19
+ readonly cards: Record<string, CardComponent>;
20
+ /** 原始形态卡片注册表(无覆盖;详情弹层等防嵌套消费) */
21
+ readonly rawCards: Record<string, CardComponent>;
22
+ /** 客户端槽注册表(home 首期唯一槽;缺席 = chat 流形态) */
23
+ readonly slots?: ClientSlotRegistry;
24
+ /**
25
+ * 旁路/消息卡内联流过滤(域注入;缺省恒等):域声明哪些卡不进内联流
26
+ * (由域浮层自持,如 mall 会员门禁卡系)——同时参与 home-first 形态判定。
27
+ */
28
+ readonly filterInlineCards?: (cards: readonly TboxCardPayload[]) => TboxCardPayload[];
29
+ }
30
+
31
+ const IDENTITY_FILTER = (cards: readonly TboxCardPayload[]): TboxCardPayload[] => [...cards];
32
+
33
+ const KitChatContext = createContext<KitChatContextValue | null>(null);
34
+
35
+ export function KitChatProvider({
36
+ store,
37
+ cards,
38
+ rawCards,
39
+ slots,
40
+ filterInlineCards,
41
+ children,
42
+ }: KitChatContextValue & { children: ReactNode }) {
43
+ const value = useMemo<KitChatContextValue>(
44
+ () => ({
45
+ store,
46
+ cards,
47
+ rawCards,
48
+ ...(slots ? { slots } : {}),
49
+ ...(filterInlineCards ? { filterInlineCards } : {}),
50
+ }),
51
+ [store, cards, rawCards, slots, filterInlineCards],
52
+ );
53
+ return <KitChatContext.Provider value={value}>{children}</KitChatContext.Provider>;
54
+ }
55
+
56
+ function useKitChatContext(): KitChatContextValue {
57
+ const value = useContext(KitChatContext);
58
+ if (!value) {
59
+ throw new Error('KitChatProvider 缺席:kit 组件须在 <ChatPage>(或自组 Provider)内使用');
60
+ }
61
+ return value;
62
+ }
63
+
64
+ /** 选择器读取(镜像 zustand 绑定 hook 调用签名;组件从 context 取 store)。 */
65
+ export function useChatStore<T>(selector: (state: CoreChatState) => T): T {
66
+ return useKitChatContext().store(selector);
67
+ }
68
+
69
+ /** store API(getState/subscribe;effect/事件回调场景)。 */
70
+ export function useChatStoreApi(): CoreChatStore {
71
+ return useKitChatContext().store;
72
+ }
73
+
74
+ /** 聊天入口卡片注册表(MessageBubble 等卡渲染消费)。 */
75
+ export function useChatCards(): Record<string, CardComponent> {
76
+ return useKitChatContext().cards;
77
+ }
78
+
79
+ /** 原始形态卡片注册表(RawCardRenderer 消费)。 */
80
+ export function useChatRawCards(): Record<string, CardComponent> {
81
+ return useKitChatContext().rawCards;
82
+ }
83
+
84
+ /** 客户端槽注册表(home 槽;缺席 = chat 流形态)。 */
85
+ export function useClientSlots(): ClientSlotRegistry | undefined {
86
+ return useKitChatContext().slots;
87
+ }
88
+
89
+ /** 旁路/消息卡内联流过滤器(域注入;缺省恒等)。 */
90
+ export function useInlineCardFilter(): (cards: readonly TboxCardPayload[]) => TboxCardPayload[] {
91
+ return useKitChatContext().filterInlineCards ?? IDENTITY_FILTER;
92
+ }
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createElement } from 'react';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import { Card, CardButton, CardHeader, defineCard, useCardActions } from './index';
5
+ import { createSurfaceHarness } from './surface';
6
+
7
+ /** 一张用 kit 动作的卡:没有 provider 会抛「KitChatProvider 缺席」。 */
8
+ const DemoCard = defineCard({ type: 'demo-card' }, ({ data, cardId, isHistory }) => {
9
+ const api = useCardActions({ cardId, isHistory });
10
+ return (
11
+ <Card>
12
+ <CardHeader title={String((data as { title: string }).title)} />
13
+ <CardButton onClick={() => api.send('继续')}>继续</CardButton>
14
+ </Card>
15
+ );
16
+ });
17
+
18
+ describe('createSurfaceHarness', () => {
19
+ it('给出与运行时同形的 provider,kit 卡片可直接渲染', () => {
20
+ const harness = createSurfaceHarness({ cards: { 'demo-card': DemoCard } });
21
+ const html = renderToStaticMarkup(
22
+ harness.wrap(createElement(DemoCard, { data: { title: '停车订单' }, cardId: 'c1', isHistory: false })),
23
+ );
24
+ expect(html).toContain('停车订单');
25
+ expect(html).toContain('继续');
26
+ });
27
+
28
+ it('历史态可渲染且动作禁用', () => {
29
+ const harness = createSurfaceHarness({ cards: { 'demo-card': DemoCard } });
30
+ const html = renderToStaticMarkup(
31
+ harness.wrap(createElement(DemoCard, { data: { title: '停车订单' }, cardId: 'c1', isHistory: true })),
32
+ );
33
+ expect(html).toContain('disabled');
34
+ });
35
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * SurfaceHarness:卡片/聊天表面的唯一装配入口。
3
+ *
4
+ * 证据(check:fast)、截图(card render)、预览页都要渲染真实组件——但每个入口都手搭
5
+ * provider 栈,就会出现「预览崩、证据过、运行时坏」的分裂。这里把 store + provider 收成
6
+ * 一个工厂:看到的就是运行时看到的。
7
+ *
8
+ * 用法:
9
+ * const harness = createSurfaceHarness({ cards, state });
10
+ * renderToStaticMarkup(harness.wrap(<MyCard ... />));
11
+ */
12
+ import type { ReactNode } from 'react';
13
+ import type { CardComponent } from '@tbox.cn/app-contracts';
14
+ import type { ClientSlotRegistry, CoreChatState } from '@tbox.cn/app-agent-sdk-client';
15
+ import { KitChatProvider } from './store-context';
16
+ import { createPreviewStore } from './preview-provider';
17
+
18
+ export interface SurfaceHarnessOptions {
19
+ /** cards = 组合层注册表(含覆盖);rawCards 缺省同 cards。 */
20
+ cards?: Record<string, CardComponent>;
21
+ rawCards?: Record<string, CardComponent>;
22
+ /** 客户端槽(home);缺省无。 */
23
+ slots?: ClientSlotRegistry;
24
+ /** store 初值覆盖(如 isGenerating / 历史态)。 */
25
+ state?: Partial<CoreChatState>;
26
+ }
27
+
28
+ export interface SurfaceHarness {
29
+ store: ReturnType<typeof createPreviewStore>;
30
+ /** 把一个元素包进与运行时同形的 provider 树。 */
31
+ wrap: (node: ReactNode) => ReactNode;
32
+ }
33
+
34
+ export function createSurfaceHarness(options: SurfaceHarnessOptions = {}): SurfaceHarness {
35
+ const cards = options.cards ?? {};
36
+ const rawCards = options.rawCards ?? cards;
37
+ const store = createPreviewStore(options.state);
38
+ const wrap = (node: ReactNode): ReactNode => (
39
+ <KitChatProvider store={store} cards={cards} rawCards={rawCards} {...(options.slots ? { slots: options.slots } : {})}>
40
+ {node}
41
+ </KitChatProvider>
42
+ );
43
+ return { store, wrap };
44
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * vitest 全局 setup:React act() 环境声明单一真源。
3
+ * 此前散落各用例内联声明、多数漏声明(act 告警刷屏 CI 日志);
4
+ * 统一收敛后新用例自动继承,无需逐文件记忆。node 环境纯逻辑用例设此全局无副作用。
5
+ */
6
+ (globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean })
7
+ .IS_REACT_ACT_ENVIRONMENT = true;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * 基座重置(进 `@layer base`):盒模型、文档级字体、卡框与重置规则都在这一层,
3
+ * 组件上的工具类可以覆写它们;层外的跨组件规则见文件末尾(有意留层外)。
4
+ * token 来自 tokens.css / motion.css。
5
+ */
6
+ @import './tokens.css';
7
+ @import './motion.css';
8
+
9
+ @layer base {
10
+ * {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ html,
15
+ body,
16
+ #root {
17
+ margin: 0;
18
+ padding: 0;
19
+ height: 100%;
20
+ }
21
+
22
+ body {
23
+ /* mall-vis 字栈:demo 拉丁栈 + 显式 CJK(demo 依赖容器隐式 CJK,模板面向开放浏览器) */
24
+ font-family:
25
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC',
26
+ 'Microsoft YaHei', sans-serif;
27
+ font-size: var(--tbox-fs-body);
28
+ color: var(--tbox-text-primary);
29
+ background: var(--tbox-bg-page);
30
+ -webkit-font-smoothing: antialiased;
31
+ }
32
+
33
+ /* 顶层容器全宽(渐变底铺满),内容区由各处 max-width:800px 居中(对齐原模板 #app)。 */
34
+ #root {
35
+ width: 100%;
36
+ position: relative;
37
+ }
38
+
39
+ /* 去掉移动端点击高亮 */
40
+ * {
41
+ -webkit-tap-highlight-color: transparent;
42
+ }
43
+
44
+ /* 卡片统一外层 = 卡片「卡框」。所有卡片共有的框在这里,单卡组件别重复写:
45
+ - 间距:卡片与上下元素(工具调用 / 气泡)的间距,与 .tool-calls 一致;
46
+ - 外观:默认背景(白) / 1px 边框 / 圆角 / 阴影;`overflow:hidden` 把内容裁进圆角;
47
+ - 入场动效:mount 即播(0.36s 上浮淡入,对齐 mall-vis 消息卡节奏)。
48
+ 值为物理 px(大写 PX):圆角 var(--tbox-radius-lg)=24、边框 1、阴影 var(--tbox-shadow-sm)=0 4 13。
49
+ ⚠️ **内边距不在卡框里**——由卡片自己写。卡框给 padding 会让「自带背景色的卡」在外面露一圈白边(卡里套卡)。
50
+ 宽度也不在卡框里:默认占满整列(≈移动端 350~400px 设计宽),紧凑卡自己写 max-width。
51
+ 单卡组件(.tbox-<type>)只画内容;**要整卡换底色 / 出血图,直接在自己 root 上 `background:<色>` 或铺满图**——
52
+ 会铺满卡框、裁进圆角、不出白边(别再自己设圆角,卡框已裁)。不写背景则露卡框默认白底,不透明。 */
53
+ .tbox-card {
54
+ margin-bottom: 6PX;
55
+ background: var(--tbox-bg-card);
56
+ border: 1PX solid var(--tbox-border);
57
+ border-radius: var(--tbox-radius-lg);
58
+ box-shadow: var(--tbox-shadow-sm);
59
+ overflow: hidden;
60
+ animation: tbox-card-enter var(--tbox-motion-duration-slow) ease;
61
+ }
62
+
63
+ @keyframes tbox-card-enter {
64
+ from {
65
+ opacity: 0;
66
+ transform: translateY(8PX);
67
+ }
68
+
69
+ to {
70
+ opacity: 1;
71
+ transform: translateY(0);
72
+ }
73
+ }
74
+
75
+ @media (prefers-reduced-motion: reduce) {
76
+ .tbox-card {
77
+ animation: none;
78
+ }
79
+ }
80
+
81
+ /* ===== 弹层进出场(kit overlay 内核;工具类 animate-[tbox-sheet-in_…] 引用) =====
82
+ 只做 transform / opacity(两个属性在所有兼容基线内且可合成)。退出动画配 `both` 填充,
83
+ 保证动画结束后元素停在收起位,等 usePresence 卸载。 */
84
+ @keyframes tbox-sheet-in {
85
+ from {
86
+ transform: translateY(100%);
87
+ }
88
+
89
+ to {
90
+ transform: translateY(0);
91
+ }
92
+ }
93
+
94
+ @keyframes tbox-sheet-out {
95
+ from {
96
+ transform: translateY(0);
97
+ }
98
+
99
+ to {
100
+ transform: translateY(100%);
101
+ }
102
+ }
103
+
104
+ @keyframes tbox-fade-in {
105
+ from {
106
+ opacity: 0;
107
+ }
108
+
109
+ to {
110
+ opacity: 1;
111
+ }
112
+ }
113
+
114
+ @keyframes tbox-fade-out {
115
+ from {
116
+ opacity: 1;
117
+ }
118
+
119
+ to {
120
+ opacity: 0;
121
+ }
122
+ }
123
+
124
+ /* 多卡纵向容器(SDK CardCarousel 多卡分支):容器内卡片关闭逐卡入场动画——
125
+ 同屏多卡逐张挂载时 0.36s 上浮淡入会交叠抖动;单卡直出与其他场景的入场动画保留
126
+ (命中卡片本体 .tbox-card:卡框动画在自身规则上,item 中间层无动画规则) */
127
+ .tbox-card-stack .tbox-card {
128
+ animation: none;
129
+ }
130
+
131
+ /* 兜底态(未知 cardType / 渲染出错,由 CardRenderer 给外层加此修饰类):
132
+ 复用卡框,弱化成无阴影的虚线提示框(内边距自带,因为卡框不再给 padding) */
133
+ .tbox-card--fallback {
134
+ max-width: 80%;
135
+ padding: 16PX 12PX;
136
+ background: var(--tbox-bg-subtle);
137
+ border: 0.5PX dashed var(--tbox-border);
138
+ box-shadow: none;
139
+ color: var(--tbox-text-muted);
140
+ font-size: var(--tbox-fs-caption);
141
+ }
142
+
143
+
144
+ /* 表单控件继承排版:模板不引 preflight,原生 button/input 否则落到浏览器默认 13.33px(越档字号)。
145
+ 作用域限定在壳与卡片内,工具类仍可覆写。 */
146
+ :where(.tbox-app, .chat-page, .tbox-card) :where(button, input, textarea, select) {
147
+ font: inherit;
148
+ color: inherit;
149
+ letter-spacing: inherit;
150
+ }
151
+
152
+ /* 基元/模块迁移后不再各自写 margin reset:标题、段落、列表统一归零(在 base 层,工具类可覆写)。 */
153
+ h1, h2, h3, h4, h5, h6, p, dl, dd, dt, ul, ol {
154
+ margin: 0;
155
+ }
156
+ }
157
+
158
+ /* ── 层外:壳的跨组件覆写(必须压过工具类,故不进 @layer) ── */
159
+ /* 录音期间锁页面(由 useVoicePress 在 document.body 上 toggle,不是 TSX 元素):
160
+ 禁选中/拖拽/长按菜单,必须压过浏览器默认与页面内联样式。 */
161
+ .tbox-voice-page-lock,
162
+ .tbox-voice-page-lock * {
163
+ -webkit-user-select: none !important;
164
+ user-select: none !important;
165
+ -webkit-touch-callout: none !important;
166
+ -webkit-user-drag: none !important;
167
+ }
@@ -0,0 +1,193 @@
1
+ {
2
+ "$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.css+motion.css 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。 pairs 段 = 对比度对账清单(fg/bg 都是 platform 键;min 为 WCAG 阈值;color-mix 派生的由浏览器车道补验)。",
3
+ "platform": [
4
+ "--tbox-accent",
5
+ "--tbox-accent-light",
6
+ "--tbox-bg-card",
7
+ "--tbox-bg-page",
8
+ "--tbox-bg-subtle",
9
+ "--tbox-bg-warm",
10
+ "--tbox-border",
11
+ "--tbox-border-strong",
12
+ "--tbox-content-max-width",
13
+ "--tbox-error",
14
+ "--tbox-fs-body",
15
+ "--tbox-fs-caption",
16
+ "--tbox-fs-heading",
17
+ "--tbox-icon-color",
18
+ "--tbox-ink",
19
+ "--tbox-input-bg",
20
+ "--tbox-input-padding",
21
+ "--tbox-input-radius",
22
+ "--tbox-media-item-radius",
23
+ "--tbox-media-item-size",
24
+ "--tbox-motion-duration-base",
25
+ "--tbox-motion-duration-fast",
26
+ "--tbox-motion-duration-slow",
27
+ "--tbox-motion-easing-emphasized",
28
+ "--tbox-motion-easing-standard",
29
+ "--tbox-page-gutter",
30
+ "--tbox-primary",
31
+ "--tbox-primary-dark",
32
+ "--tbox-primary-light",
33
+ "--tbox-radius-lg",
34
+ "--tbox-radius-md",
35
+ "--tbox-radius-sm",
36
+ "--tbox-send-btn-size",
37
+ "--tbox-shadow-lg",
38
+ "--tbox-shadow-md",
39
+ "--tbox-shadow-sm",
40
+ "--tbox-success",
41
+ "--tbox-text-muted",
42
+ "--tbox-text-primary",
43
+ "--tbox-text-secondary",
44
+ "--tbox-transition-base",
45
+ "--tbox-transition-fast",
46
+ "--tbox-warning"
47
+ ],
48
+ "domains": [
49
+ "--tbox-domain-member-accent",
50
+ "--tbox-domain-member-border",
51
+ "--tbox-domain-member-surface",
52
+ "--tbox-domain-parking-accent",
53
+ "--tbox-domain-parking-border",
54
+ "--tbox-domain-parking-surface",
55
+ "--tbox-domain-promotion-accent",
56
+ "--tbox-domain-promotion-surface",
57
+ "--tbox-domain-sg-accent",
58
+ "--tbox-domain-sg-border",
59
+ "--tbox-domain-sg-surface"
60
+ ],
61
+ "assets": [
62
+ "--tbox-asset-bumpin-bg",
63
+ "--tbox-asset-home-poster-compact",
64
+ "--tbox-asset-home-poster-stage",
65
+ "--tbox-asset-member-login-hero",
66
+ "--tbox-asset-member-mascot",
67
+ "--tbox-asset-parking-hero",
68
+ "--tbox-asset-promotion-activity-header",
69
+ "--tbox-asset-promotion-coupon-header",
70
+ "--tbox-asset-sg-header"
71
+ ],
72
+ "pairs": [
73
+ {
74
+ "fg": "--tbox-text-primary",
75
+ "bg": "--tbox-bg-card",
76
+ "min": 4.5,
77
+ "usage": "正文"
78
+ },
79
+ {
80
+ "fg": "--tbox-text-primary",
81
+ "bg": "--tbox-bg-page",
82
+ "min": 4.5,
83
+ "usage": "正文"
84
+ },
85
+ {
86
+ "fg": "--tbox-text-secondary",
87
+ "bg": "--tbox-bg-card",
88
+ "min": 4.5,
89
+ "usage": "次要文字"
90
+ },
91
+ {
92
+ "fg": "--tbox-text-secondary",
93
+ "bg": "--tbox-bg-page",
94
+ "min": 4.5,
95
+ "usage": "次要文字"
96
+ },
97
+ {
98
+ "fg": "--tbox-text-muted",
99
+ "bg": "--tbox-bg-card",
100
+ "min": 4.5,
101
+ "usage": "说明文字"
102
+ },
103
+ {
104
+ "fg": "--tbox-text-muted",
105
+ "bg": "--tbox-bg-page",
106
+ "min": 4.5,
107
+ "usage": "说明文字"
108
+ },
109
+ {
110
+ "fg": "--tbox-primary",
111
+ "bg": "--tbox-bg-card",
112
+ "min": 4.5,
113
+ "usage": "链接与主色文字"
114
+ },
115
+ {
116
+ "fg": "--tbox-primary-light",
117
+ "bg": "--tbox-primary-dark",
118
+ "min": 4.5,
119
+ "usage": "深底主视觉文字(hero tone=inverse)"
120
+ }
121
+ ],
122
+ "derive": {
123
+ "$comment": "浅色模式派生规则(pnpm exec tbox-app theme derive 消费):from = seed | accent;l 为相对种子的 L 增量,L/C 为绝对目标;派生结果须 pairs 全部闭合。键必须 ⊆ platform。",
124
+ "--tbox-primary": {
125
+ "from": "seed"
126
+ },
127
+ "--tbox-primary-dark": {
128
+ "from": "seed",
129
+ "l": -0.12
130
+ },
131
+ "--tbox-primary-light": {
132
+ "from": "seed",
133
+ "L": 0.96,
134
+ "C": 0.03
135
+ },
136
+ "--tbox-accent": {
137
+ "from": "accent"
138
+ },
139
+ "--tbox-accent-light": {
140
+ "from": "accent",
141
+ "L": 0.96,
142
+ "C": 0.03
143
+ },
144
+ "--tbox-bg-page": {
145
+ "from": "seed",
146
+ "L": 0.975,
147
+ "C": 0.008,
148
+ "mood": {
149
+ "warm": {
150
+ "H": 80
151
+ },
152
+ "cool": {
153
+ "H": 240
154
+ }
155
+ }
156
+ },
157
+ "--tbox-bg-card": {
158
+ "from": "seed",
159
+ "L": 0.99,
160
+ "C": 0.004
161
+ },
162
+ "--tbox-bg-subtle": {
163
+ "from": "seed",
164
+ "L": 0.95,
165
+ "C": 0.01
166
+ },
167
+ "--tbox-text-primary": {
168
+ "from": "seed",
169
+ "L": 0.25,
170
+ "C": 0.02
171
+ },
172
+ "--tbox-text-secondary": {
173
+ "from": "seed",
174
+ "L": 0.42,
175
+ "C": 0.02
176
+ },
177
+ "--tbox-text-muted": {
178
+ "from": "seed",
179
+ "L": 0.52,
180
+ "C": 0.015
181
+ },
182
+ "--tbox-border": {
183
+ "from": "seed",
184
+ "L": 0.9,
185
+ "C": 0.01
186
+ },
187
+ "--tbox-border-strong": {
188
+ "from": "seed",
189
+ "L": 0.82,
190
+ "C": 0.015
191
+ }
192
+ }
193
+ }