@snowui-design-system/components 0.1.0 → 0.2.0-alpha.4

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 (319) hide show
  1. package/README.md +1 -2
  2. package/package.json +9 -3
  3. package/src/components/Accordion.md +218 -0
  4. package/src/components/Accordion.svelte +301 -0
  5. package/src/components/Accordion.test.ts +126 -0
  6. package/src/components/AccordionItem.md +114 -0
  7. package/src/components/AccordionItem.svelte +389 -0
  8. package/src/components/AccordionItem.test.ts +52 -0
  9. package/src/components/Avatar.md +54 -36
  10. package/src/components/Avatar.svelte +73 -126
  11. package/src/components/AvatarGroup.md +17 -14
  12. package/src/components/AvatarGroup.svelte +12 -50
  13. package/src/components/AvatarGroup.test.ts +69 -68
  14. package/src/components/Badge.md +53 -8
  15. package/src/components/Badge.svelte +303 -79
  16. package/src/components/Badge.test.ts +47 -0
  17. package/src/components/Breadcrumb.md +164 -0
  18. package/src/components/Breadcrumb.svelte +330 -0
  19. package/src/components/Breadcrumb.test.ts +154 -0
  20. package/src/components/Button.md +243 -57
  21. package/src/components/Button.svelte +278 -177
  22. package/src/components/Button.test.ts +175 -86
  23. package/src/components/ButtonGroup.md +140 -0
  24. package/src/components/ButtonGroup.svelte +491 -0
  25. package/src/components/ButtonGroup.test.ts +58 -0
  26. package/src/components/Card.md +186 -0
  27. package/src/components/Card.svelte +408 -0
  28. package/src/components/Card.test.ts +193 -0
  29. package/src/components/Checkbox.md +14 -10
  30. package/src/components/Checkbox.svelte +39 -99
  31. package/src/components/Chip.md +185 -0
  32. package/src/components/Chip.svelte +241 -0
  33. package/src/components/Chip.test.ts +117 -0
  34. package/src/components/CodeBlock.md +29 -16
  35. package/src/components/CodeBlock.svelte +132 -352
  36. package/src/components/CodeBlock.test.ts +15 -1
  37. package/src/components/CopyButton.md +41 -0
  38. package/src/components/CopyButton.svelte +164 -0
  39. package/src/components/CopyButton.test.ts +26 -0
  40. package/src/components/Dialog.md +95 -0
  41. package/src/components/Dialog.svelte +416 -0
  42. package/src/components/Dialog.test.ts +145 -0
  43. package/src/components/ExpandButton.md +41 -0
  44. package/src/components/ExpandButton.svelte +103 -0
  45. package/src/components/ExpandButton.test.ts +18 -0
  46. package/src/components/Form.md +4 -3
  47. package/src/components/Form.test.ts +72 -73
  48. package/src/components/Frame.md +243 -0
  49. package/src/components/Frame.svelte +208 -87
  50. package/src/components/Frame.test.ts +121 -0
  51. package/src/components/Icon.md +34 -6
  52. package/src/components/Icon.svelte +46 -95
  53. package/src/components/Image.md +24 -13
  54. package/src/components/Image.svelte +42 -128
  55. package/src/components/ImageGroup.md +6 -7
  56. package/src/components/ImageGroup.svelte +1 -28
  57. package/src/components/Indicator.md +92 -0
  58. package/src/components/Indicator.svelte +490 -0
  59. package/src/components/Indicator.test.ts +57 -0
  60. package/src/components/Input.md +81 -28
  61. package/src/components/Input.svelte +291 -178
  62. package/src/components/Input.test.ts +85 -48
  63. package/src/components/Kbd.md +0 -3
  64. package/src/components/Kbd.svelte +0 -1
  65. package/src/components/Link.md +192 -0
  66. package/src/components/Link.svelte +464 -0
  67. package/src/components/Link.test.ts +110 -0
  68. package/src/components/Listbox.md +52 -10
  69. package/src/components/Listbox.svelte +204 -50
  70. package/src/components/Listbox.test.ts +76 -33
  71. package/src/components/LocaleProvider.md +52 -0
  72. package/src/components/LocaleProvider.svelte +30 -0
  73. package/src/components/LocaleProvider.test.ts +32 -0
  74. package/src/components/MenuItem.md +23 -9
  75. package/src/components/MenuItem.svelte +57 -47
  76. package/src/components/MenuItem.test.ts +72 -65
  77. package/src/components/Pagination.md +504 -0
  78. package/src/components/Pagination.svelte +958 -0
  79. package/src/components/Pagination.test.ts +316 -0
  80. package/src/components/Popover.md +245 -42
  81. package/src/components/Popover.svelte +558 -127
  82. package/src/components/Popover.test.ts +361 -44
  83. package/src/components/Progress.md +91 -0
  84. package/src/components/Progress.svelte +374 -0
  85. package/src/components/Progress.test.ts +56 -0
  86. package/src/components/Radio.md +4 -6
  87. package/src/components/Radio.svelte +25 -117
  88. package/src/components/ScrollArea.md +116 -0
  89. package/src/components/ScrollArea.svelte +180 -0
  90. package/src/components/ScrollArea.test.ts +84 -0
  91. package/src/components/SearchInput.md +135 -0
  92. package/src/components/SearchInput.svelte +153 -0
  93. package/src/components/SearchInput.test.ts +61 -0
  94. package/src/components/Select.md +39 -8
  95. package/src/components/Select.svelte +196 -45
  96. package/src/components/Select.test.ts +79 -41
  97. package/src/components/SelectButton.md +50 -0
  98. package/src/components/SelectButton.svelte +186 -0
  99. package/src/components/SelectButton.test.ts +142 -0
  100. package/src/components/Separator.md +89 -0
  101. package/src/components/Separator.svelte +143 -0
  102. package/src/components/Separator.test.ts +35 -0
  103. package/src/components/Skeleton.md +2 -5
  104. package/src/components/Skeleton.svelte +202 -7
  105. package/src/components/Skeleton.test.ts +10 -10
  106. package/src/components/Slider.md +101 -0
  107. package/src/components/Slider.svelte +566 -0
  108. package/src/components/Slider.test.ts +51 -0
  109. package/src/components/Spinner.md +3 -4
  110. package/src/components/Spinner.svelte +11 -23
  111. package/src/components/{Toggle.md → Switch.md} +20 -21
  112. package/src/components/Switch.svelte +314 -0
  113. package/src/components/Switch.test.ts +57 -0
  114. package/src/components/Table.md +249 -0
  115. package/src/components/Table.svelte +139 -0
  116. package/src/components/Table.test.ts +64 -0
  117. package/src/components/TableBody.md +63 -0
  118. package/src/components/TableBody.svelte +78 -0
  119. package/src/components/TableBody.test.ts +13 -0
  120. package/src/components/TableCell.md +89 -0
  121. package/src/components/TableCell.svelte +368 -0
  122. package/src/components/TableCell.test.ts +51 -0
  123. package/src/components/TableHead.md +129 -0
  124. package/src/components/TableHead.svelte +281 -0
  125. package/src/components/TableHead.test.ts +44 -0
  126. package/src/components/TableHeader.md +26 -0
  127. package/src/components/TableHeader.svelte +10 -0
  128. package/src/components/TableHeader.test.ts +3 -0
  129. package/src/components/TableRow.md +36 -0
  130. package/src/components/TableRow.svelte +64 -0
  131. package/src/components/TableRow.test.ts +2 -0
  132. package/src/components/TableToolbar.svelte +260 -0
  133. package/src/components/Tag.md +270 -0
  134. package/src/components/Tag.svelte +462 -0
  135. package/src/components/Tag.test.ts +91 -0
  136. package/src/components/Text.md +87 -25
  137. package/src/components/Text.svelte +467 -93
  138. package/src/components/Text.test.ts +21 -36
  139. package/src/components/Textarea.md +22 -7
  140. package/src/components/Textarea.svelte +76 -155
  141. package/src/components/Textarea.test.ts +12 -5
  142. package/src/components/Tooltip.md +101 -12
  143. package/src/components/Tooltip.svelte +581 -108
  144. package/src/components/Tooltip.test.ts +63 -1
  145. package/src/context.ts +93 -5
  146. package/src/dev.ts +6 -10
  147. package/src/i18n/locale.svelte.ts +60 -0
  148. package/src/i18n/messages.ts +45 -0
  149. package/src/index.ts +177 -2
  150. package/src/keys.ts +7 -0
  151. package/src/lib/clipboard.ts +10 -0
  152. package/src/lib/color.md +36 -0
  153. package/src/lib/color.ts +57 -0
  154. package/src/lib/date-format.md +37 -0
  155. package/src/lib/date-format.ts +130 -0
  156. package/src/lib/edge-fade.md +101 -0
  157. package/src/lib/edge-fade.ts +55 -0
  158. package/src/lib/floating-position.md +20 -0
  159. package/src/lib/floating-position.ts +107 -0
  160. package/src/lib/number-format.md +40 -0
  161. package/src/lib/number-format.ts +132 -0
  162. package/src/lib/overlay-scrollbar.md +36 -0
  163. package/src/lib/overlay-scrollbar.svelte.ts +221 -0
  164. package/src/lib/overlay-trigger-timing.md +15 -0
  165. package/src/lib/overlay-trigger-timing.ts +8 -0
  166. package/src/lib/progressive-blur.md +95 -0
  167. package/src/lib/progressive-blur.ts +266 -0
  168. package/src/lib/resizable.md +41 -0
  169. package/src/lib/resizable.ts +211 -0
  170. package/src/lib/table-context.svelte.ts +129 -0
  171. package/src/lib/table-row-context.svelte.ts +16 -0
  172. package/src/lib/tooltip-behavior.ts +39 -0
  173. package/src/lib/tooltip-delay.md +33 -0
  174. package/src/lib/tooltip-delay.ts +49 -0
  175. package/src/lib/tooltip-overlay.md +30 -0
  176. package/src/lib/tooltip-overlay.ts +64 -0
  177. package/src/lib/truncate.md +7 -2
  178. package/src/lib/truncate.ts +105 -10
  179. package/src/logic/README.md +17 -7
  180. package/src/logic/component-parts.md +32 -0
  181. package/src/logic/component-parts.svelte.ts +130 -0
  182. package/src/logic/dialog.md +30 -0
  183. package/src/logic/dialog.svelte.ts +88 -0
  184. package/src/logic/frame-actions.md +28 -0
  185. package/src/logic/frame-actions.svelte.ts +49 -0
  186. package/src/logic/frame-class-state.md +21 -0
  187. package/src/logic/frame-class-state.svelte.ts +163 -0
  188. package/src/logic/frame-dom-runtime.svelte.ts +51 -0
  189. package/src/logic/frame-inline-style.md +56 -0
  190. package/src/logic/frame-inline-style.svelte.ts +623 -0
  191. package/src/logic/frame-motion-defaults.md +90 -9
  192. package/src/logic/frame-motion-defaults.ts +55 -49
  193. package/src/logic/frame-motion.svelte.ts +173 -0
  194. package/src/logic/frame-perception.md +83 -0
  195. package/src/logic/frame-perception.svelte.ts +273 -0
  196. package/src/logic/frame-prop-filter.ts +7 -1
  197. package/src/logic/frame-scale-observer.md +153 -0
  198. package/src/logic/frame-scale-observer.svelte.ts +98 -0
  199. package/src/logic/frame-scale-resolver.md +25 -0
  200. package/src/logic/frame-scale-resolver.svelte.ts +56 -0
  201. package/src/logic/frame-state-value.md +74 -0
  202. package/src/logic/frame-state-value.ts +30 -0
  203. package/src/logic/frame-state.svelte.ts +426 -0
  204. package/src/logic/frame-truncation.md +17 -3
  205. package/src/logic/frame-truncation.svelte.ts +23 -43
  206. package/src/logic/frame-types.md +2 -1
  207. package/src/logic/frame-types.ts +41 -7
  208. package/src/logic/frame-utils.md +4 -0
  209. package/src/logic/frame-utils.ts +54 -26
  210. package/src/logic/image-preview.md +9 -2
  211. package/src/logic/image-preview.ts +33 -7
  212. package/src/logic/morph.md +19 -0
  213. package/src/logic/morph.ts +7 -0
  214. package/src/logic/motion-config.ts +49 -3
  215. package/src/logic/motion-engine.md +43 -0
  216. package/src/logic/motion-engine.ts +272 -0
  217. package/src/logic/overlay-presence.svelte.ts +71 -0
  218. package/src/logic/popover.md +89 -0
  219. package/src/logic/popover.svelte.ts +236 -0
  220. package/src/logic/resource-size.md +21 -0
  221. package/src/logic/resource-size.ts +53 -0
  222. package/src/logic/text-collapse.md +2 -1
  223. package/src/logic/text-collapse.svelte.ts +1 -1
  224. package/src/logic/wc-adapter.ts +1 -1
  225. package/src/motion/README.md +97 -37
  226. package/src/motion/{defaults/bridge.md → bridge.md} +24 -4
  227. package/src/motion/{defaults/bridge.ts → bridge.ts} +16 -5
  228. package/src/motion/{defaults/content-crossfade.ts → content-crossfade.ts} +1 -1
  229. package/src/motion/{defaults/expand.md → expand.md} +2 -2
  230. package/src/motion/{defaults/expand.ts → expand.ts} +4 -3
  231. package/src/motion/fade-in.md +40 -0
  232. package/src/motion/fade-in.ts +14 -0
  233. package/src/motion/{defaults/fade-out.md → fade-out.md} +2 -2
  234. package/src/motion/fade-out.ts +14 -0
  235. package/src/motion/{defaults/morph.md → morph.md} +1 -1
  236. package/src/motion/{defaults/morph.ts → morph.ts} +3 -3
  237. package/src/motion/move.md +179 -0
  238. package/src/motion/move.ts +74 -0
  239. package/src/motion/number.md +50 -0
  240. package/src/motion/number.ts +30 -0
  241. package/src/motion/presets/README.md +50 -0
  242. package/src/motion/presets/dialog.md +20 -0
  243. package/src/motion/presets/dialog.ts +47 -0
  244. package/src/motion/presets/effects.md +32 -0
  245. package/src/motion/presets/effects.ts +111 -0
  246. package/src/motion/presets/generic.md +27 -0
  247. package/src/motion/presets/generic.ts +32 -0
  248. package/src/motion/presets/overlay.md +21 -0
  249. package/src/motion/presets/overlay.ts +18 -0
  250. package/src/motion/presets/replacement.md +19 -0
  251. package/src/motion/presets/replacement.ts +6 -0
  252. package/src/motion/presets/resize.md +23 -0
  253. package/src/motion/presets/resize.ts +16 -0
  254. package/src/motion/presets/tab.md +21 -0
  255. package/src/motion/presets/tab.ts +19 -0
  256. package/src/motion/presets/tooltip.md +20 -0
  257. package/src/motion/presets/tooltip.ts +37 -0
  258. package/src/motion/presets/utils.md +15 -0
  259. package/src/motion/presets/utils.ts +11 -0
  260. package/src/motion/primitives.md +22 -0
  261. package/src/motion/primitives.ts +46 -0
  262. package/src/motion/{defaults/replace.md → replace.md} +2 -2
  263. package/src/motion/{defaults/replace.ts → replace.ts} +4 -4
  264. package/src/motion/{defaults/rotate.md → rotate.md} +4 -4
  265. package/src/motion/{defaults/rotate.ts → rotate.ts} +4 -3
  266. package/src/motion/scale-in.md +40 -0
  267. package/src/motion/scale-in.ts +19 -0
  268. package/src/motion/spring.md +19 -0
  269. package/src/motion/spring.ts +96 -0
  270. package/src/motion/tokens.md +45 -0
  271. package/src/motion/tokens.ts +80 -0
  272. package/src/motion/{defaults/while-2xl.ts → while-2xl.ts} +1 -1
  273. package/src/motion/{defaults/while-active.ts → while-active.ts} +1 -1
  274. package/src/motion/while-appear.ts +10 -0
  275. package/src/motion/{defaults/while-click.ts → while-click.ts} +1 -1
  276. package/src/motion/{defaults/while-collapsed.ts → while-collapsed.ts} +1 -1
  277. package/src/motion/{defaults/while-disabled.ts → while-disabled.ts} +3 -2
  278. package/src/motion/while-disappear.ts +10 -0
  279. package/src/motion/{defaults/while-drag.ts → while-drag.ts} +1 -1
  280. package/src/motion/{defaults/while-editing.ts → while-editing.ts} +1 -1
  281. package/src/motion/{defaults/while-expanded.ts → while-expanded.ts} +1 -1
  282. package/src/motion/{defaults/while-focus.ts → while-focus.ts} +1 -1
  283. package/src/motion/{defaults/while-hover.ts → while-hover.ts} +1 -1
  284. package/src/motion/{defaults/while-idle.ts → while-idle.ts} +1 -1
  285. package/src/motion/{defaults/while-key.ts → while-key.ts} +1 -1
  286. package/src/motion/{defaults/while-lg.ts → while-lg.ts} +1 -1
  287. package/src/motion/{defaults/while-load.ts → while-load.ts} +3 -2
  288. package/src/motion/{defaults/while-md.ts → while-md.ts} +1 -1
  289. package/src/motion/{defaults/while-reload.ts → while-reload.ts} +1 -1
  290. package/src/motion/{defaults/while-scroll.ts → while-scroll.ts} +1 -1
  291. package/src/motion/{defaults/while-sm.ts → while-sm.ts} +1 -1
  292. package/src/motion/{defaults/while-uploading.ts → while-uploading.ts} +1 -1
  293. package/src/motion/{defaults/while-validating.ts → while-validating.ts} +1 -1
  294. package/src/motion/{defaults/while-xl.ts → while-xl.ts} +1 -1
  295. package/src/motion/{defaults/while-xs.ts → while-xs.ts} +1 -1
  296. package/src/styles/auto-layout.css +92 -10
  297. package/src/styles/layout.css +370 -30
  298. package/src/styles/scrollbar.css +72 -7
  299. package/src/App.svelte +0 -103
  300. package/src/components/QuickAction.md +0 -146
  301. package/src/components/QuickAction.svelte +0 -161
  302. package/src/components/QuickAction.test.ts +0 -299
  303. package/src/components/Test.md +0 -72
  304. package/src/components/Test.svelte +0 -106
  305. package/src/components/Test.test.ts +0 -27
  306. package/src/components/Toggle.svelte +0 -384
  307. package/src/components/Toggle.test.ts +0 -57
  308. package/src/logic/frame-profile.md +0 -156
  309. package/src/logic/frame-profile.ts +0 -130
  310. package/src/motion/NumberFlow.md +0 -16
  311. package/src/motion/defaults/fade-out.ts +0 -14
  312. package/src/motion/defaults/move.md +0 -81
  313. package/src/motion/defaults/move.ts +0 -31
  314. package/src/motion/defaults/number.md +0 -41
  315. package/src/motion/defaults/number.ts +0 -17
  316. package/src/motion/defaults/while-appear.ts +0 -12
  317. package/src/motion/defaults/while-disappear.ts +0 -12
  318. package/src//344/273/243/347/240/201.txt +0 -61
  319. /package/src/motion/{defaults/rotate.css → rotate.css} +0 -0
@@ -0,0 +1,74 @@
1
+ # frame-state-value.ts
2
+
3
+ > **版本**: v1.0.0
4
+ > **职责**: 为子组件提供只读的父 Frame 状态值解析能力。
5
+
6
+ ## 1. 能力边界
7
+
8
+ `frame-state-value.ts` 只做一件事:根据最近父级 Frame Context 的 `currentState`,从 `StateValueMap<T>` 中解析当前值。
9
+
10
+ 它不创建状态机、不写 DOM、不修改父 Frame,也不触发其他组件行为。
11
+
12
+ ## 2. API
13
+
14
+ ```ts
15
+ type StateValueMap<T> = Partial<Record<CoreState, T>>;
16
+
17
+ resolveParentStateValue<T>(
18
+ map: StateValueMap<T> | undefined,
19
+ parentContext: { currentState?: CoreState } | undefined,
20
+ fallback?: T,
21
+ ): T | undefined
22
+ ```
23
+
24
+ 解析顺序:
25
+
26
+ 1. 命中 `map[currentState]` 时返回当前状态值。
27
+ 2. 未命中时回退 `map.Idle`。
28
+ 3. 仍未命中时返回 `fallback`。
29
+
30
+ ### 2.1 状态命名边界
31
+
32
+ `Load` 是 Frame loading / skeleton 协议状态名。若组件只是表达“任务处理中、等待完成、稍后自动进入 Active”等业务等待态,优先使用 `Pending` 这类自定义状态名,避免误触发骨架屏协议。
33
+
34
+ ```svelte
35
+ <Button
36
+ Click={{ Idle: "Pending", Active: "Idle" }}
37
+ Pending={["Active", "auto"]}
38
+ >
39
+ <Icon stateIcon={{ Idle: null, Pending: Spinner, Active: Check }} />
40
+ <Text stateText={{ Idle: "Ready", Pending: "Loading...", Active: "Completed" }} />
41
+ <Badge stateCount={{ Idle: 0, Active: 1 }} />
42
+ </Button>
43
+ ```
44
+
45
+ ## 3. 已接入组件
46
+
47
+ | 组件 | 关键字 | 说明 |
48
+ | --- | --- | --- |
49
+ | `Icon` | `stateIcon` | 根据父 Frame 状态切换图标组件;状态值为 `null` 时隐藏 Icon。 |
50
+ | `Text` | `stateText` | 根据父 Frame 状态切换文本内容。 |
51
+ | `Badge` | `stateCount` | 根据父 Frame 状态切换计数;默认 `0` 隐藏,`>= 1` 显示并走出入场动效。 |
52
+
53
+ ## 4. 归属
54
+
55
+ 该能力属于 OSS:子组件只读取父 Frame 已提供的 Context,并只改变自身展示,作用半径仍为 1 个 Frame 子树内的自包含消费,不涉及 FramePro 的跨组件编排、联动控制或样式编排。
56
+
57
+ ## 5. 扩展原则
58
+
59
+ 新增子组件状态映射关键字时必须满足:
60
+
61
+ 1. 只读最近父 Frame Context。
62
+ 2. 只改变组件自身公开 prop 对应的展示。
63
+ 3. 不修改父 Frame 状态。
64
+ 4. 不触发兄弟组件或其他 Frame 行为。
65
+ 5. 不新增宿主专用 prop;能力应落在真正改变形态或内容的子组件上。
66
+
67
+ 候选扩展示例:
68
+
69
+ | 组件 | 候选关键字 | 用途 |
70
+ | --- | --- | --- |
71
+ | `Badge` | `stateLabel` / `stateTone` | 状态徽标文字或语义色 |
72
+ | `Avatar` | `stateSrc` / `stateFallback` | 状态头像或回退字符 |
73
+ | `Spinner` | `stateVisible` | 按父状态显隐 |
74
+ | `Kbd` | `stateText` | 快捷键提示切换 |
@@ -0,0 +1,30 @@
1
+ import type { CoreState, StateValueMap } from "./frame-types";
2
+
3
+ export interface ParentFrameStateContext {
4
+ currentState?: CoreState;
5
+ }
6
+
7
+ export function resolveStateValue<T>(
8
+ map: StateValueMap<T> | undefined,
9
+ state: CoreState | undefined,
10
+ fallback?: T,
11
+ ): T | undefined {
12
+ if (!map || typeof map !== "object") return fallback;
13
+
14
+ const currentState = state ?? "Idle";
15
+ if (Object.prototype.hasOwnProperty.call(map, currentState)) {
16
+ return map[currentState];
17
+ }
18
+ if (Object.prototype.hasOwnProperty.call(map, "Idle")) {
19
+ return map.Idle;
20
+ }
21
+ return fallback;
22
+ }
23
+
24
+ export function resolveParentStateValue<T>(
25
+ map: StateValueMap<T> | undefined,
26
+ parentContext: ParentFrameStateContext | undefined,
27
+ fallback?: T,
28
+ ): T | undefined {
29
+ return resolveStateValue(map, parentContext?.currentState, fallback);
30
+ }
@@ -0,0 +1,426 @@
1
+ /**
2
+ * OSS Frame 状态机(v1.0.0 起在 OSS)
3
+ *
4
+ * 与 PRO 版本(pro/src/logic/frame-state.svelte.ts)的差异:
5
+ * - 不含 §8 联动控制(linkageControl / Motion 依赖)
6
+ * - 构造函数不接收 motion 参数
7
+ * - 事件处理器中的 `if ("target" in config) { ... }` 分支被剥离
8
+ *
9
+ * 作用半径:1 个 Frame(仅修改自身 currentState 与交互状态)
10
+ *
11
+ * PRO 版本独立维护一份完整实现,FramePro 使用 PRO 版本。
12
+ * 详见 ../components/Frame.md §1 切割原则与 /Frame-Refactor-Plan.md §3.4。
13
+ */
14
+
15
+ import type { FrameProps, CoreState } from "./frame-types";
16
+ import { resolveFrameWhileMotionConfig } from "./frame-motion-defaults";
17
+
18
+ export class FrameState {
19
+ #props: FrameProps;
20
+
21
+ // === 交互状态 (Internal Interaction States) ===
22
+ hovered = $state(false);
23
+ pressed = $state(false);
24
+ focused = $state(false);
25
+ isDragging = $state(false);
26
+ isScrolling = $state(false);
27
+ isKeyActive = $state(false);
28
+
29
+ // === 核心状态 (Core State) ===
30
+ currentState = $state<CoreState>("Idle");
31
+
32
+ constructor(props: FrameProps) {
33
+ this.#props = props;
34
+
35
+ $effect(() => {
36
+ const controlledState = this.#props.currentState;
37
+ if (controlledState && this.currentState !== controlledState) {
38
+ this.currentState = controlledState;
39
+ }
40
+ });
41
+
42
+ // 状态变化时处理链式转变
43
+ $effect(() => {
44
+ const transitionConfig = this.#getTransitionConfig(this.currentState);
45
+ const { nextState, auto, run } = this.#parseTransition(transitionConfig);
46
+
47
+ // 执行回调
48
+ if (run) {
49
+ run();
50
+ }
51
+
52
+ // Reload 状态时调用 onReload 回调
53
+ if (this.currentState === "Reload" && this.#props.onReload) {
54
+ this.#props.onReload();
55
+ }
56
+
57
+ if (nextState && auto) {
58
+ const duration = this.#getDuration(this.currentState);
59
+ const timer = setTimeout(() => {
60
+ this.currentState = nextState;
61
+ }, duration);
62
+ return () => clearTimeout(timer);
63
+ }
64
+ });
65
+ }
66
+
67
+ // === 综合状态 (Derived Interaction State) ===
68
+ get interactionState() {
69
+ // 优先使用声明式状态机状态
70
+ if (this.currentState !== "Idle") return this.currentState;
71
+
72
+ // 回退到传统状态判断
73
+ if (this.#props.whileDisabled) return "Disabled";
74
+ if (this.#props.loading) return "Load";
75
+ if (this.pressed) return "Click";
76
+ if (this.hovered) return "Hover";
77
+ if (this.focused) return "Focus";
78
+ if (this.isDragging) return "Drag";
79
+ if (this.isScrolling) return "Scroll";
80
+ return "Idle";
81
+ }
82
+
83
+ // 是否有任何触发器激活 (用于 whileIdle)
84
+ get isAnyTriggerActive() {
85
+ return (
86
+ this.hovered ||
87
+ this.pressed ||
88
+ this.focused ||
89
+ this.isDragging ||
90
+ this.isScrolling ||
91
+ !!this.#props.loading ||
92
+ !!this.#props.whileActive ||
93
+ !!this.#props.whileDisabled ||
94
+ this.#props.collapsed ||
95
+ this.#props.expanded
96
+ );
97
+ }
98
+
99
+ // === Helpers ===
100
+
101
+ #parseTransition(config: any): {
102
+ nextState: CoreState | null;
103
+ auto: boolean;
104
+ run?: () => void;
105
+ } {
106
+ if (!config) return { nextState: null, auto: false };
107
+
108
+ // 1. 数组形式: [State, 'auto']
109
+ if (Array.isArray(config)) {
110
+ return {
111
+ nextState: config[0] as CoreState,
112
+ auto: config[1] === "auto",
113
+ };
114
+ }
115
+
116
+ // 2. 函数形式: () => void
117
+ if (typeof config === "function") {
118
+ return { nextState: null, auto: false, run: config };
119
+ }
120
+
121
+ // 3. 对象形式: { next, auto, run }
122
+ if (typeof config === "object" && ("next" in config || "run" in config)) {
123
+ return {
124
+ nextState: config.next as CoreState,
125
+ auto: !!config.auto,
126
+ run: config.run
127
+ };
128
+ }
129
+
130
+ // 4. 字符串形式: State
131
+ return { nextState: config as CoreState, auto: false };
132
+ }
133
+
134
+ #getWhileConfig(state: CoreState) {
135
+ // 标准状态优先走统一默认动效解析,保证 auto 时长与默认/覆写配置一致
136
+ const configMap: Record<string, any> = {
137
+ StartLoad: resolveFrameWhileMotionConfig(this.#props, "whileLoad"),
138
+ Load: resolveFrameWhileMotionConfig(this.#props, "whileLoad"),
139
+ Reload: resolveFrameWhileMotionConfig(this.#props, "whileReload"),
140
+ Appear: resolveFrameWhileMotionConfig(this.#props, "whileAppear"),
141
+ Disappear: resolveFrameWhileMotionConfig(this.#props, "whileDisappear"),
142
+ Idle: resolveFrameWhileMotionConfig(this.#props, "whileIdle"),
143
+ Active: resolveFrameWhileMotionConfig(this.#props, "whileActive"),
144
+ Disabled: resolveFrameWhileMotionConfig(this.#props, "whileDisabled"),
145
+ Validating: resolveFrameWhileMotionConfig(this.#props, "whileValidating"),
146
+ Uploading: resolveFrameWhileMotionConfig(this.#props, "whileUploading"),
147
+ Editing: resolveFrameWhileMotionConfig(this.#props, "whileEditing"),
148
+ };
149
+
150
+ // 标准状态直接返回(可为 undefined)
151
+ if (state in configMap) return configMap[state];
152
+
153
+ // 尝试获取动态属性 (Custom States): while[State]
154
+ const dynamicKey = `while${state}`;
155
+ return this.#props[dynamicKey];
156
+ }
157
+
158
+ #getDuration(state: CoreState): number {
159
+ const config = this.#getWhileConfig(state);
160
+ if (config && typeof config === "object" && "duration" in config) {
161
+ return config.duration;
162
+ }
163
+ return 300; // 默认 300ms
164
+ }
165
+
166
+ #getTransitionConfig(state: CoreState) {
167
+ const transitionMap: Record<string, any> = {
168
+ StartLoad: this.#props.StartLoad,
169
+ Load: this.#props.Load,
170
+ Reload: this.#props.Reload,
171
+ Appear: this.#props.Appear,
172
+ Disappear: this.#props.Disappear,
173
+ Idle: this.#props.Idle,
174
+ Active: this.#props.Active,
175
+ Disabled: this.#props.Disabled,
176
+ };
177
+
178
+ // 如果是标准状态且有配置,直接返回
179
+ if (transitionMap[state]) return transitionMap[state];
180
+
181
+ // 尝试获取动态属性 (Custom States): [State]
182
+ return this.#props[state];
183
+ }
184
+
185
+ // === Event Handlers ===
186
+
187
+ #handleModifiers(e: Event, config: any) {
188
+ if (config && typeof config === 'object') {
189
+ if (config.stop) e.stopPropagation();
190
+ if (config.prevent) e.preventDefault();
191
+ }
192
+ }
193
+
194
+ #isStateMapTrigger(config: any): boolean {
195
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
196
+ return false;
197
+ }
198
+
199
+ // 这些字段属于普通 Trigger/Linkage 配置,不视为"按状态映射"
200
+ const reservedKeys = [
201
+ "run",
202
+ "target",
203
+ "action",
204
+ "reverse",
205
+ "state",
206
+ "key",
207
+ "next",
208
+ "auto",
209
+ "stop",
210
+ "prevent",
211
+ ];
212
+
213
+ if (reservedKeys.some((key) => key in config)) return false;
214
+ return Object.keys(config).length > 0;
215
+ }
216
+
217
+ #resolveStateMapTrigger(config: Record<string, any>) {
218
+ return config[this.currentState] ?? config.Idle;
219
+ }
220
+
221
+ #applyEventTrigger(config: any, e: Event) {
222
+ if (!config) return;
223
+
224
+ this.#handleModifiers(e, config);
225
+
226
+ if (typeof config === "function") {
227
+ config(e);
228
+ return;
229
+ }
230
+
231
+ if (typeof config === "string") {
232
+ this.currentState = config as CoreState;
233
+ return;
234
+ }
235
+
236
+ if (Array.isArray(config)) {
237
+ if (typeof config[0] === "string") {
238
+ this.currentState = config[0] as CoreState;
239
+ }
240
+ return;
241
+ }
242
+
243
+ if (typeof config === "object") {
244
+ if ("run" in config && typeof config.run === "function") {
245
+ config.run(e);
246
+ }
247
+ if ("state" in config && typeof config.state === "string") {
248
+ this.currentState = config.state as CoreState;
249
+ } else if ("next" in config && typeof config.next === "string") {
250
+ this.currentState = config.next as CoreState;
251
+ }
252
+ // OSS Frame 不支持 §8 联动控制 (Click={{target, action}})。
253
+ // 配置中带 target 字段时,OSS 会忽略;如需联动控制请使用 FramePro。
254
+ }
255
+ }
256
+
257
+ // --- Mouse Events ---
258
+ handleClick = (e: MouseEvent) => {
259
+ const { Click } = this.#props;
260
+ if (!Click) return;
261
+
262
+ // 支持按当前状态分发点击触发器:
263
+ // Click={{ Idle: "Load", Active: "Idle" }}
264
+ if (this.#isStateMapTrigger(Click)) {
265
+ const mapped = this.#resolveStateMapTrigger(Click as Record<string, any>);
266
+ this.#applyEventTrigger(mapped, e);
267
+ return;
268
+ }
269
+
270
+ // 兼容旧行为:非映射模式仅在 Idle 状态响应 Click
271
+ if (this.currentState !== "Idle") return;
272
+ this.#applyEventTrigger(Click, e);
273
+ };
274
+
275
+ handleDblClick = (_e: MouseEvent) => {
276
+ // Reserved for future DblClick prop
277
+ };
278
+
279
+ handleContextMenu = (_e: MouseEvent) => {
280
+ // Reserved for future ContextMenu prop
281
+ };
282
+
283
+ handleMouseEnter = (e: MouseEvent) => {
284
+ this.hovered = true;
285
+ const { Hover } = this.#props;
286
+ if (Hover) {
287
+ this.#handleModifiers(e, Hover);
288
+ if (typeof Hover === "function") {
289
+ Hover(e);
290
+ } else if (typeof Hover === "string") {
291
+ this.currentState = Hover as CoreState;
292
+ } else if (typeof Hover === "object") {
293
+ if ("run" in Hover && typeof Hover.run === "function") {
294
+ Hover.run(e);
295
+ }
296
+ // OSS 忽略 target/action(§8 联动控制属 PRO)
297
+ }
298
+ }
299
+ };
300
+
301
+ handleMouseLeave = () => {
302
+ this.hovered = false;
303
+ this.pressed = false;
304
+ };
305
+
306
+ handleMouseDown = () => {
307
+ this.pressed = true;
308
+ };
309
+
310
+ handleMouseUp = (_e: MouseEvent) => {
311
+ this.pressed = false;
312
+ // Click logic moved to handleClick
313
+ };
314
+
315
+ handleMouseMove = (_e: MouseEvent) => {
316
+ // Reserved
317
+ };
318
+
319
+ // --- Touch Events ---
320
+ handleTouchStart = (_e: TouchEvent) => {
321
+ this.pressed = true;
322
+ };
323
+
324
+ handleTouchEnd = (_e: TouchEvent) => {
325
+ this.pressed = false;
326
+ };
327
+
328
+ handleTouchMove = (_e: TouchEvent) => {
329
+ // Reserved
330
+ };
331
+
332
+ handleTouchCancel = (_e: TouchEvent) => {
333
+ this.pressed = false;
334
+ };
335
+
336
+ // --- Focus Events ---
337
+ handleFocus = (e: FocusEvent) => {
338
+ this.focused = true;
339
+ const { Focus } = this.#props;
340
+ if (Focus) {
341
+ this.#handleModifiers(e, Focus);
342
+ if (typeof Focus === "function") {
343
+ Focus(e);
344
+ } else if (typeof Focus === "string") {
345
+ this.currentState = Focus as CoreState;
346
+ } else if (typeof Focus === "object") {
347
+ if ("run" in Focus && typeof Focus.run === "function") {
348
+ Focus.run(e);
349
+ }
350
+ // OSS 忽略 target/action(§8 联动控制属 PRO)
351
+ }
352
+ }
353
+ };
354
+
355
+ handleBlur = () => {
356
+ this.focused = false;
357
+ };
358
+
359
+ // --- Keyboard Events ---
360
+ handleKeyDown = (e: KeyboardEvent) => {
361
+ this.isKeyActive = true;
362
+ const { Key } = this.#props;
363
+ if (Key && e.key === Key.key) {
364
+ this.#handleModifiers(e, Key);
365
+ if ("run" in Key && typeof Key.run === "function") {
366
+ Key.run(e);
367
+ } else if ("state" in Key) {
368
+ this.currentState = Key.state as CoreState;
369
+ }
370
+ // OSS 忽略 target/action(§8 联动控制属 PRO)
371
+ }
372
+ };
373
+
374
+ handleKeyUp = () => {
375
+ this.isKeyActive = false;
376
+ };
377
+
378
+ handleKeyPress = (_e: KeyboardEvent) => {
379
+ // Reserved
380
+ };
381
+
382
+ // --- Form Events ---
383
+ handleInput = (_e: Event) => {
384
+ // Reserved
385
+ };
386
+
387
+ handleChange = (_e: Event) => {
388
+ // Reserved
389
+ };
390
+
391
+ handleSubmit = (_e: Event) => {
392
+ // Reserved
393
+ };
394
+
395
+ // --- Drag Events ---
396
+ handleDragStart = (e: DragEvent) => {
397
+ this.isDragging = true;
398
+ const { Drag } = this.#props;
399
+ if (Drag) {
400
+ this.#handleModifiers(e, Drag);
401
+ if (typeof Drag === "function") {
402
+ Drag(e);
403
+ } else if (typeof Drag === "string") {
404
+ this.currentState = Drag as CoreState;
405
+ } else if (typeof Drag === "object") {
406
+ if ("run" in Drag && typeof Drag.run === "function") {
407
+ Drag.run(e);
408
+ }
409
+ // OSS 忽略 target/action(§8 联动控制属 PRO)
410
+ }
411
+ }
412
+ };
413
+
414
+ handleDrag = (_e: DragEvent) => {
415
+ // Reserved for future Drag move handling
416
+ };
417
+
418
+ handleDragEnd = (_e: DragEvent) => {
419
+ this.isDragging = false;
420
+ };
421
+
422
+ // --- UI Events ---
423
+ handleScroll = (_e: Event) => {
424
+ // Reserved
425
+ };
426
+ }
@@ -1,7 +1,7 @@
1
1
  # frame-truncation.svelte.ts 文档
2
2
 
3
- > **版本**: v1.1.0
4
- > **职责**: 管理 Text 组件的文本截断和可展开能力(历史文件名保留为 `frame-truncation.svelte.ts`)。
3
+ > **版本**: v1.4.0
4
+ > **职责**: 通过 `TruncationController` 管理 Text、Link 与 TableCell 共用的文本截断和可展开能力(历史文件名保留)。
5
5
 
6
6
  **需求**: 提供多行截断检测、单行溢出检测、可展开/收起状态管理,并向子组件提供截断状态上下文。
7
7
 
@@ -27,6 +27,7 @@
27
27
  | isTruncated | `boolean` | 内容是否被截断 |
28
28
  | isExpanded | `boolean` | 是否已展开 (仅 lines=0 时有效) |
29
29
  | fullText | `string` | 完整文本内容 |
30
+ | availableWidth | `number` | 单行截断内容当前可用宽度,供边界截断算法复用 |
30
31
  | collapseStyles | `Record<string, string>` | collapse action 生成的样式 |
31
32
 
32
33
  ## 3. Context 提供
@@ -105,7 +106,7 @@ interface TruncationContext {
105
106
 
106
107
  ### 关联关系
107
108
 
108
- - **父组件**: [Text.svelte](./../components/Text.svelte)
109
+ - **消费组件**: [Text.svelte](./../components/Text.svelte)、[Link.svelte](./../components/Link.svelte)、[TableCell.svelte](./../components/TableCell.svelte)
109
110
  - **依赖**: [text-collapse.svelte.ts](./text-collapse.svelte.ts)
110
111
  - **Context**: [keys.ts](./../keys.ts)
111
112
 
@@ -113,6 +114,19 @@ interface TruncationContext {
113
114
 
114
115
  ## 更新日志 (Changelog)
115
116
 
117
+ ### v1.4.0 (2026-06-23)
118
+
119
+ - 单行检测同步公开 `availableWidth`,让消费组件可复用通用的单词 / Unicode 字素边界拟合算法。
120
+
121
+ ### v1.3.0 (2026-06-23)
122
+
123
+ - Link 接入共享控制器;单行截断状态、完整文字与尺寸监听继续由同一通用入口管理。
124
+
125
+ ### v1.2.0 (2026-06-19)
126
+
127
+ - 通用类名改为 `TruncationController`,保留 `TextTruncation` / `FrameTruncation` 兼容导出。
128
+ - Text、Link 与 TableCell 共用控制器,单行尺寸监听统一使用 `resizeManager`。
129
+
116
130
  ### v1.1.0 (2026-02-23)
117
131
 
118
132
  #### 架构重构