@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,38 @@
|
|
|
1
|
+
# frame-field-control.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.0
|
|
4
|
+
> **职责**: 为 `Input / Textarea / Select` 这类“外层 Frame + 内层原生表单宿主元素”的组件提供共享字段桥接逻辑。
|
|
5
|
+
|
|
6
|
+
## 功能
|
|
7
|
+
|
|
8
|
+
- `resolveFrameFieldValue(value, defaultValue, options?)`
|
|
9
|
+
- 统一解析 `value / defaultValue`
|
|
10
|
+
- 支持按控件类型跳过不应绑定值的宿主类型(如 `input[type="file"]`)
|
|
11
|
+
- `resolveFrameFieldInvalid(invalid, hostProps?)`
|
|
12
|
+
- 统一归一 `invalid` 与 `aria-invalid`
|
|
13
|
+
- `readFrameFieldValue(target, options?)`
|
|
14
|
+
- 从原生宿主元素读取当前值
|
|
15
|
+
- `syncFrameFieldValue(target, assign, options?)`
|
|
16
|
+
- 读取宿主值并写回组件绑定值
|
|
17
|
+
|
|
18
|
+
## 适用场景
|
|
19
|
+
|
|
20
|
+
- `Input`
|
|
21
|
+
- 后续 `Textarea`
|
|
22
|
+
- 后续 `Select`
|
|
23
|
+
- 其他以原生表单元素为宿主、但外层仍由 `Frame` 承担通用能力的复合组件
|
|
24
|
+
|
|
25
|
+
## 设计说明
|
|
26
|
+
|
|
27
|
+
- 这层逻辑不关心 `Frame` 的样式和状态机,只负责字段值与无效态桥接。
|
|
28
|
+
- `file` 输入这类“不应把值回写到组件绑定值”的宿主规则集中在这里,避免每个组件单独判断。
|
|
29
|
+
- 目标是让宿主型组件只负责:
|
|
30
|
+
- props 声明
|
|
31
|
+
- 样式
|
|
32
|
+
- 原生结构
|
|
33
|
+
|
|
34
|
+
## 更新日志
|
|
35
|
+
|
|
36
|
+
### v1.0.0 (2026-03-14)
|
|
37
|
+
|
|
38
|
+
- 新增字段宿主桥接模块,统一 `value/defaultValue`、`invalid/aria-invalid` 与宿主值同步逻辑。
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame Field Control
|
|
3
|
+
* v1.0.0
|
|
4
|
+
*
|
|
5
|
+
* 统一处理“Frame 外壳 + 原生表单宿主元素”的字段桥接:
|
|
6
|
+
* - value/defaultValue 解析
|
|
7
|
+
* - invalid / aria-invalid 归一
|
|
8
|
+
* - 宿主元素值同步
|
|
9
|
+
*
|
|
10
|
+
* 目标:避免 Input / Textarea / Select 各自重复维护一套字段桥接逻辑。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export type FrameFieldValue = string | number | undefined;
|
|
14
|
+
|
|
15
|
+
export type FrameFieldHostElement =
|
|
16
|
+
| HTMLInputElement
|
|
17
|
+
| HTMLTextAreaElement
|
|
18
|
+
| HTMLSelectElement;
|
|
19
|
+
|
|
20
|
+
export interface FrameFieldControlOptions {
|
|
21
|
+
controlType?: string;
|
|
22
|
+
skipTypes?: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function normalizeControlType(value?: string) {
|
|
26
|
+
return value?.trim().toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function shouldSkipByType(options?: FrameFieldControlOptions) {
|
|
30
|
+
const currentType = normalizeControlType(options?.controlType);
|
|
31
|
+
if (!currentType) return false;
|
|
32
|
+
|
|
33
|
+
return (options?.skipTypes ?? []).some(
|
|
34
|
+
(candidate) => normalizeControlType(candidate) === currentType,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function resolveFrameFieldValue<T extends FrameFieldValue>(
|
|
39
|
+
value: T,
|
|
40
|
+
defaultValue: T,
|
|
41
|
+
options?: FrameFieldControlOptions,
|
|
42
|
+
): T | undefined {
|
|
43
|
+
if (shouldSkipByType(options)) return undefined;
|
|
44
|
+
return value !== undefined ? value : defaultValue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function resolveFrameFieldInvalid(
|
|
48
|
+
invalid = false,
|
|
49
|
+
hostProps?: Record<string, any>,
|
|
50
|
+
): boolean {
|
|
51
|
+
const ariaInvalid = hostProps?.["aria-invalid"];
|
|
52
|
+
return (
|
|
53
|
+
invalid ||
|
|
54
|
+
ariaInvalid === true ||
|
|
55
|
+
ariaInvalid === "true" ||
|
|
56
|
+
ariaInvalid === ""
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function readFrameFieldValue(
|
|
61
|
+
target: EventTarget | null,
|
|
62
|
+
options?: FrameFieldControlOptions,
|
|
63
|
+
): string | undefined {
|
|
64
|
+
if (
|
|
65
|
+
!(
|
|
66
|
+
target instanceof HTMLInputElement ||
|
|
67
|
+
target instanceof HTMLTextAreaElement ||
|
|
68
|
+
target instanceof HTMLSelectElement
|
|
69
|
+
)
|
|
70
|
+
) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const resolvedOptions =
|
|
75
|
+
target instanceof HTMLInputElement
|
|
76
|
+
? {
|
|
77
|
+
...options,
|
|
78
|
+
controlType: options?.controlType ?? target.type,
|
|
79
|
+
}
|
|
80
|
+
: options;
|
|
81
|
+
|
|
82
|
+
if (shouldSkipByType(resolvedOptions)) return undefined;
|
|
83
|
+
return target.value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function syncFrameFieldValue(
|
|
87
|
+
target: EventTarget | null,
|
|
88
|
+
assign: (nextValue: string) => void,
|
|
89
|
+
options?: FrameFieldControlOptions,
|
|
90
|
+
): boolean {
|
|
91
|
+
const nextValue = readFrameFieldValue(target, options);
|
|
92
|
+
if (nextValue === undefined) return false;
|
|
93
|
+
assign(nextValue);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# identity.svelte.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v2.1.0
|
|
4
|
+
> **职责**: 管理组件的身份标识属性。
|
|
5
|
+
|
|
6
|
+
**需求**: 提供组件的身份标识和基础配置能力,包括样式注入、角色声明、标签控制和属性透传。
|
|
7
|
+
|
|
8
|
+
## 关键字
|
|
9
|
+
|
|
10
|
+
| 关键字 | 类型 | 描述 |
|
|
11
|
+
| :--- | :--- | :--- |
|
|
12
|
+
| class | `string \| LinkageControl` | 外部 CSS 类名,支持联动控制 |
|
|
13
|
+
| style | `string \| LinkageControl` | 行内样式,支持联动控制 |
|
|
14
|
+
| as | `string` | 角色声明,用于在组合模式下声明自身在父容器中的角色 |
|
|
15
|
+
| tag | `string \| LinkageControl` | 渲染的 HTML 标签名,支持联动控制 |
|
|
16
|
+
| id | `string` | 元素 ID。若未提供且组件涉及动效编排,则自动生成唯一 ID |
|
|
17
|
+
|
|
18
|
+
## ID 自动生成 [Updated in v2.1]
|
|
19
|
+
|
|
20
|
+
当组件需要参与动效编排但用户未提供 `id` 时,系统会自动生成确定性 ID。
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
// 使用模块级计数器确保 ID 唯一且可预测
|
|
24
|
+
let idCounter = 0;
|
|
25
|
+
|
|
26
|
+
// 生成格式: snowui-auto-1, snowui-auto-2, ...
|
|
27
|
+
const autoId = `snowui-auto-${++idCounter}`;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> **SSR 兼容**: 使用确定性计数器替代 `Math.random()`,确保服务端渲染与客户端 hydration 的 ID 一致。
|
|
31
|
+
|
|
32
|
+
## 联动控制
|
|
33
|
+
|
|
34
|
+
所有关键字都支持 `{ target, action }` 语法控制其他组件。详见 [frame-perception.md](./frame-perception.md)。
|
|
35
|
+
|
|
36
|
+
## Svelte 原生能力
|
|
37
|
+
|
|
38
|
+
以下能力由 Svelte 原生机制处理:
|
|
39
|
+
|
|
40
|
+
| 关键字 | 描述 | 处理方式 |
|
|
41
|
+
| :--- | :--- | :--- |
|
|
42
|
+
| children | 默认插槽,用于接收子内容 | Svelte 原生 (`Snippet`) |
|
|
43
|
+
| element | 绑定根元素的 HTMLElement | Svelte 原生 (`$bindable`) |
|
|
44
|
+
| use | Svelte Actions 数组 | Svelte 原生 (`use:action`) |
|
|
45
|
+
| ...rest | 属性透传 | 组件模板透传 |
|
|
46
|
+
|
|
47
|
+
## 上报数据
|
|
48
|
+
|
|
49
|
+
| 属性 | 描述 |
|
|
50
|
+
| :--- | :--- |
|
|
51
|
+
| role | 角色值 (即 `as` 的值) |
|
|
52
|
+
| tag | 最终渲染的 HTML 标签名 |
|
|
53
|
+
| id | 最终使用的元素 ID (自动生成或用户提供) |
|
|
54
|
+
| class | 合并后的 CSS 类名 |
|
|
55
|
+
| style | 合并后的行内样式 |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 更新日志 (Changelog)
|
|
60
|
+
|
|
61
|
+
### v2.1.0 (2026-01-20)
|
|
62
|
+
- **修复**: ID 生成使用确定性计数器 (`idCounter`) 替代 `Math.random()`
|
|
63
|
+
- **改进**: SSR hydration 兼容,确保服务端和客户端 ID 一致
|
|
64
|
+
|
|
65
|
+
### v1.3.0
|
|
66
|
+
- 新增联动控制支持
|
|
67
|
+
|
|
68
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FrameProps } from "./frame-types";
|
|
2
|
+
import { hasMotionConfig } from "./frame-utils";
|
|
3
|
+
|
|
4
|
+
// 确定性 ID 计数器,避免 SSR hydration 不匹配
|
|
5
|
+
let idCounter = 0;
|
|
6
|
+
|
|
7
|
+
export class Identity {
|
|
8
|
+
#props: FrameProps;
|
|
9
|
+
|
|
10
|
+
constructor(props: FrameProps) {
|
|
11
|
+
this.#props = props;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get id() {
|
|
15
|
+
if (this.#props.id) return this.#props.id;
|
|
16
|
+
|
|
17
|
+
// 如果包含动效配置,则需要生成 ID
|
|
18
|
+
if (hasMotionConfig(this.#props)) {
|
|
19
|
+
// 使用确定性计数器,避免 SSR/hydration 不匹配
|
|
20
|
+
return `snowui-auto-${++idCounter}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frame-layout.svelte.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.0
|
|
4
|
+
> **职责**: 管理组件的内部布局方向,支持响应式级联控制。
|
|
5
|
+
|
|
6
|
+
**需求**: 控制子元素的排列方向,确保状态切换时布局稳定(无尺寸跳动)。
|
|
7
|
+
|
|
8
|
+
## 1. 基础布局方向
|
|
9
|
+
|
|
10
|
+
| 关键字 | 描述 |
|
|
11
|
+
| :--- | :--- |
|
|
12
|
+
| row | 水平布局 |
|
|
13
|
+
| column | 垂直布局 |
|
|
14
|
+
| grid | 网格布局 |
|
|
15
|
+
| reverse | 反向布局修饰符 (配合 row/column/grid 使用) |
|
|
16
|
+
|
|
17
|
+
## 2. 响应式布局 (Responsive Layout)
|
|
18
|
+
|
|
19
|
+
`FrameLayout` 实现了 **Mobile First** 的响应式级联逻辑。
|
|
20
|
+
|
|
21
|
+
### 2.1 断点属性
|
|
22
|
+
|
|
23
|
+
支持以下断点属性来覆写布局方向:
|
|
24
|
+
|
|
25
|
+
| 关键字 | 阈值 | 类型 |
|
|
26
|
+
| :--- | :--- | :--- |
|
|
27
|
+
| xs | < 640px | `Layout` |
|
|
28
|
+
| sm | ≥ 640px | `Layout` |
|
|
29
|
+
| md | ≥ 768px | `Layout` |
|
|
30
|
+
| lg | ≥ 1024px | `Layout` |
|
|
31
|
+
| xl | ≥ 1280px | `Layout` |
|
|
32
|
+
| 2xl | ≥ 1536px | `Layout` |
|
|
33
|
+
|
|
34
|
+
**Layout 值**: `"row" | "column" | "grid" | "row-reverse" | "column-reverse"`
|
|
35
|
+
|
|
36
|
+
### 2.2 级联逻辑 (Cascade Logic)
|
|
37
|
+
|
|
38
|
+
1. **基础方向**: 首先读取基础属性 (`row`, `column` 等)。
|
|
39
|
+
2. **断点覆盖**: 根据当前容器宽度所在的断点,**从大到小**或**从小到大**应用覆盖规则。
|
|
40
|
+
* 本模块采用 **Mobile First** 策略(从小到大覆盖)。
|
|
41
|
+
* 即:`xs` 的设置会被 `sm` 覆盖,`sm` 会被 `md` 覆盖,以此类推。
|
|
42
|
+
|
|
43
|
+
**示例**:
|
|
44
|
+
|
|
45
|
+
```svelte
|
|
46
|
+
<!--
|
|
47
|
+
默认 (xs): row
|
|
48
|
+
sm 及以上: column (覆盖 row)
|
|
49
|
+
lg 及以上: row (覆盖 column)
|
|
50
|
+
-->
|
|
51
|
+
<Frame row sm="column" lg="row" />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 3. 上报数据
|
|
55
|
+
|
|
56
|
+
`FrameLayout` 计算出最终的 `direction` 属性,供 `Frame` 组件生成 CSS 类名:
|
|
57
|
+
|
|
58
|
+
- `snowui-direction-row`
|
|
59
|
+
- `snowui-direction-column`
|
|
60
|
+
- `snowui-direction-row-reverse`
|
|
61
|
+
- ...
|
|
62
|
+
|
|
63
|
+
## 3. 布局过渡 (Layout Transition)
|
|
64
|
+
|
|
65
|
+
`FrameLayout` 模块还导出了一个独立的工具函数 `createLayoutTransition`,用于实现 FLIP (First, Last, Invert, Play) 动画,常用于处理布局变化时的平滑过渡。
|
|
66
|
+
|
|
67
|
+
### 3.1 使用方法
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { createLayoutTransition } from "./frame-layout.svelte";
|
|
71
|
+
|
|
72
|
+
const transition = createLayoutTransition();
|
|
73
|
+
|
|
74
|
+
// 1. 记录初始状态 (First)
|
|
75
|
+
transition.capture(element);
|
|
76
|
+
|
|
77
|
+
// ... DOM 更新 ...
|
|
78
|
+
|
|
79
|
+
// 2. 播放过渡动画 (Last -> Invert -> Play)
|
|
80
|
+
transition.play(element, { duration: 300 });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3.2 核心逻辑
|
|
84
|
+
|
|
85
|
+
1. **Capture (First)**: 记录元素当前的 `BoundingClientRect`。
|
|
86
|
+
2. **Play (Last -> Invert -> Play)**:
|
|
87
|
+
* 获取元素新的 `BoundingClientRect`。
|
|
88
|
+
* 计算位置 (`dx`, `dy`) 和尺寸 (`dw`, `dh`) 的差异。
|
|
89
|
+
* **Invert**: 立即应用逆变换 (`transform: translate(...) scale(...)`),使元素视觉上保持在原位。
|
|
90
|
+
* **Play**: 在下一帧移除变换,利用 CSS `transition` 让元素平滑过渡到新位置。
|
|
91
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { FrameProps } from "./frame-types";
|
|
2
|
+
|
|
3
|
+
import type { FrameResponsive } from "./frame-responsive.svelte";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Log (2026-02-23): 修复 enableResponsive=false 语义。
|
|
7
|
+
* 无 responsive 实例时不再应用断点覆写(xs/sm/md...),仅保留基础方向(row/column/grid)。
|
|
8
|
+
*/
|
|
9
|
+
const BREAKPOINTS = ["xs", "sm", "md", "lg", "xl", "2xl"] as const;
|
|
10
|
+
|
|
11
|
+
export class FrameLayout {
|
|
12
|
+
#props: FrameProps;
|
|
13
|
+
#responsive: FrameResponsive | null;
|
|
14
|
+
|
|
15
|
+
constructor(props: FrameProps, responsive: FrameResponsive | null) {
|
|
16
|
+
this.#props = props;
|
|
17
|
+
this.#responsive = responsive;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get direction() {
|
|
21
|
+
// 1. 获取基础方向
|
|
22
|
+
let activeDir = this.#getBaseDirection();
|
|
23
|
+
|
|
24
|
+
// 2. 能力开关关闭时,不应用任何断点覆写
|
|
25
|
+
if (!this.#responsive) {
|
|
26
|
+
return activeDir;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 3. 获取当前断点索引
|
|
30
|
+
const currentBp = this.#responsive.breakpoint ?? 'md';
|
|
31
|
+
const currentIndex = BREAKPOINTS.indexOf(currentBp as typeof BREAKPOINTS[number]);
|
|
32
|
+
if (currentIndex < 0) {
|
|
33
|
+
return activeDir;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 4. 级联覆盖 (Mobile First)
|
|
37
|
+
// 从 xs 遍历到当前断点,如果有定义则覆盖
|
|
38
|
+
for (let i = 0; i <= currentIndex; i++) {
|
|
39
|
+
const bp = BREAKPOINTS[i];
|
|
40
|
+
const val = this.#props[bp];
|
|
41
|
+
if (val) {
|
|
42
|
+
activeDir = val;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return activeDir;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#getBaseDirection() {
|
|
50
|
+
const { row, column, grid, reverse } = this.#props;
|
|
51
|
+
if (row && reverse) return "row-reverse";
|
|
52
|
+
if (row) return "row";
|
|
53
|
+
if (column && reverse) return "column-reverse";
|
|
54
|
+
if (column) return "column";
|
|
55
|
+
if (grid && reverse) return "grid-reverse";
|
|
56
|
+
if (grid) return "grid";
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Layout Transition (FLIP)
|
|
63
|
+
* 用于处理布局变化的平滑过渡
|
|
64
|
+
*/
|
|
65
|
+
export function createLayoutTransition() {
|
|
66
|
+
let rect: DOMRect | null = null;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
// First: 记录初始状态
|
|
70
|
+
capture(element: HTMLElement) {
|
|
71
|
+
rect = element.getBoundingClientRect();
|
|
72
|
+
},
|
|
73
|
+
// Last -> Invert -> Play: 记录结束状态,计算差异,并播放动画
|
|
74
|
+
play(element: HTMLElement, options: { duration?: number } = {}) {
|
|
75
|
+
if (!rect) return;
|
|
76
|
+
|
|
77
|
+
const newRect = element.getBoundingClientRect();
|
|
78
|
+
const dx = rect.left - newRect.left;
|
|
79
|
+
const dy = rect.top - newRect.top;
|
|
80
|
+
const dw = rect.width / newRect.width;
|
|
81
|
+
const dh = rect.height / newRect.height;
|
|
82
|
+
|
|
83
|
+
// 如果没有变化,不执行动画
|
|
84
|
+
if (dx === 0 && dy === 0 && dw === 1 && dh === 1) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Invert: 瞬间应用逆变换,使元素看起来还在原来的位置
|
|
89
|
+
element.style.transform = `translate(${dx}px, ${dy}px) scale(${dw}, ${dh})`;
|
|
90
|
+
element.style.transformOrigin = 'top left'; // 确保缩放原点正确
|
|
91
|
+
element.style.transition = 'none';
|
|
92
|
+
|
|
93
|
+
// Play: 下一帧移除变换,让元素过渡到新位置
|
|
94
|
+
requestAnimationFrame(() => {
|
|
95
|
+
// 强制重绘
|
|
96
|
+
element.getBoundingClientRect();
|
|
97
|
+
|
|
98
|
+
element.style.transform = '';
|
|
99
|
+
element.style.transition = `transform ${options.duration || 300}ms ease`;
|
|
100
|
+
|
|
101
|
+
// 动画结束后清理
|
|
102
|
+
const cleanup = () => {
|
|
103
|
+
element.style.transition = '';
|
|
104
|
+
element.style.transformOrigin = '';
|
|
105
|
+
element.removeEventListener('transitionend', cleanup);
|
|
106
|
+
};
|
|
107
|
+
element.addEventListener('transitionend', cleanup);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frame-motion-defaults.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.3.5
|
|
4
|
+
> **职责**: 统一管理 Frame 默认动效注册表,并按关键字解析 `while*` 默认配置。
|
|
5
|
+
|
|
6
|
+
`frame-motion-defaults.ts` 是 Frame 默认动效入口,负责:
|
|
7
|
+
|
|
8
|
+
- 维护默认动效注册表(replace/disappear/morph/move/rotate/flip/number)
|
|
9
|
+
- 按 `FrameProps` 判定哪些 `while*` 需要默认注入
|
|
10
|
+
- 合并用户传入的 `while*` 覆写配置
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 导出 API
|
|
15
|
+
|
|
16
|
+
| 名称 | 类型 | 说明 |
|
|
17
|
+
| :--- | :--- | :--- |
|
|
18
|
+
| `FrameWhileMotionKey` | `type` | 支持的 `while*` 关键字联合类型 |
|
|
19
|
+
| `FrameMotionDefaultsRegistry` | `interface` | 默认动效注册表结构 |
|
|
20
|
+
| `FRAME_MOTION_DEFAULTS` | `const` | 默认动效总表(含 `numberComponent`) |
|
|
21
|
+
| `resolveFrameWhileMotionConfig` | `function` | 解析单个 `while*` 最终配置 |
|
|
22
|
+
| `resolveFrameWhileMotionConfigs` | `function` | 批量解析全部 `while*` 配置 |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 解析规则
|
|
27
|
+
|
|
28
|
+
### 1. 默认启用规则
|
|
29
|
+
|
|
30
|
+
无总开关;当关键字被“使用”时,自动注入默认动效。常见触发来源:
|
|
31
|
+
|
|
32
|
+
- 事件触发器:`Click` / `Hover` / `Focus` / `Drag` / `Scroll` / `Key`
|
|
33
|
+
- 状态链:`StartLoad` / `Load` / `Reload` / `Active` / `Disabled` / `Validating` / `Uploading` / `Editing`(含 `Idle -> Active/Disabled` 自动链路)
|
|
34
|
+
- 显式传入 `while*`
|
|
35
|
+
|
|
36
|
+
#### `whileActive` 差异驱动规则(v1.3.0)
|
|
37
|
+
|
|
38
|
+
当 `whileActive` 由默认系统注入时,会优先根据 `stateStyle` 中 `Idle -> Active` 的属性变化自动选择动效:
|
|
39
|
+
|
|
40
|
+
- `opacity` 变化:触发“出现/消失”(`replaceIn` / `replaceOut`)
|
|
41
|
+
- 布局尺寸变化(`width/height/min/max/padding/margin/gap/border-radius`):触发 `morph`
|
|
42
|
+
- `transform: translateX/Y` 变化:触发 `move`(按方向映射 left/right/down)
|
|
43
|
+
- 旋转变化(`transform: rotate` 或 `rotate` 属性):触发 `rotateClockwise`
|
|
44
|
+
- 翻转变化(`transform: rotateY` 或 `rotateY/rotate-y` 属性):触发 `flip`
|
|
45
|
+
|
|
46
|
+
若未命中以上精确规则,但 `Idle -> Active` 仍存在任意样式差异,则兜底注入 `morph`,避免组件样式直接跳变。
|
|
47
|
+
|
|
48
|
+
### 2. 合并优先级
|
|
49
|
+
|
|
50
|
+
`mergeMotionConfig(defaultConfig, userValue)`:
|
|
51
|
+
|
|
52
|
+
- `userValue === false`: 关闭该关键字默认动效(返回 `undefined`)
|
|
53
|
+
- `userValue === true`: 使用默认动效
|
|
54
|
+
- `userValue` 为对象: 与默认值浅合并(用户字段覆盖默认字段)
|
|
55
|
+
- 其他: 返回默认值
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 默认动效来源
|
|
60
|
+
|
|
61
|
+
默认动效文件位于 `../motion/*.ts`,由 `FRAME_MOTION_DEFAULTS` 统一暴露:
|
|
62
|
+
|
|
63
|
+
- `replaceIn` / `replaceOut`
|
|
64
|
+
- `disappear`
|
|
65
|
+
- `morph`
|
|
66
|
+
- `move` / `moveRight` / `moveLeft` / `moveDown`
|
|
67
|
+
- `rotateClockwise` / `flip`
|
|
68
|
+
- `number` / `numberComponent`(默认数字变化动效:`NumberFlow`)
|
|
69
|
+
|
|
70
|
+
`while*` 默认映射位于 `../motion/defaults/while-*.ts`,每个关键字对应一个独立文件:
|
|
71
|
+
|
|
72
|
+
- `while-load.ts`
|
|
73
|
+
- `while-reload.ts`
|
|
74
|
+
- `while-appear.ts`
|
|
75
|
+
- `while-disappear.ts`
|
|
76
|
+
- `while-idle.ts`
|
|
77
|
+
- `while-active.ts`
|
|
78
|
+
- `while-disabled.ts`
|
|
79
|
+
- `while-click.ts`
|
|
80
|
+
- `while-drag.ts`
|
|
81
|
+
- `while-hover.ts`
|
|
82
|
+
- `while-focus.ts`
|
|
83
|
+
- `while-key.ts`
|
|
84
|
+
- `while-scroll.ts`
|
|
85
|
+
- `while-validating.ts`
|
|
86
|
+
- `while-uploading.ts`
|
|
87
|
+
- `while-editing.ts`
|
|
88
|
+
- `while-collapsed.ts`
|
|
89
|
+
- `while-expanded.ts`
|
|
90
|
+
- `while-xs.ts`
|
|
91
|
+
- `while-sm.ts`
|
|
92
|
+
- `while-md.ts`
|
|
93
|
+
- `while-lg.ts`
|
|
94
|
+
- `while-xl.ts`
|
|
95
|
+
- `while-2xl.ts`
|
|
96
|
+
|
|
97
|
+
### 默认值策略(当前)
|
|
98
|
+
|
|
99
|
+
- 状态/生命周期关键字默认有可见动效(如 `whileLoad` / `whileReload` / `whileAppear` / `whileDisappear` / `whileActive`)。
|
|
100
|
+
- 交互触发关键字默认无视觉效果:`whileHover` / `whileClick` / `whileFocus` / `whileDrag` / `whileKey`。
|
|
101
|
+
- 页面可按需覆写或关闭默认动效。
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 使用示例
|
|
106
|
+
|
|
107
|
+
```svelte
|
|
108
|
+
<Frame Click="Load" Load={["Active", "auto"]}>
|
|
109
|
+
{#snippet children({ motionDefaults })}
|
|
110
|
+
<Frame whileAppear={motionDefaults.replaceIn} />
|
|
111
|
+
{/snippet}
|
|
112
|
+
</Frame>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 更新日志 (Changelog)
|
|
118
|
+
|
|
119
|
+
### v1.3.5 (2026-03-03)
|
|
120
|
+
|
|
121
|
+
#### 修复
|
|
122
|
+
- 修复 `calc(var(...))` 差异比较误判:不再用“首个数字”直接比较复杂表达式,避免把变量名中的数字(如 `--size-4`)当成终值,导致 `whileActive -> morph` 漏触发。
|
|
123
|
+
|
|
124
|
+
### v1.3.4 (2026-03-03)
|
|
125
|
+
|
|
126
|
+
#### 修复
|
|
127
|
+
- `whileActive -> morph` 新增尺寸比推导:基于 `Idle/Active` 的尺寸差异自动计算 `scale` 起点,组件在尺寸变量跳变时也能由 Frame 默认动效平滑过渡。
|
|
128
|
+
- morph 识别新增自定义尺寸变量键匹配(`--*size/width/height/padding/margin/gap/radius*`),无需在各组件内单独声明 morph 过渡。
|
|
129
|
+
|
|
130
|
+
### v1.3.3 (2026-03-03)
|
|
131
|
+
|
|
132
|
+
#### 修复
|
|
133
|
+
- `whileActive` 差异推断新增兜底策略:只要 `Idle -> Active` 存在任意样式差异,默认注入 `morph`。
|
|
134
|
+
- 形态变化识别补充 `inline-size / block-size / flex-basis`,提升复杂组件(非纯 width/height 写法)的命中率。
|
|
135
|
+
|
|
136
|
+
### v1.3.2 (2026-03-03)
|
|
137
|
+
|
|
138
|
+
#### 修复
|
|
139
|
+
- 扩展 `whileActive` 形态变化识别:由仅 `width/height` 扩展为布局尺寸/间距属性(`min/max/padding/margin/gap/border-radius`)变化也可触发 `morph`。
|
|
140
|
+
- 扩展旋转/翻转/位移识别:除 `transform` 字符串外,新增支持 `rotate`、`rotateY/rotate-y`、`translateX/translateY/translate-x/translate-y` 等独立属性写法。
|
|
141
|
+
|
|
142
|
+
### v1.3.1 (2026-03-03)
|
|
143
|
+
|
|
144
|
+
#### 修复
|
|
145
|
+
- `whileActive` 默认注入条件新增支持 `Idle={["Active","auto"]}` 自动链路。
|
|
146
|
+
- `whileDisabled` 默认注入条件新增支持 `Idle={["Disabled","auto"]}` 自动链路。
|
|
147
|
+
- 结果:不依赖 `Click/Active/Disabled` 显式关键字时,Button/Icon 等组件也可通过 Idle 自动链路触发默认动效。
|
|
148
|
+
|
|
149
|
+
### v1.3.0 (2026-03-03)
|
|
150
|
+
|
|
151
|
+
#### 新功能
|
|
152
|
+
- 为 `whileActive` 新增 `stateStyle` 差异驱动的默认动效匹配:
|
|
153
|
+
- 透明度 -> 出现/消失
|
|
154
|
+
- 宽高 -> morph
|
|
155
|
+
- 位移 -> move
|
|
156
|
+
- 旋转 -> rotate
|
|
157
|
+
- 翻转 -> flip
|
|
158
|
+
- `whileActive` 默认动效改为“命中规则才注入”,未命中则不注入可见动效。
|
|
159
|
+
|
|
160
|
+
### v1.2.0 (2026-02-28)
|
|
161
|
+
|
|
162
|
+
#### 架构重构
|
|
163
|
+
- 将 `DEFAULT_WHILE_MOTION_MAP` 的每个 `while*` 默认值拆分到 `../motion/defaults/while-*.ts` 独立文件。
|
|
164
|
+
|
|
165
|
+
#### 文档更新
|
|
166
|
+
- 新增 `while*` 默认映射文件清单。
|
|
167
|
+
|
|
168
|
+
### v1.1.0 (2026-02-27)
|
|
169
|
+
|
|
170
|
+
#### 新功能
|
|
171
|
+
- 注册表新增 `moveRight/moveLeft/moveDown/rotateClockwise/flip`。
|
|
172
|
+
- 默认 `whileReload` 改为统一复用 `rotateClockwise`。
|
|
173
|
+
|
|
174
|
+
#### 文档更新
|
|
175
|
+
- 同步默认策略为“状态默认可见、交互默认无效果”。
|
|
176
|
+
|
|
177
|
+
### v1.0.3 (2026-02-26)
|
|
178
|
+
|
|
179
|
+
#### 调整
|
|
180
|
+
- 将剩余默认动效(包括状态/生命周期/响应式相关 `while*`)统一改为无视觉效果(空配置)。
|