framer-motion 9.1.0 → 9.1.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/README.md +15 -15
- package/dist/cjs/index.js +605 -116
- package/dist/es/animation/hooks/animation-controls.mjs +1 -1
- package/dist/es/animation/index.mjs +1 -1
- package/dist/es/animation/legacy-popmotion/find-spring.mjs +1 -1
- package/dist/es/animation/legacy-popmotion/keyframes.mjs +3 -8
- package/dist/es/animation/utils/easing.mjs +1 -1
- package/dist/es/components/AnimateSharedLayout.mjs +2 -2
- package/dist/es/components/Reorder/Group.mjs +1 -1
- package/dist/es/components/Reorder/Item.mjs +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +3 -4
- package/dist/es/gestures/focus.mjs +2 -3
- package/dist/es/gestures/hover.mjs +1 -2
- package/dist/es/gestures/press.mjs +2 -3
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animation/exit.mjs +1 -2
- package/dist/es/motion/features/viewport/index.mjs +2 -3
- package/dist/es/render/VisualElement.mjs +3 -4
- package/dist/es/render/dom/resize/handle-element.mjs +64 -0
- package/dist/es/render/dom/resize/handle-window.mjs +30 -0
- package/dist/es/render/dom/resize/index.mjs +8 -0
- package/dist/es/render/dom/scroll/index.mjs +74 -0
- package/dist/es/render/dom/scroll/info.mjs +56 -0
- package/dist/es/render/dom/scroll/offsets/edge.mjs +45 -0
- package/dist/es/render/dom/scroll/offsets/index.mjs +54 -0
- package/dist/es/render/dom/scroll/offsets/inset.mjs +25 -0
- package/dist/es/render/dom/scroll/offsets/offset.mjs +35 -0
- package/dist/es/render/dom/scroll/offsets/presets.mjs +20 -0
- package/dist/es/render/dom/scroll/on-scroll-handler.mjs +38 -0
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
- package/dist/es/render/dom/utils/is-css-variable.mjs +4 -7
- package/dist/es/render/dom/utils/resolve-element.mjs +21 -0
- package/dist/es/render/dom/utils/unit-conversion.mjs +2 -11
- package/dist/es/render/dom/viewport/index.mjs +52 -0
- package/dist/es/render/html/HTMLVisualElement.mjs +2 -2
- package/dist/es/render/html/utils/build-styles.mjs +2 -2
- package/dist/es/render/utils/animation-state.mjs +16 -21
- package/dist/es/render/utils/is-controlling-variants.mjs +1 -10
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/render/utils/variant-props.mjs +12 -0
- package/dist/es/utils/errors.mjs +18 -0
- package/dist/es/utils/interpolate.mjs +1 -1
- package/dist/es/utils/mix-color.mjs +1 -1
- package/dist/es/utils/mix-complex.mjs +1 -1
- package/dist/es/utils/offsets/default.mjs +9 -0
- package/dist/es/utils/offsets/fill.mjs +12 -0
- package/dist/es/utils/offsets/time.mjs +5 -0
- package/dist/es/utils/use-in-view.mjs +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/use-inverted-scale.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +2 -2
- package/dist/es/value/use-will-change/index.mjs +2 -2
- package/dist/framer-motion.dev.js +238 -370
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/projection.dev.js +53 -78
- package/dist/size-rollup-dom-animation-assets.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +1 -1
- package/package.json +9 -11
package/dist/cjs/index.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var heyListen = require('hey-listen');
|
|
7
|
-
var dom = require('@motionone/dom');
|
|
8
6
|
|
|
9
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
8
|
|
|
@@ -152,19 +150,20 @@ function isAnimationControls(v) {
|
|
|
152
150
|
return typeof v === "object" && typeof v.start === "function";
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
const
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"whileHover"
|
|
160
|
-
"
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"whileInView",
|
|
153
|
+
const variantPriorityOrder$1 = [
|
|
154
|
+
"animate" /* AnimationType.Animate */,
|
|
155
|
+
"whileInView" /* AnimationType.InView */,
|
|
156
|
+
"whileFocus" /* AnimationType.Focus */,
|
|
157
|
+
"whileHover" /* AnimationType.Hover */,
|
|
158
|
+
"whileTap" /* AnimationType.Tap */,
|
|
159
|
+
"whileDrag" /* AnimationType.Drag */,
|
|
160
|
+
"exit" /* AnimationType.Exit */,
|
|
164
161
|
];
|
|
162
|
+
const variantProps = ["initial", ...variantPriorityOrder$1];
|
|
163
|
+
|
|
165
164
|
function isControllingVariants(props) {
|
|
166
165
|
return (isAnimationControls(props.animate) ||
|
|
167
|
-
variantProps
|
|
166
|
+
variantProps.some((name) => isVariantLabel(props[name])));
|
|
168
167
|
}
|
|
169
168
|
function isVariantNode(props) {
|
|
170
169
|
return Boolean(isControllingVariants(props) || props.variants);
|
|
@@ -540,12 +539,9 @@ function buildTransform(transform, { enableHardwareAcceleration = true, allowTra
|
|
|
540
539
|
return transformString;
|
|
541
540
|
}
|
|
542
541
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
function isCSSVariable$1(key) {
|
|
547
|
-
return key.startsWith("--");
|
|
548
|
-
}
|
|
542
|
+
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
543
|
+
const isCSSVariableName = checkStringStartsWith("--");
|
|
544
|
+
const isCSSVariableToken = checkStringStartsWith("var(--");
|
|
549
545
|
|
|
550
546
|
/**
|
|
551
547
|
* Provided a value and a ValueType, returns the value as that value type.
|
|
@@ -692,7 +688,7 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
692
688
|
/**
|
|
693
689
|
* If this is a CSS variable we don't do any further processing.
|
|
694
690
|
*/
|
|
695
|
-
if (
|
|
691
|
+
if (isCSSVariableName(key)) {
|
|
696
692
|
vars[key] = value;
|
|
697
693
|
continue;
|
|
698
694
|
}
|
|
@@ -1331,17 +1327,6 @@ function addPointerEvent(target, eventName, handler, options) {
|
|
|
1331
1327
|
return addDomEvent(target, eventName, addPointerInfo(handler), options);
|
|
1332
1328
|
}
|
|
1333
1329
|
|
|
1334
|
-
exports.AnimationType = void 0;
|
|
1335
|
-
(function (AnimationType) {
|
|
1336
|
-
AnimationType["Animate"] = "animate";
|
|
1337
|
-
AnimationType["Hover"] = "whileHover";
|
|
1338
|
-
AnimationType["Tap"] = "whileTap";
|
|
1339
|
-
AnimationType["Drag"] = "whileDrag";
|
|
1340
|
-
AnimationType["Focus"] = "whileFocus";
|
|
1341
|
-
AnimationType["InView"] = "whileInView";
|
|
1342
|
-
AnimationType["Exit"] = "exit";
|
|
1343
|
-
})(exports.AnimationType || (exports.AnimationType = {}));
|
|
1344
|
-
|
|
1345
1330
|
/**
|
|
1346
1331
|
* Pipe
|
|
1347
1332
|
* Compose other transformers to run linearily
|
|
@@ -1420,7 +1405,7 @@ function addHoverEvent(node, isActive) {
|
|
|
1420
1405
|
return;
|
|
1421
1406
|
const props = node.getProps();
|
|
1422
1407
|
if (node.animationState && props.whileHover) {
|
|
1423
|
-
node.animationState.setActive(
|
|
1408
|
+
node.animationState.setActive("whileHover" /* AnimationType.Hover */, isActive);
|
|
1424
1409
|
}
|
|
1425
1410
|
if (props[callbackName]) {
|
|
1426
1411
|
props[callbackName](event, info);
|
|
@@ -1458,13 +1443,13 @@ class FocusGesture extends Feature {
|
|
|
1458
1443
|
}
|
|
1459
1444
|
if (!isFocusVisible || !this.node.animationState)
|
|
1460
1445
|
return;
|
|
1461
|
-
this.node.animationState.setActive(
|
|
1446
|
+
this.node.animationState.setActive("whileFocus" /* AnimationType.Focus */, true);
|
|
1462
1447
|
this.isActive = true;
|
|
1463
1448
|
}
|
|
1464
1449
|
onBlur() {
|
|
1465
1450
|
if (!this.isActive || !this.node.animationState)
|
|
1466
1451
|
return;
|
|
1467
|
-
this.node.animationState.setActive(
|
|
1452
|
+
this.node.animationState.setActive("whileFocus" /* AnimationType.Focus */, false);
|
|
1468
1453
|
this.isActive = false;
|
|
1469
1454
|
}
|
|
1470
1455
|
mount() {
|
|
@@ -1560,7 +1545,7 @@ class PressGesture extends Feature {
|
|
|
1560
1545
|
* Ensure we trigger animations before firing event callback
|
|
1561
1546
|
*/
|
|
1562
1547
|
if (whileTap && this.node.animationState) {
|
|
1563
|
-
this.node.animationState.setActive(
|
|
1548
|
+
this.node.animationState.setActive("whileTap" /* AnimationType.Tap */, true);
|
|
1564
1549
|
}
|
|
1565
1550
|
onTapStart && onTapStart(event, info);
|
|
1566
1551
|
}
|
|
@@ -1569,7 +1554,7 @@ class PressGesture extends Feature {
|
|
|
1569
1554
|
this.isPressing = false;
|
|
1570
1555
|
const props = this.node.getProps();
|
|
1571
1556
|
if (props.whileTap && this.node.animationState) {
|
|
1572
|
-
this.node.animationState.setActive(
|
|
1557
|
+
this.node.animationState.setActive("whileTap" /* AnimationType.Tap */, false);
|
|
1573
1558
|
}
|
|
1574
1559
|
return !isDragActive();
|
|
1575
1560
|
}
|
|
@@ -1664,7 +1649,7 @@ class InViewFeature extends Feature {
|
|
|
1664
1649
|
const { onViewportEnter } = this.node.getProps();
|
|
1665
1650
|
onViewportEnter && onViewportEnter(null);
|
|
1666
1651
|
if (this.node.animationState) {
|
|
1667
|
-
this.node.animationState.setActive(
|
|
1652
|
+
this.node.animationState.setActive("whileInView" /* AnimationType.InView */, true);
|
|
1668
1653
|
}
|
|
1669
1654
|
});
|
|
1670
1655
|
}
|
|
@@ -1701,7 +1686,7 @@ class InViewFeature extends Feature {
|
|
|
1701
1686
|
this.hasEnteredView = true;
|
|
1702
1687
|
}
|
|
1703
1688
|
if (this.node.animationState) {
|
|
1704
|
-
this.node.animationState.setActive(
|
|
1689
|
+
this.node.animationState.setActive("whileInView" /* AnimationType.InView */, isIntersecting);
|
|
1705
1690
|
}
|
|
1706
1691
|
/**
|
|
1707
1692
|
* Use the latest committed props rather than the ones in scope
|
|
@@ -1872,7 +1857,7 @@ function createRenderStep(runNextFrame) {
|
|
|
1872
1857
|
return step;
|
|
1873
1858
|
}
|
|
1874
1859
|
|
|
1875
|
-
const maxElapsed = 40;
|
|
1860
|
+
const maxElapsed$1 = 40;
|
|
1876
1861
|
let useDefaultElapsed = true;
|
|
1877
1862
|
let runNextFrame = false;
|
|
1878
1863
|
let isProcessing = false;
|
|
@@ -1909,7 +1894,7 @@ const processFrame = (timestamp) => {
|
|
|
1909
1894
|
runNextFrame = false;
|
|
1910
1895
|
frameData.delta = useDefaultElapsed
|
|
1911
1896
|
? defaultTimestep
|
|
1912
|
-
: Math.max(Math.min(timestamp - frameData.timestamp, maxElapsed), 1);
|
|
1897
|
+
: Math.max(Math.min(timestamp - frameData.timestamp, maxElapsed$1), 1);
|
|
1913
1898
|
frameData.timestamp = timestamp;
|
|
1914
1899
|
isProcessing = true;
|
|
1915
1900
|
stepsOrder.forEach(processStep);
|
|
@@ -2015,7 +2000,7 @@ class MotionValue {
|
|
|
2015
2000
|
* This will be replaced by the build step with the latest version number.
|
|
2016
2001
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2017
2002
|
*/
|
|
2018
|
-
this.version = "9.1.
|
|
2003
|
+
this.version = "9.1.2";
|
|
2019
2004
|
/**
|
|
2020
2005
|
* Duration, in milliseconds, since last updating frame.
|
|
2021
2006
|
*
|
|
@@ -2718,6 +2703,21 @@ function isWillChangeMotionValue(value) {
|
|
|
2718
2703
|
const optimizedAppearDataId = "framerAppearId";
|
|
2719
2704
|
const optimizedAppearDataAttribute = "data-" + camelToDash(optimizedAppearDataId);
|
|
2720
2705
|
|
|
2706
|
+
exports.warning = noop;
|
|
2707
|
+
exports.invariant = noop;
|
|
2708
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2709
|
+
exports.warning = (check, message) => {
|
|
2710
|
+
if (!check && typeof console !== "undefined") {
|
|
2711
|
+
console.warn(message);
|
|
2712
|
+
}
|
|
2713
|
+
};
|
|
2714
|
+
exports.invariant = (check, message) => {
|
|
2715
|
+
if (!check) {
|
|
2716
|
+
throw new Error(message);
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
2721
|
/**
|
|
2722
2722
|
* Converts seconds to milliseconds
|
|
2723
2723
|
*
|
|
@@ -2817,7 +2817,7 @@ const colorTypes = [hex, rgba, hsla];
|
|
|
2817
2817
|
const getColorType = (v) => colorTypes.find((type) => type.test(v));
|
|
2818
2818
|
function asRGBA(color) {
|
|
2819
2819
|
const type = getColorType(color);
|
|
2820
|
-
|
|
2820
|
+
exports.invariant(Boolean(type), `'${color}' is not an animatable color. Use the equivalent color code instead.`);
|
|
2821
2821
|
let model = type.parse(color);
|
|
2822
2822
|
if (type === hsla) {
|
|
2823
2823
|
// TODO Remove this cast - needed since Framer Motion's stricter typing
|
|
@@ -2885,7 +2885,7 @@ const mixComplex = (origin, target) => {
|
|
|
2885
2885
|
return pipe(mixArray(originStats.values, targetStats.values), template);
|
|
2886
2886
|
}
|
|
2887
2887
|
else {
|
|
2888
|
-
|
|
2888
|
+
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.`);
|
|
2889
2889
|
return (p) => `${p > 0 ? target : origin}`;
|
|
2890
2890
|
}
|
|
2891
2891
|
};
|
|
@@ -2963,8 +2963,8 @@ function createMixers(output, ease, customMixer) {
|
|
|
2963
2963
|
*/
|
|
2964
2964
|
function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
|
|
2965
2965
|
const inputLength = input.length;
|
|
2966
|
-
|
|
2967
|
-
|
|
2966
|
+
exports.invariant(inputLength === output.length, "Both input and output ranges must be the same length");
|
|
2967
|
+
exports.invariant(!ease || !Array.isArray(ease) || ease.length === inputLength - 1, "Array of easing functions must be of length `input.length - 1`, as it applies to the transitions **between** the defined values.");
|
|
2968
2968
|
// If input runs highest -> lowest, reverse both arrays
|
|
2969
2969
|
if (input[0] > input[inputLength - 1]) {
|
|
2970
2970
|
input = [...input].reverse();
|
|
@@ -2988,6 +2988,24 @@ function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {})
|
|
|
2988
2988
|
: interpolator;
|
|
2989
2989
|
}
|
|
2990
2990
|
|
|
2991
|
+
function fillOffset(offset, remaining) {
|
|
2992
|
+
const min = offset[offset.length - 1];
|
|
2993
|
+
for (let i = 1; i <= remaining; i++) {
|
|
2994
|
+
const offsetProgress = progress(0, remaining, i);
|
|
2995
|
+
offset.push(mix(min, 1, offsetProgress));
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
function defaultOffset$1(arr) {
|
|
3000
|
+
const offset = [0];
|
|
3001
|
+
fillOffset(offset, arr.length - 1);
|
|
3002
|
+
return offset;
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
function convertOffsetToTimes(offset, duration) {
|
|
3006
|
+
return offset.map((o) => o * duration);
|
|
3007
|
+
}
|
|
3008
|
+
|
|
2991
3009
|
/*
|
|
2992
3010
|
Bezier function generator
|
|
2993
3011
|
This has been modified from Gaëtan Renaudeau's BezierEasing
|
|
@@ -3062,13 +3080,13 @@ const easingLookup = {
|
|
|
3062
3080
|
const easingDefinitionToFunction = (definition) => {
|
|
3063
3081
|
if (Array.isArray(definition)) {
|
|
3064
3082
|
// If cubic bezier definition, create bezier curve
|
|
3065
|
-
|
|
3083
|
+
exports.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`);
|
|
3066
3084
|
const [x1, y1, x2, y2] = definition;
|
|
3067
3085
|
return cubicBezier(x1, y1, x2, y2);
|
|
3068
3086
|
}
|
|
3069
3087
|
else if (typeof definition === "string") {
|
|
3070
3088
|
// Else lookup from table
|
|
3071
|
-
|
|
3089
|
+
exports.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`);
|
|
3072
3090
|
return easingLookup[definition];
|
|
3073
3091
|
}
|
|
3074
3092
|
return definition;
|
|
@@ -3080,13 +3098,6 @@ const isEasingArray = (ease) => {
|
|
|
3080
3098
|
function defaultEasing(values, easing) {
|
|
3081
3099
|
return values.map(() => easing || easeInOut).splice(0, values.length - 1);
|
|
3082
3100
|
}
|
|
3083
|
-
function defaultOffset(values) {
|
|
3084
|
-
const numValues = values.length;
|
|
3085
|
-
return values.map((_value, i) => i !== 0 ? i / (numValues - 1) : 0);
|
|
3086
|
-
}
|
|
3087
|
-
function convertOffsetToTimes(offset, duration) {
|
|
3088
|
-
return offset.map((o) => o * duration);
|
|
3089
|
-
}
|
|
3090
3101
|
function keyframes({ keyframes: keyframeValues, ease = easeInOut, times, duration = 300, }) {
|
|
3091
3102
|
keyframeValues = [...keyframeValues];
|
|
3092
3103
|
/**
|
|
@@ -3112,7 +3123,7 @@ function keyframes({ keyframes: keyframeValues, ease = easeInOut, times, duratio
|
|
|
3112
3123
|
// TODO Maybe we should warn here if there's a length mismatch
|
|
3113
3124
|
times && times.length === keyframeValues.length
|
|
3114
3125
|
? times
|
|
3115
|
-
: defaultOffset(keyframeValues), duration);
|
|
3126
|
+
: defaultOffset$1(keyframeValues), duration);
|
|
3116
3127
|
function createInterpolator() {
|
|
3117
3128
|
return interpolate(absoluteTimes, keyframeValues, {
|
|
3118
3129
|
ease: Array.isArray(easingFunctions)
|
|
@@ -3142,7 +3153,7 @@ const maxDamping = 1;
|
|
|
3142
3153
|
function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, }) {
|
|
3143
3154
|
let envelope;
|
|
3144
3155
|
let derivative;
|
|
3145
|
-
|
|
3156
|
+
exports.warning(duration <= maxDuration * 1000, "Spring duration must be 10 seconds or less");
|
|
3146
3157
|
let dampingRatio = 1 - bounce;
|
|
3147
3158
|
/**
|
|
3148
3159
|
* Restrict dampingRatio and duration to within acceptable ranges.
|
|
@@ -3962,7 +3973,7 @@ const createMotionValueAnimation = (valueName, value, target, transition = {}) =
|
|
|
3962
3973
|
const targetKeyframe = keyframes[keyframes.length - 1];
|
|
3963
3974
|
const isOriginAnimatable = isAnimatable(valueName, originKeyframe);
|
|
3964
3975
|
const isTargetAnimatable = isAnimatable(valueName, targetKeyframe);
|
|
3965
|
-
|
|
3976
|
+
exports.warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${valueName} from "${originKeyframe}" to "${targetKeyframe}". ${originKeyframe} is not an animatable value - to enable this animation set ${originKeyframe} to a value animatable to ${targetKeyframe} via the \`style\` property.`);
|
|
3966
3977
|
let options = {
|
|
3967
3978
|
keyframes,
|
|
3968
3979
|
velocity: value.getVelocity(),
|
|
@@ -4169,13 +4180,13 @@ function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
|
|
|
4169
4180
|
}
|
|
4170
4181
|
|
|
4171
4182
|
const variantPriorityOrder = [
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4183
|
+
"animate" /* AnimationType.Animate */,
|
|
4184
|
+
"whileInView" /* AnimationType.InView */,
|
|
4185
|
+
"whileFocus" /* AnimationType.Focus */,
|
|
4186
|
+
"whileHover" /* AnimationType.Hover */,
|
|
4187
|
+
"whileTap" /* AnimationType.Tap */,
|
|
4188
|
+
"whileDrag" /* AnimationType.Drag */,
|
|
4189
|
+
"exit" /* AnimationType.Exit */,
|
|
4179
4190
|
];
|
|
4180
4191
|
const reversePriorityOrder = [...variantPriorityOrder].reverse();
|
|
4181
4192
|
const numAnimationTypes = variantPriorityOrder.length;
|
|
@@ -4438,16 +4449,12 @@ function createAnimationState(visualElement) {
|
|
|
4438
4449
|
* Change whether a certain animation type is active.
|
|
4439
4450
|
*/
|
|
4440
4451
|
function setActive(type, isActive, options) {
|
|
4452
|
+
var _a;
|
|
4441
4453
|
// If the active state hasn't changed, we can safely do nothing here
|
|
4442
4454
|
if (state[type].isActive === isActive)
|
|
4443
4455
|
return Promise.resolve();
|
|
4444
4456
|
// Propagate active change to children
|
|
4445
|
-
|
|
4446
|
-
visualElement.variantChildren.forEach((child) => {
|
|
4447
|
-
child.animationState &&
|
|
4448
|
-
child.animationState.setActive(type, isActive);
|
|
4449
|
-
});
|
|
4450
|
-
}
|
|
4457
|
+
(_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach((child) => { var _a; return (_a = child.animationState) === null || _a === void 0 ? void 0 : _a.setActive(type, isActive); });
|
|
4451
4458
|
state[type].isActive = isActive;
|
|
4452
4459
|
const animations = animateChanges(options, type);
|
|
4453
4460
|
for (const key in state) {
|
|
@@ -4481,13 +4488,13 @@ function createTypeState(isActive = false) {
|
|
|
4481
4488
|
}
|
|
4482
4489
|
function createState() {
|
|
4483
4490
|
return {
|
|
4484
|
-
[
|
|
4485
|
-
[
|
|
4486
|
-
[
|
|
4487
|
-
[
|
|
4488
|
-
[
|
|
4489
|
-
[
|
|
4490
|
-
[
|
|
4491
|
+
["animate" /* AnimationType.Animate */]: createTypeState(true),
|
|
4492
|
+
["whileInView" /* AnimationType.InView */]: createTypeState(),
|
|
4493
|
+
["whileHover" /* AnimationType.Hover */]: createTypeState(),
|
|
4494
|
+
["whileTap" /* AnimationType.Tap */]: createTypeState(),
|
|
4495
|
+
["whileDrag" /* AnimationType.Drag */]: createTypeState(),
|
|
4496
|
+
["whileFocus" /* AnimationType.Focus */]: createTypeState(),
|
|
4497
|
+
["exit" /* AnimationType.Exit */]: createTypeState(),
|
|
4491
4498
|
};
|
|
4492
4499
|
}
|
|
4493
4500
|
|
|
@@ -4538,7 +4545,7 @@ class ExitAnimationFeature extends Feature {
|
|
|
4538
4545
|
if (!this.node.animationState || isPresent === prevIsPresent) {
|
|
4539
4546
|
return;
|
|
4540
4547
|
}
|
|
4541
|
-
const exitAnimation = this.node.animationState.setActive(
|
|
4548
|
+
const exitAnimation = this.node.animationState.setActive("exit" /* AnimationType.Exit */, !isPresent, { custom: custom !== null && custom !== void 0 ? custom : this.node.getProps().custom });
|
|
4542
4549
|
if (onExitComplete && !isPresent) {
|
|
4543
4550
|
exitAnimation.then(() => onExitComplete(this.id));
|
|
4544
4551
|
}
|
|
@@ -5152,7 +5159,7 @@ class VisualElementDragControls {
|
|
|
5152
5159
|
// Fire onDragStart event
|
|
5153
5160
|
onDragStart && onDragStart(event, info);
|
|
5154
5161
|
const { animationState } = this.visualElement;
|
|
5155
|
-
animationState && animationState.setActive(
|
|
5162
|
+
animationState && animationState.setActive("whileDrag" /* AnimationType.Drag */, true);
|
|
5156
5163
|
};
|
|
5157
5164
|
const onMove = (event, info) => {
|
|
5158
5165
|
// latestPointerEvent = event
|
|
@@ -5217,7 +5224,7 @@ class VisualElementDragControls {
|
|
|
5217
5224
|
this.openGlobalLock();
|
|
5218
5225
|
this.openGlobalLock = null;
|
|
5219
5226
|
}
|
|
5220
|
-
animationState && animationState.setActive(
|
|
5227
|
+
animationState && animationState.setActive("whileDrag" /* AnimationType.Drag */, false);
|
|
5221
5228
|
}
|
|
5222
5229
|
updateAxis(axis, _point, offset) {
|
|
5223
5230
|
const { drag } = this.getProps();
|
|
@@ -5270,7 +5277,7 @@ class VisualElementDragControls {
|
|
|
5270
5277
|
if (!constraints || !isRefObject(constraints))
|
|
5271
5278
|
return false;
|
|
5272
5279
|
const constraintsElement = constraints.current;
|
|
5273
|
-
|
|
5280
|
+
exports.invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
|
5274
5281
|
const { projection } = this.visualElement;
|
|
5275
5282
|
// TODO
|
|
5276
5283
|
if (!projection || !projection.layout)
|
|
@@ -7355,9 +7362,6 @@ const correctBorderRadius = {
|
|
|
7355
7362
|
},
|
|
7356
7363
|
};
|
|
7357
7364
|
|
|
7358
|
-
function isCSSVariable(value) {
|
|
7359
|
-
return typeof value === "string" && value.startsWith("var(--");
|
|
7360
|
-
}
|
|
7361
7365
|
/**
|
|
7362
7366
|
* Parse Framer's special CSS variable format into a CSS token and a fallback.
|
|
7363
7367
|
*
|
|
@@ -7377,7 +7381,7 @@ function parseCSSVariable(current) {
|
|
|
7377
7381
|
}
|
|
7378
7382
|
const maxDepth = 4;
|
|
7379
7383
|
function getVariableValue(current, element, depth = 1) {
|
|
7380
|
-
|
|
7384
|
+
exports.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`);
|
|
7381
7385
|
const [token, fallback] = parseCSSVariable(current);
|
|
7382
7386
|
// No CSS variable detected
|
|
7383
7387
|
if (!token)
|
|
@@ -7387,7 +7391,7 @@ function getVariableValue(current, element, depth = 1) {
|
|
|
7387
7391
|
if (resolved) {
|
|
7388
7392
|
return resolved.trim();
|
|
7389
7393
|
}
|
|
7390
|
-
else if (
|
|
7394
|
+
else if (isCSSVariableToken(fallback)) {
|
|
7391
7395
|
// The fallback might itself be a CSS variable, in which case we attempt to resolve it too.
|
|
7392
7396
|
return getVariableValue(fallback, element, depth + 1);
|
|
7393
7397
|
}
|
|
@@ -7412,7 +7416,7 @@ function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
|
7412
7416
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
7413
7417
|
visualElement.values.forEach((value) => {
|
|
7414
7418
|
const current = value.get();
|
|
7415
|
-
if (!
|
|
7419
|
+
if (!isCSSVariableToken(current))
|
|
7416
7420
|
return;
|
|
7417
7421
|
const resolved = getVariableValue(current, element);
|
|
7418
7422
|
if (resolved)
|
|
@@ -7422,7 +7426,7 @@ function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
|
7422
7426
|
// we only read single-var properties like `var(--foo)`, not `calc(var(--foo) + 20px)`
|
|
7423
7427
|
for (const key in target) {
|
|
7424
7428
|
const current = target[key];
|
|
7425
|
-
if (!
|
|
7429
|
+
if (!isCSSVariableToken(current))
|
|
7426
7430
|
continue;
|
|
7427
7431
|
const resolved = getVariableValue(current, element);
|
|
7428
7432
|
if (!resolved)
|
|
@@ -7506,15 +7510,6 @@ const hasPositionalKey = (target) => {
|
|
|
7506
7510
|
return Object.keys(target).some(isPositionalKey);
|
|
7507
7511
|
};
|
|
7508
7512
|
const isNumOrPxType = (v) => v === number || v === px;
|
|
7509
|
-
var BoundingBoxDimension;
|
|
7510
|
-
(function (BoundingBoxDimension) {
|
|
7511
|
-
BoundingBoxDimension["width"] = "width";
|
|
7512
|
-
BoundingBoxDimension["height"] = "height";
|
|
7513
|
-
BoundingBoxDimension["left"] = "left";
|
|
7514
|
-
BoundingBoxDimension["right"] = "right";
|
|
7515
|
-
BoundingBoxDimension["top"] = "top";
|
|
7516
|
-
BoundingBoxDimension["bottom"] = "bottom";
|
|
7517
|
-
})(BoundingBoxDimension || (BoundingBoxDimension = {}));
|
|
7518
7513
|
const getPosFromMatrix = (matrix, pos) => parseFloat(matrix.split(", ")[pos]);
|
|
7519
7514
|
const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
|
|
7520
7515
|
if (transform === "none" || !transform)
|
|
@@ -7619,11 +7614,11 @@ const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, tr
|
|
|
7619
7614
|
for (let i = fromIndex; i < numKeyframes; i++) {
|
|
7620
7615
|
if (!toType) {
|
|
7621
7616
|
toType = findDimensionValueType(to[i]);
|
|
7622
|
-
|
|
7617
|
+
exports.invariant(toType === fromType ||
|
|
7623
7618
|
(isNumOrPxType(fromType) && isNumOrPxType(toType)), "Keyframes must be of the same dimension as the current value");
|
|
7624
7619
|
}
|
|
7625
7620
|
else {
|
|
7626
|
-
|
|
7621
|
+
exports.invariant(findDimensionValueType(to[i]) === toType, "All keyframes must be of the same type");
|
|
7627
7622
|
}
|
|
7628
7623
|
}
|
|
7629
7624
|
}
|
|
@@ -7769,7 +7764,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
7769
7764
|
* and warn against mismatches.
|
|
7770
7765
|
*/
|
|
7771
7766
|
if (process.env.NODE_ENV === "development") {
|
|
7772
|
-
warnOnce(nextValue.version === "9.1.
|
|
7767
|
+
warnOnce(nextValue.version === "9.1.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 9.1.2 may not work as expected.`);
|
|
7773
7768
|
}
|
|
7774
7769
|
}
|
|
7775
7770
|
else if (isMotionValue(prevValue)) {
|
|
@@ -7818,6 +7813,7 @@ const propEventHandlers = [
|
|
|
7818
7813
|
"LayoutAnimationStart",
|
|
7819
7814
|
"LayoutAnimationComplete",
|
|
7820
7815
|
];
|
|
7816
|
+
const numVariantProps = variantProps.length;
|
|
7821
7817
|
/**
|
|
7822
7818
|
* A VisualElement is an imperative abstraction around UI elements such as
|
|
7823
7819
|
* HTMLElement, SVGElement, Three.Object3D etc.
|
|
@@ -8012,8 +8008,8 @@ class VisualElement {
|
|
|
8012
8008
|
isStrict) {
|
|
8013
8009
|
const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
|
|
8014
8010
|
renderedProps.ignoreStrict
|
|
8015
|
-
?
|
|
8016
|
-
:
|
|
8011
|
+
? exports.warning(false, strictMessage)
|
|
8012
|
+
: exports.invariant(false, strictMessage);
|
|
8017
8013
|
}
|
|
8018
8014
|
for (let i = 0; i < numFeatures; i++) {
|
|
8019
8015
|
const name = featureNames[i];
|
|
@@ -8288,8 +8284,6 @@ class VisualElement {
|
|
|
8288
8284
|
}
|
|
8289
8285
|
}
|
|
8290
8286
|
}
|
|
8291
|
-
const variantProps = ["initial", ...variantPriorityOrder];
|
|
8292
|
-
const numVariantProps = variantProps.length;
|
|
8293
8287
|
|
|
8294
8288
|
class DOMVisualElement extends VisualElement {
|
|
8295
8289
|
sortInstanceNodePosition(a, b) {
|
|
@@ -8345,7 +8339,7 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
8345
8339
|
}
|
|
8346
8340
|
else {
|
|
8347
8341
|
const computedStyle = getComputedStyle$1(instance);
|
|
8348
|
-
const value = (
|
|
8342
|
+
const value = (isCSSVariableName(key)
|
|
8349
8343
|
? computedStyle.getPropertyValue(key)
|
|
8350
8344
|
: computedStyle[key]) || 0;
|
|
8351
8345
|
return typeof value === "string" ? value.trim() : value;
|
|
@@ -8981,9 +8975,9 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
|
8981
8975
|
};
|
|
8982
8976
|
|
|
8983
8977
|
let id = 0;
|
|
8984
|
-
const AnimateSharedLayout = ({ children
|
|
8978
|
+
const AnimateSharedLayout = ({ children }) => {
|
|
8985
8979
|
React__namespace.useEffect(() => {
|
|
8986
|
-
|
|
8980
|
+
exports.warning(false, "AnimateSharedLayout is deprecated: https://www.framer.com/docs/guide-upgrade/##shared-layout-animations");
|
|
8987
8981
|
}, []);
|
|
8988
8982
|
return (React__namespace.createElement(LayoutGroup, { id: useConstant(() => `asl-${id++}`) }, children));
|
|
8989
8983
|
};
|
|
@@ -9111,7 +9105,7 @@ function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...p
|
|
|
9111
9105
|
const Component = useConstant(() => motion(as));
|
|
9112
9106
|
const order = [];
|
|
9113
9107
|
const isReordering = React.useRef(false);
|
|
9114
|
-
|
|
9108
|
+
exports.invariant(Boolean(values), "Reorder.Group must be provided a values prop");
|
|
9115
9109
|
const context = {
|
|
9116
9110
|
axis,
|
|
9117
9111
|
registerItem: (value, layout) => {
|
|
@@ -9264,7 +9258,7 @@ function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout =
|
|
|
9264
9258
|
};
|
|
9265
9259
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
9266
9260
|
const measuredLayout = React.useRef(null);
|
|
9267
|
-
|
|
9261
|
+
exports.invariant(Boolean(context), "Reorder.Item must be a child of Reorder.Group");
|
|
9268
9262
|
const { axis, registerItem, updateOrder } = context;
|
|
9269
9263
|
React.useEffect(() => {
|
|
9270
9264
|
registerItem(value, measuredLayout.current);
|
|
@@ -9285,6 +9279,17 @@ const Reorder = {
|
|
|
9285
9279
|
Item,
|
|
9286
9280
|
};
|
|
9287
9281
|
|
|
9282
|
+
exports.AnimationType = void 0;
|
|
9283
|
+
(function (AnimationType) {
|
|
9284
|
+
AnimationType["Animate"] = "animate";
|
|
9285
|
+
AnimationType["Hover"] = "whileHover";
|
|
9286
|
+
AnimationType["Tap"] = "whileTap";
|
|
9287
|
+
AnimationType["Drag"] = "whileDrag";
|
|
9288
|
+
AnimationType["Focus"] = "whileFocus";
|
|
9289
|
+
AnimationType["InView"] = "whileInView";
|
|
9290
|
+
AnimationType["Exit"] = "exit";
|
|
9291
|
+
})(exports.AnimationType || (exports.AnimationType = {}));
|
|
9292
|
+
|
|
9288
9293
|
/**
|
|
9289
9294
|
* @public
|
|
9290
9295
|
*/
|
|
@@ -9420,8 +9425,443 @@ function useVelocity(value) {
|
|
|
9420
9425
|
return velocity;
|
|
9421
9426
|
}
|
|
9422
9427
|
|
|
9428
|
+
function resolveElements(elements, selectorCache) {
|
|
9429
|
+
var _a;
|
|
9430
|
+
if (typeof elements === "string") {
|
|
9431
|
+
if (selectorCache) {
|
|
9432
|
+
(_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = document.querySelectorAll(elements));
|
|
9433
|
+
elements = selectorCache[elements];
|
|
9434
|
+
}
|
|
9435
|
+
else {
|
|
9436
|
+
elements = document.querySelectorAll(elements);
|
|
9437
|
+
}
|
|
9438
|
+
}
|
|
9439
|
+
else if (elements instanceof Element) {
|
|
9440
|
+
elements = [elements];
|
|
9441
|
+
}
|
|
9442
|
+
/**
|
|
9443
|
+
* Return an empty array
|
|
9444
|
+
*/
|
|
9445
|
+
return Array.from(elements || []);
|
|
9446
|
+
}
|
|
9447
|
+
|
|
9448
|
+
const resizeHandlers = new WeakMap();
|
|
9449
|
+
let observer;
|
|
9450
|
+
function getElementSize(target, borderBoxSize) {
|
|
9451
|
+
if (borderBoxSize) {
|
|
9452
|
+
const { inlineSize, blockSize } = borderBoxSize[0];
|
|
9453
|
+
return { width: inlineSize, height: blockSize };
|
|
9454
|
+
}
|
|
9455
|
+
else if (target instanceof SVGElement && "getBBox" in target) {
|
|
9456
|
+
return target.getBBox();
|
|
9457
|
+
}
|
|
9458
|
+
else {
|
|
9459
|
+
return {
|
|
9460
|
+
width: target.offsetWidth,
|
|
9461
|
+
height: target.offsetHeight,
|
|
9462
|
+
};
|
|
9463
|
+
}
|
|
9464
|
+
}
|
|
9465
|
+
function notifyTarget({ target, contentRect, borderBoxSize, }) {
|
|
9466
|
+
var _a;
|
|
9467
|
+
(_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
|
|
9468
|
+
handler({
|
|
9469
|
+
target,
|
|
9470
|
+
contentSize: contentRect,
|
|
9471
|
+
get size() {
|
|
9472
|
+
return getElementSize(target, borderBoxSize);
|
|
9473
|
+
},
|
|
9474
|
+
});
|
|
9475
|
+
});
|
|
9476
|
+
}
|
|
9477
|
+
function notifyAll(entries) {
|
|
9478
|
+
entries.forEach(notifyTarget);
|
|
9479
|
+
}
|
|
9480
|
+
function createResizeObserver() {
|
|
9481
|
+
if (typeof ResizeObserver === "undefined")
|
|
9482
|
+
return;
|
|
9483
|
+
observer = new ResizeObserver(notifyAll);
|
|
9484
|
+
}
|
|
9485
|
+
function resizeElement(target, handler) {
|
|
9486
|
+
if (!observer)
|
|
9487
|
+
createResizeObserver();
|
|
9488
|
+
const elements = resolveElements(target);
|
|
9489
|
+
elements.forEach((element) => {
|
|
9490
|
+
let elementHandlers = resizeHandlers.get(element);
|
|
9491
|
+
if (!elementHandlers) {
|
|
9492
|
+
elementHandlers = new Set();
|
|
9493
|
+
resizeHandlers.set(element, elementHandlers);
|
|
9494
|
+
}
|
|
9495
|
+
elementHandlers.add(handler);
|
|
9496
|
+
observer === null || observer === void 0 ? void 0 : observer.observe(element);
|
|
9497
|
+
});
|
|
9498
|
+
return () => {
|
|
9499
|
+
elements.forEach((element) => {
|
|
9500
|
+
const elementHandlers = resizeHandlers.get(element);
|
|
9501
|
+
elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.delete(handler);
|
|
9502
|
+
if (!(elementHandlers === null || elementHandlers === void 0 ? void 0 : elementHandlers.size)) {
|
|
9503
|
+
observer === null || observer === void 0 ? void 0 : observer.unobserve(element);
|
|
9504
|
+
}
|
|
9505
|
+
});
|
|
9506
|
+
};
|
|
9507
|
+
}
|
|
9508
|
+
|
|
9509
|
+
const windowCallbacks = new Set();
|
|
9510
|
+
let windowResizeHandler;
|
|
9511
|
+
function createWindowResizeHandler() {
|
|
9512
|
+
windowResizeHandler = () => {
|
|
9513
|
+
const size = {
|
|
9514
|
+
width: window.innerWidth,
|
|
9515
|
+
height: window.innerHeight,
|
|
9516
|
+
};
|
|
9517
|
+
const info = {
|
|
9518
|
+
target: window,
|
|
9519
|
+
size,
|
|
9520
|
+
contentSize: size,
|
|
9521
|
+
};
|
|
9522
|
+
windowCallbacks.forEach((callback) => callback(info));
|
|
9523
|
+
};
|
|
9524
|
+
window.addEventListener("resize", windowResizeHandler);
|
|
9525
|
+
}
|
|
9526
|
+
function resizeWindow(callback) {
|
|
9527
|
+
windowCallbacks.add(callback);
|
|
9528
|
+
if (!windowResizeHandler)
|
|
9529
|
+
createWindowResizeHandler();
|
|
9530
|
+
return () => {
|
|
9531
|
+
windowCallbacks.delete(callback);
|
|
9532
|
+
if (!windowCallbacks.size && windowResizeHandler) {
|
|
9533
|
+
windowResizeHandler = undefined;
|
|
9534
|
+
}
|
|
9535
|
+
};
|
|
9536
|
+
}
|
|
9537
|
+
|
|
9538
|
+
function resize(a, b) {
|
|
9539
|
+
return typeof a === "function" ? resizeWindow(a) : resizeElement(a, b);
|
|
9540
|
+
}
|
|
9541
|
+
|
|
9542
|
+
/**
|
|
9543
|
+
* A time in milliseconds, beyond which we consider the scroll velocity to be 0.
|
|
9544
|
+
*/
|
|
9545
|
+
const maxElapsed = 50;
|
|
9546
|
+
const createAxisInfo = () => ({
|
|
9547
|
+
current: 0,
|
|
9548
|
+
offset: [],
|
|
9549
|
+
progress: 0,
|
|
9550
|
+
scrollLength: 0,
|
|
9551
|
+
targetOffset: 0,
|
|
9552
|
+
targetLength: 0,
|
|
9553
|
+
containerLength: 0,
|
|
9554
|
+
velocity: 0,
|
|
9555
|
+
});
|
|
9556
|
+
const createScrollInfo = () => ({
|
|
9557
|
+
time: 0,
|
|
9558
|
+
x: createAxisInfo(),
|
|
9559
|
+
y: createAxisInfo(),
|
|
9560
|
+
});
|
|
9561
|
+
const keys = {
|
|
9562
|
+
x: {
|
|
9563
|
+
length: "Width",
|
|
9564
|
+
position: "Left",
|
|
9565
|
+
},
|
|
9566
|
+
y: {
|
|
9567
|
+
length: "Height",
|
|
9568
|
+
position: "Top",
|
|
9569
|
+
},
|
|
9570
|
+
};
|
|
9571
|
+
function updateAxisInfo(element, axisName, info, time) {
|
|
9572
|
+
const axis = info[axisName];
|
|
9573
|
+
const { length, position } = keys[axisName];
|
|
9574
|
+
const prev = axis.current;
|
|
9575
|
+
const prevTime = info.time;
|
|
9576
|
+
axis.current = element["scroll" + position];
|
|
9577
|
+
axis.scrollLength = element["scroll" + length] - element["client" + length];
|
|
9578
|
+
axis.offset.length = 0;
|
|
9579
|
+
axis.offset[0] = 0;
|
|
9580
|
+
axis.offset[1] = axis.scrollLength;
|
|
9581
|
+
axis.progress = progress(0, axis.scrollLength, axis.current);
|
|
9582
|
+
const elapsed = time - prevTime;
|
|
9583
|
+
axis.velocity =
|
|
9584
|
+
elapsed > maxElapsed
|
|
9585
|
+
? 0
|
|
9586
|
+
: velocityPerSecond(axis.current - prev, elapsed);
|
|
9587
|
+
}
|
|
9588
|
+
function updateScrollInfo(element, info, time) {
|
|
9589
|
+
updateAxisInfo(element, "x", info, time);
|
|
9590
|
+
updateAxisInfo(element, "y", info, time);
|
|
9591
|
+
info.time = time;
|
|
9592
|
+
}
|
|
9593
|
+
|
|
9594
|
+
function calcInset(element, container) {
|
|
9595
|
+
let inset = { x: 0, y: 0 };
|
|
9596
|
+
let current = element;
|
|
9597
|
+
while (current && current !== container) {
|
|
9598
|
+
if (current instanceof HTMLElement) {
|
|
9599
|
+
inset.x += current.offsetLeft;
|
|
9600
|
+
inset.y += current.offsetTop;
|
|
9601
|
+
current = current.offsetParent;
|
|
9602
|
+
}
|
|
9603
|
+
else if (current instanceof SVGGraphicsElement && "getBBox" in current) {
|
|
9604
|
+
const { top, left } = current.getBBox();
|
|
9605
|
+
inset.x += left;
|
|
9606
|
+
inset.y += top;
|
|
9607
|
+
/**
|
|
9608
|
+
* Assign the next parent element as the <svg /> tag.
|
|
9609
|
+
*/
|
|
9610
|
+
while (current && current.tagName !== "svg") {
|
|
9611
|
+
current = current.parentNode;
|
|
9612
|
+
}
|
|
9613
|
+
}
|
|
9614
|
+
}
|
|
9615
|
+
return inset;
|
|
9616
|
+
}
|
|
9617
|
+
|
|
9618
|
+
const ScrollOffset = {
|
|
9619
|
+
Enter: [
|
|
9620
|
+
[0, 1],
|
|
9621
|
+
[1, 1],
|
|
9622
|
+
],
|
|
9623
|
+
Exit: [
|
|
9624
|
+
[0, 0],
|
|
9625
|
+
[1, 0],
|
|
9626
|
+
],
|
|
9627
|
+
Any: [
|
|
9628
|
+
[1, 0],
|
|
9629
|
+
[0, 1],
|
|
9630
|
+
],
|
|
9631
|
+
All: [
|
|
9632
|
+
[0, 0],
|
|
9633
|
+
[1, 1],
|
|
9634
|
+
],
|
|
9635
|
+
};
|
|
9636
|
+
|
|
9637
|
+
const namedEdges = {
|
|
9638
|
+
start: 0,
|
|
9639
|
+
center: 0.5,
|
|
9640
|
+
end: 1,
|
|
9641
|
+
};
|
|
9642
|
+
function resolveEdge(edge, length, inset = 0) {
|
|
9643
|
+
let delta = 0;
|
|
9644
|
+
/**
|
|
9645
|
+
* If we have this edge defined as a preset, replace the definition
|
|
9646
|
+
* with the numerical value.
|
|
9647
|
+
*/
|
|
9648
|
+
if (namedEdges[edge] !== undefined) {
|
|
9649
|
+
edge = namedEdges[edge];
|
|
9650
|
+
}
|
|
9651
|
+
/**
|
|
9652
|
+
* Handle unit values
|
|
9653
|
+
*/
|
|
9654
|
+
if (typeof edge === "string") {
|
|
9655
|
+
const asNumber = parseFloat(edge);
|
|
9656
|
+
if (edge.endsWith("px")) {
|
|
9657
|
+
delta = asNumber;
|
|
9658
|
+
}
|
|
9659
|
+
else if (edge.endsWith("%")) {
|
|
9660
|
+
edge = asNumber / 100;
|
|
9661
|
+
}
|
|
9662
|
+
else if (edge.endsWith("vw")) {
|
|
9663
|
+
delta = (asNumber / 100) * document.documentElement.clientWidth;
|
|
9664
|
+
}
|
|
9665
|
+
else if (edge.endsWith("vh")) {
|
|
9666
|
+
delta = (asNumber / 100) * document.documentElement.clientHeight;
|
|
9667
|
+
}
|
|
9668
|
+
else {
|
|
9669
|
+
edge = asNumber;
|
|
9670
|
+
}
|
|
9671
|
+
}
|
|
9672
|
+
/**
|
|
9673
|
+
* If the edge is defined as a number, handle as a progress value.
|
|
9674
|
+
*/
|
|
9675
|
+
if (typeof edge === "number") {
|
|
9676
|
+
delta = length * edge;
|
|
9677
|
+
}
|
|
9678
|
+
return inset + delta;
|
|
9679
|
+
}
|
|
9680
|
+
|
|
9681
|
+
const defaultOffset = [0, 0];
|
|
9682
|
+
function resolveOffset(offset, containerLength, targetLength, targetInset) {
|
|
9683
|
+
let offsetDefinition = Array.isArray(offset) ? offset : defaultOffset;
|
|
9684
|
+
let targetPoint = 0;
|
|
9685
|
+
let containerPoint = 0;
|
|
9686
|
+
if (typeof offset === "number") {
|
|
9687
|
+
/**
|
|
9688
|
+
* If we're provided offset: [0, 0.5, 1] then each number x should become
|
|
9689
|
+
* [x, x], so we default to the behaviour of mapping 0 => 0 of both target
|
|
9690
|
+
* and container etc.
|
|
9691
|
+
*/
|
|
9692
|
+
offsetDefinition = [offset, offset];
|
|
9693
|
+
}
|
|
9694
|
+
else if (typeof offset === "string") {
|
|
9695
|
+
offset = offset.trim();
|
|
9696
|
+
if (offset.includes(" ")) {
|
|
9697
|
+
offsetDefinition = offset.split(" ");
|
|
9698
|
+
}
|
|
9699
|
+
else {
|
|
9700
|
+
/**
|
|
9701
|
+
* If we're provided a definition like "100px" then we want to apply
|
|
9702
|
+
* that only to the top of the target point, leaving the container at 0.
|
|
9703
|
+
* Whereas a named offset like "end" should be applied to both.
|
|
9704
|
+
*/
|
|
9705
|
+
offsetDefinition = [offset, namedEdges[offset] ? offset : `0`];
|
|
9706
|
+
}
|
|
9707
|
+
}
|
|
9708
|
+
targetPoint = resolveEdge(offsetDefinition[0], targetLength, targetInset);
|
|
9709
|
+
containerPoint = resolveEdge(offsetDefinition[1], containerLength);
|
|
9710
|
+
return targetPoint - containerPoint;
|
|
9711
|
+
}
|
|
9712
|
+
|
|
9713
|
+
const point = { x: 0, y: 0 };
|
|
9714
|
+
function resolveOffsets(container, info, options) {
|
|
9715
|
+
let { offset: offsetDefinition = ScrollOffset.All } = options;
|
|
9716
|
+
const { target = container, axis = "y" } = options;
|
|
9717
|
+
const lengthLabel = axis === "y" ? "height" : "width";
|
|
9718
|
+
const inset = target !== container ? calcInset(target, container) : point;
|
|
9719
|
+
/**
|
|
9720
|
+
* Measure the target and container. If they're the same thing then we
|
|
9721
|
+
* use the container's scrollWidth/Height as the target, from there
|
|
9722
|
+
* all other calculations can remain the same.
|
|
9723
|
+
*/
|
|
9724
|
+
const targetSize = target === container
|
|
9725
|
+
? { width: container.scrollWidth, height: container.scrollHeight }
|
|
9726
|
+
: { width: target.clientWidth, height: target.clientHeight };
|
|
9727
|
+
const containerSize = {
|
|
9728
|
+
width: container.clientWidth,
|
|
9729
|
+
height: container.clientHeight,
|
|
9730
|
+
};
|
|
9731
|
+
/**
|
|
9732
|
+
* Reset the length of the resolved offset array rather than creating a new one.
|
|
9733
|
+
* TODO: More reusable data structures for targetSize/containerSize would also be good.
|
|
9734
|
+
*/
|
|
9735
|
+
info[axis].offset.length = 0;
|
|
9736
|
+
/**
|
|
9737
|
+
* Populate the offset array by resolving the user's offset definition into
|
|
9738
|
+
* a list of pixel scroll offets.
|
|
9739
|
+
*/
|
|
9740
|
+
let hasChanged = !info[axis].interpolate;
|
|
9741
|
+
const numOffsets = offsetDefinition.length;
|
|
9742
|
+
for (let i = 0; i < numOffsets; i++) {
|
|
9743
|
+
const offset = resolveOffset(offsetDefinition[i], containerSize[lengthLabel], targetSize[lengthLabel], inset[axis]);
|
|
9744
|
+
if (!hasChanged && offset !== info[axis].interpolatorOffsets[i]) {
|
|
9745
|
+
hasChanged = true;
|
|
9746
|
+
}
|
|
9747
|
+
info[axis].offset[i] = offset;
|
|
9748
|
+
}
|
|
9749
|
+
/**
|
|
9750
|
+
* If the pixel scroll offsets have changed, create a new interpolator function
|
|
9751
|
+
* to map scroll value into a progress.
|
|
9752
|
+
*/
|
|
9753
|
+
if (hasChanged) {
|
|
9754
|
+
info[axis].interpolate = interpolate(info[axis].offset, defaultOffset$1(offsetDefinition));
|
|
9755
|
+
info[axis].interpolatorOffsets = [...info[axis].offset];
|
|
9756
|
+
}
|
|
9757
|
+
info[axis].progress = info[axis].interpolate(info[axis].current);
|
|
9758
|
+
}
|
|
9759
|
+
|
|
9760
|
+
function measure(container, target = container, info) {
|
|
9761
|
+
/**
|
|
9762
|
+
* Find inset of target within scrollable container
|
|
9763
|
+
*/
|
|
9764
|
+
info.x.targetOffset = 0;
|
|
9765
|
+
info.y.targetOffset = 0;
|
|
9766
|
+
if (target !== container) {
|
|
9767
|
+
let node = target;
|
|
9768
|
+
while (node && node !== container) {
|
|
9769
|
+
info.x.targetOffset += node.offsetLeft;
|
|
9770
|
+
info.y.targetOffset += node.offsetTop;
|
|
9771
|
+
node = node.offsetParent;
|
|
9772
|
+
}
|
|
9773
|
+
}
|
|
9774
|
+
info.x.targetLength =
|
|
9775
|
+
target === container ? target.scrollWidth : target.clientWidth;
|
|
9776
|
+
info.y.targetLength =
|
|
9777
|
+
target === container ? target.scrollHeight : target.clientHeight;
|
|
9778
|
+
info.x.containerLength = container.clientWidth;
|
|
9779
|
+
info.y.containerLength = container.clientHeight;
|
|
9780
|
+
}
|
|
9781
|
+
function createOnScrollHandler(element, onScroll, info, options = {}) {
|
|
9782
|
+
return {
|
|
9783
|
+
measure: () => measure(element, options.target, info),
|
|
9784
|
+
update: (time) => {
|
|
9785
|
+
updateScrollInfo(element, info, time);
|
|
9786
|
+
if (options.offset || options.target) {
|
|
9787
|
+
resolveOffsets(element, info, options);
|
|
9788
|
+
}
|
|
9789
|
+
},
|
|
9790
|
+
notify: () => onScroll(info),
|
|
9791
|
+
};
|
|
9792
|
+
}
|
|
9793
|
+
|
|
9794
|
+
const scrollListeners = new WeakMap();
|
|
9795
|
+
const resizeListeners = new WeakMap();
|
|
9796
|
+
const onScrollHandlers = new WeakMap();
|
|
9797
|
+
const getEventTarget = (element) => element === document.documentElement ? window : element;
|
|
9798
|
+
function scroll(onScroll, { container = document.documentElement, ...options } = {}) {
|
|
9799
|
+
let containerHandlers = onScrollHandlers.get(container);
|
|
9800
|
+
/**
|
|
9801
|
+
* Get the onScroll handlers for this container.
|
|
9802
|
+
* If one isn't found, create a new one.
|
|
9803
|
+
*/
|
|
9804
|
+
if (!containerHandlers) {
|
|
9805
|
+
containerHandlers = new Set();
|
|
9806
|
+
onScrollHandlers.set(container, containerHandlers);
|
|
9807
|
+
}
|
|
9808
|
+
/**
|
|
9809
|
+
* Create a new onScroll handler for the provided callback.
|
|
9810
|
+
*/
|
|
9811
|
+
const info = createScrollInfo();
|
|
9812
|
+
const containerHandler = createOnScrollHandler(container, onScroll, info, options);
|
|
9813
|
+
containerHandlers.add(containerHandler);
|
|
9814
|
+
/**
|
|
9815
|
+
* Check if there's a scroll event listener for this container.
|
|
9816
|
+
* If not, create one.
|
|
9817
|
+
*/
|
|
9818
|
+
if (!scrollListeners.has(container)) {
|
|
9819
|
+
const listener = () => {
|
|
9820
|
+
const time = performance.now();
|
|
9821
|
+
for (const handler of containerHandlers)
|
|
9822
|
+
handler.measure();
|
|
9823
|
+
for (const handler of containerHandlers)
|
|
9824
|
+
handler.update(time);
|
|
9825
|
+
for (const handler of containerHandlers)
|
|
9826
|
+
handler.notify();
|
|
9827
|
+
};
|
|
9828
|
+
scrollListeners.set(container, listener);
|
|
9829
|
+
const target = getEventTarget(container);
|
|
9830
|
+
window.addEventListener("resize", listener, { passive: true });
|
|
9831
|
+
if (container !== document.documentElement) {
|
|
9832
|
+
resizeListeners.set(container, resize(container, listener));
|
|
9833
|
+
}
|
|
9834
|
+
target.addEventListener("scroll", listener, { passive: true });
|
|
9835
|
+
}
|
|
9836
|
+
const listener = scrollListeners.get(container);
|
|
9837
|
+
const onLoadProcesss = requestAnimationFrame(listener);
|
|
9838
|
+
return () => {
|
|
9839
|
+
var _a;
|
|
9840
|
+
cancelAnimationFrame(onLoadProcesss);
|
|
9841
|
+
/**
|
|
9842
|
+
* Check if we even have any handlers for this container.
|
|
9843
|
+
*/
|
|
9844
|
+
const currentHandlers = onScrollHandlers.get(container);
|
|
9845
|
+
if (!currentHandlers)
|
|
9846
|
+
return;
|
|
9847
|
+
currentHandlers.delete(containerHandler);
|
|
9848
|
+
if (currentHandlers.size)
|
|
9849
|
+
return;
|
|
9850
|
+
/**
|
|
9851
|
+
* If no more handlers, remove the scroll listener too.
|
|
9852
|
+
*/
|
|
9853
|
+
const scrollListener = scrollListeners.get(container);
|
|
9854
|
+
scrollListeners.delete(container);
|
|
9855
|
+
if (scrollListener) {
|
|
9856
|
+
getEventTarget(container).removeEventListener("scroll", scrollListener);
|
|
9857
|
+
(_a = resizeListeners.get(container)) === null || _a === void 0 ? void 0 : _a();
|
|
9858
|
+
window.removeEventListener("resize", scrollListener);
|
|
9859
|
+
}
|
|
9860
|
+
};
|
|
9861
|
+
}
|
|
9862
|
+
|
|
9423
9863
|
function refWarning(name, ref) {
|
|
9424
|
-
|
|
9864
|
+
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.`);
|
|
9425
9865
|
}
|
|
9426
9866
|
const createScrollMotionValues = () => ({
|
|
9427
9867
|
scrollX: motionValue(0),
|
|
@@ -9437,7 +9877,7 @@ function useScroll({ container, target, layoutEffect = true, ...options } = {})
|
|
|
9437
9877
|
useLifecycleEffect(() => {
|
|
9438
9878
|
refWarning("target", target);
|
|
9439
9879
|
refWarning("container", container);
|
|
9440
|
-
return
|
|
9880
|
+
return scroll(({ x, y }) => {
|
|
9441
9881
|
values.scrollX.set(x.current);
|
|
9442
9882
|
values.scrollXProgress.set(x.progress);
|
|
9443
9883
|
values.scrollY.set(y.current);
|
|
@@ -9506,7 +9946,7 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
9506
9946
|
memberName = "transform";
|
|
9507
9947
|
}
|
|
9508
9948
|
else if (!name.startsWith("origin") &&
|
|
9509
|
-
!
|
|
9949
|
+
!isCSSVariableName(name) &&
|
|
9510
9950
|
name !== "willChange") {
|
|
9511
9951
|
memberName = camelToDash(name);
|
|
9512
9952
|
}
|
|
@@ -9618,7 +10058,7 @@ function animationControls() {
|
|
|
9618
10058
|
return () => void subscribers.delete(visualElement);
|
|
9619
10059
|
},
|
|
9620
10060
|
start(definition, transitionOverride) {
|
|
9621
|
-
|
|
10061
|
+
exports.invariant(hasMounted, "controls.start() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
|
9622
10062
|
const animations = [];
|
|
9623
10063
|
subscribers.forEach((visualElement) => {
|
|
9624
10064
|
animations.push(animateVisualElement(visualElement, definition, {
|
|
@@ -9628,7 +10068,7 @@ function animationControls() {
|
|
|
9628
10068
|
return Promise.all(animations);
|
|
9629
10069
|
},
|
|
9630
10070
|
set(definition) {
|
|
9631
|
-
|
|
10071
|
+
exports.invariant(hasMounted, "controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
|
9632
10072
|
return subscribers.forEach((visualElement) => {
|
|
9633
10073
|
setValues(visualElement, definition);
|
|
9634
10074
|
});
|
|
@@ -9733,6 +10173,55 @@ function useCycle(...items) {
|
|
|
9733
10173
|
return [item, runCycle];
|
|
9734
10174
|
}
|
|
9735
10175
|
|
|
10176
|
+
const thresholds = {
|
|
10177
|
+
any: 0,
|
|
10178
|
+
all: 1,
|
|
10179
|
+
};
|
|
10180
|
+
function inView(elementOrSelector, onStart, { root, margin: rootMargin, amount = "any" } = {}) {
|
|
10181
|
+
/**
|
|
10182
|
+
* If this browser doesn't support IntersectionObserver, return a dummy stop function.
|
|
10183
|
+
* Default triggering of onStart is tricky - it could be used for starting/stopping
|
|
10184
|
+
* videos, lazy loading content etc. We could provide an option to enable a fallback, or
|
|
10185
|
+
* provide a fallback callback option.
|
|
10186
|
+
*/
|
|
10187
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
10188
|
+
return () => { };
|
|
10189
|
+
}
|
|
10190
|
+
const elements = resolveElements(elementOrSelector);
|
|
10191
|
+
const activeIntersections = new WeakMap();
|
|
10192
|
+
const onIntersectionChange = (entries) => {
|
|
10193
|
+
entries.forEach((entry) => {
|
|
10194
|
+
const onEnd = activeIntersections.get(entry.target);
|
|
10195
|
+
/**
|
|
10196
|
+
* If there's no change to the intersection, we don't need to
|
|
10197
|
+
* do anything here.
|
|
10198
|
+
*/
|
|
10199
|
+
if (entry.isIntersecting === Boolean(onEnd))
|
|
10200
|
+
return;
|
|
10201
|
+
if (entry.isIntersecting) {
|
|
10202
|
+
const newOnEnd = onStart(entry);
|
|
10203
|
+
if (typeof newOnEnd === "function") {
|
|
10204
|
+
activeIntersections.set(entry.target, newOnEnd);
|
|
10205
|
+
}
|
|
10206
|
+
else {
|
|
10207
|
+
observer.unobserve(entry.target);
|
|
10208
|
+
}
|
|
10209
|
+
}
|
|
10210
|
+
else if (onEnd) {
|
|
10211
|
+
onEnd(entry);
|
|
10212
|
+
activeIntersections.delete(entry.target);
|
|
10213
|
+
}
|
|
10214
|
+
});
|
|
10215
|
+
};
|
|
10216
|
+
const observer = new IntersectionObserver(onIntersectionChange, {
|
|
10217
|
+
root,
|
|
10218
|
+
rootMargin,
|
|
10219
|
+
threshold: typeof amount === "number" ? amount : thresholds[amount],
|
|
10220
|
+
});
|
|
10221
|
+
elements.forEach((element) => observer.observe(element));
|
|
10222
|
+
return () => observer.disconnect();
|
|
10223
|
+
}
|
|
10224
|
+
|
|
9736
10225
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
9737
10226
|
const [isInView, setInView] = React.useState(false);
|
|
9738
10227
|
React.useEffect(() => {
|
|
@@ -9747,7 +10236,7 @@ function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
|
9747
10236
|
margin,
|
|
9748
10237
|
amount: amount === "some" ? "any" : amount,
|
|
9749
10238
|
};
|
|
9750
|
-
return
|
|
10239
|
+
return inView(ref.current, onEnter, options);
|
|
9751
10240
|
}, [root, ref, margin, once]);
|
|
9752
10241
|
return isInView;
|
|
9753
10242
|
}
|
|
@@ -10128,8 +10617,8 @@ function useInvertedScale(scale) {
|
|
|
10128
10617
|
let parentScaleX = useMotionValue(1);
|
|
10129
10618
|
let parentScaleY = useMotionValue(1);
|
|
10130
10619
|
const visualElement = useVisualElementContext();
|
|
10131
|
-
|
|
10132
|
-
|
|
10620
|
+
exports.invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
|
|
10621
|
+
exports.warning(hasWarned, "useInvertedScale is deprecated and will be removed in 3.0. Use the layout prop instead.");
|
|
10133
10622
|
hasWarned = true;
|
|
10134
10623
|
if (scale) {
|
|
10135
10624
|
parentScaleX = scale.scaleX || parentScaleX;
|