framer-motion 12.23.1 → 12.23.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/dist/cjs/client.js +1 -1
- package/dist/cjs/{create-C-c1JfhA.js → create-Ch9BUY4E.js} +3 -3
- package/dist/cjs/index.js +35 -13
- package/dist/cjs/m.js +2 -2
- package/dist/es/components/Reorder/Group.mjs +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -1
- package/dist/es/motion/index.mjs +2 -2
- package/dist/es/value/use-scroll.mjs +35 -13
- package/dist/framer-motion.dev.js +48 -26
- package/dist/framer-motion.js +1 -1
- package/dist/types/index.d.ts +1 -2
- package/package.json +4 -4
package/dist/cjs/client.js
CHANGED
|
@@ -4827,7 +4827,7 @@ class VisualElementDragControls {
|
|
|
4827
4827
|
if (!constraints || !isRefObject(constraints))
|
|
4828
4828
|
return false;
|
|
4829
4829
|
const constraintsElement = constraints.current;
|
|
4830
|
-
motionUtils.invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
|
4830
|
+
motionUtils.invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.", "drag-constraints-ref");
|
|
4831
4831
|
const { projection } = this.visualElement;
|
|
4832
4832
|
// TODO
|
|
4833
4833
|
if (!projection || !projection.layout)
|
|
@@ -5752,8 +5752,8 @@ function useStrictMode(configAndProps, preloadedFeatures) {
|
|
|
5752
5752
|
isStrict) {
|
|
5753
5753
|
const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
|
|
5754
5754
|
configAndProps.ignoreStrict
|
|
5755
|
-
? motionUtils.warning(false, strictMessage)
|
|
5756
|
-
: motionUtils.invariant(false, strictMessage);
|
|
5755
|
+
? motionUtils.warning(false, strictMessage, "lazy-strict-mode")
|
|
5756
|
+
: motionUtils.invariant(false, strictMessage, "lazy-strict-mode");
|
|
5757
5757
|
}
|
|
5758
5758
|
}
|
|
5759
5759
|
function getProjectionFunctionality(props) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var create = require('./create-
|
|
7
|
+
var create = require('./create-Ch9BUY4E.js');
|
|
8
8
|
var motionDom = require('motion-dom');
|
|
9
9
|
var motionUtils = require('motion-utils');
|
|
10
10
|
|
|
@@ -571,7 +571,7 @@ function ReorderGroupComponent({ children, as = "ul", axis = "y", onReorder, val
|
|
|
571
571
|
const Component = create.useConstant(() => motion[as]);
|
|
572
572
|
const order = [];
|
|
573
573
|
const isReordering = React.useRef(false);
|
|
574
|
-
motionUtils.invariant(Boolean(values), "Reorder.Group must be provided a values prop");
|
|
574
|
+
motionUtils.invariant(Boolean(values), "Reorder.Group must be provided a values prop", "reorder-values");
|
|
575
575
|
const context = {
|
|
576
576
|
axis,
|
|
577
577
|
registerItem: (value, layout) => {
|
|
@@ -1852,24 +1852,23 @@ function useMotionValueEvent(value, event, callback) {
|
|
|
1852
1852
|
React.useInsertionEffect(() => value.on(event, callback), [value, event, callback]);
|
|
1853
1853
|
}
|
|
1854
1854
|
|
|
1855
|
-
function refWarning(name, ref) {
|
|
1856
|
-
motionUtils.warning(Boolean(!ref || ref.current), `You have defined a ${name} options but the provided ref is not yet hydrated, probably because it's defined higher up the tree. Try calling useScroll() in the same component as the ref, or setting its \`layoutEffect: false\` option.`);
|
|
1857
|
-
}
|
|
1858
1855
|
const createScrollMotionValues = () => ({
|
|
1859
1856
|
scrollX: motionDom.motionValue(0),
|
|
1860
1857
|
scrollY: motionDom.motionValue(0),
|
|
1861
1858
|
scrollXProgress: motionDom.motionValue(0),
|
|
1862
1859
|
scrollYProgress: motionDom.motionValue(0),
|
|
1863
1860
|
});
|
|
1864
|
-
|
|
1861
|
+
const isRefPending = (ref) => {
|
|
1862
|
+
if (!ref)
|
|
1863
|
+
return false;
|
|
1864
|
+
return !ref.current;
|
|
1865
|
+
};
|
|
1866
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
1865
1867
|
const values = create.useConstant(createScrollMotionValues);
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
refWarning("target", target);
|
|
1871
|
-
refWarning("container", container);
|
|
1872
|
-
return scroll((_progress, { x, y, }) => {
|
|
1868
|
+
const scrollAnimation = React.useRef(null);
|
|
1869
|
+
const needsStart = React.useRef(false);
|
|
1870
|
+
const start = React.useCallback(() => {
|
|
1871
|
+
scrollAnimation.current = scroll((_progress, { x, y, }) => {
|
|
1873
1872
|
values.scrollX.set(x.current);
|
|
1874
1873
|
values.scrollXProgress.set(x.progress);
|
|
1875
1874
|
values.scrollY.set(y.current);
|
|
@@ -1879,7 +1878,30 @@ function useScroll({ container, target, layoutEffect = true, ...options } = {})
|
|
|
1879
1878
|
container: container?.current || undefined,
|
|
1880
1879
|
target: target?.current || undefined,
|
|
1881
1880
|
});
|
|
1881
|
+
return () => {
|
|
1882
|
+
scrollAnimation.current?.();
|
|
1883
|
+
};
|
|
1882
1884
|
}, [container, target, JSON.stringify(options.offset)]);
|
|
1885
|
+
create.useIsomorphicLayoutEffect(() => {
|
|
1886
|
+
needsStart.current = false;
|
|
1887
|
+
if (isRefPending(container) || isRefPending(target)) {
|
|
1888
|
+
needsStart.current = true;
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1891
|
+
else {
|
|
1892
|
+
return start();
|
|
1893
|
+
}
|
|
1894
|
+
}, [start]);
|
|
1895
|
+
React.useEffect(() => {
|
|
1896
|
+
if (needsStart.current) {
|
|
1897
|
+
motionUtils.invariant(!isRefPending(container), "Container ref is defined but not hydrated", "use-scroll-ref");
|
|
1898
|
+
motionUtils.invariant(!isRefPending(target), "Target ref is defined but not hydrated", "use-scroll-ref");
|
|
1899
|
+
return start();
|
|
1900
|
+
}
|
|
1901
|
+
else {
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
}, [start]);
|
|
1883
1905
|
return values;
|
|
1884
1906
|
}
|
|
1885
1907
|
|
package/dist/cjs/m.js
CHANGED
|
@@ -364,8 +364,8 @@ function useStrictMode(configAndProps, preloadedFeatures) {
|
|
|
364
364
|
isStrict) {
|
|
365
365
|
const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
|
|
366
366
|
configAndProps.ignoreStrict
|
|
367
|
-
? motionUtils.warning(false, strictMessage)
|
|
368
|
-
: motionUtils.invariant(false, strictMessage);
|
|
367
|
+
? motionUtils.warning(false, strictMessage, "lazy-strict-mode")
|
|
368
|
+
: motionUtils.invariant(false, strictMessage, "lazy-strict-mode");
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
function getProjectionFunctionality(props) {
|
|
@@ -11,7 +11,7 @@ function ReorderGroupComponent({ children, as = "ul", axis = "y", onReorder, val
|
|
|
11
11
|
const Component = useConstant(() => motion[as]);
|
|
12
12
|
const order = [];
|
|
13
13
|
const isReordering = useRef(false);
|
|
14
|
-
invariant(Boolean(values), "Reorder.Group must be provided a values prop");
|
|
14
|
+
invariant(Boolean(values), "Reorder.Group must be provided a values prop", "reorder-values");
|
|
15
15
|
const context = {
|
|
16
16
|
axis,
|
|
17
17
|
registerItem: (value, layout) => {
|
|
@@ -251,7 +251,7 @@ class VisualElementDragControls {
|
|
|
251
251
|
if (!constraints || !isRefObject(constraints))
|
|
252
252
|
return false;
|
|
253
253
|
const constraintsElement = constraints.current;
|
|
254
|
-
invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
|
254
|
+
invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.", "drag-constraints-ref");
|
|
255
255
|
const { projection } = this.visualElement;
|
|
256
256
|
// TODO
|
|
257
257
|
if (!projection || !projection.layout)
|
package/dist/es/motion/index.mjs
CHANGED
|
@@ -81,8 +81,8 @@ function useStrictMode(configAndProps, preloadedFeatures) {
|
|
|
81
81
|
isStrict) {
|
|
82
82
|
const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
|
|
83
83
|
configAndProps.ignoreStrict
|
|
84
|
-
? warning(false, strictMessage)
|
|
85
|
-
: invariant(false, strictMessage);
|
|
84
|
+
? warning(false, strictMessage, "lazy-strict-mode")
|
|
85
|
+
: invariant(false, strictMessage, "lazy-strict-mode");
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
function getProjectionFunctionality(props) {
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import { motionValue } from 'motion-dom';
|
|
2
|
-
import {
|
|
3
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { invariant } from 'motion-utils';
|
|
3
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
4
4
|
import { scroll } from '../render/dom/scroll/index.mjs';
|
|
5
5
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
6
6
|
import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
|
|
7
7
|
|
|
8
|
-
function refWarning(name, ref) {
|
|
9
|
-
warning(Boolean(!ref || ref.current), `You have defined a ${name} options but the provided ref is not yet hydrated, probably because it's defined higher up the tree. Try calling useScroll() in the same component as the ref, or setting its \`layoutEffect: false\` option.`);
|
|
10
|
-
}
|
|
11
8
|
const createScrollMotionValues = () => ({
|
|
12
9
|
scrollX: motionValue(0),
|
|
13
10
|
scrollY: motionValue(0),
|
|
14
11
|
scrollXProgress: motionValue(0),
|
|
15
12
|
scrollYProgress: motionValue(0),
|
|
16
13
|
});
|
|
17
|
-
|
|
14
|
+
const isRefPending = (ref) => {
|
|
15
|
+
if (!ref)
|
|
16
|
+
return false;
|
|
17
|
+
return !ref.current;
|
|
18
|
+
};
|
|
19
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
18
20
|
const values = useConstant(createScrollMotionValues);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
refWarning("target", target);
|
|
24
|
-
refWarning("container", container);
|
|
25
|
-
return scroll((_progress, { x, y, }) => {
|
|
21
|
+
const scrollAnimation = useRef(null);
|
|
22
|
+
const needsStart = useRef(false);
|
|
23
|
+
const start = useCallback(() => {
|
|
24
|
+
scrollAnimation.current = scroll((_progress, { x, y, }) => {
|
|
26
25
|
values.scrollX.set(x.current);
|
|
27
26
|
values.scrollXProgress.set(x.progress);
|
|
28
27
|
values.scrollY.set(y.current);
|
|
@@ -32,7 +31,30 @@ function useScroll({ container, target, layoutEffect = true, ...options } = {})
|
|
|
32
31
|
container: container?.current || undefined,
|
|
33
32
|
target: target?.current || undefined,
|
|
34
33
|
});
|
|
34
|
+
return () => {
|
|
35
|
+
scrollAnimation.current?.();
|
|
36
|
+
};
|
|
35
37
|
}, [container, target, JSON.stringify(options.offset)]);
|
|
38
|
+
useIsomorphicLayoutEffect(() => {
|
|
39
|
+
needsStart.current = false;
|
|
40
|
+
if (isRefPending(container) || isRefPending(target)) {
|
|
41
|
+
needsStart.current = true;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return start();
|
|
46
|
+
}
|
|
47
|
+
}, [start]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (needsStart.current) {
|
|
50
|
+
invariant(!isRefPending(container), "Container ref is defined but not hydrated", "use-scroll-ref");
|
|
51
|
+
invariant(!isRefPending(target), "Target ref is defined but not hydrated", "use-scroll-ref");
|
|
52
|
+
return start();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}, [start]);
|
|
36
58
|
return values;
|
|
37
59
|
}
|
|
38
60
|
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
{
|
|
117
117
|
const formatMessage = (message, errorCode) => {
|
|
118
118
|
return errorCode
|
|
119
|
-
? `${message}. For more information and steps for solving, visit https://motion.dev/
|
|
119
|
+
? `${message}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${errorCode}`
|
|
120
120
|
: message;
|
|
121
121
|
};
|
|
122
122
|
exports.warning = (check, message, errorCode) => {
|
|
@@ -375,13 +375,13 @@
|
|
|
375
375
|
const easingDefinitionToFunction = (definition) => {
|
|
376
376
|
if (isBezierDefinition(definition)) {
|
|
377
377
|
// If cubic bezier definition, create bezier curve
|
|
378
|
-
exports.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values
|
|
378
|
+
exports.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`, "cubic-bezier-length");
|
|
379
379
|
const [x1, y1, x2, y2] = definition;
|
|
380
380
|
return cubicBezier(x1, y1, x2, y2);
|
|
381
381
|
}
|
|
382
382
|
else if (isValidEasing(definition)) {
|
|
383
383
|
// Else lookup from table
|
|
384
|
-
exports.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'
|
|
384
|
+
exports.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`, "invalid-easing-type");
|
|
385
385
|
return easingLookup[definition];
|
|
386
386
|
}
|
|
387
387
|
return definition;
|
|
@@ -941,7 +941,7 @@
|
|
|
941
941
|
const getColorType = (v) => colorTypes.find((type) => type.test(v));
|
|
942
942
|
function asRGBA(color) {
|
|
943
943
|
const type = getColorType(color);
|
|
944
|
-
exports.warning(Boolean(type), `'${color}' is not an animatable color. Use the equivalent color code instead
|
|
944
|
+
exports.warning(Boolean(type), `'${color}' is not an animatable color. Use the equivalent color code instead.`, "color-not-animatable");
|
|
945
945
|
if (!Boolean(type))
|
|
946
946
|
return false;
|
|
947
947
|
let model = type.parse(color);
|
|
@@ -1059,7 +1059,7 @@
|
|
|
1059
1059
|
return pipe(mixArray(matchOrder(originStats, targetStats), targetStats.values), template);
|
|
1060
1060
|
}
|
|
1061
1061
|
else {
|
|
1062
|
-
exports.warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition
|
|
1062
|
+
exports.warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`, "complex-values-different");
|
|
1063
1063
|
return mixImmediate(origin, target);
|
|
1064
1064
|
}
|
|
1065
1065
|
};
|
|
@@ -1165,7 +1165,7 @@
|
|
|
1165
1165
|
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
|
|
1166
1166
|
let envelope;
|
|
1167
1167
|
let derivative;
|
|
1168
|
-
exports.warning(duration <= secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less");
|
|
1168
|
+
exports.warning(duration <= secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less", "spring-duration-limit");
|
|
1169
1169
|
let dampingRatio = 1 - bounce;
|
|
1170
1170
|
/**
|
|
1171
1171
|
* Restrict dampingRatio and duration to within acceptable ranges.
|
|
@@ -1525,7 +1525,7 @@
|
|
|
1525
1525
|
*/
|
|
1526
1526
|
function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
|
|
1527
1527
|
const inputLength = input.length;
|
|
1528
|
-
exports.invariant(inputLength === output.length, "Both input and output ranges must be the same length");
|
|
1528
|
+
exports.invariant(inputLength === output.length, "Both input and output ranges must be the same length", "range-length");
|
|
1529
1529
|
/**
|
|
1530
1530
|
* If we're only provided a single input, we can just make a function
|
|
1531
1531
|
* that returns the output.
|
|
@@ -2418,7 +2418,7 @@
|
|
|
2418
2418
|
this.isPseudoElement = Boolean(pseudoElement);
|
|
2419
2419
|
this.allowFlatten = allowFlatten;
|
|
2420
2420
|
this.options = options;
|
|
2421
|
-
exports.invariant(typeof options.type !== "string", `
|
|
2421
|
+
exports.invariant(typeof options.type !== "string", `Mini animate() doesn't support "type" as a string.`, "mini-spring");
|
|
2422
2422
|
const transition = applyGeneratorOptions(options);
|
|
2423
2423
|
this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
|
|
2424
2424
|
if (transition.autoplay === false) {
|
|
@@ -2634,7 +2634,7 @@
|
|
|
2634
2634
|
* @internal
|
|
2635
2635
|
*/
|
|
2636
2636
|
const isAnimatable = (value, name) => {
|
|
2637
|
-
// If the list of keys
|
|
2637
|
+
// If the list of keys that might be non-animatable grows, replace with Set
|
|
2638
2638
|
if (name === "zIndex")
|
|
2639
2639
|
return false;
|
|
2640
2640
|
// If it's a number or a keyframes array, we can animate it. We might at some point
|
|
@@ -2679,7 +2679,7 @@
|
|
|
2679
2679
|
const targetKeyframe = keyframes[keyframes.length - 1];
|
|
2680
2680
|
const isOriginAnimatable = isAnimatable(originKeyframe, name);
|
|
2681
2681
|
const isTargetAnimatable = isAnimatable(targetKeyframe, name);
|
|
2682
|
-
exports.warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". ${originKeyframe} is not an animatable value -
|
|
2682
|
+
exports.warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". "${isOriginAnimatable ? targetKeyframe : originKeyframe}" is not an animatable value.`, "value-not-animatable");
|
|
2683
2683
|
// Always skip if any of these are true
|
|
2684
2684
|
if (!isOriginAnimatable || !isTargetAnimatable) {
|
|
2685
2685
|
return false;
|
|
@@ -3009,7 +3009,7 @@
|
|
|
3009
3009
|
}
|
|
3010
3010
|
const maxDepth = 4;
|
|
3011
3011
|
function getVariableValue(current, element, depth = 1) {
|
|
3012
|
-
exports.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency
|
|
3012
|
+
exports.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
|
|
3013
3013
|
const [token, fallback] = parseCSSVariable(current);
|
|
3014
3014
|
// No CSS variable detected
|
|
3015
3015
|
if (!token)
|
|
@@ -10330,7 +10330,7 @@
|
|
|
10330
10330
|
if (!constraints || !isRefObject(constraints))
|
|
10331
10331
|
return false;
|
|
10332
10332
|
const constraintsElement = constraints.current;
|
|
10333
|
-
exports.invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
|
10333
|
+
exports.invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.", "drag-constraints-ref");
|
|
10334
10334
|
const { projection } = this.visualElement;
|
|
10335
10335
|
// TODO
|
|
10336
10336
|
if (!projection || !projection.layout)
|
|
@@ -11254,8 +11254,8 @@
|
|
|
11254
11254
|
isStrict) {
|
|
11255
11255
|
const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
|
|
11256
11256
|
configAndProps.ignoreStrict
|
|
11257
|
-
? exports.warning(false, strictMessage)
|
|
11258
|
-
: exports.invariant(false, strictMessage);
|
|
11257
|
+
? exports.warning(false, strictMessage, "lazy-strict-mode")
|
|
11258
|
+
: exports.invariant(false, strictMessage, "lazy-strict-mode");
|
|
11259
11259
|
}
|
|
11260
11260
|
}
|
|
11261
11261
|
function getProjectionFunctionality(props) {
|
|
@@ -11741,7 +11741,7 @@
|
|
|
11741
11741
|
const Component = useConstant(() => motion[as]);
|
|
11742
11742
|
const order = [];
|
|
11743
11743
|
const isReordering = React$1.useRef(false);
|
|
11744
|
-
exports.invariant(Boolean(values), "Reorder.Group must be provided a values prop");
|
|
11744
|
+
exports.invariant(Boolean(values), "Reorder.Group must be provided a values prop", "reorder-values");
|
|
11745
11745
|
const context = {
|
|
11746
11746
|
axis,
|
|
11747
11747
|
registerItem: (value, layout) => {
|
|
@@ -13022,24 +13022,23 @@
|
|
|
13022
13022
|
React$1.useInsertionEffect(() => value.on(event, callback), [value, event, callback]);
|
|
13023
13023
|
}
|
|
13024
13024
|
|
|
13025
|
-
function refWarning(name, ref) {
|
|
13026
|
-
exports.warning(Boolean(!ref || ref.current), `You have defined a ${name} options but the provided ref is not yet hydrated, probably because it's defined higher up the tree. Try calling useScroll() in the same component as the ref, or setting its \`layoutEffect: false\` option.`);
|
|
13027
|
-
}
|
|
13028
13025
|
const createScrollMotionValues = () => ({
|
|
13029
13026
|
scrollX: motionValue(0),
|
|
13030
13027
|
scrollY: motionValue(0),
|
|
13031
13028
|
scrollXProgress: motionValue(0),
|
|
13032
13029
|
scrollYProgress: motionValue(0),
|
|
13033
13030
|
});
|
|
13034
|
-
|
|
13031
|
+
const isRefPending = (ref) => {
|
|
13032
|
+
if (!ref)
|
|
13033
|
+
return false;
|
|
13034
|
+
return !ref.current;
|
|
13035
|
+
};
|
|
13036
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
13035
13037
|
const values = useConstant(createScrollMotionValues);
|
|
13036
|
-
const
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
refWarning("target", target);
|
|
13041
|
-
refWarning("container", container);
|
|
13042
|
-
return scroll((_progress, { x, y, }) => {
|
|
13038
|
+
const scrollAnimation = React$1.useRef(null);
|
|
13039
|
+
const needsStart = React$1.useRef(false);
|
|
13040
|
+
const start = React$1.useCallback(() => {
|
|
13041
|
+
scrollAnimation.current = scroll((_progress, { x, y, }) => {
|
|
13043
13042
|
values.scrollX.set(x.current);
|
|
13044
13043
|
values.scrollXProgress.set(x.progress);
|
|
13045
13044
|
values.scrollY.set(y.current);
|
|
@@ -13049,7 +13048,30 @@
|
|
|
13049
13048
|
container: container?.current || undefined,
|
|
13050
13049
|
target: target?.current || undefined,
|
|
13051
13050
|
});
|
|
13051
|
+
return () => {
|
|
13052
|
+
scrollAnimation.current?.();
|
|
13053
|
+
};
|
|
13052
13054
|
}, [container, target, JSON.stringify(options.offset)]);
|
|
13055
|
+
useIsomorphicLayoutEffect(() => {
|
|
13056
|
+
needsStart.current = false;
|
|
13057
|
+
if (isRefPending(container) || isRefPending(target)) {
|
|
13058
|
+
needsStart.current = true;
|
|
13059
|
+
return;
|
|
13060
|
+
}
|
|
13061
|
+
else {
|
|
13062
|
+
return start();
|
|
13063
|
+
}
|
|
13064
|
+
}, [start]);
|
|
13065
|
+
React$1.useEffect(() => {
|
|
13066
|
+
if (needsStart.current) {
|
|
13067
|
+
exports.invariant(!isRefPending(container), "Container ref is defined but not hydrated", "use-scroll-ref");
|
|
13068
|
+
exports.invariant(!isRefPending(target), "Target ref is defined but not hydrated", "use-scroll-ref");
|
|
13069
|
+
return start();
|
|
13070
|
+
}
|
|
13071
|
+
else {
|
|
13072
|
+
return;
|
|
13073
|
+
}
|
|
13074
|
+
}, [start]);
|
|
13053
13075
|
return values;
|
|
13054
13076
|
}
|
|
13055
13077
|
|