@h-ai/cli 0.1.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.
- package/LICENSE +202 -0
- package/README.md +167 -0
- package/dist/chunk-2H7UOFLK.js +10 -0
- package/dist/chunk-2H7UOFLK.js.map +1 -0
- package/dist/chunk-LANIDJC7.js +659 -0
- package/dist/chunk-LANIDJC7.js.map +1 -0
- package/dist/chunk-YV7WPUI6.js +206 -0
- package/dist/chunk-YV7WPUI6.js.map +1 -0
- package/dist/config-templates-S5RI2MC6.js +5 -0
- package/dist/config-templates-S5RI2MC6.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1650 -0
- package/dist/index.js.map +1 -0
- package/dist/skill-templates-N5DU5FNX.js +5 -0
- package/dist/skill-templates-N5DU5FNX.js.map +1 -0
- package/dist/src-XJ6YXNAF.js +15030 -0
- package/dist/src-XJ6YXNAF.js.map +1 -0
- package/package.json +59 -0
- package/templates/README.md +126 -0
- package/templates/apps/admin/messages/en-US.json +33 -0
- package/templates/apps/admin/messages/zh-CN.json +33 -0
- package/templates/apps/admin/src/routes/+layout.svelte.hbs +30 -0
- package/templates/apps/admin/src/routes/+page.svelte.hbs +35 -0
- package/templates/apps/admin/src/routes/admin/+layout.svelte.hbs +44 -0
- package/templates/apps/admin/src/routes/admin/+page.svelte.hbs +45 -0
- package/templates/apps/admin/src/routes/admin/settings/+page.svelte.hbs +37 -0
- package/templates/apps/admin/src/routes/api/health/+server.ts +12 -0
- package/templates/apps/android-app/.env.hbs +3 -0
- package/templates/apps/android-app/capacitor.config.ts.hbs +12 -0
- package/templates/apps/android-app/messages/en-US.json +24 -0
- package/templates/apps/android-app/messages/zh-CN.json +24 -0
- package/templates/apps/android-app/src/lib/api.ts.hbs +30 -0
- package/templates/apps/android-app/src/lib/capacitor.ts +21 -0
- package/templates/apps/android-app/src/routes/+layout.svelte.hbs +42 -0
- package/templates/apps/android-app/src/routes/+layout.ts +7 -0
- package/templates/apps/android-app/src/routes/+page.svelte.hbs +27 -0
- package/templates/apps/api/src/routes/+layout.svelte +14 -0
- package/templates/apps/api/src/routes/+page.svelte +11 -0
- package/templates/apps/api/src/routes/api/v1/health/+server.ts +14 -0
- package/templates/apps/api/src/routes/api/v1/items/+server.ts +37 -0
- package/templates/apps/api/src/routes/api/v1/items/[id]/+server.ts +30 -0
- package/templates/apps/h5/messages/en-US.json +37 -0
- package/templates/apps/h5/messages/zh-CN.json +37 -0
- package/templates/apps/h5/src/routes/+layout.svelte.hbs +57 -0
- package/templates/apps/h5/src/routes/+page.svelte.hbs +27 -0
- package/templates/apps/h5/src/routes/discover/+page.svelte.hbs +27 -0
- package/templates/apps/h5/src/routes/profile/+page.svelte.hbs +27 -0
- package/templates/apps/website/messages/en-US.json +32 -0
- package/templates/apps/website/messages/zh-CN.json +32 -0
- package/templates/apps/website/src/routes/+layout.svelte.hbs +66 -0
- package/templates/apps/website/src/routes/+page.svelte.hbs +33 -0
- package/templates/apps/website/src/routes/about/+page.svelte.hbs +27 -0
- package/templates/apps/website/src/routes/api/health/+server.ts +12 -0
- package/templates/apps/website/src/routes/contact/+page.svelte.hbs +59 -0
- package/templates/apps/website/src/routes/services/+page.svelte.hbs +63 -0
- package/templates/base/e2e/helpers.ts +49 -0
- package/templates/base/package.json.hbs +67 -0
- package/templates/base/playwright.config.ts +32 -0
- package/templates/base/src/app.css +2 -0
- package/templates/base/src/app.d.ts.hbs +18 -0
- package/templates/base/src/app.html.hbs +16 -0
- package/templates/base/src/hooks.server.ts.hbs +123 -0
- package/templates/base/src/lib/server/init.ts.hbs +190 -0
- package/templates/base/svelte.config.js.hbs +30 -0
- package/templates/base/tsconfig.json +8 -0
- package/templates/base/vite.config.ts.hbs +27 -0
- package/templates/features/ai/routes/api/chat/+server.ts +26 -0
- package/templates/features/datapipe/routes/api/datapipe/pipeline/+server.ts +41 -0
- package/templates/features/iam/routes-admin/(auth)/+layout.svelte.hbs +21 -0
- package/templates/features/iam/routes-admin/(auth)/auth/login/+page.svelte.hbs +98 -0
- package/templates/features/iam/routes-admin/(auth)/auth/register/+page.svelte.hbs +124 -0
- package/templates/features/iam/routes-h5/auth/login/+page.svelte.hbs +98 -0
- package/templates/features/iam/routes-h5/auth/register/+page.svelte.hbs +114 -0
- package/templates/features/iam/routes-shared/api/auth/login/+server.ts +32 -0
- package/templates/features/iam/routes-shared/api/auth/logout/+server.ts +15 -0
- package/templates/features/iam/routes-shared/api/auth/me/+server.ts +12 -0
- package/templates/features/iam/routes-shared/api/auth/register/+server.ts +26 -0
- package/templates/features/payment/routes/api/v1/payment/create/+server.ts +30 -0
- package/templates/features/payment/routes/api/v1/payment/notify/[provider]/+server.ts +42 -0
- package/templates/features/payment/routes/api/v1/payment/query/[orderNo]/+server.ts +25 -0
- package/templates/features/storage/routes/api/upload/+server.ts +35 -0
- package/templates/features/vecdb/routes/api/vecdb/search/+server.ts +36 -0
- package/templates/i18n/project.inlang/settings.json +11 -0
- package/templates/skills/AGENTS.md +26 -0
- package/templates/skills/CLAUDE.md +12 -0
- package/templates/skills/copilot-instructions.md +61 -0
- package/templates/skills/hai-ai/SKILL.md +721 -0
- package/templates/skills/hai-api-client/SKILL.md +355 -0
- package/templates/skills/hai-app-create/SKILL.md +371 -0
- package/templates/skills/hai-app-review/SKILL.md +156 -0
- package/templates/skills/hai-app-tests/SKILL.md +468 -0
- package/templates/skills/hai-audit/SKILL.md +145 -0
- package/templates/skills/hai-build/SKILL.md +319 -0
- package/templates/skills/hai-cache/SKILL.md +190 -0
- package/templates/skills/hai-capacitor/SKILL.md +377 -0
- package/templates/skills/hai-core/SKILL.md +484 -0
- package/templates/skills/hai-crypto/SKILL.md +198 -0
- package/templates/skills/hai-datapipe/SKILL.md +220 -0
- package/templates/skills/hai-deploy/SKILL.md +216 -0
- package/templates/skills/hai-iam/SKILL.md +361 -0
- package/templates/skills/hai-kit/SKILL.md +484 -0
- package/templates/skills/hai-payment/SKILL.md +275 -0
- package/templates/skills/hai-reach/SKILL.md +315 -0
- package/templates/skills/hai-reldb/SKILL.md +465 -0
- package/templates/skills/hai-scheduler/SKILL.md +188 -0
- package/templates/skills/hai-storage/SKILL.md +276 -0
- package/templates/skills/hai-ui/SKILL.md +438 -0
- package/templates/skills/hai-vecdb/SKILL.md +279 -0
- package/templates/skills/opencode.json +11 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hai-ui
|
|
3
|
+
description: 使用 @h-ai/ui 构建多端应用界面,包含三层组件架构(原子/组合/场景)、DaisyUI 样式 + Bits UI headless 交互、移动端组件(SafeArea/BottomNav/PullRefresh/ActionSheet/SwipeCell/InfiniteScroll/AppBar)、Design Token 系统与平台检测;当需求涉及界面、表单、表格、移动端适配或主题切换时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# hai-ui
|
|
7
|
+
|
|
8
|
+
> `@h-ai/ui` 是基于 Svelte 5 Runes 的多端 UI 组件库,采用 DaisyUI v5 + Tailwind CSS v4 + Bits UI v2,支持 32 主题、内置中英文 i18n、自动导入。内置 Shiki 代码高亮、Design Token 系统和 7 个移动端组件。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 运行环境
|
|
13
|
+
|
|
14
|
+
> **浏览器端专用。** Svelte 组件在浏览器中渲染,服务端无需引用。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 适用场景
|
|
19
|
+
|
|
20
|
+
- 构建管理后台页面(表单、表格、弹窗、导航等)
|
|
21
|
+
- 移动端/App 界面开发(SafeArea、BottomNav、PullRefresh 等)
|
|
22
|
+
- 使用 Bits UI headless 交互组件(Combobox、DatePicker、Calendar)
|
|
23
|
+
- 使用 IAM 场景组件(登录/注册/密码/用户资料表单)
|
|
24
|
+
- 使用 Storage 场景组件(文件上传/图片上传/文件列表)
|
|
25
|
+
- 配置主题切换与 i18n 多语言
|
|
26
|
+
- 多端平台检测与适配
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 项目配置(从 npm 安装)
|
|
31
|
+
|
|
32
|
+
> 以下示例面向通过 `npm install @h-ai/ui` 引用发布包的项目。monorepo 内部使用 `workspace:*` 时路径略有不同。
|
|
33
|
+
|
|
34
|
+
### 1. 安装依赖
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 核心包
|
|
38
|
+
npm install @h-ai/ui
|
|
39
|
+
|
|
40
|
+
# 必须的对等依赖与构建工具
|
|
41
|
+
npm install -D svelte @sveltejs/kit @sveltejs/vite-plugin-svelte
|
|
42
|
+
npm install -D tailwindcss @tailwindcss/vite daisyui
|
|
43
|
+
|
|
44
|
+
# 图标(可选但推荐)
|
|
45
|
+
npm install -D @iconify/tailwind4 @iconify-json/tabler
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. svelte.config.js
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { autoImportHaiUi } from '@h-ai/ui/auto-import'
|
|
52
|
+
import adapter from '@sveltejs/adapter-auto'
|
|
53
|
+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
|
54
|
+
|
|
55
|
+
/** @type {import('@sveltejs/kit').Config} */
|
|
56
|
+
const config = {
|
|
57
|
+
// autoImportHaiUi 必须在 vitePreprocess 之前
|
|
58
|
+
preprocess: [autoImportHaiUi(), vitePreprocess()],
|
|
59
|
+
compilerOptions: {
|
|
60
|
+
runes: true, // 强制 Svelte 5 Runes 模式
|
|
61
|
+
},
|
|
62
|
+
kit: {
|
|
63
|
+
adapter: adapter(),
|
|
64
|
+
alias: {
|
|
65
|
+
$components: './src/lib/components',
|
|
66
|
+
$stores: './src/lib/stores',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default config
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. vite.config.ts
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { sveltekit } from '@sveltejs/kit/vite'
|
|
78
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
79
|
+
import { defineConfig } from 'vite'
|
|
80
|
+
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
plugins: [
|
|
83
|
+
sveltekit(),
|
|
84
|
+
tailwindcss(),
|
|
85
|
+
],
|
|
86
|
+
optimizeDeps: {
|
|
87
|
+
// bits-ui 使用 Svelte 虚拟模块,需排除预构建
|
|
88
|
+
exclude: ['bits-ui'],
|
|
89
|
+
},
|
|
90
|
+
ssr: {
|
|
91
|
+
// @h-ai 包为 ESM + Svelte 组件,需 Vite 在 SSR 时处理
|
|
92
|
+
noExternal: [/@h-ai\//],
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 4. src/app.css
|
|
98
|
+
|
|
99
|
+
```css
|
|
100
|
+
/* ─── Tailwind CSS v4 ─── */
|
|
101
|
+
@import 'tailwindcss';
|
|
102
|
+
|
|
103
|
+
/* ─── @h-ai/ui 共享样式 ─── */
|
|
104
|
+
@import '@h-ai/ui/styles/global.css'; /* 基础重置、滚动条、焦点样式 */
|
|
105
|
+
@import '@h-ai/ui/styles/theme.css'; /* Tailwind v4 @theme Token(品牌色/阴影/动效) */
|
|
106
|
+
|
|
107
|
+
/* ─── 移动端项目追加(可选) ─── */
|
|
108
|
+
@import '@h-ai/ui/styles/design-tokens.css'; /* CSS 自定义属性:间距/圆角/z-index */
|
|
109
|
+
@import '@h-ai/ui/styles/mobile.css'; /* 安全区域/触摸优化/键盘适配 */
|
|
110
|
+
|
|
111
|
+
/* ─── 扫描 @h-ai/ui 组件中使用的 Tailwind 类名 ─── */
|
|
112
|
+
@source "../node_modules/@h-ai/ui/dist/**/*.{svelte,ts}";
|
|
113
|
+
|
|
114
|
+
/* ─── DaisyUI 主题 ─── */
|
|
115
|
+
@plugin "daisyui" {
|
|
116
|
+
themes:
|
|
117
|
+
light --default,
|
|
118
|
+
dark --prefersdark,
|
|
119
|
+
cupcake,
|
|
120
|
+
emerald,
|
|
121
|
+
corporate,
|
|
122
|
+
nord,
|
|
123
|
+
dracula,
|
|
124
|
+
night,
|
|
125
|
+
dim,
|
|
126
|
+
business,
|
|
127
|
+
sunset;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ─── 图标(可选) ─── */
|
|
131
|
+
@plugin "@iconify/tailwind4" {
|
|
132
|
+
prefixes: tabler;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
> **关键**:`@source` 行让 TailwindCSS 扫描 `@h-ai/ui` 组件中使用的 class 名,否则组件样式会丢失。路径指向 npm 安装目录下的 `dist/`。
|
|
137
|
+
|
|
138
|
+
### 5. app.html 防闪烁脚本
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
<!doctype html>
|
|
142
|
+
<html lang="%lang%">
|
|
143
|
+
<head>
|
|
144
|
+
<meta charset="utf-8" />
|
|
145
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
146
|
+
<script>
|
|
147
|
+
// 防止主题切换闪烁:在 DOM 渲染前应用已保存的主题
|
|
148
|
+
(function(){var t=localStorage.getItem('hai-theme');if(t)document.documentElement.setAttribute('data-theme',t)})()
|
|
149
|
+
</script>
|
|
150
|
+
%sveltekit.head%
|
|
151
|
+
</head>
|
|
152
|
+
<body data-sveltekit-preload-data="hover">
|
|
153
|
+
<div style="display: contents">%sveltekit.body%</div>
|
|
154
|
+
</body>
|
|
155
|
+
</html>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 6. 平台检测
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { detectPlatform, isMobile, isNativeApp, usePlatform } from '@h-ai/ui'
|
|
162
|
+
|
|
163
|
+
// 一次性检测
|
|
164
|
+
const platform = detectPlatform() // 'ios' | 'android' | 'web'
|
|
165
|
+
const mobile = isMobile() // boolean
|
|
166
|
+
const native = isNativeApp() // boolean(Capacitor 环境)
|
|
167
|
+
|
|
168
|
+
// Svelte 5 响应式(组件中使用)
|
|
169
|
+
const p = usePlatform()
|
|
170
|
+
// p.platform / p.isMobile / p.isNative
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 三层组件架构
|
|
176
|
+
|
|
177
|
+
### 原子组件(Primitives,21 个)
|
|
178
|
+
|
|
179
|
+
| 组件 | Props 要点 | 说明 |
|
|
180
|
+
| ------------ | ------------------------------------------------------------- | -------- |
|
|
181
|
+
| `Button` | `variant`, `size`, `loading`, `disabled`, `outline`, `circle` | 按钮 |
|
|
182
|
+
| `IconButton` | `icon: string \| Snippet`, `tooltip`, `variant`, `size` | 图标按钮 |
|
|
183
|
+
| `Input` | `value`, `type`, `size`, `error`, `placeholder` | 输入框 |
|
|
184
|
+
| `Textarea` | `value`, `rows`, `autoResize`, `error` | 文本域 |
|
|
185
|
+
| `Select` | `value`, `options: SelectOption[]`, `placeholder` | 下拉选择 |
|
|
186
|
+
| `Checkbox` | `checked`, `label`, `indeterminate` | 复选框 |
|
|
187
|
+
| `Switch` | `checked`, `label`, `size` | 开关 |
|
|
188
|
+
| `Radio` | `value`, `options`, `direction` | 单选组 |
|
|
189
|
+
| `Range` | `value`, `min`, `max`, `step`, `variant`, `size` | 滑块 |
|
|
190
|
+
| `Rating` | `value`, `max` | 评分 |
|
|
191
|
+
| `Badge` | `variant`, `size`, `outline` | 徽标 |
|
|
192
|
+
| `Avatar` | `src`, `name`, `size`, `shape` | 头像 |
|
|
193
|
+
| `Tag` | `text`, `variant`, `closable` | 标签 |
|
|
194
|
+
| `Spinner` | `size`, `variant` | 加载动画 |
|
|
195
|
+
| `Progress` | `value`, `max`, `striped`, `animated` | 进度条 |
|
|
196
|
+
|
|
197
|
+
### 组合组件(Compounds,25 + 7 移动端)
|
|
198
|
+
|
|
199
|
+
由原子组件 + Bits UI headless 交互组合。
|
|
200
|
+
|
|
201
|
+
#### 桌面端组合组件
|
|
202
|
+
|
|
203
|
+
| 组件 | Props 要点 | 说明 |
|
|
204
|
+
| ------------ | ------------------------------------------------------------------ | ------------- |
|
|
205
|
+
| `Form` | `loading`, `disabled`, `onsubmit` | 表单容器 |
|
|
206
|
+
| `FormField` | `label`, `name`, `error`, `hint`, `required` | 表单字段 |
|
|
207
|
+
| `Modal` | `open`, `title`, `size`, `closeOnBackdrop` | 模态框 |
|
|
208
|
+
| `Drawer` | `open`, `position`, `size` | 抽屉 |
|
|
209
|
+
| `DataTable` | `data`, `columns`, `keyField`, snippet slots | 数据表格 |
|
|
210
|
+
| `Combobox` | `options`, `value`, `multiple`, `placeholder`, `error`, `onchange` | 可搜索选择 |
|
|
211
|
+
| `Calendar` | `value`, `minValue`, `maxValue` | 独立日历 |
|
|
212
|
+
| `DatePicker` | `value`, `minValue`, `maxValue`, `error` | 日期输入+弹出 |
|
|
213
|
+
| `Tabs` | `items: TabItem[]`, `active`, `type` | 标签页 |
|
|
214
|
+
| `Pagination` | `page`, `total`, `pageSize`, `onchange` | 分页 |
|
|
215
|
+
| `Dropdown` | `items: DropdownItem[]`, `trigger` | 下拉菜单 |
|
|
216
|
+
| `Accordion` | `items: AccordionItem[]` | 折叠面板 |
|
|
217
|
+
| `Skeleton` | `variant`, `count`, `animation` | 骨架屏 |
|
|
218
|
+
| `Empty` | `title`, `description`, `icon` | 空状态 |
|
|
219
|
+
|
|
220
|
+
#### 移动端组合组件(7 个)
|
|
221
|
+
|
|
222
|
+
| 组件 | Props 要点 | 说明 |
|
|
223
|
+
| ---------------- | ----------------------------------------------------------------------------- | ---------------- |
|
|
224
|
+
| `SafeArea` | `top`, `bottom`, `left`, `right` | 安全区域容器 |
|
|
225
|
+
| `AppBar` | `title`, `backHref`, `onback`, `fixed`, `transparent`, snippet `left`/`right` | 顶部导航栏 |
|
|
226
|
+
| `BottomNav` | `items: BottomNavItem[]`, `active` | 底部导航栏 |
|
|
227
|
+
| `ActionSheet` | `open`, `title`, `items: ActionSheetItem[]`, `cancelText`, `onselect` | 底部弹出操作面板 |
|
|
228
|
+
| `PullRefresh` | `refreshing`, `onrefresh`, `threshold`, `pullText`, `releaseText` | 下拉刷新 |
|
|
229
|
+
| `InfiniteScroll` | `loading`, `finished`, `threshold`, `onload`, `loadingText`, `finishedText` | 无限滚动加载 |
|
|
230
|
+
| `SwipeCell` | `leftActions`, `rightActions: SwipeCellAction[]`, `threshold` | 滑动操作单元格 |
|
|
231
|
+
|
|
232
|
+
**移动端组件用法示例**:
|
|
233
|
+
|
|
234
|
+
```svelte
|
|
235
|
+
<script lang="ts">
|
|
236
|
+
import type { BottomNavItem } from '@h-ai/ui'
|
|
237
|
+
|
|
238
|
+
const navItems: BottomNavItem[] = [
|
|
239
|
+
{ key: 'home', label: '首页', icon: 'tabler:home', href: '/' },
|
|
240
|
+
{ key: 'discover', label: '发现', icon: 'tabler:compass', href: '/discover' },
|
|
241
|
+
{ key: 'profile', label: '我的', icon: 'tabler:user', href: '/profile' },
|
|
242
|
+
]
|
|
243
|
+
</script>
|
|
244
|
+
|
|
245
|
+
<SafeArea top bottom>
|
|
246
|
+
<AppBar title="首页" />
|
|
247
|
+
<PullRefresh bind:refreshing onrefresh={loadData}>
|
|
248
|
+
<main class="p-4">
|
|
249
|
+
<!-- 页面内容 -->
|
|
250
|
+
</main>
|
|
251
|
+
</PullRefresh>
|
|
252
|
+
<BottomNav items={navItems} active="home" />
|
|
253
|
+
</SafeArea>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**ActionSheet 用法**:
|
|
257
|
+
|
|
258
|
+
```svelte
|
|
259
|
+
<script lang="ts">
|
|
260
|
+
import type { ActionSheetItem } from '@h-ai/ui'
|
|
261
|
+
|
|
262
|
+
let showActions = $state(false)
|
|
263
|
+
const actions: ActionSheetItem[] = [
|
|
264
|
+
{ key: 'camera', label: '拍照' },
|
|
265
|
+
{ key: 'album', label: '从相册选择' },
|
|
266
|
+
{ key: 'delete', label: '删除', destructive: true },
|
|
267
|
+
]
|
|
268
|
+
</script>
|
|
269
|
+
|
|
270
|
+
<ActionSheet bind:open={showActions} title="选择操作" items={actions} onselect={handleAction} />
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**SwipeCell 用法**:
|
|
274
|
+
|
|
275
|
+
```svelte
|
|
276
|
+
<script lang="ts">
|
|
277
|
+
import type { SwipeCellAction } from '@h-ai/ui'
|
|
278
|
+
|
|
279
|
+
const rightActions: SwipeCellAction[] = [
|
|
280
|
+
{ key: 'edit', label: '编辑', color: '#3b82f6' },
|
|
281
|
+
{ key: 'delete', label: '删除', color: '#ef4444' },
|
|
282
|
+
]
|
|
283
|
+
</script>
|
|
284
|
+
|
|
285
|
+
<SwipeCell {rightActions} onaction={handleSwipeAction}>
|
|
286
|
+
<div class="p-4">列表项内容</div>
|
|
287
|
+
</SwipeCell>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### 场景组件(Scenes)
|
|
291
|
+
|
|
292
|
+
内置中英文翻译的业务场景组件。
|
|
293
|
+
|
|
294
|
+
#### IAM 场景组件
|
|
295
|
+
|
|
296
|
+
| 组件 | Props 要点 | 说明 |
|
|
297
|
+
| -------------- | ----------------------------------------------- | -------- |
|
|
298
|
+
| `LoginForm` | `showRememberMe`, `showRegisterLink`, `errors` | 登录表单 |
|
|
299
|
+
| `RegisterForm` | `fields`, `minPasswordLength`, `errors` | 注册表单 |
|
|
300
|
+
| `UserProfile` | `user`, `editable`, `fields`, `avatarUploadUrl` | 用户资料 |
|
|
301
|
+
|
|
302
|
+
#### Storage 场景组件
|
|
303
|
+
|
|
304
|
+
| 组件 | Props 要点 | 说明 |
|
|
305
|
+
| ------------- | ---------------------------------------------- | -------- |
|
|
306
|
+
| `FileUpload` | `accept`, `maxSize`, `uploadUrl`, `autoUpload` | 文件上传 |
|
|
307
|
+
| `ImageUpload` | `value`, `uploadUrl`, `aspectRatio` | 图片上传 |
|
|
308
|
+
| `FileList` | `files: FileItem[]`, `layout`, `showPreview` | 文件列表 |
|
|
309
|
+
|
|
310
|
+
#### AI 场景组件
|
|
311
|
+
|
|
312
|
+
| 组件 | 说明 |
|
|
313
|
+
| -------------------- | --------------------------------- |
|
|
314
|
+
| `MarkdownRenderer` | Markdown 渲染(内置 Shiki 高亮) |
|
|
315
|
+
| `AiDocumentEditor` | AI 文档编辑器 |
|
|
316
|
+
|
|
317
|
+
> AI 场景组件使用 Shiki(纯 ESM)进行代码高亮,支持 27 种语言,通过 CSS 变量 `--hai-hl-*` 自定义颜色。无需额外安装 Shiki,已内置。
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Design Token 系统
|
|
322
|
+
|
|
323
|
+
### theme.css — Tailwind v4 `@theme` Token
|
|
324
|
+
|
|
325
|
+
通过 `@import '@h-ai/ui/styles/theme.css'` 导入,提供全局设计 Token:
|
|
326
|
+
|
|
327
|
+
```css
|
|
328
|
+
@theme {
|
|
329
|
+
--color-brand: oklch(0.6 0.2 275);
|
|
330
|
+
--shadow-xs / --shadow-soft / --shadow-lifted / --shadow-float / --shadow-overlay
|
|
331
|
+
--ease-out-expo / --ease-in-out
|
|
332
|
+
--font-feature-tabular: 'tnum';
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
应用可在导入后追加自己的 `@theme` 块覆盖或扩展。
|
|
337
|
+
|
|
338
|
+
### design-tokens.css — CSS 自定义属性
|
|
339
|
+
|
|
340
|
+
```css
|
|
341
|
+
--hai-spacing-xs: 4px; --hai-spacing-sm: 8px;
|
|
342
|
+
--hai-spacing-md: 16px; --hai-spacing-lg: 24px;
|
|
343
|
+
--hai-radius-sm: 4px; --hai-radius-md: 8px;
|
|
344
|
+
--hai-touch-target-min: 44px;
|
|
345
|
+
--hai-safe-area-top: env(safe-area-inset-top);
|
|
346
|
+
--hai-z-dropdown: 1000; --hai-z-modal: 2000; --hai-z-toast: 3000;
|
|
347
|
+
--hai-transition-fast: 150ms ease;
|
|
348
|
+
--hai-transition-normal: 250ms ease;
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### mobile.css 提供的全局类
|
|
352
|
+
|
|
353
|
+
| 类名 | 用途 |
|
|
354
|
+
| ----------------------- | ------------------------------- |
|
|
355
|
+
| `.hai-safe-top` | 上方安全区域 padding |
|
|
356
|
+
| `.hai-safe-bottom` | 下方安全区域 padding |
|
|
357
|
+
| `.hai-safe-all` | 四周安全区域 padding |
|
|
358
|
+
| `.hai-scroll-container` | 优化的滚动容器(momentum 滚动) |
|
|
359
|
+
| `.hai-keyboard-aware` | 虚拟键盘弹起时自动调整内容 |
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## 主题系统
|
|
364
|
+
|
|
365
|
+
支持 32 个 DaisyUI 主题。
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { applyTheme, getCurrentTheme, isDarkTheme, THEMES, THEME_GROUPS } from '@h-ai/ui'
|
|
369
|
+
|
|
370
|
+
applyTheme('dark') // 应用主题(自动持久化 localStorage)
|
|
371
|
+
getCurrentTheme() // 获取当前主题名
|
|
372
|
+
isDarkTheme('dracula') // 检查是否暗色主题
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## 代码高亮(Shiki)
|
|
378
|
+
|
|
379
|
+
AI 场景组件(`MarkdownRenderer`、`AiDocumentEditor`)内置 Shiki 代码高亮(纯 ESM,支持 Vite SSR/Client 双模式)。
|
|
380
|
+
|
|
381
|
+
### 支持语言(27 种)
|
|
382
|
+
|
|
383
|
+
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
|
|
384
|
+
|
|
385
|
+
### 自定义高亮颜色
|
|
386
|
+
|
|
387
|
+
通过 CSS 变量覆盖(在 `app.css` 或组件作用域内):
|
|
388
|
+
|
|
389
|
+
```css
|
|
390
|
+
:root {
|
|
391
|
+
--hai-hl-keyword: #c586c0;
|
|
392
|
+
--hai-hl-string: #ce9178;
|
|
393
|
+
--hai-hl-comment: #6a9955;
|
|
394
|
+
--hai-hl-function: #dcdcaa;
|
|
395
|
+
--hai-hl-variable: #9cdcfe;
|
|
396
|
+
--hai-hl-type: #4ec9b0;
|
|
397
|
+
--hai-hl-number: #b5cea8;
|
|
398
|
+
--hai-hl-operator: #d4d4d4;
|
|
399
|
+
--hai-hl-punctuation: #808080;
|
|
400
|
+
--hai-hl-foreground: #d4d4d4;
|
|
401
|
+
--hai-hl-background: #1e1e1e;
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## 重要约定
|
|
408
|
+
|
|
409
|
+
1. **Svelte 5 Runes**:使用 `$state`、`$derived`、`$effect`
|
|
410
|
+
2. **Snippet 插槽**:使用 `{#snippet name()}...{/snippet}` 语法
|
|
411
|
+
3. **自动导入例外**:`toast`、类型导入、`Range`/`FileList` 必须显式 `import`
|
|
412
|
+
4. **Combobox 统一单选/多选**:`MultiSelect` 已删除
|
|
413
|
+
5. **移动端样式**:务必引入 `design-tokens.css` + `mobile.css`,使用 SafeArea 包裹原生 App 页面
|
|
414
|
+
6. **`@source` 必须配置**:未配置则 TailwindCSS 无法扫描 `@h-ai/ui` 组件中的 class,样式会丢失
|
|
415
|
+
7. **`ssr.noExternal`**:Vite SSR 需要将 `@h-ai/*` 包纳入处理,否则 SSR 时 Svelte 组件无法正确编译
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## 导出路径
|
|
420
|
+
|
|
421
|
+
| 路径 | 用途 |
|
|
422
|
+
| --------------------------- | -------------------------------------- |
|
|
423
|
+
| `@h-ai/ui` | 主入口:所有组件、工具函数、类型 |
|
|
424
|
+
| `@h-ai/ui/auto-import` | Svelte 预处理器:组件自动导入 |
|
|
425
|
+
| `@h-ai/ui/components/*` | 按路径引用单个组件 |
|
|
426
|
+
| `@h-ai/ui/styles/global.css` | 全局基础样式(重置/滚动条/焦点) |
|
|
427
|
+
| `@h-ai/ui/styles/theme.css` | Tailwind v4 `@theme` Token |
|
|
428
|
+
| `@h-ai/ui/styles/design-tokens.css`| CSS 自定义属性(间距/圆角/z-index) |
|
|
429
|
+
| `@h-ai/ui/styles/mobile.css` | 移动端优化(安全区域/触摸/键盘) |
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 相关 Skills
|
|
434
|
+
|
|
435
|
+
- `hai-kit`:SvelteKit 集成(hooks.server.ts、API 端点、认证守卫)
|
|
436
|
+
- `hai-iam`:IAM 模块 API(与 LoginForm/RegisterForm 配合)
|
|
437
|
+
- `hai-capacitor`:原生 App 开发(与 SafeArea/AppBar 配合)
|
|
438
|
+
- `hai-api-client`:客户端数据获取
|