@aura-react-comp/motion 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/esm/composed/aurora.d.ts +14 -0
- package/esm/composed/aurora.d.ts.map +1 -0
- package/esm/composed/aurora.js +66 -0
- package/esm/composed/confetti.d.ts +14 -0
- package/esm/composed/confetti.d.ts.map +1 -0
- package/esm/composed/confetti.js +99 -0
- package/esm/composed/cursor.d.ts +12 -0
- package/esm/composed/cursor.d.ts.map +1 -0
- package/esm/composed/cursor.js +112 -0
- package/esm/composed/draggable.d.ts +19 -0
- package/esm/composed/draggable.d.ts.map +1 -0
- package/esm/composed/draggable.js +62 -0
- package/esm/composed/flip-list.d.ts +21 -0
- package/esm/composed/flip-list.d.ts.map +1 -0
- package/esm/composed/flip-list.js +53 -0
- package/esm/composed/layout-group.d.ts +6 -0
- package/esm/composed/layout-group.d.ts.map +1 -0
- package/esm/composed/layout-group.js +7 -0
- package/esm/composed/lottie-player.d.ts +13 -0
- package/esm/composed/lottie-player.d.ts.map +1 -0
- package/esm/composed/lottie-player.js +57 -0
- package/esm/composed/page-transition.d.ts +23 -0
- package/esm/composed/page-transition.d.ts.map +1 -0
- package/esm/composed/page-transition.js +53 -0
- package/esm/composed/parallax.d.ts +19 -0
- package/esm/composed/parallax.d.ts.map +1 -0
- package/esm/composed/parallax.js +59 -0
- package/esm/composed/path-draw.d.ts +22 -0
- package/esm/composed/path-draw.d.ts.map +1 -0
- package/esm/composed/path-draw.js +53 -0
- package/esm/composed/reorder.d.ts +6 -0
- package/esm/composed/reorder.d.ts.map +1 -0
- package/esm/composed/reorder.js +7 -0
- package/esm/composed/scroll-driven.d.ts +23 -0
- package/esm/composed/scroll-driven.d.ts.map +1 -0
- package/esm/composed/scroll-driven.js +62 -0
- package/esm/composed/timeline.d.ts +37 -0
- package/esm/composed/timeline.d.ts.map +1 -0
- package/esm/composed/timeline.js +106 -0
- package/esm/composed/view-transition.d.ts +16 -0
- package/esm/composed/view-transition.d.ts.map +1 -0
- package/esm/composed/view-transition.js +47 -0
- package/esm/config/index.d.ts +6 -0
- package/esm/config/index.d.ts.map +1 -0
- package/esm/config/index.js +5 -0
- package/esm/hooks/index.d.ts +5 -0
- package/esm/hooks/index.d.ts.map +1 -0
- package/esm/hooks/index.js +4 -0
- package/esm/index.d.ts +58 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +42 -0
- package/esm/primitive/focus-ring.d.ts +18 -0
- package/esm/primitive/focus-ring.d.ts.map +1 -0
- package/esm/primitive/focus-ring.js +81 -0
- package/esm/primitive/in-viewport.d.ts +19 -0
- package/esm/primitive/in-viewport.d.ts.map +1 -0
- package/esm/primitive/in-viewport.js +41 -0
- package/esm/primitive/keyframes.d.ts +23 -0
- package/esm/primitive/keyframes.d.ts.map +1 -0
- package/esm/primitive/keyframes.js +41 -0
- package/esm/primitive/magnetic.d.ts +14 -0
- package/esm/primitive/magnetic.d.ts.map +1 -0
- package/esm/primitive/magnetic.js +51 -0
- package/esm/primitive/number-ticker.d.ts +16 -0
- package/esm/primitive/number-ticker.d.ts.map +1 -0
- package/esm/primitive/number-ticker.js +42 -0
- package/esm/primitive/reveal.d.ts +22 -0
- package/esm/primitive/reveal.d.ts.map +1 -0
- package/esm/primitive/reveal.js +45 -0
- package/esm/primitive/skeleton-shimmer.d.ts +12 -0
- package/esm/primitive/skeleton-shimmer.d.ts.map +1 -0
- package/esm/primitive/skeleton-shimmer.js +50 -0
- package/esm/primitive/split-text.d.ts +17 -0
- package/esm/primitive/split-text.d.ts.map +1 -0
- package/esm/primitive/split-text.js +97 -0
- package/esm/primitive/transition.d.ts +54 -0
- package/esm/primitive/transition.d.ts.map +1 -0
- package/esm/primitive/transition.js +174 -0
- package/esm/primitive/typewriter.d.ts +15 -0
- package/esm/primitive/typewriter.d.ts.map +1 -0
- package/esm/primitive/typewriter.js +75 -0
- package/esm/tokens.css +32 -0
- package/esm/tokens.d.ts +33 -0
- package/esm/tokens.d.ts.map +1 -0
- package/esm/tokens.js +52 -0
- package/package.json +64 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 文字拆分进场:按字 / 词 / 行三种粒度依次入场。
|
|
5
|
+
* reduced-motion 下直接渲染完整文本。
|
|
6
|
+
*/
|
|
7
|
+
import { Fragment, useMemo } from 'react';
|
|
8
|
+
import { motion, useReducedMotion } from 'motion/react';
|
|
9
|
+
import { motionDurations, motionEases } from "../tokens";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
function split(text, granularity) {
|
|
14
|
+
if (granularity === 'char') return Array.from(text);
|
|
15
|
+
if (granularity === 'word') return text.split(/(\s+)/).filter(Boolean);
|
|
16
|
+
return text.split('\n');
|
|
17
|
+
}
|
|
18
|
+
export function SplitText({
|
|
19
|
+
text,
|
|
20
|
+
granularity = 'char',
|
|
21
|
+
stagger = 0.04,
|
|
22
|
+
duration = 'normal',
|
|
23
|
+
mode = 'mount',
|
|
24
|
+
className,
|
|
25
|
+
style
|
|
26
|
+
}) {
|
|
27
|
+
const reduced = useReducedMotion();
|
|
28
|
+
const parts = useMemo(() => split(text, granularity), [text, granularity]);
|
|
29
|
+
if (reduced) {
|
|
30
|
+
return /*#__PURE__*/_jsx("span", {
|
|
31
|
+
className: className,
|
|
32
|
+
style: style,
|
|
33
|
+
children: granularity === 'line' ? parts.map((p, i) => /*#__PURE__*/_jsxs(Fragment, {
|
|
34
|
+
children: [i > 0 && /*#__PURE__*/_jsx("br", {}), p]
|
|
35
|
+
}, i)) : text
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const container = {
|
|
39
|
+
hidden: {},
|
|
40
|
+
show: {
|
|
41
|
+
transition: {
|
|
42
|
+
staggerChildren: stagger
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const item = {
|
|
47
|
+
hidden: {
|
|
48
|
+
opacity: 0,
|
|
49
|
+
y: granularity === 'line' ? 12 : 8
|
|
50
|
+
},
|
|
51
|
+
show: {
|
|
52
|
+
opacity: 1,
|
|
53
|
+
y: 0,
|
|
54
|
+
transition: {
|
|
55
|
+
duration: motionDurations[duration],
|
|
56
|
+
ease: motionEases.decelerate
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const trigger = mode === 'inView' ? {
|
|
61
|
+
whileInView: 'show',
|
|
62
|
+
viewport: {
|
|
63
|
+
once: true,
|
|
64
|
+
margin: '0px 0px -32px 0px'
|
|
65
|
+
}
|
|
66
|
+
} : {
|
|
67
|
+
animate: 'show'
|
|
68
|
+
};
|
|
69
|
+
return /*#__PURE__*/_jsx(motion.span, {
|
|
70
|
+
className: className,
|
|
71
|
+
style: {
|
|
72
|
+
display: 'inline-block',
|
|
73
|
+
...style
|
|
74
|
+
},
|
|
75
|
+
initial: "hidden",
|
|
76
|
+
variants: container,
|
|
77
|
+
...trigger,
|
|
78
|
+
"aria-label": text,
|
|
79
|
+
children: parts.map((part, i) => {
|
|
80
|
+
// 空白片段保留原样,不参与动画
|
|
81
|
+
if (/^\s+$/.test(part)) return /*#__PURE__*/_jsx(Fragment, {
|
|
82
|
+
children: part
|
|
83
|
+
}, i);
|
|
84
|
+
return /*#__PURE__*/_jsx(motion.span, {
|
|
85
|
+
variants: item,
|
|
86
|
+
"aria-hidden": true,
|
|
87
|
+
style: {
|
|
88
|
+
display: 'inline-block',
|
|
89
|
+
willChange: 'transform, opacity'
|
|
90
|
+
},
|
|
91
|
+
children: granularity === 'line' ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
92
|
+
children: [i > 0 && /*#__PURE__*/_jsx("br", {}), part]
|
|
93
|
+
}) : part
|
|
94
|
+
}, i);
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* 进出场过渡四件套:Slide / Fade / Zoom / Collapse。
|
|
4
|
+
*
|
|
5
|
+
* 两种使用模式:
|
|
6
|
+
* - **保留式**:`<Slide visible={open} />` —— DOM 常驻,visible 切换动画;
|
|
7
|
+
* - **卸载式**:`{open && <Slide />}` 包在 `<AnimatePresence>` 内 —— 卸载时播退场。
|
|
8
|
+
*
|
|
9
|
+
* 全部只动画 transform / opacity(Collapse 的 height 是既有例外,见其 JSDoc),
|
|
10
|
+
* 时长与缓动一律走动效令牌。
|
|
11
|
+
*
|
|
12
|
+
* 可测性:根元素暴露 `data-motion-state`("entered" | "exited",由 visible 派生的
|
|
13
|
+
* **意图状态**——动画完成时机会略有滞后,测试断言以意图为准)。
|
|
14
|
+
*/
|
|
15
|
+
import { type HTMLMotionProps } from 'motion/react';
|
|
16
|
+
import { type DistanceToken, type DurationToken, type EaseToken } from '../tokens';
|
|
17
|
+
type Direction = 'up' | 'down' | 'left' | 'right';
|
|
18
|
+
/** 保留式显隐省略时(undefined),组件默认可见,退场交给外层 AnimatePresence */
|
|
19
|
+
export interface TransitionBaseProps extends Omit<HTMLMotionProps<'div'>, 'initial' | 'animate' | 'exit' | 'transition'> {
|
|
20
|
+
duration?: DurationToken;
|
|
21
|
+
ease?: EaseToken;
|
|
22
|
+
}
|
|
23
|
+
export interface SlideProps extends TransitionBaseProps {
|
|
24
|
+
direction?: Direction;
|
|
25
|
+
distance?: DistanceToken;
|
|
26
|
+
visible?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** 位移 + 淡入淡出:抽屉、浮层、区块显隐的默认选择 */
|
|
29
|
+
export declare function Slide({ visible, direction, distance, duration, ease, style, ...rest }: SlideProps): import("react").JSX.Element;
|
|
30
|
+
export type FadeProps = TransitionBaseProps & {
|
|
31
|
+
visible?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** 纯淡入淡出:内容位置不变,最不打扰的过渡 */
|
|
34
|
+
export declare function Fade({ visible, duration, ease, style, ...rest }: FadeProps): import("react").JSX.Element;
|
|
35
|
+
export type ZoomProps = TransitionBaseProps & {
|
|
36
|
+
visible?: boolean;
|
|
37
|
+
/** 收起态缩放比例,默认 0.92(足够可感知、不突兀) */
|
|
38
|
+
fromScale?: number;
|
|
39
|
+
};
|
|
40
|
+
/** 缩放 + 淡入淡出:弹窗、卡片、头像等"从原点长出来"的场景 */
|
|
41
|
+
export declare function Zoom({ visible, fromScale, duration, ease, style, ...rest }: ZoomProps): import("react").JSX.Element;
|
|
42
|
+
export interface CollapseProps extends Omit<HTMLMotionProps<'div'>, 'initial' | 'animate' | 'exit' | 'transition'> {
|
|
43
|
+
open?: boolean;
|
|
44
|
+
duration?: DurationToken;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 高度展开/收起:折叠面板、筛选区、详情展开。
|
|
48
|
+
*
|
|
49
|
+
* ⚠️ 实现使用 `height: auto` 动画(motion 内部测量)——这会触发逐帧布局,
|
|
50
|
+
* **不要用于长列表或页面级区域**;此类场景请改用 `<Slide>` / `<Fade>`。
|
|
51
|
+
*/
|
|
52
|
+
export declare function Collapse({ open, duration, style, children, ...rest }: CollapseProps): import("react").JSX.Element;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transition.d.ts","sourceRoot":"","sources":["transition.tsx"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAU,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,WAAW,CAAC;AAEnB,KAAK,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,wDAAwD;AACxD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IACnF,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAgBD,MAAM,WAAW,UAAW,SAAQ,mBAAmB;IACrD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,gCAAgC;AAChC,wBAAgB,KAAK,CAAC,EACpB,OAAc,EACd,SAAgB,EAChB,QAAe,EACf,QAAmB,EACnB,IAAmB,EACnB,KAAK,EACL,GAAG,IAAI,EACR,EAAE,UAAU,+BAaZ;AAED,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpE,2BAA2B;AAC3B,wBAAgB,IAAI,CAAC,EACnB,OAAc,EACd,QAAmB,EACnB,IAAiB,EACjB,KAAK,EACL,GAAG,IAAI,EACR,EAAE,SAAS,+BAYX;AAED,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qCAAqC;AACrC,wBAAgB,IAAI,CAAC,EACnB,OAAc,EACd,SAAgB,EAChB,QAAmB,EACnB,IAAmB,EACnB,KAAK,EACL,GAAG,IAAI,EACR,EAAE,SAAS,+BAYX;AAED,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IACnF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAY,EACZ,QAAmB,EACnB,KAAK,EACL,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,aAAa,+BAaf"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 进出场过渡四件套:Slide / Fade / Zoom / Collapse。
|
|
5
|
+
*
|
|
6
|
+
* 两种使用模式:
|
|
7
|
+
* - **保留式**:`<Slide visible={open} />` —— DOM 常驻,visible 切换动画;
|
|
8
|
+
* - **卸载式**:`{open && <Slide />}` 包在 `<AnimatePresence>` 内 —— 卸载时播退场。
|
|
9
|
+
*
|
|
10
|
+
* 全部只动画 transform / opacity(Collapse 的 height 是既有例外,见其 JSDoc),
|
|
11
|
+
* 时长与缓动一律走动效令牌。
|
|
12
|
+
*
|
|
13
|
+
* 可测性:根元素暴露 `data-motion-state`("entered" | "exited",由 visible 派生的
|
|
14
|
+
* **意图状态**——动画完成时机会略有滞后,测试断言以意图为准)。
|
|
15
|
+
*/
|
|
16
|
+
import { motion } from 'motion/react';
|
|
17
|
+
import { motionDurations, motionDistances, motionEases } from "../tokens";
|
|
18
|
+
|
|
19
|
+
/** 保留式显隐省略时(undefined),组件默认可见,退场交给外层 AnimatePresence */
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
function offsetFor(direction, distance) {
|
|
22
|
+
const d = motionDistances[distance];
|
|
23
|
+
switch (direction) {
|
|
24
|
+
case 'up':
|
|
25
|
+
return {
|
|
26
|
+
y: d
|
|
27
|
+
};
|
|
28
|
+
case 'down':
|
|
29
|
+
return {
|
|
30
|
+
y: -d
|
|
31
|
+
};
|
|
32
|
+
case 'left':
|
|
33
|
+
return {
|
|
34
|
+
x: d
|
|
35
|
+
};
|
|
36
|
+
case 'right':
|
|
37
|
+
return {
|
|
38
|
+
x: -d
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** 位移 + 淡入淡出:抽屉、浮层、区块显隐的默认选择 */
|
|
43
|
+
export function Slide({
|
|
44
|
+
visible = true,
|
|
45
|
+
direction = 'up',
|
|
46
|
+
distance = 'md',
|
|
47
|
+
duration = 'normal',
|
|
48
|
+
ease = 'decelerate',
|
|
49
|
+
style,
|
|
50
|
+
...rest
|
|
51
|
+
}) {
|
|
52
|
+
const offset = offsetFor(direction, distance);
|
|
53
|
+
return /*#__PURE__*/_jsx(motion.div, {
|
|
54
|
+
initial: {
|
|
55
|
+
opacity: 0,
|
|
56
|
+
...offset
|
|
57
|
+
},
|
|
58
|
+
animate: visible ? {
|
|
59
|
+
opacity: 1,
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0
|
|
62
|
+
} : {
|
|
63
|
+
opacity: 0,
|
|
64
|
+
...offset
|
|
65
|
+
},
|
|
66
|
+
exit: {
|
|
67
|
+
opacity: 0,
|
|
68
|
+
...offset
|
|
69
|
+
},
|
|
70
|
+
transition: {
|
|
71
|
+
duration: motionDurations[duration],
|
|
72
|
+
ease: motionEases[ease]
|
|
73
|
+
},
|
|
74
|
+
"data-motion-state": visible ? 'entered' : 'exited',
|
|
75
|
+
style: style,
|
|
76
|
+
...rest
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** 纯淡入淡出:内容位置不变,最不打扰的过渡 */
|
|
80
|
+
export function Fade({
|
|
81
|
+
visible = true,
|
|
82
|
+
duration = 'normal',
|
|
83
|
+
ease = 'standard',
|
|
84
|
+
style,
|
|
85
|
+
...rest
|
|
86
|
+
}) {
|
|
87
|
+
return /*#__PURE__*/_jsx(motion.div, {
|
|
88
|
+
initial: {
|
|
89
|
+
opacity: 0
|
|
90
|
+
},
|
|
91
|
+
animate: {
|
|
92
|
+
opacity: visible ? 1 : 0
|
|
93
|
+
},
|
|
94
|
+
exit: {
|
|
95
|
+
opacity: 0
|
|
96
|
+
},
|
|
97
|
+
transition: {
|
|
98
|
+
duration: motionDurations[duration],
|
|
99
|
+
ease: motionEases[ease]
|
|
100
|
+
},
|
|
101
|
+
"data-motion-state": visible ? 'entered' : 'exited',
|
|
102
|
+
style: style,
|
|
103
|
+
...rest
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** 缩放 + 淡入淡出:弹窗、卡片、头像等"从原点长出来"的场景 */
|
|
107
|
+
export function Zoom({
|
|
108
|
+
visible = true,
|
|
109
|
+
fromScale = 0.92,
|
|
110
|
+
duration = 'normal',
|
|
111
|
+
ease = 'decelerate',
|
|
112
|
+
style,
|
|
113
|
+
...rest
|
|
114
|
+
}) {
|
|
115
|
+
return /*#__PURE__*/_jsx(motion.div, {
|
|
116
|
+
initial: {
|
|
117
|
+
opacity: 0,
|
|
118
|
+
scale: fromScale
|
|
119
|
+
},
|
|
120
|
+
animate: {
|
|
121
|
+
opacity: visible ? 1 : 0,
|
|
122
|
+
scale: visible ? 1 : fromScale
|
|
123
|
+
},
|
|
124
|
+
exit: {
|
|
125
|
+
opacity: 0,
|
|
126
|
+
scale: fromScale
|
|
127
|
+
},
|
|
128
|
+
transition: {
|
|
129
|
+
duration: motionDurations[duration],
|
|
130
|
+
ease: motionEases[ease]
|
|
131
|
+
},
|
|
132
|
+
"data-motion-state": visible ? 'entered' : 'exited',
|
|
133
|
+
style: style,
|
|
134
|
+
...rest
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 高度展开/收起:折叠面板、筛选区、详情展开。
|
|
139
|
+
*
|
|
140
|
+
* ⚠️ 实现使用 `height: auto` 动画(motion 内部测量)——这会触发逐帧布局,
|
|
141
|
+
* **不要用于长列表或页面级区域**;此类场景请改用 `<Slide>` / `<Fade>`。
|
|
142
|
+
*/
|
|
143
|
+
export function Collapse({
|
|
144
|
+
open = false,
|
|
145
|
+
duration = 'normal',
|
|
146
|
+
style,
|
|
147
|
+
children,
|
|
148
|
+
...rest
|
|
149
|
+
}) {
|
|
150
|
+
return /*#__PURE__*/_jsx(motion.div, {
|
|
151
|
+
initial: false,
|
|
152
|
+
animate: open ? {
|
|
153
|
+
height: 'auto',
|
|
154
|
+
opacity: 1
|
|
155
|
+
} : {
|
|
156
|
+
height: 0,
|
|
157
|
+
opacity: 0
|
|
158
|
+
},
|
|
159
|
+
exit: {
|
|
160
|
+
height: 0,
|
|
161
|
+
opacity: 0
|
|
162
|
+
},
|
|
163
|
+
transition: {
|
|
164
|
+
duration: motionDurations[duration],
|
|
165
|
+
ease: motionEases.standard
|
|
166
|
+
},
|
|
167
|
+
style: {
|
|
168
|
+
overflow: 'hidden',
|
|
169
|
+
...style
|
|
170
|
+
},
|
|
171
|
+
...rest,
|
|
172
|
+
children: children
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface TypewriterProps {
|
|
3
|
+
text: string;
|
|
4
|
+
/** 每个字符的间隔(毫秒) */
|
|
5
|
+
speed?: number;
|
|
6
|
+
/** 起始延时(毫秒) */
|
|
7
|
+
delay?: number;
|
|
8
|
+
/** 是否显示闪烁光标 */
|
|
9
|
+
caret?: boolean;
|
|
10
|
+
/** 全部输出完成时回调 */
|
|
11
|
+
onComplete?: () => void;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function Typewriter({ text, speed, delay, caret, onComplete, className, }: TypewriterProps): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=typewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typewriter.d.ts","sourceRoot":"","sources":["typewriter.tsx"],"names":[],"mappings":";AAUA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gBAAgB;IAChB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,KAAU,EACV,KAAS,EACT,KAAY,EACZ,UAAU,EACV,SAAS,GACV,EAAE,eAAe,+BAwDjB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 打字机:AI 流式回复的补位方案(无流式接口时模拟逐字输出)。
|
|
5
|
+
* reduced-motion 下直接呈现全文;文本变化时重放。
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useRef, useState } from 'react';
|
|
8
|
+
import { motion, useReducedMotion } from 'motion/react';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
export function Typewriter({
|
|
12
|
+
text,
|
|
13
|
+
speed = 32,
|
|
14
|
+
delay = 0,
|
|
15
|
+
caret = true,
|
|
16
|
+
onComplete,
|
|
17
|
+
className
|
|
18
|
+
}) {
|
|
19
|
+
const reduced = useReducedMotion();
|
|
20
|
+
const [count, setCount] = useState(0);
|
|
21
|
+
const doneRef = useRef(false);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (reduced) {
|
|
24
|
+
setCount(text.length);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setCount(0);
|
|
28
|
+
doneRef.current = false;
|
|
29
|
+
let timer;
|
|
30
|
+
const startTimer = setTimeout(() => {
|
|
31
|
+
timer = setInterval(() => {
|
|
32
|
+
setCount(c => {
|
|
33
|
+
if (c >= text.length) {
|
|
34
|
+
clearInterval(timer);
|
|
35
|
+
return c;
|
|
36
|
+
}
|
|
37
|
+
return c + 1;
|
|
38
|
+
});
|
|
39
|
+
}, speed);
|
|
40
|
+
}, delay);
|
|
41
|
+
return () => {
|
|
42
|
+
clearTimeout(startTimer);
|
|
43
|
+
clearInterval(timer);
|
|
44
|
+
};
|
|
45
|
+
}, [text, speed, delay, reduced]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (count >= text.length && text.length > 0 && !doneRef.current) {
|
|
48
|
+
doneRef.current = true;
|
|
49
|
+
onComplete?.();
|
|
50
|
+
}
|
|
51
|
+
}, [count, text, onComplete]);
|
|
52
|
+
const done = count >= text.length;
|
|
53
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
54
|
+
className: className,
|
|
55
|
+
children: [text.slice(0, count), caret && !done && /*#__PURE__*/_jsx(motion.span, {
|
|
56
|
+
"aria-hidden": true,
|
|
57
|
+
animate: {
|
|
58
|
+
opacity: [1, 0]
|
|
59
|
+
},
|
|
60
|
+
transition: {
|
|
61
|
+
duration: 0.7,
|
|
62
|
+
repeat: Infinity,
|
|
63
|
+
ease: 'linear'
|
|
64
|
+
},
|
|
65
|
+
children: "\u258D"
|
|
66
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
67
|
+
"aria-live": "polite",
|
|
68
|
+
style: {
|
|
69
|
+
position: 'absolute',
|
|
70
|
+
left: -9999
|
|
71
|
+
},
|
|
72
|
+
children: done ? text : ''
|
|
73
|
+
})]
|
|
74
|
+
});
|
|
75
|
+
}
|
package/esm/tokens.css
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动效令牌(CSS 端)—— 与 src/tokens.ts 保持一致(tokens.test.ts 守护漂移)。
|
|
3
|
+
* 消费方:引入本包的 `tokens.css` 子路径,或依赖 ui/x/business
|
|
4
|
+
* 等联动包的级联引入。
|
|
5
|
+
*/
|
|
6
|
+
:root {
|
|
7
|
+
--aura-motion-duration-instant: 80ms;
|
|
8
|
+
--aura-motion-duration-fast: 160ms;
|
|
9
|
+
--aura-motion-duration-normal: 280ms;
|
|
10
|
+
--aura-motion-duration-slow: 480ms;
|
|
11
|
+
--aura-motion-duration-deliberate: 720ms;
|
|
12
|
+
|
|
13
|
+
--aura-motion-ease-standard: cubic-bezier(0.2, 0, 0, 1);
|
|
14
|
+
--aura-motion-ease-decelerate: cubic-bezier(0, 0, 0, 1);
|
|
15
|
+
--aura-motion-ease-accelerate: cubic-bezier(0.3, 0, 1, 1);
|
|
16
|
+
|
|
17
|
+
--aura-motion-distance-sm: 8px;
|
|
18
|
+
--aura-motion-distance-md: 16px;
|
|
19
|
+
--aura-motion-distance-lg: 32px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* 可访问性第一层降级:令牌驱动的样式(工具类 / 业务自研 less)在此整体归零。
|
|
23
|
+
引擎层与组件层的降级分别由 <MotionConfig reducedMotion> 与 useReducedMotion 承担。 */
|
|
24
|
+
@media (prefers-reduced-motion: reduce) {
|
|
25
|
+
:root {
|
|
26
|
+
--aura-motion-duration-instant: 0ms;
|
|
27
|
+
--aura-motion-duration-fast: 0ms;
|
|
28
|
+
--aura-motion-duration-normal: 0ms;
|
|
29
|
+
--aura-motion-duration-slow: 0ms;
|
|
30
|
+
--aura-motion-duration-deliberate: 0ms;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/esm/tokens.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动效令牌 —— 单一来源。
|
|
3
|
+
*
|
|
4
|
+
* 与 `tokens.css` 必须保持一致(有 tokens.test.ts 守护双端漂移)。
|
|
5
|
+
* 时长单位为**秒**(motion 的 duration 单位),CSS 端使用毫秒。
|
|
6
|
+
*/
|
|
7
|
+
export type DurationToken = 'instant' | 'fast' | 'normal' | 'slow' | 'deliberate';
|
|
8
|
+
export type EaseToken = 'standard' | 'decelerate' | 'accelerate';
|
|
9
|
+
export type SpringToken = 'spring' | 'bouncy';
|
|
10
|
+
export type DistanceToken = 'sm' | 'md' | 'lg';
|
|
11
|
+
/** 过渡时长(秒)。`prefers-reduced-motion` 下由 MotionConfig 与 CSS 令牌双层归零。 */
|
|
12
|
+
export declare const motionDurations: Record<DurationToken, number>;
|
|
13
|
+
/** cubic-bezier 缓动控制点 */
|
|
14
|
+
export declare const motionEases: Record<EaseToken, [number, number, number, number]>;
|
|
15
|
+
/** 弹簧物理参数 */
|
|
16
|
+
export declare const motionSprings: Record<SpringToken, {
|
|
17
|
+
type: 'spring';
|
|
18
|
+
stiffness: number;
|
|
19
|
+
damping: number;
|
|
20
|
+
}>;
|
|
21
|
+
/** Slide / 位移类动画的距离档位(px) */
|
|
22
|
+
export declare const motionDistances: Record<DistanceToken, number>;
|
|
23
|
+
export declare const motionTokens: {
|
|
24
|
+
readonly duration: Record<DurationToken, number>;
|
|
25
|
+
readonly ease: Record<EaseToken, [number, number, number, number]>;
|
|
26
|
+
readonly spring: Record<SpringToken, {
|
|
27
|
+
type: 'spring';
|
|
28
|
+
stiffness: number;
|
|
29
|
+
damping: number;
|
|
30
|
+
}>;
|
|
31
|
+
readonly distance: Record<DistanceToken, number>;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,CAAC;AAClF,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;AACjE,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9C,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/C,qEAAqE;AACrE,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAMzD,CAAC;AAEF,yBAAyB;AACzB,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAI3E,CAAC;AAEF,aAAa;AACb,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,WAAW,EACX;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAIvD,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAIzD,CAAC;AAEF,eAAO,MAAM,YAAY;;;;cAbf,QAAQ;mBAAa,MAAM;iBAAW,MAAM;;;CAkB5C,CAAC"}
|
package/esm/tokens.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 动效令牌 —— 单一来源。
|
|
3
|
+
*
|
|
4
|
+
* 与 `tokens.css` 必须保持一致(有 tokens.test.ts 守护双端漂移)。
|
|
5
|
+
* 时长单位为**秒**(motion 的 duration 单位),CSS 端使用毫秒。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** 过渡时长(秒)。`prefers-reduced-motion` 下由 MotionConfig 与 CSS 令牌双层归零。 */
|
|
9
|
+
export const motionDurations = {
|
|
10
|
+
instant: 0.08,
|
|
11
|
+
fast: 0.16,
|
|
12
|
+
normal: 0.28,
|
|
13
|
+
slow: 0.48,
|
|
14
|
+
deliberate: 0.72
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** cubic-bezier 缓动控制点 */
|
|
18
|
+
export const motionEases = {
|
|
19
|
+
standard: [0.2, 0, 0, 1],
|
|
20
|
+
// 默认:缓入缓出
|
|
21
|
+
decelerate: [0, 0, 0, 1],
|
|
22
|
+
// 进场:快速出发、缓慢停靠
|
|
23
|
+
accelerate: [0.3, 0, 1, 1] // 退场:缓慢出发、快速离开
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** 弹簧物理参数 */
|
|
27
|
+
export const motionSprings = {
|
|
28
|
+
spring: {
|
|
29
|
+
type: 'spring',
|
|
30
|
+
stiffness: 320,
|
|
31
|
+
damping: 30
|
|
32
|
+
},
|
|
33
|
+
// 默认:稳定不弹
|
|
34
|
+
bouncy: {
|
|
35
|
+
type: 'spring',
|
|
36
|
+
stiffness: 400,
|
|
37
|
+
damping: 17
|
|
38
|
+
} // 活泼:轻微回弹
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Slide / 位移类动画的距离档位(px) */
|
|
42
|
+
export const motionDistances = {
|
|
43
|
+
sm: 8,
|
|
44
|
+
md: 16,
|
|
45
|
+
lg: 32
|
|
46
|
+
};
|
|
47
|
+
export const motionTokens = {
|
|
48
|
+
duration: motionDurations,
|
|
49
|
+
ease: motionEases,
|
|
50
|
+
spring: motionSprings,
|
|
51
|
+
distance: motionDistances
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aura-react-comp/motion",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Aura 动效组件库 — 令牌驱动的场景化动画组件(进出场、数字与文字特效、滚动驱动、编排、手势)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"aura",
|
|
7
|
+
"react",
|
|
8
|
+
"motion",
|
|
9
|
+
"animation",
|
|
10
|
+
"transition",
|
|
11
|
+
"spring"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://asbeforelandy.github.io/aura/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/AsBeforeLandy/aura/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/AsBeforeLandy/aura.git",
|
|
20
|
+
"directory": "packages/motion"
|
|
21
|
+
},
|
|
22
|
+
"author": "Aura Team",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "esm/index.js",
|
|
26
|
+
"module": "esm/index.js",
|
|
27
|
+
"types": "esm/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"esm"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"**/*.css"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./esm/index.d.ts",
|
|
37
|
+
"import": "./esm/index.js",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./tokens.css": "./esm/tokens.css",
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"lottie-web": ">=4.0.0",
|
|
45
|
+
"react": ">=18.0.0",
|
|
46
|
+
"react-dom": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"lottie-web": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"motion": "^12.0.0"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"lottie-web": "^5.13.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "father build",
|
|
65
|
+
"dev": "father dev"
|
|
66
|
+
}
|
|
6
67
|
}
|