framer-motion 12.6.2 → 12.6.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-BLp_edji.js → create-B2InJs4e.js} +68 -115
- package/dist/cjs/dom-mini.js +14 -219
- package/dist/cjs/dom.js +56 -199
- package/dist/cjs/index.js +32 -156
- package/dist/cjs/m.js +8 -12
- package/dist/cjs/mini.js +10 -214
- package/dist/dom-mini.d.ts +3 -3
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +17 -14
- package/dist/dom.js +1 -1
- package/dist/es/animation/animate/index.mjs +2 -2
- package/dist/es/animation/animators/AcceleratedAnimation.mjs +5 -3
- package/dist/es/animation/animators/MainThreadAnimation.mjs +6 -4
- package/dist/es/animation/animators/waapi/animate-elements.mjs +10 -9
- package/dist/es/animation/animators/waapi/animate-sequence.mjs +2 -2
- package/dist/es/animation/animators/waapi/animate-style.mjs +2 -2
- package/dist/es/animation/generators/spring/index.mjs +9 -1
- package/dist/es/animation/interfaces/motion-value.mjs +2 -2
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
- package/dist/es/animation/interfaces/visual-element-variant.mjs +1 -2
- package/dist/es/animation/optimized-appear/handoff.mjs +2 -4
- package/dist/es/animation/optimized-appear/start.mjs +4 -6
- package/dist/es/animation/sequence/create.mjs +2 -2
- package/dist/es/animation/sequence/utils/calc-time.mjs +1 -2
- package/dist/es/components/AnimatePresence/index.mjs +2 -2
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +5 -10
- package/dist/es/motion/features/animation/index.mjs +1 -2
- package/dist/es/motion/index.mjs +2 -3
- package/dist/es/motion/utils/use-visual-element.mjs +3 -5
- package/dist/es/projection/node/create-projection-node.mjs +17 -25
- package/dist/es/projection/styles/transform.mjs +1 -1
- package/dist/es/render/VisualElement.mjs +3 -4
- package/dist/es/render/dom/DOMKeyframesResolver.mjs +1 -2
- package/dist/es/render/dom/resize/handle-element.mjs +5 -6
- package/dist/es/render/dom/scroll/track.mjs +1 -2
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
- package/dist/es/render/dom/utils/filter-props.mjs +1 -1
- package/dist/es/render/html/utils/scrape-motion-values.mjs +1 -2
- package/dist/es/render/utils/KeyframesResolver.mjs +2 -3
- package/dist/es/render/utils/animation-state.mjs +3 -5
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/render/utils/resolve-variants.mjs +1 -1
- package/dist/es/utils/mix/complex.mjs +1 -2
- package/dist/es/value/types/complex/index.mjs +2 -3
- package/dist/es/value/use-scroll.mjs +2 -2
- package/dist/framer-motion.dev.js +445 -414
- package/dist/framer-motion.js +1 -1
- package/dist/mini.d.ts +1 -1
- package/dist/mini.js +1 -1
- package/dist/size-rollup-animate.js +1 -1
- package/dist/size-rollup-dom-animation-assets.js +1 -1
- package/dist/size-rollup-dom-animation-m.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-rollup-scroll.js +1 -1
- package/dist/size-rollup-waapi-animate.js +1 -1
- package/dist/types/index.d.ts +28 -31
- package/package.json +4 -4
- package/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -112
- package/dist/es/animation/animators/waapi/index.mjs +0 -32
- package/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
- package/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +0 -13
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-B2InJs4e.js');
|
|
8
8
|
var motionDom = require('motion-dom');
|
|
9
9
|
var motionUtils = require('motion-utils');
|
|
10
10
|
|
|
@@ -308,9 +308,9 @@ const AnimatePresence = ({ children, custom, initial = true, onExitComplete, pre
|
|
|
308
308
|
isEveryExitComplete = false;
|
|
309
309
|
});
|
|
310
310
|
if (isEveryExitComplete) {
|
|
311
|
-
forceRender
|
|
311
|
+
forceRender?.();
|
|
312
312
|
setRenderedChildren(pendingPresentChildren.current);
|
|
313
|
-
propagate &&
|
|
313
|
+
propagate && safeToRemove?.();
|
|
314
314
|
onExitComplete && onExitComplete();
|
|
315
315
|
}
|
|
316
316
|
};
|
|
@@ -786,7 +786,6 @@ function calculateRepeatDuration(duration, repeat, _repeatDelay) {
|
|
|
786
786
|
* calculate an absolute time for the next keyframes.
|
|
787
787
|
*/
|
|
788
788
|
function calcNextTime(current, next, prev, labels) {
|
|
789
|
-
var _a;
|
|
790
789
|
if (typeof next === "number") {
|
|
791
790
|
return next;
|
|
792
791
|
}
|
|
@@ -797,7 +796,7 @@ function calcNextTime(current, next, prev, labels) {
|
|
|
797
796
|
return prev;
|
|
798
797
|
}
|
|
799
798
|
else {
|
|
800
|
-
return
|
|
799
|
+
return labels.get(next) ?? current;
|
|
801
800
|
}
|
|
802
801
|
}
|
|
803
802
|
|
|
@@ -910,7 +909,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
|
|
|
910
909
|
const numKeyframes = valueKeyframesAsList.length;
|
|
911
910
|
const createGenerator = motionDom.isGenerator(type)
|
|
912
911
|
? type
|
|
913
|
-
: generators
|
|
912
|
+
: generators?.[type];
|
|
914
913
|
if (numKeyframes <= 2 && createGenerator) {
|
|
915
914
|
/**
|
|
916
915
|
* As we're creating an easing function from a spring,
|
|
@@ -932,7 +931,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
|
|
|
932
931
|
ease = springEasing.ease;
|
|
933
932
|
duration = springEasing.duration;
|
|
934
933
|
}
|
|
935
|
-
duration
|
|
934
|
+
duration ?? (duration = defaultDuration);
|
|
936
935
|
const startTime = currentTime + calculatedDelay;
|
|
937
936
|
/**
|
|
938
937
|
* If there's only one time offset of 0, fill in a second with length 1
|
|
@@ -1235,7 +1234,7 @@ function createScopedAnimate(scope) {
|
|
|
1235
1234
|
else {
|
|
1236
1235
|
animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
|
|
1237
1236
|
}
|
|
1238
|
-
const animation = new motionDom.
|
|
1237
|
+
const animation = new motionDom.GroupAnimationWithThen(animations);
|
|
1239
1238
|
if (scope) {
|
|
1240
1239
|
scope.animations.push(animation);
|
|
1241
1240
|
}
|
|
@@ -1245,125 +1244,6 @@ function createScopedAnimate(scope) {
|
|
|
1245
1244
|
}
|
|
1246
1245
|
const animate = createScopedAnimate();
|
|
1247
1246
|
|
|
1248
|
-
function setCSSVar(element, name, value) {
|
|
1249
|
-
element.style.setProperty(name, value);
|
|
1250
|
-
}
|
|
1251
|
-
function setStyle(element, name, value) {
|
|
1252
|
-
element.style[name] = value;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
1256
|
-
try {
|
|
1257
|
-
document.createElement("div").animate({ opacity: [1] });
|
|
1258
|
-
}
|
|
1259
|
-
catch (e) {
|
|
1260
|
-
return false;
|
|
1261
|
-
}
|
|
1262
|
-
return true;
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
const state = new WeakMap();
|
|
1266
|
-
function hydrateKeyframes(valueName, keyframes, read) {
|
|
1267
|
-
for (let i = 0; i < keyframes.length; i++) {
|
|
1268
|
-
if (keyframes[i] === null) {
|
|
1269
|
-
keyframes[i] = i === 0 ? read() : keyframes[i - 1];
|
|
1270
|
-
}
|
|
1271
|
-
if (typeof keyframes[i] === "number" &&
|
|
1272
|
-
create.browserNumberValueTypes[valueName]) {
|
|
1273
|
-
keyframes[i] = create.browserNumberValueTypes[valueName].transform(keyframes[i]);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
if (!supportsPartialKeyframes() && keyframes.length < 2) {
|
|
1277
|
-
keyframes.unshift(read());
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
const defaultEasing = "easeOut";
|
|
1281
|
-
function getElementAnimationState(element) {
|
|
1282
|
-
const animationState = state.get(element) || new Map();
|
|
1283
|
-
state.set(element, animationState);
|
|
1284
|
-
return state.get(element);
|
|
1285
|
-
}
|
|
1286
|
-
class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
1287
|
-
constructor(element, valueName, valueKeyframes, options) {
|
|
1288
|
-
const isCSSVar = valueName.startsWith("--");
|
|
1289
|
-
motionUtils.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
|
|
1290
|
-
const existingAnimation = getElementAnimationState(element).get(valueName);
|
|
1291
|
-
existingAnimation && existingAnimation.stop();
|
|
1292
|
-
const readInitialKeyframe = () => {
|
|
1293
|
-
return valueName.startsWith("--")
|
|
1294
|
-
? element.style.getPropertyValue(valueName)
|
|
1295
|
-
: window.getComputedStyle(element)[valueName];
|
|
1296
|
-
};
|
|
1297
|
-
if (!Array.isArray(valueKeyframes)) {
|
|
1298
|
-
valueKeyframes = [valueKeyframes];
|
|
1299
|
-
}
|
|
1300
|
-
hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
|
|
1301
|
-
// TODO: Replace this with toString()?
|
|
1302
|
-
if (motionDom.isGenerator(options.type)) {
|
|
1303
|
-
const generatorOptions = motionDom.createGeneratorEasing(options, 100, options.type);
|
|
1304
|
-
options.ease = motionDom.supportsLinearEasing()
|
|
1305
|
-
? generatorOptions.ease
|
|
1306
|
-
: defaultEasing;
|
|
1307
|
-
options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
|
|
1308
|
-
options.type = "keyframes";
|
|
1309
|
-
}
|
|
1310
|
-
else {
|
|
1311
|
-
options.ease = options.ease || defaultEasing;
|
|
1312
|
-
}
|
|
1313
|
-
const onFinish = () => {
|
|
1314
|
-
this.setValue(element, valueName, create.getFinalKeyframe(valueKeyframes, options));
|
|
1315
|
-
this.cancel();
|
|
1316
|
-
this.resolveFinishedPromise();
|
|
1317
|
-
};
|
|
1318
|
-
const init = () => {
|
|
1319
|
-
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
1320
|
-
this.options = options;
|
|
1321
|
-
this.updateFinishedPromise();
|
|
1322
|
-
this.removeAnimation = () => {
|
|
1323
|
-
const elementState = state.get(element);
|
|
1324
|
-
elementState && elementState.delete(valueName);
|
|
1325
|
-
};
|
|
1326
|
-
};
|
|
1327
|
-
if (!create.supportsWaapi()) {
|
|
1328
|
-
super();
|
|
1329
|
-
init();
|
|
1330
|
-
onFinish();
|
|
1331
|
-
}
|
|
1332
|
-
else {
|
|
1333
|
-
super(create.startWaapiAnimation(element, valueName, valueKeyframes, options));
|
|
1334
|
-
init();
|
|
1335
|
-
if (options.autoplay === false) {
|
|
1336
|
-
this.animation.pause();
|
|
1337
|
-
}
|
|
1338
|
-
this.animation.onfinish = onFinish;
|
|
1339
|
-
getElementAnimationState(element).set(valueName, this);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
1344
|
-
* resolves when the animation finishes at all but in a future update could/should
|
|
1345
|
-
* reject if its cancels.
|
|
1346
|
-
*/
|
|
1347
|
-
then(resolve, reject) {
|
|
1348
|
-
return this.currentFinishedPromise.then(resolve, reject);
|
|
1349
|
-
}
|
|
1350
|
-
updateFinishedPromise() {
|
|
1351
|
-
this.currentFinishedPromise = new Promise((resolve) => {
|
|
1352
|
-
this.resolveFinishedPromise = resolve;
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
play() {
|
|
1356
|
-
if (this.state === "finished") {
|
|
1357
|
-
this.updateFinishedPromise();
|
|
1358
|
-
}
|
|
1359
|
-
super.play();
|
|
1360
|
-
}
|
|
1361
|
-
cancel() {
|
|
1362
|
-
this.removeAnimation();
|
|
1363
|
-
super.cancel();
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
1247
|
function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
1368
1248
|
const elements = motionDom.resolveElements(elementOrSelector, scope);
|
|
1369
1249
|
const numElements = elements.length;
|
|
@@ -1383,13 +1263,15 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
1383
1263
|
const valueOptions = {
|
|
1384
1264
|
...motionDom.getValueTransition(elementTransition, valueName),
|
|
1385
1265
|
};
|
|
1386
|
-
valueOptions.duration = valueOptions.duration
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1266
|
+
valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
|
|
1267
|
+
valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
|
|
1268
|
+
animations.push(new motionDom.NativeAnimation({
|
|
1269
|
+
element,
|
|
1270
|
+
name: valueName,
|
|
1271
|
+
keyframes: valueKeyframes,
|
|
1272
|
+
transition: valueOptions,
|
|
1273
|
+
allowFlatten: !elementTransition.type && !elementTransition.ease,
|
|
1274
|
+
}));
|
|
1393
1275
|
}
|
|
1394
1276
|
}
|
|
1395
1277
|
return animations;
|
|
@@ -1397,7 +1279,7 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
1397
1279
|
|
|
1398
1280
|
const createScopedWaapiAnimate = (scope) => {
|
|
1399
1281
|
function scopedAnimate(elementOrSelector, keyframes, options) {
|
|
1400
|
-
return new motionDom.
|
|
1282
|
+
return new motionDom.GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
|
|
1401
1283
|
}
|
|
1402
1284
|
return scopedAnimate;
|
|
1403
1285
|
};
|
|
@@ -1436,8 +1318,7 @@ function getElementSize(target, borderBoxSize) {
|
|
|
1436
1318
|
}
|
|
1437
1319
|
}
|
|
1438
1320
|
function notifyTarget({ target, contentRect, borderBoxSize, }) {
|
|
1439
|
-
|
|
1440
|
-
(_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
|
|
1321
|
+
resizeHandlers.get(target)?.forEach((handler) => {
|
|
1441
1322
|
handler({
|
|
1442
1323
|
target,
|
|
1443
1324
|
contentSize: contentRect,
|
|
@@ -1466,14 +1347,14 @@ function resizeElement(target, handler) {
|
|
|
1466
1347
|
resizeHandlers.set(element, elementHandlers);
|
|
1467
1348
|
}
|
|
1468
1349
|
elementHandlers.add(handler);
|
|
1469
|
-
observer
|
|
1350
|
+
observer?.observe(element);
|
|
1470
1351
|
});
|
|
1471
1352
|
return () => {
|
|
1472
1353
|
elements.forEach((element) => {
|
|
1473
1354
|
const elementHandlers = resizeHandlers.get(element);
|
|
1474
|
-
elementHandlers
|
|
1475
|
-
if (!
|
|
1476
|
-
observer
|
|
1355
|
+
elementHandlers?.delete(handler);
|
|
1356
|
+
if (!elementHandlers?.size) {
|
|
1357
|
+
observer?.unobserve(element);
|
|
1477
1358
|
}
|
|
1478
1359
|
});
|
|
1479
1360
|
};
|
|
@@ -1852,7 +1733,6 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
|
|
|
1852
1733
|
const listener = scrollListeners.get(container);
|
|
1853
1734
|
motionDom.frame.read(listener, false, true);
|
|
1854
1735
|
return () => {
|
|
1855
|
-
var _a;
|
|
1856
1736
|
motionDom.cancelFrame(listener);
|
|
1857
1737
|
/**
|
|
1858
1738
|
* Check if we even have any handlers for this container.
|
|
@@ -1870,7 +1750,7 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
|
|
|
1870
1750
|
scrollListeners.delete(container);
|
|
1871
1751
|
if (scrollListener) {
|
|
1872
1752
|
getEventTarget(container).removeEventListener("scroll", scrollListener);
|
|
1873
|
-
|
|
1753
|
+
resizeListeners.get(container)?.();
|
|
1874
1754
|
window.removeEventListener("resize", scrollListener);
|
|
1875
1755
|
}
|
|
1876
1756
|
};
|
|
@@ -2101,8 +1981,8 @@ function useScroll({ container, target, layoutEffect = true, ...options } = {})
|
|
|
2101
1981
|
values.scrollYProgress.set(y.progress);
|
|
2102
1982
|
}, {
|
|
2103
1983
|
...options,
|
|
2104
|
-
container:
|
|
2105
|
-
target:
|
|
1984
|
+
container: container?.current || undefined,
|
|
1985
|
+
target: target?.current || undefined,
|
|
2106
1986
|
});
|
|
2107
1987
|
}, [container, target, JSON.stringify(options.offset)]);
|
|
2108
1988
|
return values;
|
|
@@ -2760,7 +2640,6 @@ const appearStoreId = (elementId, valueName) => {
|
|
|
2760
2640
|
};
|
|
2761
2641
|
|
|
2762
2642
|
function handoffOptimizedAppearAnimation(elementId, valueName, frame) {
|
|
2763
|
-
var _a;
|
|
2764
2643
|
const storeId = appearStoreId(elementId, valueName);
|
|
2765
2644
|
const optimisedAnimation = appearAnimationStore.get(storeId);
|
|
2766
2645
|
if (!optimisedAnimation) {
|
|
@@ -2768,8 +2647,7 @@ function handoffOptimizedAppearAnimation(elementId, valueName, frame) {
|
|
|
2768
2647
|
}
|
|
2769
2648
|
const { animation, startTime } = optimisedAnimation;
|
|
2770
2649
|
function cancelAnimation() {
|
|
2771
|
-
|
|
2772
|
-
(_a = window.MotionCancelOptimisedAnimation) === null || _a === void 0 ? void 0 : _a.call(window, elementId, valueName, frame);
|
|
2650
|
+
window.MotionCancelOptimisedAnimation?.(elementId, valueName, frame);
|
|
2773
2651
|
}
|
|
2774
2652
|
/**
|
|
2775
2653
|
* We can cancel the animation once it's finished now that we've synced
|
|
@@ -2779,7 +2657,7 @@ function handoffOptimizedAppearAnimation(elementId, valueName, frame) {
|
|
|
2779
2657
|
* older browsers.
|
|
2780
2658
|
*/
|
|
2781
2659
|
animation.onfinish = cancelAnimation;
|
|
2782
|
-
if (startTime === null ||
|
|
2660
|
+
if (startTime === null || window.MotionHandoffIsComplete?.(elementId)) {
|
|
2783
2661
|
/**
|
|
2784
2662
|
* If the startTime is null, this animation is the Paint Ready detection animation
|
|
2785
2663
|
* and we can cancel it immediately without handoff.
|
|
@@ -2831,7 +2709,7 @@ function startOptimizedAppearAnimation(element, name, keyframes, options, onRead
|
|
|
2831
2709
|
window.MotionHandoffAnimation = handoffOptimizedAppearAnimation;
|
|
2832
2710
|
const storeId = appearStoreId(id, name);
|
|
2833
2711
|
if (!readyAnimation) {
|
|
2834
|
-
readyAnimation =
|
|
2712
|
+
readyAnimation = motionDom.startWaapiAnimation(element, name, [keyframes[0], keyframes[0]],
|
|
2835
2713
|
/**
|
|
2836
2714
|
* 10 secs is basically just a super-safe duration to give Chrome
|
|
2837
2715
|
* long enough to get the animation ready.
|
|
@@ -2913,18 +2791,16 @@ function startOptimizedAppearAnimation(element, name, keyframes, options, onRead
|
|
|
2913
2791
|
}
|
|
2914
2792
|
};
|
|
2915
2793
|
window.MotionCheckAppearSync = (visualElement, valueName, value) => {
|
|
2916
|
-
var _a, _b;
|
|
2917
2794
|
const appearId = create.getOptimisedAppearId(visualElement);
|
|
2918
2795
|
if (!appearId)
|
|
2919
2796
|
return;
|
|
2920
|
-
const valueIsOptimised =
|
|
2921
|
-
const externalAnimationValue =
|
|
2797
|
+
const valueIsOptimised = window.MotionHasOptimisedAnimation?.(appearId, valueName);
|
|
2798
|
+
const externalAnimationValue = visualElement.props.values?.[valueName];
|
|
2922
2799
|
if (!valueIsOptimised || !externalAnimationValue)
|
|
2923
2800
|
return;
|
|
2924
2801
|
const removeSyncCheck = value.on("change", (latestValue) => {
|
|
2925
|
-
var _a;
|
|
2926
2802
|
if (externalAnimationValue.get() !== latestValue) {
|
|
2927
|
-
|
|
2803
|
+
window.MotionCancelOptimisedAnimation?.(appearId, valueName);
|
|
2928
2804
|
removeSyncCheck();
|
|
2929
2805
|
}
|
|
2930
2806
|
});
|
|
@@ -2933,7 +2809,7 @@ function startOptimizedAppearAnimation(element, name, keyframes, options, onRead
|
|
|
2933
2809
|
}
|
|
2934
2810
|
const startAnimation = () => {
|
|
2935
2811
|
readyAnimation.cancel();
|
|
2936
|
-
const appearAnimation =
|
|
2812
|
+
const appearAnimation = motionDom.startWaapiAnimation(element, name, keyframes, options);
|
|
2937
2813
|
/**
|
|
2938
2814
|
* Record the time of the first started animation. We call performance.now() once
|
|
2939
2815
|
* here and once in handoff to ensure we're getting
|
package/dist/cjs/m.js
CHANGED
|
@@ -177,7 +177,6 @@ const SwitchLayoutGroupContext = react.createContext({});
|
|
|
177
177
|
const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
|
|
178
178
|
|
|
179
179
|
function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor) {
|
|
180
|
-
var _a, _b;
|
|
181
180
|
const { visualElement: parent } = react.useContext(MotionContext);
|
|
182
181
|
const lazyContext = react.useContext(LazyContext);
|
|
183
182
|
const presenceContext = react.useContext(PresenceContext);
|
|
@@ -227,8 +226,8 @@ function useVisualElement(Component, visualState, props, createVisualElement, Pr
|
|
|
227
226
|
*/
|
|
228
227
|
const optimisedAppearId = props[optimizedAppearDataAttribute];
|
|
229
228
|
const wantsHandoff = react.useRef(Boolean(optimisedAppearId) &&
|
|
230
|
-
!
|
|
231
|
-
|
|
229
|
+
!window.MotionHandoffIsComplete?.(optimisedAppearId) &&
|
|
230
|
+
window.MotionHasOptimisedAnimation?.(optimisedAppearId));
|
|
232
231
|
useIsomorphicLayoutEffect(() => {
|
|
233
232
|
if (!visualElement)
|
|
234
233
|
return;
|
|
@@ -259,8 +258,7 @@ function useVisualElement(Component, visualState, props, createVisualElement, Pr
|
|
|
259
258
|
if (wantsHandoff.current) {
|
|
260
259
|
// This ensures all future calls to animateChanges() in this component will run in useEffect
|
|
261
260
|
queueMicrotask(() => {
|
|
262
|
-
|
|
263
|
-
(_a = window.MotionHandoffMarkAsComplete) === null || _a === void 0 ? void 0 : _a.call(window, optimisedAppearId);
|
|
261
|
+
window.MotionHandoffMarkAsComplete?.(optimisedAppearId);
|
|
264
262
|
});
|
|
265
263
|
wantsHandoff.current = false;
|
|
266
264
|
}
|
|
@@ -308,7 +306,6 @@ function getClosestProjectingNode(visualElement) {
|
|
|
308
306
|
* component "offline", or outside the React render cycle.
|
|
309
307
|
*/
|
|
310
308
|
function createRendererMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component, }) {
|
|
311
|
-
var _a, _b;
|
|
312
309
|
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
313
310
|
function MotionComponent(props, externalRef) {
|
|
314
311
|
/**
|
|
@@ -344,7 +341,7 @@ function createRendererMotionComponent({ preloadedFeatures, createVisualElement,
|
|
|
344
341
|
}
|
|
345
342
|
MotionComponent.displayName = `motion.${typeof Component === "string"
|
|
346
343
|
? Component
|
|
347
|
-
: `create(${
|
|
344
|
+
: `create(${Component.displayName ?? Component.name ?? ""})`}`;
|
|
348
345
|
const ForwardRefMotionComponent = react.forwardRef(MotionComponent);
|
|
349
346
|
ForwardRefMotionComponent[motionComponentSymbol] = Component;
|
|
350
347
|
return ForwardRefMotionComponent;
|
|
@@ -376,7 +373,7 @@ function getProjectionFunctionality(props) {
|
|
|
376
373
|
return {};
|
|
377
374
|
const combined = { ...drag, ...layout };
|
|
378
375
|
return {
|
|
379
|
-
MeasureLayout:
|
|
376
|
+
MeasureLayout: drag?.isEnabled(props) || layout?.isEnabled(props)
|
|
380
377
|
? combined.MeasureLayout
|
|
381
378
|
: undefined,
|
|
382
379
|
ProjectionNode: combined.ProjectionNode,
|
|
@@ -807,7 +804,7 @@ try {
|
|
|
807
804
|
*/
|
|
808
805
|
loadExternalIsValidProp(require("@emotion/is-prop-valid").default);
|
|
809
806
|
}
|
|
810
|
-
catch
|
|
807
|
+
catch {
|
|
811
808
|
// We don't need to actually do anything here - the fallback is the existing `isPropValid`.
|
|
812
809
|
}
|
|
813
810
|
function filterProps(props, isDom, forwardMotionProps) {
|
|
@@ -1036,7 +1033,7 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
1036
1033
|
|
|
1037
1034
|
function getValueState(visualElement) {
|
|
1038
1035
|
const state = [{}, {}];
|
|
1039
|
-
visualElement
|
|
1036
|
+
visualElement?.values.forEach((value, key) => {
|
|
1040
1037
|
state[0][key] = value.get();
|
|
1041
1038
|
state[1][key] = value.getVelocity();
|
|
1042
1039
|
});
|
|
@@ -1179,7 +1176,6 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
1179
1176
|
}
|
|
1180
1177
|
|
|
1181
1178
|
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
1182
|
-
var _a;
|
|
1183
1179
|
const { style } = props;
|
|
1184
1180
|
const newValues = {};
|
|
1185
1181
|
for (const key in style) {
|
|
@@ -1187,7 +1183,7 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
|
1187
1183
|
(prevProps.style &&
|
|
1188
1184
|
isMotionValue(prevProps.style[key])) ||
|
|
1189
1185
|
isForcedMotionValue(key, props) ||
|
|
1190
|
-
|
|
1186
|
+
visualElement?.getValue(key)?.liveStyle !== undefined) {
|
|
1191
1187
|
newValues[key] = style[key];
|
|
1192
1188
|
}
|
|
1193
1189
|
}
|
package/dist/cjs/mini.js
CHANGED
|
@@ -25,212 +25,6 @@ function useUnmountEffect(callback) {
|
|
|
25
25
|
return react.useEffect(() => () => callback(), []);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
|
|
29
|
-
const keyframeOptions = { [valueName]: keyframes };
|
|
30
|
-
if (times)
|
|
31
|
-
keyframeOptions.offset = times;
|
|
32
|
-
const easing = motionDom.mapEasingToNativeEasing(ease, duration);
|
|
33
|
-
/**
|
|
34
|
-
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
35
|
-
*/
|
|
36
|
-
if (Array.isArray(easing))
|
|
37
|
-
keyframeOptions.easing = easing;
|
|
38
|
-
if (motionDom.statsBuffer.value) {
|
|
39
|
-
motionDom.activeAnimations.waapi++;
|
|
40
|
-
}
|
|
41
|
-
const animation = element.animate(keyframeOptions, {
|
|
42
|
-
delay,
|
|
43
|
-
duration,
|
|
44
|
-
easing: !Array.isArray(easing) ? easing : "linear",
|
|
45
|
-
fill: "both",
|
|
46
|
-
iterations: repeat + 1,
|
|
47
|
-
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
48
|
-
});
|
|
49
|
-
if (motionDom.statsBuffer.value) {
|
|
50
|
-
animation.finished.finally(() => {
|
|
51
|
-
motionDom.activeAnimations.waapi--;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return animation;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const createUnitType = (unit) => ({
|
|
58
|
-
test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
|
|
59
|
-
parse: parseFloat,
|
|
60
|
-
transform: (v) => `${v}${unit}`,
|
|
61
|
-
});
|
|
62
|
-
const px = /*@__PURE__*/ createUnitType("px");
|
|
63
|
-
|
|
64
|
-
const browserNumberValueTypes = {
|
|
65
|
-
// Border props
|
|
66
|
-
borderWidth: px,
|
|
67
|
-
borderTopWidth: px,
|
|
68
|
-
borderRightWidth: px,
|
|
69
|
-
borderBottomWidth: px,
|
|
70
|
-
borderLeftWidth: px,
|
|
71
|
-
borderRadius: px,
|
|
72
|
-
radius: px,
|
|
73
|
-
borderTopLeftRadius: px,
|
|
74
|
-
borderTopRightRadius: px,
|
|
75
|
-
borderBottomRightRadius: px,
|
|
76
|
-
borderBottomLeftRadius: px,
|
|
77
|
-
// Positioning props
|
|
78
|
-
width: px,
|
|
79
|
-
maxWidth: px,
|
|
80
|
-
height: px,
|
|
81
|
-
maxHeight: px,
|
|
82
|
-
top: px,
|
|
83
|
-
right: px,
|
|
84
|
-
bottom: px,
|
|
85
|
-
left: px,
|
|
86
|
-
// Spacing props
|
|
87
|
-
padding: px,
|
|
88
|
-
paddingTop: px,
|
|
89
|
-
paddingRight: px,
|
|
90
|
-
paddingBottom: px,
|
|
91
|
-
paddingLeft: px,
|
|
92
|
-
margin: px,
|
|
93
|
-
marginTop: px,
|
|
94
|
-
marginRight: px,
|
|
95
|
-
marginBottom: px,
|
|
96
|
-
marginLeft: px,
|
|
97
|
-
// Misc
|
|
98
|
-
backgroundPositionX: px,
|
|
99
|
-
backgroundPositionY: px,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const isNotNull = (value) => value !== null;
|
|
103
|
-
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
104
|
-
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
105
|
-
const index = repeat && repeatType !== "loop" && repeat % 2 === 1
|
|
106
|
-
? 0
|
|
107
|
-
: resolvedKeyframes.length - 1;
|
|
108
|
-
return !index || finalKeyframe === undefined
|
|
109
|
-
? resolvedKeyframes[index]
|
|
110
|
-
: finalKeyframe;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function setCSSVar(element, name, value) {
|
|
114
|
-
element.style.setProperty(name, value);
|
|
115
|
-
}
|
|
116
|
-
function setStyle(element, name, value) {
|
|
117
|
-
element.style[name] = value;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
121
|
-
try {
|
|
122
|
-
document.createElement("div").animate({ opacity: [1] });
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const supportsWaapi = /*@__PURE__*/ motionUtils.memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
131
|
-
|
|
132
|
-
const state = new WeakMap();
|
|
133
|
-
function hydrateKeyframes(valueName, keyframes, read) {
|
|
134
|
-
for (let i = 0; i < keyframes.length; i++) {
|
|
135
|
-
if (keyframes[i] === null) {
|
|
136
|
-
keyframes[i] = i === 0 ? read() : keyframes[i - 1];
|
|
137
|
-
}
|
|
138
|
-
if (typeof keyframes[i] === "number" &&
|
|
139
|
-
browserNumberValueTypes[valueName]) {
|
|
140
|
-
keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (!supportsPartialKeyframes() && keyframes.length < 2) {
|
|
144
|
-
keyframes.unshift(read());
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const defaultEasing = "easeOut";
|
|
148
|
-
function getElementAnimationState(element) {
|
|
149
|
-
const animationState = state.get(element) || new Map();
|
|
150
|
-
state.set(element, animationState);
|
|
151
|
-
return state.get(element);
|
|
152
|
-
}
|
|
153
|
-
class NativeAnimation extends motionDom.NativeAnimationControls {
|
|
154
|
-
constructor(element, valueName, valueKeyframes, options) {
|
|
155
|
-
const isCSSVar = valueName.startsWith("--");
|
|
156
|
-
motionUtils.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
|
|
157
|
-
const existingAnimation = getElementAnimationState(element).get(valueName);
|
|
158
|
-
existingAnimation && existingAnimation.stop();
|
|
159
|
-
const readInitialKeyframe = () => {
|
|
160
|
-
return valueName.startsWith("--")
|
|
161
|
-
? element.style.getPropertyValue(valueName)
|
|
162
|
-
: window.getComputedStyle(element)[valueName];
|
|
163
|
-
};
|
|
164
|
-
if (!Array.isArray(valueKeyframes)) {
|
|
165
|
-
valueKeyframes = [valueKeyframes];
|
|
166
|
-
}
|
|
167
|
-
hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
|
|
168
|
-
// TODO: Replace this with toString()?
|
|
169
|
-
if (motionDom.isGenerator(options.type)) {
|
|
170
|
-
const generatorOptions = motionDom.createGeneratorEasing(options, 100, options.type);
|
|
171
|
-
options.ease = motionDom.supportsLinearEasing()
|
|
172
|
-
? generatorOptions.ease
|
|
173
|
-
: defaultEasing;
|
|
174
|
-
options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
|
|
175
|
-
options.type = "keyframes";
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
options.ease = options.ease || defaultEasing;
|
|
179
|
-
}
|
|
180
|
-
const onFinish = () => {
|
|
181
|
-
this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
|
|
182
|
-
this.cancel();
|
|
183
|
-
this.resolveFinishedPromise();
|
|
184
|
-
};
|
|
185
|
-
const init = () => {
|
|
186
|
-
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
187
|
-
this.options = options;
|
|
188
|
-
this.updateFinishedPromise();
|
|
189
|
-
this.removeAnimation = () => {
|
|
190
|
-
const elementState = state.get(element);
|
|
191
|
-
elementState && elementState.delete(valueName);
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
if (!supportsWaapi()) {
|
|
195
|
-
super();
|
|
196
|
-
init();
|
|
197
|
-
onFinish();
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
super(startWaapiAnimation(element, valueName, valueKeyframes, options));
|
|
201
|
-
init();
|
|
202
|
-
if (options.autoplay === false) {
|
|
203
|
-
this.animation.pause();
|
|
204
|
-
}
|
|
205
|
-
this.animation.onfinish = onFinish;
|
|
206
|
-
getElementAnimationState(element).set(valueName, this);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
211
|
-
* resolves when the animation finishes at all but in a future update could/should
|
|
212
|
-
* reject if its cancels.
|
|
213
|
-
*/
|
|
214
|
-
then(resolve, reject) {
|
|
215
|
-
return this.currentFinishedPromise.then(resolve, reject);
|
|
216
|
-
}
|
|
217
|
-
updateFinishedPromise() {
|
|
218
|
-
this.currentFinishedPromise = new Promise((resolve) => {
|
|
219
|
-
this.resolveFinishedPromise = resolve;
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
play() {
|
|
223
|
-
if (this.state === "finished") {
|
|
224
|
-
this.updateFinishedPromise();
|
|
225
|
-
}
|
|
226
|
-
super.play();
|
|
227
|
-
}
|
|
228
|
-
cancel() {
|
|
229
|
-
this.removeAnimation();
|
|
230
|
-
super.cancel();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
28
|
function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
235
29
|
const elements = motionDom.resolveElements(elementOrSelector, scope);
|
|
236
30
|
const numElements = elements.length;
|
|
@@ -250,13 +44,15 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
250
44
|
const valueOptions = {
|
|
251
45
|
...motionDom.getValueTransition(elementTransition, valueName),
|
|
252
46
|
};
|
|
253
|
-
valueOptions.duration = valueOptions.duration
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
47
|
+
valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
|
|
48
|
+
valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
|
|
49
|
+
animations.push(new motionDom.NativeAnimation({
|
|
50
|
+
element,
|
|
51
|
+
name: valueName,
|
|
52
|
+
keyframes: valueKeyframes,
|
|
53
|
+
transition: valueOptions,
|
|
54
|
+
allowFlatten: !elementTransition.type && !elementTransition.ease,
|
|
55
|
+
}));
|
|
260
56
|
}
|
|
261
57
|
}
|
|
262
58
|
return animations;
|
|
@@ -264,7 +60,7 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
264
60
|
|
|
265
61
|
const createScopedWaapiAnimate = (scope) => {
|
|
266
62
|
function scopedAnimate(elementOrSelector, keyframes, options) {
|
|
267
|
-
return new motionDom.
|
|
63
|
+
return new motionDom.GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
|
|
268
64
|
}
|
|
269
65
|
return scopedAnimate;
|
|
270
66
|
};
|