@tbox.cn/app-agent-ui-kit 1.0.0-alpha.1 → 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 (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
@@ -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,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,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
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$comment": "主题可覆写变量封闭清单(主题轨 W-T2;doctor theme-package-structure 消费——超集即 error;theme-contract.test.ts 锁 tokens.less+motion.less 的平台键 ⊆ platform 段)。domains 段 = 域色两段式通道(identity/surface/border 三角色,v1 封闭;promotion 按域色矩阵无描边列)。assets 段 = 素材变量链语义位(W-T3 铺开,铺开后逐一核对)。",
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
3
  "platform": [
4
4
  "--tbox-accent",
5
5
  "--tbox-accent-light",
@@ -68,5 +68,126 @@
68
68
  "--tbox-asset-promotion-activity-header",
69
69
  "--tbox-asset-promotion-coupon-header",
70
70
  "--tbox-asset-sg-header"
71
- ]
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
+ }
72
193
  }
@@ -2,7 +2,7 @@
2
2
  * 主题契约锁(主题轨 W-T2):contract.json 单一真源 ↔ kit css 机械一致。
3
3
  *
4
4
  * 断言:
5
- * ① tokens.less + motion.less 的 :root 变量集 ⊆ contract.platform(css 演进不漂移清单);
5
+ * ① tokens.css + motion.css 的 :root 变量集 ⊆ contract.platform(css 演进不漂移清单);
6
6
  * ② contract 三段非空且全局唯一(无重复键);
7
7
  * ③ domains/assets 段命名空间前缀正确(--tbox-domain-* / --tbox-asset-*)。
8
8
  *
@@ -18,6 +18,7 @@ const contract = JSON.parse(readFileSync(path.join(themeDir, 'contract.json'), '
18
18
  platform: string[];
19
19
  domains: string[];
20
20
  assets: string[];
21
+ derive?: Record<string, { from: 'seed' | 'accent'; L?: number; C?: number; l?: number; mood?: Record<string, { H: number }> }>;
21
22
  };
22
23
 
23
24
  function extractRootVars(file: string): string[] {
@@ -37,8 +38,8 @@ function extractRootVars(file: string): string[] {
37
38
  }
38
39
 
39
40
  describe('主题契约(contract.json)', () => {
40
- it('tokens.less + motion.less 的 :root 变量 ⊆ contract.platform', () => {
41
- const cssVars = [...extractRootVars('tokens.less'), ...extractRootVars('motion.less')];
41
+ it('tokens.css + motion.css 的 :root 变量 ⊆ contract.platform', () => {
42
+ const cssVars = [...extractRootVars('tokens.css'), ...extractRootVars('motion.css')];
42
43
  expect(cssVars.length).toBeGreaterThan(40);
43
44
  const allowed = new Set(contract.platform);
44
45
  const drift = cssVars.filter((v) => !allowed.has(v));
@@ -55,6 +56,21 @@ describe('主题契约(contract.json)', () => {
55
56
  for (const key of contract.assets) expect(key.startsWith('--tbox-asset-')).toBe(true);
56
57
  });
57
58
 
59
+ it('derive 段的键 ⊆ platform,且带 from 来源', () => {
60
+ const derive = contract.derive ?? {};
61
+ const allowed = new Set(contract.platform);
62
+ const drift = Object.entries(derive)
63
+ .filter(([key]) => !key.startsWith('$'))
64
+ .filter(([key]) => !allowed.has(key))
65
+ .map(([key]) => key);
66
+ expect(drift, 'derive 声明了契约外的令牌:' + drift.join(', ')).toEqual([]);
67
+ for (const [key, rule] of Object.entries(derive)) {
68
+ if (key.startsWith('$')) continue;
69
+ expect(['seed', 'accent']).toContain(rule.from);
70
+ }
71
+ expect(Object.keys(derive).length).toBeGreaterThan(8);
72
+ });
73
+
58
74
  it('motion 族 5 键在清单内(主题轨 T-2.1 契约)', () => {
59
75
  for (const key of [
60
76
  '--tbox-motion-duration-fast',
@@ -5,13 +5,15 @@
5
5
  * 所以这些设计变量必须落在 client。卡片组件与页面统一用 var(--tbox-*) 引用,
6
6
  * 禁止硬编码十六进制色值 / px 字号。
7
7
  *
8
- * 注:这里的 px 会被 postcss-px-to-viewport(750 基准)转成 vw。
8
+ * 单位约定(2026-11 统一样式层):全部长/字号/圆角/阴影写**物理 px**(大写 `PX`)。
9
+ * 组件样式一律走 Tailwind 工具类(4px 标度 + 12/14/16/18/20/24/30/36 字号档),
10
+ * 这些变量只服务主题投影(`rounded-lg` / `shadow-sm` 等)。模板没有 rem 换算,也没有动态根字号。
9
11
  * 视觉源对照与域色矩阵见 docs/reference/templates.md(视觉体系与域色矩阵)。
10
12
  */
11
13
  :root {
12
14
  /* 主色(mall-vis 蓝系) */
13
15
  --tbox-primary: #096bfa;
14
- --tbox-primary-dark: #2368ec;
16
+ --tbox-primary-dark: #1c61e5;
15
17
  --tbox-primary-light: #eaf3ff;
16
18
  --tbox-accent: #096bfa;
17
19
  --tbox-accent-light: #eaf3ff;
@@ -33,41 +35,38 @@
33
35
  --tbox-border-strong: #d3dae6;
34
36
 
35
37
  /* 阴影 */
36
- --tbox-shadow-sm: 0 8px 26px rgba(38, 59, 92, 0.05);
37
- --tbox-shadow-md: 0 12px 32px rgba(24, 82, 177, 0.1);
38
- --tbox-shadow-lg: 0 14px 34px rgba(2, 46, 122, 0.08);
38
+ --tbox-shadow-sm: 0 4PX 13PX rgba(38, 59, 92, 0.05);
39
+ --tbox-shadow-md: 0 6PX 16PX rgba(24, 82, 177, 0.1);
40
+ --tbox-shadow-lg: 0 7PX 17PX rgba(2, 46, 122, 0.08);
39
41
 
40
42
  /* 状态色 */
41
43
  --tbox-success: #169e5a;
42
44
  --tbox-warning: #df8b16;
43
45
  --tbox-error: #e42f46;
44
46
 
45
- /* 字号——按 750/2x 设计稿基线,对标消息气泡(MessageBubble):
46
- 正文 .msg-markdown / __text = 25px,次要信息(时间/角色) = 18~19px,标题 h1~h4 = 36/32/30/28px。
47
- 注意:rootValue 100 + 根字号脚本会把 px 折半渲染(750 稿 → ≈375 手机列),
48
- 所以这里写的是 2x 值,别按普通 web 的 12/14/16 写(那样渲染出来只有一半、发虚)。 */
49
- --tbox-fs-heading: 30px; /* ≈气泡 h3:商品名 / 店名 */
50
- --tbox-fs-body: 25px; /* =气泡正文 */
51
- --tbox-fs-caption: 20px; /* ≈气泡次要信息(时间/角色) */
47
+ /* 字号角色(物理 px):聊天正文 16、卡片正文 14、说明 12,都在 Tailwind 档位内。
48
+ 组件按角色取值,主题才改得动字号;不要再写设计稿 2x 值。 */
49
+ --tbox-fs-heading: 18PX; /* 卡片/分区标题 */
50
+ --tbox-fs-body: 16PX; /* 聊天正文 */
51
+ --tbox-fs-caption: 12PX; /* 说明与次要信息 */
52
52
 
53
53
  /* 圆角 */
54
- --tbox-radius-sm: 12px;
55
- --tbox-radius-md: 18px;
56
- --tbox-radius-lg: 48px;
54
+ --tbox-radius-sm: 6PX;
55
+ --tbox-radius-md: 9PX;
56
+ --tbox-radius-lg: 24PX;
57
57
 
58
- /* 内容最大宽度(对齐参考 H5):全宽渐变底 + 内容区 720px 居中。
59
- 大写 PX 不被 postcss-pxtorem 转换(正则大小写敏感),保持固定像素。 */
58
+ /* 内容最大宽度(对齐参考 H5):全宽渐变底 + 内容区 720px 居中。 */
60
59
  --tbox-content-max-width: 720PX;
61
60
  /* 页面水平栅格:欢迎区、主卡、快捷入口、输入区、消息气泡和消息卡片共用。 */
62
61
  --tbox-page-gutter: 16PX;
63
62
 
64
63
  /* 媒体缩略图 */
65
- --tbox-media-item-size: 174px;
66
- --tbox-media-item-radius: 12px;
64
+ --tbox-media-item-size: 87PX;
65
+ --tbox-media-item-radius: 6PX;
67
66
 
68
67
  /* 输入框 */
69
68
  --tbox-input-bg: rgba(255, 255, 255, 0.7);
70
- /* 输入条跨过 450PX 根字号阈值时保持固定高度,仅横向伸缩。 */
69
+ /* 输入条高度固定,仅横向伸缩。 */
71
70
  --tbox-input-radius: 25PX;
72
71
  --tbox-input-padding: 10PX 12PX;
73
72
  --tbox-send-btn-size: 22PX;