@snowui-design-system/components 0.1.0
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 +82 -0
- package/package.json +47 -0
- package/src/App.svelte +103 -0
- package/src/components/Avatar.md +452 -0
- package/src/components/Avatar.svelte +593 -0
- package/src/components/Avatar.test.ts +231 -0
- package/src/components/AvatarGroup.md +246 -0
- package/src/components/AvatarGroup.svelte +691 -0
- package/src/components/AvatarGroup.test.ts +142 -0
- package/src/components/Badge.md +164 -0
- package/src/components/Badge.svelte +461 -0
- package/src/components/Badge.test.ts +293 -0
- package/src/components/Button.md +312 -0
- package/src/components/Button.svelte +796 -0
- package/src/components/Button.test.ts +631 -0
- package/src/components/Checkbox.md +313 -0
- package/src/components/Checkbox.svelte +466 -0
- package/src/components/Checkbox.test.ts +57 -0
- package/src/components/CodeBlock.md +240 -0
- package/src/components/CodeBlock.svelte +1287 -0
- package/src/components/CodeBlock.test.ts +192 -0
- package/src/components/Form.md +33 -0
- package/src/components/Form.test.ts +307 -0
- package/src/components/Frame.svelte +220 -0
- package/src/components/Icon.md +279 -0
- package/src/components/Icon.svelte +505 -0
- package/src/components/Icon.test.ts +82 -0
- package/src/components/Image.md +292 -0
- package/src/components/Image.svelte +634 -0
- package/src/components/Image.test.ts +42 -0
- package/src/components/ImageGroup.md +168 -0
- package/src/components/ImageGroup.svelte +151 -0
- package/src/components/ImageGroup.test.ts +46 -0
- package/src/components/InView.test.ts +55 -0
- package/src/components/Input.md +666 -0
- package/src/components/Input.svelte +2741 -0
- package/src/components/Input.test.ts +503 -0
- package/src/components/Kbd.md +100 -0
- package/src/components/Kbd.svelte +110 -0
- package/src/components/Kbd.test.ts +50 -0
- package/src/components/Listbox.md +245 -0
- package/src/components/Listbox.svelte +389 -0
- package/src/components/Listbox.test.ts +139 -0
- package/src/components/MenuItem.md +184 -0
- package/src/components/MenuItem.svelte +326 -0
- package/src/components/MenuItem.test.ts +167 -0
- package/src/components/Morph.test.ts +53 -0
- package/src/components/Popover.md +87 -0
- package/src/components/Popover.svelte +186 -0
- package/src/components/Popover.test.ts +60 -0
- package/src/components/QuickAction.md +146 -0
- package/src/components/QuickAction.svelte +161 -0
- package/src/components/QuickAction.test.ts +299 -0
- package/src/components/Radio.md +318 -0
- package/src/components/Radio.svelte +502 -0
- package/src/components/Radio.test.ts +76 -0
- package/src/components/Select.md +492 -0
- package/src/components/Select.svelte +535 -0
- package/src/components/Select.test.ts +146 -0
- package/src/components/Skeleton.md +323 -0
- package/src/components/Skeleton.svelte +791 -0
- package/src/components/Skeleton.test.ts +121 -0
- package/src/components/Spinner.md +136 -0
- package/src/components/Spinner.svelte +296 -0
- package/src/components/Spinner.test.ts +88 -0
- package/src/components/SplitText.test.ts +142 -0
- package/src/components/Stagger.test.ts +57 -0
- package/src/components/Test.md +72 -0
- package/src/components/Test.svelte +106 -0
- package/src/components/Test.test.ts +27 -0
- package/src/components/Text.md +450 -0
- package/src/components/Text.svelte +507 -0
- package/src/components/Text.test.ts +150 -0
- package/src/components/Textarea.md +240 -0
- package/src/components/Textarea.svelte +742 -0
- package/src/components/Textarea.test.ts +131 -0
- package/src/components/Toggle.md +196 -0
- package/src/components/Toggle.svelte +384 -0
- package/src/components/Toggle.test.ts +57 -0
- package/src/components/Tooltip.md +164 -0
- package/src/components/Tooltip.svelte +417 -0
- package/src/components/Tooltip.test.ts +64 -0
- package/src/context.ts +312 -0
- package/src/dev.ts +10 -0
- package/src/index.ts +29 -0
- package/src/keys.ts +26 -0
- package/src/lib/search-filter.md +82 -0
- package/src/lib/search-filter.ts +57 -0
- package/src/lib/truncate.md +25 -0
- package/src/lib/truncate.ts +234 -0
- package/src/logic/README.md +146 -0
- package/src/logic/collapse.svelte.ts +6 -0
- package/src/logic/frame-dom-runtime.md +19 -0
- package/src/logic/frame-dom-runtime.svelte.ts +286 -0
- package/src/logic/frame-field-control.md +38 -0
- package/src/logic/frame-field-control.ts +95 -0
- package/src/logic/frame-identity.md +68 -0
- package/src/logic/frame-identity.svelte.ts +25 -0
- package/src/logic/frame-layout.md +91 -0
- package/src/logic/frame-layout.svelte.ts +111 -0
- package/src/logic/frame-motion-defaults.md +180 -0
- package/src/logic/frame-motion-defaults.ts +711 -0
- package/src/logic/frame-profile.md +156 -0
- package/src/logic/frame-profile.ts +130 -0
- package/src/logic/frame-prop-filter.md +34 -0
- package/src/logic/frame-prop-filter.ts +254 -0
- package/src/logic/frame-responsive.md +91 -0
- package/src/logic/frame-responsive.svelte.ts +92 -0
- package/src/logic/frame-skeleton-runtime.md +20 -0
- package/src/logic/frame-skeleton-runtime.svelte.ts +160 -0
- package/src/logic/frame-truncation.md +127 -0
- package/src/logic/frame-truncation.svelte.ts +193 -0
- package/src/logic/frame-types.md +157 -0
- package/src/logic/frame-types.ts +434 -0
- package/src/logic/frame-utils.md +22 -0
- package/src/logic/frame-utils.ts +250 -0
- package/src/logic/geometry-cache.ts +120 -0
- package/src/logic/image-preview.md +24 -0
- package/src/logic/image-preview.ts +186 -0
- package/src/logic/layout-flip.ts +109 -0
- package/src/logic/motion-config.ts +102 -0
- package/src/logic/motion-types.md +47 -0
- package/src/logic/motion-types.ts +119 -0
- package/src/logic/observer.md +20 -0
- package/src/logic/observer.svelte.ts +53 -0
- package/src/logic/responsive.md +64 -0
- package/src/logic/responsive.svelte.ts +118 -0
- package/src/logic/text-collapse.md +22 -0
- package/src/logic/text-collapse.svelte.ts +507 -0
- package/src/logic/wc-adapter.ts +188 -0
- package/src/motion/NumberFlow.md +16 -0
- package/src/motion/README.md +87 -0
- package/src/motion/defaults/bridge.md +53 -0
- package/src/motion/defaults/bridge.ts +171 -0
- package/src/motion/defaults/content-crossfade.ts +22 -0
- package/src/motion/defaults/expand.md +66 -0
- package/src/motion/defaults/expand.ts +22 -0
- package/src/motion/defaults/fade-out.md +41 -0
- package/src/motion/defaults/fade-out.ts +14 -0
- package/src/motion/defaults/morph.md +42 -0
- package/src/motion/defaults/morph.ts +14 -0
- package/src/motion/defaults/move.md +81 -0
- package/src/motion/defaults/move.ts +31 -0
- package/src/motion/defaults/number.md +41 -0
- package/src/motion/defaults/number.ts +17 -0
- package/src/motion/defaults/replace.md +56 -0
- package/src/motion/defaults/replace.ts +22 -0
- package/src/motion/defaults/rotate.css +15 -0
- package/src/motion/defaults/rotate.md +60 -0
- package/src/motion/defaults/rotate.ts +20 -0
- package/src/motion/defaults/while-2xl.ts +9 -0
- package/src/motion/defaults/while-active.ts +12 -0
- package/src/motion/defaults/while-appear.ts +12 -0
- package/src/motion/defaults/while-click.ts +9 -0
- package/src/motion/defaults/while-collapsed.ts +12 -0
- package/src/motion/defaults/while-disabled.ts +13 -0
- package/src/motion/defaults/while-disappear.ts +12 -0
- package/src/motion/defaults/while-drag.ts +9 -0
- package/src/motion/defaults/while-editing.ts +9 -0
- package/src/motion/defaults/while-expanded.ts +12 -0
- package/src/motion/defaults/while-focus.ts +9 -0
- package/src/motion/defaults/while-hover.ts +13 -0
- package/src/motion/defaults/while-idle.ts +9 -0
- package/src/motion/defaults/while-key.ts +9 -0
- package/src/motion/defaults/while-lg.ts +9 -0
- package/src/motion/defaults/while-load.ts +11 -0
- package/src/motion/defaults/while-md.ts +9 -0
- package/src/motion/defaults/while-reload.ts +12 -0
- package/src/motion/defaults/while-scroll.ts +9 -0
- package/src/motion/defaults/while-sm.ts +9 -0
- package/src/motion/defaults/while-uploading.ts +9 -0
- package/src/motion/defaults/while-validating.ts +9 -0
- package/src/motion/defaults/while-xl.ts +9 -0
- package/src/motion/defaults/while-xs.ts +9 -0
- package/src/styles/README.md +95 -0
- package/src/styles/auto-layout.css +111 -0
- package/src/styles/index.css +7 -0
- package/src/styles/layout.css +319 -0
- package/src/styles/scale.css +106 -0
- package/src/styles/scale.md +218 -0
- package/src/styles/scrollbar.css +173 -0
- package/src/styles/tokens.css +192 -0
- package/src/vite-env.d.ts +9 -0
- package/src//344/273/243/347/240/201.txt +61 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Frame Profile (能力画像)
|
|
2
|
+
|
|
3
|
+
> **版本**: v2.2.2
|
|
4
|
+
> **类型**: 逻辑模块
|
|
5
|
+
> **关联样式**: `Frame.svelte` 内联样式
|
|
6
|
+
|
|
7
|
+
Frame Profile 通过预定义的能力画像(Profile),快速赋予 Frame 组件特定的一组默认行为和样式。它是"配置优于代码"原则在 SnowUI 中的体现。
|
|
8
|
+
|
|
9
|
+
## 1. 核心概念
|
|
10
|
+
|
|
11
|
+
通过 `profile` 属性指定组件的角色画像。不同的画像会自动注入不同的默认属性(样式类、交互逻辑等)。
|
|
12
|
+
|
|
13
|
+
| Profile | 描述 | 用途 |
|
|
14
|
+
| :--- | :--- | :--- |
|
|
15
|
+
| `Surface` | **可操作表面** | 按钮、菜单项、列表项等需要用户点击的区域。 |
|
|
16
|
+
| `Field` | **输入区域** | Input、Textarea、Select 等需要用户输入的区域。 |
|
|
17
|
+
| `Container` | **数据容器** | 仅用于布局包裹,没有任何交互样式。 |
|
|
18
|
+
| `Anchor` | **定位锚点** | 链接导航,hover 改变颜色。 |
|
|
19
|
+
|
|
20
|
+
## 2. Profile 详解
|
|
21
|
+
|
|
22
|
+
### 2.1 Surface (可操作表面)
|
|
23
|
+
|
|
24
|
+
最常用的 Profile,用于构建具备标准交互反馈的 UI 元素。
|
|
25
|
+
|
|
26
|
+
* **注入类名**: `.snowui-profile-surface`
|
|
27
|
+
* **默认行为**:
|
|
28
|
+
* `cursor: pointer`
|
|
29
|
+
* `whileClick`: 默认点击动效
|
|
30
|
+
* **Hover**: 自动叠加 `color-mix(currentColor, 4%/10%)`,可通过 `--hover-opacity` 覆盖
|
|
31
|
+
|
|
32
|
+
**样式定义**:
|
|
33
|
+
> 样式定义已内联至 `src/components/Frame.svelte`
|
|
34
|
+
|
|
35
|
+
```css
|
|
36
|
+
.snowui-profile-surface:hover {
|
|
37
|
+
background-image: linear-gradient(
|
|
38
|
+
color-mix(in srgb, currentColor var(--hover-opacity, 4%), transparent),
|
|
39
|
+
color-mix(in srgb, currentColor var(--hover-opacity, 4%), transparent)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2.2 Field (输入区域) [New in v2.2]
|
|
45
|
+
|
|
46
|
+
用于输入型组件,提供 focus 状态而非 hover 叠加。
|
|
47
|
+
|
|
48
|
+
* **注入类名**: `.snowui-profile-field`
|
|
49
|
+
* **默认行为**:
|
|
50
|
+
* `cursor: text`
|
|
51
|
+
* **Default**: 基础内边框为 `Black/20%`
|
|
52
|
+
* **Hover**: 边框颜色加深
|
|
53
|
+
* **Focus**: 边框变为 `Black/40%`,外层显示 `Black/4%` 的 4px focus ring
|
|
54
|
+
* 支持通过 `--snowui-field-*` 变量覆写默认边框、hover、focus 与光标表现,供 `Input / Textarea / Select` 等组件把自身基础样式桥接到 Profile 层
|
|
55
|
+
|
|
56
|
+
```css
|
|
57
|
+
.snowui-profile-field:hover {
|
|
58
|
+
border-color: var(--black-20);
|
|
59
|
+
}
|
|
60
|
+
.snowui-profile-field:focus-within {
|
|
61
|
+
border-color: var(--black-40);
|
|
62
|
+
box-shadow: 0 0 0 4px var(--black-4);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2.3 Container (容器)
|
|
67
|
+
|
|
68
|
+
* **注入类名**: `.snowui-profile-container`
|
|
69
|
+
* **用途**: 纯净的布局容器,无额外样式。
|
|
70
|
+
|
|
71
|
+
### 2.4 Anchor (锚点)
|
|
72
|
+
|
|
73
|
+
* **注入类名**: `.snowui-profile-anchor`
|
|
74
|
+
* **用途**: 链接导航,hover 时改变颜色。
|
|
75
|
+
|
|
76
|
+
## 3. 优先级规则 (Priority Rules)
|
|
77
|
+
|
|
78
|
+
Profile 仅提供**默认值 (Defaults)**。用户显式定义的属性永远拥有更高优先级。
|
|
79
|
+
|
|
80
|
+
1. **覆盖原则**: 如果用户定义了 `whileHover`,则 Profile 默认的 `whileHover` 被完全替换(而非合并)。
|
|
81
|
+
2. **追加原则** (仅 Class/Style): Profile 注入的 `class` 和 `style` 会追加到用户定义的样式之后。
|
|
82
|
+
|
|
83
|
+
## 4. 扩展 API
|
|
84
|
+
|
|
85
|
+
### 4.1 自定义 Profile (`defineProfile`)
|
|
86
|
+
|
|
87
|
+
允许用户定义全新的 Profile。
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { defineProfile } from '@snowui/components';
|
|
91
|
+
|
|
92
|
+
defineProfile('Card', {
|
|
93
|
+
class: 'my-card',
|
|
94
|
+
whileHover: { scale: 1.02 },
|
|
95
|
+
whileClick: { scale: 0.98 }
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 4.2 继承 Profile (`extendProfile`)
|
|
100
|
+
|
|
101
|
+
基于现有 Profile 创建变体。
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { extendProfile } from '@snowui/components';
|
|
105
|
+
|
|
106
|
+
// 继承 Surface,创建 InteractiveCard
|
|
107
|
+
extendProfile('Surface', 'InteractiveCard', {
|
|
108
|
+
whileHover: { scale: 1.05 },
|
|
109
|
+
class: 'interactive-card'
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**合并规则**:
|
|
114
|
+
- `class` 和 `style`: 追加到基础 Profile
|
|
115
|
+
- 其他属性: 覆盖基础 Profile
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
<!-- @UserDefined -->
|
|
120
|
+
<!-- 用户可以在此定义额外的业务 Profile 规则,严禁 AI 修改 -->
|
|
121
|
+
<!-- /@UserDefined -->
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
# For AI
|
|
126
|
+
|
|
127
|
+
## Module Index
|
|
128
|
+
|
|
129
|
+
* **Logic Implementation**: [frame-profile.ts](./frame-profile.ts)
|
|
130
|
+
* **Type Definitions**: [frame-types.ts](./frame-types.ts)
|
|
131
|
+
|
|
132
|
+
## Dependency Graph
|
|
133
|
+
|
|
134
|
+
* **Child Of**: [Frame.svelte](./../components/Frame.svelte) (Imported and used to resolve props)
|
|
135
|
+
* **Related Styles**: inlined in `src/components/Frame.svelte`
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 更新日志 (Changelog)
|
|
140
|
+
|
|
141
|
+
### v2.2.2 (2026-03-15)
|
|
142
|
+
- **调整**: `Field` Profile 默认基础边框统一为 `Black/20%`,与 `Input / Textarea / Select` 的默认视觉对齐。
|
|
143
|
+
|
|
144
|
+
### v2.2.0 (2026-01-23)
|
|
145
|
+
- **新增**: `Field` Profile,用于输入型组件 (Input, Textarea, Select)
|
|
146
|
+
- **改进**: Surface hover 样式使用 `var(--hover-opacity, 4%)` 默认值
|
|
147
|
+
- **改进**: 文档新增 hover 样式说明
|
|
148
|
+
|
|
149
|
+
### v2.1.0 (2026-01-20)
|
|
150
|
+
- **新增**: `defineProfile()` 函数,支持用户自定义 Profile
|
|
151
|
+
- **新增**: `extendProfile()` 函数,支持 Profile 继承
|
|
152
|
+
- **改进**: 使用 `Map` 替代 `Record` 存储配置,支持动态扩展
|
|
153
|
+
- **修复**: `transition: all` 改为显式属性列表,避免性能问题
|
|
154
|
+
|
|
155
|
+
### v1.0.0
|
|
156
|
+
- 初始版本,实现 Surface、Container、Anchor 三种内置 Profile
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { FrameProps, FrameProfile } from './frame-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Profile 配置存储
|
|
5
|
+
* 使用 Map 支持动态注册自定义 Profile
|
|
6
|
+
*/
|
|
7
|
+
const profileConfigs = new Map<string, Partial<FrameProps>>([
|
|
8
|
+
['Surface', {
|
|
9
|
+
class: 'snowui-profile-surface',
|
|
10
|
+
whileClick: {}
|
|
11
|
+
}],
|
|
12
|
+
['Field', {
|
|
13
|
+
class: 'snowui-profile-field',
|
|
14
|
+
// TODO: 样式待提供 (输入型交互: Input, Textarea, Select)
|
|
15
|
+
}],
|
|
16
|
+
['Container', {
|
|
17
|
+
class: 'snowui-profile-container',
|
|
18
|
+
// 纯净状态,无默认行为
|
|
19
|
+
}],
|
|
20
|
+
['Anchor', {
|
|
21
|
+
class: 'snowui-profile-anchor',
|
|
22
|
+
// 预留,目前无默认行为
|
|
23
|
+
}]
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 定义自定义 Profile
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* defineProfile('Card', {
|
|
32
|
+
* class: 'my-card',
|
|
33
|
+
* whileHover: { scale: 1.02 },
|
|
34
|
+
* profile: 'Surface' // 可选:继承自 Surface
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param name - Profile 名称
|
|
39
|
+
* @param config - Profile 配置
|
|
40
|
+
*/
|
|
41
|
+
export function defineProfile(name: string, config: Partial<FrameProps>): void {
|
|
42
|
+
profileConfigs.set(name, config);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 扩展现有 Profile(继承)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* extendProfile('Surface', 'InteractiveCard', {
|
|
51
|
+
* whileHover: { scale: 1.05 },
|
|
52
|
+
* whileClick: { scale: 0.98 }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param base - 基础 Profile 名称
|
|
57
|
+
* @param name - 新 Profile 名称
|
|
58
|
+
* @param overrides - 覆盖/扩展的配置
|
|
59
|
+
*/
|
|
60
|
+
export function extendProfile(
|
|
61
|
+
base: FrameProfile | string,
|
|
62
|
+
name: string,
|
|
63
|
+
overrides: Partial<FrameProps>
|
|
64
|
+
): void {
|
|
65
|
+
const baseConfig = profileConfigs.get(base) || {};
|
|
66
|
+
|
|
67
|
+
// 合并配置,class 和 style 追加,其他属性覆盖
|
|
68
|
+
const merged: Partial<FrameProps> = { ...baseConfig };
|
|
69
|
+
|
|
70
|
+
for (const key in overrides) {
|
|
71
|
+
const propKey = key as keyof FrameProps;
|
|
72
|
+
if (propKey === 'class' && baseConfig.class && overrides.class) {
|
|
73
|
+
merged.class = `${baseConfig.class} ${overrides.class}`;
|
|
74
|
+
} else if (propKey === 'style' && baseConfig.style && overrides.style) {
|
|
75
|
+
merged.style = `${baseConfig.style}; ${overrides.style}`;
|
|
76
|
+
} else {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
merged[propKey] = overrides[propKey];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
profileConfigs.set(name, merged);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 获取 Profile 配置(内部使用)
|
|
87
|
+
*/
|
|
88
|
+
export function getProfileConfig(profile: string): Partial<FrameProps> | undefined {
|
|
89
|
+
return profileConfigs.get(profile);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 解析 Profile 属性,合并默认配置
|
|
94
|
+
* 用户显式传入的 props 优先级高于 Profile 默认值
|
|
95
|
+
*
|
|
96
|
+
* @param profile - 组件的 Profile(支持内置和自定义)
|
|
97
|
+
* @param userProps - 用户传入的原始 Props
|
|
98
|
+
* @returns 合并后的 Props
|
|
99
|
+
*/
|
|
100
|
+
export function resolveProfileProps(
|
|
101
|
+
profile: FrameProfile | string | undefined,
|
|
102
|
+
userProps: FrameProps
|
|
103
|
+
): FrameProps {
|
|
104
|
+
if (!profile || !profileConfigs.has(profile)) {
|
|
105
|
+
return userProps;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const defaults = profileConfigs.get(profile)!;
|
|
109
|
+
const merged: FrameProps = { ...userProps };
|
|
110
|
+
|
|
111
|
+
// 遍历默认配置进行合并
|
|
112
|
+
for (const key in defaults) {
|
|
113
|
+
const propKey = key as keyof FrameProps;
|
|
114
|
+
|
|
115
|
+
// 只有当用户未显式定义该属性时,才使用 Profile 默认值
|
|
116
|
+
if (merged[propKey] === undefined) {
|
|
117
|
+
// @ts-ignore - 这里的类型比较复杂,暂时忽略
|
|
118
|
+
merged[propKey] = defaults[propKey];
|
|
119
|
+
} else if (propKey === 'class' && defaults.class) {
|
|
120
|
+
// 特殊处理 class:追加而非覆盖
|
|
121
|
+
merged.class = `${defaults.class} ${merged.class}`;
|
|
122
|
+
} else if (propKey === 'style' && defaults.style) {
|
|
123
|
+
// 特殊处理 style:追加而非覆盖
|
|
124
|
+
merged.style = `${defaults.style} ${merged.style}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return merged;
|
|
129
|
+
}
|
|
130
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frame-prop-filter.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.1.0
|
|
4
|
+
> **职责**: 统一维护 Frame 内部关键字识别规则,同时提供 DOM 过滤与复合组件 props 分发能力。
|
|
5
|
+
|
|
6
|
+
## 功能
|
|
7
|
+
|
|
8
|
+
- `filterFrameDomProps(frameProps)`:
|
|
9
|
+
- 提取原生事件处理器 `eventHandlers`
|
|
10
|
+
- 移除内部关键字后输出 `domProps`
|
|
11
|
+
- 提供 `disabled` 统一布尔值
|
|
12
|
+
- `isFrameInternalProp(key, options?)`:
|
|
13
|
+
- 判断某个 prop 名是否属于 Frame 内部关键字
|
|
14
|
+
- 支持附加 `customStates` 对应的动态状态名识别
|
|
15
|
+
- `splitFrameHostProps(source, options?)`:
|
|
16
|
+
- 将复合组件收到的 props 拆分为 `frameProps` 和 `hostProps`
|
|
17
|
+
- 适用于 `Input / Textarea / Select` 这类“外层 Frame + 内层原生宿主元素”的组件
|
|
18
|
+
|
|
19
|
+
## 设计说明
|
|
20
|
+
|
|
21
|
+
- 将“DOM 透传白/黑名单”集中管理,避免 `Frame.svelte` 里超长解构列表。
|
|
22
|
+
- 将“复合组件 props 分发规则”与 “Frame DOM 过滤规则”收敛到同一份关键字真相来源,避免组件侧再维护一套平行白名单。
|
|
23
|
+
- 便于后续在 standards 检查脚本中复用关键字集合。
|
|
24
|
+
|
|
25
|
+
## 更新日志
|
|
26
|
+
|
|
27
|
+
### v1.1.0 (2026-03-14)
|
|
28
|
+
|
|
29
|
+
- 新增 `isFrameInternalProp` 与 `splitFrameHostProps`,供 `Input / Textarea` 等复合组件复用。
|
|
30
|
+
- Frame DOM 过滤改为复用同一份内部关键字识别逻辑,减少重复维护。
|
|
31
|
+
|
|
32
|
+
### v1.0.0 (2026-02-07)
|
|
33
|
+
|
|
34
|
+
- 新增 Frame 属性过滤模块,减少 `Frame.svelte` 内联解构复杂度。
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame 属性过滤器
|
|
3
|
+
* - 分离原生事件处理器
|
|
4
|
+
* - 过滤内部关键字,避免透传到 DOM
|
|
5
|
+
* - 为 Input / Textarea 这类“Frame 外壳 + 原生宿主元素”组件提供共享的 props 分发能力
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const NATIVE_EVENT_KEYS = [
|
|
9
|
+
"onclick",
|
|
10
|
+
"ondblclick",
|
|
11
|
+
"oncontextmenu",
|
|
12
|
+
"onmouseenter",
|
|
13
|
+
"onmouseleave",
|
|
14
|
+
"onmousemove",
|
|
15
|
+
"onmousedown",
|
|
16
|
+
"onmouseup",
|
|
17
|
+
"onfocus",
|
|
18
|
+
"onblur",
|
|
19
|
+
"onkeydown",
|
|
20
|
+
"onkeyup",
|
|
21
|
+
"onkeypress",
|
|
22
|
+
"ontouchstart",
|
|
23
|
+
"ontouchend",
|
|
24
|
+
"ontouchmove",
|
|
25
|
+
"ontouchcancel",
|
|
26
|
+
"oninput",
|
|
27
|
+
"onchange",
|
|
28
|
+
"onsubmit",
|
|
29
|
+
"onscroll",
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
32
|
+
export const FRAME_INTERNAL_PROP_KEYS = [
|
|
33
|
+
"enableResponsive",
|
|
34
|
+
"enableContext",
|
|
35
|
+
"enableScaleObserver",
|
|
36
|
+
"enableDefaultMotion",
|
|
37
|
+
"enableAutoLayout",
|
|
38
|
+
"profile",
|
|
39
|
+
"scope",
|
|
40
|
+
"lines",
|
|
41
|
+
"onTruncate",
|
|
42
|
+
"access",
|
|
43
|
+
"responsive",
|
|
44
|
+
"scaleHeightVar",
|
|
45
|
+
"scaleWidthVar",
|
|
46
|
+
"scaleAspectRatioVar",
|
|
47
|
+
"scaleSizeVar",
|
|
48
|
+
"scaleObserverTarget",
|
|
49
|
+
"scaleBasis",
|
|
50
|
+
"scaleMixHeightWeight",
|
|
51
|
+
"scaleAspectBaseRatio",
|
|
52
|
+
"sizeRatio",
|
|
53
|
+
"iconSizeRatio",
|
|
54
|
+
"avatarSizeRatio",
|
|
55
|
+
"loopMotion",
|
|
56
|
+
"loading",
|
|
57
|
+
"disabled",
|
|
58
|
+
"skeleton",
|
|
59
|
+
"renderHints",
|
|
60
|
+
"customStates",
|
|
61
|
+
"stateContent",
|
|
62
|
+
"styles",
|
|
63
|
+
"padding",
|
|
64
|
+
"gap",
|
|
65
|
+
"radius",
|
|
66
|
+
"border",
|
|
67
|
+
"innerBorder",
|
|
68
|
+
"fontSize",
|
|
69
|
+
"minWidth",
|
|
70
|
+
"minHeight",
|
|
71
|
+
"width",
|
|
72
|
+
"height",
|
|
73
|
+
"opacity",
|
|
74
|
+
"size",
|
|
75
|
+
"iconSize",
|
|
76
|
+
"avatarSize",
|
|
77
|
+
"collapsed",
|
|
78
|
+
"expanded",
|
|
79
|
+
"row",
|
|
80
|
+
"column",
|
|
81
|
+
"grid",
|
|
82
|
+
"reverse",
|
|
83
|
+
"whileHover",
|
|
84
|
+
"whileClick",
|
|
85
|
+
"whileFocus",
|
|
86
|
+
"whileDrag",
|
|
87
|
+
"whileScroll",
|
|
88
|
+
"whileKey",
|
|
89
|
+
"whileLoad",
|
|
90
|
+
"whileReload",
|
|
91
|
+
"whileActive",
|
|
92
|
+
"whileDisabled",
|
|
93
|
+
"whileAppear",
|
|
94
|
+
"whileDisappear",
|
|
95
|
+
"whileIdle",
|
|
96
|
+
"whileValidating",
|
|
97
|
+
"whileUploading",
|
|
98
|
+
"whileEditing",
|
|
99
|
+
"whileCollapsed",
|
|
100
|
+
"whileExpanded",
|
|
101
|
+
"whileXs",
|
|
102
|
+
"whileSm",
|
|
103
|
+
"whileMd",
|
|
104
|
+
"whileLg",
|
|
105
|
+
"whileXl",
|
|
106
|
+
"while2xl",
|
|
107
|
+
"variants",
|
|
108
|
+
"scroll",
|
|
109
|
+
"timeline",
|
|
110
|
+
"layoutId",
|
|
111
|
+
"itemId",
|
|
112
|
+
"orchestrate",
|
|
113
|
+
"orchestrateMode",
|
|
114
|
+
"orchestrateDelay",
|
|
115
|
+
"orchestrateOrder",
|
|
116
|
+
"orchestrateTrigger",
|
|
117
|
+
"orchestrateTarget",
|
|
118
|
+
"orchestrateGroup",
|
|
119
|
+
"morph",
|
|
120
|
+
"tag",
|
|
121
|
+
"as",
|
|
122
|
+
"element",
|
|
123
|
+
"use",
|
|
124
|
+
"Click",
|
|
125
|
+
"Hover",
|
|
126
|
+
"Focus",
|
|
127
|
+
"Key",
|
|
128
|
+
"Drag",
|
|
129
|
+
"Scroll",
|
|
130
|
+
"Active",
|
|
131
|
+
"Load",
|
|
132
|
+
"Reload",
|
|
133
|
+
"StartLoad",
|
|
134
|
+
"Appear",
|
|
135
|
+
"Disappear",
|
|
136
|
+
"Idle",
|
|
137
|
+
"Disabled",
|
|
138
|
+
"Validating",
|
|
139
|
+
"Uploading",
|
|
140
|
+
"Editing",
|
|
141
|
+
"onReload",
|
|
142
|
+
"stateVars",
|
|
143
|
+
"stateClass",
|
|
144
|
+
"stateStyle",
|
|
145
|
+
] as const;
|
|
146
|
+
|
|
147
|
+
export const FRAME_INTERNAL_PROP_PATTERNS = [
|
|
148
|
+
/^(StartLoad|Load|Reload|Appear|Disappear|Idle|Active|Disabled|Validating|Uploading|Editing)$/,
|
|
149
|
+
/^(Click|Drag|Hover|Focus|Key|Scroll)$/,
|
|
150
|
+
/^while[A-Z0-9].*$/,
|
|
151
|
+
/^(xs|sm|md|lg|xl|2xl)$/,
|
|
152
|
+
/^onReload$/,
|
|
153
|
+
] as const;
|
|
154
|
+
|
|
155
|
+
export interface FrameEventHandlers {
|
|
156
|
+
[key: string]: any;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface SplitFrameHostPropsResult {
|
|
160
|
+
frameProps: Record<string, any>;
|
|
161
|
+
hostProps: Record<string, any>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface FilteredFrameProps {
|
|
165
|
+
eventHandlers: FrameEventHandlers;
|
|
166
|
+
domProps: Record<string, any>;
|
|
167
|
+
disabled: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function collectCustomStateNames(
|
|
171
|
+
source?: Record<string, any>,
|
|
172
|
+
options?: { customStates?: string[] },
|
|
173
|
+
): Set<string> {
|
|
174
|
+
const names = new Set<string>();
|
|
175
|
+
const candidates = [
|
|
176
|
+
...(Array.isArray(source?.customStates) ? source.customStates : []),
|
|
177
|
+
...(options?.customStates ?? []),
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
for (const candidate of candidates) {
|
|
181
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
182
|
+
names.add(candidate.trim());
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return names;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function isFrameInternalProp(
|
|
190
|
+
key: string,
|
|
191
|
+
options?: {
|
|
192
|
+
customStateNames?: Iterable<string>;
|
|
193
|
+
},
|
|
194
|
+
): boolean {
|
|
195
|
+
if (
|
|
196
|
+
(FRAME_INTERNAL_PROP_KEYS as readonly string[]).includes(key) ||
|
|
197
|
+
FRAME_INTERNAL_PROP_PATTERNS.some((pattern) => pattern.test(key))
|
|
198
|
+
) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (options?.customStateNames) {
|
|
203
|
+
for (const stateName of options.customStateNames) {
|
|
204
|
+
if (stateName === key) return true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function splitFrameHostProps(
|
|
212
|
+
source: Record<string, any>,
|
|
213
|
+
options?: {
|
|
214
|
+
customStates?: string[];
|
|
215
|
+
},
|
|
216
|
+
): SplitFrameHostPropsResult {
|
|
217
|
+
const frameProps: Record<string, any> = {};
|
|
218
|
+
const hostProps: Record<string, any> = {};
|
|
219
|
+
const customStateNames = collectCustomStateNames(source, options);
|
|
220
|
+
|
|
221
|
+
for (const [key, value] of Object.entries(source)) {
|
|
222
|
+
if (isFrameInternalProp(key, { customStateNames })) {
|
|
223
|
+
frameProps[key] = value;
|
|
224
|
+
} else {
|
|
225
|
+
hostProps[key] = value;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return { frameProps, hostProps };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function filterFrameDomProps(frameProps: any): FilteredFrameProps {
|
|
233
|
+
const eventHandlers: FrameEventHandlers = {};
|
|
234
|
+
for (const key of NATIVE_EVENT_KEYS) {
|
|
235
|
+
eventHandlers[key] = frameProps[key];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const domProps: Record<string, any> = { ...frameProps };
|
|
239
|
+
for (const key of NATIVE_EVENT_KEYS) {
|
|
240
|
+
delete domProps[key];
|
|
241
|
+
}
|
|
242
|
+
const customStateNames = collectCustomStateNames(frameProps);
|
|
243
|
+
for (const key of Object.keys(domProps)) {
|
|
244
|
+
if (isFrameInternalProp(key, { customStateNames })) {
|
|
245
|
+
delete domProps[key];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
eventHandlers,
|
|
251
|
+
domProps,
|
|
252
|
+
disabled: !!frameProps.disabled,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frame-responsive.svelte.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v2.1.0
|
|
4
|
+
> **职责**: 管理组件的响应式能力,提供断点检测。
|
|
5
|
+
|
|
6
|
+
**需求**: 基于容器宽度实现响应式设计,允许在不同断点下覆写组件属性、样式或形态。
|
|
7
|
+
|
|
8
|
+
## 1. 共享监听机制 (Shared Observer)
|
|
9
|
+
|
|
10
|
+
为了优化性能,`FrameResponsive` 使用**全局单例**的 `ResizeObserver`。
|
|
11
|
+
|
|
12
|
+
- **机制**: 无论页面上有多少个 `Frame` 组件,都只创建一个 `ResizeObserver` 实例。
|
|
13
|
+
- **订阅**: 每个 `Frame` 组件注册时,将自身元素添加到订阅列表。
|
|
14
|
+
- **分发**: 当 `ResizeObserver` 触发回调时,根据变化的元素分发给对应的订阅者。
|
|
15
|
+
- **清理**: 当所有订阅者都注销后,自动断开 `ResizeObserver` 连接以释放资源。
|
|
16
|
+
|
|
17
|
+
### 1.1 内存管理优化 [New in v2.1]
|
|
18
|
+
|
|
19
|
+
使用 `WeakMap` 替代 `Map` 存储订阅者回调,允许元素被垃圾回收时自动清理订阅关系。
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// 使用 WeakMap 防止内存泄漏
|
|
23
|
+
const subscribers = new WeakMap<Element, (width: number) => void>();
|
|
24
|
+
// 配合 Set 管理元素生命周期 (WeakMap 不可遍历)
|
|
25
|
+
const observedElements = new Set<Element>();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 2. 断点定义 (Breakpoints)
|
|
29
|
+
|
|
30
|
+
遵循 Tailwind CSS 标准断点:
|
|
31
|
+
|
|
32
|
+
| 断点名称 | 最小宽度 (px) | 描述 |
|
|
33
|
+
| :--- | :--- | :--- |
|
|
34
|
+
| **xs** | 0 | 超小屏 (默认) |
|
|
35
|
+
| **sm** | 640 | 小屏 |
|
|
36
|
+
| **md** | 768 | 中屏 |
|
|
37
|
+
| **lg** | 1024 | 大屏 |
|
|
38
|
+
| **xl** | 1280 | 超大屏 |
|
|
39
|
+
| **2xl** | 1536 | 超超大屏 |
|
|
40
|
+
|
|
41
|
+
## 3. 状态属性
|
|
42
|
+
|
|
43
|
+
| 属性 | 类型 | 描述 |
|
|
44
|
+
| :--- | :--- | :--- |
|
|
45
|
+
| containerWidth | `number` | 当前容器宽度 (px) |
|
|
46
|
+
| breakpoint | `string` | 当前生效的断点名称 (`xs` - `2xl`) |
|
|
47
|
+
|
|
48
|
+
## 4. 使用方式
|
|
49
|
+
|
|
50
|
+
在 `Frame` 组件中:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const responsive = new FrameResponsive();
|
|
54
|
+
|
|
55
|
+
// 绑定到 DOM 元素
|
|
56
|
+
use:responsive.resizeObserver
|
|
57
|
+
|
|
58
|
+
// 获取当前断点
|
|
59
|
+
const currentBp = responsive.breakpoint;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 5. 全局配置 (Global Configuration)
|
|
63
|
+
|
|
64
|
+
支持通过 Svelte Context 注入全局断点配置。
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { setContext } from 'svelte';
|
|
68
|
+
import { FRAME_BREAKPOINTS_CONTEXT_KEY } from '@snowui/keys';
|
|
69
|
+
|
|
70
|
+
setContext(FRAME_BREAKPOINTS_CONTEXT_KEY, {
|
|
71
|
+
xs: 600,
|
|
72
|
+
sm: 800,
|
|
73
|
+
md: 1000,
|
|
74
|
+
lg: 1200,
|
|
75
|
+
xl: 1400,
|
|
76
|
+
"2xl": 1600
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 更新日志 (Changelog)
|
|
83
|
+
|
|
84
|
+
### v2.1.0 (2026-01-20)
|
|
85
|
+
- **内存优化**: 使用 `WeakMap` 替代 `Map` 存储订阅者,防止内存泄漏
|
|
86
|
+
- **新增**: `observedElements` Set 用于管理元素生命周期
|
|
87
|
+
- **改进**: 完善 `destroy()` 清理逻辑
|
|
88
|
+
|
|
89
|
+
### v1.0.0
|
|
90
|
+
- 初始版本,实现共享 `ResizeObserver` 机制
|
|
91
|
+
|