motion-dom 13.5.1 → 14.1.0
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/index.js +113 -67
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +19 -33
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/FollowAnimation.mjs +5 -0
- package/dist/es/animation/FollowAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +7 -2
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +1 -4
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/utils/resolve-start-time.mjs +17 -0
- package/dist/es/animation/utils/resolve-start-time.mjs.map +1 -0
- package/dist/es/index.mjs +1 -1
- package/dist/es/layout/animate-layout.mjs +19 -0
- package/dist/es/layout/animate-layout.mjs.map +1 -0
- package/dist/es/projection/node/create-projection-node.mjs +33 -8
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/render/svg/utils/build-attrs.mjs +7 -0
- package/dist/es/render/svg/utils/build-attrs.mjs.map +1 -1
- package/dist/es/render/utils/animation-state.mjs +15 -0
- package/dist/es/render/utils/animation-state.mjs.map +1 -1
- package/dist/index.d.ts +35 -25
- package/dist/motion-dom.dev.js +112 -67
- package/dist/motion-dom.js +1 -1
- package/package.json +9 -3
- package/dist/es/scroll/observe.mjs +0 -23
- package/dist/es/scroll/observe.mjs.map +0 -1
package/dist/motion-dom.dev.js
CHANGED
|
@@ -1489,6 +1489,19 @@
|
|
|
1489
1489
|
}
|
|
1490
1490
|
}
|
|
1491
1491
|
|
|
1492
|
+
/**
|
|
1493
|
+
* If an animation's keyframes resolve, or its first frame renders, more than
|
|
1494
|
+
* this long after its start time, it starts from then instead. While we prefer
|
|
1495
|
+
* to "start" an animation as soon as it's triggered, this avoids a visual jump
|
|
1496
|
+
* into it after main thread work.
|
|
1497
|
+
*
|
|
1498
|
+
* Manual timing steps frames by however long it likes, so never lags.
|
|
1499
|
+
*/
|
|
1500
|
+
const MAX_START_DELAY = 40;
|
|
1501
|
+
const resolveStartTime = (startTime, now) => now - startTime > MAX_START_DELAY && !motionUtils.MotionGlobalConfig.useManualTiming
|
|
1502
|
+
? now
|
|
1503
|
+
: startTime;
|
|
1504
|
+
|
|
1492
1505
|
function baseRecord(kind, animation) {
|
|
1493
1506
|
return {
|
|
1494
1507
|
kind,
|
|
@@ -1684,6 +1697,10 @@
|
|
|
1684
1697
|
if (this.startTime === null)
|
|
1685
1698
|
return generator.next(0);
|
|
1686
1699
|
const { delay = 0, keyframes, repeat, repeatType, repeatDelay, type, onUpdate, finalKeyframe, } = this.options;
|
|
1700
|
+
if (this.startTime === this.pendingStartTime) {
|
|
1701
|
+
this.startTime = resolveStartTime(this.startTime, timestamp);
|
|
1702
|
+
}
|
|
1703
|
+
this.pendingStartTime = undefined;
|
|
1687
1704
|
/**
|
|
1688
1705
|
* requestAnimationFrame timestamps can come through as lower than
|
|
1689
1706
|
* the startTime as set by performance.now(). Here we prevent this,
|
|
@@ -1868,10 +1885,10 @@
|
|
|
1868
1885
|
this.startTime = now;
|
|
1869
1886
|
}
|
|
1870
1887
|
else if (this.holdTime !== null) {
|
|
1871
|
-
this.startTime = now - this.holdTime;
|
|
1888
|
+
this.startTime = now - this.holdTime / (this.playbackSpeed || 1);
|
|
1872
1889
|
}
|
|
1873
1890
|
else if (!this.startTime) {
|
|
1874
|
-
this.startTime = startTime ?? now;
|
|
1891
|
+
this.startTime = startTime ?? (this.pendingStartTime = now);
|
|
1875
1892
|
}
|
|
1876
1893
|
if (this.state === "finished" && this.speed < 0) {
|
|
1877
1894
|
this.startTime += this.calculatedDuration;
|
|
@@ -2732,16 +2749,13 @@
|
|
|
2732
2749
|
/**
|
|
2733
2750
|
* Attaches a timeline to the animation, for instance the `ScrollTimeline`.
|
|
2734
2751
|
*/
|
|
2735
|
-
attachTimeline({ timeline, onAttach, observe,
|
|
2736
|
-
// Deprecated rangeStart/rangeEnd from framer-motion 13.0–13.4. Removed in v14.
|
|
2737
|
-
...range }) {
|
|
2752
|
+
attachTimeline({ timeline, onAttach, observe, }) {
|
|
2738
2753
|
if (this.allowFlatten) {
|
|
2739
2754
|
this.animation.effect?.updateTiming({ easing: "linear" });
|
|
2740
2755
|
}
|
|
2741
2756
|
this.animation.onfinish = null;
|
|
2742
2757
|
if (timeline && supportsScrollTimeline()) {
|
|
2743
2758
|
this.animation.timeline = timeline;
|
|
2744
|
-
Object.assign(this.animation, range);
|
|
2745
2759
|
onAttach?.(this.animation);
|
|
2746
2760
|
return motionUtils.noop;
|
|
2747
2761
|
}
|
|
@@ -2994,15 +3008,6 @@
|
|
|
2994
3008
|
type !== "inertia");
|
|
2995
3009
|
}
|
|
2996
3010
|
|
|
2997
|
-
/**
|
|
2998
|
-
* Maximum time allowed between an animation being created and it being
|
|
2999
|
-
* resolved for us to use the latter as the start time.
|
|
3000
|
-
*
|
|
3001
|
-
* This is to ensure that while we prefer to "start" an animation as soon
|
|
3002
|
-
* as it's triggered, we also want to avoid a visual jump if there's a big delay
|
|
3003
|
-
* between these two moments.
|
|
3004
|
-
*/
|
|
3005
|
-
const MAX_RESOLVE_DELAY = 40;
|
|
3006
3011
|
class AsyncMotionValueAnimation extends WithPromise {
|
|
3007
3012
|
constructor(options) {
|
|
3008
3013
|
super();
|
|
@@ -3051,31 +3056,7 @@
|
|
|
3051
3056
|
makeAnimationInstant(options);
|
|
3052
3057
|
options.repeat = 0;
|
|
3053
3058
|
}
|
|
3054
|
-
/**
|
|
3055
|
-
* Resolve startTime for the animation.
|
|
3056
|
-
*
|
|
3057
|
-
* This method uses the createdAt and resolvedAt to calculate the
|
|
3058
|
-
* animation startTime. *Ideally*, we would use the createdAt time as t=0
|
|
3059
|
-
* as the following frame would then be the first frame of the animation in
|
|
3060
|
-
* progress, which would feel snappier.
|
|
3061
|
-
*
|
|
3062
|
-
* However, if there's a delay (main thread work) between the creation of
|
|
3063
|
-
* the animation and the first committed frame, we prefer to use resolvedAt
|
|
3064
|
-
* to avoid a sudden jump into the animation.
|
|
3065
|
-
*/
|
|
3066
|
-
const startTime = sync
|
|
3067
|
-
? !this.resolvedAt
|
|
3068
|
-
? this.createdAt
|
|
3069
|
-
: this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY
|
|
3070
|
-
? this.resolvedAt
|
|
3071
|
-
: this.createdAt
|
|
3072
|
-
: undefined;
|
|
3073
3059
|
const { onComplete } = options;
|
|
3074
|
-
/**
|
|
3075
|
-
* A startTime passed in options (an optimised appear handoff syncing
|
|
3076
|
-
* to its WAAPI animation) takes precedence over the derived one.
|
|
3077
|
-
*/
|
|
3078
|
-
options.startTime ?? (options.startTime = startTime);
|
|
3079
3060
|
options.finalKeyframe = finalKeyframe;
|
|
3080
3061
|
options.keyframes = keyframes;
|
|
3081
3062
|
/**
|
|
@@ -3096,6 +3077,24 @@
|
|
|
3096
3077
|
* values may not be valid CSS and would trigger browser warnings.
|
|
3097
3078
|
*/
|
|
3098
3079
|
const useWaapi = canAnimateValue && !isHandoff && supportsBrowserAnimation(options);
|
|
3080
|
+
/**
|
|
3081
|
+
* Resolve startTime for the animation. A startTime passed in options
|
|
3082
|
+
* (an optimised appear handoff syncing to its WAAPI animation) takes
|
|
3083
|
+
* precedence.
|
|
3084
|
+
*
|
|
3085
|
+
* *Ideally*, we would use the createdAt time as t=0 as the following
|
|
3086
|
+
* frame would then be the first frame of the animation in progress,
|
|
3087
|
+
* which would feel snappier. If keyframes resolved on a later frame,
|
|
3088
|
+
* and long after creation, we start from then instead.
|
|
3089
|
+
*
|
|
3090
|
+
* If they resolved immediately, a JSAnimation picks its own start
|
|
3091
|
+
* time and resolves it the same way on its first frame, so every
|
|
3092
|
+
* animation started in that moment stays in sync. WAAPI has no frame
|
|
3093
|
+
* of ours to do that on.
|
|
3094
|
+
*/
|
|
3095
|
+
if (sync && (useWaapi || this.resolvedAt !== this.createdAt)) {
|
|
3096
|
+
options.startTime ?? (options.startTime = resolveStartTime(this.createdAt, this.resolvedAt));
|
|
3097
|
+
}
|
|
3099
3098
|
let animation;
|
|
3100
3099
|
if (useWaapi) {
|
|
3101
3100
|
/**
|
|
@@ -5195,9 +5194,16 @@
|
|
|
5195
5194
|
attrs[keys.array] = `${length} ${spacing}`;
|
|
5196
5195
|
}
|
|
5197
5196
|
|
|
5197
|
+
/**
|
|
5198
|
+
* Values rendered via style rather than as attributes. This must include
|
|
5199
|
+
* every value WAAPI can accelerate, as WAAPI writes its final value to
|
|
5200
|
+
* style, which would otherwise override later attribute writes.
|
|
5201
|
+
*/
|
|
5198
5202
|
const cssStyleProperties = [
|
|
5199
5203
|
"transform",
|
|
5200
5204
|
"opacity",
|
|
5205
|
+
"clipPath",
|
|
5206
|
+
"filter",
|
|
5201
5207
|
"offsetDistance",
|
|
5202
5208
|
"offsetPath",
|
|
5203
5209
|
"offsetRotate",
|
|
@@ -6053,25 +6059,6 @@
|
|
|
6053
6059
|
return typeof a === "function" ? resizeWindow(a) : resizeElement(a, b);
|
|
6054
6060
|
}
|
|
6055
6061
|
|
|
6056
|
-
/**
|
|
6057
|
-
* @deprecated Kept because framer-motion 13.0–13.4 import it from
|
|
6058
|
-
* motion-dom with a ^ range. Removed in v14.
|
|
6059
|
-
*/
|
|
6060
|
-
function observeTimeline(update, timeline) {
|
|
6061
|
-
let prevProgress;
|
|
6062
|
-
const onFrame = () => {
|
|
6063
|
-
const { currentTime } = timeline;
|
|
6064
|
-
const percentage = currentTime === null ? 0 : currentTime.value;
|
|
6065
|
-
const progress = percentage / 100;
|
|
6066
|
-
if (prevProgress !== progress) {
|
|
6067
|
-
update(progress);
|
|
6068
|
-
}
|
|
6069
|
-
prevProgress = progress;
|
|
6070
|
-
};
|
|
6071
|
-
frame.preUpdate(onFrame, true);
|
|
6072
|
-
return () => cancelFrame(onFrame);
|
|
6073
|
-
}
|
|
6074
|
-
|
|
6075
6062
|
const statsBuffer = {
|
|
6076
6063
|
value: null,
|
|
6077
6064
|
addProjectionMetrics: null,
|
|
@@ -6230,6 +6217,10 @@
|
|
|
6230
6217
|
tick(timestamp) {
|
|
6231
6218
|
const { options, hasNextTarget: retargeted } = this;
|
|
6232
6219
|
const { delay = 0, onUpdate, onPlay } = options;
|
|
6220
|
+
// Retargets happen on a tick, so only the first start can lag
|
|
6221
|
+
if (!this.started) {
|
|
6222
|
+
this.startTime = resolveStartTime(this.startTime, timestamp);
|
|
6223
|
+
}
|
|
6233
6224
|
const elapsed = Math.round(timestamp - this.startTime) - delay;
|
|
6234
6225
|
const t = (this.currentTime = Math.max(0, elapsed));
|
|
6235
6226
|
const state = this.generator.next(t);
|
|
@@ -8786,6 +8777,20 @@
|
|
|
8786
8777
|
: visualElement.initialValues[key] === undefined
|
|
8787
8778
|
? visualElement.baseTarget[key]
|
|
8788
8779
|
: undefined) ?? null;
|
|
8780
|
+
/**
|
|
8781
|
+
* If it stays where it is, that's now its base. Otherwise a
|
|
8782
|
+
* later removal (like a gesture ending) would also stay,
|
|
8783
|
+
* leaving the value stuck. Stop first so accelerated
|
|
8784
|
+
* animations sync the value they reached. In practice initial
|
|
8785
|
+
* only changes like this with Fast Refresh, so this is
|
|
8786
|
+
* dev-only (#3787).
|
|
8787
|
+
*/
|
|
8788
|
+
if (fallbackAnimation[key] === null &&
|
|
8789
|
+
visualElement.initialValues[key] !== undefined) {
|
|
8790
|
+
delete visualElement.initialValues[key];
|
|
8791
|
+
motionValue?.stop();
|
|
8792
|
+
visualElement.baseTarget[key] = motionValue?.get();
|
|
8793
|
+
}
|
|
8789
8794
|
});
|
|
8790
8795
|
animations.push({ animation: fallbackAnimation });
|
|
8791
8796
|
}
|
|
@@ -9657,7 +9662,7 @@
|
|
|
9657
9662
|
visualElement &&
|
|
9658
9663
|
(layoutId || layout)) {
|
|
9659
9664
|
this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeLayoutChanged, layout: newLayout, }) => {
|
|
9660
|
-
if (this.
|
|
9665
|
+
if (this.isAnimationBlocked) {
|
|
9661
9666
|
this.target = undefined;
|
|
9662
9667
|
this.relativeTarget = undefined;
|
|
9663
9668
|
return;
|
|
@@ -9749,11 +9754,6 @@
|
|
|
9749
9754
|
isUpdateBlocked() {
|
|
9750
9755
|
return this.updateManuallyBlocked || this.updateBlockedByResize;
|
|
9751
9756
|
}
|
|
9752
|
-
isTreeAnimationBlocked() {
|
|
9753
|
-
return (this.isAnimationBlocked ||
|
|
9754
|
-
(this.parent && this.parent.isTreeAnimationBlocked()) ||
|
|
9755
|
-
false);
|
|
9756
|
-
}
|
|
9757
9757
|
// Note: currently only running on root node
|
|
9758
9758
|
startUpdate() {
|
|
9759
9759
|
if (this.isUpdateBlocked())
|
|
@@ -9807,6 +9807,14 @@
|
|
|
9807
9807
|
if (node.options.layoutRoot) {
|
|
9808
9808
|
node.willUpdate(false);
|
|
9809
9809
|
}
|
|
9810
|
+
/**
|
|
9811
|
+
* Measure the nearest dragged ancestor before the DOM
|
|
9812
|
+
* changes, so this node can follow its layout change.
|
|
9813
|
+
*/
|
|
9814
|
+
if (node.isAnimationBlocked) {
|
|
9815
|
+
node.dragSnapshot || (node.dragSnapshot = node.measure());
|
|
9816
|
+
this.dragAncestor = node;
|
|
9817
|
+
}
|
|
9810
9818
|
}
|
|
9811
9819
|
const { layoutId, layout } = this.options;
|
|
9812
9820
|
if (layoutId === undefined && !layout)
|
|
@@ -10814,7 +10822,11 @@
|
|
|
10814
10822
|
}
|
|
10815
10823
|
}
|
|
10816
10824
|
clearSnapshot() {
|
|
10817
|
-
this.resumeFrom =
|
|
10825
|
+
this.resumeFrom =
|
|
10826
|
+
this.snapshot =
|
|
10827
|
+
this.dragSnapshot =
|
|
10828
|
+
this.dragAncestor =
|
|
10829
|
+
undefined;
|
|
10818
10830
|
}
|
|
10819
10831
|
// Only run on root
|
|
10820
10832
|
resetTree() {
|
|
@@ -10824,8 +10836,13 @@
|
|
|
10824
10836
|
}
|
|
10825
10837
|
};
|
|
10826
10838
|
}
|
|
10839
|
+
/**
|
|
10840
|
+
* Nodes are depth-ordered, so a dragged ancestor's layout is updated before
|
|
10841
|
+
* its descendants'.
|
|
10842
|
+
*/
|
|
10827
10843
|
function updateLayout(node) {
|
|
10828
10844
|
node.updateLayout();
|
|
10845
|
+
followDraggedAncestor(node);
|
|
10829
10846
|
}
|
|
10830
10847
|
function notifyLayoutUpdate(node) {
|
|
10831
10848
|
const snapshot = node.resumeFrom?.snapshot || node.snapshot;
|
|
@@ -10974,6 +10991,19 @@
|
|
|
10974
10991
|
function clearIsLayoutDirty(node) {
|
|
10975
10992
|
node.isLayoutDirty = false;
|
|
10976
10993
|
}
|
|
10994
|
+
/**
|
|
10995
|
+
* A dragged node doesn't layout animate, so it jumps to its new layout. Shift
|
|
10996
|
+
* its descendants' snapshots by the same amount, so they only animate layout
|
|
10997
|
+
* changes relative to it, rather than lagging behind.
|
|
10998
|
+
*/
|
|
10999
|
+
function followDraggedAncestor(node) {
|
|
11000
|
+
const { snapshot, dragAncestor } = node;
|
|
11001
|
+
const to = dragAncestor?.layout;
|
|
11002
|
+
if (!snapshot || !to || node.resumeFrom || node.isAnimationBlocked)
|
|
11003
|
+
return;
|
|
11004
|
+
const from = dragAncestor.dragSnapshot;
|
|
11005
|
+
eachAxis((axis) => translateAxis(snapshot.layoutBox[axis], to.layoutBox[axis].min - from.layoutBox[axis].min));
|
|
11006
|
+
}
|
|
10977
11007
|
/**
|
|
10978
11008
|
* When a node is animation-blocked (e.g. during drag) and its component
|
|
10979
11009
|
* didn't re-render (memoized), willUpdate() is never called so there's
|
|
@@ -10982,7 +11012,7 @@
|
|
|
10982
11012
|
*/
|
|
10983
11013
|
function ensureDraggedNodesSnapshotted(node) {
|
|
10984
11014
|
if (node.isAnimationBlocked && node.layout && !node.isLayoutDirty) {
|
|
10985
|
-
node.snapshot = node.layout;
|
|
11015
|
+
node.snapshot = node.dragSnapshot || node.layout;
|
|
10986
11016
|
node.isLayoutDirty = true;
|
|
10987
11017
|
}
|
|
10988
11018
|
}
|
|
@@ -11483,6 +11513,21 @@
|
|
|
11483
11513
|
};
|
|
11484
11514
|
}
|
|
11485
11515
|
|
|
11516
|
+
/**
|
|
11517
|
+
* Animate layout changes made within `updateDom` on elements tagged
|
|
11518
|
+
* with `data-layout` or `data-layout-id`.
|
|
11519
|
+
*
|
|
11520
|
+
* ```
|
|
11521
|
+
* animateLayout(() => {
|
|
11522
|
+
* element.style.justifyContent = "flex-end"
|
|
11523
|
+
* })
|
|
11524
|
+
* ```
|
|
11525
|
+
*/
|
|
11526
|
+
function animateLayout(scopeOrUpdateDom, updateDomOrOptions, options) {
|
|
11527
|
+
const { scope, updateDom, defaultOptions } = parseAnimateLayoutArgs(scopeOrUpdateDom, updateDomOrOptions, options);
|
|
11528
|
+
return new LayoutAnimationBuilder(scope, updateDom, defaultOptions);
|
|
11529
|
+
}
|
|
11530
|
+
|
|
11486
11531
|
/**
|
|
11487
11532
|
* @deprecated
|
|
11488
11533
|
*
|
|
@@ -11534,6 +11579,7 @@
|
|
|
11534
11579
|
exports.analyseComplexValue = analyseComplexValue;
|
|
11535
11580
|
exports.animateEffectSubject = animateEffectSubject;
|
|
11536
11581
|
exports.animateElement = animateElement;
|
|
11582
|
+
exports.animateLayout = animateLayout;
|
|
11537
11583
|
exports.animateMotionValue = animateMotionValue;
|
|
11538
11584
|
exports.animateSingleValue = animateSingleValue;
|
|
11539
11585
|
exports.animateTarget = animateTarget;
|
|
@@ -11701,7 +11747,6 @@
|
|
|
11701
11747
|
exports.nodeGroup = nodeGroup;
|
|
11702
11748
|
exports.number = number;
|
|
11703
11749
|
exports.numberValueTypes = numberValueTypes;
|
|
11704
|
-
exports.observeTimeline = observeTimeline;
|
|
11705
11750
|
exports.optimizedAppearDataAttribute = optimizedAppearDataAttribute;
|
|
11706
11751
|
exports.optimizedAppearDataId = optimizedAppearDataId;
|
|
11707
11752
|
exports.originProps = originProps;
|