@h-ai/cli 0.1.0-alpha.54 → 0.1.0-alpha.56

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 (75) hide show
  1. package/README.md +4 -0
  2. package/dist/{chunk-FVDXJYMO.js → chunk-O3ANVICQ.js} +31 -2
  3. package/dist/chunk-O3ANVICQ.js.map +1 -0
  4. package/dist/cli-config-templates-OWBEGBZQ.js +5 -0
  5. package/dist/{cli-config-templates-WGN2I23J.js.map → cli-config-templates-OWBEGBZQ.js.map} +1 -1
  6. package/dist/index.js +3 -3
  7. package/dist/{src-6ZBWDBUB.js → src-TBIET7YU.js} +908 -127
  8. package/dist/src-TBIET7YU.js.map +1 -0
  9. package/package.json +7 -7
  10. package/templates/base/.gitignore.hbs +3 -0
  11. package/templates/base/package.json.hbs +1 -1
  12. package/templates/skills/AGENTS.md +8 -22
  13. package/templates/skills/CLAUDE.md +3 -16
  14. package/templates/skills/bridges/admin/AGENTS.md +3 -16
  15. package/templates/skills/bridges/admin/CLAUDE.md +3 -11
  16. package/templates/skills/bridges/admin/copilot-instructions.md +2 -39
  17. package/templates/skills/bridges/api/AGENTS.md +5 -18
  18. package/templates/skills/bridges/api/CLAUDE.md +3 -11
  19. package/templates/skills/bridges/api/copilot-instructions.md +3 -38
  20. package/templates/skills/bridges/fullstack/AGENTS.md.hbs +24 -59
  21. package/templates/skills/bridges/fullstack/CLAUDE.md.hbs +1 -15
  22. package/templates/skills/bridges/fullstack/copilot-instructions.md.hbs +5 -45
  23. package/templates/skills/bridges/h5/AGENTS.md +4 -17
  24. package/templates/skills/bridges/h5/CLAUDE.md +3 -11
  25. package/templates/skills/bridges/h5/copilot-instructions.md +2 -37
  26. package/templates/skills/bridges/mobile-app/AGENTS.md +5 -18
  27. package/templates/skills/bridges/mobile-app/CLAUDE.md +3 -11
  28. package/templates/skills/bridges/mobile-app/copilot-instructions.md +2 -38
  29. package/templates/skills/bridges/website/AGENTS.md +4 -17
  30. package/templates/skills/bridges/website/CLAUDE.md +3 -11
  31. package/templates/skills/bridges/website/copilot-instructions.md +2 -37
  32. package/templates/skills/copilot-instructions.md +2 -36
  33. package/templates/skills/hai-ai/SKILL.md +35 -389
  34. package/templates/skills/hai-ai/guide.md +383 -0
  35. package/templates/skills/hai-ai/reference.md +1 -1
  36. package/templates/skills/hai-api-client/SKILL.md +6 -6
  37. package/templates/skills/hai-api-contract/SKILL.md +10 -25
  38. package/templates/skills/hai-app-create/SKILL.md +29 -388
  39. package/templates/skills/hai-app-create/reference.md +350 -0
  40. package/templates/skills/hai-app-review/SKILL.md +9 -23
  41. package/templates/skills/hai-app-tests/SKILL.md +29 -494
  42. package/templates/skills/hai-app-tests/reference.md +442 -0
  43. package/templates/skills/hai-audit/SKILL.md +6 -6
  44. package/templates/skills/hai-build/SKILL.md +19 -338
  45. package/templates/skills/hai-build/reference.md +326 -0
  46. package/templates/skills/hai-cache/SKILL.md +27 -32
  47. package/templates/skills/hai-capacitor/SKILL.md +19 -366
  48. package/templates/skills/hai-capacitor/reference.md +352 -0
  49. package/templates/skills/hai-ci/SKILL.md +6 -21
  50. package/templates/skills/hai-core/SKILL.md +25 -566
  51. package/templates/skills/hai-core/reference.md +533 -0
  52. package/templates/skills/hai-crypto/SKILL.md +6 -20
  53. package/templates/skills/hai-datapipe/SKILL.md +9 -23
  54. package/templates/skills/hai-deploy/SKILL.md +63 -25
  55. package/templates/skills/hai-framework-sync/SKILL.md +8 -20
  56. package/templates/skills/hai-iam/SKILL.md +27 -371
  57. package/templates/skills/hai-iam/reference.md +343 -0
  58. package/templates/skills/hai-kit/SKILL.md +6 -6
  59. package/templates/skills/hai-payment/SKILL.md +6 -26
  60. package/templates/skills/hai-pr-review/SKILL.md +6 -22
  61. package/templates/skills/hai-reach/SKILL.md +19 -317
  62. package/templates/skills/hai-reach/reference.md +303 -0
  63. package/templates/skills/hai-reldb/SKILL.md +19 -472
  64. package/templates/skills/hai-reldb/reference.md +452 -0
  65. package/templates/skills/hai-scheduler/SKILL.md +6 -6
  66. package/templates/skills/hai-serv/SKILL.md +27 -759
  67. package/templates/skills/hai-serv/reference.md +736 -0
  68. package/templates/skills/hai-storage/SKILL.md +7 -25
  69. package/templates/skills/hai-ui/SKILL.md +29 -625
  70. package/templates/skills/hai-ui/reference.md +598 -0
  71. package/templates/skills/hai-vecdb/SKILL.md +18 -303
  72. package/templates/skills/hai-vecdb/reference.md +291 -0
  73. package/dist/chunk-FVDXJYMO.js.map +0 -1
  74. package/dist/cli-config-templates-WGN2I23J.js +0 -5
  75. package/dist/src-6ZBWDBUB.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hai-ui
3
- description: 使用 @h-ai/ui 构建多端应用界面,包含三层组件架构(原子/组合/场景)、DaisyUI 样式 + Bits UI headless 交互、移动端组件(SafeArea/BottomNav/PullRefresh/ActionSheet/SwipeCell/InfiniteScroll/AppBar)、Design Token 系统与平台检测;当需求涉及界面、表单、表格、移动端适配或主题切换时使用。
3
+ description: "使用 @h-ai/ui 构建 Svelte 5 表单、表格、弹窗、移动界面、主题与 AI 内容展示。"
4
4
  ---
5
5
 
6
6
  # hai-ui
@@ -9,627 +9,31 @@ description: 使用 @h-ai/ui 构建多端应用界面,包含三层组件架构
9
9
 
10
10
  | 项目 | 契约 |
11
11
  | --- | --- |
12
- | 能力 | 使用 @h-ai/ui 构建多端应用界面,包含三层组件架构(原子/组合/场景)、DaisyUI 样式 + Bits UI headless 交互、移动端组件(SafeArea/BottomNav/PullRefresh/ActionSheet/SwipeCell/InfiniteScroll/AppBar)、Design Token 系统与平台检测;当需求涉及界面、表单、表格、移动端适配或主题切换时使用。 |
13
- | 适用场景 | 当任务与 `hai-ui` 的能力描述匹配,并且需要遵循本 Skill 的流程和边界时 |
14
- | 输入 | 模块配置、类型化业务参数、依赖初始化状态和目标运行环境 |
15
- | 输出 | 符合模块公共 API 的实现或示例;业务结果使用 HaiResult,并同步必要测试与文档 |
16
- | 限制 | 遵守 init → use → close 生命周期与运行环境边界;不绕过类型、授权、输入校验或敏感信息保护 |
17
-
18
- > `@h-ai/ui` 是基于 Svelte 5 Runes 的多端 UI 组件库,采用 DaisyUI v5 + Tailwind CSS v4 + Bits UI v2,内置 15 个精选 DaisyUI 主题、内置中英文 i18n、自动导入。内置 Shiki 代码高亮、Mermaid 图表渲染、Design Token 系统和 7 个移动端组件。
19
-
20
- ---
21
-
22
- ## 运行环境
23
-
24
- > **面向 Svelte / SvelteKit 界面层。** 组件可用于 SvelteKit 的 SSR + CSR 页面,也可用于纯客户端 SPA / 原生壳 App;不要在纯 Node 服务模块里直接引用 UI 组件。
25
-
26
- ---
27
-
28
- ## 适用场景
29
-
30
- - 构建管理后台页面(表单、表格、弹窗、导航等)
31
- - 移动端/App 界面开发(SafeArea、BottomNav、PullRefresh 等)
32
- - 使用 Bits UI headless 交互组件(Combobox、DatePicker、Calendar)
33
- - 使用 IAM 场景组件(登录/注册/密码/权限守卫/用户资料表单)
34
- - 使用 Storage 场景组件(文件上传/图片上传/头像上传/文件列表)
35
- - 使用 CRUD 场景组件(列表过滤、详情/编辑面板、删除确认)
36
- - 渲染 AI 输出(Markdown / Mermaid 文档、代码产物预览)
37
- - 配置主题切换与 i18n 多语言
38
- - 多端平台检测与适配
39
-
40
- ---
41
-
42
- ## 使用边界
43
-
44
- - 加密输入变更会清空密文,乱序/清空/卸载后的旧结果不会回填;失败显示错误。提交前确认当前密文非空,不缓存上次密文。
45
-
46
- - `EncryptedInput` 的 `onencrypt` 必须接入真实加密服务;`algorithm` 仅标注算法。缺少回调时显示不可用,不生成密文,不允许用编码代替加密。
47
-
48
- - **优先复用 `@h-ai/ui` 现有组件**,不要在 app 中重复实现同类按钮、表格、表单、弹层或场景页面。
49
- - **页面级文案与业务逻辑放在应用层**;`@h-ai/ui` 负责展示与交互,不承接业务服务、数据库访问或页面级 i18n 管理。
50
- - **场景组件自带内置中英文文案**(如 IAM / CRUD / AI / Storage 场景),除非组件显式提供覆盖 prop,否则不要把页面翻译样板再传进去。
51
- - **自动导入不是全能魔法**:`toast`、类型导入和 `Range` 仍需显式 `import`;其它公开 Svelte 组件可交给 `autoImportHaiUi()`。
52
- - **移动端组件不是样式糖**:使用 `SafeArea` / `BottomNav` / `PullRefresh` / `ActionSheet` 时,务必同步引入 `design-tokens.css` 与 `mobile.css`。
53
-
54
- ---
55
-
56
- ## AI 使用顺序(先判断,再落地)
57
-
58
- ### 1. 先确认项目集成是否完整
59
-
60
- 至少检查以下四项:
61
-
62
- - `svelte.config.*`:`autoImportHaiUi()` 在 `vitePreprocess()` 前。
63
- - `vite.config.*`:`ssr.noExternal` 包含 `@h-ai/*`,`optimizeDeps.exclude` 包含 `bits-ui`。
64
- - `app.css`:已导入 `global.css` / `theme.css`;移动端还要导入 `design-tokens.css` / `mobile.css`。
65
- - Tailwind:已配置 `@source` 扫描 `@h-ai/ui/dist/**/*.{svelte,js,ts}`。
66
-
67
- 如果这四项不完整,优先先补集成,再写页面;否则组件很容易出现“能编译但没样式 / SSR 报错 / 自动导入失效”。
68
-
69
- ### 2. 再选组件层级
70
-
71
- 按复杂度从低到高选:
72
-
73
- - **primitives**:单个交互单元,例如 `Button`、`Input`、`Select`、`Badge`。
74
- - **compounds**:通用业务骨架,例如 `Form`、`Modal`、`Drawer`、`DataTable`、`Pagination`。
75
- - **scenes**:完整业务流,例如 `LoginForm`、`FileUpload`、`CrudPage`、`AiDocumentEditor`。
76
-
77
- 经验法则:
78
-
79
- - 只是做一个输入控件或按钮行 → 先看 primitives。
80
- - 需要通用弹层/表格/分页/表单布局 → 先看 compounds。
81
- - 已经是“登录页 / CRUD 页 / 文件上传页 / AI 文档页”这类完整场景 → 先看 scenes,**不要手搓一遍**。
82
-
83
- ### 3. 常见任务 → 首选组件
84
-
85
- | 任务 | 首选组件 | 使用要点 |
86
- | --- | --- | --- |
87
- | 后台列表页 | `PageHeader` + `Card` + `DataTable` + `Pagination` | 分页、筛选、批量操作优先复用 compounds |
88
- | 表单页/弹层表单 | `Form` + `FormField` + `Input/Select/...` | 表单字段布局统一交给 `FormField` |
89
- | 简单确认/详情弹层 | `Modal` / `Drawer` / `Confirm` | 根据桌面/移动端交互选择弹窗或抽屉 |
90
- | 完整 CRUD 页面 | `CrudPage` | 优先通过 `form` / `pagination` / `density` 配置,不要拆开重写;列头默认可排序、筛选栏自带「重置」 |
91
- | 错误页(401/403/404/500/503) | `ErrorPage` | SvelteKit `+error.svelte` 中按 `page.status` 使用,`onhome`/`onback` 接管跳转 |
92
- | 设置页 | `SettingsLayout` | 分区导航 + 内容区;`sections` + `active` + `onselect`,内容放入 children |
93
- | 登录/注册页布局 | `AuthShell` + `LoginForm` / `RegisterForm` | `variant='card'` 或 `'split'`;split 可通过 `illustration`/`description`/`highlights` 放大图与重点说明 |
94
- | 登录/注册/资料页 | `LoginForm` / `RegisterForm` / `UserProfile` | 页面只负责路由和提交逻辑 |
95
- | 文件/图片上传 | `FileUpload` / `ImageUpload` / `AvatarUpload` | 上传 URL、限制和业务状态由应用层提供 |
96
- | 移动端页面骨架 | `SafeArea` + `AppBar` + `BottomNav` | 原生壳页面优先这一套 |
97
- | AI 文档/Markdown 展示 | `MarkdownRenderer` / `AiDocumentEditor` | Mermaid、代码高亮、复制/下载已内置 |
98
-
99
- ### 4. 最后再决定是否自定义样式
100
-
101
- - 优先通过组件已有 props(`variant` / `size` / `outline` / `class` / snippet slot)调整。
102
- - 需要统一视觉规范时,优先改 `theme.css` / `design-tokens.css` 对应 token,而不是在页面里散落 magic class。
103
- - 只有当 `@h-ai/ui` 现有抽象确实不覆盖时,才在应用层补专属组件。
104
-
105
- ---
106
-
107
- ## 项目配置(从 npm 安装)
108
-
109
- > 以下示例面向通过 `npm install @h-ai/ui` 引用发布包的项目。monorepo 内部使用 `workspace:*` 时路径略有不同。
110
-
111
- ### 1. 安装依赖
112
-
113
- ```bash
114
- # 核心包
115
- npm install @h-ai/ui
116
-
117
- # 必须的对等依赖与构建工具
118
- npm install -D svelte @sveltejs/kit @sveltejs/vite-plugin-svelte
119
- npm install -D tailwindcss @tailwindcss/vite daisyui
120
-
121
- # 图标(可选但推荐)
122
- npm install -D @iconify/tailwind4 @iconify-json/tabler
123
- ```
124
-
125
- ### 2. svelte.config.js
126
-
127
- ```js
128
- import { autoImportHaiUi } from '@h-ai/ui/auto-import'
129
- import adapter from '@sveltejs/adapter-auto'
130
- import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
131
-
132
- /** @type {import('@sveltejs/kit').Config} */
133
- const config = {
134
- // autoImportHaiUi 必须在 vitePreprocess 之前
135
- preprocess: [autoImportHaiUi(), vitePreprocess()],
136
- compilerOptions: {
137
- runes: true, // 强制 Svelte 5 Runes 模式
138
- },
139
- kit: {
140
- adapter: adapter(),
141
- alias: {
142
- $components: './src/lib/components',
143
- $stores: './src/lib/stores',
144
- },
145
- },
146
- }
147
-
148
- export default config
149
- ```
150
-
151
- ### 3. vite.config.ts
152
-
153
- ```ts
154
- import { sveltekit } from '@sveltejs/kit/vite'
155
- import tailwindcss from '@tailwindcss/vite'
156
- import { defineConfig } from 'vite'
157
-
158
- export default defineConfig({
159
- plugins: [
160
- sveltekit(),
161
- tailwindcss(),
162
- ],
163
- optimizeDeps: {
164
- // bits-ui 使用 Svelte 虚拟模块,需排除预构建
165
- exclude: ['bits-ui'],
166
- },
167
- ssr: {
168
- // @h-ai 包为 ESM + Svelte 组件,需 Vite 在 SSR 时处理
169
- noExternal: [/@h-ai\//],
170
- },
171
- })
172
- ```
173
-
174
- ### 4. src/app.css
175
-
176
- ```css
177
- /* ─── Tailwind CSS v4 ─── */
178
- @import 'tailwindcss';
179
-
180
- /* ─── @h-ai/ui 共享样式 ─── */
181
- @import '@h-ai/ui/styles/global.css'; /* 基础重置、滚动条、焦点样式 */
182
- @import '@h-ai/ui/styles/theme.css'; /* Tailwind v4 @theme Token(品牌色/阴影/动效) */
183
-
184
- /* ─── 移动端项目追加(可选) ─── */
185
- @import '@h-ai/ui/styles/design-tokens.css'; /* CSS 自定义属性:间距/圆角/z-index */
186
- @import '@h-ai/ui/styles/mobile.css'; /* 安全区域/触摸优化/键盘适配 */
187
-
188
- /* ─── 扫描 @h-ai/ui 组件中使用的 Tailwind 类名 ─── */
189
- @source "../node_modules/@h-ai/ui/dist/**/*.{svelte,js,ts}";
190
- @source "../../../node_modules/@h-ai/ui/dist/**/*.{svelte,js,ts}";
191
-
192
- /* ─── DaisyUI 主题 ─── */
193
- @plugin "daisyui" {
194
- themes:
195
- light --default,
196
- dark --prefersdark,
197
- cupcake,
198
- emerald,
199
- corporate,
200
- nord,
201
- dracula,
202
- night,
203
- dim,
204
- business,
205
- sunset;
206
- }
207
-
208
- /* ─── 图标(可选) ─── */
209
- @plugin "@iconify/tailwind4" {
210
- prefixes: tabler;
211
- }
212
- ```
213
-
214
- > **关键**:`@source` 行让 TailwindCSS 扫描 `@h-ai/ui` 组件中使用的 class 名,否则组件样式会丢失。路径指向 npm 安装目录下的 `dist/`。
215
-
216
- ### 5. app.html 防闪烁脚本
217
-
218
- ```html
219
- <!doctype html>
220
- <html lang="%lang%">
221
- <head>
222
- <meta charset="utf-8" />
223
- <meta name="viewport" content="width=device-width, initial-scale=1" />
224
- <script>
225
- // 防止主题切换闪烁:在 DOM 渲染前应用已保存的主题
226
- (function(){var t='light';try{var s=localStorage.getItem('theme');if(s)t=s}catch{}document.documentElement.setAttribute('data-theme',t)})()
227
- </script>
228
- %sveltekit.head%
229
- </head>
230
- <body data-sveltekit-preload-data="hover">
231
- <div style="display: contents">%sveltekit.body%</div>
232
- </body>
233
- </html>
234
- ```
235
-
236
- ### 6. 平台检测
237
-
238
- ```typescript
239
- import { detectPlatform, isMobile, isNativeApp, usePlatform } from '@h-ai/ui'
240
-
241
- // 一次性检测
242
- const platform = detectPlatform() // 'ios' | 'android' | 'web'
243
- const mobile = isMobile() // boolean
244
- const native = isNativeApp() // boolean(Capacitor 环境)
245
-
246
- // Svelte 5 响应式(组件中使用)
247
- const p = usePlatform()
248
- // p.platform / p.isMobile / p.isNative
249
- ```
250
-
251
- ---
252
-
253
- ## 三层组件架构
254
-
255
- ### 原子组件(Primitives,20 个)
256
-
257
- | 组件 | Props 要点 | 说明 |
258
- | ------------ | ------------------------------------------------------------- | -------- |
259
- | `Button` | `variant`, `size`, `loading`, `disabled`, `outline`, `circle` | 按钮 |
260
- | `IconButton` | `icon: trusted SVG string \| Snippet`, `tooltip`, `variant`, `size` | 图标按钮 |
261
- | `Input` | `value`, `type`, `size`, `error`, `placeholder` | 输入框 |
262
- | `Textarea` | `value`, `rows`, `autoResize`, `error` | 文本域 |
263
- | `Select` | `value`, `options: SelectOption[]`, `placeholder` | 下拉选择 |
264
- | `Checkbox` | `checked`, `label`, `indeterminate` | 复选框 |
265
- | `Switch` | `checked`, `label`, `size` | 开关 |
266
- | `Radio` | `value`, `options`, `direction` | 单选组 |
267
- | `Range` | `value`, `min`, `max`, `step`, `variant`, `size` | 滑块 |
268
- | `Rating` | `value`, `max` | 评分 |
269
- | `Badge` | `variant`, `size`, `outline` | 徽标 |
270
- | `Avatar` | `src`, `name`, `size`, `shape` | 头像 |
271
- | `Tag` | `text`, `variant`, `closable` | 标签 |
272
- | `Spinner` | `size`, `variant` | 加载动画 |
273
- | `Progress` | `value`, `max`, `striped`, `animated` | 进度条 |
274
-
275
- ### 组合组件(Compounds,36 个)
276
-
277
- 由原子组件 + Bits UI headless 交互组合。
278
-
279
- #### 桌面端组合组件
280
-
281
- | 组件 | Props 要点 | 说明 |
282
- | ------------ | ------------------------------------------------------------------ | ------------- |
283
- | `Form` | `loading`, `disabled`, `onsubmit` | 表单容器 |
284
- | `FormField` | `label`, `name`, `error`, `hint`, `required` | 表单字段 |
285
- | `Modal` | `open`, `title`, `size`, `closeOnBackdrop` | 模态框 |
286
- | `Drawer` | `open`, `position`, `size`, `width`, `resizable`, `widthStorageKey` | 可选拖动并记忆宽度的抽屉 |
287
- | `DataTable` | `data`, `columns`, `keyField`, `sortKey`, `sortDir`, `onsort`, snippet slots | 数据表格(列定义 `sortable` 可排序) |
288
- | `Combobox` | `options`, `value`, `multiple`, `placeholder`, `error`, `onchange` | 可搜索选择 |
289
- | `Calendar` | `value`, `minValue`, `maxValue` | 独立日历 |
290
- | `DatePicker` | `value`, `minValue`, `maxValue`, `error` | 日期输入+弹出 |
291
- | `Tabs` | `items: TabItem[]`, `active`, `type` | 标签页 |
292
- | `Pagination` | `page`, `total`, `pageSize`, `showTotal`, `showJumper`, `showSizeChanger`, `showPageInfo`, `showFirstLast`, `onchange` | 分页(统一为 shadcn table 风格) |
293
- | `Dropdown` | `items: DropdownItem[]`, `trigger` | 下拉菜单 |
294
- | `Accordion` | `items: AccordionItem[]` | 折叠面板 |
295
- | `Skeleton` | `variant`, `count`, `animation` | 骨架屏 |
296
- | `Empty` | `title`, `description`, `icon` | 空状态 |
297
-
298
- #### 移动端组合组件(7 个)
299
-
300
- | 组件 | Props 要点 | 说明 |
301
- | ---------------- | ----------------------------------------------------------------------------- | ---------------- |
302
- | `SafeArea` | `top`, `bottom`, `left`, `right` | 安全区域容器 |
303
- | `AppBar` | `title`, `backHref`, `onback`, `fixed`, `transparent`, snippet `left`/`right` | 顶部导航栏 |
304
- | `BottomNav` | `items: BottomNavItem[]`, `active` | 底部导航栏 |
305
- | `ActionSheet` | `open`, `title`, `items: ActionSheetItem[]`, `cancelText`, `onselect` | 底部弹出操作面板 |
306
- | `PullRefresh` | `refreshing`, `onrefresh`, `threshold`, `pullText`, `releaseText` | 下拉刷新 |
307
- | `InfiniteScroll` | `loading`, `finished`, `threshold`, `onload`, `loadingText`, `finishedText` | 无限滚动加载 |
308
- | `SwipeCell` | `leftActions`, `rightActions: SwipeCellAction[]`, `threshold` | 滑动操作单元格 |
309
-
310
- **移动端组件用法示例**:
311
-
312
- ```svelte
313
- <script lang="ts">
314
- import type { BottomNavItem } from '@h-ai/ui'
315
-
316
- const navItems: BottomNavItem[] = [
317
- { key: 'home', label: '首页', icon: 'tabler:home', href: '/' },
318
- { key: 'discover', label: '发现', icon: 'tabler:compass', href: '/discover' },
319
- { key: 'profile', label: '我的', icon: 'tabler:user', href: '/profile' },
320
- ]
321
- </script>
322
-
323
- <SafeArea top bottom>
324
- <AppBar title="首页" />
325
- <PullRefresh bind:refreshing onrefresh={loadData}>
326
- <main class="p-4">
327
- <!-- 页面内容 -->
328
- </main>
329
- </PullRefresh>
330
- <BottomNav items={navItems} active="home" />
331
- </SafeArea>
332
- ```
333
-
334
- **ActionSheet 用法**:
335
-
336
- ```svelte
337
- <script lang="ts">
338
- import type { ActionSheetItem } from '@h-ai/ui'
339
-
340
- let showActions = $state(false)
341
- const actions: ActionSheetItem[] = [
342
- { key: 'camera', label: '拍照' },
343
- { key: 'album', label: '从相册选择' },
344
- { key: 'delete', label: '删除', destructive: true },
345
- ]
346
- </script>
347
-
348
- <ActionSheet bind:open={showActions} title="选择操作" items={actions} onselect={handleAction} />
349
- ```
350
-
351
- **SwipeCell 用法**:
352
-
353
- ```svelte
354
- <script lang="ts">
355
- import type { SwipeCellAction } from '@h-ai/ui'
356
-
357
- const rightActions: SwipeCellAction[] = [
358
- { key: 'edit', label: '编辑', color: '#3b82f6' },
359
- { key: 'delete', label: '删除', color: '#ef4444' },
360
- ]
361
- </script>
362
-
363
- <SwipeCell {rightActions} onaction={handleSwipeAction}>
364
- <div class="p-4">列表项内容</div>
365
- </SwipeCell>
366
- ```
367
-
368
- ### 场景组件(Scenes)
369
-
370
- 内置中英文翻译的业务场景组件。
371
-
372
- #### IAM 场景组件
373
-
374
- | 组件 | Props 要点 | 说明 |
375
- | -------------- | ----------------------------------------------- | -------- |
376
- | `AuthShell` | `variant`('card'/'split'), `title`, `brandTitle`, `brandText`, `illustration`, `description`, `highlights` | 认证页布局(包裹登录/注册表单) |
377
- | `LoginForm` | `showRememberMe`, `showRegisterLink`, `errors` | 登录表单 |
378
- | `RegisterForm` | `fields`, `minPasswordLength`, `errors` | 注册表单 |
379
- | `UserProfile` | `user`, `editable`, `fields`, `avatarUploadUrl` | 用户资料 |
380
-
381
- #### 错误页 / 设置场景组件
382
-
383
- | 组件 | Props 要点 | 说明 |
384
- | ---------------- | ------------------------------------------- | -------- |
385
- | `ErrorPage` | `status`, `code`, `title`, `description`, `homeUrl`, `onhome`, `onback` | 通用错误页(内置 401/403/404/500/503) |
386
- | `SettingsLayout` | `title`, `description`, `sections`, `active`, `onselect` | 设置页分区导航布局 |
387
-
388
- #### Storage 场景组件
389
-
390
- | 组件 | Props 要点 | 说明 |
391
- | ------------- | ---------------------------------------------- | -------- |
392
- | `FileUpload` | `accept`, `maxSize`, `uploadHandler`, `autoUpload` | 文件上传 |
393
- | `ImageUpload` | `value`, `uploadHandler`, `aspectRatio` | 图片上传 |
394
- | `AvatarUpload` | `value`, `uploadHandler`, `size`, `fallback` | 头像上传 |
395
- | `FileList` | `files: FileItem[]`, `layout`, `showPreview` | 文件列表 |
396
-
397
- 上传协议属于应用 service:组件通过 `uploadHandler(file, { signal, onProgress })` 注入实现,并接收 `{ url?, response? }`。不要把 presign、认证头或 PUT/POST 细节塞进 UI 组件;图片与头像 handler 必须返回安全的 `url`。未提供 handler 时组件只负责文件选择或本地预览。
398
-
399
- #### AI 场景组件
400
-
401
- | 组件 | 说明 |
402
- | -------------------- | --------------------------------- |
403
- | `MarkdownRenderer` | Markdown 渲染(内置 Shiki 高亮,支持 `fontSize` / `allowHtmlTags`) |
404
- | `AiDocumentDownloadMenu` | AI 文档下载菜单 |
405
- | `AiDocumentEditor` | AI 文档编辑器(支持 Mermaid、受控代码预览,以及 `fontSize` / `allowHtmlTags`) |
406
- | `AiTableEditor` | AI 表格编辑器 |
407
-
408
- > AI 场景组件使用 Shiki(纯 ESM)进行代码高亮,支持 27 种语言,通过 CSS 变量 `--hai-hl-*` 自定义颜色。无需额外安装 Shiki,已内置。`AiDocumentEditor` 默认只允许 Markdown 内置预览;HTML / JS / CSS 等高风险预览需要显式启用 `allowUnsafeCodePreview`,或通过 `oncoderun` 返回受控的预览结果。
409
- >
410
- > Mermaid 开箱即用:
411
- > - `sourceKind='document'` 时,文档中的 ```` ```mermaid ```` 代码块会在阅读态自动渲染为图表;
412
- > - `sourceKind='code'` + `showCodePreviewToggle` 时,可在「代码 / 预览」之间切换查看 Mermaid 图表;
413
- > - Mermaid 以 `securityLevel: 'strict'` 渲染为消毒后的 SVG,无需开启 `allowUnsafeCodePreview`。
414
- >
415
- > 展示层还支持:
416
- > - `fontSize`:支持 `number`(按 px)或 CSS 长度字符串(如 `1.125rem`)
417
- > - `allowHtmlTags`:默认关闭;开启后按安全白名单解析 `<b>` / `<i>` / `<u>` / `<mark>` 等标签,危险标签与属性仍会被消毒
418
-
419
- ```svelte
420
- <MarkdownRenderer content={markdown} fontSize='1.125rem' allowHtmlTags />
421
-
422
- <AiDocumentEditor
423
- title="方案文档"
424
- content={documentMarkdown}
425
- fontSize={18}
426
- allowHtmlTags
427
- showToolbar
428
- showOutline={false}
429
- />
430
- ```
431
-
432
- #### Charts 图表
433
-
434
- `Chart type='line'` 默认使用 LayerChart 原生折线图;监控看板类场景需要“分段线 + 圆点 + 最近点 hover + 竖向参考线”时,使用 `lineVariant='segmented-point'`:
435
-
436
- ```svelte
437
- <Chart
438
- type='line'
439
- data={trendData}
440
- x='label'
441
- y={['rateLimit', 'circuitBreak']}
442
- series={trendSeries}
443
- lineVariant='segmented-point'
444
- tooltipMode='nearest'
445
- showCrosshair
446
- legend
447
- grid
448
- />
449
- ```
450
-
451
- #### CRUD 场景组件
452
-
453
- | 组件 | 说明 |
454
- | ------------------- | ---- |
455
- | `CrudPage` | CRUD 主页面 |
456
- | `CrudFilterBar` | 过滤工具栏 |
457
- | `CrudDetailPanel` | 详情面板(抽屉/弹窗) |
458
- | `CrudEditPanel` | 编辑面板(抽屉/弹窗) |
459
- | `CrudDeleteConfirm` | 删除确认框 |
460
-
461
- `CrudPage` 是首选入口;只有在你明确要自定义组合方式时,才直接使用 `CrudFilterBar` / `CrudDetailPanel` / `CrudEditPanel`。
462
-
463
- ### CrudPage 配置重点
464
-
465
- | 配置项 | 说明 |
466
- | --- | --- |
467
- | `form.variant` | `'drawer'`(抽屉,默认)或 `'modal'`(弹出窗口) |
468
- | `form.drawerSize` / `form.drawerWidth` / `form.drawerResizable` | 抽屉尺寸预设 / 自定义 CSS 宽度 / 是否允许拖动并按资源记忆宽度(默认允许) |
469
- | `form.modalSize` / `form.modalWidth` / `form.modalHeight` | 弹窗尺寸预设 / 自定义宽高 |
470
- | `pagination.showSizeChanger` | 每页条数选择器(默认开启) |
471
- | `pagination.pageSizeOptions` | 每页条数候选项(默认 `[10, 20, 50, 100]`) |
472
- | `pagination.showJumper` / `pagination.showTotal` | 跳页输入 / 总数(默认开启) |
473
- | `pagination.showPageInfo` / `pagination.showFirstLast` | 页码文案 / 首页末页按钮(默认开启;紧凑视图可关闭) |
474
- | `density` | 列表密度:`'normal'`(默认)或 `'compact'`;仅影响列表行、行内操作、分页与创建/编辑/详情表单 |
475
- | `toolbarStyle` | `'toolbar'`(图标弹层,默认)或 `'filter-bar'`(平铺筛选栏) |
476
- | `showHeader` / `toolbarLeading` | 关闭默认页头并在工具栏左侧放置标题或说明 |
477
- | `toolbarActions` | 工具栏业务操作 snippet |
478
- | `card` | 卡片列表项渲染 snippet;仍复用分页和独立滚动容器 |
479
- | `detailColumns` | 点击后打开详情抽屉的列 key,例如 `['title']` |
480
- | `sortableColumns` | 可执行服务端排序的列;为空时使用全部列表列 |
481
- | `loading` / `loaded` / `error` / `onRetry` / `keepPreviousData` | 受控加载态:仅 `loaded && total===0` 显示空状态;首次显示查询中;失败显示错误+重试;`keepPreviousData`(默认 true)失败保留旧数据 |
482
-
483
- 注意:`CrudPage` 会占满父级可用高度;表格无论是否有数据都会撑满剩余空间,仅数据区滚动,表头和分页栏固定。
484
-
485
- ### CrudPage 推荐用法
486
-
487
- ```svelte
488
- <CrudPage
489
- crud={roleCrud}
490
- {data}
491
- permissions={{ create: true, update: true, delete: true }}
492
- form={{ variant: 'modal', modalSize: 'lg' }}
493
- pagination={{ showSizeChanger: true, showJumper: true, pageSizeOptions: [10, 20, 50] }}
494
- density='compact'
495
- detailColumns={['name']}
496
- sortableColumns={[{ key: 'createdAt', label: '创建时间' }]}
497
- {nav}
498
- />
499
- ```
500
-
501
- 如果想维持侧边编辑体验,可改成:
502
-
503
- ```svelte
504
- form={{ variant: 'drawer', drawerWidth: '40rem' }}
505
- ```
506
-
507
- 抽屉默认可拖动左侧边缘调整宽度,并按 `crud.resource.name` 记忆;传 `drawerResizable: false` 可关闭。
508
-
509
- ### 纯客户端控制器与惰性页签
510
-
511
- - 无 SvelteKit SSR 时用 `defineCrud` + `createCrudController` 托管 `data` / `nav`:latest-wins(seq + AbortSignal)、失败保留旧数据、并发去重、查询串回填地址栏。`<CrudPage data={c.data} nav={c.nav} loading={c.loading} loaded={c.loaded} error={c.error} onRetry={c.reload} />`。
512
- - `Tabs` 传 `lazy` 后未激活页签不渲染(`children` 提供 `isActivated(key)`),`onactivate(key)` 首次激活触发一次;配合 `createCrudController({ autoLoad: false })` 在页签首次可见时才 `load()`。
513
- - Toast 已内置 `notifySuccess` / `notifyError(err, fallback?)` / `notifyInfo` / `notifyWarning`,业务应用无需自建 toast 工具文件。
514
-
515
- ---
516
-
517
- ## Design Token 系统
518
-
519
- ### theme.css — Tailwind v4 `@theme` Token
520
-
521
- 通过 `@import '@h-ai/ui/styles/theme.css'` 导入,提供全局设计 Token:
522
-
523
- ```css
524
- @theme {
525
- --color-brand: oklch(0.6 0.2 275);
526
- --shadow-xs / --shadow-soft / --shadow-lifted / --shadow-float / --shadow-overlay
527
- --ease-out-expo / --ease-in-out
528
- --font-feature-tabular: 'tnum';
529
- }
530
- ```
531
-
532
- 应用可在导入后追加自己的 `@theme` 块覆盖或扩展。
533
-
534
- ### design-tokens.css — CSS 自定义属性
535
-
536
- ```css
537
- --hai-spacing-xs: 4px; --hai-spacing-sm: 8px;
538
- --hai-spacing-md: 16px; --hai-spacing-lg: 24px;
539
- --hai-radius-sm: 4px; --hai-radius-md: 8px;
540
- --hai-touch-target-min: 44px;
541
- --hai-safe-area-top: env(safe-area-inset-top);
542
- --hai-z-dropdown: 1000; --hai-z-modal: 2000; --hai-z-toast: 3000;
543
- --hai-transition-fast: 150ms ease;
544
- --hai-transition-normal: 250ms ease;
545
- ```
546
-
547
- ### mobile.css 提供的全局类
548
-
549
- | 类名 | 用途 |
550
- | ----------------------- | ------------------------------- |
551
- | `.hai-safe-top` | 上方安全区域 padding |
552
- | `.hai-safe-bottom` | 下方安全区域 padding |
553
- | `.hai-safe-all` | 四周安全区域 padding |
554
- | `.hai-scroll-container` | 优化的滚动容器(momentum 滚动) |
555
- | `.hai-keyboard-aware` | 虚拟键盘弹起时自动调整内容 |
556
-
557
- ---
558
-
559
- ## 主题系统
560
-
561
- 支持 15 个精选 DaisyUI 主题。
562
-
563
- ```typescript
564
- import { applyTheme, getCurrentTheme, isDarkTheme, THEMES, THEME_GROUPS } from '@h-ai/ui'
565
-
566
- applyTheme('dark') // 应用主题(自动持久化 localStorage)
567
- getCurrentTheme() // 获取当前主题名
568
- isDarkTheme('dracula') // 检查是否暗色主题
569
- ```
570
-
571
- ---
572
-
573
- ## 代码高亮(Shiki)
574
-
575
- AI 场景组件(`MarkdownRenderer`、`AiDocumentEditor`)内置 Shiki 代码高亮(纯 ESM,支持 Vite SSR/Client 双模式)。
576
-
577
- ### 支持语言(27 种)
578
-
579
- typescript, javascript, python, java, go, rust, c, cpp, csharp, ruby, php, swift, kotlin, sql, html, css, json, yaml, toml, markdown, bash, shell, powershell, dockerfile, xml, graphql, plaintext
580
-
581
- ### 自定义高亮颜色
582
-
583
- 通过 CSS 变量覆盖(在 `app.css` 或组件作用域内):
584
-
585
- ```css
586
- :root {
587
- --hai-hl-keyword: #c586c0;
588
- --hai-hl-string: #ce9178;
589
- --hai-hl-comment: #6a9955;
590
- --hai-hl-function: #dcdcaa;
591
- --hai-hl-variable: #9cdcfe;
592
- --hai-hl-type: #4ec9b0;
593
- --hai-hl-number: #b5cea8;
594
- --hai-hl-operator: #d4d4d4;
595
- --hai-hl-punctuation: #808080;
596
- --hai-hl-foreground: #d4d4d4;
597
- --hai-hl-background: #1e1e1e;
598
- }
599
- ```
600
-
601
- ---
602
-
603
- ## 重要约定
604
-
605
- 1. **Svelte 5 Runes**:使用 `$state`、`$derived`、`$effect`
606
- 2. **Snippet 插槽**:使用 `{#snippet name()}...{/snippet}` 语法
607
- 3. **自动导入例外**:`toast`、类型导入与 `Range` 必须显式 `import`;其余公开 Svelte 组件可自动导入
608
- 4. **Combobox 统一单选/多选**:`MultiSelect` 已删除
609
- 5. **移动端样式**:务必引入 `design-tokens.css` + `mobile.css`,使用 SafeArea 包裹原生 App 页面
610
- 6. **`@source` 必须配置**:未配置则 TailwindCSS 无法扫描 `@h-ai/ui` 组件中的 class,样式会丢失
611
- 7. **`ssr.noExternal`**:Vite SSR 需要将 `@h-ai/*` 包纳入处理,否则 SSR 时 Svelte 组件无法正确编译
612
- 8. **data-* 属性透传**:公开 Svelte 组件会把调用方传入的 `data-*` 属性透传到根节点或主交互节点;测试和自动化优先直接使用 `data-testid`、`data-analytics-id`,不要为测试 ID 重复封装组件
613
-
614
- ---
615
-
616
- ## 导出路径
617
-
618
- | 路径 | 用途 |
619
- | --------------------------- | -------------------------------------- |
620
- | `@h-ai/ui` | 主入口:所有组件、工具函数、类型 |
621
- | `@h-ai/ui/auto-import` | Svelte 预处理器:组件自动导入 |
622
- | `@h-ai/ui/components/*` | 按路径引用单个组件 |
623
- | `@h-ai/ui/styles/global.css` | 全局基础样式(重置/滚动条/焦点) |
624
- | `@h-ai/ui/styles/theme.css` | Tailwind v4 `@theme` Token |
625
- | `@h-ai/ui/styles/design-tokens.css`| CSS 自定义属性(间距/圆角/z-index) |
626
- | `@h-ai/ui/styles/mobile.css` | 移动端优化(安全区域/触摸/键盘) |
627
-
628
- ---
629
-
630
- ## 相关 Skills
631
-
632
- - `hai-kit`:SvelteKit 集成(hooks.server.ts、API 端点、认证守卫)
633
- - `hai-iam`:IAM 模块 API(与 LoginForm/RegisterForm 配合)
634
- - `hai-capacitor`:原生 App 开发(与 SafeArea/AppBar 配合)
635
- - `hai-api-client`:客户端数据获取
12
+ | 能力 | 使用 @h-ai/ui 构建 Svelte 5 表单、表格、弹窗、移动界面、主题与 AI 内容展示 |
13
+ | 适用场景 | 已有 Svelte 项目中的组件选择与交互实现 |
14
+ | 输入 | 现有 Svelte 页面、组件 Props、Tailwind 扫描路径与主题 |
15
+ | 输出 | 复用原子/组合/场景组件的界面及交互验证 |
16
+ | 限制 | 无 init/close;按公开导出使用组件。复用内置翻译;SSR 不直接访问浏览器全局,高风险代码预览须显式启用。 |
17
+
18
+ ## 使用路径
19
+
20
+ - 先检查组件导入、Tailwind @source 和主题 CSS,再选场景 → 组合 → 原子组件,缺能力才自定义。
21
+ - 应用只提供页面级文案;组件内部中英文由 @h-ai/ui 维护。
22
+ - AI 文本视为不可信;Markdown/Mermaid 预览与允许执行 HTML/JS 的预览有不同边界。
23
+
24
+ ## 按需参考
25
+
26
+ 详细配置、API 签名、错误码和范本在 [reference.md](reference.md)。按下列标题定位所需小节,不默认通读;用例中的业务变量需结合当前应用补齐。
27
+
28
+ - 运行环境
29
+ - 适用场景
30
+ - 使用边界
31
+ - AI 使用顺序(先判断,再落地)
32
+ - 项目配置(从 npm 安装)
33
+ - 三层组件架构
34
+ - Design Token 系统
35
+ - 主题系统
36
+ - 代码高亮(Shiki)
37
+ - 重要约定
38
+ - 导出路径
39
+ - 相关 Skills