@snowui-design-system/components 0.1.0 → 0.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/package.json +6 -2
- package/src/components/Accordion.md +218 -0
- package/src/components/Accordion.svelte +301 -0
- package/src/components/Accordion.test.ts +126 -0
- package/src/components/AccordionItem.md +114 -0
- package/src/components/AccordionItem.svelte +389 -0
- package/src/components/AccordionItem.test.ts +52 -0
- package/src/components/Avatar.md +54 -36
- package/src/components/Avatar.svelte +73 -126
- package/src/components/AvatarGroup.md +17 -14
- package/src/components/AvatarGroup.svelte +12 -50
- package/src/components/AvatarGroup.test.ts +69 -68
- package/src/components/Badge.md +53 -8
- package/src/components/Badge.svelte +303 -79
- package/src/components/Badge.test.ts +47 -0
- package/src/components/Breadcrumb.md +164 -0
- package/src/components/Breadcrumb.svelte +330 -0
- package/src/components/Breadcrumb.test.ts +154 -0
- package/src/components/Button.md +243 -57
- package/src/components/Button.svelte +278 -177
- package/src/components/Button.test.ts +175 -86
- package/src/components/ButtonGroup.md +140 -0
- package/src/components/ButtonGroup.svelte +491 -0
- package/src/components/ButtonGroup.test.ts +58 -0
- package/src/components/Card.md +186 -0
- package/src/components/Card.svelte +408 -0
- package/src/components/Card.test.ts +193 -0
- package/src/components/Checkbox.md +14 -10
- package/src/components/Checkbox.svelte +39 -99
- package/src/components/Chip.md +185 -0
- package/src/components/Chip.svelte +241 -0
- package/src/components/Chip.test.ts +117 -0
- package/src/components/CodeBlock.md +29 -16
- package/src/components/CodeBlock.svelte +132 -352
- package/src/components/CodeBlock.test.ts +15 -1
- package/src/components/CopyButton.md +41 -0
- package/src/components/CopyButton.svelte +164 -0
- package/src/components/CopyButton.test.ts +26 -0
- package/src/components/Dialog.md +95 -0
- package/src/components/Dialog.svelte +416 -0
- package/src/components/Dialog.test.ts +145 -0
- package/src/components/ExpandButton.md +41 -0
- package/src/components/ExpandButton.svelte +103 -0
- package/src/components/ExpandButton.test.ts +18 -0
- package/src/components/Form.md +4 -3
- package/src/components/Form.test.ts +72 -73
- package/src/components/Frame.md +243 -0
- package/src/components/Frame.svelte +208 -87
- package/src/components/Frame.test.ts +121 -0
- package/src/components/Icon.md +34 -6
- package/src/components/Icon.svelte +46 -95
- package/src/components/Image.md +24 -13
- package/src/components/Image.svelte +42 -128
- package/src/components/ImageGroup.md +6 -7
- package/src/components/ImageGroup.svelte +1 -28
- package/src/components/Indicator.md +92 -0
- package/src/components/Indicator.svelte +490 -0
- package/src/components/Indicator.test.ts +57 -0
- package/src/components/Input.md +81 -28
- package/src/components/Input.svelte +291 -178
- package/src/components/Input.test.ts +85 -48
- package/src/components/Kbd.md +0 -3
- package/src/components/Kbd.svelte +0 -1
- package/src/components/Link.md +192 -0
- package/src/components/Link.svelte +464 -0
- package/src/components/Link.test.ts +110 -0
- package/src/components/Listbox.md +52 -10
- package/src/components/Listbox.svelte +204 -50
- package/src/components/Listbox.test.ts +76 -33
- package/src/components/LocaleProvider.md +52 -0
- package/src/components/LocaleProvider.svelte +30 -0
- package/src/components/LocaleProvider.test.ts +32 -0
- package/src/components/MenuItem.md +23 -9
- package/src/components/MenuItem.svelte +57 -47
- package/src/components/MenuItem.test.ts +72 -65
- package/src/components/Pagination.md +504 -0
- package/src/components/Pagination.svelte +958 -0
- package/src/components/Pagination.test.ts +316 -0
- package/src/components/Popover.md +245 -42
- package/src/components/Popover.svelte +558 -127
- package/src/components/Popover.test.ts +361 -44
- package/src/components/Progress.md +91 -0
- package/src/components/Progress.svelte +374 -0
- package/src/components/Progress.test.ts +56 -0
- package/src/components/Radio.md +4 -6
- package/src/components/Radio.svelte +25 -117
- package/src/components/ScrollArea.md +116 -0
- package/src/components/ScrollArea.svelte +180 -0
- package/src/components/ScrollArea.test.ts +84 -0
- package/src/components/SearchInput.md +135 -0
- package/src/components/SearchInput.svelte +153 -0
- package/src/components/SearchInput.test.ts +61 -0
- package/src/components/Select.md +39 -8
- package/src/components/Select.svelte +196 -45
- package/src/components/Select.test.ts +79 -41
- package/src/components/SelectButton.md +50 -0
- package/src/components/SelectButton.svelte +186 -0
- package/src/components/SelectButton.test.ts +142 -0
- package/src/components/Separator.md +89 -0
- package/src/components/Separator.svelte +143 -0
- package/src/components/Separator.test.ts +35 -0
- package/src/components/Skeleton.md +2 -5
- package/src/components/Skeleton.svelte +202 -7
- package/src/components/Skeleton.test.ts +10 -10
- package/src/components/Slider.md +101 -0
- package/src/components/Slider.svelte +566 -0
- package/src/components/Slider.test.ts +51 -0
- package/src/components/Spinner.md +3 -4
- package/src/components/Spinner.svelte +11 -23
- package/src/components/{Toggle.md → Switch.md} +20 -21
- package/src/components/Switch.svelte +314 -0
- package/src/components/Switch.test.ts +57 -0
- package/src/components/Table.md +249 -0
- package/src/components/Table.svelte +139 -0
- package/src/components/Table.test.ts +64 -0
- package/src/components/TableBody.md +63 -0
- package/src/components/TableBody.svelte +78 -0
- package/src/components/TableBody.test.ts +13 -0
- package/src/components/TableCell.md +89 -0
- package/src/components/TableCell.svelte +368 -0
- package/src/components/TableCell.test.ts +51 -0
- package/src/components/TableHead.md +129 -0
- package/src/components/TableHead.svelte +281 -0
- package/src/components/TableHead.test.ts +44 -0
- package/src/components/TableHeader.md +26 -0
- package/src/components/TableHeader.svelte +10 -0
- package/src/components/TableHeader.test.ts +3 -0
- package/src/components/TableRow.md +36 -0
- package/src/components/TableRow.svelte +64 -0
- package/src/components/TableRow.test.ts +2 -0
- package/src/components/TableToolbar.svelte +260 -0
- package/src/components/Tag.md +270 -0
- package/src/components/Tag.svelte +462 -0
- package/src/components/Tag.test.ts +91 -0
- package/src/components/Text.md +87 -25
- package/src/components/Text.svelte +467 -93
- package/src/components/Text.test.ts +21 -36
- package/src/components/Textarea.md +22 -7
- package/src/components/Textarea.svelte +76 -155
- package/src/components/Textarea.test.ts +12 -5
- package/src/components/Tooltip.md +101 -12
- package/src/components/Tooltip.svelte +581 -108
- package/src/components/Tooltip.test.ts +63 -1
- package/src/context.ts +93 -5
- package/src/dev.ts +6 -10
- package/src/i18n/locale.svelte.ts +60 -0
- package/src/i18n/messages.ts +45 -0
- package/src/index.ts +177 -2
- package/src/keys.ts +7 -0
- package/src/lib/clipboard.ts +10 -0
- package/src/lib/color.md +36 -0
- package/src/lib/color.ts +57 -0
- package/src/lib/date-format.md +37 -0
- package/src/lib/date-format.ts +130 -0
- package/src/lib/edge-fade.md +101 -0
- package/src/lib/edge-fade.ts +55 -0
- package/src/lib/floating-position.md +20 -0
- package/src/lib/floating-position.ts +107 -0
- package/src/lib/number-format.md +40 -0
- package/src/lib/number-format.ts +132 -0
- package/src/lib/overlay-scrollbar.md +36 -0
- package/src/lib/overlay-scrollbar.svelte.ts +221 -0
- package/src/lib/overlay-trigger-timing.md +15 -0
- package/src/lib/overlay-trigger-timing.ts +8 -0
- package/src/lib/progressive-blur.md +95 -0
- package/src/lib/progressive-blur.ts +266 -0
- package/src/lib/resizable.md +41 -0
- package/src/lib/resizable.ts +211 -0
- package/src/lib/table-context.svelte.ts +129 -0
- package/src/lib/table-row-context.svelte.ts +16 -0
- package/src/lib/tooltip-behavior.ts +39 -0
- package/src/lib/tooltip-delay.md +33 -0
- package/src/lib/tooltip-delay.ts +49 -0
- package/src/lib/tooltip-overlay.md +30 -0
- package/src/lib/tooltip-overlay.ts +64 -0
- package/src/lib/truncate.md +7 -2
- package/src/lib/truncate.ts +105 -10
- package/src/logic/README.md +17 -7
- package/src/logic/component-parts.md +32 -0
- package/src/logic/component-parts.svelte.ts +130 -0
- package/src/logic/dialog.md +30 -0
- package/src/logic/dialog.svelte.ts +88 -0
- package/src/logic/frame-actions.md +28 -0
- package/src/logic/frame-actions.svelte.ts +49 -0
- package/src/logic/frame-class-state.md +21 -0
- package/src/logic/frame-class-state.svelte.ts +163 -0
- package/src/logic/frame-dom-runtime.svelte.ts +51 -0
- package/src/logic/frame-inline-style.md +56 -0
- package/src/logic/frame-inline-style.svelte.ts +623 -0
- package/src/logic/frame-motion-defaults.md +90 -9
- package/src/logic/frame-motion-defaults.ts +55 -49
- package/src/logic/frame-motion.svelte.ts +173 -0
- package/src/logic/frame-perception.md +83 -0
- package/src/logic/frame-perception.svelte.ts +273 -0
- package/src/logic/frame-prop-filter.ts +7 -1
- package/src/logic/frame-scale-observer.md +153 -0
- package/src/logic/frame-scale-observer.svelte.ts +98 -0
- package/src/logic/frame-scale-resolver.md +25 -0
- package/src/logic/frame-scale-resolver.svelte.ts +56 -0
- package/src/logic/frame-state-value.md +74 -0
- package/src/logic/frame-state-value.ts +30 -0
- package/src/logic/frame-state.svelte.ts +426 -0
- package/src/logic/frame-truncation.md +17 -3
- package/src/logic/frame-truncation.svelte.ts +23 -43
- package/src/logic/frame-types.md +2 -1
- package/src/logic/frame-types.ts +41 -7
- package/src/logic/frame-utils.md +4 -0
- package/src/logic/frame-utils.ts +54 -26
- package/src/logic/image-preview.md +9 -2
- package/src/logic/image-preview.ts +33 -7
- package/src/logic/morph.md +19 -0
- package/src/logic/morph.ts +7 -0
- package/src/logic/motion-config.ts +49 -3
- package/src/logic/motion-engine.md +43 -0
- package/src/logic/motion-engine.ts +272 -0
- package/src/logic/overlay-presence.svelte.ts +71 -0
- package/src/logic/popover.md +89 -0
- package/src/logic/popover.svelte.ts +236 -0
- package/src/logic/resource-size.md +21 -0
- package/src/logic/resource-size.ts +53 -0
- package/src/logic/text-collapse.md +2 -1
- package/src/logic/text-collapse.svelte.ts +1 -1
- package/src/logic/wc-adapter.ts +1 -1
- package/src/motion/README.md +97 -37
- package/src/motion/{defaults/bridge.md → bridge.md} +24 -4
- package/src/motion/{defaults/bridge.ts → bridge.ts} +16 -5
- package/src/motion/{defaults/content-crossfade.ts → content-crossfade.ts} +1 -1
- package/src/motion/{defaults/expand.md → expand.md} +2 -2
- package/src/motion/{defaults/expand.ts → expand.ts} +4 -3
- package/src/motion/fade-in.md +40 -0
- package/src/motion/fade-in.ts +14 -0
- package/src/motion/{defaults/fade-out.md → fade-out.md} +2 -2
- package/src/motion/fade-out.ts +14 -0
- package/src/motion/{defaults/morph.md → morph.md} +1 -1
- package/src/motion/{defaults/morph.ts → morph.ts} +3 -3
- package/src/motion/move.md +179 -0
- package/src/motion/move.ts +74 -0
- package/src/motion/number.md +50 -0
- package/src/motion/number.ts +30 -0
- package/src/motion/presets/README.md +50 -0
- package/src/motion/presets/dialog.md +20 -0
- package/src/motion/presets/dialog.ts +47 -0
- package/src/motion/presets/effects.md +32 -0
- package/src/motion/presets/effects.ts +111 -0
- package/src/motion/presets/generic.md +27 -0
- package/src/motion/presets/generic.ts +32 -0
- package/src/motion/presets/overlay.md +21 -0
- package/src/motion/presets/overlay.ts +18 -0
- package/src/motion/presets/replacement.md +19 -0
- package/src/motion/presets/replacement.ts +6 -0
- package/src/motion/presets/resize.md +23 -0
- package/src/motion/presets/resize.ts +16 -0
- package/src/motion/presets/tab.md +21 -0
- package/src/motion/presets/tab.ts +19 -0
- package/src/motion/presets/tooltip.md +20 -0
- package/src/motion/presets/tooltip.ts +37 -0
- package/src/motion/presets/utils.md +15 -0
- package/src/motion/presets/utils.ts +11 -0
- package/src/motion/primitives.md +22 -0
- package/src/motion/primitives.ts +46 -0
- package/src/motion/{defaults/replace.md → replace.md} +2 -2
- package/src/motion/{defaults/replace.ts → replace.ts} +4 -4
- package/src/motion/{defaults/rotate.md → rotate.md} +4 -4
- package/src/motion/{defaults/rotate.ts → rotate.ts} +4 -3
- package/src/motion/scale-in.md +40 -0
- package/src/motion/scale-in.ts +19 -0
- package/src/motion/spring.md +19 -0
- package/src/motion/spring.ts +96 -0
- package/src/motion/tokens.md +45 -0
- package/src/motion/tokens.ts +80 -0
- package/src/motion/{defaults/while-2xl.ts → while-2xl.ts} +1 -1
- package/src/motion/{defaults/while-active.ts → while-active.ts} +1 -1
- package/src/motion/while-appear.ts +10 -0
- package/src/motion/{defaults/while-click.ts → while-click.ts} +1 -1
- package/src/motion/{defaults/while-collapsed.ts → while-collapsed.ts} +1 -1
- package/src/motion/{defaults/while-disabled.ts → while-disabled.ts} +3 -2
- package/src/motion/while-disappear.ts +10 -0
- package/src/motion/{defaults/while-drag.ts → while-drag.ts} +1 -1
- package/src/motion/{defaults/while-editing.ts → while-editing.ts} +1 -1
- package/src/motion/{defaults/while-expanded.ts → while-expanded.ts} +1 -1
- package/src/motion/{defaults/while-focus.ts → while-focus.ts} +1 -1
- package/src/motion/{defaults/while-hover.ts → while-hover.ts} +1 -1
- package/src/motion/{defaults/while-idle.ts → while-idle.ts} +1 -1
- package/src/motion/{defaults/while-key.ts → while-key.ts} +1 -1
- package/src/motion/{defaults/while-lg.ts → while-lg.ts} +1 -1
- package/src/motion/{defaults/while-load.ts → while-load.ts} +3 -2
- package/src/motion/{defaults/while-md.ts → while-md.ts} +1 -1
- package/src/motion/{defaults/while-reload.ts → while-reload.ts} +1 -1
- package/src/motion/{defaults/while-scroll.ts → while-scroll.ts} +1 -1
- package/src/motion/{defaults/while-sm.ts → while-sm.ts} +1 -1
- package/src/motion/{defaults/while-uploading.ts → while-uploading.ts} +1 -1
- package/src/motion/{defaults/while-validating.ts → while-validating.ts} +1 -1
- package/src/motion/{defaults/while-xl.ts → while-xl.ts} +1 -1
- package/src/motion/{defaults/while-xs.ts → while-xs.ts} +1 -1
- package/src/styles/auto-layout.css +92 -10
- package/src/styles/layout.css +370 -30
- package/src/styles/scrollbar.css +72 -7
- package/src/App.svelte +0 -103
- package/src/components/QuickAction.md +0 -146
- package/src/components/QuickAction.svelte +0 -161
- package/src/components/QuickAction.test.ts +0 -299
- package/src/components/Test.md +0 -72
- package/src/components/Test.svelte +0 -106
- package/src/components/Test.test.ts +0 -27
- package/src/components/Toggle.svelte +0 -384
- package/src/components/Toggle.test.ts +0 -57
- package/src/logic/frame-profile.md +0 -156
- package/src/logic/frame-profile.ts +0 -130
- package/src/motion/NumberFlow.md +0 -16
- package/src/motion/defaults/fade-out.ts +0 -14
- package/src/motion/defaults/move.md +0 -81
- package/src/motion/defaults/move.ts +0 -31
- package/src/motion/defaults/number.md +0 -41
- package/src/motion/defaults/number.ts +0 -17
- package/src/motion/defaults/while-appear.ts +0 -12
- package/src/motion/defaults/while-disappear.ts +0 -12
- package/src//344/273/243/347/240/201.txt +0 -61
- /package/src/motion/{defaults/rotate.css → rotate.css} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface TooltipBehaviorEnhancement {
|
|
2
|
+
lifecycleMotion?: boolean;
|
|
3
|
+
smoothMove?: boolean;
|
|
4
|
+
sizeMotion?: boolean;
|
|
5
|
+
switchHideDelayMs?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ResolvedTooltipBehaviorEnhancement {
|
|
9
|
+
lifecycleMotion: boolean;
|
|
10
|
+
smoothMove: boolean;
|
|
11
|
+
sizeMotion: boolean;
|
|
12
|
+
switchHideDelayMs: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const DEFAULT_TOOLTIP_BEHAVIOR: ResolvedTooltipBehaviorEnhancement = {
|
|
16
|
+
lifecycleMotion: true,
|
|
17
|
+
smoothMove: false,
|
|
18
|
+
sizeMotion: false,
|
|
19
|
+
switchHideDelayMs: 0,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let tooltipBehavior = DEFAULT_TOOLTIP_BEHAVIOR;
|
|
23
|
+
|
|
24
|
+
export function registerTooltipBehaviorEnhancement(
|
|
25
|
+
enhancement: TooltipBehaviorEnhancement,
|
|
26
|
+
): void {
|
|
27
|
+
tooltipBehavior = {
|
|
28
|
+
...DEFAULT_TOOLTIP_BEHAVIOR,
|
|
29
|
+
...enhancement,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resetTooltipBehaviorEnhancement(): void {
|
|
34
|
+
tooltipBehavior = DEFAULT_TOOLTIP_BEHAVIOR;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getTooltipBehaviorEnhancement(): ResolvedTooltipBehaviorEnhancement {
|
|
38
|
+
return tooltipBehavior;
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# tooltip-delay.ts
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.0
|
|
4
|
+
> **职责**: 协调页面内所有 Tooltip 的 hover warmup / cooldown 时序。
|
|
5
|
+
> **依赖方**: [`../components/Tooltip.svelte`](../components/Tooltip.svelte)
|
|
6
|
+
|
|
7
|
+
## 行为
|
|
8
|
+
|
|
9
|
+
| 场景 | 行为 |
|
|
10
|
+
| :--- | :--- |
|
|
11
|
+
| 首次 hover Tooltip | 延迟 `450ms` 显示 |
|
|
12
|
+
| 任一 Tooltip 成功显示后,在 cooldown 窗口内 hover 其他 Tooltip | 立即显示 |
|
|
13
|
+
| 离开 Tooltip 触发器超过 cooldown 窗口 | 恢复首次 hover 的 `450ms` 延迟 |
|
|
14
|
+
| 首次 hover 未满 `450ms` 就移开 | 不进入立即显示模式 |
|
|
15
|
+
|
|
16
|
+
cooldown 窗口为 `300ms`。该规则参考 Radix Tooltip 的 `delayDuration` / `skipDelayDuration` 语义。
|
|
17
|
+
|
|
18
|
+
## 公开 API
|
|
19
|
+
|
|
20
|
+
| API | 说明 |
|
|
21
|
+
| :--- | :--- |
|
|
22
|
+
| `TOOLTIP_HOVER_SHOW_DELAY_MS` | 首次 hover 显示延迟,来自 `OVERLAY_TRIGGER_HOVER_DELAY_MS`;Popover hover 延迟复用该值 |
|
|
23
|
+
| `TOOLTIP_SKIP_DELAY_DURATION_MS` | cooldown 窗口,固定为 `300` |
|
|
24
|
+
| `getTooltipHoverShowDelay()` | 返回当前应使用的显示延迟 |
|
|
25
|
+
| `markTooltipShown()` | Tooltip 成功显示后进入 warm 状态 |
|
|
26
|
+
| `scheduleTooltipWarmupReset()` | 离开触发器后开始 cooldown 计时 |
|
|
27
|
+
| `resetTooltipDelayState()` | 立即清理共享状态,供测试或宿主重置使用 |
|
|
28
|
+
|
|
29
|
+
## 约束
|
|
30
|
+
|
|
31
|
+
- 仅非受控模式参与共享延迟协调。
|
|
32
|
+
- `open` 受控模式由外部状态决定显隐,不读写 warmup / cooldown 状态。
|
|
33
|
+
- Popover 复用 `OVERLAY_TRIGGER_HOVER_DELAY_MS` / `TOOLTIP_HOVER_SHOW_DELAY_MS` 作为 hover 显示延迟,但不参与 Tooltip 的 warmup / cooldown 状态。
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip hover 延迟协调器。
|
|
3
|
+
*
|
|
4
|
+
* 首个 Tooltip 使用 warmup 延迟;任一 Tooltip 成功显示后,在 cooldown
|
|
5
|
+
* 窗口内切换到其他 Tooltip 时立即显示。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
OVERLAY_TRIGGER_HOVER_DELAY_MS,
|
|
10
|
+
OVERLAY_TRIGGER_SKIP_DELAY_DURATION_MS,
|
|
11
|
+
} from "./overlay-trigger-timing";
|
|
12
|
+
|
|
13
|
+
export const TOOLTIP_HOVER_SHOW_DELAY_MS = OVERLAY_TRIGGER_HOVER_DELAY_MS;
|
|
14
|
+
export const TOOLTIP_SKIP_DELAY_DURATION_MS =
|
|
15
|
+
OVERLAY_TRIGGER_SKIP_DELAY_DURATION_MS;
|
|
16
|
+
|
|
17
|
+
let isTooltipWarm = false;
|
|
18
|
+
let cooldownTimer: ReturnType<typeof setTimeout> | undefined;
|
|
19
|
+
|
|
20
|
+
function clearCooldownTimer(): void {
|
|
21
|
+
if (cooldownTimer !== undefined) {
|
|
22
|
+
clearTimeout(cooldownTimer);
|
|
23
|
+
cooldownTimer = undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getTooltipHoverShowDelay(): number {
|
|
28
|
+
return isTooltipWarm ? 0 : TOOLTIP_HOVER_SHOW_DELAY_MS;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function markTooltipShown(): void {
|
|
32
|
+
clearCooldownTimer();
|
|
33
|
+
isTooltipWarm = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function scheduleTooltipWarmupReset(): void {
|
|
37
|
+
if (!isTooltipWarm) return;
|
|
38
|
+
|
|
39
|
+
clearCooldownTimer();
|
|
40
|
+
cooldownTimer = setTimeout(() => {
|
|
41
|
+
cooldownTimer = undefined;
|
|
42
|
+
isTooltipWarm = false;
|
|
43
|
+
}, TOOLTIP_SKIP_DELAY_DURATION_MS);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function resetTooltipDelayState(): void {
|
|
47
|
+
clearCooldownTimer();
|
|
48
|
+
isTooltipWarm = false;
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# tooltip-overlay.ts
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.1
|
|
4
|
+
> **职责**: 协调页面内非受控 Tooltip 共用一个 Portal 外框。
|
|
5
|
+
> **依赖方**: [`../components/Tooltip.svelte`](../components/Tooltip.svelte)
|
|
6
|
+
|
|
7
|
+
## 行为
|
|
8
|
+
|
|
9
|
+
| 场景 | 行为 |
|
|
10
|
+
| :--- | :--- |
|
|
11
|
+
| 首次 hover Tooltip | 由 `tooltip-delay.ts` 决定显示延迟,显示后写入共享 overlay state |
|
|
12
|
+
| 从一个 Tooltip 触发器切到另一个 | 保留共享 Portal 外框,替换内容、触发器、位置与外观参数;具体移动 / 直达策略由 `Tooltip.svelte` 根据距离判定 |
|
|
13
|
+
| 离开触发器后未进入新 Tooltip | `80ms` 后清空共享 overlay state |
|
|
14
|
+
| 受控 `open` 模式 | 不使用本模块,继续由 Tooltip 本地 Portal 渲染 |
|
|
15
|
+
|
|
16
|
+
## 公开 API
|
|
17
|
+
|
|
18
|
+
| API | 说明 |
|
|
19
|
+
| :--- | :--- |
|
|
20
|
+
| `tooltipOverlay` | 当前共享 Tooltip 状态 store |
|
|
21
|
+
| `showTooltipOverlay(state)` | 清理隐藏计时并显示/更新共享外框 |
|
|
22
|
+
| `updateTooltipOverlay(state)` | 当前 active Tooltip 自身 props 变化时同步共享状态 |
|
|
23
|
+
| `scheduleTooltipOverlayHide(id, delayMs?)` | 离开触发器后隐藏;`delayMs=0` 时立即隐藏,PRO 增强可传入短延迟以承接相邻 Tooltip 切换 |
|
|
24
|
+
| `hideTooltipOverlay(id)` | 当前 active Tooltip 卸载或禁用时立即隐藏 |
|
|
25
|
+
|
|
26
|
+
## 职责边界
|
|
27
|
+
|
|
28
|
+
- 本模块只管理“同一个外框是否复用”和 active Tooltip 的渲染参数。
|
|
29
|
+
- 首次延迟、快速切换窗口与冷却恢复仍由 [`tooltip-delay.ts`](./tooltip-delay.md) 管理。
|
|
30
|
+
- 视觉样式与 Frame 动效仍在 [`Tooltip.svelte`](../components/Tooltip.svelte) 内消费。
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import { writable } from "svelte/store";
|
|
3
|
+
|
|
4
|
+
export const TOOLTIP_OVERLAY_SWITCH_HIDE_DELAY_MS = 80;
|
|
5
|
+
|
|
6
|
+
export interface TooltipOverlayState {
|
|
7
|
+
id: string;
|
|
8
|
+
triggerEl: HTMLElement;
|
|
9
|
+
position: "top" | "bottom" | "left" | "right";
|
|
10
|
+
offset: number;
|
|
11
|
+
variant: "dark" | "light";
|
|
12
|
+
className: string;
|
|
13
|
+
style?: string;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
fallbackContent: string;
|
|
16
|
+
loopMotion?: any;
|
|
17
|
+
rest: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const tooltipOverlay = writable<TooltipOverlayState | null>(null);
|
|
21
|
+
|
|
22
|
+
let activeTooltipId: string | undefined;
|
|
23
|
+
let hideTimer: ReturnType<typeof setTimeout> | undefined;
|
|
24
|
+
|
|
25
|
+
function clearHideTimer(): void {
|
|
26
|
+
if (hideTimer !== undefined) {
|
|
27
|
+
clearTimeout(hideTimer);
|
|
28
|
+
hideTimer = undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function showTooltipOverlay(state: TooltipOverlayState): void {
|
|
33
|
+
clearHideTimer();
|
|
34
|
+
activeTooltipId = state.id;
|
|
35
|
+
tooltipOverlay.set(state);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function updateTooltipOverlay(state: TooltipOverlayState): void {
|
|
39
|
+
if (activeTooltipId !== state.id) return;
|
|
40
|
+
tooltipOverlay.set(state);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function scheduleTooltipOverlayHide(id: string, delayMs = TOOLTIP_OVERLAY_SWITCH_HIDE_DELAY_MS): void {
|
|
44
|
+
clearHideTimer();
|
|
45
|
+
if (delayMs <= 0) {
|
|
46
|
+
if (activeTooltipId !== id) return;
|
|
47
|
+
activeTooltipId = undefined;
|
|
48
|
+
tooltipOverlay.set(null);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
hideTimer = setTimeout(() => {
|
|
52
|
+
hideTimer = undefined;
|
|
53
|
+
if (activeTooltipId !== id) return;
|
|
54
|
+
activeTooltipId = undefined;
|
|
55
|
+
tooltipOverlay.set(null);
|
|
56
|
+
}, TOOLTIP_OVERLAY_SWITCH_HIDE_DELAY_MS);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function hideTooltipOverlay(id: string): void {
|
|
60
|
+
if (activeTooltipId !== id) return;
|
|
61
|
+
clearHideTimer();
|
|
62
|
+
activeTooltipId = undefined;
|
|
63
|
+
tooltipOverlay.set(null);
|
|
64
|
+
}
|
package/src/lib/truncate.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# truncate.ts 文档
|
|
2
2
|
|
|
3
|
-
> **版本**: v1.
|
|
3
|
+
> **版本**: v1.3.0
|
|
4
4
|
> **职责**: 文本截断 Svelte Action。
|
|
5
5
|
|
|
6
6
|
## 依赖关系
|
|
7
7
|
|
|
8
|
-
- **被依赖**:
|
|
8
|
+
- **被依赖**: Link.svelte、frame-truncation.svelte.ts(以及后续需要边界拟合的文字组件)
|
|
9
9
|
|
|
10
10
|
## 导出
|
|
11
11
|
|
|
12
12
|
| 名称 | 类型 | 描述 |
|
|
13
13
|
| :--- | :--- | :--- |
|
|
14
14
|
| truncate | Svelte Action | 文本截断 action |
|
|
15
|
+
| fitTextToElement | Function | 按目标元素实际字体宽度返回不拆单词 / Unicode 字素的最长可见前缀 |
|
|
16
|
+
| measureTextForElement | Function | 按目标元素字体与字距测量文本宽度,供截断内容与相邻配件紧密布局 |
|
|
15
17
|
|
|
16
18
|
## 配置项
|
|
17
19
|
|
|
@@ -23,3 +25,6 @@
|
|
|
23
25
|
|
|
24
26
|
- CSS line-clamp 应用
|
|
25
27
|
- 截断状态检测
|
|
28
|
+
- 语言感知的边界截断:优先使用 `Intl.Segmenter` 的 word 分段;单个英文等字母单词放不下时只显示省略符,中日韩文字可降级为 grapheme 分段
|
|
29
|
+
- 字体宽度测量:使用 Canvas `measureText()`,并计入元素 `letter-spacing`
|
|
30
|
+
- 返回值不包含省略符,消费组件可独立渲染 `…`,避免焦点态原生 ellipsis 绘制差异
|
package/src/lib/truncate.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 3. 支持“展开/收起”模式下的高度计算。
|
|
9
9
|
* 4. 自动监听容器尺寸变化并重新计算截断状态。
|
|
10
10
|
*/
|
|
11
|
+
import { resizeManager } from "../logic/observer.svelte";
|
|
11
12
|
|
|
12
13
|
export type TruncateLines = number;
|
|
13
14
|
|
|
@@ -24,6 +25,102 @@ export interface TruncateOptions {
|
|
|
24
25
|
onUpdate?: (info: TruncateInfo) => void;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
export interface FitTextOptions {
|
|
29
|
+
locale?: string | string[];
|
|
30
|
+
/** 末尾省略符;仅用于宽度预算,不会拼接到返回文本。 */
|
|
31
|
+
ellipsis?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let textMeasureCanvas: HTMLCanvasElement | undefined;
|
|
35
|
+
|
|
36
|
+
function segmentText(text: string, granularity: "word" | "grapheme", locale?: string | string[]) {
|
|
37
|
+
if (typeof Intl !== "undefined" && "Segmenter" in Intl) {
|
|
38
|
+
const segmenter = new Intl.Segmenter(locale, { granularity });
|
|
39
|
+
return Array.from(segmenter.segment(text), ({ segment }) => segment);
|
|
40
|
+
}
|
|
41
|
+
return Array.from(text);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createElementTextMeasurer(element: HTMLElement) {
|
|
45
|
+
if (typeof document === "undefined") return (value: string) => value.length;
|
|
46
|
+
textMeasureCanvas ??= document.createElement("canvas");
|
|
47
|
+
const context = textMeasureCanvas.getContext("2d");
|
|
48
|
+
const style = getComputedStyle(element);
|
|
49
|
+
if (context) context.font = style.font;
|
|
50
|
+
const letterSpacing = Number.parseFloat(style.letterSpacing || "0") || 0;
|
|
51
|
+
const graphemeSegmenter =
|
|
52
|
+
typeof Intl !== "undefined" && "Segmenter" in Intl
|
|
53
|
+
? new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
54
|
+
: undefined;
|
|
55
|
+
|
|
56
|
+
return (value: string) => {
|
|
57
|
+
const baseWidth = context?.measureText(value).width ?? value.length;
|
|
58
|
+
if (!letterSpacing || value.length < 2) return baseWidth;
|
|
59
|
+
const count = graphemeSegmenter
|
|
60
|
+
? Array.from(graphemeSegmenter.segment(value)).length
|
|
61
|
+
: Array.from(value).length;
|
|
62
|
+
return baseWidth + Math.max(0, count - 1) * letterSpacing;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 按目标元素的实际字体、字距测量文本宽度。 */
|
|
67
|
+
export function measureTextForElement(value: string, element: HTMLElement) {
|
|
68
|
+
return createElementTextMeasurer(element)(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function longestFittingPrefix(
|
|
72
|
+
segments: string[],
|
|
73
|
+
maxWidth: number,
|
|
74
|
+
measure: (value: string) => number,
|
|
75
|
+
) {
|
|
76
|
+
let low = 0;
|
|
77
|
+
let high = segments.length;
|
|
78
|
+
while (low < high) {
|
|
79
|
+
const middle = Math.ceil((low + high) / 2);
|
|
80
|
+
const candidate = segments.slice(0, middle).join("").trimEnd();
|
|
81
|
+
if (measure(candidate) <= maxWidth) low = middle;
|
|
82
|
+
else high = middle - 1;
|
|
83
|
+
}
|
|
84
|
+
return segments.slice(0, low).join("").trimEnd();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 按实际字体宽度返回可见前缀。优先保留完整单词;中日韩文字在完整词组
|
|
89
|
+
* 放不下时可降级到 Unicode 字素边界,避免汉字与组合字符被切成半个。
|
|
90
|
+
*/
|
|
91
|
+
export function fitTextToElement(
|
|
92
|
+
text: string,
|
|
93
|
+
maxWidth: number,
|
|
94
|
+
element: HTMLElement,
|
|
95
|
+
options: FitTextOptions = {},
|
|
96
|
+
) {
|
|
97
|
+
if (!text || maxWidth <= 0) return "";
|
|
98
|
+
const measure = createElementTextMeasurer(element);
|
|
99
|
+
const availableWidth = Math.max(
|
|
100
|
+
0,
|
|
101
|
+
maxWidth - measure(options.ellipsis ?? "…"),
|
|
102
|
+
);
|
|
103
|
+
if (measure(text) <= maxWidth) return text;
|
|
104
|
+
|
|
105
|
+
const words = segmentText(text, "word", options.locale);
|
|
106
|
+
const wordPrefix = longestFittingPrefix(words, availableWidth, measure);
|
|
107
|
+
if (wordPrefix) return wordPrefix;
|
|
108
|
+
|
|
109
|
+
// 拉丁、阿拉伯等以完整单词为阅读单元的文字宁可只显示省略符,
|
|
110
|
+
// 也不从单词中间截断。中日韩文字则可安全降级到完整字素边界。
|
|
111
|
+
const canFallbackToGrapheme =
|
|
112
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u.test(
|
|
113
|
+
text,
|
|
114
|
+
);
|
|
115
|
+
if (!canFallbackToGrapheme) return "";
|
|
116
|
+
|
|
117
|
+
return longestFittingPrefix(
|
|
118
|
+
segmentText(text, "grapheme", options.locale),
|
|
119
|
+
availableWidth,
|
|
120
|
+
measure,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
27
124
|
const EPS = 1;
|
|
28
125
|
|
|
29
126
|
function measureLineHeight(cs: CSSStyleDeclaration) {
|
|
@@ -112,8 +209,8 @@ export default function truncate(node: HTMLElement, options: TruncateOptions = {
|
|
|
112
209
|
const state: RunningState = { running: false, pendingRaf: null };
|
|
113
210
|
|
|
114
211
|
let host: HTMLElement | null = null;
|
|
115
|
-
let
|
|
116
|
-
let
|
|
212
|
+
let unwatchHost: (() => void) | null = null;
|
|
213
|
+
let unwatchNode: (() => void) | null = null;
|
|
117
214
|
|
|
118
215
|
let lastHost: HTMLElement | null = null;
|
|
119
216
|
let lastAppliedMaxHeight: string | null = null;
|
|
@@ -143,12 +240,11 @@ export default function truncate(node: HTMLElement, options: TruncateOptions = {
|
|
|
143
240
|
|
|
144
241
|
// 切换 host 时,更新 host 监听
|
|
145
242
|
if (host !== lastHost) {
|
|
146
|
-
|
|
147
|
-
|
|
243
|
+
unwatchHost?.();
|
|
244
|
+
unwatchHost = null;
|
|
148
245
|
lastHost = host;
|
|
149
246
|
if (host) {
|
|
150
|
-
|
|
151
|
-
hostRo.observe(host);
|
|
247
|
+
unwatchHost = resizeManager.watch(host, requestApply);
|
|
152
248
|
}
|
|
153
249
|
}
|
|
154
250
|
|
|
@@ -214,8 +310,7 @@ export default function truncate(node: HTMLElement, options: TruncateOptions = {
|
|
|
214
310
|
|
|
215
311
|
const requestApply = () => schedule(state, apply);
|
|
216
312
|
|
|
217
|
-
|
|
218
|
-
nodeRo.observe(node);
|
|
313
|
+
unwatchNode = resizeManager.watch(node, requestApply);
|
|
219
314
|
|
|
220
315
|
requestApply();
|
|
221
316
|
|
|
@@ -225,8 +320,8 @@ export default function truncate(node: HTMLElement, options: TruncateOptions = {
|
|
|
225
320
|
requestApply();
|
|
226
321
|
},
|
|
227
322
|
destroy() {
|
|
228
|
-
|
|
229
|
-
|
|
323
|
+
unwatchNode?.();
|
|
324
|
+
unwatchHost?.();
|
|
230
325
|
if (state.pendingRaf !== null) cancelAnimationFrame(state.pendingRaf);
|
|
231
326
|
setStyle(null, null);
|
|
232
327
|
},
|
package/src/logic/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
创建新组件前,建议至少按以下顺序阅读:
|
|
13
13
|
|
|
14
14
|
1. `frame-types.ts` / `frame-types.md`
|
|
15
|
-
2. `
|
|
15
|
+
2. `layout.css` / `layout.css`
|
|
16
16
|
3. `frame-prop-filter.ts` / `frame-prop-filter.md`
|
|
17
17
|
4. `frame-field-control.ts` / `frame-field-control.md`
|
|
18
18
|
5. `frame-state.svelte.ts` / `frame-state.md`
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
| 文件 | 作用 | 什么时候先看 |
|
|
34
34
|
| :--- | :--- | :--- |
|
|
35
35
|
| `frame-types.ts` | `FrameProps`、状态机、事件、动效、编排、Scale、样式编排的总类型契约 | 任何基于 `Frame` 的新组件 |
|
|
36
|
-
| `
|
|
36
|
+
| `layout.css` | `.snowui-hoverable` / `.snowui-field-bordered` 工具类 | 判断共享 hover 或输入外框行为时 |
|
|
37
37
|
| `frame-identity.svelte.ts` | 处理 `id`,并在存在动效配置时生成稳定自动 ID | 组件需要注册 Motion 或依赖 ID 暴露变量时 |
|
|
38
38
|
| `frame-prop-filter.ts` | 统一识别 Frame 内部关键字;同时负责 `Frame -> DOM` 过滤与 `复合组件 -> Frame/宿主元素` 分发 | `Input / Textarea / Select / SearchField` 这类复合组件 |
|
|
39
39
|
| `frame-field-control.ts` | 统一处理原生表单宿主的 `value/defaultValue`、`invalid/aria-invalid` 与值同步 | `Input / Textarea / Select` 这类字段型复合组件 |
|
|
@@ -46,9 +46,11 @@
|
|
|
46
46
|
| `frame-layout.svelte.ts` | 解析 `row / column / grid / reverse` 与断点布局覆盖;附带 FLIP 布局过渡工具 | `direction`、`createLayoutTransition()` |
|
|
47
47
|
| `frame-responsive.svelte.ts` | 基于共享 `ResizeObserver` 计算容器断点 | `containerWidth`、`breakpoint` |
|
|
48
48
|
| `frame-perception.svelte.ts` | 向子组件透出 `FRAME_CONTEXT_KEY`、旧交互上下文、Skeleton 上下文和尺寸上下文 | 父级状态/断点/编排能力的上下文感知 |
|
|
49
|
+
| `component-parts.svelte.ts` | `parts.ComponentName` 直接所有权边界、默认 Props 读取、class/style 合并 | 复合组件默认内置 + `as` 外置双模式 |
|
|
49
50
|
| `frame-actions.svelte.ts` | 统一拼装并挂载用户 action 与内部 action | `buildFrameActions()`、`mountFrameActions()` |
|
|
50
51
|
| `frame-dom-runtime.svelte.ts` | 组装 DOM props、disabled/aria、capture handlers、原生事件包装器、运行时 `data-*` 属性 | `domProps`、`nativeHandlers`、`dataAttrs` |
|
|
51
52
|
| `frame-class-state.svelte.ts` | 解析 `stateVars / stateClass / stateStyle`,并生成 `computedClass` 与 `childrenRenderContext` | 状态映射 class/style 与子内容上下文 |
|
|
53
|
+
| `frame-state-value.ts` | 为子组件按最近父 Frame `currentState` 解析状态值 | `Icon stateIcon`、`Text stateText` |
|
|
52
54
|
| `frame-inline-style.svelte.ts` | 统一拼装 `computedStyle`:`while*`、桥接变量、Scale 变量、编排变量、状态样式 | 根节点最终内联样式 |
|
|
53
55
|
| `frame-skeleton-runtime.svelte.ts` | Skeleton 渲染前判定、首层子骨架探测、`renderHints` 解析 | `shouldRenderSkeleton` 等布尔判断 |
|
|
54
56
|
|
|
@@ -82,7 +84,7 @@
|
|
|
82
84
|
| 文件 | 作用 | 备注 |
|
|
83
85
|
| :--- | :--- | :--- |
|
|
84
86
|
| `text-collapse.svelte.ts` | 实际的多行/可展开折叠测量 action;负责高度约束宿主识别、样式生成、截断判断 | `Text` 组件的主折叠能力 |
|
|
85
|
-
| `frame-truncation.svelte.ts` |
|
|
87
|
+
| `frame-truncation.svelte.ts` | 历史文件名保留,当前导出通用 `TruncationController`,并兼容 `TextTruncation`;负责 `lines`、`isExpanded`、`onTruncate` | Text 与 TableCell 共用,尺寸监听统一走 resizeManager |
|
|
86
88
|
| `collapse.svelte.ts` | 兼容旧路径的转发文件 | 仅用于避免旧导入/HMR 404 |
|
|
87
89
|
|
|
88
90
|
### 6. 媒体与宿主适配
|
|
@@ -91,6 +93,9 @@
|
|
|
91
93
|
| :--- | :--- | :--- |
|
|
92
94
|
| `image-preview.ts` | 页面级图片预览事件总线,协调 `Image / ImageGroup / ImageViewer` | 图片预览、viewer presence、window fallback |
|
|
93
95
|
| `wc-adapter.ts` | Web Components 适配层 | 只在自定义元素/宿主集成场景需要 |
|
|
96
|
+
| `../lib/floating-position.ts` | 浮层边缘碰撞、边界夹取和反向方位计算 | Tooltip、Chart hover panel、后续浮层定位 |
|
|
97
|
+
| `../lib/tooltip-delay.ts` | Tooltip hover warmup / cooldown 协调器 | 多个 Tooltip 之间共享首次延迟与快速切换窗口;Popover 复用 `600ms` 基础延迟常量 |
|
|
98
|
+
| `../lib/resizable.ts` | 通用容器尺寸拖动 action 与 clamp 内核 | TableHead、普通容器与 PRO SplitPane 共用 |
|
|
94
99
|
|
|
95
100
|
### 7. 工具与兼容项
|
|
96
101
|
|
|
@@ -106,15 +111,19 @@
|
|
|
106
111
|
|
|
107
112
|
| 需求 | 先查哪里 |
|
|
108
113
|
| :--- | :--- |
|
|
109
|
-
| 只是要一个标准交互外壳 | `Frame.svelte` + `
|
|
114
|
+
| 只是要一个标准交互外壳 | `Frame.svelte` + `layout.css` |
|
|
110
115
|
| 需要把 props 拆给 `Frame` 和原生元素 | `frame-prop-filter.ts` |
|
|
111
116
|
| 需要 hover/click/focus/active/default motion | `frame-motion-defaults.ts` |
|
|
112
117
|
| 需要把状态机/事件接入 Motion | `frame-state.svelte.ts` + `frame-motion.svelte.ts` |
|
|
118
|
+
| 需要子组件按父 Frame 状态切换自身内容 | `frame-state-value.ts`(已接入 `Icon stateIcon` / `Text stateText`) |
|
|
113
119
|
| 需要响应式断点 | `frame-responsive.svelte.ts` / `frame-layout.svelte.ts` |
|
|
114
120
|
| 需要运行时尺寸驱动 | `frame-scale-observer.svelte.ts` + `frame-scale-resolver.svelte.ts` |
|
|
115
121
|
| 需要 loading/skeleton | `frame-skeleton-runtime.svelte.ts` |
|
|
116
|
-
| 需要文本行数截断/展开 | `text-collapse.svelte.ts` + `
|
|
122
|
+
| 需要文本行数截断/展开 | `text-collapse.svelte.ts` + `TruncationController` |
|
|
123
|
+
| 需要拖动列宽或容器尺寸 | `../lib/resizable.ts` + `Indicator.svelte` |
|
|
117
124
|
| 需要图片预览/查看器联动 | `image-preview.ts` |
|
|
125
|
+
| 需要浮层边缘碰撞/边界夹取 | `../lib/floating-position.ts` |
|
|
126
|
+
| 需要 Tooltip 首次延迟/快速切换时序 | `../lib/tooltip-delay.ts` |
|
|
118
127
|
| 需要跨组件样式联动 | `frame-orchestrator.svelte.ts` |
|
|
119
128
|
|
|
120
129
|
### 2. 最常见的重复造轮子场景
|
|
@@ -123,13 +132,14 @@
|
|
|
123
132
|
- 不要在每个字段组件里重复写 `value/defaultValue`、`aria-invalid`、`file input` 同步规则。统一复用 `frame-field-control.ts`。
|
|
124
133
|
- 不要在组件里单独推导 hover/active/appear 默认动效。默认注入和差异推导统一走 `frame-motion-defaults.ts`。
|
|
125
134
|
- 不要为每个组件单独 new `ResizeObserver`。统一走 `observer.svelte.ts` 或 `frame-responsive.svelte.ts`。
|
|
126
|
-
- 不要把文本截断、可展开逻辑重写在组件内部。直接复用 `
|
|
135
|
+
- 不要把文本截断、可展开逻辑重写在组件内部。直接复用 `TruncationController` / `collapse`。
|
|
136
|
+
- 不要在 Table、容器或 SplitPane 中复制 pointer、keyboard 和 clamp;统一复用 `resizable.ts`。
|
|
127
137
|
- 不要在图片组件里私造全局预览总线。统一使用 `image-preview.ts`。
|
|
128
138
|
- 不要在组件内部写“跨组件尺寸/间距联动”补丁。先看 `frame-orchestrator.svelte.ts` 是否能表达。
|
|
129
139
|
|
|
130
140
|
### 3. 组件开发前的最低检查清单
|
|
131
141
|
|
|
132
|
-
- 是否已经有匹配的 `
|
|
142
|
+
- 是否已经有匹配的 `CSS 行为`?
|
|
133
143
|
- 是否已经有共享状态/观察器/编排器可以复用?
|
|
134
144
|
- 是否只是需要在 `Frame` 外再包一层原生宿主元素?
|
|
135
145
|
- 是否属于 `Text`、`ImageViewer`、Motion 默认资源已经覆盖的能力?
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# component-parts
|
|
2
|
+
|
|
3
|
+
> **职责**:为复合组件提供 `parts.ComponentName` 的直接所有权边界、父级默认 Props 读取,以及 class/style 合并。
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
### `provideComponentParts(getParts)`
|
|
8
|
+
|
|
9
|
+
在复合组件边界提供 parts。通常由根 Frame 的 `componentParts` 内部入口调用;没有显式 parts 时也会建立空边界,阻止祖先配置递归穿透。
|
|
10
|
+
|
|
11
|
+
### `useComponentPart(ComponentName)`
|
|
12
|
+
|
|
13
|
+
子组件读取最近父级同名 part。名称必须使用 SnowUI 公开组件名 PascalCase。
|
|
14
|
+
|
|
15
|
+
### `mergeComponentPartProps(part, explicitProps)`
|
|
16
|
+
|
|
17
|
+
合并顺序:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
实例显式 Props > part
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- class:保留 part class 与实例 class。
|
|
24
|
+
- style:part style 在前、实例 style 在后。
|
|
25
|
+
- 其他字段:实例显式值覆盖 part。
|
|
26
|
+
|
|
27
|
+
## 边界
|
|
28
|
+
|
|
29
|
+
- 本模块只解析输入,不拥有业务 value/open/ARIA/事件。
|
|
30
|
+
- 受控字段由父组件类型和实现排除。
|
|
31
|
+
- 不扫描 DOM 或组件 class。
|
|
32
|
+
- 正式规范见 `../../../specs/ComponentGuidelines.md §2.6.8` 与 `../../../specs/StyleSpec.md §2.6`。
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getContext,
|
|
3
|
+
setContext,
|
|
4
|
+
type Component,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
} from "svelte";
|
|
7
|
+
import { COMPONENT_PARTS_CONTEXT_KEY } from "../keys";
|
|
8
|
+
|
|
9
|
+
export type ComponentPartProps = Record<string, unknown>;
|
|
10
|
+
export type ComponentParts = Record<string, ComponentPartProps | undefined>;
|
|
11
|
+
export type ComponentPartControlledKey =
|
|
12
|
+
| "children"
|
|
13
|
+
| "as"
|
|
14
|
+
| "value"
|
|
15
|
+
| "defaultValue"
|
|
16
|
+
| "open"
|
|
17
|
+
| "selected"
|
|
18
|
+
| "checked"
|
|
19
|
+
| "disabled"
|
|
20
|
+
| "readonly"
|
|
21
|
+
| "id"
|
|
22
|
+
| `on${string}`
|
|
23
|
+
| `aria-${string}`;
|
|
24
|
+
export type ConfigurableComponentPartProps<C extends Component<any>> = Partial<
|
|
25
|
+
Omit<ComponentProps<C>, ComponentPartControlledKey>
|
|
26
|
+
>;
|
|
27
|
+
export type ComponentPartsOf<
|
|
28
|
+
T extends Record<string, Component<any>>,
|
|
29
|
+
> = {
|
|
30
|
+
[K in keyof T]?: ConfigurableComponentPartProps<T[K]>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type ComponentPartsContext = {
|
|
34
|
+
getPart: (componentName: string) => ComponentPartProps | undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ComponentPartAccessor<T extends ComponentPartProps> = {
|
|
38
|
+
readonly current: Partial<T> | undefined;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function mergeClassValue(
|
|
42
|
+
inherited: unknown,
|
|
43
|
+
explicit: unknown,
|
|
44
|
+
): unknown {
|
|
45
|
+
if (typeof inherited !== "string") return explicit ?? inherited;
|
|
46
|
+
if (typeof explicit !== "string") return explicit ?? inherited;
|
|
47
|
+
return [inherited, explicit].filter(Boolean).join(" ");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mergeStyleValue(
|
|
51
|
+
inherited: unknown,
|
|
52
|
+
explicit: unknown,
|
|
53
|
+
): unknown {
|
|
54
|
+
if (typeof inherited !== "string") return explicit ?? inherited;
|
|
55
|
+
if (typeof explicit !== "string") return explicit ?? inherited;
|
|
56
|
+
const inheritedStyle = inherited.trim().replace(/;+$/, "");
|
|
57
|
+
const explicitStyle = explicit.trim().replace(/;+$/, "");
|
|
58
|
+
return [inheritedStyle, explicitStyle].filter(Boolean).join("; ");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 读取最近父级复合组件提供的同名 part。
|
|
63
|
+
* 返回 accessor 而不是快照,使父级替换 parts 对象时仍保持响应式。
|
|
64
|
+
*/
|
|
65
|
+
export function useComponentPart<T extends ComponentPartProps>(
|
|
66
|
+
componentName: string,
|
|
67
|
+
): ComponentPartAccessor<T> {
|
|
68
|
+
const context = getContext<ComponentPartsContext | undefined>(
|
|
69
|
+
COMPONENT_PARTS_CONTEXT_KEY,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
get current() {
|
|
74
|
+
return context?.getPart(componentName) as Partial<T> | undefined;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 为当前复合组件的直接子组件建立 parts 边界。
|
|
81
|
+
* 每个复合组件都提供自己的边界,因此祖先 parts 不会递归穿透。
|
|
82
|
+
*/
|
|
83
|
+
export function provideComponentParts(
|
|
84
|
+
getParts: () => ComponentParts | undefined,
|
|
85
|
+
): ComponentPartsContext {
|
|
86
|
+
const context: ComponentPartsContext = {
|
|
87
|
+
getPart(componentName) {
|
|
88
|
+
const parts = getParts();
|
|
89
|
+
const part = parts?.[componentName];
|
|
90
|
+
return part && typeof part === "object" ? part : undefined;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
setContext(COMPONENT_PARTS_CONTEXT_KEY, context);
|
|
94
|
+
return context;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 合并同类型 part 默认值与当前组件实例显式 Props。
|
|
99
|
+
* 显式 Props 胜出;class 合并;style 以 part 在前、显式值在后合并。
|
|
100
|
+
*/
|
|
101
|
+
export function mergeComponentPartProps<T extends ComponentPartProps>(
|
|
102
|
+
inherited: Partial<T> | undefined,
|
|
103
|
+
explicit: T,
|
|
104
|
+
): T {
|
|
105
|
+
if (!inherited) return explicit;
|
|
106
|
+
|
|
107
|
+
const explicitDefined = Object.fromEntries(
|
|
108
|
+
Object.entries(explicit).filter(([, value]) => value !== undefined),
|
|
109
|
+
) as T;
|
|
110
|
+
const merged = {
|
|
111
|
+
...inherited,
|
|
112
|
+
...explicitDefined,
|
|
113
|
+
} as T;
|
|
114
|
+
const writableMerged = merged as ComponentPartProps;
|
|
115
|
+
|
|
116
|
+
if ("class" in inherited || "class" in explicitDefined) {
|
|
117
|
+
writableMerged["class"] = mergeClassValue(
|
|
118
|
+
inherited["class"],
|
|
119
|
+
explicitDefined["class"],
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
if ("style" in inherited || "style" in explicitDefined) {
|
|
123
|
+
writableMerged["style"] = mergeStyleValue(
|
|
124
|
+
inherited["style"],
|
|
125
|
+
explicitDefined["style"],
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return merged;
|
|
130
|
+
}
|