@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,273 @@
|
|
|
1
|
+
import { setContext, getContext } from "svelte";
|
|
2
|
+
import {
|
|
3
|
+
FRAME_CONTEXT_KEY,
|
|
4
|
+
INTERACTION_CONTEXT_KEY,
|
|
5
|
+
SKELETON_CONTEXT_KEY,
|
|
6
|
+
SIZE_CONTEXT_KEY,
|
|
7
|
+
} from "../keys";
|
|
8
|
+
import type { FrameProps } from "./frame-types";
|
|
9
|
+
import type { FrameState } from "./frame-state.svelte";
|
|
10
|
+
import type { FrameLayout } from "./frame-layout.svelte";
|
|
11
|
+
import type { FrameResponsive } from "./frame-responsive.svelte";
|
|
12
|
+
|
|
13
|
+
export class FramePerception {
|
|
14
|
+
constructor(
|
|
15
|
+
props: FrameProps,
|
|
16
|
+
state: FrameState,
|
|
17
|
+
layout: FrameLayout,
|
|
18
|
+
responsive: FrameResponsive | null,
|
|
19
|
+
getLoading: () => boolean,
|
|
20
|
+
getSkeleton: () => boolean,
|
|
21
|
+
) {
|
|
22
|
+
// 获取父组件上下文(如果存在)
|
|
23
|
+
const parentContext = getContext<any>(FRAME_CONTEXT_KEY);
|
|
24
|
+
|
|
25
|
+
// 提供完整的上下文给子组件
|
|
26
|
+
const baseContext = {
|
|
27
|
+
// 角色 (Role)
|
|
28
|
+
get role() {
|
|
29
|
+
return props.as;
|
|
30
|
+
},
|
|
31
|
+
get size() {
|
|
32
|
+
return props.size;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// 状态 (State)
|
|
36
|
+
get interactionState() {
|
|
37
|
+
return state.interactionState;
|
|
38
|
+
},
|
|
39
|
+
get currentState() {
|
|
40
|
+
return state.currentState;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// 形态 (Morphology)
|
|
44
|
+
get collapsed() {
|
|
45
|
+
return props.collapsed;
|
|
46
|
+
},
|
|
47
|
+
get expanded() {
|
|
48
|
+
return props.expanded;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// 事件 (Events)
|
|
52
|
+
get Hover() {
|
|
53
|
+
return state.hovered;
|
|
54
|
+
},
|
|
55
|
+
get Click() {
|
|
56
|
+
return state.pressed;
|
|
57
|
+
},
|
|
58
|
+
get Focus() {
|
|
59
|
+
return state.focused;
|
|
60
|
+
},
|
|
61
|
+
get Drag() {
|
|
62
|
+
return state.isDragging;
|
|
63
|
+
},
|
|
64
|
+
get Key() {
|
|
65
|
+
return state.isKeyActive;
|
|
66
|
+
},
|
|
67
|
+
get Scroll() {
|
|
68
|
+
return state.isScrolling;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// 响应断点 (Responsive)
|
|
72
|
+
get breakpoint() {
|
|
73
|
+
return responsive?.breakpoint ?? 'md';
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
// 布局 (Layout)
|
|
77
|
+
get direction() {
|
|
78
|
+
return layout.direction;
|
|
79
|
+
},
|
|
80
|
+
get row() {
|
|
81
|
+
return props.row;
|
|
82
|
+
},
|
|
83
|
+
get column() {
|
|
84
|
+
return props.column;
|
|
85
|
+
},
|
|
86
|
+
get grid() {
|
|
87
|
+
return props.grid;
|
|
88
|
+
},
|
|
89
|
+
get reverse() {
|
|
90
|
+
return props.reverse;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// 动效 (Motion) - 事件驱动触发器
|
|
94
|
+
get whileLoad() {
|
|
95
|
+
return props.whileLoad;
|
|
96
|
+
},
|
|
97
|
+
get loading() {
|
|
98
|
+
return props.loading;
|
|
99
|
+
},
|
|
100
|
+
get skeleton() {
|
|
101
|
+
return props.skeleton;
|
|
102
|
+
},
|
|
103
|
+
get whileAppear() {
|
|
104
|
+
return props.whileAppear;
|
|
105
|
+
},
|
|
106
|
+
get whileDisappear() {
|
|
107
|
+
return props.whileDisappear;
|
|
108
|
+
},
|
|
109
|
+
get whileIdle() {
|
|
110
|
+
return props.whileIdle;
|
|
111
|
+
},
|
|
112
|
+
get whileActive() {
|
|
113
|
+
return props.whileActive;
|
|
114
|
+
},
|
|
115
|
+
get whileDisabled() {
|
|
116
|
+
return props.whileDisabled;
|
|
117
|
+
},
|
|
118
|
+
get whileClick() {
|
|
119
|
+
return props.whileClick;
|
|
120
|
+
},
|
|
121
|
+
get whileDrag() {
|
|
122
|
+
return props.whileDrag;
|
|
123
|
+
},
|
|
124
|
+
get whileHover() {
|
|
125
|
+
return props.whileHover;
|
|
126
|
+
},
|
|
127
|
+
get whileFocus() {
|
|
128
|
+
return props.whileFocus;
|
|
129
|
+
},
|
|
130
|
+
get whileKey() {
|
|
131
|
+
return props.whileKey;
|
|
132
|
+
},
|
|
133
|
+
get whileScroll() {
|
|
134
|
+
return props.whileScroll;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// [New] 内置扩展状态
|
|
138
|
+
get whileValidating() { return props.whileValidating; },
|
|
139
|
+
get whileUploading() { return props.whileUploading; },
|
|
140
|
+
get whileEditing() { return props.whileEditing; },
|
|
141
|
+
|
|
142
|
+
// 动效 (Motion) - 形态驱动触发器
|
|
143
|
+
get whileCollapsed() {
|
|
144
|
+
return props.whileCollapsed;
|
|
145
|
+
},
|
|
146
|
+
get whileExpanded() {
|
|
147
|
+
return props.whileExpanded;
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
// 动效 (Motion) - 响应式驱动触发器
|
|
151
|
+
get whileXs() {
|
|
152
|
+
return props.whileXs;
|
|
153
|
+
},
|
|
154
|
+
get whileSm() {
|
|
155
|
+
return props.whileSm;
|
|
156
|
+
},
|
|
157
|
+
get whileMd() {
|
|
158
|
+
return props.whileMd;
|
|
159
|
+
},
|
|
160
|
+
get whileLg() {
|
|
161
|
+
return props.whileLg;
|
|
162
|
+
},
|
|
163
|
+
get whileXl() {
|
|
164
|
+
return props.whileXl;
|
|
165
|
+
},
|
|
166
|
+
get while2xl() {
|
|
167
|
+
return props.while2xl;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
// 动效 (Motion) - 变体和参数
|
|
171
|
+
get variants() {
|
|
172
|
+
return props.variants;
|
|
173
|
+
},
|
|
174
|
+
get delay() {
|
|
175
|
+
return props.delay;
|
|
176
|
+
},
|
|
177
|
+
get timeline() {
|
|
178
|
+
return props.timeline;
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
// 动效 (Motion) - 编排模式
|
|
182
|
+
get orchestrate() {
|
|
183
|
+
return props.orchestrate;
|
|
184
|
+
},
|
|
185
|
+
get orchestrateMode() {
|
|
186
|
+
return props.orchestrateMode;
|
|
187
|
+
},
|
|
188
|
+
get orchestrateDelay() {
|
|
189
|
+
return props.orchestrateDelay;
|
|
190
|
+
},
|
|
191
|
+
get orchestrateOrder() {
|
|
192
|
+
return props.orchestrateOrder;
|
|
193
|
+
},
|
|
194
|
+
get orchestrateGroup() {
|
|
195
|
+
return props.orchestrateGroup;
|
|
196
|
+
},
|
|
197
|
+
get orchestrateTrigger() {
|
|
198
|
+
return props.orchestrateTrigger;
|
|
199
|
+
},
|
|
200
|
+
get orchestrateTarget() {
|
|
201
|
+
return props.orchestrateTarget;
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// 父组件上下文(用于链式继承)
|
|
205
|
+
parent: parentContext,
|
|
206
|
+
|
|
207
|
+
// === Frame Evolution ===
|
|
208
|
+
get scope() {
|
|
209
|
+
return props.scope;
|
|
210
|
+
},
|
|
211
|
+
get access() {
|
|
212
|
+
return props.access ?? 'writeable'; // 默认为 writeable
|
|
213
|
+
},
|
|
214
|
+
// 辅助方法:检查是否有写权限
|
|
215
|
+
canWrite() {
|
|
216
|
+
return (props.access ?? 'writeable') === 'writeable';
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// 使用 Proxy 包装以支持动态属性透传 (Custom States)
|
|
221
|
+
const contextProxy = new Proxy(baseContext, {
|
|
222
|
+
get(target, prop, receiver) {
|
|
223
|
+
if (Reflect.has(target, prop)) {
|
|
224
|
+
return Reflect.get(target, prop, receiver);
|
|
225
|
+
}
|
|
226
|
+
// 动态透传 FrameProps 中的属性 (例如 whileMyState)
|
|
227
|
+
return props[prop as keyof FrameProps];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
setContext(FRAME_CONTEXT_KEY, contextProxy);
|
|
232
|
+
|
|
233
|
+
// 兼容旧的上下文 Key(向后兼容)
|
|
234
|
+
setContext(INTERACTION_CONTEXT_KEY, {
|
|
235
|
+
get state() {
|
|
236
|
+
return state.interactionState;
|
|
237
|
+
},
|
|
238
|
+
get Hover() {
|
|
239
|
+
return state.hovered;
|
|
240
|
+
},
|
|
241
|
+
get Click() {
|
|
242
|
+
return state.pressed;
|
|
243
|
+
},
|
|
244
|
+
get Focus() {
|
|
245
|
+
return state.focused;
|
|
246
|
+
},
|
|
247
|
+
get Drag() {
|
|
248
|
+
return state.isDragging;
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
setContext(SKELETON_CONTEXT_KEY, {
|
|
253
|
+
get loading() {
|
|
254
|
+
return getLoading();
|
|
255
|
+
},
|
|
256
|
+
get skeleton() {
|
|
257
|
+
return getSkeleton();
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
setContext(SIZE_CONTEXT_KEY, {
|
|
262
|
+
get size() {
|
|
263
|
+
return props.size;
|
|
264
|
+
},
|
|
265
|
+
get iconSize() {
|
|
266
|
+
return props.iconSize;
|
|
267
|
+
},
|
|
268
|
+
get avatarSize() {
|
|
269
|
+
return props.avatarSize;
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -35,7 +35,12 @@ export const FRAME_INTERNAL_PROP_KEYS = [
|
|
|
35
35
|
"enableScaleObserver",
|
|
36
36
|
"enableDefaultMotion",
|
|
37
37
|
"enableAutoLayout",
|
|
38
|
-
"
|
|
38
|
+
"componentParts",
|
|
39
|
+
"contentFill",
|
|
40
|
+
"contentHug",
|
|
41
|
+
"pinOffset",
|
|
42
|
+
"pinOffsetX",
|
|
43
|
+
"pinOffsetY",
|
|
39
44
|
"scope",
|
|
40
45
|
"lines",
|
|
41
46
|
"onTruncate",
|
|
@@ -121,6 +126,7 @@ export const FRAME_INTERNAL_PROP_KEYS = [
|
|
|
121
126
|
"as",
|
|
122
127
|
"element",
|
|
123
128
|
"use",
|
|
129
|
+
"currentState",
|
|
124
130
|
"Click",
|
|
125
131
|
"Hover",
|
|
126
132
|
"Focus",
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# frame-scale-observer.svelte.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.3.1
|
|
4
|
+
> **职责**: 监听节点宽高并写入运行时 CSS 变量,服务统一比例系统(不直接应用视觉样式)。
|
|
5
|
+
|
|
6
|
+
## 1. 功能概览
|
|
7
|
+
|
|
8
|
+
`frameScaleObserver` 是一个 Svelte Action,用于将元素实时宽高写入 CSS 变量:
|
|
9
|
+
|
|
10
|
+
- `--snowui-scale-height-runtime`
|
|
11
|
+
- `--snowui-scale-width-runtime`
|
|
12
|
+
- `--snowui-scale-aspect-ratio-runtime`
|
|
13
|
+
- `--snowui-scale-size-runtime`
|
|
14
|
+
|
|
15
|
+
## 2. 关键字
|
|
16
|
+
|
|
17
|
+
| 关键字 | 类型 | 默认值 | 描述 |
|
|
18
|
+
| :--- | :--- | :--- | :--- |
|
|
19
|
+
| heightVar | `string` | `--snowui-scale-height-runtime` | 写入运行时高度变量名 |
|
|
20
|
+
| widthVar | `string` | `--snowui-scale-width-runtime` | 写入运行时宽度变量名 |
|
|
21
|
+
| aspectRatioVar | `string` | `--snowui-scale-aspect-ratio-runtime` | 写入运行时高宽比变量名 |
|
|
22
|
+
| sizeVar | `string` | `--snowui-scale-size-runtime` | 写入运行时统一尺寸变量名 |
|
|
23
|
+
| target | `'self' \| 'parent'` | `'self'` | 监听并写入变量的目标节点 |
|
|
24
|
+
| basis | `'height' \| 'width' \| 'mixed' \| 'aspect'` | `'height'` | 统一尺寸计算依据 |
|
|
25
|
+
| mixHeightWeight | `number` | `0.5` | `mixed` 模式高度权重 |
|
|
26
|
+
| aspectBaseRatio | `number` | `1` | `aspect` 模式参考高宽比 |
|
|
27
|
+
| sizeRatio | `number` | `1` | 统一尺寸比例 |
|
|
28
|
+
|
|
29
|
+
## 3. 统一计算链路(对容器内子内容的影响)
|
|
30
|
+
|
|
31
|
+
设:
|
|
32
|
+
- 容器解析高度 = `H`
|
|
33
|
+
- 容器解析宽度 = `W`
|
|
34
|
+
- 当前高宽比 = `R = W / H`
|
|
35
|
+
|
|
36
|
+
1. `basis size`(由 `basis` 决定)
|
|
37
|
+
- `height`: `B = H`
|
|
38
|
+
- `width`: `B = W`
|
|
39
|
+
- `mixed`: `B = H * mixHeightWeight + W * (1 - mixHeightWeight)`
|
|
40
|
+
- `aspect`: `B = H * (R / aspectBaseRatio)`
|
|
41
|
+
|
|
42
|
+
2. 统一尺寸
|
|
43
|
+
- `S = B * sizeRatio`(并写入 `sizeVar` 对应的运行时变量)
|
|
44
|
+
|
|
45
|
+
3. 默认样式计算(未被 class/props 覆盖时)
|
|
46
|
+
- `padding-x = B * --snowui-scale-ratio-padding-x`
|
|
47
|
+
- `padding-y = B * --snowui-scale-ratio-padding-y`
|
|
48
|
+
- `content-height = B - 2 * padding-y`
|
|
49
|
+
- `text-size = content-height * --snowui-scale-ratio-text`
|
|
50
|
+
- `icon-size = S * iconSizeRatio`
|
|
51
|
+
- `avatar-size = S * avatarSizeRatio`
|
|
52
|
+
- `gap = content-height * --snowui-scale-ratio-gap`
|
|
53
|
+
- `radius = B * --snowui-scale-ratio-radius`
|
|
54
|
+
- `inset-border-width = B * --snowui-scale-ratio-border-width`(`box-shadow: inset`)
|
|
55
|
+
- `border` 默认不按比例自动生成,仍由 `--snowui-scale-border`(默认 `0 solid transparent`)决定
|
|
56
|
+
|
|
57
|
+
> 影响范围:容器内文字、Icon、Avatar 以及容器自身的 padding / gap / 圆角 / 内边框都会随 `B` 与 `S` 变化。
|
|
58
|
+
|
|
59
|
+
## 4. 数值示例(H=28px)
|
|
60
|
+
|
|
61
|
+
若 `H=28` 且采用默认 `sizeRatio=1`:
|
|
62
|
+
|
|
63
|
+
- 当 `basis="height"`:`B=28`,`S=28`
|
|
64
|
+
- 当 `basis="width"`:`B=W`,`S=W`
|
|
65
|
+
- 当 `basis="mixed"` 且默认权重 `0.5`:`B=(28+W)/2`,`S=(28+W)/2`
|
|
66
|
+
- 当 `basis="aspect"` 且默认 `aspectBaseRatio=1`:`B=28*(W/28)=W`,`S=W`
|
|
67
|
+
|
|
68
|
+
例如 `W=112` 时:
|
|
69
|
+
- `height` 模式:`B=28`,`S=28`
|
|
70
|
+
- `width` 模式:`B=112`,`S=112`
|
|
71
|
+
- `mixed` 模式:`B=70`,`S=70`
|
|
72
|
+
- `aspect` 模式:`B=112`,`S=112`
|
|
73
|
+
|
|
74
|
+
因此,容器“实际宽度是多少”会直接通过 `basis` 参与 `B` 的计算,进而影响文字、Icon、Avatar、padding、gap、圆角、内边框的最终像素值。
|
|
75
|
+
|
|
76
|
+
## 5. 关键字逐项影响(11 项)
|
|
77
|
+
|
|
78
|
+
| 关键字 | 直接作用 | 对子组件/子内容的影响 |
|
|
79
|
+
| :--- | :--- | :--- |
|
|
80
|
+
| `scaleHeightVar` | 写入运行时高度 `H` | 当 `scaleBasis=height/mixed/aspect` 时,参与 `B` 计算,进而影响文字、Icon、Avatar、padding、gap、圆角、内边框 |
|
|
81
|
+
| `scaleWidthVar` | 写入运行时宽度 `W` | 当 `scaleBasis=width/mixed/aspect` 时,参与 `B` 计算,进而影响上述所有比例结果 |
|
|
82
|
+
| `scaleAspectRatioVar` | 写入运行时高宽比 `R=W/H` | 当 `scaleBasis=aspect` 时决定 `B`,进而影响上述所有比例结果 |
|
|
83
|
+
| `scaleSizeVar` | 写入运行时统一尺寸 `S` | 直接影响 Icon/Avatar 默认尺寸链路(若未被 class/props 覆盖) |
|
|
84
|
+
| `scaleObserverTarget` | 指定监听对象(`self/parent`) | 决定 `H/W/R/S` 取值来自哪个容器,从源头改变子内容所有比例结果 |
|
|
85
|
+
| `scaleBasis` | 指定 `B` 计算模式 | 决定以高、宽、混合或高宽比作为基准,直接改变文字、padding、gap、radius、内边框、Icon、Avatar |
|
|
86
|
+
| `scaleMixHeightWeight` | `mixed` 模式权重 | 改变 `B=H*w+W*(1-w)`,从而改变所有依赖 `B`/`S` 的子项 |
|
|
87
|
+
| `scaleAspectBaseRatio` | `aspect` 参考比值 | 改变 `B=H*(R/base)` 的放大/缩小倍率,进而影响所有依赖 `B`/`S` 的子项 |
|
|
88
|
+
| `sizeRatio` | 统一尺寸倍率 | 改变 `S=B*sizeRatio`,主要影响 Icon/Avatar 等统一尺寸链路(不是文字比例) |
|
|
89
|
+
| `iconSizeRatio` | Icon 独立倍率 | 在 `S` 基础上单独调整 Icon:`icon-size=S*iconSizeRatio` |
|
|
90
|
+
| `avatarSizeRatio` | Avatar 独立倍率 | 在 `S` 基础上单独调整 Avatar:`avatar-size=S*avatarSizeRatio` |
|
|
91
|
+
|
|
92
|
+
## 6. basis size 补充说明
|
|
93
|
+
|
|
94
|
+
- `basis size` 是 Scale 系统里的“统一基准尺寸”,用于后续比例计算(如 `sizeRatio`、`iconSizeRatio`、`avatarSizeRatio`)。
|
|
95
|
+
- 它与容器大小的关系由 `scaleBasis` 决定:
|
|
96
|
+
- `height`: `basis size = 容器解析高度`(显式 `--snowui-scale-height` > runtime 高度 > fallback)
|
|
97
|
+
- `width`: `basis size = 容器解析宽度`
|
|
98
|
+
- `mixed`: `basis size = 高度 * 高度权重 + 宽度 * 宽度权重`
|
|
99
|
+
- `aspect`: `basis size = 高度 * (当前高宽比 / 参考高宽比)`
|
|
100
|
+
- 因此,当“以容器高为基准”(`scaleBasis="height"`)时,`basis size` 与容器解析高度等值。
|
|
101
|
+
|
|
102
|
+
## 7. 设计约束
|
|
103
|
+
|
|
104
|
+
1. 不直接写入 `--snowui-scale-height` / `--snowui-scale-width`,避免覆盖外部 class。
|
|
105
|
+
2. 使用共享 `ResizeObserverManager`,避免每个组件独立创建观察器。
|
|
106
|
+
3. 该 observer 仅负责“观察与变量写入”,不直接触发样式覆盖;样式是否生效由 apply 模式控制。
|
|
107
|
+
|
|
108
|
+
## 8. 使用示例
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
use:frameScaleObserver={{
|
|
112
|
+
heightVar: "--snowui-scale-height-runtime",
|
|
113
|
+
widthVar: "--snowui-scale-width-runtime",
|
|
114
|
+
aspectRatioVar: "--snowui-scale-aspect-ratio-runtime",
|
|
115
|
+
sizeVar: "--snowui-scale-size-runtime",
|
|
116
|
+
basis: "height",
|
|
117
|
+
mixHeightWeight: 0.5,
|
|
118
|
+
aspectBaseRatio: 1,
|
|
119
|
+
sizeRatio: 1,
|
|
120
|
+
target: "self"
|
|
121
|
+
}}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 更新日志 (Changelog)
|
|
127
|
+
|
|
128
|
+
### v1.3.1 (2026-02-07)
|
|
129
|
+
|
|
130
|
+
#### 文档
|
|
131
|
+
- **SOBS.7** 明确 observer 职责为“仅写变量不直接应用样式”,与 apply 模式分层一致。
|
|
132
|
+
|
|
133
|
+
### v1.3.0 (2026-02-07)
|
|
134
|
+
|
|
135
|
+
#### 文档
|
|
136
|
+
- **SOBS.6** 补充统一计算链路、`H=28px` 数值示例、11 个关键字逐项影响与 `basis size` 说明。
|
|
137
|
+
|
|
138
|
+
### v1.2.0 (2026-02-07)
|
|
139
|
+
|
|
140
|
+
#### 新功能
|
|
141
|
+
- **SOBS.4** 新增 `sizeVar`,输出统一运行时尺寸变量。
|
|
142
|
+
- **SOBS.5** 新增 `basis` / `mixHeightWeight` / `aspectBaseRatio` / `sizeRatio`,使运行时尺寸计算与 scale 配置对齐。
|
|
143
|
+
|
|
144
|
+
### v1.1.0 (2026-02-07)
|
|
145
|
+
|
|
146
|
+
#### 新功能
|
|
147
|
+
- **SOBS.2** 新增运行时宽度与高宽比变量写入能力。
|
|
148
|
+
- **SOBS.3** 导出函数名统一为 `frameScaleObserver`,与文件名语义一致。
|
|
149
|
+
|
|
150
|
+
### v1.0.0 (2026-02-07)
|
|
151
|
+
|
|
152
|
+
#### 新功能
|
|
153
|
+
- **SOBS.1** 新增尺寸监听 action,向 CSS 变量写入运行时尺寸
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame Scale Observer
|
|
3
|
+
* 统一监听容器宽高并写入运行时 CSS 变量,供 scale.css 作为默认值回退使用。
|
|
4
|
+
*
|
|
5
|
+
* 设计目标:
|
|
6
|
+
* - 不覆盖外部 class 显式设置的 `--snowui-scale-height` / `--snowui-scale-width`
|
|
7
|
+
* - 写入 `--snowui-scale-height-runtime` / `--snowui-scale-width-runtime` / `--snowui-scale-aspect-ratio-runtime`
|
|
8
|
+
* - 基于共享 ResizeObserver 管理器,避免重复观察器开销
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { resizeManager } from "./observer.svelte";
|
|
12
|
+
|
|
13
|
+
export interface ScaleObserverOptions {
|
|
14
|
+
heightVar?: string;
|
|
15
|
+
widthVar?: string;
|
|
16
|
+
aspectRatioVar?: string;
|
|
17
|
+
sizeVar?: string;
|
|
18
|
+
target?: "self" | "parent";
|
|
19
|
+
basis?: "height" | "width" | "mixed" | "aspect";
|
|
20
|
+
mixHeightWeight?: number;
|
|
21
|
+
aspectBaseRatio?: number;
|
|
22
|
+
sizeRatio?: number;
|
|
23
|
+
onResize?: (width: number, height: number, size: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function frameScaleObserver(
|
|
27
|
+
node: HTMLElement,
|
|
28
|
+
options: ScaleObserverOptions | undefined,
|
|
29
|
+
) {
|
|
30
|
+
const heightVar = options?.heightVar || "--snowui-scale-height-runtime";
|
|
31
|
+
const widthVar = options?.widthVar || "--snowui-scale-width-runtime";
|
|
32
|
+
const aspectRatioVar =
|
|
33
|
+
options?.aspectRatioVar || "--snowui-scale-aspect-ratio-runtime";
|
|
34
|
+
const sizeVar = options?.sizeVar || "--snowui-scale-size-runtime";
|
|
35
|
+
const target = options?.target || "self";
|
|
36
|
+
const basis = options?.basis || "height";
|
|
37
|
+
const mixHeightWeight =
|
|
38
|
+
options?.mixHeightWeight !== undefined ? options.mixHeightWeight : 0.5;
|
|
39
|
+
const aspectBaseRatio =
|
|
40
|
+
options?.aspectBaseRatio !== undefined ? options.aspectBaseRatio : 1;
|
|
41
|
+
const sizeRatio = options?.sizeRatio !== undefined ? options.sizeRatio : 1;
|
|
42
|
+
const onResize = options?.onResize;
|
|
43
|
+
|
|
44
|
+
const getTarget = () =>
|
|
45
|
+
target === "parent" ? (node.parentElement || node) : node;
|
|
46
|
+
|
|
47
|
+
const apply = (width: number, height: number) => {
|
|
48
|
+
const el = getTarget();
|
|
49
|
+
if (
|
|
50
|
+
!el ||
|
|
51
|
+
!Number.isFinite(height) ||
|
|
52
|
+
!Number.isFinite(width) ||
|
|
53
|
+
width <= 0 ||
|
|
54
|
+
height <= 0
|
|
55
|
+
)
|
|
56
|
+
return;
|
|
57
|
+
el.style.setProperty(heightVar, `${height}px`);
|
|
58
|
+
el.style.setProperty(widthVar, `${width}px`);
|
|
59
|
+
const aspectRatio = width / height;
|
|
60
|
+
el.style.setProperty(aspectRatioVar, `${aspectRatio}`);
|
|
61
|
+
|
|
62
|
+
let basisSize = height;
|
|
63
|
+
if (basis === "width") {
|
|
64
|
+
basisSize = width;
|
|
65
|
+
} else if (basis === "mixed") {
|
|
66
|
+
const hWeight = Math.min(Math.max(mixHeightWeight, 0), 1);
|
|
67
|
+
const wWeight = 1 - hWeight;
|
|
68
|
+
basisSize = height * hWeight + width * wWeight;
|
|
69
|
+
} else if (basis === "aspect") {
|
|
70
|
+
const safeBaseRatio = aspectBaseRatio > 0 ? aspectBaseRatio : 1;
|
|
71
|
+
basisSize = height * (aspectRatio / safeBaseRatio);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const resolvedSize = basisSize * sizeRatio;
|
|
75
|
+
el.style.setProperty(sizeVar, `${resolvedSize}px`);
|
|
76
|
+
|
|
77
|
+
// Callback for Orchestration
|
|
78
|
+
if (onResize) onResize(width, height, resolvedSize);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const watchTarget = getTarget();
|
|
82
|
+
const unwatch = resizeManager.watch(watchTarget, (entry) => {
|
|
83
|
+
apply(entry.contentRect.width, entry.contentRect.height);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const rect = watchTarget.getBoundingClientRect();
|
|
87
|
+
apply(rect.width, rect.height);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
update(next?: ScaleObserverOptions) {
|
|
91
|
+
// 当前版本以首次挂载参数为准,避免频繁重绑观察器
|
|
92
|
+
if (!next) return;
|
|
93
|
+
},
|
|
94
|
+
destroy() {
|
|
95
|
+
unwatch?.();
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frame-scale-resolver.svelte.ts 文档
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.0
|
|
4
|
+
> **职责**: 统一解析 Frame 的 Scale 配置,输出 observer 参数与 style 变量注入列表。
|
|
5
|
+
|
|
6
|
+
## 功能
|
|
7
|
+
|
|
8
|
+
- `resolveScaleObserverOptions(frameProps)`:
|
|
9
|
+
- 产出 `frameScaleObserver` 所需配置(含默认值)。
|
|
10
|
+
- `resolveScaleStyleVars(frameProps)`:
|
|
11
|
+
- 产出 `--snowui-scale-*-prop` 变量注入列表,供 `Frame.svelte` 写入 style。
|
|
12
|
+
|
|
13
|
+
## 关键字映射
|
|
14
|
+
|
|
15
|
+
- `scaleHeightVar` / `scaleWidthVar` / `scaleAspectRatioVar` / `scaleSizeVar`
|
|
16
|
+
- `scaleObserverTarget` / `scaleBasis`
|
|
17
|
+
- `scaleMixHeightWeight` / `scaleAspectBaseRatio`
|
|
18
|
+
- `sizeRatio` / `iconSizeRatio` / `avatarSizeRatio`
|
|
19
|
+
|
|
20
|
+
## 更新日志
|
|
21
|
+
|
|
22
|
+
### v1.0.0 (2026-02-07)
|
|
23
|
+
|
|
24
|
+
- 新增 Scale 配置解析器模块,降低 `Frame.svelte` 复杂度。
|
|
25
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { FrameProps } from "./frame-types";
|
|
2
|
+
import type { ScaleObserverOptions } from "./frame-scale-observer.svelte";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Scale 配置解析器
|
|
6
|
+
* - 统一处理 Frame -> scale observer 的参数映射
|
|
7
|
+
* - 统一处理 Frame -> scale.css 的 props 变量注入
|
|
8
|
+
*/
|
|
9
|
+
export function resolveScaleObserverOptions(
|
|
10
|
+
frameProps: FrameProps,
|
|
11
|
+
): ScaleObserverOptions {
|
|
12
|
+
return {
|
|
13
|
+
heightVar: frameProps.scaleHeightVar || "--scale-height-runtime",
|
|
14
|
+
widthVar: frameProps.scaleWidthVar || "--scale-width-runtime",
|
|
15
|
+
aspectRatioVar:
|
|
16
|
+
frameProps.scaleAspectRatioVar ||
|
|
17
|
+
"--scale-aspect-ratio-runtime",
|
|
18
|
+
sizeVar: frameProps.scaleSizeVar || "--scale-size-runtime",
|
|
19
|
+
target: frameProps.scaleObserverTarget || "self",
|
|
20
|
+
basis: frameProps.scaleBasis || "height",
|
|
21
|
+
mixHeightWeight:
|
|
22
|
+
frameProps.scaleMixHeightWeight !== undefined
|
|
23
|
+
? frameProps.scaleMixHeightWeight
|
|
24
|
+
: 0.5,
|
|
25
|
+
aspectBaseRatio:
|
|
26
|
+
frameProps.scaleAspectBaseRatio !== undefined
|
|
27
|
+
? frameProps.scaleAspectBaseRatio
|
|
28
|
+
: 1,
|
|
29
|
+
sizeRatio:
|
|
30
|
+
frameProps.sizeRatio !== undefined ? frameProps.sizeRatio : 1,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function resolveScaleStyleVars(frameProps: FrameProps): string[] {
|
|
35
|
+
return [
|
|
36
|
+
frameProps.size !== undefined
|
|
37
|
+
? `--scale-size-prop: ${frameProps.size}px`
|
|
38
|
+
: "",
|
|
39
|
+
frameProps.sizeRatio !== undefined
|
|
40
|
+
? `--scale-size-ratio-prop: ${frameProps.sizeRatio}`
|
|
41
|
+
: "",
|
|
42
|
+
frameProps.iconSizeRatio !== undefined
|
|
43
|
+
? `--scale-icon-ratio-prop: ${frameProps.iconSizeRatio}`
|
|
44
|
+
: "",
|
|
45
|
+
frameProps.avatarSizeRatio !== undefined
|
|
46
|
+
? `--scale-avatar-ratio-prop: ${frameProps.avatarSizeRatio}`
|
|
47
|
+
: "",
|
|
48
|
+
frameProps.scaleMixHeightWeight !== undefined
|
|
49
|
+
? `--scale-mix-height-weight-prop: ${frameProps.scaleMixHeightWeight}`
|
|
50
|
+
: "",
|
|
51
|
+
frameProps.scaleAspectBaseRatio !== undefined
|
|
52
|
+
? `--scale-aspect-base-ratio-prop: ${frameProps.scaleAspectBaseRatio}`
|
|
53
|
+
: "",
|
|
54
|
+
].filter(Boolean);
|
|
55
|
+
}
|
|
56
|
+
|