@aura-react-comp/motion 0.2.10 → 0.3.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/esm/composed/confetti.d.ts.map +1 -1
- package/esm/composed/confetti.js +20 -2
- package/esm/composed/scroll-driven.d.ts +10 -1
- package/esm/composed/scroll-driven.d.ts.map +1 -1
- package/esm/composed/scroll-driven.js +12 -4
- package/esm/config/index.js +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/index.js +1 -0
- package/esm/tokens.css +55 -1
- package/esm/tokens.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confetti.d.ts","sourceRoot":"","sources":["confetti.tsx"],"names":[],"mappings":";AAgBA,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"confetti.d.ts","sourceRoot":"","sources":["confetti.tsx"],"names":[],"mappings":";AAgBA,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,MAAM,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAgDD,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,KAAW,EACX,MAA2B,EAC3B,MAAM,GACP,EAAE,aAAa,sCA0Gf"}
|
package/esm/composed/confetti.js
CHANGED
|
@@ -14,6 +14,21 @@ import { useReducedMotion } from 'motion/react';
|
|
|
14
14
|
import { motionConfettiColors } from "../tokens";
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
const DEFAULT_COLORS = [...motionConfettiColors];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 从全局令牌实时读取 Confetti 默认色板:
|
|
20
|
+
* --aura-motion-accent / cyan / blue / fuchsia 随双轴主题
|
|
21
|
+
* (data-mode × data-palette)切换,fire 时读取即与当前主题一致。
|
|
22
|
+
* 令牌缺失(SSR / 未引入 tokens.css)时回退 motionConfettiColors。
|
|
23
|
+
*/
|
|
24
|
+
function readThemeConfettiColors() {
|
|
25
|
+
if (typeof getComputedStyle !== 'function' || typeof document === 'undefined') {
|
|
26
|
+
return DEFAULT_COLORS;
|
|
27
|
+
}
|
|
28
|
+
const styles = getComputedStyle(document.documentElement);
|
|
29
|
+
const token = (name, fallback) => styles.getPropertyValue(name).trim() || fallback;
|
|
30
|
+
return [token('--aura-motion-accent', DEFAULT_COLORS[0]), token('--aura-motion-cyan', DEFAULT_COLORS[1]), token('--aura-motion-blue', DEFAULT_COLORS[2]), token('--aura-motion-fuchsia', DEFAULT_COLORS[3]), token('--aura-motion-accent-strong', DEFAULT_COLORS[4]), token('--aura-motion-cyan', DEFAULT_COLORS[5])];
|
|
31
|
+
}
|
|
17
32
|
export function Confetti({
|
|
18
33
|
fire,
|
|
19
34
|
count = 120,
|
|
@@ -21,7 +36,7 @@ export function Confetti({
|
|
|
21
36
|
x: 0.5,
|
|
22
37
|
y: 0.6
|
|
23
38
|
},
|
|
24
|
-
colors
|
|
39
|
+
colors
|
|
25
40
|
}) {
|
|
26
41
|
const canvasRef = useRef(null);
|
|
27
42
|
const reduced = useReducedMotion();
|
|
@@ -35,6 +50,9 @@ export function Confetti({
|
|
|
35
50
|
canvas.height = window.innerHeight;
|
|
36
51
|
const ox = origin.x * canvas.width;
|
|
37
52
|
const oy = origin.y * canvas.height;
|
|
53
|
+
|
|
54
|
+
// 发射瞬间取色:未显式传 colors 时跟当前主题(令牌实时值)
|
|
55
|
+
const palette = colors ?? readThemeConfettiColors();
|
|
38
56
|
const parts = Array.from({
|
|
39
57
|
length: count
|
|
40
58
|
}, (_, i) => {
|
|
@@ -53,7 +71,7 @@ export function Confetti({
|
|
|
53
71
|
tiltSpeed: 0.12 + Math.random() * 0.22,
|
|
54
72
|
w: ribbon ? 5 + Math.random() * 4 : 7 + Math.random() * 5,
|
|
55
73
|
h: ribbon ? 16 + Math.random() * 8 : 7 + Math.random() * 5,
|
|
56
|
-
color:
|
|
74
|
+
color: palette[i % palette.length],
|
|
57
75
|
life: 1,
|
|
58
76
|
decay: 0.007 + Math.random() * 0.007,
|
|
59
77
|
ribbon
|
|
@@ -8,6 +8,15 @@ import { useScroll, type MotionValue } from 'motion/react';
|
|
|
8
8
|
type ScrollOffsetOption = NonNullable<Parameters<typeof useScroll>[0]>['offset'];
|
|
9
9
|
export interface ScrollDrivenProps {
|
|
10
10
|
children: (progress: MotionValue<number>) => ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* 进度语义:
|
|
13
|
+
* - `'target'`(默认):**元素在容器内的可见进度**(由 `offset` 定义 0 与 1 锚点)。
|
|
14
|
+
* 适合"进入视口时揭示"。
|
|
15
|
+
* - `'container'`:**滚动容器自身的滚动位置**——顶部 0、底部 1。
|
|
16
|
+
* 适合阅读进度条 / 滚动叙事;无内层容器时等价于页面滚动进度。
|
|
17
|
+
*/
|
|
18
|
+
mode?: 'container' | 'target';
|
|
19
|
+
/** 仅 `mode='target'` 时生效:进度判定区间 */
|
|
11
20
|
offset?: ScrollOffsetOption;
|
|
12
21
|
/** 给进度加一层弹簧平滑(0 关闭) */
|
|
13
22
|
smooth?: number;
|
|
@@ -19,7 +28,7 @@ export interface ScrollDrivenProps {
|
|
|
19
28
|
style?: React.CSSProperties;
|
|
20
29
|
className?: string;
|
|
21
30
|
}
|
|
22
|
-
export declare function ScrollDriven({ children, offset, smooth, container, style, className, }: ScrollDrivenProps): import("react").JSX.Element;
|
|
31
|
+
export declare function ScrollDriven({ children, mode, offset, smooth, container, style, className, }: ScrollDrivenProps): import("react").JSX.Element;
|
|
23
32
|
/** 预置:顶部线性进度条(跟随页面纵向滚动) */
|
|
24
33
|
export declare function ScrollProgressBar({ smooth }: {
|
|
25
34
|
smooth?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-driven.d.ts","sourceRoot":"","sources":["scroll-driven.tsx"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAU,SAAS,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAG9E,+CAA+C;AAC/C,KAAK,kBAAkB,GAAG,WAAW,CACnC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAChC,CAAC,QAAQ,CAAC,CAAC;AAEZ,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC;IACvD,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAmC,EACnC,MAAU,EACV,SAAS,EACT,KAAK,EACL,SAAS,GACV,EAAE,iBAAiB,+
|
|
1
|
+
{"version":3,"file":"scroll-driven.d.ts","sourceRoot":"","sources":["scroll-driven.tsx"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAU,SAAS,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAG9E,+CAA+C;AAC/C,KAAK,kBAAkB,GAAG,WAAW,CACnC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAChC,CAAC,QAAQ,CAAC,CAAC;AAEZ,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC;IACvD;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC9B,mCAAmC;IACnC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAe,EACf,MAAmC,EACnC,MAAU,EACV,SAAS,EACT,KAAK,EACL,SAAS,GACV,EAAE,iBAAiB,+BA2BnB;AAED,2BAA2B;AAC3B,wBAAgB,iBAAiB,CAAC,EAAE,MAAY,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,+BAmBtE"}
|
|
@@ -12,6 +12,7 @@ import { useScrollContainer } from "../hooks/use-scroll-container";
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
export function ScrollDriven({
|
|
14
14
|
children,
|
|
15
|
+
mode = 'target',
|
|
15
16
|
offset = ['start end', 'end start'],
|
|
16
17
|
smooth = 0,
|
|
17
18
|
container,
|
|
@@ -20,16 +21,23 @@ export function ScrollDriven({
|
|
|
20
21
|
}) {
|
|
21
22
|
const ref = useRef(null);
|
|
22
23
|
const scrollContainer = useScrollContainer(ref, container);
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
// 容器自身的滚动位置(无内层容器时即页面滚动轴):顶部 0 → 底部 1
|
|
26
|
+
const containerScroll = useScroll({
|
|
27
|
+
container: scrollContainer
|
|
28
|
+
}).scrollYProgress;
|
|
29
|
+
// 元素相对容器的可见进度(需要 offset 锚点)
|
|
30
|
+
const targetScroll = useScroll({
|
|
24
31
|
target: ref,
|
|
25
32
|
container: scrollContainer,
|
|
26
33
|
offset
|
|
27
|
-
});
|
|
28
|
-
const
|
|
34
|
+
}).scrollYProgress;
|
|
35
|
+
const raw = mode === 'container' ? containerScroll : targetScroll;
|
|
36
|
+
const springed = useSpring(raw, {
|
|
29
37
|
stiffness: 200,
|
|
30
38
|
damping: 40
|
|
31
39
|
});
|
|
32
|
-
const progress = smooth > 0 ? springed : raw
|
|
40
|
+
const progress = smooth > 0 ? springed : raw;
|
|
33
41
|
return /*#__PURE__*/_jsx("div", {
|
|
34
42
|
ref: ref,
|
|
35
43
|
className: className,
|
package/esm/config/index.js
CHANGED
package/esm/hooks/index.js
CHANGED
package/esm/index.js
CHANGED
package/esm/tokens.css
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* 动效令牌(CSS 端)—— 与 src/tokens.ts 保持一致(tokens.test.ts 守护漂移)。
|
|
3
3
|
* 消费方:引入本包的 `tokens.css` 子路径,或依赖 ui/x/business
|
|
4
4
|
* 等联动包的级联引入。
|
|
5
|
+
*
|
|
6
|
+
* 颜色令牌随全局双轴主题切换:
|
|
7
|
+
* data-mode(light|dark) × data-palette(violet|ocean|sunset),
|
|
8
|
+
* 历史选择器 [data-theme="dark"] 保留兼容(= dark × violet)。
|
|
5
9
|
*/
|
|
6
10
|
:root {
|
|
7
11
|
--aura-motion-duration-instant: 80ms;
|
|
@@ -37,7 +41,8 @@
|
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/* 暗色:同一套语义,换成更亮的霓虹与更低的表面亮度 */
|
|
40
|
-
[data-theme='dark']
|
|
44
|
+
[data-theme='dark'],
|
|
45
|
+
[data-mode='dark'][data-palette='violet'] {
|
|
41
46
|
--aura-motion-accent: #a855f7;
|
|
42
47
|
--aura-motion-accent-strong: #7c3aed;
|
|
43
48
|
--aura-motion-accent-soft: rgba(168, 85, 247, 0.18);
|
|
@@ -53,6 +58,55 @@
|
|
|
53
58
|
--aura-motion-focus-color: #a855f7;
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
/* ===== Light × Ocean =====
|
|
62
|
+
主锚 #2563eb(Tailwind blue-600),accent 系全部从主锚派生;
|
|
63
|
+
cyan / blue / fuchsia 为霓虹装饰阵列,刻意不跟色板。 */
|
|
64
|
+
[data-palette='ocean'] {
|
|
65
|
+
--aura-motion-accent: #2563eb;
|
|
66
|
+
--aura-motion-accent-strong: #1d4ed8;
|
|
67
|
+
--aura-motion-accent-soft: rgba(37, 99, 235, 0.12);
|
|
68
|
+
--aura-motion-accent-glow: rgba(37, 99, 235, 0.35);
|
|
69
|
+
--aura-motion-shimmer: rgba(37, 99, 235, 0.85);
|
|
70
|
+
--aura-motion-sheen: rgba(37, 99, 235, 0.12);
|
|
71
|
+
--aura-motion-focus-color: #2563eb;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ===== Dark × Ocean ===== */
|
|
75
|
+
[data-mode='dark'][data-palette='ocean'] {
|
|
76
|
+
--aura-motion-accent: #60a5fa;
|
|
77
|
+
--aura-motion-accent-strong: #2563eb;
|
|
78
|
+
--aura-motion-accent-soft: rgba(96, 165, 250, 0.18);
|
|
79
|
+
--aura-motion-accent-glow: rgba(96, 165, 250, 0.45);
|
|
80
|
+
--aura-motion-blue: #60a5fa;
|
|
81
|
+
--aura-motion-shimmer: rgba(255, 255, 255, 0.85);
|
|
82
|
+
--aura-motion-sheen: rgba(255, 255, 255, 0.18);
|
|
83
|
+
--aura-motion-focus-color: #60a5fa;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* ===== Light × Sunset =====
|
|
87
|
+
主锚 #ea580c(Tailwind orange-600)。 */
|
|
88
|
+
[data-palette='sunset'] {
|
|
89
|
+
--aura-motion-accent: #ea580c;
|
|
90
|
+
--aura-motion-accent-strong: #c2410c;
|
|
91
|
+
--aura-motion-accent-soft: rgba(234, 88, 12, 0.12);
|
|
92
|
+
--aura-motion-accent-glow: rgba(234, 88, 12, 0.35);
|
|
93
|
+
--aura-motion-shimmer: rgba(234, 88, 12, 0.85);
|
|
94
|
+
--aura-motion-sheen: rgba(234, 88, 12, 0.12);
|
|
95
|
+
--aura-motion-focus-color: #ea580c;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ===== Dark × Sunset ===== */
|
|
99
|
+
[data-mode='dark'][data-palette='sunset'] {
|
|
100
|
+
--aura-motion-accent: #fb923c;
|
|
101
|
+
--aura-motion-accent-strong: #ea580c;
|
|
102
|
+
--aura-motion-accent-soft: rgba(251, 146, 60, 0.18);
|
|
103
|
+
--aura-motion-accent-glow: rgba(251, 146, 60, 0.45);
|
|
104
|
+
--aura-motion-blue: #60a5fa;
|
|
105
|
+
--aura-motion-shimmer: rgba(255, 255, 255, 0.85);
|
|
106
|
+
--aura-motion-sheen: rgba(255, 255, 255, 0.18);
|
|
107
|
+
--aura-motion-focus-color: #fb923c;
|
|
108
|
+
}
|
|
109
|
+
|
|
56
110
|
/* 可访问性第一层降级:令牌驱动的样式(工具类 / 业务自研 less)在此整体归零。
|
|
57
111
|
引擎层与组件层的降级分别由 <MotionConfig reducedMotion> 与 useReducedMotion 承担。 */
|
|
58
112
|
@media (prefers-reduced-motion: reduce) {
|
package/esm/tokens.js
CHANGED