@react-scrollytelling/framer-motion 0.3.0 → 0.3.2
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/dist/index.mjs +3 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -11
- package/dist/index.cjs +0 -82
- package/dist/index.d.cts +0 -31
- package/dist/index.d.cts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import { c } from "react/compiler-runtime";
|
|
2
4
|
import { useState } from "react";
|
|
3
5
|
import { useActiveSection } from "@react-scrollytelling/grouped";
|
|
@@ -21,7 +23,7 @@ function useActiveSectionMotionValue(onActiveSectionChange) {
|
|
|
21
23
|
if ($[0] !== onActiveSectionChange || $[1] !== scrolledRatioMotionValue) {
|
|
22
24
|
t0 = (scrollInfo) => {
|
|
23
25
|
const { trackingId: id, scrolledRatio } = scrollInfo;
|
|
24
|
-
setTrackingId(id);
|
|
26
|
+
setTrackingId((prev) => prev === id ? prev : id);
|
|
25
27
|
scrolledRatioMotionValue.set(scrolledRatio);
|
|
26
28
|
if (onActiveSectionChange) onActiveSectionChange(scrollInfo);
|
|
27
29
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["useCallback","useState","useActiveSection","useMotionValue","useActiveSectionMotionValue","onActiveSectionChange","$","_c","scrolledRatioMotionValue","trackingId","setTrackingId","t0","scrollInfo","id","scrolledRatio","set","onSectionScroll","t1","useCallback","useSectionScroll","useMotionValue","useSectionScrollMotionValue","sectionRef","onScroll","t0","options","$","_c","shouldObserve","undefined","scrolledRatioMotionValue","t1","scrollInfo","scrolledRatio","set","onSectionScroll","t2"],"sources":["../src/hooks/useActiveSectionMotionValue.ts","../src/hooks/useSectionScrollMotionValue.ts"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport {\n ActiveSectionScrollInfo,\n useActiveSection,\n ActiveSectionObserver,\n} from \"@react-scrollytelling/grouped\";\nimport { useMotionValue } from \"motion/react\";\n\n/**\n * Watches for all tracked sections to find the section closet to the bottom of the viewport\n * through ScrollytellingProvider.\n * It invokes the onActiveSectionChange when the active section changes.\n * Returns the Motion value of the section scroll.\n * @param onActiveSectionChange - The callback needs to be memoized\n * @returns The trackingId of the active section and the Motion value of the section scroll\n */\nexport function useActiveSectionMotionValue(\n onActiveSectionChange?: ActiveSectionObserver\n) {\n const scrolledRatioMotionValue = useMotionValue(0);\n const [trackingId, setTrackingId] = useState<string | null>(null);\n\n const onSectionScroll = useCallback(\n (scrollInfo: ActiveSectionScrollInfo) => {\n const { trackingId: id, scrolledRatio } = scrollInfo;\n setTrackingId(id);\n scrolledRatioMotionValue.set(scrolledRatio);\n\n if (onActiveSectionChange) {\n onActiveSectionChange(scrollInfo);\n }\n },\n [onActiveSectionChange, scrolledRatioMotionValue]\n );\n\n useActiveSection(onSectionScroll);\n\n return {\n trackingId,\n scrolledRatioMotionValue,\n };\n}\n","import { useCallback } from \"react\";\n\nimport {\n IntersectionObserverOptions,\n SectionScrollInfo,\n useSectionScroll,\n} from \"@react-scrollytelling/core\";\nimport { useMotionValue } from \"motion/react\";\n\n/**\n * Get the Motion value of the section scroll\n * @param sectionRef - The reference to the section element\n * @param shouldObserve - Whether the underlying IntersectionObserver should be active\n * @param onScroll - The callback to track the scroll ratio\n */\nexport function useSectionScrollMotionValue(\n sectionRef: React.RefObject<Element>,\n onScroll?: (scrollInfo: SectionScrollInfo) => void,\n shouldObserve = true,\n options?: IntersectionObserverOptions\n) {\n const scrolledRatioMotionValue = useMotionValue(0);\n\n const onSectionScroll = useCallback(\n (scrollInfo: SectionScrollInfo) => {\n const { scrolledRatio } = scrollInfo;\n scrolledRatioMotionValue.set(scrolledRatio);\n\n if (onScroll) {\n onScroll(scrollInfo);\n }\n },\n [onScroll, scrolledRatioMotionValue]\n );\n\n useSectionScroll(sectionRef, onSectionScroll, shouldObserve, options);\n\n return { scrolledRatioMotionValue };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["useCallback","useState","useActiveSection","useMotionValue","useActiveSectionMotionValue","onActiveSectionChange","$","_c","scrolledRatioMotionValue","trackingId","setTrackingId","t0","scrollInfo","id","scrolledRatio","prev","set","onSectionScroll","t1","useCallback","useSectionScroll","useMotionValue","useSectionScrollMotionValue","sectionRef","onScroll","t0","options","$","_c","shouldObserve","undefined","scrolledRatioMotionValue","t1","scrollInfo","scrolledRatio","set","onSectionScroll","t2"],"sources":["../src/hooks/useActiveSectionMotionValue.ts","../src/hooks/useSectionScrollMotionValue.ts"],"sourcesContent":["import { useCallback, useState } from \"react\";\n\nimport {\n type ActiveSectionScrollInfo,\n useActiveSection,\n type ActiveSectionObserver,\n} from \"@react-scrollytelling/grouped\";\nimport { useMotionValue } from \"motion/react\";\n\n/**\n * Watches for all tracked sections to find the section closet to the bottom of the viewport\n * through ScrollytellingProvider.\n * It invokes the onActiveSectionChange when the active section changes.\n * Returns the Motion value of the section scroll.\n * @param onActiveSectionChange - The callback needs to be memoized\n * @returns The trackingId of the active section and the Motion value of the section scroll\n */\nexport function useActiveSectionMotionValue(\n onActiveSectionChange?: ActiveSectionObserver\n) {\n const scrolledRatioMotionValue = useMotionValue(0);\n const [trackingId, setTrackingId] = useState<string | null>(null);\n\n const onSectionScroll = useCallback(\n (scrollInfo: ActiveSectionScrollInfo) => {\n const { trackingId: id, scrolledRatio } = scrollInfo;\n setTrackingId((prev) => (prev === id ? prev : id));\n scrolledRatioMotionValue.set(scrolledRatio);\n\n if (onActiveSectionChange) {\n onActiveSectionChange(scrollInfo);\n }\n },\n [onActiveSectionChange, scrolledRatioMotionValue]\n );\n\n useActiveSection(onSectionScroll);\n\n return {\n trackingId,\n scrolledRatioMotionValue,\n };\n}\n","import { useCallback } from \"react\";\n\nimport {\n type IntersectionObserverOptions,\n type SectionScrollInfo,\n useSectionScroll,\n} from \"@react-scrollytelling/core\";\nimport { useMotionValue } from \"motion/react\";\n\n/**\n * Get the Motion value of the section scroll\n * @param sectionRef - The reference to the section element\n * @param shouldObserve - Whether the underlying IntersectionObserver should be active\n * @param onScroll - The callback to track the scroll ratio\n */\nexport function useSectionScrollMotionValue(\n sectionRef: React.RefObject<Element>,\n onScroll?: (scrollInfo: SectionScrollInfo) => void,\n shouldObserve = true,\n options?: IntersectionObserverOptions\n) {\n const scrolledRatioMotionValue = useMotionValue(0);\n\n const onSectionScroll = useCallback(\n (scrollInfo: SectionScrollInfo) => {\n const { scrolledRatio } = scrollInfo;\n scrolledRatioMotionValue.set(scrolledRatio);\n\n if (onScroll) {\n onScroll(scrollInfo);\n }\n },\n [onScroll, scrolledRatioMotionValue]\n );\n\n useSectionScroll(sectionRef, onSectionScroll, shouldObserve, options);\n\n return { scrolledRatioMotionValue };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAOI,4BAAAC,uBAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAGL,MAAAC,2BAAiCL,eAAe,EAAE;CAClD,MAAA,CAAAM,YAAAC,iBAAoCT,SAAwB,KAAK;CAAC,IAAAU;AAAA,KAAAL,EAAA,OAAAD,yBAAAC,EAAA,OAAAE,0BAAA;AAGhEG,QAAAC,eAAA;GACE,MAAA,EAAAH,YAAAI,IAAAC,kBAA0CF;AAC1CF,kBAAcK,SAAWA,SAASF,KAATE,OAAAF,GAAyB;AAClDL,4BAAwBQ,IAAKF,cAAc;AAE3C,OAAIT,sBACFA,uBAAsBO,WAAW;;AAEpCN,IAAA,KAAAD;AAAAC,IAAA,KAAAE;AAAAF,IAAA,KAAAK;OAAAA,MAAAL,EAAA;AAIHJ,kBAbwBS,GAaS;CAAA,IAAAO;AAAA,KAAAZ,EAAA,OAAAE,4BAAAF,EAAA,OAAAG,YAAA;AAE1BS,OAAA;GAAAT;GAAAD;GAGN;AAAAF,IAAA,KAAAE;AAAAF,IAAA,KAAAG;AAAAH,IAAA,KAAAY;OAAAA,MAAAZ,EAAA;AAAA,QAHMY;;;;;;;;;;;ACvBT,SAAOI,4BAAAC,YAAAC,UAAAC,IAAAC,SAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAGL,MAAAC,gBAAAJ,OAAAK,SAAA,OAAAL;CAGA,MAAAM,2BAAiCV,eAAe,EAAE;CAAC,IAAAW;AAAA,KAAAL,EAAA,OAAAH,YAAAG,EAAA,OAAAI,0BAAA;AAGjDC,QAAAC,eAAA;GACE,MAAA,EAAAC,kBAA0BD;AAC1BF,4BAAwBI,IAAKD,cAAc;AAE3C,OAAIV,SACFA,UAASS,WAAW;;AAEvBN,IAAA,KAAAH;AAAAG,IAAA,KAAAI;AAAAJ,IAAA,KAAAK;OAAAA,MAAAL,EAAA;AAIHP,kBAAiBG,YAZOS,IAYsBH,eAAeH,QAAQ;CAAA,IAAAW;AAAA,KAAAV,EAAA,OAAAI,0BAAA;AAE9DM,OAAA,EAAAN,0BAA4B;AAAAJ,IAAA,KAAAI;AAAAJ,IAAA,KAAAU;OAAAA,MAAAV,EAAA;AAAA,QAA5BU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-scrollytelling/framer-motion",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "@hsunpei",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://github.com/hsunpei/react-scrollytelling#readme",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.mjs",
|
|
13
13
|
"types": "dist/index.d.mts",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"files": [
|
|
@@ -17,14 +17,8 @@
|
|
|
17
17
|
],
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"default": "./dist/index.mjs"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./dist/index.d.cts",
|
|
26
|
-
"default": "./dist/index.cjs"
|
|
27
|
-
}
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
28
22
|
}
|
|
29
23
|
},
|
|
30
24
|
"repository": {
|
package/dist/index.cjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let react_compiler_runtime = require("react/compiler-runtime");
|
|
3
|
-
let react = require("react");
|
|
4
|
-
let _react_scrollytelling_grouped = require("@react-scrollytelling/grouped");
|
|
5
|
-
let motion_react = require("motion/react");
|
|
6
|
-
let _react_scrollytelling_core = require("@react-scrollytelling/core");
|
|
7
|
-
|
|
8
|
-
//#region src/hooks/useActiveSectionMotionValue.ts
|
|
9
|
-
/**
|
|
10
|
-
* Watches for all tracked sections to find the section closet to the bottom of the viewport
|
|
11
|
-
* through ScrollytellingProvider.
|
|
12
|
-
* It invokes the onActiveSectionChange when the active section changes.
|
|
13
|
-
* Returns the Motion value of the section scroll.
|
|
14
|
-
* @param onActiveSectionChange - The callback needs to be memoized
|
|
15
|
-
* @returns The trackingId of the active section and the Motion value of the section scroll
|
|
16
|
-
*/
|
|
17
|
-
function useActiveSectionMotionValue(onActiveSectionChange) {
|
|
18
|
-
const $ = (0, react_compiler_runtime.c)(6);
|
|
19
|
-
const scrolledRatioMotionValue = (0, motion_react.useMotionValue)(0);
|
|
20
|
-
const [trackingId, setTrackingId] = (0, react.useState)(null);
|
|
21
|
-
let t0;
|
|
22
|
-
if ($[0] !== onActiveSectionChange || $[1] !== scrolledRatioMotionValue) {
|
|
23
|
-
t0 = (scrollInfo) => {
|
|
24
|
-
const { trackingId: id, scrolledRatio } = scrollInfo;
|
|
25
|
-
setTrackingId(id);
|
|
26
|
-
scrolledRatioMotionValue.set(scrolledRatio);
|
|
27
|
-
if (onActiveSectionChange) onActiveSectionChange(scrollInfo);
|
|
28
|
-
};
|
|
29
|
-
$[0] = onActiveSectionChange;
|
|
30
|
-
$[1] = scrolledRatioMotionValue;
|
|
31
|
-
$[2] = t0;
|
|
32
|
-
} else t0 = $[2];
|
|
33
|
-
(0, _react_scrollytelling_grouped.useActiveSection)(t0);
|
|
34
|
-
let t1;
|
|
35
|
-
if ($[3] !== scrolledRatioMotionValue || $[4] !== trackingId) {
|
|
36
|
-
t1 = {
|
|
37
|
-
trackingId,
|
|
38
|
-
scrolledRatioMotionValue
|
|
39
|
-
};
|
|
40
|
-
$[3] = scrolledRatioMotionValue;
|
|
41
|
-
$[4] = trackingId;
|
|
42
|
-
$[5] = t1;
|
|
43
|
-
} else t1 = $[5];
|
|
44
|
-
return t1;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/hooks/useSectionScrollMotionValue.ts
|
|
49
|
-
/**
|
|
50
|
-
* Get the Motion value of the section scroll
|
|
51
|
-
* @param sectionRef - The reference to the section element
|
|
52
|
-
* @param shouldObserve - Whether the underlying IntersectionObserver should be active
|
|
53
|
-
* @param onScroll - The callback to track the scroll ratio
|
|
54
|
-
*/
|
|
55
|
-
function useSectionScrollMotionValue(sectionRef, onScroll, t0, options) {
|
|
56
|
-
const $ = (0, react_compiler_runtime.c)(5);
|
|
57
|
-
const shouldObserve = t0 === void 0 ? true : t0;
|
|
58
|
-
const scrolledRatioMotionValue = (0, motion_react.useMotionValue)(0);
|
|
59
|
-
let t1;
|
|
60
|
-
if ($[0] !== onScroll || $[1] !== scrolledRatioMotionValue) {
|
|
61
|
-
t1 = (scrollInfo) => {
|
|
62
|
-
const { scrolledRatio } = scrollInfo;
|
|
63
|
-
scrolledRatioMotionValue.set(scrolledRatio);
|
|
64
|
-
if (onScroll) onScroll(scrollInfo);
|
|
65
|
-
};
|
|
66
|
-
$[0] = onScroll;
|
|
67
|
-
$[1] = scrolledRatioMotionValue;
|
|
68
|
-
$[2] = t1;
|
|
69
|
-
} else t1 = $[2];
|
|
70
|
-
(0, _react_scrollytelling_core.useSectionScroll)(sectionRef, t1, shouldObserve, options);
|
|
71
|
-
let t2;
|
|
72
|
-
if ($[3] !== scrolledRatioMotionValue) {
|
|
73
|
-
t2 = { scrolledRatioMotionValue };
|
|
74
|
-
$[3] = scrolledRatioMotionValue;
|
|
75
|
-
$[4] = t2;
|
|
76
|
-
} else t2 = $[4];
|
|
77
|
-
return t2;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
exports.useActiveSectionMotionValue = useActiveSectionMotionValue;
|
|
82
|
-
exports.useSectionScrollMotionValue = useSectionScrollMotionValue;
|
package/dist/index.d.cts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as motion_dist_react0 from "motion/dist/react";
|
|
2
|
-
import { ActiveSectionObserver } from "@react-scrollytelling/grouped";
|
|
3
|
-
import { IntersectionObserverOptions, SectionScrollInfo } from "@react-scrollytelling/core";
|
|
4
|
-
|
|
5
|
-
//#region src/hooks/useActiveSectionMotionValue.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Watches for all tracked sections to find the section closet to the bottom of the viewport
|
|
8
|
-
* through ScrollytellingProvider.
|
|
9
|
-
* It invokes the onActiveSectionChange when the active section changes.
|
|
10
|
-
* Returns the Motion value of the section scroll.
|
|
11
|
-
* @param onActiveSectionChange - The callback needs to be memoized
|
|
12
|
-
* @returns The trackingId of the active section and the Motion value of the section scroll
|
|
13
|
-
*/
|
|
14
|
-
declare function useActiveSectionMotionValue(onActiveSectionChange?: ActiveSectionObserver): {
|
|
15
|
-
trackingId: string | null;
|
|
16
|
-
scrolledRatioMotionValue: motion_dist_react0.MotionValue<number>;
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/hooks/useSectionScrollMotionValue.d.ts
|
|
20
|
-
/**
|
|
21
|
-
* Get the Motion value of the section scroll
|
|
22
|
-
* @param sectionRef - The reference to the section element
|
|
23
|
-
* @param shouldObserve - Whether the underlying IntersectionObserver should be active
|
|
24
|
-
* @param onScroll - The callback to track the scroll ratio
|
|
25
|
-
*/
|
|
26
|
-
declare function useSectionScrollMotionValue(sectionRef: React.RefObject<Element>, onScroll?: (scrollInfo: SectionScrollInfo) => void, shouldObserve?: boolean, options?: IntersectionObserverOptions): {
|
|
27
|
-
scrolledRatioMotionValue: motion_dist_react0.MotionValue<number>;
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
export { useActiveSectionMotionValue, useSectionScrollMotionValue };
|
|
31
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/hooks/useActiveSectionMotionValue.ts","../src/hooks/useSectionScrollMotionValue.ts"],"mappings":";;;;;;;;;AAiBA;;;;iBAAgB,2BAAA,CACd,qBAAA,GAAwB,qBAAA;;4BAAqB,kBAAA,CAAA,WAAA;AAAA;;;;;;;AAD/C;;iBCFgB,2BAAA,CACd,UAAA,EAAY,KAAA,CAAM,SAAA,CAAU,OAAA,GAC5B,QAAA,IAAY,UAAA,EAAY,iBAAA,WACxB,aAAA,YACA,OAAA,GAAU,2BAAA;4BAA2B,kBAAA,CAAA,WAAA;AAAA"}
|