@snowui-design-system/components 0.3.0-alpha.0 → 0.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +13 -6
  2. package/component-catalog.json +2 -23
  3. package/dist/client/blocks/Sidebar.js +2 -2
  4. package/dist/client/blocks/SidebarItem.js +2 -2
  5. package/dist/client/blocks/SidebarSection.js +2 -2
  6. package/dist/client/compat.d.ts +1 -1
  7. package/dist/client/compat.js +1 -1
  8. package/dist/client/components/BlurText.js +2 -2
  9. package/dist/client/components/DataTable.js +2 -2
  10. package/dist/client/components/FlowText.js +2 -2
  11. package/dist/client/components/Frame.d.ts +9 -0
  12. package/dist/client/components/Frame.js +82 -24
  13. package/dist/client/components/GradientMotion.d.ts +1 -1
  14. package/dist/client/components/GradientMotion.js +2 -2
  15. package/dist/client/components/NumberFlow.js +4 -4
  16. package/dist/client/components/NumericText.js +2 -2
  17. package/dist/client/components/ScrambleText.js +2 -2
  18. package/dist/client/components/SidePanel.js +3 -3
  19. package/dist/client/components/SlotText.js +2 -2
  20. package/dist/client/components/TableCell.js +1 -1
  21. package/dist/client/components/Toaster.js +1 -1
  22. package/dist/client/index.d.ts +0 -1
  23. package/dist/client/index.js +3 -5
  24. package/dist/client/internal/snow-ui-logo/Wordmark.js +1 -1
  25. package/dist/client/lib/edge-fade.js +1 -1
  26. package/dist/client/lib/resizable.d.ts +1 -1
  27. package/dist/client/logic/frame-motion.d.ts +15 -23
  28. package/dist/client/logic/frame-motion.js +196 -30
  29. package/dist/client/logic/frame-state.d.ts +2 -14
  30. package/dist/client/logic/frame-state.js +60 -9
  31. package/dist/client/motion/number.d.ts +3 -3
  32. package/dist/client/motion/number.js +3 -3
  33. package/dist/client/styles/components.css +14 -14
  34. package/dist/client/styles/layout.css +1 -1
  35. package/dist/server/blocks/Sidebar.js +2 -2
  36. package/dist/server/blocks/SidebarItem.js +2 -2
  37. package/dist/server/blocks/SidebarSection.js +2 -2
  38. package/dist/server/compat.d.ts +1 -1
  39. package/dist/server/compat.js +1 -1
  40. package/dist/server/components/BlurText.js +2 -2
  41. package/dist/server/components/DataTable.js +2 -2
  42. package/dist/server/components/FlowText.js +2 -2
  43. package/dist/server/components/Frame.d.ts +9 -0
  44. package/dist/server/components/Frame.js +52 -24
  45. package/dist/server/components/GradientMotion.d.ts +1 -1
  46. package/dist/server/components/GradientMotion.js +2 -2
  47. package/dist/server/components/NumberFlow.js +4 -4
  48. package/dist/server/components/NumericText.js +2 -2
  49. package/dist/server/components/ScrambleText.js +2 -2
  50. package/dist/server/components/SidePanel.js +3 -3
  51. package/dist/server/components/SlotText.js +2 -2
  52. package/dist/server/components/TableCell.js +1 -1
  53. package/dist/server/components/Toaster.js +1 -1
  54. package/dist/server/index.d.ts +0 -1
  55. package/dist/server/index.js +3 -5
  56. package/dist/server/internal/snow-ui-logo/Wordmark.js +1 -1
  57. package/dist/server/lib/edge-fade.js +1 -1
  58. package/dist/server/lib/resizable.d.ts +1 -1
  59. package/dist/server/logic/frame-motion.d.ts +15 -23
  60. package/dist/server/logic/frame-motion.js +75 -29
  61. package/dist/server/logic/frame-state.d.ts +2 -14
  62. package/dist/server/logic/frame-state.js +60 -9
  63. package/dist/server/motion/number.d.ts +3 -3
  64. package/dist/server/motion/number.js +3 -3
  65. package/dist/server/styles/components.css +14 -14
  66. package/dist/server/styles/layout.css +1 -1
  67. package/package.json +2 -2
  68. package/dist/client/components/FramePro.d.ts +0 -23
  69. package/dist/client/components/FramePro.js +0 -412
  70. package/dist/client/logic/frame-pro-motion.d.ts +0 -26
  71. package/dist/client/logic/frame-pro-motion.js +0 -310
  72. package/dist/client/logic/frame-pro-state.d.ts +0 -39
  73. package/dist/client/logic/frame-pro-state.js +0 -538
  74. package/dist/server/components/FramePro.d.ts +0 -23
  75. package/dist/server/components/FramePro.js +0 -301
  76. package/dist/server/logic/frame-pro-motion.d.ts +0 -26
  77. package/dist/server/logic/frame-pro-motion.js +0 -176
  78. package/dist/server/logic/frame-pro-state.d.ts +0 -39
  79. package/dist/server/logic/frame-pro-state.js +0 -445
@@ -1,310 +0,0 @@
1
- /* frame-pro-motion.svelte.js generated by Svelte v5.56.4 */
2
- import * as $ from 'svelte/internal/client';
3
- import { hasMotionConfig } from "./frame-utils.js";
4
- import { captureFlipRect, beginFlipEnter, applyFlipExit } from "./layout-flip.js";
5
-
6
- export class FrameMotion {
7
- #props;
8
- #motion;
9
- #state;
10
- #responsive;
11
- #getId;
12
- #getElement;
13
-
14
- constructor(props, motion, state, responsive, getId, getElement) {
15
- this.#props = props;
16
- this.#motion = motion;
17
- this.#state = state;
18
- this.#responsive = responsive;
19
- this.#getId = getId;
20
- this.#getElement = getElement;
21
-
22
- // 注册到编排器,并触发独立 FLIP 进场(无需 Motion 上下文)
23
- $.user_effect(() => {
24
- const id = this.#getId();
25
- const element = this.#getElement();
26
-
27
- // 独立 FLIP 进场:layoutId/itemId 存在时尝试从模块注册表读取起点
28
- const flipId = this.#props.itemId ?? this.#props.layoutId;
29
-
30
- if (flipId && element) {
31
- beginFlipEnter(flipId, element);
32
- }
33
-
34
- if (!this.#motion || !this.shouldRegister || !element || !id) return;
35
-
36
- return this.#motion.register({
37
- id,
38
- element,
39
- timeline: this.#props.timeline,
40
- scroll: this.#props.scroll,
41
- layoutId: this.#props.itemId ?? this.#props.layoutId,
42
- scope: this.#props.scope
43
- });
44
- });
45
-
46
- // === 状态变化 -> 动效通知 (合并优化) ===
47
- // 使用单一 effect 替代多个独立 effect,减少响应式订阅开销
48
- // 缓存上一次的触发器状态,用于差量更新
49
- let prevTriggerStates = {};
50
-
51
- $.user_effect(() => {
52
- // 收集所有触发器状态
53
- const currentStates = {
54
- whileHover: this.#state.hovered,
55
- whileClick: this.#state.pressed,
56
- whileFocus: this.#state.focused,
57
- whileDrag: this.#state.isDragging,
58
- whileScroll: this.#state.isScrolling,
59
- whileKey: this.#state.isKeyActive,
60
- whileLoad: this.#state.currentState === "StartLoad" || this.#state.currentState === "Load" || !!this.#props.loading,
61
- whileReload: this.#state.currentState === "Reload" || !!this.#props.whileReload,
62
- whileActive: this.#state.currentState === "Active" || !!this.#props.whileActive,
63
- whileDisabled: this.#state.currentState === "Disabled" || !!this.#props.whileDisabled,
64
- whileValidating: this.#state.currentState === "Validating" || !!this.#props.whileValidating,
65
- whileUploading: this.#state.currentState === "Uploading" || !!this.#props.whileUploading,
66
- whileEditing: this.#state.currentState === "Editing" || !!this.#props.whileEditing,
67
- whileCollapsed: !!this.#props.collapsed,
68
- whileExpanded: !!this.#props.expanded,
69
- whileIdle: !this.#state.isAnyTriggerActive
70
- };
71
-
72
- // 仅通知发生变化的触发器
73
- for (const [event, active] of Object.entries(currentStates)) {
74
- if (prevTriggerStates[event] !== active) {
75
- this.#notify(event, { active });
76
- }
77
- }
78
-
79
- prevTriggerStates = currentStates;
80
- });
81
-
82
- // 生命周期通知 (单独保留,因为需要 cleanup)
83
- $.user_effect(() => {
84
- this.#notify("whileAppear", { active: true });
85
-
86
- // === 编排触发逻辑 ===
87
- // 根据 orchestrateTrigger 决定何时触发编排
88
- const trigger = this.#props.orchestrateTrigger ?? "appear";
89
-
90
- if (this.#props.orchestrate && trigger === "appear") {
91
- const id = this.#getId();
92
-
93
- if (id && this.#motion) {
94
- // 使用微任务或下一帧确保子组件已挂载并注册
95
- requestAnimationFrame(() => {
96
- this.#motion?.Play(id);
97
- });
98
- }
99
- }
100
-
101
- return () => this.#notify("whileDisappear", { active: true });
102
- });
103
-
104
- // === orchestrateTrigger: hover ===
105
- $.user_effect(() => {
106
- const trigger = this.#props.orchestrateTrigger;
107
-
108
- if (this.#props.orchestrate && trigger === "hover" && this.#state.hovered) {
109
- const id = this.#getId();
110
-
111
- if (id && this.#motion) {
112
- this.#motion.Play(id);
113
- }
114
- }
115
- });
116
-
117
- // === orchestrateTrigger: click ===
118
- $.user_effect(() => {
119
- const trigger = this.#props.orchestrateTrigger;
120
-
121
- if (this.#props.orchestrate && trigger === "click" && this.#state.pressed) {
122
- const id = this.#getId();
123
-
124
- if (id && this.#motion) {
125
- this.#motion.Play(id);
126
- }
127
- }
128
- });
129
-
130
- // === orchestrateTrigger: scroll ===
131
- $.user_effect(() => {
132
- const trigger = this.#props.orchestrateTrigger;
133
-
134
- if (this.#props.orchestrate && trigger === "scroll" && this.#state.isScrolling) {
135
- const id = this.#getId();
136
-
137
- if (id && this.#motion) {
138
- this.#motion.Play(id);
139
- }
140
- }
141
- });
142
-
143
- // 响应式断点通知
144
- let prevBreakpoint;
145
-
146
- $.user_effect(() => {
147
- if (!this.#responsive) return;
148
-
149
- const breakpoint = this.#responsive.breakpoint;
150
-
151
- if (!breakpoint || breakpoint === prevBreakpoint) return;
152
-
153
- const eventMap = {
154
- xs: "whileXs",
155
- sm: "whileSm",
156
- md: "whileMd",
157
- lg: "whileLg",
158
- xl: "whileXl",
159
- "2xl": "while2xl"
160
- };
161
-
162
- const eventName = eventMap[breakpoint];
163
-
164
- if (eventName) this.#notify(eventName, { active: true });
165
-
166
- prevBreakpoint = breakpoint;
167
- });
168
-
169
- // Setup whileScroll trigger
170
- $.user_effect(() => {
171
- if (this.#props.whileScroll) {
172
- this.#setupWhileScroll();
173
- }
174
- });
175
- }
176
-
177
- get shouldRegister() {
178
- const id = this.#getId();
179
-
180
- return !!id || hasMotionConfig(this.#props);
181
- }
182
-
183
- get controller() {
184
- return {
185
- play: (options) => {
186
- const id = this.#getId();
187
-
188
- if (id && this.#motion) this.#motion.Play(id, options);
189
- },
190
-
191
- captureLayout: (layoutId) => {
192
- const id = layoutId ?? this.#props.itemId ?? this.#props.layoutId ?? this.#getId();
193
- const element = this.#getElement();
194
-
195
- if (id && element && this.#motion) {
196
- this.#motion.captureLayout(id, element);
197
- }
198
- },
199
-
200
- playLayoutTo: (target, options) => {
201
- const id = options?.layoutId ?? this.#props.itemId ?? this.#props.layoutId ?? this.#getId();
202
- const element = this.#getElement();
203
-
204
- if (id && element && this.#motion) {
205
- this.#motion.playLayoutTo(id, element, target, options);
206
- } else {
207
- options?.onComplete?.();
208
- }
209
- },
210
-
211
- /** 捕获当前 Frame 位置写入模块级 FLIP 注册表,无需 initMotion 上下文。 */
212
- captureFlip: (layoutId) => {
213
- const id = layoutId ?? this.#props.itemId ?? this.#props.layoutId ?? this.#getId();
214
- const element = this.#getElement();
215
-
216
- if (id && element) captureFlipRect(id, element);
217
- },
218
-
219
- /** 将当前 Frame 以 FLIP 方式过渡到目标位置,无需 initMotion 上下文。 */
220
- playFlipTo: (target, options) => {
221
- const element = this.#getElement();
222
-
223
- if (element && target) {
224
- applyFlipExit(element, target, options);
225
- } else {
226
- options?.onComplete?.();
227
- }
228
- },
229
-
230
- reset: () => {
231
- const id = this.#getId();
232
-
233
- if (id && this.#motion) this.#motion.Reset(id);
234
- },
235
-
236
- pause: () => {
237
- // TODO
238
- }
239
- };
240
- }
241
-
242
- #notify(event, detail) {
243
- const id = this.#getId();
244
-
245
- if (!this.#motion || !this.shouldRegister || !id) return;
246
-
247
- this.#motion.notify(id, event, detail);
248
- }
249
-
250
- #setupWhileScroll() {
251
- const element = this.#getElement();
252
-
253
- if (!element) return;
254
-
255
- // 解析 offset 配置 (如 ["start center", "end center"])
256
- const scrollConfig = this.#props.scroll;
257
-
258
- const offset = scrollConfig?.offset ?? ["start center", "end center"];
259
-
260
- // 解析偏移量
261
- const parseOffset = (str) => {
262
- const parts = str.split(" ");
263
-
264
- return {
265
- element: parts[0] || "start", // start, center, end
266
- viewport: parts[1] || "center" // start, center, end
267
- };
268
- };
269
-
270
- const startOffset = parseOffset(offset[0]);
271
-
272
- const handleScroll = () => {
273
- const rect = element.getBoundingClientRect();
274
- const viewportHeight = window.innerHeight;
275
-
276
- // 计算元素位置
277
- const getElementPosition = (pos) => {
278
- if (pos === "start") return rect.top;
279
- if (pos === "end") return rect.bottom;
280
-
281
- return rect.top + rect.height / 2; // center
282
- };
283
-
284
- // 计算视口位置
285
- const getViewportPosition = (pos) => {
286
- if (pos === "start") return 0;
287
- if (pos === "end") return viewportHeight;
288
-
289
- return viewportHeight / 2; // center
290
- };
291
-
292
- const elementPos = getElementPosition(startOffset.element);
293
- const viewportTrigger = getViewportPosition(startOffset.viewport);
294
-
295
- // 当元素位置到达视口触发点时激活
296
- const isActive = elementPos <= viewportTrigger;
297
-
298
- if (this.#state.isScrolling !== isActive) {
299
- this.#state.isScrolling = isActive;
300
- }
301
- };
302
-
303
- window.addEventListener("scroll", handleScroll);
304
- handleScroll(); // Initial check
305
-
306
- return () => {
307
- window.removeEventListener("scroll", handleScroll);
308
- };
309
- }
310
- }
@@ -1,39 +0,0 @@
1
- import type { FrameProps, CoreState } from "./frame-types";
2
- import type { Motion } from "./motion.js";
3
- export declare class FrameState {
4
- #private;
5
- hovered: boolean;
6
- pressed: boolean;
7
- focused: boolean;
8
- isDragging: boolean;
9
- isScrolling: boolean;
10
- isKeyActive: boolean;
11
- currentState: CoreState;
12
- constructor(props: FrameProps, motion: Motion | undefined);
13
- get interactionState(): (string & {}) | "StartLoad" | "Load" | "Reload" | "Appear" | "Disappear" | "Idle" | "Active" | "Disabled" | "Validating" | "Uploading" | "Editing" | "Click" | "Hover" | "Focus" | "Drag" | "Scroll";
14
- get isAnyTriggerActive(): boolean | undefined;
15
- handleClick: (e: MouseEvent) => void;
16
- handleDblClick: (_e: MouseEvent) => void;
17
- handleContextMenu: (_e: MouseEvent) => void;
18
- handleMouseEnter: (e: MouseEvent) => void;
19
- handleMouseLeave: () => void;
20
- handleMouseDown: () => void;
21
- handleMouseUp: (_e: MouseEvent) => void;
22
- handleMouseMove: (_e: MouseEvent) => void;
23
- handleTouchStart: (_e: TouchEvent) => void;
24
- handleTouchEnd: (_e: TouchEvent) => void;
25
- handleTouchMove: (_e: TouchEvent) => void;
26
- handleTouchCancel: (_e: TouchEvent) => void;
27
- handleFocus: (e: FocusEvent) => void;
28
- handleBlur: () => void;
29
- handleKeyDown: (e: KeyboardEvent) => void;
30
- handleKeyUp: () => void;
31
- handleKeyPress: (_e: KeyboardEvent) => void;
32
- handleInput: (_e: Event) => void;
33
- handleChange: (_e: Event) => void;
34
- handleSubmit: (_e: Event) => void;
35
- handleDragStart: (e: DragEvent) => void;
36
- handleDrag: (_e: DragEvent) => void;
37
- handleDragEnd: (_e: DragEvent) => void;
38
- handleScroll: (_e: Event) => void;
39
- }