framer-motion 12.4.12 → 12.5.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/client.js +1 -1
- package/dist/cjs/{create-Da6xW2BP.js → create-BErQMR-o.js} +4283 -4778
- package/dist/cjs/debug.js +5 -281
- package/dist/cjs/dom-mini.js +9 -7
- package/dist/cjs/dom.js +164 -659
- package/dist/cjs/index.js +1555 -1553
- package/dist/cjs/m.js +11 -179
- package/dist/cjs/mini.js +8 -0
- package/dist/debug.d.ts +2 -35
- package/dist/dom-mini.d.ts +1 -181
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +3 -242
- package/dist/dom.js +1 -1
- package/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/animation/animators/BaseAnimation.mjs +1 -1
- package/dist/es/animation/animators/MainThreadAnimation.mjs +1 -2
- package/dist/es/animation/animators/drivers/driver-frameloop.mjs +1 -2
- package/dist/es/animation/animators/waapi/index.mjs +1 -3
- package/dist/es/animation/generators/utils/velocity.mjs +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs +2 -4
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
- package/dist/es/animation/optimized-appear/start.mjs +3 -3
- package/dist/es/animation/sequence/utils/edit.mjs +1 -1
- package/dist/es/components/AnimatePresence/index.mjs +1 -1
- package/dist/es/components/Reorder/utils/check-reorder.mjs +1 -1
- package/dist/es/debug.mjs +1 -1
- package/dist/es/dom.mjs +1 -5
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -2
- package/dist/es/gestures/hover.mjs +1 -2
- package/dist/es/gestures/pan/PanSession.mjs +1 -2
- package/dist/es/gestures/pan/index.mjs +1 -1
- package/dist/es/gestures/press.mjs +1 -2
- package/dist/es/index.mjs +14 -19
- package/dist/es/motion/features/layout/MeasureLayout.mjs +1 -2
- package/dist/es/motion/utils/use-visual-element.mjs +6 -6
- package/dist/es/projection/node/create-projection-node.mjs +2 -8
- package/dist/es/projection/shared/stack.mjs +1 -1
- package/dist/es/projection.mjs +1 -3
- package/dist/es/render/VisualElement.mjs +2 -5
- package/dist/es/render/components/create-proxy.mjs +1 -1
- package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
- package/dist/es/render/dom/scroll/info.mjs +1 -2
- package/dist/es/render/dom/scroll/observe.mjs +1 -1
- package/dist/es/render/dom/scroll/on-scroll-handler.mjs +1 -1
- package/dist/es/render/dom/scroll/track.mjs +1 -1
- package/dist/es/render/dom/utils/unit-conversion.mjs +3 -20
- package/dist/es/render/html/HTMLVisualElement.mjs +2 -3
- package/dist/es/render/html/utils/parse-transform.mjs +83 -0
- package/dist/es/render/svg/SVGVisualElement.mjs +1 -1
- package/dist/es/render/svg/config-motion.mjs +1 -1
- package/dist/es/render/utils/KeyframesResolver.mjs +1 -1
- package/dist/es/render/utils/flat-tree.mjs +1 -1
- package/dist/es/render/utils/motion-values.mjs +3 -3
- package/dist/es/render/utils/setters.mjs +1 -1
- package/dist/es/utils/delay.mjs +1 -2
- package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +1 -1
- package/dist/es/utils/use-animation-frame.mjs +1 -1
- package/dist/es/utils/use-force-update.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +1 -1
- package/dist/es/value/scroll/use-element-scroll.mjs +1 -1
- package/dist/es/value/scroll/use-viewport-scroll.mjs +1 -1
- package/dist/es/value/use-combine-values.mjs +2 -2
- package/dist/es/value/use-computed.mjs +1 -1
- package/dist/es/value/use-inverted-scale.mjs +3 -3
- package/dist/es/value/use-motion-value.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +4 -4
- package/dist/es/value/use-spring.mjs +1 -1
- package/dist/es/value/use-transform.mjs +1 -1
- package/dist/es/value/use-velocity.mjs +1 -1
- package/dist/es/value/use-will-change/WillChangeMotionValue.mjs +2 -2
- package/dist/framer-motion.dev.js +8320 -8281
- package/dist/framer-motion.js +1 -1
- package/dist/m.d.ts +49 -241
- package/dist/size-rollup-animate.js +1 -1
- 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-rollup-scroll.js +1 -1
- package/dist/types/client.d.ts +2 -2
- package/dist/types/index.d.ts +43 -79
- package/dist/{types.d-6pKw1mTI.d.ts → types.d-B50aGbjN.d.ts} +81 -289
- package/package.json +5 -6
- package/dist/es/frameloop/batcher.mjs +0 -69
- package/dist/es/frameloop/frame.mjs +0 -6
- package/dist/es/frameloop/index-legacy.mjs +0 -20
- package/dist/es/frameloop/microtask.mjs +0 -5
- package/dist/es/frameloop/order.mjs +0 -10
- package/dist/es/frameloop/render-step.mjs +0 -92
- package/dist/es/frameloop/sync-time.mjs +0 -31
- package/dist/es/stats/animation-count.mjs +0 -7
- package/dist/es/stats/buffer.mjs +0 -6
- package/dist/es/stats/index.mjs +0 -113
- package/dist/es/utils/GlobalConfig.mjs +0 -6
- package/dist/es/utils/array.mjs +0 -21
- package/dist/es/utils/subscription-manager.mjs +0 -40
- package/dist/es/utils/velocity-per-second.mjs +0 -11
- package/dist/es/utils/warn-once.mjs +0 -11
- package/dist/es/value/index.mjs +0 -319
- package/dist/three.d.ts +0 -2833
package/dist/cjs/dom.js
CHANGED
|
@@ -13,20 +13,10 @@ const clamp = (min, max, v) => {
|
|
|
13
13
|
return v;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
/*
|
|
17
|
-
Convert velocity into velocity per second
|
|
18
|
-
|
|
19
|
-
@param [number]: Unit per frame
|
|
20
|
-
@param [number]: Frame duration in ms
|
|
21
|
-
*/
|
|
22
|
-
function velocityPerSecond(velocity, frameDuration) {
|
|
23
|
-
return frameDuration ? velocity * (1000 / frameDuration) : 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
const velocitySampleDuration = 5; // ms
|
|
27
17
|
function calcGeneratorVelocity(resolveValue, t, current) {
|
|
28
18
|
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
29
|
-
return velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
19
|
+
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
30
20
|
}
|
|
31
21
|
|
|
32
22
|
const springDefaults = {
|
|
@@ -390,21 +380,11 @@ function calcNextTime(current, next, prev, labels) {
|
|
|
390
380
|
}
|
|
391
381
|
}
|
|
392
382
|
|
|
393
|
-
function addUniqueItem(arr, item) {
|
|
394
|
-
if (arr.indexOf(item) === -1)
|
|
395
|
-
arr.push(item);
|
|
396
|
-
}
|
|
397
|
-
function removeItem(arr, item) {
|
|
398
|
-
const index = arr.indexOf(item);
|
|
399
|
-
if (index > -1)
|
|
400
|
-
arr.splice(index, 1);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
383
|
function eraseKeyframes(sequence, startTime, endTime) {
|
|
404
384
|
for (let i = 0; i < sequence.length; i++) {
|
|
405
385
|
const keyframe = sequence[i];
|
|
406
386
|
if (keyframe.at > startTime && keyframe.at < endTime) {
|
|
407
|
-
removeItem(sequence, keyframe);
|
|
387
|
+
motionUtils.removeItem(sequence, keyframe);
|
|
408
388
|
// If we remove this item we have to push the pointer back one
|
|
409
389
|
i--;
|
|
410
390
|
}
|
|
@@ -692,178 +672,6 @@ const isNumberKeyframesArray = (keyframes) => keyframes.every(isNumber);
|
|
|
692
672
|
|
|
693
673
|
const visualElementStore = new WeakMap();
|
|
694
674
|
|
|
695
|
-
const MotionGlobalConfig = {
|
|
696
|
-
skipAnimations: false,
|
|
697
|
-
useManualTiming: false,
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
const stepsOrder = [
|
|
701
|
-
"read", // Read
|
|
702
|
-
"resolveKeyframes", // Write/Read/Write/Read
|
|
703
|
-
"update", // Compute
|
|
704
|
-
"preRender", // Compute
|
|
705
|
-
"render", // Write
|
|
706
|
-
"postRender", // Compute
|
|
707
|
-
];
|
|
708
|
-
|
|
709
|
-
const statsBuffer = {
|
|
710
|
-
value: null,
|
|
711
|
-
addProjectionMetrics: null,
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
function createRenderStep(runNextFrame, stepName) {
|
|
715
|
-
/**
|
|
716
|
-
* We create and reuse two queues, one to queue jobs for the current frame
|
|
717
|
-
* and one for the next. We reuse to avoid triggering GC after x frames.
|
|
718
|
-
*/
|
|
719
|
-
let thisFrame = new Set();
|
|
720
|
-
let nextFrame = new Set();
|
|
721
|
-
/**
|
|
722
|
-
* Track whether we're currently processing jobs in this step. This way
|
|
723
|
-
* we can decide whether to schedule new jobs for this frame or next.
|
|
724
|
-
*/
|
|
725
|
-
let isProcessing = false;
|
|
726
|
-
let flushNextFrame = false;
|
|
727
|
-
/**
|
|
728
|
-
* A set of processes which were marked keepAlive when scheduled.
|
|
729
|
-
*/
|
|
730
|
-
const toKeepAlive = new WeakSet();
|
|
731
|
-
let latestFrameData = {
|
|
732
|
-
delta: 0.0,
|
|
733
|
-
timestamp: 0.0,
|
|
734
|
-
isProcessing: false,
|
|
735
|
-
};
|
|
736
|
-
let numCalls = 0;
|
|
737
|
-
function triggerCallback(callback) {
|
|
738
|
-
if (toKeepAlive.has(callback)) {
|
|
739
|
-
step.schedule(callback);
|
|
740
|
-
runNextFrame();
|
|
741
|
-
}
|
|
742
|
-
numCalls++;
|
|
743
|
-
callback(latestFrameData);
|
|
744
|
-
}
|
|
745
|
-
const step = {
|
|
746
|
-
/**
|
|
747
|
-
* Schedule a process to run on the next frame.
|
|
748
|
-
*/
|
|
749
|
-
schedule: (callback, keepAlive = false, immediate = false) => {
|
|
750
|
-
const addToCurrentFrame = immediate && isProcessing;
|
|
751
|
-
const queue = addToCurrentFrame ? thisFrame : nextFrame;
|
|
752
|
-
if (keepAlive)
|
|
753
|
-
toKeepAlive.add(callback);
|
|
754
|
-
if (!queue.has(callback))
|
|
755
|
-
queue.add(callback);
|
|
756
|
-
return callback;
|
|
757
|
-
},
|
|
758
|
-
/**
|
|
759
|
-
* Cancel the provided callback from running on the next frame.
|
|
760
|
-
*/
|
|
761
|
-
cancel: (callback) => {
|
|
762
|
-
nextFrame.delete(callback);
|
|
763
|
-
toKeepAlive.delete(callback);
|
|
764
|
-
},
|
|
765
|
-
/**
|
|
766
|
-
* Execute all schedule callbacks.
|
|
767
|
-
*/
|
|
768
|
-
process: (frameData) => {
|
|
769
|
-
latestFrameData = frameData;
|
|
770
|
-
/**
|
|
771
|
-
* If we're already processing we've probably been triggered by a flushSync
|
|
772
|
-
* inside an existing process. Instead of executing, mark flushNextFrame
|
|
773
|
-
* as true and ensure we flush the following frame at the end of this one.
|
|
774
|
-
*/
|
|
775
|
-
if (isProcessing) {
|
|
776
|
-
flushNextFrame = true;
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
isProcessing = true;
|
|
780
|
-
[thisFrame, nextFrame] = [nextFrame, thisFrame];
|
|
781
|
-
// Execute this frame
|
|
782
|
-
thisFrame.forEach(triggerCallback);
|
|
783
|
-
/**
|
|
784
|
-
* If we're recording stats then
|
|
785
|
-
*/
|
|
786
|
-
if (stepName && statsBuffer.value) {
|
|
787
|
-
statsBuffer.value.frameloop[stepName].push(numCalls);
|
|
788
|
-
}
|
|
789
|
-
numCalls = 0;
|
|
790
|
-
// Clear the frame so no callbacks remain. This is to avoid
|
|
791
|
-
// memory leaks should this render step not run for a while.
|
|
792
|
-
thisFrame.clear();
|
|
793
|
-
isProcessing = false;
|
|
794
|
-
if (flushNextFrame) {
|
|
795
|
-
flushNextFrame = false;
|
|
796
|
-
step.process(frameData);
|
|
797
|
-
}
|
|
798
|
-
},
|
|
799
|
-
};
|
|
800
|
-
return step;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
const maxElapsed$1 = 40;
|
|
804
|
-
function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
|
|
805
|
-
let runNextFrame = false;
|
|
806
|
-
let useDefaultElapsed = true;
|
|
807
|
-
const state = {
|
|
808
|
-
delta: 0.0,
|
|
809
|
-
timestamp: 0.0,
|
|
810
|
-
isProcessing: false,
|
|
811
|
-
};
|
|
812
|
-
const flagRunNextFrame = () => (runNextFrame = true);
|
|
813
|
-
const steps = stepsOrder.reduce((acc, key) => {
|
|
814
|
-
acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
|
|
815
|
-
return acc;
|
|
816
|
-
}, {});
|
|
817
|
-
const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
|
|
818
|
-
const processBatch = () => {
|
|
819
|
-
const timestamp = performance.now();
|
|
820
|
-
runNextFrame = false;
|
|
821
|
-
{
|
|
822
|
-
state.delta = useDefaultElapsed
|
|
823
|
-
? 1000 / 60
|
|
824
|
-
: Math.max(Math.min(timestamp - state.timestamp, maxElapsed$1), 1);
|
|
825
|
-
}
|
|
826
|
-
state.timestamp = timestamp;
|
|
827
|
-
state.isProcessing = true;
|
|
828
|
-
// Unrolled render loop for better per-frame performance
|
|
829
|
-
read.process(state);
|
|
830
|
-
resolveKeyframes.process(state);
|
|
831
|
-
update.process(state);
|
|
832
|
-
preRender.process(state);
|
|
833
|
-
render.process(state);
|
|
834
|
-
postRender.process(state);
|
|
835
|
-
state.isProcessing = false;
|
|
836
|
-
if (runNextFrame && allowKeepAlive) {
|
|
837
|
-
useDefaultElapsed = false;
|
|
838
|
-
scheduleNextBatch(processBatch);
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
const wake = () => {
|
|
842
|
-
runNextFrame = true;
|
|
843
|
-
useDefaultElapsed = true;
|
|
844
|
-
if (!state.isProcessing) {
|
|
845
|
-
scheduleNextBatch(processBatch);
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
const schedule = stepsOrder.reduce((acc, key) => {
|
|
849
|
-
const step = steps[key];
|
|
850
|
-
acc[key] = (process, keepAlive = false, immediate = false) => {
|
|
851
|
-
if (!runNextFrame)
|
|
852
|
-
wake();
|
|
853
|
-
return step.schedule(process, keepAlive, immediate);
|
|
854
|
-
};
|
|
855
|
-
return acc;
|
|
856
|
-
}, {});
|
|
857
|
-
const cancel = (process) => {
|
|
858
|
-
for (let i = 0; i < stepsOrder.length; i++) {
|
|
859
|
-
steps[stepsOrder[i]].cancel(process);
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
return { schedule, cancel, state, steps };
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
|
|
866
|
-
|
|
867
675
|
/**
|
|
868
676
|
* Generate a list of every possible transform key.
|
|
869
677
|
*/
|
|
@@ -910,386 +718,6 @@ const resolveFinalValueInKeyframes = (v) => {
|
|
|
910
718
|
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
911
719
|
};
|
|
912
720
|
|
|
913
|
-
let now;
|
|
914
|
-
function clearTime() {
|
|
915
|
-
now = undefined;
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* An eventloop-synchronous alternative to performance.now().
|
|
919
|
-
*
|
|
920
|
-
* Ensures that time measurements remain consistent within a synchronous context.
|
|
921
|
-
* Usually calling performance.now() twice within the same synchronous context
|
|
922
|
-
* will return different values which isn't useful for animations when we're usually
|
|
923
|
-
* trying to sync animations to the same frame.
|
|
924
|
-
*/
|
|
925
|
-
const time = {
|
|
926
|
-
now: () => {
|
|
927
|
-
if (now === undefined) {
|
|
928
|
-
time.set(frameData.isProcessing || MotionGlobalConfig.useManualTiming
|
|
929
|
-
? frameData.timestamp
|
|
930
|
-
: performance.now());
|
|
931
|
-
}
|
|
932
|
-
return now;
|
|
933
|
-
},
|
|
934
|
-
set: (newTime) => {
|
|
935
|
-
now = newTime;
|
|
936
|
-
queueMicrotask(clearTime);
|
|
937
|
-
},
|
|
938
|
-
};
|
|
939
|
-
|
|
940
|
-
class SubscriptionManager {
|
|
941
|
-
constructor() {
|
|
942
|
-
this.subscriptions = [];
|
|
943
|
-
}
|
|
944
|
-
add(handler) {
|
|
945
|
-
addUniqueItem(this.subscriptions, handler);
|
|
946
|
-
return () => removeItem(this.subscriptions, handler);
|
|
947
|
-
}
|
|
948
|
-
notify(a, b, c) {
|
|
949
|
-
const numSubscriptions = this.subscriptions.length;
|
|
950
|
-
if (!numSubscriptions)
|
|
951
|
-
return;
|
|
952
|
-
if (numSubscriptions === 1) {
|
|
953
|
-
/**
|
|
954
|
-
* If there's only a single handler we can just call it without invoking a loop.
|
|
955
|
-
*/
|
|
956
|
-
this.subscriptions[0](a, b, c);
|
|
957
|
-
}
|
|
958
|
-
else {
|
|
959
|
-
for (let i = 0; i < numSubscriptions; i++) {
|
|
960
|
-
/**
|
|
961
|
-
* Check whether the handler exists before firing as it's possible
|
|
962
|
-
* the subscriptions were modified during this loop running.
|
|
963
|
-
*/
|
|
964
|
-
const handler = this.subscriptions[i];
|
|
965
|
-
handler && handler(a, b, c);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
getSize() {
|
|
970
|
-
return this.subscriptions.length;
|
|
971
|
-
}
|
|
972
|
-
clear() {
|
|
973
|
-
this.subscriptions.length = 0;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
const warned = new Set();
|
|
978
|
-
function warnOnce(condition, message, element) {
|
|
979
|
-
if (condition || warned.has(message))
|
|
980
|
-
return;
|
|
981
|
-
console.warn(message);
|
|
982
|
-
if (element)
|
|
983
|
-
console.warn(element);
|
|
984
|
-
warned.add(message);
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* Maximum time between the value of two frames, beyond which we
|
|
989
|
-
* assume the velocity has since been 0.
|
|
990
|
-
*/
|
|
991
|
-
const MAX_VELOCITY_DELTA = 30;
|
|
992
|
-
const isFloat = (value) => {
|
|
993
|
-
return !isNaN(parseFloat(value));
|
|
994
|
-
};
|
|
995
|
-
/**
|
|
996
|
-
* `MotionValue` is used to track the state and velocity of motion values.
|
|
997
|
-
*
|
|
998
|
-
* @public
|
|
999
|
-
*/
|
|
1000
|
-
class MotionValue {
|
|
1001
|
-
/**
|
|
1002
|
-
* @param init - The initiating value
|
|
1003
|
-
* @param config - Optional configuration options
|
|
1004
|
-
*
|
|
1005
|
-
* - `transformer`: A function to transform incoming values with.
|
|
1006
|
-
*
|
|
1007
|
-
* @internal
|
|
1008
|
-
*/
|
|
1009
|
-
constructor(init, options = {}) {
|
|
1010
|
-
/**
|
|
1011
|
-
* This will be replaced by the build step with the latest version number.
|
|
1012
|
-
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1013
|
-
*/
|
|
1014
|
-
this.version = "12.4.12";
|
|
1015
|
-
/**
|
|
1016
|
-
* Tracks whether this value can output a velocity. Currently this is only true
|
|
1017
|
-
* if the value is numerical, but we might be able to widen the scope here and support
|
|
1018
|
-
* other value types.
|
|
1019
|
-
*
|
|
1020
|
-
* @internal
|
|
1021
|
-
*/
|
|
1022
|
-
this.canTrackVelocity = null;
|
|
1023
|
-
/**
|
|
1024
|
-
* An object containing a SubscriptionManager for each active event.
|
|
1025
|
-
*/
|
|
1026
|
-
this.events = {};
|
|
1027
|
-
this.updateAndNotify = (v, render = true) => {
|
|
1028
|
-
const currentTime = time.now();
|
|
1029
|
-
/**
|
|
1030
|
-
* If we're updating the value during another frame or eventloop
|
|
1031
|
-
* than the previous frame, then the we set the previous frame value
|
|
1032
|
-
* to current.
|
|
1033
|
-
*/
|
|
1034
|
-
if (this.updatedAt !== currentTime) {
|
|
1035
|
-
this.setPrevFrameValue();
|
|
1036
|
-
}
|
|
1037
|
-
this.prev = this.current;
|
|
1038
|
-
this.setCurrent(v);
|
|
1039
|
-
// Update update subscribers
|
|
1040
|
-
if (this.current !== this.prev && this.events.change) {
|
|
1041
|
-
this.events.change.notify(this.current);
|
|
1042
|
-
}
|
|
1043
|
-
// Update render subscribers
|
|
1044
|
-
if (render && this.events.renderRequest) {
|
|
1045
|
-
this.events.renderRequest.notify(this.current);
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
this.hasAnimated = false;
|
|
1049
|
-
this.setCurrent(init);
|
|
1050
|
-
this.owner = options.owner;
|
|
1051
|
-
}
|
|
1052
|
-
setCurrent(current) {
|
|
1053
|
-
this.current = current;
|
|
1054
|
-
this.updatedAt = time.now();
|
|
1055
|
-
if (this.canTrackVelocity === null && current !== undefined) {
|
|
1056
|
-
this.canTrackVelocity = isFloat(this.current);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
setPrevFrameValue(prevFrameValue = this.current) {
|
|
1060
|
-
this.prevFrameValue = prevFrameValue;
|
|
1061
|
-
this.prevUpdatedAt = this.updatedAt;
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Adds a function that will be notified when the `MotionValue` is updated.
|
|
1065
|
-
*
|
|
1066
|
-
* It returns a function that, when called, will cancel the subscription.
|
|
1067
|
-
*
|
|
1068
|
-
* When calling `onChange` inside a React component, it should be wrapped with the
|
|
1069
|
-
* `useEffect` hook. As it returns an unsubscribe function, this should be returned
|
|
1070
|
-
* from the `useEffect` function to ensure you don't add duplicate subscribers..
|
|
1071
|
-
*
|
|
1072
|
-
* ```jsx
|
|
1073
|
-
* export const MyComponent = () => {
|
|
1074
|
-
* const x = useMotionValue(0)
|
|
1075
|
-
* const y = useMotionValue(0)
|
|
1076
|
-
* const opacity = useMotionValue(1)
|
|
1077
|
-
*
|
|
1078
|
-
* useEffect(() => {
|
|
1079
|
-
* function updateOpacity() {
|
|
1080
|
-
* const maxXY = Math.max(x.get(), y.get())
|
|
1081
|
-
* const newOpacity = transform(maxXY, [0, 100], [1, 0])
|
|
1082
|
-
* opacity.set(newOpacity)
|
|
1083
|
-
* }
|
|
1084
|
-
*
|
|
1085
|
-
* const unsubscribeX = x.on("change", updateOpacity)
|
|
1086
|
-
* const unsubscribeY = y.on("change", updateOpacity)
|
|
1087
|
-
*
|
|
1088
|
-
* return () => {
|
|
1089
|
-
* unsubscribeX()
|
|
1090
|
-
* unsubscribeY()
|
|
1091
|
-
* }
|
|
1092
|
-
* }, [])
|
|
1093
|
-
*
|
|
1094
|
-
* return <motion.div style={{ x }} />
|
|
1095
|
-
* }
|
|
1096
|
-
* ```
|
|
1097
|
-
*
|
|
1098
|
-
* @param subscriber - A function that receives the latest value.
|
|
1099
|
-
* @returns A function that, when called, will cancel this subscription.
|
|
1100
|
-
*
|
|
1101
|
-
* @deprecated
|
|
1102
|
-
*/
|
|
1103
|
-
onChange(subscription) {
|
|
1104
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1105
|
-
warnOnce(false, `value.onChange(callback) is deprecated. Switch to value.on("change", callback).`);
|
|
1106
|
-
}
|
|
1107
|
-
return this.on("change", subscription);
|
|
1108
|
-
}
|
|
1109
|
-
on(eventName, callback) {
|
|
1110
|
-
if (!this.events[eventName]) {
|
|
1111
|
-
this.events[eventName] = new SubscriptionManager();
|
|
1112
|
-
}
|
|
1113
|
-
const unsubscribe = this.events[eventName].add(callback);
|
|
1114
|
-
if (eventName === "change") {
|
|
1115
|
-
return () => {
|
|
1116
|
-
unsubscribe();
|
|
1117
|
-
/**
|
|
1118
|
-
* If we have no more change listeners by the start
|
|
1119
|
-
* of the next frame, stop active animations.
|
|
1120
|
-
*/
|
|
1121
|
-
frame.read(() => {
|
|
1122
|
-
if (!this.events.change.getSize()) {
|
|
1123
|
-
this.stop();
|
|
1124
|
-
}
|
|
1125
|
-
});
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
return unsubscribe;
|
|
1129
|
-
}
|
|
1130
|
-
clearListeners() {
|
|
1131
|
-
for (const eventManagers in this.events) {
|
|
1132
|
-
this.events[eventManagers].clear();
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Attaches a passive effect to the `MotionValue`.
|
|
1137
|
-
*
|
|
1138
|
-
* @internal
|
|
1139
|
-
*/
|
|
1140
|
-
attach(passiveEffect, stopPassiveEffect) {
|
|
1141
|
-
this.passiveEffect = passiveEffect;
|
|
1142
|
-
this.stopPassiveEffect = stopPassiveEffect;
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Sets the state of the `MotionValue`.
|
|
1146
|
-
*
|
|
1147
|
-
* @remarks
|
|
1148
|
-
*
|
|
1149
|
-
* ```jsx
|
|
1150
|
-
* const x = useMotionValue(0)
|
|
1151
|
-
* x.set(10)
|
|
1152
|
-
* ```
|
|
1153
|
-
*
|
|
1154
|
-
* @param latest - Latest value to set.
|
|
1155
|
-
* @param render - Whether to notify render subscribers. Defaults to `true`
|
|
1156
|
-
*
|
|
1157
|
-
* @public
|
|
1158
|
-
*/
|
|
1159
|
-
set(v, render = true) {
|
|
1160
|
-
if (!render || !this.passiveEffect) {
|
|
1161
|
-
this.updateAndNotify(v, render);
|
|
1162
|
-
}
|
|
1163
|
-
else {
|
|
1164
|
-
this.passiveEffect(v, this.updateAndNotify);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
setWithVelocity(prev, current, delta) {
|
|
1168
|
-
this.set(current);
|
|
1169
|
-
this.prev = undefined;
|
|
1170
|
-
this.prevFrameValue = prev;
|
|
1171
|
-
this.prevUpdatedAt = this.updatedAt - delta;
|
|
1172
|
-
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Set the state of the `MotionValue`, stopping any active animations,
|
|
1175
|
-
* effects, and resets velocity to `0`.
|
|
1176
|
-
*/
|
|
1177
|
-
jump(v, endAnimation = true) {
|
|
1178
|
-
this.updateAndNotify(v);
|
|
1179
|
-
this.prev = v;
|
|
1180
|
-
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
1181
|
-
endAnimation && this.stop();
|
|
1182
|
-
if (this.stopPassiveEffect)
|
|
1183
|
-
this.stopPassiveEffect();
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
* Returns the latest state of `MotionValue`
|
|
1187
|
-
*
|
|
1188
|
-
* @returns - The latest state of `MotionValue`
|
|
1189
|
-
*
|
|
1190
|
-
* @public
|
|
1191
|
-
*/
|
|
1192
|
-
get() {
|
|
1193
|
-
return this.current;
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* @public
|
|
1197
|
-
*/
|
|
1198
|
-
getPrevious() {
|
|
1199
|
-
return this.prev;
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Returns the latest velocity of `MotionValue`
|
|
1203
|
-
*
|
|
1204
|
-
* @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
|
|
1205
|
-
*
|
|
1206
|
-
* @public
|
|
1207
|
-
*/
|
|
1208
|
-
getVelocity() {
|
|
1209
|
-
const currentTime = time.now();
|
|
1210
|
-
if (!this.canTrackVelocity ||
|
|
1211
|
-
this.prevFrameValue === undefined ||
|
|
1212
|
-
currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
|
|
1213
|
-
return 0;
|
|
1214
|
-
}
|
|
1215
|
-
const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
|
|
1216
|
-
// Casts because of parseFloat's poor typing
|
|
1217
|
-
return velocityPerSecond(parseFloat(this.current) -
|
|
1218
|
-
parseFloat(this.prevFrameValue), delta);
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Registers a new animation to control this `MotionValue`. Only one
|
|
1222
|
-
* animation can drive a `MotionValue` at one time.
|
|
1223
|
-
*
|
|
1224
|
-
* ```jsx
|
|
1225
|
-
* value.start()
|
|
1226
|
-
* ```
|
|
1227
|
-
*
|
|
1228
|
-
* @param animation - A function that starts the provided animation
|
|
1229
|
-
*
|
|
1230
|
-
* @internal
|
|
1231
|
-
*/
|
|
1232
|
-
start(startAnimation) {
|
|
1233
|
-
this.stop();
|
|
1234
|
-
return new Promise((resolve) => {
|
|
1235
|
-
this.hasAnimated = true;
|
|
1236
|
-
this.animation = startAnimation(resolve);
|
|
1237
|
-
if (this.events.animationStart) {
|
|
1238
|
-
this.events.animationStart.notify();
|
|
1239
|
-
}
|
|
1240
|
-
}).then(() => {
|
|
1241
|
-
if (this.events.animationComplete) {
|
|
1242
|
-
this.events.animationComplete.notify();
|
|
1243
|
-
}
|
|
1244
|
-
this.clearAnimation();
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
/**
|
|
1248
|
-
* Stop the currently active animation.
|
|
1249
|
-
*
|
|
1250
|
-
* @public
|
|
1251
|
-
*/
|
|
1252
|
-
stop() {
|
|
1253
|
-
if (this.animation) {
|
|
1254
|
-
this.animation.stop();
|
|
1255
|
-
if (this.events.animationCancel) {
|
|
1256
|
-
this.events.animationCancel.notify();
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
this.clearAnimation();
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Returns `true` if this value is currently animating.
|
|
1263
|
-
*
|
|
1264
|
-
* @public
|
|
1265
|
-
*/
|
|
1266
|
-
isAnimating() {
|
|
1267
|
-
return !!this.animation;
|
|
1268
|
-
}
|
|
1269
|
-
clearAnimation() {
|
|
1270
|
-
delete this.animation;
|
|
1271
|
-
}
|
|
1272
|
-
/**
|
|
1273
|
-
* Destroy and clean up subscribers to this `MotionValue`.
|
|
1274
|
-
*
|
|
1275
|
-
* The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
|
|
1276
|
-
* handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
|
|
1277
|
-
* created a `MotionValue` via the `motionValue` function.
|
|
1278
|
-
*
|
|
1279
|
-
* @public
|
|
1280
|
-
*/
|
|
1281
|
-
destroy() {
|
|
1282
|
-
this.clearListeners();
|
|
1283
|
-
this.stop();
|
|
1284
|
-
if (this.stopPassiveEffect) {
|
|
1285
|
-
this.stopPassiveEffect();
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
function motionValue(init, options) {
|
|
1290
|
-
return new MotionValue(init, options);
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
721
|
function getValueState(visualElement) {
|
|
1294
722
|
const state = [{}, {}];
|
|
1295
723
|
visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
|
|
@@ -1339,7 +767,7 @@ function setMotionValue(visualElement, key, value) {
|
|
|
1339
767
|
visualElement.getValue(key).set(value);
|
|
1340
768
|
}
|
|
1341
769
|
else {
|
|
1342
|
-
visualElement.addValue(key, motionValue(value));
|
|
770
|
+
visualElement.addValue(key, motionDom.motionValue(value));
|
|
1343
771
|
}
|
|
1344
772
|
}
|
|
1345
773
|
function setTarget(visualElement, definition) {
|
|
@@ -1877,25 +1305,89 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
|
|
|
1877
1305
|
}
|
|
1878
1306
|
}
|
|
1879
1307
|
|
|
1880
|
-
const
|
|
1881
|
-
const
|
|
1882
|
-
const
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1308
|
+
const radToDeg = (rad) => (rad * 180) / Math.PI;
|
|
1309
|
+
const rotate = (v) => {
|
|
1310
|
+
const angle = radToDeg(Math.atan2(v[1], v[0]));
|
|
1311
|
+
return rebaseAngle(angle);
|
|
1312
|
+
};
|
|
1313
|
+
const matrix2dParsers = {
|
|
1314
|
+
x: 4,
|
|
1315
|
+
y: 5,
|
|
1316
|
+
translateX: 4,
|
|
1317
|
+
translateY: 5,
|
|
1318
|
+
scaleX: 0,
|
|
1319
|
+
scaleY: 3,
|
|
1320
|
+
scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
|
|
1321
|
+
rotate,
|
|
1322
|
+
rotateZ: rotate,
|
|
1323
|
+
skewX: (v) => radToDeg(Math.atan(v[1])),
|
|
1324
|
+
skewY: (v) => radToDeg(Math.atan(v[2])),
|
|
1325
|
+
skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,
|
|
1326
|
+
};
|
|
1327
|
+
const rebaseAngle = (angle) => {
|
|
1328
|
+
angle = angle % 360;
|
|
1329
|
+
if (angle < 0)
|
|
1330
|
+
angle += 360;
|
|
1331
|
+
return angle;
|
|
1332
|
+
};
|
|
1333
|
+
const rotateZ = rotate;
|
|
1334
|
+
const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
1335
|
+
const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
|
|
1336
|
+
const matrix3dParsers = {
|
|
1337
|
+
x: 12,
|
|
1338
|
+
y: 13,
|
|
1339
|
+
z: 14,
|
|
1340
|
+
translateX: 12,
|
|
1341
|
+
translateY: 13,
|
|
1342
|
+
translateZ: 14,
|
|
1343
|
+
scaleX,
|
|
1344
|
+
scaleY,
|
|
1345
|
+
scale: (v) => (scaleX(v) + scaleY(v)) / 2,
|
|
1346
|
+
rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
|
|
1347
|
+
rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
|
|
1348
|
+
rotateZ,
|
|
1349
|
+
rotate: rotateZ,
|
|
1350
|
+
skewX: (v) => radToDeg(Math.atan(v[4])),
|
|
1351
|
+
skewY: (v) => radToDeg(Math.atan(v[1])),
|
|
1352
|
+
skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,
|
|
1353
|
+
};
|
|
1354
|
+
function defaultTransformValue(name) {
|
|
1355
|
+
return name.includes("scale") ? 1 : 0;
|
|
1356
|
+
}
|
|
1357
|
+
function parseValueFromTransform(transform, name) {
|
|
1358
|
+
if (!transform || transform === "none") {
|
|
1359
|
+
return defaultTransformValue(name);
|
|
1888
1360
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
return 0;
|
|
1896
|
-
}
|
|
1361
|
+
const matrix3dMatch = transform.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);
|
|
1362
|
+
let parsers;
|
|
1363
|
+
let match;
|
|
1364
|
+
if (matrix3dMatch) {
|
|
1365
|
+
parsers = matrix3dParsers;
|
|
1366
|
+
match = matrix3dMatch;
|
|
1897
1367
|
}
|
|
1368
|
+
else {
|
|
1369
|
+
const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
|
|
1370
|
+
parsers = matrix2dParsers;
|
|
1371
|
+
match = matrix2dMatch;
|
|
1372
|
+
}
|
|
1373
|
+
if (!match) {
|
|
1374
|
+
return defaultTransformValue(name);
|
|
1375
|
+
}
|
|
1376
|
+
const valueParser = parsers[name];
|
|
1377
|
+
const values = match[1].split(",").map(convertTransformToNumber);
|
|
1378
|
+
return typeof valueParser === "function"
|
|
1379
|
+
? valueParser(values)
|
|
1380
|
+
: values[valueParser];
|
|
1381
|
+
}
|
|
1382
|
+
const readTransformValue = (instance, name) => {
|
|
1383
|
+
const { transform = "none" } = getComputedStyle(instance);
|
|
1384
|
+
return parseValueFromTransform(transform, name);
|
|
1898
1385
|
};
|
|
1386
|
+
function convertTransformToNumber(value) {
|
|
1387
|
+
return parseFloat(value.trim());
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
const isNumOrPxType = (v) => v === number || v === px;
|
|
1899
1391
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
1900
1392
|
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
1901
1393
|
function removeNonTranslationalTransform(visualElement) {
|
|
@@ -1918,8 +1410,8 @@ const positionalValues = {
|
|
|
1918
1410
|
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
1919
1411
|
right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
|
|
1920
1412
|
// Transform
|
|
1921
|
-
x:
|
|
1922
|
-
y:
|
|
1413
|
+
x: (_bbox, { transform }) => parseValueFromTransform(transform, "x"),
|
|
1414
|
+
y: (_bbox, { transform }) => parseValueFromTransform(transform, "y"),
|
|
1923
1415
|
};
|
|
1924
1416
|
// Alias translate longform names
|
|
1925
1417
|
positionalValues.translateX = positionalValues.x;
|
|
@@ -2019,8 +1511,8 @@ class KeyframeResolver {
|
|
|
2019
1511
|
toResolve.add(this);
|
|
2020
1512
|
if (!isScheduled) {
|
|
2021
1513
|
isScheduled = true;
|
|
2022
|
-
frame.read(readAllKeyframes);
|
|
2023
|
-
frame.resolveKeyframes(measureAllKeyframes);
|
|
1514
|
+
motionDom.frame.read(readAllKeyframes);
|
|
1515
|
+
motionDom.frame.resolveKeyframes(measureAllKeyframes);
|
|
2024
1516
|
}
|
|
2025
1517
|
}
|
|
2026
1518
|
else {
|
|
@@ -2373,7 +1865,7 @@ class BaseAnimation {
|
|
|
2373
1865
|
// Track whether the animation has been stopped. Stopped animations won't restart.
|
|
2374
1866
|
this.isStopped = false;
|
|
2375
1867
|
this.hasAttemptedResolve = false;
|
|
2376
|
-
this.createdAt = time.now();
|
|
1868
|
+
this.createdAt = motionDom.time.now();
|
|
2377
1869
|
this.options = {
|
|
2378
1870
|
autoplay,
|
|
2379
1871
|
delay,
|
|
@@ -2419,7 +1911,7 @@ class BaseAnimation {
|
|
|
2419
1911
|
* Otherwise, it will call initPlayback on the implementing class.
|
|
2420
1912
|
*/
|
|
2421
1913
|
onKeyframesResolved(keyframes, finalKeyframe) {
|
|
2422
|
-
this.resolvedAt = time.now();
|
|
1914
|
+
this.resolvedAt = motionDom.time.now();
|
|
2423
1915
|
this.hasAttemptedResolve = true;
|
|
2424
1916
|
const { name, type, velocity, delay, onComplete, onUpdate, isGenerator, } = this.options;
|
|
2425
1917
|
/**
|
|
@@ -2908,13 +2400,13 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
2908
2400
|
const frameloopDriver = (update) => {
|
|
2909
2401
|
const passTimestamp = ({ timestamp }) => update(timestamp);
|
|
2910
2402
|
return {
|
|
2911
|
-
start: () => frame.update(passTimestamp, true),
|
|
2912
|
-
stop: () => cancelFrame(passTimestamp),
|
|
2403
|
+
start: () => motionDom.frame.update(passTimestamp, true),
|
|
2404
|
+
stop: () => motionDom.cancelFrame(passTimestamp),
|
|
2913
2405
|
/**
|
|
2914
2406
|
* If we're processing this frame we can use the
|
|
2915
2407
|
* framelocked timestamp to keep things in sync.
|
|
2916
2408
|
*/
|
|
2917
|
-
now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),
|
|
2409
|
+
now: () => (motionDom.frameData.isProcessing ? motionDom.frameData.timestamp : motionDom.time.now()),
|
|
2918
2410
|
};
|
|
2919
2411
|
};
|
|
2920
2412
|
|
|
@@ -3046,6 +2538,7 @@ class MainThreadAnimation extends BaseAnimation {
|
|
|
3046
2538
|
}
|
|
3047
2539
|
onPostResolved() {
|
|
3048
2540
|
const { autoplay = true } = this.options;
|
|
2541
|
+
motionDom.activeAnimations.mainThread++;
|
|
3049
2542
|
this.play();
|
|
3050
2543
|
if (this.pendingPlayState === "paused" || !autoplay) {
|
|
3051
2544
|
this.pause();
|
|
@@ -3277,6 +2770,7 @@ class MainThreadAnimation extends BaseAnimation {
|
|
|
3277
2770
|
this.updateFinishedPromise();
|
|
3278
2771
|
this.startTime = this.cancelTime = null;
|
|
3279
2772
|
this.resolver.cancel();
|
|
2773
|
+
motionDom.activeAnimations.mainThread--;
|
|
3280
2774
|
}
|
|
3281
2775
|
stopDriver() {
|
|
3282
2776
|
if (!this.driver)
|
|
@@ -3313,6 +2807,9 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
|
|
|
3313
2807
|
*/
|
|
3314
2808
|
if (Array.isArray(easing))
|
|
3315
2809
|
keyframeOptions.easing = easing;
|
|
2810
|
+
if (motionDom.statsBuffer.value) {
|
|
2811
|
+
motionDom.activeAnimations.waapi++;
|
|
2812
|
+
}
|
|
3316
2813
|
const animation = element.animate(keyframeOptions, {
|
|
3317
2814
|
delay,
|
|
3318
2815
|
duration,
|
|
@@ -3321,6 +2818,11 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
|
|
|
3321
2818
|
iterations: repeat + 1,
|
|
3322
2819
|
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
3323
2820
|
});
|
|
2821
|
+
if (motionDom.statsBuffer.value) {
|
|
2822
|
+
animation.finished.finally(() => {
|
|
2823
|
+
motionDom.activeAnimations.waapi--;
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
3324
2826
|
return animation;
|
|
3325
2827
|
}
|
|
3326
2828
|
|
|
@@ -3739,6 +3241,11 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3739
3241
|
shouldSkip = true;
|
|
3740
3242
|
}
|
|
3741
3243
|
}
|
|
3244
|
+
if (motionUtils.MotionGlobalConfig.skipAnimations) {
|
|
3245
|
+
shouldSkip = true;
|
|
3246
|
+
options.duration = 0;
|
|
3247
|
+
options.delay = 0;
|
|
3248
|
+
}
|
|
3742
3249
|
/**
|
|
3743
3250
|
* If the transition type or easing has been explicitly set by the user
|
|
3744
3251
|
* then we don't want to allow flattening the animation.
|
|
@@ -3752,7 +3259,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3752
3259
|
if (shouldSkip && !isHandoff && value.get() !== undefined) {
|
|
3753
3260
|
const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
|
|
3754
3261
|
if (finalKeyframe !== undefined) {
|
|
3755
|
-
frame.update(() => {
|
|
3262
|
+
motionDom.frame.update(() => {
|
|
3756
3263
|
options.onUpdate(finalKeyframe);
|
|
3757
3264
|
options.onComplete();
|
|
3758
3265
|
});
|
|
@@ -3814,7 +3321,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
3814
3321
|
if (window.MotionHandoffAnimation) {
|
|
3815
3322
|
const appearId = getOptimisedAppearId(visualElement);
|
|
3816
3323
|
if (appearId) {
|
|
3817
|
-
const startTime = window.MotionHandoffAnimation(appearId, key, frame);
|
|
3324
|
+
const startTime = window.MotionHandoffAnimation(appearId, key, motionDom.frame);
|
|
3818
3325
|
if (startTime !== null) {
|
|
3819
3326
|
valueTransition.startTime = startTime;
|
|
3820
3327
|
isHandoff = true;
|
|
@@ -3832,7 +3339,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
3832
3339
|
}
|
|
3833
3340
|
if (transitionEnd) {
|
|
3834
3341
|
Promise.all(animations).then(() => {
|
|
3835
|
-
frame.update(() => {
|
|
3342
|
+
motionDom.frame.update(() => {
|
|
3836
3343
|
transitionEnd && setTarget(visualElement, transitionEnd);
|
|
3837
3344
|
});
|
|
3838
3345
|
});
|
|
@@ -3954,7 +3461,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3954
3461
|
* and warn against mismatches.
|
|
3955
3462
|
*/
|
|
3956
3463
|
if (process.env.NODE_ENV === "development") {
|
|
3957
|
-
warnOnce(nextValue.version === "12.
|
|
3464
|
+
motionUtils.warnOnce(nextValue.version === "12.5.0", `Attempting to mix Motion versions ${nextValue.version} with 12.5.0 may not work as expected.`);
|
|
3958
3465
|
}
|
|
3959
3466
|
}
|
|
3960
3467
|
else if (isMotionValue(prevValue)) {
|
|
@@ -3962,7 +3469,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3962
3469
|
* If we're swapping from a motion value to a static value,
|
|
3963
3470
|
* create a new motion value from that
|
|
3964
3471
|
*/
|
|
3965
|
-
element.addValue(key, motionValue(nextValue, { owner: element }));
|
|
3472
|
+
element.addValue(key, motionDom.motionValue(nextValue, { owner: element }));
|
|
3966
3473
|
}
|
|
3967
3474
|
else if (prevValue !== nextValue) {
|
|
3968
3475
|
/**
|
|
@@ -3981,7 +3488,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3981
3488
|
}
|
|
3982
3489
|
else {
|
|
3983
3490
|
const latestValue = element.getStaticValue(key);
|
|
3984
|
-
element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue, { owner: element }));
|
|
3491
|
+
element.addValue(key, motionDom.motionValue(latestValue !== undefined ? latestValue : nextValue, { owner: element }));
|
|
3985
3492
|
}
|
|
3986
3493
|
}
|
|
3987
3494
|
}
|
|
@@ -4081,10 +3588,10 @@ class VisualElement {
|
|
|
4081
3588
|
};
|
|
4082
3589
|
this.renderScheduledAt = 0.0;
|
|
4083
3590
|
this.scheduleRender = () => {
|
|
4084
|
-
const now = time.now();
|
|
3591
|
+
const now = motionDom.time.now();
|
|
4085
3592
|
if (this.renderScheduledAt < now) {
|
|
4086
3593
|
this.renderScheduledAt = now;
|
|
4087
|
-
frame.render(this.render, false, true);
|
|
3594
|
+
motionDom.frame.render(this.render, false, true);
|
|
4088
3595
|
}
|
|
4089
3596
|
};
|
|
4090
3597
|
const { latestValues, renderState, onUpdate } = visualState;
|
|
@@ -4144,7 +3651,7 @@ class VisualElement {
|
|
|
4144
3651
|
? true
|
|
4145
3652
|
: prefersReducedMotion.current;
|
|
4146
3653
|
if (process.env.NODE_ENV !== "production") {
|
|
4147
|
-
warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.");
|
|
3654
|
+
motionUtils.warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.");
|
|
4148
3655
|
}
|
|
4149
3656
|
if (this.parent)
|
|
4150
3657
|
this.parent.children.add(this);
|
|
@@ -4152,8 +3659,8 @@ class VisualElement {
|
|
|
4152
3659
|
}
|
|
4153
3660
|
unmount() {
|
|
4154
3661
|
this.projection && this.projection.unmount();
|
|
4155
|
-
cancelFrame(this.notifyUpdate);
|
|
4156
|
-
cancelFrame(this.render);
|
|
3662
|
+
motionDom.cancelFrame(this.notifyUpdate);
|
|
3663
|
+
motionDom.cancelFrame(this.render);
|
|
4157
3664
|
this.valueSubscriptions.forEach((remove) => remove());
|
|
4158
3665
|
this.valueSubscriptions.clear();
|
|
4159
3666
|
this.removeFromVariantTree && this.removeFromVariantTree();
|
|
@@ -4180,7 +3687,7 @@ class VisualElement {
|
|
|
4180
3687
|
}
|
|
4181
3688
|
const removeOnChange = value.on("change", (latestValue) => {
|
|
4182
3689
|
this.latestValues[key] = latestValue;
|
|
4183
|
-
this.props.onUpdate && frame.preRender(this.notifyUpdate);
|
|
3690
|
+
this.props.onUpdate && motionDom.frame.preRender(this.notifyUpdate);
|
|
4184
3691
|
if (valueIsTransform && this.projection) {
|
|
4185
3692
|
this.projection.isTransformDirty = true;
|
|
4186
3693
|
}
|
|
@@ -4367,7 +3874,7 @@ class VisualElement {
|
|
|
4367
3874
|
}
|
|
4368
3875
|
let value = this.values.get(key);
|
|
4369
3876
|
if (value === undefined && defaultValue !== undefined) {
|
|
4370
|
-
value = motionValue(defaultValue === null ? undefined : defaultValue, { owner: this });
|
|
3877
|
+
value = motionDom.motionValue(defaultValue === null ? undefined : defaultValue, { owner: this });
|
|
4371
3878
|
this.addValue(key, value);
|
|
4372
3879
|
}
|
|
4373
3880
|
return value;
|
|
@@ -4440,7 +3947,7 @@ class VisualElement {
|
|
|
4440
3947
|
}
|
|
4441
3948
|
on(eventName, callback) {
|
|
4442
3949
|
if (!this.events[eventName]) {
|
|
4443
|
-
this.events[eventName] = new SubscriptionManager();
|
|
3950
|
+
this.events[eventName] = new motionUtils.SubscriptionManager();
|
|
4444
3951
|
}
|
|
4445
3952
|
return this.events[eventName].add(callback);
|
|
4446
3953
|
}
|
|
@@ -4835,7 +4342,7 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
4835
4342
|
}
|
|
4836
4343
|
onBindTransform() {
|
|
4837
4344
|
if (this.current && !this.renderState.dimensions) {
|
|
4838
|
-
frame.postRender(this.updateDimensions);
|
|
4345
|
+
motionDom.frame.postRender(this.updateDimensions);
|
|
4839
4346
|
}
|
|
4840
4347
|
}
|
|
4841
4348
|
build(renderState, latestValues, props) {
|
|
@@ -4894,8 +4401,7 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
4894
4401
|
}
|
|
4895
4402
|
readValueFromInstance(instance, key) {
|
|
4896
4403
|
if (transformProps.has(key)) {
|
|
4897
|
-
|
|
4898
|
-
return defaultType ? defaultType.default || 0 : 0;
|
|
4404
|
+
return readTransformValue(instance, key);
|
|
4899
4405
|
}
|
|
4900
4406
|
else {
|
|
4901
4407
|
const computedStyle = getComputedStyle$1(instance);
|
|
@@ -4991,9 +4497,9 @@ function createObjectVisualElement(subject) {
|
|
|
4991
4497
|
}
|
|
4992
4498
|
|
|
4993
4499
|
function animateSingleValue(value, keyframes, options) {
|
|
4994
|
-
const motionValue
|
|
4995
|
-
motionValue
|
|
4996
|
-
return motionValue
|
|
4500
|
+
const motionValue = isMotionValue(value) ? value : motionDom.motionValue(value);
|
|
4501
|
+
motionValue.start(animateMotionValue("", motionValue, keyframes, options));
|
|
4502
|
+
return motionValue.animation;
|
|
4997
4503
|
}
|
|
4998
4504
|
|
|
4999
4505
|
function isSingleValue(subject, keyframes) {
|
|
@@ -5245,8 +4751,8 @@ function observeTimeline(update, timeline) {
|
|
|
5245
4751
|
}
|
|
5246
4752
|
prevProgress = progress;
|
|
5247
4753
|
};
|
|
5248
|
-
frame.update(onFrame, true);
|
|
5249
|
-
return () => cancelFrame(onFrame);
|
|
4754
|
+
motionDom.frame.update(onFrame, true);
|
|
4755
|
+
return () => motionDom.cancelFrame(onFrame);
|
|
5250
4756
|
}
|
|
5251
4757
|
|
|
5252
4758
|
const resizeHandlers = new WeakMap();
|
|
@@ -5387,7 +4893,7 @@ function updateAxisInfo(element, axisName, info, time) {
|
|
|
5387
4893
|
axis.velocity =
|
|
5388
4894
|
elapsed > maxElapsed
|
|
5389
4895
|
? 0
|
|
5390
|
-
: velocityPerSecond(axis.current - prev, elapsed);
|
|
4896
|
+
: motionUtils.velocityPerSecond(axis.current - prev, elapsed);
|
|
5391
4897
|
}
|
|
5392
4898
|
function updateScrollInfo(element, info, time) {
|
|
5393
4899
|
updateAxisInfo(element, "x", info, time);
|
|
@@ -5612,7 +5118,7 @@ function measure(container, target = container, info) {
|
|
|
5612
5118
|
*/
|
|
5613
5119
|
if (process.env.NODE_ENV !== "production") {
|
|
5614
5120
|
if (container && target && target !== container) {
|
|
5615
|
-
warnOnce(getComputedStyle(container).position !== "static", "Please ensure that the container has a non-static position, like 'relative', 'fixed', or 'absolute' to ensure scroll offset is calculated correctly.");
|
|
5121
|
+
motionUtils.warnOnce(getComputedStyle(container).position !== "static", "Please ensure that the container has a non-static position, like 'relative', 'fixed', or 'absolute' to ensure scroll offset is calculated correctly.");
|
|
5616
5122
|
}
|
|
5617
5123
|
}
|
|
5618
5124
|
}
|
|
@@ -5660,7 +5166,7 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
|
|
|
5660
5166
|
};
|
|
5661
5167
|
const updateAll = () => {
|
|
5662
5168
|
for (const handler of containerHandlers) {
|
|
5663
|
-
handler.update(frameData.timestamp);
|
|
5169
|
+
handler.update(motionDom.frameData.timestamp);
|
|
5664
5170
|
}
|
|
5665
5171
|
};
|
|
5666
5172
|
const notifyAll = () => {
|
|
@@ -5668,9 +5174,9 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
|
|
|
5668
5174
|
handler.notify();
|
|
5669
5175
|
};
|
|
5670
5176
|
const listener = () => {
|
|
5671
|
-
frame.read(measureAll, false, true);
|
|
5672
|
-
frame.read(updateAll, false, true);
|
|
5673
|
-
frame.update(notifyAll, false, true);
|
|
5177
|
+
motionDom.frame.read(measureAll, false, true);
|
|
5178
|
+
motionDom.frame.read(updateAll, false, true);
|
|
5179
|
+
motionDom.frame.update(notifyAll, false, true);
|
|
5674
5180
|
};
|
|
5675
5181
|
scrollListeners.set(container, listener);
|
|
5676
5182
|
const target = getEventTarget(container);
|
|
@@ -5681,10 +5187,10 @@ function scrollInfo(onScroll, { container = document.documentElement, ...options
|
|
|
5681
5187
|
target.addEventListener("scroll", listener, { passive: true });
|
|
5682
5188
|
}
|
|
5683
5189
|
const listener = scrollListeners.get(container);
|
|
5684
|
-
frame.read(listener, false, true);
|
|
5190
|
+
motionDom.frame.read(listener, false, true);
|
|
5685
5191
|
return () => {
|
|
5686
5192
|
var _a;
|
|
5687
|
-
cancelFrame(listener);
|
|
5193
|
+
motionDom.cancelFrame(listener);
|
|
5688
5194
|
/**
|
|
5689
5195
|
* Check if we even have any handlers for this container.
|
|
5690
5196
|
*/
|
|
@@ -5867,16 +5373,16 @@ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
|
|
|
5867
5373
|
* Timeout defined in ms
|
|
5868
5374
|
*/
|
|
5869
5375
|
function delay(callback, timeout) {
|
|
5870
|
-
const start = time.now();
|
|
5376
|
+
const start = motionDom.time.now();
|
|
5871
5377
|
const checkElapsed = ({ timestamp }) => {
|
|
5872
5378
|
const elapsed = timestamp - start;
|
|
5873
5379
|
if (elapsed >= timeout) {
|
|
5874
|
-
cancelFrame(checkElapsed);
|
|
5380
|
+
motionDom.cancelFrame(checkElapsed);
|
|
5875
5381
|
callback(elapsed - timeout);
|
|
5876
5382
|
}
|
|
5877
5383
|
};
|
|
5878
|
-
frame.read(checkElapsed, true);
|
|
5879
|
-
return () => cancelFrame(checkElapsed);
|
|
5384
|
+
motionDom.frame.read(checkElapsed, true);
|
|
5385
|
+
return () => motionDom.cancelFrame(checkElapsed);
|
|
5880
5386
|
}
|
|
5881
5387
|
function delayInSeconds(callback, timeout) {
|
|
5882
5388
|
return delay(callback, motionUtils.secondsToMilliseconds(timeout));
|
|
@@ -5908,22 +5414,22 @@ function transform(...args) {
|
|
|
5908
5414
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
5909
5415
|
}
|
|
5910
5416
|
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5417
|
+
Object.defineProperty(exports, "MotionValue", {
|
|
5418
|
+
enumerable: true,
|
|
5419
|
+
get: function () { return motionDom.MotionValue; }
|
|
5420
|
+
});
|
|
5421
|
+
Object.defineProperty(exports, "cancelFrame", {
|
|
5422
|
+
enumerable: true,
|
|
5423
|
+
get: function () { return motionDom.cancelFrame; }
|
|
5424
|
+
});
|
|
5425
|
+
Object.defineProperty(exports, "frame", {
|
|
5426
|
+
enumerable: true,
|
|
5427
|
+
get: function () { return motionDom.frame; }
|
|
5428
|
+
});
|
|
5429
|
+
Object.defineProperty(exports, "frameData", {
|
|
5430
|
+
enumerable: true,
|
|
5431
|
+
get: function () { return motionDom.frameData; }
|
|
5432
|
+
});
|
|
5927
5433
|
Object.defineProperty(exports, "hover", {
|
|
5928
5434
|
enumerable: true,
|
|
5929
5435
|
get: function () { return motionDom.hover; }
|
|
@@ -5932,10 +5438,18 @@ Object.defineProperty(exports, "isDragActive", {
|
|
|
5932
5438
|
enumerable: true,
|
|
5933
5439
|
get: function () { return motionDom.isDragActive; }
|
|
5934
5440
|
});
|
|
5441
|
+
Object.defineProperty(exports, "motionValue", {
|
|
5442
|
+
enumerable: true,
|
|
5443
|
+
get: function () { return motionDom.motionValue; }
|
|
5444
|
+
});
|
|
5935
5445
|
Object.defineProperty(exports, "press", {
|
|
5936
5446
|
enumerable: true,
|
|
5937
5447
|
get: function () { return motionDom.press; }
|
|
5938
5448
|
});
|
|
5449
|
+
Object.defineProperty(exports, "time", {
|
|
5450
|
+
enumerable: true,
|
|
5451
|
+
get: function () { return motionDom.time; }
|
|
5452
|
+
});
|
|
5939
5453
|
Object.defineProperty(exports, "invariant", {
|
|
5940
5454
|
enumerable: true,
|
|
5941
5455
|
get: function () { return motionUtils.invariant; }
|
|
@@ -5948,15 +5462,12 @@ Object.defineProperty(exports, "progress", {
|
|
|
5948
5462
|
enumerable: true,
|
|
5949
5463
|
get: function () { return motionUtils.progress; }
|
|
5950
5464
|
});
|
|
5951
|
-
exports.MotionValue = MotionValue;
|
|
5952
5465
|
exports.animate = animate;
|
|
5953
5466
|
exports.animateMini = animateMini;
|
|
5954
5467
|
exports.anticipate = anticipate;
|
|
5955
5468
|
exports.backIn = backIn;
|
|
5956
5469
|
exports.backInOut = backInOut;
|
|
5957
5470
|
exports.backOut = backOut;
|
|
5958
|
-
exports.cancelFrame = cancelFrame;
|
|
5959
|
-
exports.cancelSync = cancelSync;
|
|
5960
5471
|
exports.circIn = circIn;
|
|
5961
5472
|
exports.circInOut = circInOut;
|
|
5962
5473
|
exports.circOut = circOut;
|
|
@@ -5969,16 +5480,12 @@ exports.distance2D = distance2D;
|
|
|
5969
5480
|
exports.easeIn = easeIn;
|
|
5970
5481
|
exports.easeInOut = easeInOut;
|
|
5971
5482
|
exports.easeOut = easeOut;
|
|
5972
|
-
exports.frame = frame;
|
|
5973
|
-
exports.frameData = frameData;
|
|
5974
|
-
exports.frameSteps = frameSteps;
|
|
5975
5483
|
exports.inView = inView;
|
|
5976
5484
|
exports.inertia = inertia;
|
|
5977
5485
|
exports.interpolate = interpolate;
|
|
5978
5486
|
exports.keyframes = keyframes;
|
|
5979
5487
|
exports.mirrorEasing = mirrorEasing;
|
|
5980
5488
|
exports.mix = mix;
|
|
5981
|
-
exports.motionValue = motionValue;
|
|
5982
5489
|
exports.pipe = pipe;
|
|
5983
5490
|
exports.reverseEasing = reverseEasing;
|
|
5984
5491
|
exports.scroll = scroll;
|
|
@@ -5986,7 +5493,5 @@ exports.scrollInfo = scrollInfo;
|
|
|
5986
5493
|
exports.spring = spring;
|
|
5987
5494
|
exports.stagger = stagger;
|
|
5988
5495
|
exports.steps = steps;
|
|
5989
|
-
exports.sync = sync;
|
|
5990
|
-
exports.time = time;
|
|
5991
5496
|
exports.transform = transform;
|
|
5992
5497
|
exports.wrap = wrap;
|