motion-dom 13.1.1-alpha.0 → 13.2.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 +152 -150
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/animate/effects.mjs +48 -0
- package/dist/es/animation/animate/effects.mjs.map +1 -0
- package/dist/es/animation/generators/inertia.mjs +8 -6
- package/dist/es/animation/generators/inertia.mjs.map +1 -1
- package/dist/es/animation/generators/spring.mjs +43 -58
- package/dist/es/animation/generators/spring.mjs.map +1 -1
- package/dist/es/animation/generators/utils/calc-duration.mjs +5 -4
- package/dist/es/animation/generators/utils/calc-duration.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +2 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/waapi/supports/waapi.mjs +3 -6
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/accelerated-values.mjs +1 -12
- package/dist/es/animation/waapi/utils/accelerated-values.mjs.map +1 -1
- package/dist/es/effects/MotionValueState.mjs +8 -2
- package/dist/es/effects/MotionValueState.mjs.map +1 -1
- package/dist/es/effects/style/index.mjs +4 -11
- package/dist/es/effects/style/index.mjs.map +1 -1
- package/dist/es/effects/style/transform.mjs +0 -5
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/effects/utils/create-effect.mjs +6 -3
- package/dist/es/effects/utils/create-effect.mjs.map +1 -1
- package/dist/es/index.mjs +4 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +8 -13
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +1 -3
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/projection/utils/has-transform.mjs +1 -7
- package/dist/es/projection/utils/has-transform.mjs.map +1 -1
- package/dist/es/render/VisualElement.mjs +2 -5
- package/dist/es/render/VisualElement.mjs.map +1 -1
- package/dist/es/render/html/utils/build-styles.mjs +12 -10
- package/dist/es/render/html/utils/build-styles.mjs.map +1 -1
- package/dist/es/render/html/utils/build-transform.mjs +0 -5
- package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/index.d.ts +72 -9
- package/dist/motion-dom.dev.js +152 -150
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -736,15 +736,16 @@ resolution = 10 // as milliseconds
|
|
|
736
736
|
* to prevent infinite loops
|
|
737
737
|
*/
|
|
738
738
|
const maxGeneratorDuration = 20000;
|
|
739
|
-
function calcGeneratorDuration(generator) {
|
|
739
|
+
function calcGeneratorDuration(generator, timeStep = 50, maxDuration = maxGeneratorDuration, keyframes) {
|
|
740
740
|
let duration = 0;
|
|
741
|
-
const timeStep = 50;
|
|
742
741
|
let state = generator.next(duration);
|
|
743
|
-
|
|
742
|
+
keyframes?.push(state.value);
|
|
743
|
+
while (!state.done && duration < maxDuration) {
|
|
744
744
|
duration += timeStep;
|
|
745
745
|
state = generator.next(duration);
|
|
746
|
+
keyframes?.push(state.value);
|
|
746
747
|
}
|
|
747
|
-
return duration >=
|
|
748
|
+
return duration >= maxDuration ? Infinity : duration;
|
|
748
749
|
}
|
|
749
750
|
|
|
750
751
|
/**
|
|
@@ -828,9 +829,13 @@ function findSpring({ duration = springDefaults.duration, bounce = springDefault
|
|
|
828
829
|
const exponentialDecay = undampedFreq * dampingRatio;
|
|
829
830
|
const delta = exponentialDecay * duration;
|
|
830
831
|
const d = delta * velocity + velocity;
|
|
831
|
-
const e =
|
|
832
|
+
const e = dampingRatio *
|
|
833
|
+
dampingRatio *
|
|
834
|
+
undampedFreq *
|
|
835
|
+
undampedFreq *
|
|
836
|
+
duration;
|
|
832
837
|
const f = Math.exp(-delta);
|
|
833
|
-
const g = calcAngularFreq(
|
|
838
|
+
const g = calcAngularFreq(undampedFreq * undampedFreq, dampingRatio);
|
|
834
839
|
const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
|
|
835
840
|
return (factor * ((d - e) * f)) / g;
|
|
836
841
|
};
|
|
@@ -861,7 +866,7 @@ function findSpring({ duration = springDefaults.duration, bounce = springDefault
|
|
|
861
866
|
};
|
|
862
867
|
}
|
|
863
868
|
else {
|
|
864
|
-
const stiffness =
|
|
869
|
+
const stiffness = undampedFreq * undampedFreq * mass;
|
|
865
870
|
return {
|
|
866
871
|
stiffness,
|
|
867
872
|
damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
|
|
@@ -941,6 +946,7 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
941
946
|
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
942
947
|
const initialDelta = target - origin;
|
|
943
948
|
const undampedAngularFreq = motionUtils.millisecondsToSeconds(Math.sqrt(stiffness / mass));
|
|
949
|
+
const decay = dampingRatio * undampedAngularFreq;
|
|
944
950
|
/**
|
|
945
951
|
* If we're working on a granular scale, use smaller defaults for determining
|
|
946
952
|
* when the spring is finished.
|
|
@@ -957,35 +963,38 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
957
963
|
: springDefaults.restDelta.default);
|
|
958
964
|
let resolveSpring;
|
|
959
965
|
let resolveVelocity;
|
|
960
|
-
// Underdamped coefficients, hoisted for use in the inlined next() hot path
|
|
961
|
-
let angularFreq;
|
|
962
|
-
let A;
|
|
963
|
-
let sinCoeff;
|
|
964
|
-
let cosCoeff;
|
|
965
966
|
if (dampingRatio < 1) {
|
|
966
|
-
angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
967
|
-
A =
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
967
|
+
const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
968
|
+
const A = (initialVelocity + decay * initialDelta) / angularFreq;
|
|
969
|
+
// Coefficients for the analytical derivative (px/ms)
|
|
970
|
+
const sinCoeff = decay * A + initialDelta * angularFreq;
|
|
971
|
+
const cosCoeff = decay * initialDelta - A * angularFreq;
|
|
972
|
+
/**
|
|
973
|
+
* The underdamped hot path needs both position and velocity every
|
|
974
|
+
* frame and they share the same exp/sin/cos terms, so sample both
|
|
975
|
+
* at once, memoized by t, to only calculate them once per frame.
|
|
976
|
+
*/
|
|
977
|
+
let sampledT = -1;
|
|
978
|
+
let position = 0;
|
|
979
|
+
let velocityAtT = 0;
|
|
980
|
+
const sample = (t) => {
|
|
981
|
+
if (t !== sampledT) {
|
|
982
|
+
sampledT = t;
|
|
983
|
+
const envelope = Math.exp(-decay * t);
|
|
984
|
+
const sin = Math.sin(angularFreq * t);
|
|
985
|
+
const cos = Math.cos(angularFreq * t);
|
|
986
|
+
position = target - envelope * (A * sin + initialDelta * cos);
|
|
987
|
+
velocityAtT = envelope * (sinCoeff * sin + cosCoeff * cos);
|
|
988
|
+
}
|
|
989
|
+
};
|
|
971
990
|
// Underdamped spring
|
|
972
991
|
resolveSpring = (t) => {
|
|
973
|
-
|
|
974
|
-
return
|
|
975
|
-
envelope *
|
|
976
|
-
(A * Math.sin(angularFreq * t) +
|
|
977
|
-
initialDelta * Math.cos(angularFreq * t)));
|
|
992
|
+
sample(t);
|
|
993
|
+
return position;
|
|
978
994
|
};
|
|
979
|
-
// Analytical derivative of underdamped spring (px/ms)
|
|
980
|
-
sinCoeff =
|
|
981
|
-
dampingRatio * undampedAngularFreq * A + initialDelta * angularFreq;
|
|
982
|
-
cosCoeff =
|
|
983
|
-
dampingRatio * undampedAngularFreq * initialDelta - A * angularFreq;
|
|
984
995
|
resolveVelocity = (t) => {
|
|
985
|
-
|
|
986
|
-
return
|
|
987
|
-
(sinCoeff * Math.sin(angularFreq * t) +
|
|
988
|
-
cosCoeff * Math.cos(angularFreq * t));
|
|
996
|
+
sample(t);
|
|
997
|
+
return velocityAtT;
|
|
989
998
|
};
|
|
990
999
|
}
|
|
991
1000
|
else if (dampingRatio === 1) {
|
|
@@ -1003,13 +1012,12 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
1003
1012
|
// Overdamped spring
|
|
1004
1013
|
const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
|
|
1005
1014
|
resolveSpring = (t) => {
|
|
1006
|
-
const envelope = Math.exp(-
|
|
1015
|
+
const envelope = Math.exp(-decay * t);
|
|
1007
1016
|
// When performing sinh or cosh values can hit Infinity so we cap them here
|
|
1008
1017
|
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
1009
1018
|
return (target -
|
|
1010
1019
|
(envelope *
|
|
1011
|
-
((initialVelocity +
|
|
1012
|
-
dampingRatio * undampedAngularFreq * initialDelta) *
|
|
1020
|
+
((initialVelocity + decay * initialDelta) *
|
|
1013
1021
|
Math.sinh(freqForT) +
|
|
1014
1022
|
dampedAngularFreq *
|
|
1015
1023
|
initialDelta *
|
|
@@ -1017,43 +1025,21 @@ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce
|
|
|
1017
1025
|
dampedAngularFreq);
|
|
1018
1026
|
};
|
|
1019
1027
|
// Analytical derivative of overdamped spring (px/ms)
|
|
1020
|
-
const P = (initialVelocity +
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
const sinhCoeff = dampingRatio * undampedAngularFreq * P - initialDelta * dampedAngularFreq;
|
|
1024
|
-
const coshCoeff = dampingRatio * undampedAngularFreq * initialDelta - P * dampedAngularFreq;
|
|
1028
|
+
const P = (initialVelocity + decay * initialDelta) / dampedAngularFreq;
|
|
1029
|
+
const sinhCoeff = decay * P - initialDelta * dampedAngularFreq;
|
|
1030
|
+
const coshCoeff = decay * initialDelta - P * dampedAngularFreq;
|
|
1025
1031
|
resolveVelocity = (t) => {
|
|
1026
|
-
const envelope = Math.exp(-
|
|
1032
|
+
const envelope = Math.exp(-decay * t);
|
|
1027
1033
|
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
1028
|
-
return envelope *
|
|
1034
|
+
return (envelope *
|
|
1029
1035
|
(sinhCoeff * Math.sinh(freqForT) +
|
|
1030
|
-
coshCoeff * Math.cosh(freqForT));
|
|
1036
|
+
coshCoeff * Math.cosh(freqForT)));
|
|
1031
1037
|
};
|
|
1032
1038
|
}
|
|
1033
1039
|
const generator = {
|
|
1034
1040
|
calculatedDuration: isResolvedFromDuration ? duration || null : null,
|
|
1035
1041
|
velocity: (t) => motionUtils.secondsToMilliseconds(resolveVelocity(t)),
|
|
1036
1042
|
next: (t) => {
|
|
1037
|
-
/**
|
|
1038
|
-
* For underdamped physics springs we need both position and
|
|
1039
|
-
* velocity each tick. Compute shared trig values once to avoid
|
|
1040
|
-
* duplicate Math.exp/sin/cos calls on the hot path.
|
|
1041
|
-
*/
|
|
1042
|
-
if (!isResolvedFromDuration && dampingRatio < 1) {
|
|
1043
|
-
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
1044
|
-
const sin = Math.sin(angularFreq * t);
|
|
1045
|
-
const cos = Math.cos(angularFreq * t);
|
|
1046
|
-
const current = target -
|
|
1047
|
-
envelope *
|
|
1048
|
-
(A * sin + initialDelta * cos);
|
|
1049
|
-
const currentVelocity = motionUtils.secondsToMilliseconds(envelope *
|
|
1050
|
-
(sinCoeff * sin + cosCoeff * cos));
|
|
1051
|
-
state.done =
|
|
1052
|
-
Math.abs(currentVelocity) <= restSpeed &&
|
|
1053
|
-
Math.abs(target - current) <= restDelta;
|
|
1054
|
-
state.value = state.done ? target : current;
|
|
1055
|
-
return state;
|
|
1056
|
-
}
|
|
1057
1043
|
const current = resolveSpring(t);
|
|
1058
1044
|
if (!isResolvedFromDuration) {
|
|
1059
1045
|
const currentVelocity = motionUtils.secondsToMilliseconds(resolveVelocity(t));
|
|
@@ -1084,19 +1070,13 @@ spring.applyToOptions = (options) => {
|
|
|
1084
1070
|
return options;
|
|
1085
1071
|
};
|
|
1086
1072
|
|
|
1087
|
-
const velocitySampleDuration = 5; // ms
|
|
1088
|
-
function getGeneratorVelocity(resolveValue, t, current) {
|
|
1089
|
-
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
1090
|
-
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
1073
|
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
1094
1074
|
const origin = keyframes[0];
|
|
1095
1075
|
const state = {
|
|
1096
1076
|
done: false,
|
|
1097
1077
|
value: origin,
|
|
1098
1078
|
};
|
|
1099
|
-
const isOutOfBounds = (v) =>
|
|
1079
|
+
const isOutOfBounds = (v) => v < min || v > max;
|
|
1100
1080
|
const nearestBoundary = (v) => {
|
|
1101
1081
|
if (min === undefined)
|
|
1102
1082
|
return max;
|
|
@@ -1114,12 +1094,10 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1114
1094
|
if (target !== ideal)
|
|
1115
1095
|
amplitude = target - origin;
|
|
1116
1096
|
const calcDelta = (t) => -amplitude * Math.exp(-t / timeConstant);
|
|
1117
|
-
const calcLatest = (t) => target + calcDelta(t);
|
|
1118
1097
|
const applyFriction = (t) => {
|
|
1119
1098
|
const delta = calcDelta(t);
|
|
1120
|
-
const latest = calcLatest(t);
|
|
1121
1099
|
state.done = Math.abs(delta) <= restDelta;
|
|
1122
|
-
state.value = state.done ? target :
|
|
1100
|
+
state.value = state.done ? target : target + delta;
|
|
1123
1101
|
};
|
|
1124
1102
|
/**
|
|
1125
1103
|
* Ideally this would resolve for t in a stateless way, we could
|
|
@@ -1135,7 +1113,12 @@ function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, b
|
|
|
1135
1113
|
timeReachedBoundary = t;
|
|
1136
1114
|
spring$1 = spring({
|
|
1137
1115
|
keyframes: [state.value, nearestBoundary(state.value)],
|
|
1138
|
-
|
|
1116
|
+
/**
|
|
1117
|
+
* The friction curve is target + calcDelta(t), so its exact
|
|
1118
|
+
* derivative is -calcDelta(t) / timeConstant in units/ms,
|
|
1119
|
+
* converted here to the units/second expected by spring.
|
|
1120
|
+
*/
|
|
1121
|
+
velocity: (-calcDelta(t) / timeConstant) * 1000,
|
|
1139
1122
|
damping: bounceDamping,
|
|
1140
1123
|
stiffness: bounceStiffness,
|
|
1141
1124
|
restDelta,
|
|
@@ -1304,6 +1287,12 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
1304
1287
|
};
|
|
1305
1288
|
}
|
|
1306
1289
|
|
|
1290
|
+
const velocitySampleDuration = 5; // ms
|
|
1291
|
+
function getGeneratorVelocity(resolveValue, t, current) {
|
|
1292
|
+
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
1293
|
+
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1307
1296
|
const isNotNull = (value) => value !== null;
|
|
1308
1297
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
1309
1298
|
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
@@ -2480,15 +2469,6 @@ const acceleratedValues = new Set([
|
|
|
2480
2469
|
"transform",
|
|
2481
2470
|
"backgroundColor",
|
|
2482
2471
|
]);
|
|
2483
|
-
function hasIndependentTransform(values) {
|
|
2484
|
-
if (!values)
|
|
2485
|
-
return false;
|
|
2486
|
-
for (const key in values) {
|
|
2487
|
-
if (transformProps.has(key))
|
|
2488
|
-
return true;
|
|
2489
|
-
}
|
|
2490
|
-
return false;
|
|
2491
|
-
}
|
|
2492
2472
|
|
|
2493
2473
|
const browserColorFunctions = /^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;
|
|
2494
2474
|
function hasBrowserOnlyColors(keyframes) {
|
|
@@ -2528,8 +2508,7 @@ function supportsBrowserAnimation(options) {
|
|
|
2528
2508
|
!(subject instanceof SVGElement)) {
|
|
2529
2509
|
return false;
|
|
2530
2510
|
}
|
|
2531
|
-
const
|
|
2532
|
-
const { onUpdate, transformTemplate } = owner.getProps();
|
|
2511
|
+
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
2533
2512
|
return (supportsWaapi() &&
|
|
2534
2513
|
name &&
|
|
2535
2514
|
/**
|
|
@@ -2539,9 +2518,7 @@ function supportsBrowserAnimation(options) {
|
|
|
2539
2518
|
(acceleratedValues.has(name) ||
|
|
2540
2519
|
(colorProperties.has(name) &&
|
|
2541
2520
|
hasBrowserOnlyColors(keyframes))) &&
|
|
2542
|
-
(name !== "transform" ||
|
|
2543
|
-
(!transformTemplate &&
|
|
2544
|
-
!hasIndependentTransform(owner.latestValues))) &&
|
|
2521
|
+
(name !== "transform" || !transformTemplate) &&
|
|
2545
2522
|
/**
|
|
2546
2523
|
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
2547
2524
|
* no way to read the value from WAAPI every frame.
|
|
@@ -3688,6 +3665,7 @@ function getOptimisedAppearId(visualElement) {
|
|
|
3688
3665
|
return visualElement.props[optimizedAppearDataAttribute];
|
|
3689
3666
|
}
|
|
3690
3667
|
|
|
3668
|
+
const isBrowser$1 = typeof window !== "undefined";
|
|
3691
3669
|
/**
|
|
3692
3670
|
* Decide whether we should block this animation. Previously, we achieved this
|
|
3693
3671
|
* just by checking whether the key was listed in protectedKeys, but this
|
|
@@ -3751,7 +3729,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
3751
3729
|
* to see if we're handling off from an existing animation.
|
|
3752
3730
|
*/
|
|
3753
3731
|
let isHandoff = false;
|
|
3754
|
-
if (window.MotionHandoffAnimation) {
|
|
3732
|
+
if (isBrowser$1 && window.MotionHandoffAnimation) {
|
|
3755
3733
|
const appearId = getOptimisedAppearId(visualElement);
|
|
3756
3734
|
if (appearId) {
|
|
3757
3735
|
const startTime = window.MotionHandoffAnimation(appearId, key, frame);
|
|
@@ -4321,6 +4299,47 @@ const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
|
4321
4299
|
return true;
|
|
4322
4300
|
});
|
|
4323
4301
|
|
|
4302
|
+
/**
|
|
4303
|
+
* Effects registered via `animate.addEffect()`, most recent first.
|
|
4304
|
+
*/
|
|
4305
|
+
const effects = [];
|
|
4306
|
+
function addEffect(effect) {
|
|
4307
|
+
motionUtils.invariant(typeof effect.test === "function" && typeof effect.read === "function", "Effects passed to animate.addEffect() need test() and read().", "effect-missing-test");
|
|
4308
|
+
removeEffect(effect);
|
|
4309
|
+
effects.unshift(effect);
|
|
4310
|
+
}
|
|
4311
|
+
function removeEffect(effect) {
|
|
4312
|
+
motionUtils.removeItem(effects, effect);
|
|
4313
|
+
}
|
|
4314
|
+
function findEffect(subject) {
|
|
4315
|
+
return effects.find((effect) => effect.test(subject));
|
|
4316
|
+
}
|
|
4317
|
+
/**
|
|
4318
|
+
* Animate the keys of `subject` via `effect`. Motion values are created on
|
|
4319
|
+
* first animation, seeded from `effect.read()` or the first keyframe, and
|
|
4320
|
+
* then bound to the subject via the effect for the rest of its life.
|
|
4321
|
+
*/
|
|
4322
|
+
function animateEffectSubject(effect, subject, keyframes, transition = {}) {
|
|
4323
|
+
const animations = [];
|
|
4324
|
+
for (const key in keyframes) {
|
|
4325
|
+
const target = keyframes[key];
|
|
4326
|
+
let value = effect.get(subject, key);
|
|
4327
|
+
if (!value) {
|
|
4328
|
+
const initial = effect.read(subject, key, target) ?? firstKeyframe(target);
|
|
4329
|
+
motionUtils.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
4330
|
+
value = motionValue(initial);
|
|
4331
|
+
effect(subject, { [key]: value });
|
|
4332
|
+
}
|
|
4333
|
+
value.start(animateMotionValue(key, value, target, getValueTransition(transition, key)));
|
|
4334
|
+
value.animation && animations.push(value.animation);
|
|
4335
|
+
}
|
|
4336
|
+
return animations;
|
|
4337
|
+
}
|
|
4338
|
+
function firstKeyframe(target) {
|
|
4339
|
+
const first = Array.isArray(target) ? target[0] : undefined;
|
|
4340
|
+
return first === null ? undefined : first;
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4324
4343
|
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
4325
4344
|
if (elementOrSelector == null) {
|
|
4326
4345
|
return [];
|
|
@@ -4365,7 +4384,13 @@ const getValueAsType = (value, type) => {
|
|
|
4365
4384
|
};
|
|
4366
4385
|
|
|
4367
4386
|
class MotionValueState {
|
|
4368
|
-
|
|
4387
|
+
/**
|
|
4388
|
+
* @param step - The frameloop step renders are scheduled in. Defaults
|
|
4389
|
+
* to `frame.render`. Effects that feed a render loop running in
|
|
4390
|
+
* `frame.render` (GPU scenes) should write in `frame.preRender`.
|
|
4391
|
+
*/
|
|
4392
|
+
constructor(step = frame.render) {
|
|
4393
|
+
this.step = step;
|
|
4369
4394
|
this.latest = {};
|
|
4370
4395
|
this.values = new Map();
|
|
4371
4396
|
}
|
|
@@ -4382,7 +4407,7 @@ class MotionValueState {
|
|
|
4382
4407
|
else {
|
|
4383
4408
|
this.latest[name] = v;
|
|
4384
4409
|
}
|
|
4385
|
-
render &&
|
|
4410
|
+
render && this.step(render);
|
|
4386
4411
|
};
|
|
4387
4412
|
onChange();
|
|
4388
4413
|
const cancelOnChange = value.on("change", onChange);
|
|
@@ -4401,10 +4426,10 @@ class MotionValueState {
|
|
|
4401
4426
|
}
|
|
4402
4427
|
}
|
|
4403
4428
|
|
|
4404
|
-
function createEffect(addValue) {
|
|
4429
|
+
function createEffect(addValue, { step, ...options } = {}) {
|
|
4405
4430
|
const stateCache = new WeakMap();
|
|
4406
|
-
|
|
4407
|
-
const state = stateCache.get(subject) ?? new MotionValueState();
|
|
4431
|
+
const effect = (subject, values) => {
|
|
4432
|
+
const state = stateCache.get(subject) ?? new MotionValueState(step);
|
|
4408
4433
|
stateCache.set(subject, state);
|
|
4409
4434
|
const subscriptions = [];
|
|
4410
4435
|
for (const key in values) {
|
|
@@ -4417,6 +4442,9 @@ function createEffect(addValue) {
|
|
|
4417
4442
|
cancel();
|
|
4418
4443
|
};
|
|
4419
4444
|
};
|
|
4445
|
+
return Object.assign(effect, options, {
|
|
4446
|
+
get: (subject, key) => stateCache.get(subject)?.get(key),
|
|
4447
|
+
});
|
|
4420
4448
|
}
|
|
4421
4449
|
|
|
4422
4450
|
function canSetAsProperty(element, name) {
|
|
@@ -4512,37 +4540,25 @@ function buildTransform$1(state) {
|
|
|
4512
4540
|
? `${pathRotation}deg`
|
|
4513
4541
|
: pathRotation}) `;
|
|
4514
4542
|
}
|
|
4515
|
-
const userTransform = state.latest.transform;
|
|
4516
|
-
if (userTransform && userTransform !== "none") {
|
|
4517
|
-
transformIsDefault = false;
|
|
4518
|
-
transform += userTransform;
|
|
4519
|
-
}
|
|
4520
4543
|
return transformIsDefault ? "none" : transform.trim();
|
|
4521
4544
|
}
|
|
4522
4545
|
|
|
4523
4546
|
const originProps = new Set(["originX", "originY", "originZ"]);
|
|
4524
|
-
/**
|
|
4525
|
-
* Internal key for the computed transform channel. The user "transform"
|
|
4526
|
-
* value now composes into this channel, so it can't share the "transform"
|
|
4527
|
-
* key. Prefixed with $ so it can never collide with a real style key
|
|
4528
|
-
* (like "transformStyle", which is the transform-style CSS property).
|
|
4529
|
-
*/
|
|
4530
|
-
const computedTransform = "$transform";
|
|
4531
4547
|
const addStyleValue = (element, state, key, value) => {
|
|
4532
4548
|
let render = undefined;
|
|
4533
4549
|
let computed = undefined;
|
|
4534
|
-
if (transformProps.has(key)
|
|
4535
|
-
if (!state.get(
|
|
4550
|
+
if (transformProps.has(key)) {
|
|
4551
|
+
if (!state.get("transform")) {
|
|
4536
4552
|
// If this is an HTML element, we need to set the transform-box to fill-box
|
|
4537
4553
|
// to normalise the transform relative to the element's bounding box
|
|
4538
4554
|
if (!isHTMLElement(element) && !state.get("transformBox")) {
|
|
4539
4555
|
addStyleValue(element, state, "transformBox", new MotionValue("fill-box"));
|
|
4540
4556
|
}
|
|
4541
|
-
state.set(
|
|
4557
|
+
state.set("transform", new MotionValue("none"), () => {
|
|
4542
4558
|
element.style.transform = buildTransform$1(state);
|
|
4543
4559
|
});
|
|
4544
4560
|
}
|
|
4545
|
-
computed = state.get(
|
|
4561
|
+
computed = state.get("transform");
|
|
4546
4562
|
}
|
|
4547
4563
|
else if (originProps.has(key)) {
|
|
4548
4564
|
if (!state.get("transformOrigin")) {
|
|
@@ -6817,10 +6833,7 @@ class VisualElement {
|
|
|
6817
6833
|
}
|
|
6818
6834
|
if (value.accelerate &&
|
|
6819
6835
|
acceleratedValues.has(key) &&
|
|
6820
|
-
this.current instanceof HTMLElement
|
|
6821
|
-
(key !== "transform" ||
|
|
6822
|
-
(!this.props.transformTemplate &&
|
|
6823
|
-
!hasIndependentTransform(this.latestValues)))) {
|
|
6836
|
+
this.current instanceof HTMLElement) {
|
|
6824
6837
|
const { factory, keyframes, times, ease, duration } = value.accelerate;
|
|
6825
6838
|
const animation = new NativeAnimation({
|
|
6826
6839
|
element: this.current,
|
|
@@ -7215,12 +7228,6 @@ function hasTransform(values) {
|
|
|
7215
7228
|
values.skewX ||
|
|
7216
7229
|
values.skewY);
|
|
7217
7230
|
}
|
|
7218
|
-
function hasVisualTransform(values) {
|
|
7219
|
-
return (hasTransform(values) ||
|
|
7220
|
-
(values.transform &&
|
|
7221
|
-
values.transform !== "none" &&
|
|
7222
|
-
values.transform !== ""));
|
|
7223
|
-
}
|
|
7224
7231
|
function has2DTranslate(values) {
|
|
7225
7232
|
return is2DTranslate(values.x) || is2DTranslate(values.y);
|
|
7226
7233
|
}
|
|
@@ -7415,11 +7422,6 @@ function buildTransform(latestValues, transform, transformTemplate) {
|
|
|
7415
7422
|
transformIsDefault = false;
|
|
7416
7423
|
transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
|
|
7417
7424
|
}
|
|
7418
|
-
const userTransform = latestValues.transform;
|
|
7419
|
-
if (userTransform && userTransform !== "none") {
|
|
7420
|
-
transformIsDefault = false;
|
|
7421
|
-
transformString += userTransform;
|
|
7422
|
-
}
|
|
7423
7425
|
transformString = transformString.trim();
|
|
7424
7426
|
// If we have a custom `transform` template, pass our transform values and
|
|
7425
7427
|
// generated transformString to that before returning
|
|
@@ -7445,7 +7447,7 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
7445
7447
|
*/
|
|
7446
7448
|
for (const key in latestValues) {
|
|
7447
7449
|
const value = latestValues[key];
|
|
7448
|
-
if (transformProps.has(key)
|
|
7450
|
+
if (transformProps.has(key)) {
|
|
7449
7451
|
// If this is a transform, flag to enable further transform processing
|
|
7450
7452
|
hasTransform = true;
|
|
7451
7453
|
continue;
|
|
@@ -7468,15 +7470,17 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
7468
7470
|
}
|
|
7469
7471
|
}
|
|
7470
7472
|
}
|
|
7471
|
-
if (
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7473
|
+
if (!latestValues.transform) {
|
|
7474
|
+
if (hasTransform || transformTemplate) {
|
|
7475
|
+
style.transform = buildTransform(latestValues, state.transform, transformTemplate);
|
|
7476
|
+
}
|
|
7477
|
+
else if (style.transform) {
|
|
7478
|
+
/**
|
|
7479
|
+
* If we have previously created a transform but currently don't have any,
|
|
7480
|
+
* reset transform style to none.
|
|
7481
|
+
*/
|
|
7482
|
+
style.transform = "none";
|
|
7483
|
+
}
|
|
7480
7484
|
}
|
|
7481
7485
|
/**
|
|
7482
7486
|
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
@@ -8481,7 +8485,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
8481
8485
|
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
8482
8486
|
}
|
|
8483
8487
|
if (latestTransform) {
|
|
8484
|
-
const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY,
|
|
8488
|
+
const { transformPerspective, rotate, pathRotation, rotateX, rotateY, skewX, skewY, } = latestTransform;
|
|
8485
8489
|
if (transformPerspective)
|
|
8486
8490
|
transform = `perspective(${transformPerspective}px) ${transform}`;
|
|
8487
8491
|
if (rotate)
|
|
@@ -8497,8 +8501,6 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
8497
8501
|
transform += `skewX(${skewX}deg) `;
|
|
8498
8502
|
if (skewY)
|
|
8499
8503
|
transform += `skewY(${skewY}deg) `;
|
|
8500
|
-
if (userTransform && userTransform !== "none")
|
|
8501
|
-
transform += `${userTransform} `;
|
|
8502
8504
|
}
|
|
8503
8505
|
/**
|
|
8504
8506
|
* Apply scale to match the size of the element to the size we want it.
|
|
@@ -8742,14 +8744,14 @@ const transformAxes = ["", "X", "Y", "Z"];
|
|
|
8742
8744
|
*/
|
|
8743
8745
|
const animationTarget = 1000;
|
|
8744
8746
|
let id = 0;
|
|
8745
|
-
function resetDistortingTransform(key, visualElement, values, sharedAnimationValues
|
|
8747
|
+
function resetDistortingTransform(key, visualElement, values, sharedAnimationValues) {
|
|
8746
8748
|
const { latestValues } = visualElement;
|
|
8747
|
-
// Record the distorting transform and then temporarily
|
|
8749
|
+
// Record the distorting transform and then temporarily set it to 0
|
|
8748
8750
|
if (latestValues[key]) {
|
|
8749
8751
|
values[key] = latestValues[key];
|
|
8750
|
-
visualElement.setStaticValue(key,
|
|
8752
|
+
visualElement.setStaticValue(key, 0);
|
|
8751
8753
|
if (sharedAnimationValues) {
|
|
8752
|
-
sharedAnimationValues[key] =
|
|
8754
|
+
sharedAnimationValues[key] = 0;
|
|
8753
8755
|
}
|
|
8754
8756
|
}
|
|
8755
8757
|
}
|
|
@@ -9328,7 +9330,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
9328
9330
|
if (isResetRequested &&
|
|
9329
9331
|
this.instance &&
|
|
9330
9332
|
(hasProjection ||
|
|
9331
|
-
|
|
9333
|
+
hasTransform(this.latestValues) ||
|
|
9332
9334
|
transformTemplateHasChanged)) {
|
|
9333
9335
|
resetTransform(this.instance, transformTemplateValue);
|
|
9334
9336
|
this.shouldResetTransform = false;
|
|
@@ -9996,8 +9998,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
9996
9998
|
latestValues.rotateY ||
|
|
9997
9999
|
latestValues.rotateZ ||
|
|
9998
10000
|
latestValues.skewX ||
|
|
9999
|
-
latestValues.skewY
|
|
10000
|
-
(latestValues.transform && latestValues.transform !== "none")) {
|
|
10001
|
+
latestValues.skewY) {
|
|
10001
10002
|
hasDistortingTransform = true;
|
|
10002
10003
|
}
|
|
10003
10004
|
// If there's no distorting values, we don't need to do any more.
|
|
@@ -10007,9 +10008,6 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
10007
10008
|
if (latestValues.z) {
|
|
10008
10009
|
resetDistortingTransform("z", visualElement, resetValues, this.animationValues);
|
|
10009
10010
|
}
|
|
10010
|
-
if (latestValues.transform && latestValues.transform !== "none") {
|
|
10011
|
-
resetDistortingTransform("transform", visualElement, resetValues, this.animationValues, "none");
|
|
10012
|
-
}
|
|
10013
10011
|
// Check the skew and rotate value of all axes and reset to 0
|
|
10014
10012
|
for (let i = 0; i < transformAxes.length; i++) {
|
|
10015
10013
|
resetDistortingTransform(`rotate${transformAxes[i]}`, visualElement, resetValues, this.animationValues);
|
|
@@ -10059,8 +10057,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
10059
10057
|
targetStyle.pointerEvents =
|
|
10060
10058
|
resolveMotionValue(styleProp?.pointerEvents) || "";
|
|
10061
10059
|
}
|
|
10062
|
-
if (this.hasProjected &&
|
|
10063
|
-
!hasVisualTransform(this.latestValues)) {
|
|
10060
|
+
if (this.hasProjected && !hasTransform(this.latestValues)) {
|
|
10064
10061
|
targetStyle.transform = transformTemplate
|
|
10065
10062
|
? transformTemplate({}, "")
|
|
10066
10063
|
: "none";
|
|
@@ -10825,6 +10822,7 @@ exports.JSAnimation = JSAnimation;
|
|
|
10825
10822
|
exports.KeyframeResolver = KeyframeResolver;
|
|
10826
10823
|
exports.LayoutAnimationBuilder = LayoutAnimationBuilder;
|
|
10827
10824
|
exports.MotionValue = MotionValue;
|
|
10825
|
+
exports.MotionValueState = MotionValueState;
|
|
10828
10826
|
exports.NativeAnimation = NativeAnimation;
|
|
10829
10827
|
exports.NativeAnimationExtended = NativeAnimationExtended;
|
|
10830
10828
|
exports.NativeAnimationWrapper = NativeAnimationWrapper;
|
|
@@ -10836,11 +10834,13 @@ exports.VisualElement = VisualElement;
|
|
|
10836
10834
|
exports.acceleratedValues = acceleratedValues;
|
|
10837
10835
|
exports.addAttrValue = addAttrValue;
|
|
10838
10836
|
exports.addDomEvent = addDomEvent;
|
|
10837
|
+
exports.addEffect = addEffect;
|
|
10839
10838
|
exports.addScaleCorrector = addScaleCorrector;
|
|
10840
10839
|
exports.addStyleValue = addStyleValue;
|
|
10841
10840
|
exports.addValueToWillChange = addValueToWillChange;
|
|
10842
10841
|
exports.alpha = alpha;
|
|
10843
10842
|
exports.analyseComplexValue = analyseComplexValue;
|
|
10843
|
+
exports.animateEffectSubject = animateEffectSubject;
|
|
10844
10844
|
exports.animateMotionValue = animateMotionValue;
|
|
10845
10845
|
exports.animateSingleValue = animateSingleValue;
|
|
10846
10846
|
exports.animateTarget = animateTarget;
|
|
@@ -10904,6 +10904,7 @@ exports.createAxis = createAxis;
|
|
|
10904
10904
|
exports.createAxisDelta = createAxisDelta;
|
|
10905
10905
|
exports.createBox = createBox;
|
|
10906
10906
|
exports.createDelta = createDelta;
|
|
10907
|
+
exports.createEffect = createEffect;
|
|
10907
10908
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
10908
10909
|
exports.createProjectionNode = createProjectionNode;
|
|
10909
10910
|
exports.createRenderBatcher = createRenderBatcher;
|
|
@@ -10920,6 +10921,7 @@ exports.eachAxis = eachAxis;
|
|
|
10920
10921
|
exports.fillOffset = fillOffset;
|
|
10921
10922
|
exports.fillWildcards = fillWildcards;
|
|
10922
10923
|
exports.findDimensionValueType = findDimensionValueType;
|
|
10924
|
+
exports.findEffect = findEffect;
|
|
10923
10925
|
exports.findValueType = findValueType;
|
|
10924
10926
|
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
10925
10927
|
exports.followValue = followValue;
|
|
@@ -10945,7 +10947,6 @@ exports.getViewAnimationLayerInfo = getViewAnimationLayerInfo;
|
|
|
10945
10947
|
exports.getViewAnimations = getViewAnimations;
|
|
10946
10948
|
exports.globalProjectionState = globalProjectionState;
|
|
10947
10949
|
exports.has2DTranslate = has2DTranslate;
|
|
10948
|
-
exports.hasIndependentTransform = hasIndependentTransform;
|
|
10949
10950
|
exports.hasReducedMotionListener = hasReducedMotionListener;
|
|
10950
10951
|
exports.hasScale = hasScale;
|
|
10951
10952
|
exports.hasTransform = hasTransform;
|
|
@@ -11024,6 +11025,7 @@ exports.recordStats = recordStats;
|
|
|
11024
11025
|
exports.removeAxisDelta = removeAxisDelta;
|
|
11025
11026
|
exports.removeAxisTransforms = removeAxisTransforms;
|
|
11026
11027
|
exports.removeBoxTransforms = removeBoxTransforms;
|
|
11028
|
+
exports.removeEffect = removeEffect;
|
|
11027
11029
|
exports.removePointDelta = removePointDelta;
|
|
11028
11030
|
exports.renderHTML = renderHTML;
|
|
11029
11031
|
exports.renderSVG = renderSVG;
|