@h-ai/ui 1.0.0-beta.2 → 1.0.0-beta.20

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 (139) hide show
  1. package/README.en.md +228 -70
  2. package/README.ja.md +227 -69
  3. package/README.md +229 -72
  4. package/auto-import.d.ts +4 -0
  5. package/auto-import.js +241 -65
  6. package/dist/components/compounds/Accordion.svelte +6 -2
  7. package/dist/components/compounds/BottomNav.svelte +14 -2
  8. package/dist/components/compounds/Card.svelte +3 -1
  9. package/dist/components/compounds/Combobox.svelte +41 -5
  10. package/dist/components/compounds/DataTable.svelte +28 -8
  11. package/dist/components/compounds/DatePicker.svelte +6 -1
  12. package/dist/components/compounds/Drawer.svelte +12 -4
  13. package/dist/components/compounds/Dropdown.svelte +135 -59
  14. package/dist/components/compounds/Empty.svelte +10 -2
  15. package/dist/components/compounds/FormField.svelte +10 -2
  16. package/dist/components/compounds/JsonViewer.svelte +18 -6
  17. package/dist/components/compounds/Modal.svelte +8 -2
  18. package/dist/components/compounds/Pagination.svelte +22 -7
  19. package/dist/components/compounds/Popover.svelte +93 -12
  20. package/dist/components/compounds/Steps.svelte +24 -8
  21. package/dist/components/compounds/SwipeCell.svelte +3 -1
  22. package/dist/components/compounds/TableToolbar.svelte +32 -9
  23. package/dist/components/compounds/Tabs.svelte +25 -5
  24. package/dist/components/compounds/TagInput.svelte +2 -0
  25. package/dist/components/compounds/Timeline.svelte +6 -2
  26. package/dist/components/compounds/ToastContainer.svelte +41 -10
  27. package/dist/components/compounds/Tooltip.svelte +1 -1
  28. package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
  29. package/dist/components/control-size.js +48 -8
  30. package/dist/components/primitives/Avatar.svelte +9 -3
  31. package/dist/components/primitives/BareInput.svelte +3 -1
  32. package/dist/components/primitives/Button.svelte +6 -2
  33. package/dist/components/primitives/Checkbox.svelte +5 -0
  34. package/dist/components/primitives/IconButton.svelte +3 -1
  35. package/dist/components/primitives/Input.svelte +19 -3
  36. package/dist/components/primitives/Radio.svelte +4 -1
  37. package/dist/components/primitives/Range.svelte +3 -1
  38. package/dist/components/primitives/Rating.svelte +9 -3
  39. package/dist/components/primitives/Select.svelte +21 -5
  40. package/dist/components/primitives/Tag.svelte +6 -10
  41. package/dist/components/primitives/Textarea.svelte +14 -2
  42. package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
  43. package/dist/components/scenes/ai/document-download.js +6 -2
  44. package/dist/components/scenes/ai/document-parse.js +24 -8
  45. package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
  46. package/dist/components/scenes/ai/highlight.js +18 -1
  47. package/dist/components/scenes/ai/markdown-parse.js +81 -28
  48. package/dist/components/scenes/ai/mermaid-render.js +13 -1
  49. package/dist/components/scenes/ai/safe-html.js +9 -3
  50. package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
  51. package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
  52. package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
  53. package/dist/components/scenes/app/FeedbackList.svelte +138 -21
  54. package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
  55. package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
  56. package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
  57. package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
  58. package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
  59. package/dist/components/scenes/app/ThemeSelector.svelte +29 -5
  60. package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
  61. package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
  62. package/dist/components/scenes/app/feedback-functions.js +6 -2
  63. package/dist/components/scenes/charts/Chart.svelte +55 -21
  64. package/dist/components/scenes/charts/Chart.svelte.d.ts +0 -1
  65. package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
  66. package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
  67. package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
  68. package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
  69. package/dist/components/scenes/charts/MetricCard.svelte +69 -0
  70. package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
  71. package/dist/components/scenes/charts/ReportCard.svelte +48 -0
  72. package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
  73. package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
  74. package/dist/components/scenes/charts/chart-presets.js +56 -0
  75. package/dist/components/scenes/charts/chart-types.d.ts +13 -2
  76. package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
  77. package/dist/components/scenes/charts/dashboard-types.js +1 -0
  78. package/dist/components/scenes/charts/index.d.ts +6 -2
  79. package/dist/components/scenes/charts/index.js +4 -1
  80. package/dist/components/scenes/charts/renderers/AreaChart.svelte +1 -0
  81. package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +1 -0
  82. package/dist/components/scenes/charts/renderers/BarChart.svelte +1 -0
  83. package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +1 -0
  84. package/dist/components/scenes/charts/renderers/LineChart.svelte +39 -12
  85. package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +1 -0
  86. package/dist/components/scenes/charts/renderers/PieChart.svelte +1 -0
  87. package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +1 -0
  88. package/dist/components/scenes/charts/renderers/ScatterChart.svelte +1 -0
  89. package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +1 -0
  90. package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
  91. package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
  92. package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
  93. package/dist/components/scenes/crud/CrudPage.svelte +34 -9
  94. package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
  95. package/dist/components/scenes/crud/crud-form-validation.js +27 -9
  96. package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
  97. package/dist/components/scenes/error/error-presets.js +30 -5
  98. package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
  99. package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
  100. package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
  101. package/dist/components/scenes/iam/AuthPanel.svelte +74 -16
  102. package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
  103. package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
  104. package/dist/components/scenes/iam/LoginForm.svelte +32 -8
  105. package/dist/components/scenes/iam/PasswordInput.svelte +50 -12
  106. package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
  107. package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
  108. package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
  109. package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
  110. package/dist/components/scenes/iam/UserProfile.svelte +41 -14
  111. package/dist/components/scenes/iam/auth-captcha.js +9 -2
  112. package/dist/components/scenes/iam/auth-error-message.d.ts +2 -2
  113. package/dist/components/scenes/iam/auth-error-message.js +16 -3
  114. package/dist/components/scenes/iam/password-utils.js +9 -2
  115. package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
  116. package/dist/components/scenes/storage/FileList.svelte +3 -1
  117. package/dist/components/scenes/storage/FileUpload.svelte +7 -2
  118. package/dist/components/scenes/types.d.ts +2 -2
  119. package/dist/guide-storage.js +12 -4
  120. package/dist/guide.svelte.js +59 -16
  121. package/dist/i18n.svelte.js +9 -3
  122. package/dist/internal/dialog-focus.d.ts +19 -0
  123. package/dist/internal/dialog-focus.js +104 -4
  124. package/dist/internal/form-validation.svelte.js +46 -15
  125. package/dist/internal/icon-safety.js +6 -2
  126. package/dist/message.svelte.js +6 -2
  127. package/dist/messagebox.svelte.js +6 -2
  128. package/dist/messages/en-US.json +7 -1
  129. package/dist/messages/ja-JP.json +7 -1
  130. package/dist/messages/zh-CN.json +7 -1
  131. package/dist/styles/eye-care.css +55 -0
  132. package/dist/styles/global.css +16 -0
  133. package/dist/styles/theme.css +1 -0
  134. package/dist/theme-config.d.ts +1 -1
  135. package/dist/theme-config.js +136 -21
  136. package/dist/toast.svelte.js +14 -3
  137. package/dist/types.d.ts +3 -3
  138. package/dist/utils.js +6 -2
  139. package/package.json +19 -19
@@ -12,20 +12,30 @@
12
12
  } = $props()
13
13
 
14
14
  let mode = $state<'mask' | 'outline'>('outline')
15
- let rect = $state({ x: 0.1, y: 0.1, width: 0.2, height: 0.2 })
15
+ let rect = $state({
16
+ x: 0.1,
17
+ y: 0.1,
18
+ width: 0.2,
19
+ height: 0.2,
20
+ })
16
21
  let start = $state<{ x: number, y: number } | null>(null)
17
22
  let selected = $state(false)
18
23
  let loading = $state(false)
19
24
  let error = $state('')
20
25
  let imageFailed = $state(false)
21
- useToastFeedback(() => imageFailed ? uiM('feedback_preview_failed') : '', 'warning')
26
+ useToastFeedback(() => imageFailed
27
+ ? uiM('feedback_preview_failed')
28
+ : '', 'warning')
22
29
  const url = $derived(imagePreviewUrl(attachment.url))
23
30
 
24
31
  function point(event: PointerEvent & { currentTarget: HTMLDivElement }) {
25
32
  const bounds = (event.currentTarget.querySelector('img') ?? event.currentTarget).getBoundingClientRect()
26
33
  if (!bounds.width || !bounds.height)
27
34
  return { x: 0, y: 0 }
28
- return { x: Math.max(0, Math.min(1, (event.clientX - bounds.left) / bounds.width)), y: Math.max(0, Math.min(1, (event.clientY - bounds.top) / bounds.height)) }
35
+ return {
36
+ x: Math.max(0, Math.min(1, (event.clientX - bounds.left) / bounds.width)),
37
+ y: Math.max(0, Math.min(1, (event.clientY - bounds.top) / bounds.height)),
38
+ }
29
39
  }
30
40
  function begin(event: PointerEvent & { currentTarget: HTMLDivElement }) {
31
41
  if (!onannotate || loading)
@@ -40,7 +50,12 @@
40
50
  if (!start)
41
51
  return
42
52
  const end = point(event)
43
- rect = { x: Math.min(start.x, end.x), y: Math.min(start.y, end.y), width: Math.abs(end.x - start.x), height: Math.abs(end.y - start.y) }
53
+ rect = {
54
+ x: Math.min(start.x, end.x),
55
+ y: Math.min(start.y, end.y),
56
+ width: Math.abs(end.x - start.x),
57
+ height: Math.abs(end.y - start.y),
58
+ }
44
59
  }
45
60
  function keydown(event: KeyboardEvent) {
46
61
  if (!onannotate || loading)
@@ -50,15 +65,37 @@
50
65
  selected = true
51
66
  return
52
67
  }
53
- if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.key))
68
+ if (![
69
+ 'ArrowLeft',
70
+ 'ArrowRight',
71
+ 'ArrowUp',
72
+ 'ArrowDown',
73
+ ].includes(event.key)) {
54
74
  return
75
+ }
55
76
  event.preventDefault()
56
77
  selected = true
57
- const dx = event.key === 'ArrowLeft' ? -0.01 : event.key === 'ArrowRight' ? 0.01 : 0
58
- const dy = event.key === 'ArrowUp' ? -0.01 : event.key === 'ArrowDown' ? 0.01 : 0
78
+ const dx = event.key === 'ArrowLeft'
79
+ ? -0.01
80
+ : event.key === 'ArrowRight'
81
+ ? 0.01
82
+ : 0
83
+ const dy = event.key === 'ArrowUp'
84
+ ? -0.01
85
+ : event.key === 'ArrowDown'
86
+ ? 0.01
87
+ : 0
59
88
  rect = event.shiftKey
60
- ? { ...rect, width: Math.max(0.01, Math.min(1 - rect.x, rect.width + dx)), height: Math.max(0.01, Math.min(1 - rect.y, rect.height + dy)) }
61
- : { ...rect, x: Math.max(0, Math.min(1 - rect.width, rect.x + dx)), y: Math.max(0, Math.min(1 - rect.height, rect.y + dy)) }
89
+ ? {
90
+ ...rect,
91
+ width: Math.max(0.01, Math.min(1 - rect.x, rect.width + dx)),
92
+ height: Math.max(0.01, Math.min(1 - rect.y, rect.height + dy)),
93
+ }
94
+ : {
95
+ ...rect,
96
+ x: Math.max(0, Math.min(1 - rect.width, rect.x + dx)),
97
+ y: Math.max(0, Math.min(1 - rect.height, rect.y + dy)),
98
+ }
62
99
  }
63
100
  function end(event: PointerEvent & { currentTarget: HTMLDivElement }) {
64
101
  move(event)
@@ -74,7 +111,15 @@
74
111
  loading = true
75
112
  error = ''
76
113
  try {
77
- await onannotate({ id: attachment.id, mode, rect: { ...rect, width: Math.min(rect.width, 1 - rect.x), height: Math.min(rect.height, 1 - rect.y) } })
114
+ await onannotate({
115
+ id: attachment.id,
116
+ mode,
117
+ rect: {
118
+ ...rect,
119
+ width: Math.min(rect.width, 1 - rect.x),
120
+ height: Math.min(rect.height, 1 - rect.y),
121
+ },
122
+ })
78
123
  selected = false
79
124
  }
80
125
  catch (cause) {
@@ -89,7 +134,9 @@
89
134
 
90
135
  {#if url}
91
136
  <div class='space-y-3 min-w-0'>
92
- <div class='relative w-fit max-w-full overflow-hidden rounded-lg border border-base-content/10 select-none' role='button' aria-label={attachment.name} aria-disabled={!onannotate} tabindex={onannotate ? 0 : -1} onkeydown={keydown} style:touch-action={onannotate ? 'none' : 'auto'} onpointerdown={begin} onpointermove={move} onpointerup={end} onpointercancel={cancel}>
137
+ <div class='relative w-fit max-w-full overflow-hidden rounded-lg border border-base-content/10 select-none' role='button' aria-label={attachment.name} aria-disabled={!onannotate} tabindex={onannotate
138
+ ? 0
139
+ : -1} onkeydown={keydown} style:touch-action={onannotate ? 'none' : 'auto'} onpointerdown={begin} onpointermove={move} onpointerup={end} onpointercancel={cancel}>
93
140
  <img src={url} alt={attachment.name} class='block max-w-full h-auto' draggable='false' referrerpolicy='no-referrer' onerror={() => imageFailed = true} onload={() => imageFailed = false} />
94
141
  {#if selected}
95
142
  <div class:mask-preview={mode === 'mask'} class='pointer-events-none absolute border-2 border-error' style:left={`${rect.x * 100}%`} style:top={`${rect.y * 100}%`} style:width={`${rect.width * 100}%`} style:height={`${rect.height * 100}%`}></div>
@@ -97,11 +144,15 @@
97
144
  </div>
98
145
  {#if onannotate && !imageFailed}
99
146
  <div class='flex flex-wrap gap-2'>
100
- <Button size='xs' variant={mode === 'outline' ? 'primary' : 'ghost'} onclick={() => {
147
+ <Button size='xs' variant={mode === 'outline'
148
+ ? 'primary'
149
+ : 'ghost'} onclick={() => {
101
150
  mode = 'outline'
102
151
  selected = true
103
152
  }}>{uiM('feedback_mark_outline')}</Button>
104
- <Button size='xs' variant={mode === 'mask' ? 'primary' : 'ghost'} onclick={() => {
153
+ <Button size='xs' variant={mode === 'mask'
154
+ ? 'primary'
155
+ : 'ghost'} onclick={() => {
105
156
  mode = 'mask'
106
157
  selected = true
107
158
  }}>{uiM('feedback_mark_mask')}</Button>
@@ -108,7 +108,9 @@
108
108
  })
109
109
  </script>
110
110
 
111
- <div {...dataAttributes} bind:this={containerRef} class='dropdown {align === 'end' ? 'dropdown-end' : ''} {open ? 'dropdown-open' : ''} {className}'>
111
+ <div {...dataAttributes} bind:this={containerRef} class='dropdown {align === 'end'
112
+ ? 'dropdown-end'
113
+ : ''} {open ? 'dropdown-open' : ''} {className}'>
112
114
  <BareButton
113
115
  type='button'
114
116
  class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'btn-sm gap-2 min-w-fit'}'
@@ -134,7 +136,9 @@
134
136
  {#each languages as lang (lang.value)}
135
137
  <BareButton
136
138
  type='button'
137
- class='flex items-center gap-2 w-full px-3 py-2 rounded-lg text-left transition-colors whitespace-nowrap {lang.value === currentLanguage ? 'bg-primary/10 text-primary' : 'hover:bg-base-200'}'
139
+ class='flex items-center gap-2 w-full px-3 py-2 rounded-lg text-left transition-colors whitespace-nowrap {lang.value === currentLanguage
140
+ ? 'bg-primary/10 text-primary'
141
+ : 'hover:bg-base-200'}'
138
142
  onclick={() => selectLanguage(lang.value)}
139
143
  >
140
144
  {#if lang.flag}
@@ -90,7 +90,9 @@
90
90
  <nav class='flex gap-1 overflow-x-auto lg:flex-col lg:overflow-visible'>
91
91
  {#each sections as section (section.id)}
92
92
  {#if section.href}
93
- <a href={section.href} class={navItemClass(section.id)} aria-current={section.id === active ? 'page' : undefined}>
93
+ <a href={section.href} class={navItemClass(section.id)} aria-current={section.id === active
94
+ ? 'page'
95
+ : undefined}>
94
96
  {#if section.icon}<span class='{section.icon} size-4 shrink-0'></span>{/if}
95
97
  <span class='whitespace-nowrap'>{section.label}</span>
96
98
  </a>
@@ -20,7 +20,7 @@
20
20
  <script lang='ts'>
21
21
  import type { ThemeInfo } from '../../../theme-config.js'
22
22
  import type { DataAttributes } from '../../../types.js'
23
- import { tick } from 'svelte'
23
+ import { onMount, tick } from 'svelte'
24
24
  import { uiM } from '../../../messages.js'
25
25
  import { THEME_GROUPS, THEMES } from '../../../theme-config.js'
26
26
  import { cn, getDataAttributes } from '../../../utils.js'
@@ -68,6 +68,11 @@
68
68
  const displaySelectLabel = $derived(selectLabel ?? uiM('theme_selector_label'))
69
69
  const menuId = $props.id()
70
70
 
71
+ // SSR 先渲染按钮,等客户端绑定点击和键盘事件后再启用。
72
+ let ready = $state(false)
73
+ onMount(() => {
74
+ ready = true
75
+ })
71
76
  let open = $state(false)
72
77
  let containerRef = $state<HTMLDivElement | null>(null)
73
78
 
@@ -95,15 +100,31 @@
95
100
  const opening = !open
96
101
  open = true
97
102
  await tick()
98
- const choices = [...containerRef?.querySelectorAll<HTMLButtonElement>('[data-theme-option]') ?? []]
103
+ const choices = [
104
+ ...containerRef?.querySelectorAll<HTMLButtonElement>('[data-theme-option]') ?? [],
105
+ ]
99
106
  const current = choices.findIndex(button => button === document.activeElement)
100
107
  const selected = choices.findIndex(button => button.dataset.themeOption === currentTheme)
101
- const index = event.key === 'Home' ? 0 : event.key === 'End' ? choices.length - 1 : opening ? Math.max(0, selected) : (current + (event.key === 'ArrowDown' ? 1 : -1) + choices.length) % choices.length
108
+ const index = event.key === 'Home'
109
+ ? 0
110
+ : event.key === 'End'
111
+ ? choices.length - 1
112
+ : opening
113
+ ? Math.max(0, selected)
114
+ : (current + (event.key === 'ArrowDown'
115
+ ? 1
116
+ : -1) + choices.length) % choices.length
102
117
  choices[index]?.focus()
103
118
  }
104
119
 
105
120
  function themeName(theme: ThemeInfo): string {
106
- return theme.id === 'high-contrast' ? uiM('theme_high_contrast') : theme.id === 'formal' ? uiM('theme_formal') : theme.name
121
+ return theme.id === 'high-contrast'
122
+ ? uiM('theme_high_contrast')
123
+ : theme.id === 'formal'
124
+ ? uiM('theme_formal')
125
+ : theme.id === 'eye-care'
126
+ ? uiM('theme_eye_care')
127
+ : theme.name
107
128
  }
108
129
 
109
130
  function renderThemePreview(theme: ThemeInfo) {
@@ -132,9 +153,12 @@
132
153
  })
133
154
  </script>
134
155
 
135
- <div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end' ? 'dropdown-end' : '', open ? 'dropdown-open' : '', className)}>
156
+ <div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end'
157
+ ? 'dropdown-end'
158
+ : '', open ? 'dropdown-open' : '', className)}>
136
159
  <button
137
160
  type='button'
161
+ disabled={!ready}
138
162
  class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'gap-2'}'
139
163
  onclick={() => (open = !open)}
140
164
  onkeydown={handleKeydown}
@@ -69,12 +69,16 @@
69
69
  }
70
70
  </script>
71
71
 
72
- <div {...dataAttributes} class='tooltip tooltip-bottom {className}' data-tip={isDark ? (labels.switchToLight ?? uiM('theme_switch_to_light')) : (labels.switchToDark ?? uiM('theme_switch_to_dark'))}>
72
+ <div {...dataAttributes} class='tooltip tooltip-bottom {className}' data-tip={isDark
73
+ ? (labels.switchToLight ?? uiM('theme_switch_to_light'))
74
+ : (labels.switchToDark ?? uiM('theme_switch_to_dark'))}>
73
75
  <IconButton
74
76
  variant='ghost'
75
77
  size='sm'
76
78
  onclick={toggleTheme}
77
- ariaLabel={isDark ? (labels.switchToLight ?? uiM('theme_switch_to_light')) : (labels.switchToDark ?? uiM('theme_switch_to_dark'))}
79
+ ariaLabel={isDark
80
+ ? (labels.switchToLight ?? uiM('theme_switch_to_light'))
81
+ : (labels.switchToDark ?? uiM('theme_switch_to_dark'))}
78
82
  >
79
83
  {#if isDark}
80
84
  <svg xmlns='http://www.w3.org/2000/svg' class='h-5 w-5' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'>
@@ -57,7 +57,7 @@
57
57
  {#if actions}<div class='ml-auto flex max-w-full shrink-0 flex-wrap items-center gap-1.5 sm:gap-2'>{@render actions()}</div>{/if}
58
58
  </header>
59
59
  {/if}
60
- <main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
60
+ <main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='relative flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
61
61
  {@render children()}
62
62
  </main>
63
63
  {#if footer}<footer class='shrink-0 border-t border-base-content/8 px-3 py-1 text-center text-xs text-base-content/45 sm:px-4'>{@render footer()}</footer>{/if}
@@ -41,7 +41,9 @@ export function notificationLabel(status) {
41
41
  * ```
42
42
  */
43
43
  export function feedbackTime(timestamp) {
44
- return Number.isFinite(timestamp) ? new Date(timestamp).toLocaleString(getUILocale()) : '—';
44
+ return Number.isFinite(timestamp)
45
+ ? new Date(timestamp).toLocaleString(getUILocale())
46
+ : '—';
45
47
  }
46
48
  /**
47
49
  * 按本地日历回填日期输入,避免 UTC 转换改变用户选择的日期。
@@ -72,7 +74,9 @@ export function feedbackDayBoundary(value, boundary) {
72
74
  return undefined;
73
75
  if (boundary === 'end')
74
76
  date.setDate(date.getDate() + 1);
75
- return date.getTime() - (boundary === 'end' ? 1 : 0);
77
+ return date.getTime() - (boundary === 'end'
78
+ ? 1
79
+ : 0);
76
80
  }
77
81
  /**
78
82
  * 以文本显示 JSON,不将诊断材料解释为 HTML。
@@ -20,18 +20,16 @@
20
20
  -->
21
21
  <script lang='ts'>
22
22
  import type { ChartProps, ChartSeries, ChartType } from './chart-types.js'
23
+ import { onMount } from 'svelte'
23
24
  import { uiM } from '../../../messages.js'
24
25
  import { cn, getDataAttributes } from '../../../utils.js'
26
+ import { resolveChartPreset } from './chart-presets.js'
25
27
  import { DAISYUI_CHART_COLORS, resolveChartColors } from './chart-theme.js'
26
- import AreaChart from './renderers/AreaChart.svelte'
27
- import BarChart from './renderers/BarChart.svelte'
28
- import LineChart from './renderers/LineChart.svelte'
29
- import PieChart from './renderers/PieChart.svelte'
30
- import ScatterChart from './renderers/ScatterChart.svelte'
31
- import 'layerchart/daisyui-5.css'
28
+ import ChartLoadError from './ChartLoadError.svelte'
32
29
 
33
30
  const {
34
- type,
31
+ type: requestedType,
32
+ preset,
35
33
  data = [],
36
34
  x,
37
35
  y,
@@ -46,8 +44,27 @@
46
44
  ...restProps
47
45
  }: ChartProps = $props()
48
46
 
47
+ const presetConfig = $derived(resolveChartPreset(preset))
48
+ const type = $derived(requestedType ?? presetConfig.type ?? 'line')
49
+ const nativeProps = $derived({
50
+ ...presetConfig.props,
51
+ ...restProps,
52
+ })
49
53
  const dataAttributes = $derived(getDataAttributes(restProps))
50
54
 
55
+ // 仅浏览器挂载且确有数据时加载对应图形;Svelte await 自动丢弃过期 Promise 的结果。
56
+ const renderers = {
57
+ bar: () => import('./renderers/BarChart.svelte'),
58
+ line: () => import('./renderers/LineChart.svelte'),
59
+ area: () => import('./renderers/AreaChart.svelte'),
60
+ pie: () => import('./renderers/PieChart.svelte'),
61
+ scatter: () => import('./renderers/ScatterChart.svelte'),
62
+ }
63
+ let mounted = $state(false)
64
+ onMount(() => {
65
+ mounted = true
66
+ })
67
+
51
68
  const chartSizeHeights: Record<NonNullable<ChartProps['size']>, number> = {
52
69
  sm: 200,
53
70
  md: 300,
@@ -58,10 +75,15 @@
58
75
 
59
76
  /** 图表可视高度优先尊重 LayerChart 原生 height,未传时使用 @h-ai/ui 的 size 预设。 */
60
77
  const chartHeight = $derived(
61
- typeof restProps.height === 'number' ? restProps.height : chartSizeHeights[size],
78
+ typeof nativeProps.height === 'number'
79
+ ? nativeProps.height
80
+ : chartSizeHeights[size],
62
81
  )
63
82
 
64
83
  const isEmpty = $derived(empty || data.length === 0)
84
+ const rendererPromise = $derived(mounted && !loading && !isEmpty
85
+ ? renderers[type]()
86
+ : undefined)
65
87
  const hasHeader = $derived(Boolean(title || description))
66
88
 
67
89
  const rootClass = $derived(
@@ -106,13 +128,15 @@
106
128
  const resolvedSeries = $derived(resolveChartColors(normalizedSeries))
107
129
 
108
130
  /** 饼图使用统一 x/y API 时,将 x 映射为 key/label,y 的第一项映射为 value。 */
109
- const pieValue = $derived(Array.isArray(y) ? y[0] : y)
131
+ const pieValue = $derived(Array.isArray(y)
132
+ ? y[0]
133
+ : y)
110
134
 
111
135
  const cartesianLayerProps = $derived({
112
136
  data,
113
137
  height: chartHeight,
114
138
  cRange: DAISYUI_CHART_COLORS,
115
- ...restProps,
139
+ ...nativeProps,
116
140
  orientation,
117
141
  series: resolvedSeries,
118
142
  x,
@@ -126,7 +150,7 @@
126
150
  label: x,
127
151
  value: pieValue,
128
152
  cRange: DAISYUI_CHART_COLORS,
129
- ...restProps,
153
+ ...nativeProps,
130
154
  series: resolvedSeries,
131
155
  })
132
156
  </script>
@@ -148,16 +172,26 @@
148
172
  <span class='loading loading-spinner loading-md text-primary' aria-label={uiM('chart_loading')}></span>
149
173
  {:else if isEmpty}
150
174
  <p class='text-sm text-base-content/50'>{uiM('chart_empty')}</p>
151
- {:else if type === 'bar'}
152
- <BarChart {...cartesianLayerProps} />
153
- {:else if type === 'line'}
154
- <LineChart {...cartesianLayerProps} />
155
- {:else if type === 'area'}
156
- <AreaChart {...cartesianLayerProps} />
157
- {:else if type === 'pie'}
158
- <PieChart {...pieLayerProps} />
159
- {:else if type === 'scatter'}
160
- <ScatterChart {...cartesianLayerProps} />
175
+ {:else if !mounted}
176
+ <div class='flex h-full items-center justify-center' role='status' aria-label={uiM('chart_loading')}>
177
+ <span class='loading loading-spinner loading-md text-primary'></span>
178
+ </div>
179
+ {:else}
180
+ {#await rendererPromise}
181
+ <div class='flex h-full items-center justify-center' role='status' aria-label={uiM('chart_loading')}>
182
+ <span class='loading loading-spinner loading-md text-primary'></span>
183
+ </div>
184
+ {:then renderer}
185
+ {#if renderer}
186
+ {@const Renderer = renderer.default}
187
+ <Renderer {...(type === 'pie'
188
+ ? pieLayerProps
189
+ : cartesianLayerProps)} />
190
+ {/if}
191
+ {:catch}
192
+ <!-- 浏览器可能缓存失败的模块请求;刷新文档后才能可靠重试同一资源。 -->
193
+ <ChartLoadError onretry={() => window.location.reload()} />
194
+ {/await}
161
195
  {/if}
162
196
  </div>
163
197
  </div>
@@ -1,5 +1,4 @@
1
1
  import type { ChartProps } from './chart-types.js';
2
- import 'layerchart/daisyui-5.css';
3
2
  /**
4
3
  * Chart
5
4
  * =============================================================================
@@ -0,0 +1,13 @@
1
+ <!-- 图形模块加载失败时使用统一 Toast,原位保留重试操作。 -->
2
+ <script lang='ts'>
3
+ import { uiM } from '../../../messages.js'
4
+ import { useToastFeedback } from '../../../toast.svelte.js'
5
+ import Button from '../../primitives/Button.svelte'
6
+ /** 重试由 Chart 重新创建本次动态导入。 */
7
+ const { onretry }: { onretry: () => void } = $props()
8
+ useToastFeedback(() => uiM('chart_load_failed'))
9
+ </script>
10
+
11
+ <div class='flex h-full items-center justify-center'>
12
+ <Button onclick={onretry} size='sm'>{uiM('chart_retry')}</Button>
13
+ </div>
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ onretry: () => void;
3
+ };
4
+ declare const ChartLoadError: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type ChartLoadError = ReturnType<typeof ChartLoadError>;
6
+ export default ChartLoadError;
@@ -0,0 +1,34 @@
1
+ <!--
2
+ @component DashboardGrid
3
+ 使用容器查询适配看板,不依赖视口宽度或图形引擎。
4
+ @example
5
+ ```ts
6
+ import { mount, unmount } from 'svelte'
7
+ import { DashboardGrid } from '@h-ai/ui'
8
+ const component = mount(DashboardGrid, { target: document.body, props: { label: 'Reports', columns: 2 } })
9
+ await unmount(component)
10
+ ```
11
+ -->
12
+ <script lang='ts'>
13
+ import type { DashboardGridProps } from './dashboard-types.js'
14
+ import { cn, getDataAttributes } from '../../../utils.js'
15
+
16
+ const { label, columns = 2, children, class: className = '', ...restProps }: DashboardGridProps = $props()
17
+ </script>
18
+
19
+ <div {...getDataAttributes(restProps)} role='group' aria-label={label} class={cn('hai-dashboard-grid min-w-0', className)} style={`--hai-dashboard-columns: ${columns}; --hai-dashboard-medium-columns: ${Math.min(columns, 2)};`}>
20
+ <div class='hai-dashboard-grid__items'>
21
+ {#if children}{@render children()}{/if}
22
+ </div>
23
+ </div>
24
+
25
+ <style>
26
+ .hai-dashboard-grid { container: hai-dashboard / inline-size; }
27
+ .hai-dashboard-grid__items { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
28
+ @container hai-dashboard (min-width: 40rem) {
29
+ .hai-dashboard-grid__items { grid-template-columns: repeat(var(--hai-dashboard-medium-columns), minmax(0, 1fr)); }
30
+ }
31
+ @container hai-dashboard (min-width: 64rem) {
32
+ .hai-dashboard-grid__items { grid-template-columns: repeat(var(--hai-dashboard-columns), minmax(0, 1fr)); }
33
+ }
34
+ </style>
@@ -0,0 +1,15 @@
1
+ import type { DashboardGridProps } from './dashboard-types.js';
2
+ /**
3
+ * DashboardGrid
4
+ * 使用容器查询适配看板,不依赖视口宽度或图形引擎。
5
+ * @example
6
+ * ```ts
7
+ * import { mount, unmount } from 'svelte'
8
+ * import { DashboardGrid } from '@h-ai/ui'
9
+ * const component = mount(DashboardGrid, { target: document.body, props: { label: 'Reports', columns: 2 } })
10
+ * await unmount(component)
11
+ * ```
12
+ */
13
+ declare const DashboardGrid: import("svelte").Component<DashboardGridProps, {}, "">;
14
+ type DashboardGrid = ReturnType<typeof DashboardGrid>;
15
+ export default DashboardGrid;
@@ -0,0 +1,69 @@
1
+ <!--
2
+ @component MetricCard
3
+ 指标卡不依赖图形引擎;可通过 children 按需补充迷你趋势图。
4
+ @example
5
+ ```ts
6
+ import { mount, unmount } from 'svelte'
7
+ import { MetricCard } from '@h-ai/ui'
8
+ const component = mount(MetricCard, { target: document.body, props: { title: 'Revenue', value: '128,430', trend: 12.8, trendLabel: 'vs previous month', trendTone: 'success' } })
9
+ await unmount(component)
10
+ ```
11
+ -->
12
+ <script lang='ts'>
13
+ import type { MetricCardProps } from './dashboard-types.js'
14
+ import { getUILocale, uiM } from '../../../messages.js'
15
+ import { cn, getDataAttributes } from '../../../utils.js'
16
+ import Card from '../../compounds/Card.svelte'
17
+
18
+ const { title, value, unit = '', trend, trendLabel = '', trendTone = 'neutral', description = '', loading = false, children, class: className = '', ...restProps }: MetricCardProps = $props()
19
+ const hasValue = $derived(value != null && (typeof value !== 'number' || Number.isFinite(value)))
20
+ const hasTrend = $derived(typeof trend === 'number' && Number.isFinite(trend))
21
+ const direction = $derived((trend ?? 0) > 0
22
+ ? 'up'
23
+ : (trend ?? 0) < 0
24
+ ? 'down'
25
+ : 'flat')
26
+ const trendText = $derived(new Intl.NumberFormat(getUILocale(), { style: 'percent', maximumFractionDigits: 1, signDisplay: 'exceptZero' }).format((trend ?? 0) / 100))
27
+ const toneClass = {
28
+ success: 'text-success',
29
+ warning: 'text-warning',
30
+ error: 'text-error',
31
+ neutral: 'text-base-content',
32
+ }
33
+ </script>
34
+
35
+ <Card {...getDataAttributes(restProps)} class={cn('hai-metric-card min-w-0', className)} shadow={false}>
36
+ <div aria-busy={loading} class='flex min-w-0 flex-col gap-2'>
37
+ <h2 class='text-sm font-medium text-base-content/80'>{title}</h2>
38
+ {#if loading}
39
+ <div role='status' aria-label={uiM('chart_loading')} class='skeleton h-9 w-32'></div>
40
+ {:else}
41
+ <div class='flex min-w-0 flex-wrap items-baseline gap-x-2'>
42
+ <span class='break-words text-3xl font-semibold tracking-tight tabular-nums'>{hasValue ? value : '—'}</span>
43
+ {#if unit && hasValue}<span class='text-sm text-base-content/80'>{unit}</span>{/if}
44
+ </div>
45
+ {#if hasTrend}
46
+ <div class='flex flex-wrap items-center gap-x-2 gap-y-1 text-sm'>
47
+ <span data-trend-direction={direction} class={cn('inline-flex items-center gap-1 font-medium tabular-nums', toneClass[trendTone])}>
48
+ <svg aria-hidden='true' viewBox='0 0 20 20' class='size-4 shrink-0' fill='none' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'>
49
+ <path d={direction === 'up'
50
+ ? 'M3 14 8 9 12 12 17 5 M12 5h5v5'
51
+ : direction === 'down'
52
+ ? 'M3 6 8 11 12 8 17 15 M12 15h5v-5'
53
+ : 'M3 10h14 m-4 -4 4 4 -4 4'}></path>
54
+ </svg>
55
+ <span class='sr-only'>{uiM(direction === 'up'
56
+ ? 'metric_increase'
57
+ : direction === 'down'
58
+ ? 'metric_decrease'
59
+ : 'metric_unchanged')}</span>
60
+ {trendText}
61
+ </span>
62
+ {#if trendLabel}<span class='text-base-content/80'>{trendLabel}</span>{/if}
63
+ </div>
64
+ {/if}
65
+ {#if children}{@render children()}{/if}
66
+ {/if}
67
+ {#if description}<p class='break-words text-xs text-base-content/80'>{description}</p>{/if}
68
+ </div>
69
+ </Card>
@@ -0,0 +1,15 @@
1
+ import type { MetricCardProps } from './dashboard-types.js';
2
+ /**
3
+ * MetricCard
4
+ * 指标卡不依赖图形引擎;可通过 children 按需补充迷你趋势图。
5
+ * @example
6
+ * ```ts
7
+ * import { mount, unmount } from 'svelte'
8
+ * import { MetricCard } from '@h-ai/ui'
9
+ * const component = mount(MetricCard, { target: document.body, props: { title: 'Revenue', value: '128,430', trend: 12.8, trendLabel: 'vs previous month', trendTone: 'success' } })
10
+ * await unmount(component)
11
+ * ```
12
+ */
13
+ declare const MetricCard: import("svelte").Component<MetricCardProps, {}, "">;
14
+ type MetricCard = ReturnType<typeof MetricCard>;
15
+ export default MetricCard;
@@ -0,0 +1,48 @@
1
+ <!--
2
+ @component ReportCard
3
+ 复用 Card 的报表容器,内容插槽不限制 LayerChart 图形能力。
4
+ @example
5
+ ```ts
6
+ import { mount, unmount } from 'svelte'
7
+ import { ReportCard } from '@h-ai/ui'
8
+ const component = mount(ReportCard, { target: document.body, props: { title: 'Revenue', empty: true } })
9
+ await unmount(component)
10
+ ```
11
+ -->
12
+ <script lang='ts'>
13
+ import type { ReportCardProps } from './dashboard-types.js'
14
+ import { uiM } from '../../../messages.js'
15
+ import { cn, getDataAttributes } from '../../../utils.js'
16
+ import Card from '../../compounds/Card.svelte'
17
+
18
+ const { title, description = '', actions, children, footer, loading = false, empty = false, minHeight = 240, class: className = '', ...restProps }: ReportCardProps = $props()
19
+ const titleId = $props.id()
20
+ </script>
21
+
22
+ <Card {...getDataAttributes(restProps)} class={cn('hai-report-card min-w-0', className)} shadow={false}>
23
+ {#snippet header()}
24
+ <div class='flex w-full min-w-0 flex-wrap items-start justify-between gap-3'>
25
+ <div class='min-w-0'>
26
+ <h2 id={titleId} class='break-words text-sm font-semibold'>{title}</h2>
27
+ {#if description}<p class='mt-1 break-words text-xs font-normal text-base-content/80'>{description}</p>{/if}
28
+ </div>
29
+ {#if actions}<div class='flex shrink-0 flex-wrap gap-2 font-normal'>{@render actions()}</div>{/if}
30
+ </div>
31
+ {/snippet}
32
+ <section aria-labelledby={titleId} aria-busy={loading} class='min-w-0' style={`min-height: ${Math.max(0, minHeight)}px;`}>
33
+ {#if loading || empty}
34
+ <div class='flex items-center justify-center' style={`min-height: ${Math.max(0, minHeight)}px;`}>
35
+ {#if loading}
36
+ <span role='status' class='loading loading-spinner loading-md text-primary' aria-label={uiM('chart_loading')}></span>
37
+ {:else}
38
+ <p class='text-sm text-base-content/80'>{uiM('chart_empty')}</p>
39
+ {/if}
40
+ </div>
41
+ {:else if children}
42
+ {@render children()}
43
+ {/if}
44
+ </section>
45
+ {#if footer}
46
+ <div class='min-w-0 border-t border-base-300 pt-3 text-xs text-base-content/80'>{@render footer()}</div>
47
+ {/if}
48
+ </Card>
@@ -0,0 +1,15 @@
1
+ import type { ReportCardProps } from './dashboard-types.js';
2
+ /**
3
+ * ReportCard
4
+ * 复用 Card 的报表容器,内容插槽不限制 LayerChart 图形能力。
5
+ * @example
6
+ * ```ts
7
+ * import { mount, unmount } from 'svelte'
8
+ * import { ReportCard } from '@h-ai/ui'
9
+ * const component = mount(ReportCard, { target: document.body, props: { title: 'Revenue', empty: true } })
10
+ * await unmount(component)
11
+ * ```
12
+ */
13
+ declare const ReportCard: import("svelte").Component<ReportCardProps, {}, "">;
14
+ type ReportCard = ReturnType<typeof ReportCard>;
15
+ export default ReportCard;