motion 11.14.4 → 11.16.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 +3 -19
- package/dist/cjs/index.js +1795 -1724
- package/dist/cjs/mini.js +215 -185
- package/dist/cjs/react-client.js +3713 -3699
- package/dist/cjs/react-m.js +3 -2
- package/dist/cjs/react-mini.js +215 -185
- package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +1 -0
- package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +7 -7
- package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +8 -8
- package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +26 -89
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +3 -3
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/index.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/generators/spring/find.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +9 -6
- package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +7 -6
- package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +4 -3
- package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +32 -6
- package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-repeat-duration.mjs +5 -0
- package/dist/es/framer-motion/dist/es/animation/sequence/utils/normalize-times.mjs +13 -0
- package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +4 -4
- package/dist/es/framer-motion/dist/es/events/event-info.mjs +1 -0
- package/dist/es/framer-motion/dist/es/frameloop/render-step.mjs +3 -2
- package/dist/es/framer-motion/dist/es/gestures/drag/utils/constraints.mjs +2 -1
- package/dist/es/framer-motion/dist/es/gestures/hover.mjs +1 -0
- package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +5 -4
- package/dist/es/framer-motion/dist/es/gestures/press.mjs +1 -0
- package/dist/es/framer-motion/dist/es/projection/animation/mix-values.mjs +3 -3
- package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +15 -15
- package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +1 -0
- package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +3 -3
- package/dist/es/framer-motion/dist/es/render/dom/scroll/info.mjs +2 -1
- package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +1 -0
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/delay.mjs +2 -1
- package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +3 -3
- package/dist/es/framer-motion/dist/es/utils/offsets/fill.mjs +2 -1
- package/dist/es/framer-motion/dist/es/value/index.mjs +2 -2
- package/dist/es/framer-motion/dist/es/value/use-spring.mjs +3 -3
- package/dist/es/motion/lib/index.mjs +8 -8
- package/dist/es/motion/lib/react.mjs +8 -8
- package/dist/es/{framer-motion/dist/es/animation/GroupPlaybackControls.mjs → motion-dom/dist/es/animation/controls/BaseGroup.mjs} +6 -5
- package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +13 -0
- package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es/animation/generators}/utils/create-generator-easing.mjs +6 -3
- package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +85 -0
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi → motion-dom/dist/es/animation/waapi/utils}/easing.mjs +3 -3
- package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/linear.mjs +2 -1
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-linear-easing.mjs → motion-dom/dist/es/utils/supports/linear-easing.mjs} +1 -1
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/memo-supports.mjs → motion-dom/dist/es/utils/supports/memo.mjs} +3 -2
- package/dist/es/motion-dom/dist/es/utils/supports/scroll-timeline.mjs +6 -0
- package/dist/motion.dev.js +1795 -1724
- package/dist/motion.js +1 -1
- package/package.json +3 -3
- package/dist/es/framer-motion/dist/es/render/dom/scroll/supports.mjs +0 -5
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/calc-duration.mjs +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/is-generator.mjs +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/utils/get-value-transition.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/attach-timeline.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es}/utils/is-bezier-definition.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-flags.mjs → motion-dom/dist/es/utils/supports/flags.mjs} +0 -0
- /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/memo.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/progress.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/time-conversion.mjs +0 -0
package/dist/cjs/mini.js
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
const noop = (any) => any;
|
|
6
|
+
|
|
7
|
+
let invariant = noop;
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
invariant = (check, message) => {
|
|
10
|
+
if (!check) {
|
|
11
|
+
throw new Error(message);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
5
16
|
function memo(callback) {
|
|
6
17
|
let result;
|
|
7
18
|
return () => {
|
|
@@ -11,16 +22,43 @@ function memo(callback) {
|
|
|
11
22
|
};
|
|
12
23
|
}
|
|
13
24
|
|
|
25
|
+
/*
|
|
26
|
+
Progress within given range
|
|
27
|
+
|
|
28
|
+
Given a lower limit and an upper limit, we return the progress
|
|
29
|
+
(expressed as a number 0-1) represented by the given value, and
|
|
30
|
+
limit that progress to within 0-1.
|
|
31
|
+
|
|
32
|
+
@param [number]: Lower limit
|
|
33
|
+
@param [number]: Upper limit
|
|
34
|
+
@param [number]: Value to find progress within given range
|
|
35
|
+
@return [number]: Progress of value within range as expressed 0-1
|
|
36
|
+
*/
|
|
37
|
+
const progress = (from, to, value) => {
|
|
38
|
+
const toFromDifference = to - from;
|
|
39
|
+
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Converts seconds to milliseconds
|
|
44
|
+
*
|
|
45
|
+
* @param seconds - Time in seconds.
|
|
46
|
+
* @return milliseconds - Converted time in milliseconds.
|
|
47
|
+
*/
|
|
48
|
+
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
|
49
|
+
const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
|
|
50
|
+
|
|
14
51
|
const supportsScrollTimeline = memo(() => window.ScrollTimeline !== undefined);
|
|
15
52
|
|
|
16
|
-
class
|
|
53
|
+
class BaseGroupPlaybackControls {
|
|
17
54
|
constructor(animations) {
|
|
18
55
|
// Bound to accomodate common `return animation.stop` pattern
|
|
19
56
|
this.stop = () => this.runAll("stop");
|
|
20
57
|
this.animations = animations.filter(Boolean);
|
|
21
58
|
}
|
|
22
|
-
|
|
23
|
-
|
|
59
|
+
get finished() {
|
|
60
|
+
// Support for new finished Promise and legacy thennable API
|
|
61
|
+
return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
|
|
24
62
|
}
|
|
25
63
|
/**
|
|
26
64
|
* TODO: Filter out cancelled or stopped animations before returning
|
|
@@ -91,46 +129,15 @@ class GroupPlaybackControls {
|
|
|
91
129
|
}
|
|
92
130
|
}
|
|
93
131
|
|
|
94
|
-
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
95
|
-
var _a;
|
|
96
|
-
if (elementOrSelector instanceof Element) {
|
|
97
|
-
return [elementOrSelector];
|
|
98
|
-
}
|
|
99
|
-
else if (typeof elementOrSelector === "string") {
|
|
100
|
-
let root = document;
|
|
101
|
-
if (scope) {
|
|
102
|
-
// TODO: Refactor to utils package
|
|
103
|
-
// invariant(
|
|
104
|
-
// Boolean(scope.current),
|
|
105
|
-
// "Scope provided, but no element detected."
|
|
106
|
-
// )
|
|
107
|
-
root = scope.current;
|
|
108
|
-
}
|
|
109
|
-
const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
|
|
110
|
-
return elements ? Array.from(elements) : [];
|
|
111
|
-
}
|
|
112
|
-
return Array.from(elementOrSelector);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const noop = (any) => any;
|
|
116
|
-
|
|
117
|
-
let invariant = noop;
|
|
118
|
-
if (process.env.NODE_ENV !== "production") {
|
|
119
|
-
invariant = (check, message) => {
|
|
120
|
-
if (!check) {
|
|
121
|
-
throw new Error(message);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
132
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @param seconds - Time in seconds.
|
|
130
|
-
* @return milliseconds - Converted time in milliseconds.
|
|
133
|
+
* TODO: This is a temporary class to support the legacy
|
|
134
|
+
* thennable API
|
|
131
135
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
class GroupPlaybackControls extends BaseGroupPlaybackControls {
|
|
137
|
+
then(onResolve, onReject) {
|
|
138
|
+
return Promise.all(this.animations).then(onResolve).catch(onReject);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
134
141
|
|
|
135
142
|
function getValueTransition(transition, key) {
|
|
136
143
|
return transition
|
|
@@ -140,35 +147,126 @@ function getValueTransition(transition, key) {
|
|
|
140
147
|
: undefined;
|
|
141
148
|
}
|
|
142
149
|
|
|
143
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Implement a practical max duration for keyframe generation
|
|
152
|
+
* to prevent infinite loops
|
|
153
|
+
*/
|
|
154
|
+
const maxGeneratorDuration = 20000;
|
|
155
|
+
function calcGeneratorDuration(generator) {
|
|
156
|
+
let duration = 0;
|
|
157
|
+
const timeStep = 50;
|
|
158
|
+
let state = generator.next(duration);
|
|
159
|
+
while (!state.done && duration < maxGeneratorDuration) {
|
|
160
|
+
duration += timeStep;
|
|
161
|
+
state = generator.next(duration);
|
|
162
|
+
}
|
|
163
|
+
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
164
|
+
}
|
|
144
165
|
|
|
145
|
-
|
|
146
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Create a progress => progress easing function from a generator.
|
|
168
|
+
*/
|
|
169
|
+
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
170
|
+
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
171
|
+
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
172
|
+
return {
|
|
173
|
+
type: "keyframes",
|
|
174
|
+
ease: (progress) => {
|
|
175
|
+
return generator.next(duration * progress).value / scale;
|
|
176
|
+
},
|
|
177
|
+
duration: millisecondsToSeconds(duration),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
147
180
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
181
|
+
function isGenerator(type) {
|
|
182
|
+
return typeof type === "function";
|
|
183
|
+
}
|
|
151
184
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*/
|
|
157
|
-
const progress = (from, to, value) => {
|
|
158
|
-
const toFromDifference = to - from;
|
|
159
|
-
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
|
160
|
-
};
|
|
185
|
+
function attachTimeline(animation, timeline) {
|
|
186
|
+
animation.timeline = timeline;
|
|
187
|
+
animation.onfinish = null;
|
|
188
|
+
}
|
|
161
189
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
let points = "";
|
|
166
|
-
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
167
|
-
for (let i = 0; i < numPoints; i++) {
|
|
168
|
-
points += easing(progress(0, numPoints - 1, i)) + ", ";
|
|
190
|
+
class NativeAnimationControls {
|
|
191
|
+
constructor(animation) {
|
|
192
|
+
this.animation = animation;
|
|
169
193
|
}
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
get duration() {
|
|
195
|
+
var _a, _b, _c;
|
|
196
|
+
const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
|
|
197
|
+
((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
|
|
198
|
+
300;
|
|
199
|
+
return millisecondsToSeconds(Number(durationInMs));
|
|
200
|
+
}
|
|
201
|
+
get time() {
|
|
202
|
+
var _a;
|
|
203
|
+
if (this.animation) {
|
|
204
|
+
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
205
|
+
}
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
set time(newTime) {
|
|
209
|
+
if (this.animation) {
|
|
210
|
+
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
get speed() {
|
|
214
|
+
return this.animation ? this.animation.playbackRate : 1;
|
|
215
|
+
}
|
|
216
|
+
set speed(newSpeed) {
|
|
217
|
+
if (this.animation) {
|
|
218
|
+
this.animation.playbackRate = newSpeed;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
get state() {
|
|
222
|
+
return this.animation ? this.animation.playState : "finished";
|
|
223
|
+
}
|
|
224
|
+
get startTime() {
|
|
225
|
+
return this.animation ? this.animation.startTime : null;
|
|
226
|
+
}
|
|
227
|
+
get finished() {
|
|
228
|
+
return this.animation ? this.animation.finished : Promise.resolve();
|
|
229
|
+
}
|
|
230
|
+
play() {
|
|
231
|
+
this.animation && this.animation.play();
|
|
232
|
+
}
|
|
233
|
+
pause() {
|
|
234
|
+
this.animation && this.animation.pause();
|
|
235
|
+
}
|
|
236
|
+
stop() {
|
|
237
|
+
if (!this.animation ||
|
|
238
|
+
this.state === "idle" ||
|
|
239
|
+
this.state === "finished") {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (this.animation.commitStyles) {
|
|
243
|
+
this.animation.commitStyles();
|
|
244
|
+
}
|
|
245
|
+
this.cancel();
|
|
246
|
+
}
|
|
247
|
+
flatten() {
|
|
248
|
+
var _a;
|
|
249
|
+
if (!this.animation)
|
|
250
|
+
return;
|
|
251
|
+
(_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
|
|
252
|
+
}
|
|
253
|
+
attachTimeline(timeline) {
|
|
254
|
+
if (this.animation)
|
|
255
|
+
attachTimeline(this.animation, timeline);
|
|
256
|
+
return noop;
|
|
257
|
+
}
|
|
258
|
+
complete() {
|
|
259
|
+
this.animation && this.animation.finish();
|
|
260
|
+
}
|
|
261
|
+
cancel() {
|
|
262
|
+
try {
|
|
263
|
+
this.animation && this.animation.cancel();
|
|
264
|
+
}
|
|
265
|
+
catch (e) { }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
|
172
270
|
|
|
173
271
|
/**
|
|
174
272
|
* Add the ability for test suites to manually set support flags
|
|
@@ -195,6 +293,17 @@ const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
|
|
|
195
293
|
return true;
|
|
196
294
|
}, "linearEasing");
|
|
197
295
|
|
|
296
|
+
const generateLinearEasing = (easing, duration, // as milliseconds
|
|
297
|
+
resolution = 10 // as milliseconds
|
|
298
|
+
) => {
|
|
299
|
+
let points = "";
|
|
300
|
+
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
301
|
+
for (let i = 0; i < numPoints; i++) {
|
|
302
|
+
points += easing(progress(0, numPoints - 1, i)) + ", ";
|
|
303
|
+
}
|
|
304
|
+
return `linear(${points.substring(0, points.length - 2)})`;
|
|
305
|
+
};
|
|
306
|
+
|
|
198
307
|
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
199
308
|
const supportedWaapiEasing = {
|
|
200
309
|
linear: "linear",
|
|
@@ -226,6 +335,27 @@ function mapEasingToNativeEasing(easing, duration) {
|
|
|
226
335
|
}
|
|
227
336
|
}
|
|
228
337
|
|
|
338
|
+
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
339
|
+
var _a;
|
|
340
|
+
if (elementOrSelector instanceof Element) {
|
|
341
|
+
return [elementOrSelector];
|
|
342
|
+
}
|
|
343
|
+
else if (typeof elementOrSelector === "string") {
|
|
344
|
+
let root = document;
|
|
345
|
+
if (scope) {
|
|
346
|
+
// TODO: Refactor to utils package
|
|
347
|
+
// invariant(
|
|
348
|
+
// Boolean(scope.current),
|
|
349
|
+
// "Scope provided, but no element detected."
|
|
350
|
+
// )
|
|
351
|
+
root = scope.current;
|
|
352
|
+
}
|
|
353
|
+
const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
|
|
354
|
+
return elements ? Array.from(elements) : [];
|
|
355
|
+
}
|
|
356
|
+
return Array.from(elementOrSelector);
|
|
357
|
+
}
|
|
358
|
+
|
|
229
359
|
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
|
|
230
360
|
const keyframeOptions = { [valueName]: keyframes };
|
|
231
361
|
if (times)
|
|
@@ -246,35 +376,6 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
|
|
|
246
376
|
});
|
|
247
377
|
}
|
|
248
378
|
|
|
249
|
-
/**
|
|
250
|
-
* Implement a practical max duration for keyframe generation
|
|
251
|
-
* to prevent infinite loops
|
|
252
|
-
*/
|
|
253
|
-
const maxGeneratorDuration = 20000;
|
|
254
|
-
function calcGeneratorDuration(generator) {
|
|
255
|
-
let duration = 0;
|
|
256
|
-
const timeStep = 50;
|
|
257
|
-
let state = generator.next(duration);
|
|
258
|
-
while (!state.done && duration < maxGeneratorDuration) {
|
|
259
|
-
duration += timeStep;
|
|
260
|
-
state = generator.next(duration);
|
|
261
|
-
}
|
|
262
|
-
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Create a progress => progress easing function from a generator.
|
|
267
|
-
*/
|
|
268
|
-
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
269
|
-
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
270
|
-
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
271
|
-
return {
|
|
272
|
-
type: "keyframes",
|
|
273
|
-
ease: (progress) => generator.next(duration * progress).value / scale,
|
|
274
|
-
duration: millisecondsToSeconds(duration),
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
379
|
const createUnitType = (unit) => ({
|
|
279
380
|
test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
|
|
280
381
|
parse: parseFloat,
|
|
@@ -320,15 +421,6 @@ const browserNumberValueTypes = {
|
|
|
320
421
|
backgroundPositionY: px,
|
|
321
422
|
};
|
|
322
423
|
|
|
323
|
-
function isGenerator(type) {
|
|
324
|
-
return typeof type === "function";
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function attachTimeline(animation, timeline) {
|
|
328
|
-
animation.timeline = timeline;
|
|
329
|
-
animation.onfinish = null;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
424
|
const isNotNull = (value) => value !== null;
|
|
333
425
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
334
426
|
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
@@ -380,12 +472,9 @@ function getElementAnimationState(element) {
|
|
|
380
472
|
state.set(element, animationState);
|
|
381
473
|
return state.get(element);
|
|
382
474
|
}
|
|
383
|
-
class NativeAnimation {
|
|
475
|
+
class NativeAnimation extends NativeAnimationControls {
|
|
384
476
|
constructor(element, valueName, valueKeyframes, options) {
|
|
385
477
|
const isCSSVar = valueName.startsWith("--");
|
|
386
|
-
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
387
|
-
this.options = options;
|
|
388
|
-
this.updateFinishedPromise();
|
|
389
478
|
invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
|
|
390
479
|
const existingAnimation = getElementAnimationState(element).get(valueName);
|
|
391
480
|
existingAnimation && existingAnimation.stop();
|
|
@@ -410,92 +499,32 @@ class NativeAnimation {
|
|
|
410
499
|
else {
|
|
411
500
|
options.ease = options.ease || defaultEasing;
|
|
412
501
|
}
|
|
413
|
-
this.removeAnimation = () => { var _a; return (_a = state.get(element)) === null || _a === void 0 ? void 0 : _a.delete(valueName); };
|
|
414
502
|
const onFinish = () => {
|
|
415
|
-
this.setValue(element, valueName, getFinalKeyframe(valueKeyframes,
|
|
503
|
+
this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
|
|
416
504
|
this.cancel();
|
|
417
505
|
this.resolveFinishedPromise();
|
|
418
506
|
};
|
|
507
|
+
const init = () => {
|
|
508
|
+
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
509
|
+
this.options = options;
|
|
510
|
+
this.updateFinishedPromise();
|
|
511
|
+
this.removeAnimation = () => { var _a; return (_a = state.get(element)) === null || _a === void 0 ? void 0 : _a.delete(valueName); };
|
|
512
|
+
};
|
|
419
513
|
if (!supportsWaapi()) {
|
|
514
|
+
super();
|
|
515
|
+
init();
|
|
420
516
|
onFinish();
|
|
421
517
|
}
|
|
422
518
|
else {
|
|
423
|
-
|
|
519
|
+
super(startWaapiAnimation(element, valueName, valueKeyframes, options));
|
|
520
|
+
init();
|
|
424
521
|
if (options.autoplay === false) {
|
|
425
522
|
this.animation.pause();
|
|
426
523
|
}
|
|
427
524
|
this.animation.onfinish = onFinish;
|
|
428
|
-
if (this.pendingTimeline) {
|
|
429
|
-
attachTimeline(this.animation, this.pendingTimeline);
|
|
430
|
-
}
|
|
431
525
|
getElementAnimationState(element).set(valueName, this);
|
|
432
526
|
}
|
|
433
527
|
}
|
|
434
|
-
get duration() {
|
|
435
|
-
return millisecondsToSeconds(this.options.duration || 300);
|
|
436
|
-
}
|
|
437
|
-
get time() {
|
|
438
|
-
var _a;
|
|
439
|
-
if (this.animation) {
|
|
440
|
-
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
441
|
-
}
|
|
442
|
-
return 0;
|
|
443
|
-
}
|
|
444
|
-
set time(newTime) {
|
|
445
|
-
if (this.animation) {
|
|
446
|
-
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
get speed() {
|
|
450
|
-
return this.animation ? this.animation.playbackRate : 1;
|
|
451
|
-
}
|
|
452
|
-
set speed(newSpeed) {
|
|
453
|
-
if (this.animation) {
|
|
454
|
-
this.animation.playbackRate = newSpeed;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
get state() {
|
|
458
|
-
return this.animation ? this.animation.playState : "finished";
|
|
459
|
-
}
|
|
460
|
-
get startTime() {
|
|
461
|
-
return this.animation ? this.animation.startTime : null;
|
|
462
|
-
}
|
|
463
|
-
flatten() {
|
|
464
|
-
var _a;
|
|
465
|
-
if (!this.animation)
|
|
466
|
-
return;
|
|
467
|
-
(_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
|
|
468
|
-
}
|
|
469
|
-
play() {
|
|
470
|
-
if (this.state === "finished") {
|
|
471
|
-
this.updateFinishedPromise();
|
|
472
|
-
}
|
|
473
|
-
this.animation && this.animation.play();
|
|
474
|
-
}
|
|
475
|
-
pause() {
|
|
476
|
-
this.animation && this.animation.pause();
|
|
477
|
-
}
|
|
478
|
-
stop() {
|
|
479
|
-
if (!this.animation ||
|
|
480
|
-
this.state === "idle" ||
|
|
481
|
-
this.state === "finished") {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
if (this.animation.commitStyles) {
|
|
485
|
-
this.animation.commitStyles();
|
|
486
|
-
}
|
|
487
|
-
this.cancel();
|
|
488
|
-
}
|
|
489
|
-
complete() {
|
|
490
|
-
this.animation && this.animation.finish();
|
|
491
|
-
}
|
|
492
|
-
cancel() {
|
|
493
|
-
this.removeAnimation();
|
|
494
|
-
try {
|
|
495
|
-
this.animation && this.animation.cancel();
|
|
496
|
-
}
|
|
497
|
-
catch (e) { }
|
|
498
|
-
}
|
|
499
528
|
/**
|
|
500
529
|
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
501
530
|
* resolves when the animation finishes at all but in a future update could/should
|
|
@@ -509,14 +538,15 @@ class NativeAnimation {
|
|
|
509
538
|
this.resolveFinishedPromise = resolve;
|
|
510
539
|
});
|
|
511
540
|
}
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
this.
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
attachTimeline(this.animation, timeline);
|
|
541
|
+
play() {
|
|
542
|
+
if (this.state === "finished") {
|
|
543
|
+
this.updateFinishedPromise();
|
|
518
544
|
}
|
|
519
|
-
|
|
545
|
+
super.play();
|
|
546
|
+
}
|
|
547
|
+
cancel() {
|
|
548
|
+
this.removeAnimation();
|
|
549
|
+
super.cancel();
|
|
520
550
|
}
|
|
521
551
|
}
|
|
522
552
|
|