@aura-react-comp/motion 0.2.10 → 0.2.11
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.
|
@@ -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,EA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;;;;;;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,
|