framer-motion 12.7.4 → 12.7.5-alpha.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/README.md +1 -1
- package/dist/cjs/client.js +1 -1
- package/dist/cjs/{create-BErHrlzf.js → create-C7kXmWbI.js} +99 -2828
- package/dist/cjs/dom-mini.js +82 -66
- package/dist/cjs/dom.js +264 -3000
- package/dist/cjs/index.js +138 -196
- package/dist/cjs/m.js +13 -170
- package/dist/cjs/mini.js +77 -9
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +5 -94
- package/dist/dom.js +1 -1
- package/dist/es/animation/animate/sequence.mjs +1 -1
- package/dist/es/animation/animators/waapi/animate-elements.mjs +78 -10
- package/dist/es/animation/interfaces/motion-value.mjs +11 -30
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
- package/dist/es/animation/optimized-appear/store-id.mjs +1 -1
- package/dist/es/animation/sequence/create.mjs +2 -5
- package/dist/es/animation/sequence/utils/edit.mjs +2 -3
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/stagger.mjs +1 -1
- package/dist/es/components/Reorder/utils/check-reorder.mjs +1 -1
- package/dist/es/dom.mjs +2 -18
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -3
- package/dist/es/gestures/drag/utils/constraints.mjs +2 -3
- package/dist/es/gestures/focus.mjs +1 -1
- package/dist/es/gestures/pan/PanSession.mjs +1 -2
- package/dist/es/index.mjs +3 -24
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +2 -4
- package/dist/es/projection/geometry/delta-apply.mjs +1 -1
- package/dist/es/projection/geometry/delta-calc.mjs +1 -1
- package/dist/es/projection/geometry/delta-remove.mjs +1 -2
- package/dist/es/projection/node/create-projection-node.mjs +3 -7
- package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
- package/dist/es/projection/styles/scale-box-shadow.mjs +1 -2
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection.mjs +1 -3
- package/dist/es/render/VisualElement.mjs +2 -9
- package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
- package/dist/es/render/dom/scroll/attach-animation.mjs +17 -0
- package/dist/es/render/dom/scroll/attach-function.mjs +23 -0
- package/dist/es/render/dom/scroll/index.mjs +6 -82
- package/dist/es/render/dom/scroll/offsets/index.mjs +2 -3
- package/dist/es/render/dom/scroll/utils/get-timeline.mjs +29 -0
- package/dist/es/render/html/HTMLVisualElement.mjs +1 -3
- package/dist/es/render/html/utils/build-styles.mjs +1 -4
- package/dist/es/render/html/utils/build-transform.mjs +1 -3
- package/dist/es/render/svg/SVGVisualElement.mjs +1 -3
- package/dist/es/render/svg/config-motion.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
- package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/utils/delay.mjs +1 -1
- package/dist/es/utils/transform.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +4 -4
- package/dist/es/value/use-spring.mjs +2 -3
- package/dist/es/value/use-will-change/get-will-change-name.mjs +1 -2
- package/dist/framer-motion.dev.js +3853 -3394
- package/dist/framer-motion.js +1 -1
- package/dist/m.d.ts +3 -50
- package/dist/mini.js +1 -1
- package/dist/size-rollup-animate.js +1 -1
- package/dist/size-rollup-dom-animation-assets.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/size-rollup-scroll.js +1 -1
- package/dist/size-rollup-waapi-animate.js +1 -1
- package/dist/types/client.d.ts +4 -3
- package/dist/types/index.d.ts +56 -351
- package/dist/{types.d-B50aGbjN.d.ts → types.d-B1Voffvi.d.ts} +3 -138
- package/package.json +9 -9
- package/dist/es/animation/animators/AcceleratedAnimation.mjs +0 -319
- package/dist/es/animation/animators/BaseAnimation.mjs +0 -120
- package/dist/es/animation/animators/MainThreadAnimation.mjs +0 -394
- package/dist/es/animation/animators/drivers/driver-frameloop.mjs +0 -16
- package/dist/es/animation/animators/utils/accelerated-values.mjs +0 -14
- package/dist/es/animation/animators/utils/can-animate.mjs +0 -42
- package/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +0 -5
- package/dist/es/animation/generators/inertia.mjs +0 -87
- package/dist/es/animation/generators/keyframes.mjs +0 -51
- package/dist/es/animation/generators/spring/defaults.mjs +0 -27
- package/dist/es/animation/generators/spring/find.mjs +0 -85
- package/dist/es/animation/generators/spring/index.mjs +0 -174
- package/dist/es/animation/generators/utils/velocity.mjs +0 -9
- package/dist/es/animation/utils/is-animatable.mjs +0 -30
- package/dist/es/animation/utils/is-none.mjs +0 -15
- package/dist/es/easing/anticipate.mjs +0 -5
- package/dist/es/easing/back.mjs +0 -9
- package/dist/es/easing/circ.mjs +0 -8
- package/dist/es/easing/cubic-bezier.mjs +0 -51
- package/dist/es/easing/ease.mjs +0 -7
- package/dist/es/easing/modifiers/mirror.mjs +0 -5
- package/dist/es/easing/modifiers/reverse.mjs +0 -5
- package/dist/es/easing/steps.mjs +0 -15
- package/dist/es/easing/utils/get-easing-for-segment.mjs +0 -8
- package/dist/es/easing/utils/is-easing-array.mjs +0 -5
- package/dist/es/easing/utils/map.mjs +0 -37
- package/dist/es/render/dom/DOMKeyframesResolver.mjs +0 -130
- package/dist/es/render/dom/scroll/observe.mjs +0 -18
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +0 -42
- package/dist/es/render/dom/utils/is-css-variable.mjs +0 -15
- package/dist/es/render/dom/utils/unit-conversion.mjs +0 -36
- package/dist/es/render/dom/value-types/animatable-none.mjs +0 -15
- package/dist/es/render/dom/value-types/defaults.mjs +0 -30
- package/dist/es/render/dom/value-types/dimensions.mjs +0 -15
- package/dist/es/render/dom/value-types/find.mjs +0 -15
- package/dist/es/render/dom/value-types/get-as-type.mjs +0 -10
- package/dist/es/render/dom/value-types/number-browser.mjs +0 -41
- package/dist/es/render/dom/value-types/number.mjs +0 -18
- package/dist/es/render/dom/value-types/test.mjs +0 -6
- package/dist/es/render/dom/value-types/transform.mjs +0 -31
- package/dist/es/render/dom/value-types/type-auto.mjs +0 -9
- package/dist/es/render/dom/value-types/type-int.mjs +0 -8
- package/dist/es/render/html/utils/keys-position.mjs +0 -13
- package/dist/es/render/html/utils/keys-transform.mjs +0 -28
- package/dist/es/render/html/utils/make-none-animatable.mjs +0 -30
- package/dist/es/render/html/utils/parse-transform.mjs +0 -83
- package/dist/es/render/utils/KeyframesResolver.mjs +0 -163
- package/dist/es/utils/clamp.mjs +0 -9
- package/dist/es/utils/hsla-to-rgba.mjs +0 -42
- package/dist/es/utils/interpolate.mjs +0 -76
- package/dist/es/utils/is-numerical-string.mjs +0 -6
- package/dist/es/utils/is-zero-value-string.mjs +0 -6
- package/dist/es/utils/mix/color.mjs +0 -47
- package/dist/es/utils/mix/complex.mjs +0 -93
- package/dist/es/utils/mix/immediate.mjs +0 -5
- package/dist/es/utils/mix/index.mjs +0 -14
- package/dist/es/utils/mix/number.mjs +0 -26
- package/dist/es/utils/mix/visibility.mjs +0 -16
- package/dist/es/utils/offsets/default.mjs +0 -9
- package/dist/es/utils/offsets/fill.mjs +0 -12
- package/dist/es/utils/offsets/time.mjs +0 -5
- package/dist/es/utils/pipe.mjs +0 -11
- package/dist/es/utils/use-instant-transition-state.mjs +0 -5
- package/dist/es/utils/wrap.mjs +0 -6
- package/dist/es/value/types/color/hex.mjs +0 -40
- package/dist/es/value/types/color/hsla.mjs +0 -22
- package/dist/es/value/types/color/index.mjs +0 -27
- package/dist/es/value/types/color/rgba.mjs +0 -25
- package/dist/es/value/types/color/utils.mjs +0 -29
- package/dist/es/value/types/complex/filter.mjs +0 -30
- package/dist/es/value/types/complex/index.mjs +0 -91
- package/dist/es/value/types/numbers/index.mjs +0 -17
- package/dist/es/value/types/numbers/units.mjs +0 -17
- package/dist/es/value/types/utils/color-regex.mjs +0 -3
- package/dist/es/value/types/utils/float-regex.mjs +0 -3
- package/dist/es/value/types/utils/is-nullish.mjs +0 -5
- package/dist/es/value/types/utils/sanitize.mjs +0 -5
- package/dist/es/value/types/utils/single-color-regex.mjs +0 -3
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { warning, secondsToMilliseconds, millisecondsToSeconds } from 'motion-utils';
|
|
2
|
-
import { clamp } from '../../../utils/clamp.mjs';
|
|
3
|
-
import { springDefaults } from './defaults.mjs';
|
|
4
|
-
|
|
5
|
-
const safeMin = 0.001;
|
|
6
|
-
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
|
|
7
|
-
let envelope;
|
|
8
|
-
let derivative;
|
|
9
|
-
warning(duration <= secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less");
|
|
10
|
-
let dampingRatio = 1 - bounce;
|
|
11
|
-
/**
|
|
12
|
-
* Restrict dampingRatio and duration to within acceptable ranges.
|
|
13
|
-
*/
|
|
14
|
-
dampingRatio = clamp(springDefaults.minDamping, springDefaults.maxDamping, dampingRatio);
|
|
15
|
-
duration = clamp(springDefaults.minDuration, springDefaults.maxDuration, millisecondsToSeconds(duration));
|
|
16
|
-
if (dampingRatio < 1) {
|
|
17
|
-
/**
|
|
18
|
-
* Underdamped spring
|
|
19
|
-
*/
|
|
20
|
-
envelope = (undampedFreq) => {
|
|
21
|
-
const exponentialDecay = undampedFreq * dampingRatio;
|
|
22
|
-
const delta = exponentialDecay * duration;
|
|
23
|
-
const a = exponentialDecay - velocity;
|
|
24
|
-
const b = calcAngularFreq(undampedFreq, dampingRatio);
|
|
25
|
-
const c = Math.exp(-delta);
|
|
26
|
-
return safeMin - (a / b) * c;
|
|
27
|
-
};
|
|
28
|
-
derivative = (undampedFreq) => {
|
|
29
|
-
const exponentialDecay = undampedFreq * dampingRatio;
|
|
30
|
-
const delta = exponentialDecay * duration;
|
|
31
|
-
const d = delta * velocity + velocity;
|
|
32
|
-
const e = Math.pow(dampingRatio, 2) * Math.pow(undampedFreq, 2) * duration;
|
|
33
|
-
const f = Math.exp(-delta);
|
|
34
|
-
const g = calcAngularFreq(Math.pow(undampedFreq, 2), dampingRatio);
|
|
35
|
-
const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
|
|
36
|
-
return (factor * ((d - e) * f)) / g;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
/**
|
|
41
|
-
* Critically-damped spring
|
|
42
|
-
*/
|
|
43
|
-
envelope = (undampedFreq) => {
|
|
44
|
-
const a = Math.exp(-undampedFreq * duration);
|
|
45
|
-
const b = (undampedFreq - velocity) * duration + 1;
|
|
46
|
-
return -safeMin + a * b;
|
|
47
|
-
};
|
|
48
|
-
derivative = (undampedFreq) => {
|
|
49
|
-
const a = Math.exp(-undampedFreq * duration);
|
|
50
|
-
const b = (velocity - undampedFreq) * (duration * duration);
|
|
51
|
-
return a * b;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
const initialGuess = 5 / duration;
|
|
55
|
-
const undampedFreq = approximateRoot(envelope, derivative, initialGuess);
|
|
56
|
-
duration = secondsToMilliseconds(duration);
|
|
57
|
-
if (isNaN(undampedFreq)) {
|
|
58
|
-
return {
|
|
59
|
-
stiffness: springDefaults.stiffness,
|
|
60
|
-
damping: springDefaults.damping,
|
|
61
|
-
duration,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const stiffness = Math.pow(undampedFreq, 2) * mass;
|
|
66
|
-
return {
|
|
67
|
-
stiffness,
|
|
68
|
-
damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
|
|
69
|
-
duration,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const rootIterations = 12;
|
|
74
|
-
function approximateRoot(envelope, derivative, initialGuess) {
|
|
75
|
-
let result = initialGuess;
|
|
76
|
-
for (let i = 1; i < rootIterations; i++) {
|
|
77
|
-
result = result - envelope(result) / derivative(result);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
function calcAngularFreq(undampedFreq, dampingRatio) {
|
|
82
|
-
return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { calcAngularFreq, findSpring };
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { createGeneratorEasing, supportsLinearEasing, calcGeneratorDuration, maxGeneratorDuration, generateLinearEasing } from 'motion-dom';
|
|
2
|
-
import { millisecondsToSeconds, secondsToMilliseconds } from 'motion-utils';
|
|
3
|
-
import { clamp } from '../../../utils/clamp.mjs';
|
|
4
|
-
import { calcGeneratorVelocity } from '../utils/velocity.mjs';
|
|
5
|
-
import { springDefaults } from './defaults.mjs';
|
|
6
|
-
import { findSpring, calcAngularFreq } from './find.mjs';
|
|
7
|
-
|
|
8
|
-
const durationKeys = ["duration", "bounce"];
|
|
9
|
-
const physicsKeys = ["stiffness", "damping", "mass"];
|
|
10
|
-
function isSpringType(options, keys) {
|
|
11
|
-
return keys.some((key) => options[key] !== undefined);
|
|
12
|
-
}
|
|
13
|
-
function getSpringOptions(options) {
|
|
14
|
-
let springOptions = {
|
|
15
|
-
velocity: springDefaults.velocity,
|
|
16
|
-
stiffness: springDefaults.stiffness,
|
|
17
|
-
damping: springDefaults.damping,
|
|
18
|
-
mass: springDefaults.mass,
|
|
19
|
-
isResolvedFromDuration: false,
|
|
20
|
-
...options,
|
|
21
|
-
};
|
|
22
|
-
// stiffness/damping/mass overrides duration/bounce
|
|
23
|
-
if (!isSpringType(options, physicsKeys) &&
|
|
24
|
-
isSpringType(options, durationKeys)) {
|
|
25
|
-
if (options.visualDuration) {
|
|
26
|
-
const visualDuration = options.visualDuration;
|
|
27
|
-
const root = (2 * Math.PI) / (visualDuration * 1.2);
|
|
28
|
-
const stiffness = root * root;
|
|
29
|
-
const damping = 2 *
|
|
30
|
-
clamp(0.05, 1, 1 - (options.bounce || 0)) *
|
|
31
|
-
Math.sqrt(stiffness);
|
|
32
|
-
springOptions = {
|
|
33
|
-
...springOptions,
|
|
34
|
-
mass: springDefaults.mass,
|
|
35
|
-
stiffness,
|
|
36
|
-
damping,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const derived = findSpring(options);
|
|
41
|
-
springOptions = {
|
|
42
|
-
...springOptions,
|
|
43
|
-
...derived,
|
|
44
|
-
mass: springDefaults.mass,
|
|
45
|
-
};
|
|
46
|
-
springOptions.isResolvedFromDuration = true;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return springOptions;
|
|
50
|
-
}
|
|
51
|
-
function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce = springDefaults.bounce) {
|
|
52
|
-
const options = typeof optionsOrVisualDuration !== "object"
|
|
53
|
-
? {
|
|
54
|
-
visualDuration: optionsOrVisualDuration,
|
|
55
|
-
keyframes: [0, 1],
|
|
56
|
-
bounce,
|
|
57
|
-
}
|
|
58
|
-
: optionsOrVisualDuration;
|
|
59
|
-
let { restSpeed, restDelta } = options;
|
|
60
|
-
const origin = options.keyframes[0];
|
|
61
|
-
const target = options.keyframes[options.keyframes.length - 1];
|
|
62
|
-
/**
|
|
63
|
-
* This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
|
|
64
|
-
* to reduce GC during animation.
|
|
65
|
-
*/
|
|
66
|
-
const state = { done: false, value: origin };
|
|
67
|
-
const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, } = getSpringOptions({
|
|
68
|
-
...options,
|
|
69
|
-
velocity: -millisecondsToSeconds(options.velocity || 0),
|
|
70
|
-
});
|
|
71
|
-
const initialVelocity = velocity || 0.0;
|
|
72
|
-
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
73
|
-
const initialDelta = target - origin;
|
|
74
|
-
const undampedAngularFreq = millisecondsToSeconds(Math.sqrt(stiffness / mass));
|
|
75
|
-
/**
|
|
76
|
-
* If we're working on a granular scale, use smaller defaults for determining
|
|
77
|
-
* when the spring is finished.
|
|
78
|
-
*
|
|
79
|
-
* These defaults have been selected emprically based on what strikes a good
|
|
80
|
-
* ratio between feeling good and finishing as soon as changes are imperceptible.
|
|
81
|
-
*/
|
|
82
|
-
const isGranularScale = Math.abs(initialDelta) < 5;
|
|
83
|
-
restSpeed || (restSpeed = isGranularScale
|
|
84
|
-
? springDefaults.restSpeed.granular
|
|
85
|
-
: springDefaults.restSpeed.default);
|
|
86
|
-
restDelta || (restDelta = isGranularScale
|
|
87
|
-
? springDefaults.restDelta.granular
|
|
88
|
-
: springDefaults.restDelta.default);
|
|
89
|
-
let resolveSpring;
|
|
90
|
-
if (dampingRatio < 1) {
|
|
91
|
-
const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
92
|
-
// Underdamped spring
|
|
93
|
-
resolveSpring = (t) => {
|
|
94
|
-
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
95
|
-
return (target -
|
|
96
|
-
envelope *
|
|
97
|
-
(((initialVelocity +
|
|
98
|
-
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
99
|
-
angularFreq) *
|
|
100
|
-
Math.sin(angularFreq * t) +
|
|
101
|
-
initialDelta * Math.cos(angularFreq * t)));
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else if (dampingRatio === 1) {
|
|
105
|
-
// Critically damped spring
|
|
106
|
-
resolveSpring = (t) => target -
|
|
107
|
-
Math.exp(-undampedAngularFreq * t) *
|
|
108
|
-
(initialDelta +
|
|
109
|
-
(initialVelocity + undampedAngularFreq * initialDelta) * t);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// Overdamped spring
|
|
113
|
-
const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
|
|
114
|
-
resolveSpring = (t) => {
|
|
115
|
-
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
116
|
-
// When performing sinh or cosh values can hit Infinity so we cap them here
|
|
117
|
-
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
118
|
-
return (target -
|
|
119
|
-
(envelope *
|
|
120
|
-
((initialVelocity +
|
|
121
|
-
dampingRatio * undampedAngularFreq * initialDelta) *
|
|
122
|
-
Math.sinh(freqForT) +
|
|
123
|
-
dampedAngularFreq *
|
|
124
|
-
initialDelta *
|
|
125
|
-
Math.cosh(freqForT))) /
|
|
126
|
-
dampedAngularFreq);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
const generator = {
|
|
130
|
-
calculatedDuration: isResolvedFromDuration ? duration || null : null,
|
|
131
|
-
next: (t) => {
|
|
132
|
-
const current = resolveSpring(t);
|
|
133
|
-
if (!isResolvedFromDuration) {
|
|
134
|
-
let currentVelocity = 0.0;
|
|
135
|
-
/**
|
|
136
|
-
* We only need to calculate velocity for under-damped springs
|
|
137
|
-
* as over- and critically-damped springs can't overshoot, so
|
|
138
|
-
* checking only for displacement is enough.
|
|
139
|
-
*/
|
|
140
|
-
if (dampingRatio < 1) {
|
|
141
|
-
currentVelocity =
|
|
142
|
-
t === 0
|
|
143
|
-
? secondsToMilliseconds(initialVelocity)
|
|
144
|
-
: calcGeneratorVelocity(resolveSpring, t, current);
|
|
145
|
-
}
|
|
146
|
-
const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
|
|
147
|
-
const isBelowDisplacementThreshold = Math.abs(target - current) <= restDelta;
|
|
148
|
-
state.done =
|
|
149
|
-
isBelowVelocityThreshold && isBelowDisplacementThreshold;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
state.done = t >= duration;
|
|
153
|
-
}
|
|
154
|
-
state.value = state.done ? target : current;
|
|
155
|
-
return state;
|
|
156
|
-
},
|
|
157
|
-
toString: () => {
|
|
158
|
-
const calculatedDuration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
159
|
-
const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
|
|
160
|
-
return calculatedDuration + "ms " + easing;
|
|
161
|
-
},
|
|
162
|
-
toTransition: () => { },
|
|
163
|
-
};
|
|
164
|
-
return generator;
|
|
165
|
-
}
|
|
166
|
-
spring.applyToOptions = (options) => {
|
|
167
|
-
const generatorOptions = createGeneratorEasing(options, 100, spring);
|
|
168
|
-
options.ease = supportsLinearEasing() ? generatorOptions.ease : "easeOut";
|
|
169
|
-
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
170
|
-
options.type = "keyframes";
|
|
171
|
-
return options;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export { spring };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { velocityPerSecond } from 'motion-utils';
|
|
2
|
-
|
|
3
|
-
const velocitySampleDuration = 5; // ms
|
|
4
|
-
function calcGeneratorVelocity(resolveValue, t, current) {
|
|
5
|
-
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
6
|
-
return velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { calcGeneratorVelocity };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { complex } from '../../value/types/complex/index.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check if a value is animatable. Examples:
|
|
5
|
-
*
|
|
6
|
-
* ✅: 100, "100px", "#fff"
|
|
7
|
-
* ❌: "block", "url(2.jpg)"
|
|
8
|
-
* @param value
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
const isAnimatable = (value, name) => {
|
|
13
|
-
// If the list of keys tat might be non-animatable grows, replace with Set
|
|
14
|
-
if (name === "zIndex")
|
|
15
|
-
return false;
|
|
16
|
-
// If it's a number or a keyframes array, we can animate it. We might at some point
|
|
17
|
-
// need to do a deep isAnimatable check of keyframes, or let Popmotion handle this,
|
|
18
|
-
// but for now lets leave it like this for performance reasons
|
|
19
|
-
if (typeof value === "number" || Array.isArray(value))
|
|
20
|
-
return true;
|
|
21
|
-
if (typeof value === "string" && // It's animatable if we have a string
|
|
22
|
-
(complex.test(value) || value === "0") && // And it contains numbers and/or colors
|
|
23
|
-
!value.startsWith("url(") // Unless it starts with "url("
|
|
24
|
-
) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { isAnimatable };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isZeroValueString } from '../../utils/is-zero-value-string.mjs';
|
|
2
|
-
|
|
3
|
-
function isNone(value) {
|
|
4
|
-
if (typeof value === "number") {
|
|
5
|
-
return value === 0;
|
|
6
|
-
}
|
|
7
|
-
else if (value !== null) {
|
|
8
|
-
return value === "none" || value === "0" || isZeroValueString(value);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { isNone };
|
package/dist/es/easing/back.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { cubicBezier } from './cubic-bezier.mjs';
|
|
2
|
-
import { mirrorEasing } from './modifiers/mirror.mjs';
|
|
3
|
-
import { reverseEasing } from './modifiers/reverse.mjs';
|
|
4
|
-
|
|
5
|
-
const backOut = /*@__PURE__*/ cubicBezier(0.33, 1.53, 0.69, 0.99);
|
|
6
|
-
const backIn = /*@__PURE__*/ reverseEasing(backOut);
|
|
7
|
-
const backInOut = /*@__PURE__*/ mirrorEasing(backIn);
|
|
8
|
-
|
|
9
|
-
export { backIn, backInOut, backOut };
|
package/dist/es/easing/circ.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { mirrorEasing } from './modifiers/mirror.mjs';
|
|
2
|
-
import { reverseEasing } from './modifiers/reverse.mjs';
|
|
3
|
-
|
|
4
|
-
const circIn = (p) => 1 - Math.sin(Math.acos(p));
|
|
5
|
-
const circOut = reverseEasing(circIn);
|
|
6
|
-
const circInOut = mirrorEasing(circIn);
|
|
7
|
-
|
|
8
|
-
export { circIn, circInOut, circOut };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { noop } from 'motion-utils';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
Bezier function generator
|
|
5
|
-
This has been modified from Gaëtan Renaudeau's BezierEasing
|
|
6
|
-
https://github.com/gre/bezier-easing/blob/master/src/index.js
|
|
7
|
-
https://github.com/gre/bezier-easing/blob/master/LICENSE
|
|
8
|
-
|
|
9
|
-
I've removed the newtonRaphsonIterate algo because in benchmarking it
|
|
10
|
-
wasn't noticiably faster than binarySubdivision, indeed removing it
|
|
11
|
-
usually improved times, depending on the curve.
|
|
12
|
-
I also removed the lookup table, as for the added bundle size and loop we're
|
|
13
|
-
only cutting ~4 or so subdivision iterations. I bumped the max iterations up
|
|
14
|
-
to 12 to compensate and this still tended to be faster for no perceivable
|
|
15
|
-
loss in accuracy.
|
|
16
|
-
Usage
|
|
17
|
-
const easeOut = cubicBezier(.17,.67,.83,.67);
|
|
18
|
-
const x = easeOut(0.5); // returns 0.627...
|
|
19
|
-
*/
|
|
20
|
-
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
|
21
|
-
const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) *
|
|
22
|
-
t;
|
|
23
|
-
const subdivisionPrecision = 0.0000001;
|
|
24
|
-
const subdivisionMaxIterations = 12;
|
|
25
|
-
function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
|
|
26
|
-
let currentX;
|
|
27
|
-
let currentT;
|
|
28
|
-
let i = 0;
|
|
29
|
-
do {
|
|
30
|
-
currentT = lowerBound + (upperBound - lowerBound) / 2.0;
|
|
31
|
-
currentX = calcBezier(currentT, mX1, mX2) - x;
|
|
32
|
-
if (currentX > 0.0) {
|
|
33
|
-
upperBound = currentT;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
lowerBound = currentT;
|
|
37
|
-
}
|
|
38
|
-
} while (Math.abs(currentX) > subdivisionPrecision &&
|
|
39
|
-
++i < subdivisionMaxIterations);
|
|
40
|
-
return currentT;
|
|
41
|
-
}
|
|
42
|
-
function cubicBezier(mX1, mY1, mX2, mY2) {
|
|
43
|
-
// If this is a linear gradient, return linear easing
|
|
44
|
-
if (mX1 === mY1 && mX2 === mY2)
|
|
45
|
-
return noop;
|
|
46
|
-
const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
|
|
47
|
-
// If animation is at start/end, return t without easing
|
|
48
|
-
return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { cubicBezier };
|
package/dist/es/easing/ease.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { cubicBezier } from './cubic-bezier.mjs';
|
|
2
|
-
|
|
3
|
-
const easeIn = /*@__PURE__*/ cubicBezier(0.42, 0, 1, 1);
|
|
4
|
-
const easeOut = /*@__PURE__*/ cubicBezier(0, 0, 0.58, 1);
|
|
5
|
-
const easeInOut = /*@__PURE__*/ cubicBezier(0.42, 0, 0.58, 1);
|
|
6
|
-
|
|
7
|
-
export { easeIn, easeInOut, easeOut };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// Accepts an easing function and returns a new one that outputs mirrored values for
|
|
2
|
-
// the second half of the animation. Turns easeIn into easeInOut.
|
|
3
|
-
const mirrorEasing = (easing) => (p) => p <= 0.5 ? easing(2 * p) / 2 : (2 - easing(2 * (1 - p))) / 2;
|
|
4
|
-
|
|
5
|
-
export { mirrorEasing };
|
package/dist/es/easing/steps.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { clamp } from '../utils/clamp.mjs';
|
|
2
|
-
|
|
3
|
-
function steps(numSteps, direction = "end") {
|
|
4
|
-
return (progress) => {
|
|
5
|
-
progress =
|
|
6
|
-
direction === "end"
|
|
7
|
-
? Math.min(progress, 0.999)
|
|
8
|
-
: Math.max(progress, 0.001);
|
|
9
|
-
const expanded = progress * numSteps;
|
|
10
|
-
const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
|
|
11
|
-
return clamp(0, 1, rounded / numSteps);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { steps };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isBezierDefinition } from 'motion-dom';
|
|
2
|
-
import { invariant, noop } from 'motion-utils';
|
|
3
|
-
import { anticipate } from '../anticipate.mjs';
|
|
4
|
-
import { backIn, backInOut, backOut } from '../back.mjs';
|
|
5
|
-
import { circIn, circInOut, circOut } from '../circ.mjs';
|
|
6
|
-
import { cubicBezier } from '../cubic-bezier.mjs';
|
|
7
|
-
import { easeIn, easeInOut, easeOut } from '../ease.mjs';
|
|
8
|
-
|
|
9
|
-
const easingLookup = {
|
|
10
|
-
linear: noop,
|
|
11
|
-
easeIn,
|
|
12
|
-
easeInOut,
|
|
13
|
-
easeOut,
|
|
14
|
-
circIn,
|
|
15
|
-
circInOut,
|
|
16
|
-
circOut,
|
|
17
|
-
backIn,
|
|
18
|
-
backInOut,
|
|
19
|
-
backOut,
|
|
20
|
-
anticipate,
|
|
21
|
-
};
|
|
22
|
-
const easingDefinitionToFunction = (definition) => {
|
|
23
|
-
if (isBezierDefinition(definition)) {
|
|
24
|
-
// If cubic bezier definition, create bezier curve
|
|
25
|
-
invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`);
|
|
26
|
-
const [x1, y1, x2, y2] = definition;
|
|
27
|
-
return cubicBezier(x1, y1, x2, y2);
|
|
28
|
-
}
|
|
29
|
-
else if (typeof definition === "string") {
|
|
30
|
-
// Else lookup from table
|
|
31
|
-
invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`);
|
|
32
|
-
return easingLookup[definition];
|
|
33
|
-
}
|
|
34
|
-
return definition;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { easingDefinitionToFunction };
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { isNone } from '../../animation/utils/is-none.mjs';
|
|
2
|
-
import { positionalKeys } from '../html/utils/keys-position.mjs';
|
|
3
|
-
import { makeNoneKeyframesAnimatable } from '../html/utils/make-none-animatable.mjs';
|
|
4
|
-
import { KeyframeResolver } from '../utils/KeyframesResolver.mjs';
|
|
5
|
-
import { getVariableValue } from './utils/css-variables-conversion.mjs';
|
|
6
|
-
import { isCSSVariableToken } from './utils/is-css-variable.mjs';
|
|
7
|
-
import { isNumOrPxType, positionalValues } from './utils/unit-conversion.mjs';
|
|
8
|
-
import { findDimensionValueType } from './value-types/dimensions.mjs';
|
|
9
|
-
|
|
10
|
-
class DOMKeyframesResolver extends KeyframeResolver {
|
|
11
|
-
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
12
|
-
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
13
|
-
}
|
|
14
|
-
readKeyframes() {
|
|
15
|
-
const { unresolvedKeyframes, element, name } = this;
|
|
16
|
-
if (!element || !element.current)
|
|
17
|
-
return;
|
|
18
|
-
super.readKeyframes();
|
|
19
|
-
/**
|
|
20
|
-
* If any keyframe is a CSS variable, we need to find its value by sampling the element
|
|
21
|
-
*/
|
|
22
|
-
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
23
|
-
let keyframe = unresolvedKeyframes[i];
|
|
24
|
-
if (typeof keyframe === "string") {
|
|
25
|
-
keyframe = keyframe.trim();
|
|
26
|
-
if (isCSSVariableToken(keyframe)) {
|
|
27
|
-
const resolved = getVariableValue(keyframe, element.current);
|
|
28
|
-
if (resolved !== undefined) {
|
|
29
|
-
unresolvedKeyframes[i] = resolved;
|
|
30
|
-
}
|
|
31
|
-
if (i === unresolvedKeyframes.length - 1) {
|
|
32
|
-
this.finalKeyframe = keyframe;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Resolve "none" values. We do this potentially twice - once before and once after measuring keyframes.
|
|
39
|
-
* This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which
|
|
40
|
-
* have a far bigger performance impact.
|
|
41
|
-
*/
|
|
42
|
-
this.resolveNoneKeyframes();
|
|
43
|
-
/**
|
|
44
|
-
* Check to see if unit type has changed. If so schedule jobs that will
|
|
45
|
-
* temporarily set styles to the destination keyframes.
|
|
46
|
-
* Skip if we have more than two keyframes or this isn't a positional value.
|
|
47
|
-
* TODO: We can throw if there are multiple keyframes and the value type changes.
|
|
48
|
-
*/
|
|
49
|
-
if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const [origin, target] = unresolvedKeyframes;
|
|
53
|
-
const originType = findDimensionValueType(origin);
|
|
54
|
-
const targetType = findDimensionValueType(target);
|
|
55
|
-
/**
|
|
56
|
-
* Either we don't recognise these value types or we can animate between them.
|
|
57
|
-
*/
|
|
58
|
-
if (originType === targetType)
|
|
59
|
-
return;
|
|
60
|
-
/**
|
|
61
|
-
* If both values are numbers or pixels, we can animate between them by
|
|
62
|
-
* converting them to numbers.
|
|
63
|
-
*/
|
|
64
|
-
if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {
|
|
65
|
-
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
66
|
-
const value = unresolvedKeyframes[i];
|
|
67
|
-
if (typeof value === "string") {
|
|
68
|
-
unresolvedKeyframes[i] = parseFloat(value);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
/**
|
|
74
|
-
* Else, the only way to resolve this is by measuring the element.
|
|
75
|
-
*/
|
|
76
|
-
this.needsMeasurement = true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
resolveNoneKeyframes() {
|
|
80
|
-
const { unresolvedKeyframes, name } = this;
|
|
81
|
-
const noneKeyframeIndexes = [];
|
|
82
|
-
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
83
|
-
if (isNone(unresolvedKeyframes[i])) {
|
|
84
|
-
noneKeyframeIndexes.push(i);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (noneKeyframeIndexes.length) {
|
|
88
|
-
makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
measureInitialState() {
|
|
92
|
-
const { element, unresolvedKeyframes, name } = this;
|
|
93
|
-
if (!element || !element.current)
|
|
94
|
-
return;
|
|
95
|
-
if (name === "height") {
|
|
96
|
-
this.suspendedScrollY = window.pageYOffset;
|
|
97
|
-
}
|
|
98
|
-
this.measuredOrigin = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
|
|
99
|
-
unresolvedKeyframes[0] = this.measuredOrigin;
|
|
100
|
-
// Set final key frame to measure after next render
|
|
101
|
-
const measureKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
|
|
102
|
-
if (measureKeyframe !== undefined) {
|
|
103
|
-
element.getValue(name, measureKeyframe).jump(measureKeyframe, false);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
measureEndState() {
|
|
107
|
-
const { element, name, unresolvedKeyframes } = this;
|
|
108
|
-
if (!element || !element.current)
|
|
109
|
-
return;
|
|
110
|
-
const value = element.getValue(name);
|
|
111
|
-
value && value.jump(this.measuredOrigin, false);
|
|
112
|
-
const finalKeyframeIndex = unresolvedKeyframes.length - 1;
|
|
113
|
-
const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex];
|
|
114
|
-
unresolvedKeyframes[finalKeyframeIndex] = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
|
|
115
|
-
if (finalKeyframe !== null && this.finalKeyframe === undefined) {
|
|
116
|
-
this.finalKeyframe = finalKeyframe;
|
|
117
|
-
}
|
|
118
|
-
// If we removed transform values, reapply them before the next render
|
|
119
|
-
if (this.removedTransforms?.length) {
|
|
120
|
-
this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
|
|
121
|
-
element
|
|
122
|
-
.getValue(unsetTransformName)
|
|
123
|
-
.set(unsetTransformValue);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
this.resolveNoneKeyframes();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export { DOMKeyframesResolver };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { frame, cancelFrame } from 'motion-dom';
|
|
2
|
-
|
|
3
|
-
function observeTimeline(update, timeline) {
|
|
4
|
-
let prevProgress;
|
|
5
|
-
const onFrame = () => {
|
|
6
|
-
const { currentTime } = timeline;
|
|
7
|
-
const percentage = currentTime === null ? 0 : currentTime.value;
|
|
8
|
-
const progress = percentage / 100;
|
|
9
|
-
if (prevProgress !== progress) {
|
|
10
|
-
update(progress);
|
|
11
|
-
}
|
|
12
|
-
prevProgress = progress;
|
|
13
|
-
};
|
|
14
|
-
frame.update(onFrame, true);
|
|
15
|
-
return () => cancelFrame(onFrame);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { observeTimeline };
|