@h-ai/ui 0.1.0-alpha.67 → 0.1.0-alpha.68

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 (286) hide show
  1. package/README.en.md +31 -5
  2. package/README.ja.md +31 -5
  3. package/README.md +64 -38
  4. package/dist/components/compounds/Accordion.svelte +24 -0
  5. package/dist/components/compounds/Accordion.svelte.d.ts +34 -0
  6. package/dist/components/compounds/ActionSheet.svelte +24 -0
  7. package/dist/components/compounds/ActionSheet.svelte.d.ts +38 -0
  8. package/dist/components/compounds/Alert.svelte +15 -4
  9. package/dist/components/compounds/Alert.svelte.d.ts +10 -0
  10. package/dist/components/compounds/AppBar.svelte +24 -0
  11. package/dist/components/compounds/AppBar.svelte.d.ts +33 -0
  12. package/dist/components/compounds/BottomNav.svelte +37 -0
  13. package/dist/components/compounds/BottomNav.svelte.d.ts +43 -0
  14. package/dist/components/compounds/Breadcrumb.svelte +11 -0
  15. package/dist/components/compounds/Breadcrumb.svelte.d.ts +20 -0
  16. package/dist/components/compounds/Calendar.svelte +20 -6
  17. package/dist/components/compounds/Calendar.svelte.d.ts +20 -6
  18. package/dist/components/compounds/Card.svelte +10 -0
  19. package/dist/components/compounds/Card.svelte.d.ts +10 -0
  20. package/dist/components/compounds/Combobox.svelte +35 -18
  21. package/dist/components/compounds/Combobox.svelte.d.ts +35 -18
  22. package/dist/components/compounds/Confirm.svelte +11 -0
  23. package/dist/components/compounds/Confirm.svelte.d.ts +21 -0
  24. package/dist/components/compounds/DataTable.svelte +40 -17
  25. package/dist/components/compounds/DataTable.svelte.d.ts +9 -13
  26. package/dist/components/compounds/DatePicker.svelte +20 -6
  27. package/dist/components/compounds/DatePicker.svelte.d.ts +20 -6
  28. package/dist/components/compounds/Drawer.svelte +11 -0
  29. package/dist/components/compounds/Drawer.svelte.d.ts +21 -0
  30. package/dist/components/compounds/Dropdown.svelte +10 -0
  31. package/dist/components/compounds/Dropdown.svelte.d.ts +10 -0
  32. package/dist/components/compounds/Empty.svelte +16 -5
  33. package/dist/components/compounds/Empty.svelte.d.ts +20 -0
  34. package/dist/components/compounds/Form.svelte +37 -2
  35. package/dist/components/compounds/Form.svelte.d.ts +20 -0
  36. package/dist/components/compounds/FormField.svelte +11 -0
  37. package/dist/components/compounds/FormField.svelte.d.ts +20 -0
  38. package/dist/components/compounds/FormLayout.svelte +13 -1
  39. package/dist/components/compounds/FormLayout.svelte.d.ts +13 -0
  40. package/dist/components/compounds/InfiniteScroll.svelte +24 -0
  41. package/dist/components/compounds/InfiniteScroll.svelte.d.ts +34 -0
  42. package/dist/components/compounds/MessageBoxContainer.svelte +11 -0
  43. package/dist/components/compounds/MessageBoxContainer.svelte.d.ts +21 -0
  44. package/dist/components/compounds/MessageBoxDialog.svelte +14 -0
  45. package/dist/components/compounds/MessageBoxDialog.svelte.d.ts +21 -0
  46. package/dist/components/compounds/MessageContainer.svelte +11 -0
  47. package/dist/components/compounds/MessageContainer.svelte.d.ts +21 -0
  48. package/dist/components/compounds/Modal.svelte +10 -0
  49. package/dist/components/compounds/Modal.svelte.d.ts +10 -0
  50. package/dist/components/compounds/PageHeader.svelte +21 -8
  51. package/dist/components/compounds/PageHeader.svelte.d.ts +21 -8
  52. package/dist/components/compounds/Pagination.svelte +34 -8
  53. package/dist/components/compounds/Pagination.svelte.d.ts +20 -0
  54. package/dist/components/compounds/Popover.svelte +11 -0
  55. package/dist/components/compounds/Popover.svelte.d.ts +20 -0
  56. package/dist/components/compounds/PullRefresh.svelte +24 -0
  57. package/dist/components/compounds/PullRefresh.svelte.d.ts +32 -0
  58. package/dist/components/compounds/Result.svelte +11 -0
  59. package/dist/components/compounds/Result.svelte.d.ts +20 -0
  60. package/dist/components/compounds/SafeArea.svelte +24 -0
  61. package/dist/components/compounds/SafeArea.svelte.d.ts +32 -0
  62. package/dist/components/compounds/Skeleton.svelte +10 -0
  63. package/dist/components/compounds/Skeleton.svelte.d.ts +10 -0
  64. package/dist/components/compounds/Steps.svelte +11 -0
  65. package/dist/components/compounds/Steps.svelte.d.ts +20 -0
  66. package/dist/components/compounds/SwipeCell.svelte +24 -0
  67. package/dist/components/compounds/SwipeCell.svelte.d.ts +37 -0
  68. package/dist/components/compounds/TableToolbar.svelte +66 -28
  69. package/dist/components/compounds/TableToolbar.svelte.d.ts +29 -19
  70. package/dist/components/compounds/Tabs.svelte +58 -10
  71. package/dist/components/compounds/Tabs.svelte.d.ts +10 -0
  72. package/dist/components/compounds/TagInput.svelte +11 -0
  73. package/dist/components/compounds/TagInput.svelte.d.ts +20 -0
  74. package/dist/components/compounds/Timeline.svelte +24 -0
  75. package/dist/components/compounds/Timeline.svelte.d.ts +34 -0
  76. package/dist/components/compounds/ToastContainer.svelte +11 -0
  77. package/dist/components/compounds/ToastContainer.svelte.d.ts +26 -0
  78. package/dist/components/compounds/Tooltip.svelte +11 -0
  79. package/dist/components/compounds/Tooltip.svelte.d.ts +22 -0
  80. package/dist/components/compounds/accordion-types.d.ts +10 -1
  81. package/dist/components/compounds/action-sheet-types.d.ts +9 -0
  82. package/dist/components/compounds/bottom-nav-types.d.ts +9 -0
  83. package/dist/components/compounds/swipe-cell-types.d.ts +9 -0
  84. package/dist/components/compounds/timeline-types.d.ts +9 -0
  85. package/dist/components/control-size.d.ts +17 -0
  86. package/dist/components/control-size.js +8 -0
  87. package/dist/components/primitives/Avatar.svelte +10 -0
  88. package/dist/components/primitives/Avatar.svelte.d.ts +10 -0
  89. package/dist/components/primitives/Badge.svelte +10 -0
  90. package/dist/components/primitives/Badge.svelte.d.ts +10 -0
  91. package/dist/components/primitives/BareButton.svelte +11 -0
  92. package/dist/components/primitives/BareButton.svelte.d.ts +20 -0
  93. package/dist/components/primitives/BareInput.svelte +11 -0
  94. package/dist/components/primitives/BareInput.svelte.d.ts +20 -0
  95. package/dist/components/primitives/Button.svelte +10 -0
  96. package/dist/components/primitives/Button.svelte.d.ts +10 -0
  97. package/dist/components/primitives/Checkbox.svelte +11 -0
  98. package/dist/components/primitives/Checkbox.svelte.d.ts +20 -0
  99. package/dist/components/primitives/IconButton.svelte +11 -0
  100. package/dist/components/primitives/IconButton.svelte.d.ts +20 -0
  101. package/dist/components/primitives/Input.svelte +10 -0
  102. package/dist/components/primitives/Input.svelte.d.ts +10 -0
  103. package/dist/components/primitives/Progress.svelte +11 -0
  104. package/dist/components/primitives/Progress.svelte.d.ts +20 -0
  105. package/dist/components/primitives/Radio.svelte +11 -0
  106. package/dist/components/primitives/Radio.svelte.d.ts +20 -0
  107. package/dist/components/primitives/Range.svelte +24 -0
  108. package/dist/components/primitives/Range.svelte.d.ts +34 -0
  109. package/dist/components/primitives/Rating.svelte +24 -0
  110. package/dist/components/primitives/Rating.svelte.d.ts +34 -0
  111. package/dist/components/primitives/Select.svelte +11 -0
  112. package/dist/components/primitives/Select.svelte.d.ts +21 -0
  113. package/dist/components/primitives/Spinner.svelte +11 -0
  114. package/dist/components/primitives/Spinner.svelte.d.ts +20 -0
  115. package/dist/components/primitives/Switch.svelte +11 -0
  116. package/dist/components/primitives/Switch.svelte.d.ts +20 -0
  117. package/dist/components/primitives/Tag.svelte +11 -0
  118. package/dist/components/primitives/Tag.svelte.d.ts +20 -0
  119. package/dist/components/primitives/Textarea.svelte +11 -0
  120. package/dist/components/primitives/Textarea.svelte.d.ts +21 -0
  121. package/dist/components/primitives/ToggleCheckbox.svelte +11 -0
  122. package/dist/components/primitives/ToggleCheckbox.svelte.d.ts +20 -0
  123. package/dist/components/primitives/ToggleInput.svelte +11 -0
  124. package/dist/components/primitives/ToggleInput.svelte.d.ts +20 -0
  125. package/dist/components/primitives/ToggleRadio.svelte +11 -0
  126. package/dist/components/primitives/ToggleRadio.svelte.d.ts +20 -0
  127. package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte +27 -0
  128. package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte.d.ts +27 -0
  129. package/dist/components/scenes/ai/AiDocumentEditor.svelte +79 -0
  130. package/dist/components/scenes/ai/AiDocumentEditor.svelte.d.ts +23 -0
  131. package/dist/components/scenes/ai/MarkdownRenderer.svelte +11 -0
  132. package/dist/components/scenes/ai/MarkdownRenderer.svelte.d.ts +28 -0
  133. package/dist/components/scenes/ai/code-preview.d.ts +28 -0
  134. package/dist/components/scenes/ai/code-preview.js +20 -0
  135. package/dist/components/scenes/ai/document-download.d.ts +52 -0
  136. package/dist/components/scenes/ai/document-download.js +30 -2
  137. package/dist/components/scenes/ai/document-parse.d.ts +71 -14
  138. package/dist/components/scenes/ai/document-parse.js +19 -9
  139. package/dist/components/scenes/ai/document-types.d.ts +222 -88
  140. package/dist/components/scenes/ai/editor-markdown-extensions.d.ts +16 -0
  141. package/dist/components/scenes/ai/editor-markdown-extensions.js +16 -0
  142. package/dist/components/scenes/ai/highlight.d.ts +11 -0
  143. package/dist/components/scenes/ai/highlight.js +11 -0
  144. package/dist/components/scenes/ai/markdown-parse.d.ts +8 -2
  145. package/dist/components/scenes/ai/markdown-parse.js +2 -2
  146. package/dist/components/scenes/ai/mermaid-host-sync.d.ts +38 -0
  147. package/dist/components/scenes/ai/mermaid-host-sync.js +30 -0
  148. package/dist/components/scenes/ai/mermaid-render.d.ts +23 -0
  149. package/dist/components/scenes/ai/mermaid-render.js +23 -0
  150. package/dist/components/scenes/ai/safe-html.d.ts +54 -6
  151. package/dist/components/scenes/ai/safe-html.js +54 -6
  152. package/dist/components/scenes/ai/table/AiTableEditor.svelte +48 -0
  153. package/dist/components/scenes/ai/table/AiTableEditor.svelte.d.ts +24 -0
  154. package/dist/components/scenes/ai/table/table-types.d.ts +79 -0
  155. package/dist/components/scenes/app/FeedbackModal.svelte +45 -5
  156. package/dist/components/scenes/app/FeedbackModal.svelte.d.ts +45 -5
  157. package/dist/components/scenes/app/LanguageSwitch.svelte +29 -19
  158. package/dist/components/scenes/app/LanguageSwitch.svelte.d.ts +28 -19
  159. package/dist/components/scenes/app/SettingsLayout.svelte +21 -9
  160. package/dist/components/scenes/app/SettingsLayout.svelte.d.ts +21 -9
  161. package/dist/components/scenes/app/SettingsModal.svelte +23 -0
  162. package/dist/components/scenes/app/SettingsModal.svelte.d.ts +23 -0
  163. package/dist/components/scenes/app/ThemeColorPicker.svelte +31 -0
  164. package/dist/components/scenes/app/ThemeColorPicker.svelte.d.ts +31 -0
  165. package/dist/components/scenes/app/ThemeSelector.svelte +21 -6
  166. package/dist/components/scenes/app/ThemeSelector.svelte.d.ts +21 -6
  167. package/dist/components/scenes/app/ThemeToggle.svelte +21 -4
  168. package/dist/components/scenes/app/ThemeToggle.svelte.d.ts +21 -4
  169. package/dist/components/scenes/app/index.d.ts +1 -1
  170. package/dist/components/scenes/app/index.js +1 -1
  171. package/dist/components/scenes/charts/Chart.svelte +11 -0
  172. package/dist/components/scenes/charts/Chart.svelte.d.ts +20 -0
  173. package/dist/components/scenes/charts/chart-theme.d.ts +25 -1
  174. package/dist/components/scenes/charts/chart-theme.js +25 -1
  175. package/dist/components/scenes/charts/chart-types.d.ts +83 -7
  176. package/dist/components/scenes/charts/renderers/LineChart.svelte +53 -0
  177. package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +13 -0
  178. package/dist/components/scenes/crud/CrudDeleteConfirm.svelte +10 -0
  179. package/dist/components/scenes/crud/CrudDeleteConfirm.svelte.d.ts +10 -0
  180. package/dist/components/scenes/crud/CrudDetailDrawer.svelte +8 -0
  181. package/dist/components/scenes/crud/CrudDetailDrawer.svelte.d.ts +8 -0
  182. package/dist/components/scenes/crud/CrudDetailPanel.svelte +18 -0
  183. package/dist/components/scenes/crud/CrudDetailPanel.svelte.d.ts +18 -0
  184. package/dist/components/scenes/crud/CrudEditPanel.svelte +10 -0
  185. package/dist/components/scenes/crud/CrudEditPanel.svelte.d.ts +10 -0
  186. package/dist/components/scenes/crud/CrudFilterBar.svelte +18 -0
  187. package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +18 -0
  188. package/dist/components/scenes/crud/CrudPage.svelte +37 -5
  189. package/dist/components/scenes/crud/CrudPage.svelte.d.ts +35 -3
  190. package/dist/components/scenes/crud/crud-controller.svelte.d.ts +142 -23
  191. package/dist/components/scenes/crud/crud-controller.svelte.js +22 -11
  192. package/dist/components/scenes/crud/crud-form-validation.d.ts +12 -0
  193. package/dist/components/scenes/crud/crud-form-validation.js +12 -0
  194. package/dist/components/scenes/crud/crud-types.d.ts +79 -8
  195. package/dist/components/scenes/crud/nav-adapter.d.ts +14 -0
  196. package/dist/components/scenes/crud/nav-adapter.js +8 -0
  197. package/dist/components/scenes/crypto/EncryptedInput.svelte +24 -0
  198. package/dist/components/scenes/crypto/EncryptedInput.svelte.d.ts +34 -0
  199. package/dist/components/scenes/crypto/HashDisplay.svelte +11 -0
  200. package/dist/components/scenes/crypto/HashDisplay.svelte.d.ts +21 -0
  201. package/dist/components/scenes/crypto/SignatureDisplay.svelte +11 -0
  202. package/dist/components/scenes/crypto/SignatureDisplay.svelte.d.ts +21 -0
  203. package/dist/components/scenes/error/ErrorPage.svelte +8 -1
  204. package/dist/components/scenes/error/ErrorPage.svelte.d.ts +8 -1
  205. package/dist/components/scenes/error/error-presets.d.ts +40 -4
  206. package/dist/components/scenes/error/error-presets.js +22 -2
  207. package/dist/components/scenes/guide/GuideHost.svelte +27 -0
  208. package/dist/components/scenes/guide/GuideHost.svelte.d.ts +27 -0
  209. package/dist/components/scenes/guide/HelpCenter.svelte +27 -0
  210. package/dist/components/scenes/guide/HelpCenter.svelte.d.ts +27 -0
  211. package/dist/components/scenes/iam/AuthPanel.svelte +26 -2
  212. package/dist/components/scenes/iam/AuthPanel.svelte.d.ts +25 -0
  213. package/dist/components/scenes/iam/AuthShell.svelte +8 -3
  214. package/dist/components/scenes/iam/AuthShell.svelte.d.ts +8 -3
  215. package/dist/components/scenes/iam/ChangePasswordForm.svelte +10 -0
  216. package/dist/components/scenes/iam/ChangePasswordForm.svelte.d.ts +10 -0
  217. package/dist/components/scenes/iam/ForgotPasswordForm.svelte +11 -0
  218. package/dist/components/scenes/iam/ForgotPasswordForm.svelte.d.ts +21 -0
  219. package/dist/components/scenes/iam/LoginForm.svelte +24 -31
  220. package/dist/components/scenes/iam/LoginForm.svelte.d.ts +10 -0
  221. package/dist/components/scenes/iam/PasswordInput.svelte +23 -0
  222. package/dist/components/scenes/iam/PasswordInput.svelte.d.ts +23 -0
  223. package/dist/components/scenes/iam/PermGuard.svelte +21 -11
  224. package/dist/components/scenes/iam/PermGuard.svelte.d.ts +30 -0
  225. package/dist/components/scenes/iam/RegisterForm.svelte +10 -0
  226. package/dist/components/scenes/iam/RegisterForm.svelte.d.ts +10 -0
  227. package/dist/components/scenes/iam/ResetPasswordForm.svelte +10 -0
  228. package/dist/components/scenes/iam/ResetPasswordForm.svelte.d.ts +10 -0
  229. package/dist/components/scenes/iam/UserProfile.svelte +11 -0
  230. package/dist/components/scenes/iam/UserProfile.svelte.d.ts +21 -0
  231. package/dist/components/scenes/iam/auth-error-message.d.ts +10 -0
  232. package/dist/components/scenes/iam/auth-error-message.js +10 -0
  233. package/dist/components/scenes/iam/password-utils.d.ts +39 -1
  234. package/dist/components/scenes/iam/password-utils.js +39 -1
  235. package/dist/components/scenes/iam/permission-context.svelte.d.ts +33 -23
  236. package/dist/components/scenes/iam/permission-context.svelte.js +20 -22
  237. package/dist/components/scenes/storage/AvatarUpload.svelte +11 -0
  238. package/dist/components/scenes/storage/AvatarUpload.svelte.d.ts +20 -0
  239. package/dist/components/scenes/storage/FileList.svelte +13 -2
  240. package/dist/components/scenes/storage/FileList.svelte.d.ts +20 -0
  241. package/dist/components/scenes/storage/FileUpload.svelte +37 -2
  242. package/dist/components/scenes/storage/FileUpload.svelte.d.ts +21 -0
  243. package/dist/components/scenes/storage/ImageUpload.svelte +11 -0
  244. package/dist/components/scenes/storage/ImageUpload.svelte.d.ts +21 -0
  245. package/dist/components/scenes/types.d.ts +352 -11
  246. package/dist/guide-storage.d.ts +13 -1
  247. package/dist/guide-storage.js +13 -1
  248. package/dist/guide-types.d.ts +67 -2
  249. package/dist/guide.svelte.d.ts +22 -1
  250. package/dist/guide.svelte.js +22 -1
  251. package/dist/i18n.svelte.d.ts +64 -3
  252. package/dist/i18n.svelte.js +99 -18
  253. package/dist/index.d.ts +2 -1
  254. package/dist/index.js +1 -2
  255. package/dist/internal/browser-safety.d.ts +51 -2
  256. package/dist/internal/browser-safety.js +45 -7
  257. package/dist/internal/form-context.d.ts +73 -0
  258. package/dist/internal/form-context.js +57 -0
  259. package/dist/internal/form-validation.svelte.d.ts +42 -0
  260. package/dist/internal/form-validation.svelte.js +26 -0
  261. package/dist/internal/icon-safety.d.ts +7 -0
  262. package/dist/internal/icon-safety.js +7 -0
  263. package/dist/internal/locale.d.ts +19 -0
  264. package/dist/internal/locale.js +21 -0
  265. package/dist/message.svelte.d.ts +90 -0
  266. package/dist/message.svelte.js +84 -0
  267. package/dist/messagebox.svelte.d.ts +61 -13
  268. package/dist/messagebox.svelte.js +55 -13
  269. package/dist/messages/en-US.json +6 -1
  270. package/dist/messages/ja-JP.json +389 -0
  271. package/dist/messages/zh-CN.json +6 -1
  272. package/dist/messages.d.ts +24 -3
  273. package/dist/messages.js +18 -3
  274. package/dist/styles/design-tokens.css +4 -2
  275. package/dist/styles/global.css +28 -8
  276. package/dist/styles/theme.css +2 -0
  277. package/dist/theme-config.d.ts +173 -0
  278. package/dist/theme-config.js +143 -0
  279. package/dist/toast.svelte.d.ts +114 -4
  280. package/dist/toast.svelte.js +108 -4
  281. package/dist/types.d.ts +526 -9
  282. package/dist/utils/platform.svelte.d.ts +28 -15
  283. package/dist/utils/platform.svelte.js +19 -14
  284. package/dist/utils.d.ts +102 -0
  285. package/dist/utils.js +93 -0
  286. package/package.json +66 -6
@@ -7,6 +7,12 @@
7
7
  import { readStoredValue, writeStoredValue } from './internal/browser-safety.js';
8
8
  /**
9
9
  * DaisyUI 内置主题配置(精选)
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { THEMES } from '@h-ai/ui'
14
+ * const choices = THEMES.map(theme => ({ value: theme.id, label: theme.name }))
15
+ * ```
10
16
  */
11
17
  export const THEMES = [
12
18
  // 亮色主题
@@ -29,6 +35,13 @@ export const THEMES = [
29
35
  ];
30
36
  /**
31
37
  * 主题分组配置
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { THEME_GROUPS } from '@h-ai/ui'
42
+ * const light = THEME_GROUPS.find(group => group.id === 'light')
43
+ * const choices = light?.themes
44
+ * ```
32
45
  */
33
46
  export const THEME_GROUPS = [
34
47
  {
@@ -44,22 +57,52 @@ export const THEME_GROUPS = [
44
57
  ];
45
58
  /**
46
59
  * 暗色主题列表
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { DARK_THEMES } from '@h-ai/ui'
64
+ * const dark = DARK_THEMES.includes('dark')
65
+ * ```
47
66
  */
48
67
  export const DARK_THEMES = THEMES.filter(t => t.dark).map(t => t.id);
49
68
  /**
50
69
  * 支持的主题 ID 列表
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { SUPPORTED_THEME_IDS } from '@h-ai/ui'
74
+ * const supported = SUPPORTED_THEME_IDS.includes('light')
75
+ * ```
51
76
  */
52
77
  export const SUPPORTED_THEME_IDS = THEMES.map(theme => theme.id);
53
78
  /**
54
79
  * 默认主题色
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * import { DEFAULT_THEME_COLOR } from '@h-ai/ui'
84
+ * const style = { '--brand-color': DEFAULT_THEME_COLOR }
85
+ * ```
55
86
  */
56
87
  export const DEFAULT_THEME_COLOR = '#5765f0';
57
88
  /**
58
89
  * 主题色 CSS 变量名
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { DEFAULT_THEME_COLOR_CSS_VAR } from '@h-ai/ui'
94
+ * document.documentElement.style.setProperty(DEFAULT_THEME_COLOR_CSS_VAR, '#2563eb')
95
+ * ```
59
96
  */
60
97
  export const DEFAULT_THEME_COLOR_CSS_VAR = '--hai-theme-color-default';
61
98
  /**
62
99
  * 内置主题色预设
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { THEME_COLOR_PRESETS } from '@h-ai/ui'
104
+ * const options = THEME_COLOR_PRESETS.map(preset => ({ value: preset.value, labelKey: preset.labelKey }))
105
+ * ```
63
106
  */
64
107
  export const THEME_COLOR_PRESETS = [
65
108
  { value: DEFAULT_THEME_COLOR, labelKey: 'theme_color_tech_purple' },
@@ -71,26 +114,65 @@ const SHORT_HEX_COLOR_REGEX = /^#[0-9a-f]{3}$/i;
71
114
  const SUPPORTED_THEME_ID_SET = new Set(SUPPORTED_THEME_IDS);
72
115
  /**
73
116
  * 默认主题
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * import { DEFAULT_THEME, applyTheme } from '@h-ai/ui'
121
+ * applyTheme(DEFAULT_THEME, false)
122
+ * ```
74
123
  */
75
124
  export const DEFAULT_THEME = 'light';
76
125
  /**
77
126
  * 主题存储键名
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { THEME_STORAGE_KEY, getSavedTheme } from '@h-ai/ui'
131
+ * const preference = { key: THEME_STORAGE_KEY, value: getSavedTheme('light') }
132
+ * // 通过公开安全读取函数消费偏好,不直接访问受限存储。
133
+ * ```
78
134
  */
79
135
  export const THEME_STORAGE_KEY = 'theme';
80
136
  /**
81
137
  * 获取主题信息
138
+ * @param themeId - 主题候选 ID。
139
+ * @returns 匹配的主题元数据,不存在时返回 undefined。
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { getThemeInfo } from '@h-ai/ui'
144
+ * const theme = getThemeInfo('light')
145
+ * const background = theme?.bgColor
146
+ * ```
82
147
  */
83
148
  export function getThemeInfo(themeId) {
84
149
  return THEMES.find(t => t.id === themeId);
85
150
  }
86
151
  /**
87
152
  * 检查是否为暗色主题
153
+ * @param themeId - 主题候选 ID。
154
+ * @returns 是否属于内置暗色主题。
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { isDarkTheme } from '@h-ai/ui'
159
+ * const dark = isDarkTheme('dark')
160
+ * ```
88
161
  */
89
162
  export function isDarkTheme(themeId) {
90
163
  return DARK_THEMES.includes(themeId);
91
164
  }
92
165
  /**
93
166
  * 归一化主题 ID,不支持的值回退到默认主题。
167
+ * @param themeId - 主题候选 ID。
168
+ * @param fallbackThemeId - 候选不支持时尝试的主题。
169
+ * @returns 支持的主题 ID;无效输入按候选和默认主题回退。
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * import { normalizeThemeId } from '@h-ai/ui'
174
+ * const theme = normalizeThemeId('unknown-theme', 'light')
175
+ * ```
94
176
  */
95
177
  export function normalizeThemeId(themeId, fallbackThemeId = DEFAULT_THEME) {
96
178
  const normalized = `${themeId ?? ''}`;
@@ -101,6 +183,14 @@ export function normalizeThemeId(themeId, fallbackThemeId = DEFAULT_THEME) {
101
183
  }
102
184
  /**
103
185
  * 归一化 Hex 颜色;无效值返回 null。
186
+ * @param value - 待处理或校验的值。
187
+ * @returns 小写六位 Hex 颜色;无效输入返回 null。
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * import { normalizeHexColor } from '@h-ai/ui'
192
+ * const color = normalizeHexColor('#abc')
193
+ * ```
104
194
  */
105
195
  export function normalizeHexColor(value) {
106
196
  const normalized = value?.trim().toLowerCase() ?? '';
@@ -114,6 +204,14 @@ export function normalizeHexColor(value) {
114
204
  }
115
205
  /**
116
206
  * 解析主题对应的浏览器色调。
207
+ * @param themeId - 主题候选 ID。
208
+ * @returns 供浏览器控件配色使用的 light/dark 值。
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * import { resolveThemeTone } from '@h-ai/ui'
213
+ * const tone = resolveThemeTone('dark')
214
+ * ```
117
215
  */
118
216
  export function resolveThemeTone(themeId) {
119
217
  return isDarkTheme(themeId) ? 'dark' : 'light';
@@ -127,6 +225,15 @@ function escapeJsonForScript(value) {
127
225
  }
128
226
  /**
129
227
  * 生成首屏主题恢复脚本,适合注入到 SvelteKit `app.html` 的 `<script>` 中。
228
+ * @param options - 本次操作的行为与显示选项。
229
+ * @returns 可放入受控 HTML shell 的初始化脚本文本。
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * import { createThemeBootstrapScript } from '@h-ai/ui'
234
+ * const script = createThemeBootstrapScript({ storageKey: 'demo-theme', defaultThemeId: 'light' })
235
+ * // 在应用 HTML shell 中作为受控脚本使用,避免首屏主题闪烁。
236
+ * ```
130
237
  */
131
238
  export function createThemeBootstrapScript(options) {
132
239
  const defaultThemeId = normalizeThemeId(options.defaultThemeId ?? DEFAULT_THEME);
@@ -156,6 +263,13 @@ export function createThemeBootstrapScript(options) {
156
263
  *
157
264
  * 返回值是“脚本标签内的文本内容”,适合宿主在构建阶段或服务端模板中注入。
158
265
  * 对于 SvelteKit `app.html`,请直接粘贴这段脚本字符串的内容,不能写 `{@html getThemeInitScript()}`。
266
+ * @returns 使用默认存储约定的主题初始化脚本。
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * import { getThemeInitScript } from '@h-ai/ui'
271
+ * const script = getThemeInitScript()
272
+ * ```
159
273
  */
160
274
  export function getThemeInitScript() {
161
275
  return createThemeBootstrapScript({
@@ -167,6 +281,14 @@ export function getThemeInitScript() {
167
281
  * 应用主题
168
282
  * @param theme - 主题 ID
169
283
  * @param persist - 是否持久化到 localStorage
284
+ * @returns {void} 无返回值;更新当前文档,并按 persist 决定是否保存偏好。
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * import { applyTheme } from '@h-ai/ui'
289
+ * applyTheme('dark', false)
290
+ * // false 仅更新当前 DOM,不写入持久化偏好。
291
+ * ```
170
292
  */
171
293
  export function applyTheme(theme, persist = true) {
172
294
  if (typeof document === 'undefined')
@@ -178,6 +300,13 @@ export function applyTheme(theme, persist = true) {
178
300
  }
179
301
  /**
180
302
  * 获取当前主题
303
+ * @returns 当前文档主题;无 DOM 时使用默认值。
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * import { getCurrentTheme } from '@h-ai/ui'
308
+ * const theme = getCurrentTheme()
309
+ * ```
181
310
  */
182
311
  export function getCurrentTheme() {
183
312
  if (typeof document === 'undefined')
@@ -188,6 +317,13 @@ export function getCurrentTheme() {
188
317
  * 获取保存的主题;存储为空或不可用时使用宿主默认主题。
189
318
  *
190
319
  * @param fallbackTheme - 未保存主题时的默认值,默认 light
320
+ * @returns 安全读取并归一化的主题偏好。
321
+ *
322
+ * @example
323
+ * ```ts
324
+ * import { getSavedTheme } from '@h-ai/ui'
325
+ * const theme = getSavedTheme('light')
326
+ * ```
191
327
  */
192
328
  export function getSavedTheme(fallbackTheme = DEFAULT_THEME) {
193
329
  return readStoredValue(THEME_STORAGE_KEY) ?? fallbackTheme;
@@ -201,6 +337,13 @@ export function getSavedTheme(fallbackTheme = DEFAULT_THEME) {
201
337
  * @plugin "daisyui" {
202
338
  * themes: light --default, dark --prefersdark, cupcake, bumblebee, ...
203
339
  * }
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * import { DAISYUI_THEMES_CONFIG } from '@h-ai/ui'
344
+ * const css = '@plugin "daisyui" { themes: ' + DAISYUI_THEMES_CONFIG + '; }'
345
+ * // 将生成的配置用于构建时 CSS,不在浏览器动态安装主题。
346
+ * ```
204
347
  */
205
348
  export const DAISYUI_THEMES_CONFIG = THEMES.map((t, i) => {
206
349
  if (i === 0)
@@ -7,6 +7,12 @@
7
7
  import type { ToastProps } from './types.js';
8
8
  /**
9
9
  * Toast 项
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import type { ToastItem } from '@h-ai/ui'
14
+ * const example: ToastItem = { id: 'toast-1', message: '保存完成', variant: 'success', duration: 3000 }
15
+ * ```
10
16
  */
11
17
  export interface ToastItem extends ToastProps {
12
18
  id: string;
@@ -20,26 +26,110 @@ declare class ToastState {
20
26
  private timers;
21
27
  /**
22
28
  * 添加 Toast
29
+ * @param props - 组件的属性对象。
30
+ * @returns 新条目的 ID,可用于提前移除。
31
+ * @example
32
+ * ```ts
33
+ * import { toast } from '@h-ai/ui'
34
+ * // 布局中需挂载 ToastContainer。
35
+ * const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
36
+ * toast.remove(id)
37
+ * ```
23
38
  */
24
39
  add(props: Omit<ToastProps, 'onclose'>): string;
25
40
  /**
26
41
  * 移除 Toast
42
+ * @param id - 待移除的条目 ID。
43
+ * @returns {void} 无返回值;同时清理对应的自动关闭定时器。
44
+ * @example
45
+ * ```ts
46
+ * import { toast } from '@h-ai/ui'
47
+ * // 布局中需挂载 ToastContainer。
48
+ * const id = toast.info('同步中', 0)
49
+ * toast.remove(id)
50
+ * ```
27
51
  */
28
52
  remove(id: string): void;
29
53
  /**
30
54
  * 清空所有 Toast
55
+ * @returns {void} 无返回值;同时清理对应的自动关闭定时器。
56
+ * @example
57
+ * ```ts
58
+ * import { toast } from '@h-ai/ui'
59
+ * // 布局中需挂载 ToastContainer。
60
+ * toast.info('同步中', 0)
61
+ * toast.clear()
62
+ * ```
31
63
  */
32
64
  clear(): void;
33
65
  /**
34
66
  * 快捷方法
67
+ * @param message - 已经本地化的用户提示。
68
+ * @param duration - 提示持续时间,单位毫秒。
69
+ * @returns 新条目的 ID,可用于提前移除。
70
+ * @example
71
+ * ```ts
72
+ * import { toast } from '@h-ai/ui'
73
+ * // 布局中需挂载 ToastContainer。
74
+ * const id = toast.success('操作结果', 3000)
75
+ * toast.remove(id)
76
+ * ```
35
77
  */
36
78
  success(message: string, duration?: number): string;
79
+ /**
80
+ * 处理 error 操作。
81
+ * @param message - 已经本地化的用户提示。
82
+ * @param duration - 提示持续时间,单位毫秒。
83
+ * @returns 新条目的 ID,可用于提前移除。
84
+ * @example
85
+ * ```ts
86
+ * import { toast } from '@h-ai/ui'
87
+ * // 布局中需挂载 ToastContainer。
88
+ * const id = toast.error('操作结果', 3000)
89
+ * toast.remove(id)
90
+ * ```
91
+ */
37
92
  error(message: string, duration?: number): string;
93
+ /**
94
+ * 处理 warning 操作。
95
+ * @param message - 已经本地化的用户提示。
96
+ * @param duration - 提示持续时间,单位毫秒。
97
+ * @returns 新条目的 ID,可用于提前移除。
98
+ * @example
99
+ * ```ts
100
+ * import { toast } from '@h-ai/ui'
101
+ * // 布局中需挂载 ToastContainer。
102
+ * const id = toast.warning('操作结果', 3000)
103
+ * toast.remove(id)
104
+ * ```
105
+ */
38
106
  warning(message: string, duration?: number): string;
107
+ /**
108
+ * 处理 info 操作。
109
+ * @param message - 已经本地化的用户提示。
110
+ * @param duration - 提示持续时间,单位毫秒。
111
+ * @returns 新条目的 ID,可用于提前移除。
112
+ * @example
113
+ * ```ts
114
+ * import { toast } from '@h-ai/ui'
115
+ * // 布局中需挂载 ToastContainer。
116
+ * const id = toast.info('操作结果', 3000)
117
+ * toast.remove(id)
118
+ * ```
119
+ */
39
120
  info(message: string, duration?: number): string;
40
121
  }
41
122
  /**
42
123
  * Toast 单例
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import { toast } from '@h-ai/ui'
128
+ * // 页面布局需挂载 ToastContainer。
129
+ * const id = toast.success('保存完成', 3000)
130
+ * toast.remove(id)
131
+ * toast.clear()
132
+ * ```
43
133
  */
44
134
  export declare const toast: ToastState;
45
135
  /**
@@ -49,9 +139,14 @@ export declare const toast: ToastState;
49
139
  *
50
140
  * @param message - 用户可见的成功文案(已本地化)。
51
141
  * @param duration - 可选停留时长(毫秒),默认 3000。
142
+ * @returns 新通知的 ID,可交给 toast.remove 提前移除。
52
143
  *
53
144
  * @example
54
- * notifySuccess(m.submit_submitted())
145
+ * ```ts
146
+ * import { notifySuccess, toast } from '@h-ai/ui'
147
+ * const id = notifySuccess('保存完成', 3000)
148
+ * toast.remove(id)
149
+ * ```
55
150
  */
56
151
  export declare function notifySuccess(message: string, duration?: number): string;
57
152
  /**
@@ -63,9 +158,14 @@ export declare function notifySuccess(message: string, duration?: number): strin
63
158
  * @param error - 错误对象或已本地化的错误文案。
64
159
  * @param fallback - 当 error 非 Error 且为空时使用的兜底文案。
65
160
  * @param duration - 可选停留时长(毫秒),默认 5000。
161
+ * @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
66
162
  *
67
163
  * @example
68
- * notifyError(error, m.submit_failed())
164
+ * ```ts
165
+ * import { notifyError, toast } from '@h-ai/ui'
166
+ * const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
167
+ * toast.remove(id)
168
+ * ```
69
169
  */
70
170
  export declare function notifyError(error: unknown, fallback?: string, duration?: number): string;
71
171
  /**
@@ -73,9 +173,14 @@ export declare function notifyError(error: unknown, fallback?: string, duration?
73
173
  *
74
174
  * @param message - 用户可见文案(已本地化)。
75
175
  * @param duration - 可选停留时长(毫秒),默认 3000。
176
+ * @returns 新提示的 ID。
76
177
  *
77
178
  * @example
78
- * notifyInfo(m.common_saved())
179
+ * ```ts
180
+ * import { notifyInfo, toast } from '@h-ai/ui'
181
+ * const id = notifyInfo('正在同步', 3000)
182
+ * toast.remove(id)
183
+ * ```
79
184
  */
80
185
  export declare function notifyInfo(message: string, duration?: number): string;
81
186
  /**
@@ -83,9 +188,14 @@ export declare function notifyInfo(message: string, duration?: number): string;
83
188
  *
84
189
  * @param message - 用户可见文案(已本地化)。
85
190
  * @param duration - 可选停留时长(毫秒),默认 5000。
191
+ * @returns 新警告的 ID。
86
192
  *
87
193
  * @example
88
- * notifyWarning(m.quota_almost_reached())
194
+ * ```ts
195
+ * import { notifyWarning, toast } from '@h-ai/ui'
196
+ * const id = notifyWarning('请先保存修改', 5000)
197
+ * toast.remove(id)
198
+ * ```
89
199
  */
90
200
  export declare function notifyWarning(message: string, duration?: number): string;
91
201
  export {};
@@ -13,6 +13,15 @@ class ToastState {
13
13
  timers = new Map();
14
14
  /**
15
15
  * 添加 Toast
16
+ * @param props - 组件的属性对象。
17
+ * @returns 新条目的 ID,可用于提前移除。
18
+ * @example
19
+ * ```ts
20
+ * import { toast } from '@h-ai/ui'
21
+ * // 布局中需挂载 ToastContainer。
22
+ * const id = toast.add({ message: '保存完成', variant: 'success', duration: 3000 })
23
+ * toast.remove(id)
24
+ * ```
16
25
  */
17
26
  add(props) {
18
27
  const id = Math.random().toString(36).slice(2, 9);
@@ -36,6 +45,15 @@ class ToastState {
36
45
  }
37
46
  /**
38
47
  * 移除 Toast
48
+ * @param id - 待移除的条目 ID。
49
+ * @returns {void} 无返回值;同时清理对应的自动关闭定时器。
50
+ * @example
51
+ * ```ts
52
+ * import { toast } from '@h-ai/ui'
53
+ * // 布局中需挂载 ToastContainer。
54
+ * const id = toast.info('同步中', 0)
55
+ * toast.remove(id)
56
+ * ```
39
57
  */
40
58
  remove(id) {
41
59
  const timer = this.timers.get(id);
@@ -47,6 +65,14 @@ class ToastState {
47
65
  }
48
66
  /**
49
67
  * 清空所有 Toast
68
+ * @returns {void} 无返回值;同时清理对应的自动关闭定时器。
69
+ * @example
70
+ * ```ts
71
+ * import { toast } from '@h-ai/ui'
72
+ * // 布局中需挂载 ToastContainer。
73
+ * toast.info('同步中', 0)
74
+ * toast.clear()
75
+ * ```
50
76
  */
51
77
  clear() {
52
78
  for (const timer of this.timers.values()) {
@@ -57,22 +83,80 @@ class ToastState {
57
83
  }
58
84
  /**
59
85
  * 快捷方法
86
+ * @param message - 已经本地化的用户提示。
87
+ * @param duration - 提示持续时间,单位毫秒。
88
+ * @returns 新条目的 ID,可用于提前移除。
89
+ * @example
90
+ * ```ts
91
+ * import { toast } from '@h-ai/ui'
92
+ * // 布局中需挂载 ToastContainer。
93
+ * const id = toast.success('操作结果', 3000)
94
+ * toast.remove(id)
95
+ * ```
60
96
  */
61
97
  success(message, duration) {
62
98
  return this.add({ message, variant: 'success', duration });
63
99
  }
100
+ /**
101
+ * 处理 error 操作。
102
+ * @param message - 已经本地化的用户提示。
103
+ * @param duration - 提示持续时间,单位毫秒。
104
+ * @returns 新条目的 ID,可用于提前移除。
105
+ * @example
106
+ * ```ts
107
+ * import { toast } from '@h-ai/ui'
108
+ * // 布局中需挂载 ToastContainer。
109
+ * const id = toast.error('操作结果', 3000)
110
+ * toast.remove(id)
111
+ * ```
112
+ */
64
113
  error(message, duration) {
65
114
  return this.add({ message, variant: 'error', duration });
66
115
  }
116
+ /**
117
+ * 处理 warning 操作。
118
+ * @param message - 已经本地化的用户提示。
119
+ * @param duration - 提示持续时间,单位毫秒。
120
+ * @returns 新条目的 ID,可用于提前移除。
121
+ * @example
122
+ * ```ts
123
+ * import { toast } from '@h-ai/ui'
124
+ * // 布局中需挂载 ToastContainer。
125
+ * const id = toast.warning('操作结果', 3000)
126
+ * toast.remove(id)
127
+ * ```
128
+ */
67
129
  warning(message, duration) {
68
130
  return this.add({ message, variant: 'warning', duration });
69
131
  }
132
+ /**
133
+ * 处理 info 操作。
134
+ * @param message - 已经本地化的用户提示。
135
+ * @param duration - 提示持续时间,单位毫秒。
136
+ * @returns 新条目的 ID,可用于提前移除。
137
+ * @example
138
+ * ```ts
139
+ * import { toast } from '@h-ai/ui'
140
+ * // 布局中需挂载 ToastContainer。
141
+ * const id = toast.info('操作结果', 3000)
142
+ * toast.remove(id)
143
+ * ```
144
+ */
70
145
  info(message, duration) {
71
146
  return this.add({ message, variant: 'info', duration });
72
147
  }
73
148
  }
74
149
  /**
75
150
  * Toast 单例
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import { toast } from '@h-ai/ui'
155
+ * // 页面布局需挂载 ToastContainer。
156
+ * const id = toast.success('保存完成', 3000)
157
+ * toast.remove(id)
158
+ * toast.clear()
159
+ * ```
76
160
  */
77
161
  export const toast = new ToastState();
78
162
  /** 成功提示默认停留时长(毫秒)。 */
@@ -86,9 +170,14 @@ const ERROR_DURATION = 5000;
86
170
  *
87
171
  * @param message - 用户可见的成功文案(已本地化)。
88
172
  * @param duration - 可选停留时长(毫秒),默认 3000。
173
+ * @returns 新通知的 ID,可交给 toast.remove 提前移除。
89
174
  *
90
175
  * @example
91
- * notifySuccess(m.submit_submitted())
176
+ * ```ts
177
+ * import { notifySuccess, toast } from '@h-ai/ui'
178
+ * const id = notifySuccess('保存完成', 3000)
179
+ * toast.remove(id)
180
+ * ```
92
181
  */
93
182
  export function notifySuccess(message, duration = SUCCESS_DURATION) {
94
183
  return toast.success(message, duration);
@@ -102,9 +191,14 @@ export function notifySuccess(message, duration = SUCCESS_DURATION) {
102
191
  * @param error - 错误对象或已本地化的错误文案。
103
192
  * @param fallback - 当 error 非 Error 且为空时使用的兜底文案。
104
193
  * @param duration - 可选停留时长(毫秒),默认 5000。
194
+ * @returns 新错误通知的 ID,可交给 toast.remove 提前移除。
105
195
  *
106
196
  * @example
107
- * notifyError(error, m.submit_failed())
197
+ * ```ts
198
+ * import { notifyError, toast } from '@h-ai/ui'
199
+ * const id = notifyError(new Error('提交失败'), '请稍后重试', 5000)
200
+ * toast.remove(id)
201
+ * ```
108
202
  */
109
203
  export function notifyError(error, fallback = '', duration = ERROR_DURATION) {
110
204
  const message = error instanceof Error
@@ -117,9 +211,14 @@ export function notifyError(error, fallback = '', duration = ERROR_DURATION) {
117
211
  *
118
212
  * @param message - 用户可见文案(已本地化)。
119
213
  * @param duration - 可选停留时长(毫秒),默认 3000。
214
+ * @returns 新提示的 ID。
120
215
  *
121
216
  * @example
122
- * notifyInfo(m.common_saved())
217
+ * ```ts
218
+ * import { notifyInfo, toast } from '@h-ai/ui'
219
+ * const id = notifyInfo('正在同步', 3000)
220
+ * toast.remove(id)
221
+ * ```
123
222
  */
124
223
  export function notifyInfo(message, duration = SUCCESS_DURATION) {
125
224
  return toast.info(message, duration);
@@ -129,9 +228,14 @@ export function notifyInfo(message, duration = SUCCESS_DURATION) {
129
228
  *
130
229
  * @param message - 用户可见文案(已本地化)。
131
230
  * @param duration - 可选停留时长(毫秒),默认 5000。
231
+ * @returns 新警告的 ID。
132
232
  *
133
233
  * @example
134
- * notifyWarning(m.quota_almost_reached())
234
+ * ```ts
235
+ * import { notifyWarning, toast } from '@h-ai/ui'
236
+ * const id = notifyWarning('请先保存修改', 5000)
237
+ * toast.remove(id)
238
+ * ```
135
239
  */
136
240
  export function notifyWarning(message, duration = ERROR_DURATION) {
137
241
  return toast.warning(message, duration);