motion 12.6.3-alpha.0 → 12.6.3
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/debug.js +12 -12
- package/dist/cjs/index.js +402 -352
- package/dist/cjs/mini.js +339 -352
- package/dist/cjs/react-client.js +169 -181
- package/dist/cjs/react-m.js +18 -22
- package/dist/cjs/react-mini.js +275 -336
- package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +2 -2
- package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +7 -4
- package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +8 -6
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +10 -8
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +2 -2
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -2
- package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +11 -1
- package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +3 -3
- package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
- package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-variant.mjs +1 -2
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/handoff.mjs +2 -4
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +4 -6
- package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +3 -3
- package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-time.mjs +1 -2
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +2 -2
- package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +5 -10
- package/dist/es/framer-motion/dist/es/motion/features/animation/index.mjs +1 -2
- package/dist/es/framer-motion/dist/es/motion/index.mjs +2 -3
- package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +3 -5
- package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +19 -27
- package/dist/es/framer-motion/dist/es/projection/styles/transform.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +3 -4
- package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +1 -2
- package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +5 -6
- package/dist/es/framer-motion/dist/es/render/dom/scroll/track.mjs +1 -2
- package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/dom/utils/filter-props.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/html/utils/scrape-motion-values.mjs +1 -2
- package/dist/es/framer-motion/dist/es/render/utils/KeyframesResolver.mjs +2 -3
- package/dist/es/framer-motion/dist/es/render/utils/animation-state.mjs +3 -5
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/utils/resolve-variants.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -2
- package/dist/es/framer-motion/dist/es/value/types/complex/index.mjs +2 -3
- package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +2 -2
- package/dist/es/framer-motion/dist/es/value/use-will-change/add-will-change.mjs +0 -7
- package/dist/es/motion/lib/react.mjs +0 -1
- package/dist/es/motion-dom/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
- package/dist/es/motion-dom/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
- package/dist/es/motion-dom/dist/es/animation/NativeAnimation.mjs +161 -0
- package/dist/es/motion-dom/dist/es/animation/generators/utils/is-generator.mjs +1 -1
- package/dist/es/motion-dom/dist/es/animation/keyframes/get-final.mjs +12 -0
- package/dist/es/motion-dom/dist/es/animation/keyframes/hydrate.mjs +26 -0
- package/dist/es/motion-dom/dist/es/animation/utils/get-value-transition.mjs +3 -5
- package/dist/es/motion-dom/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
- package/dist/es/motion-dom/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
- package/dist/es/motion-dom/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
- package/dist/es/motion-dom/dist/es/animation/waapi/easing/supported.mjs +15 -0
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/index.mjs → motion-dom/dist/es/animation/waapi/start-waapi-animation.mjs} +8 -6
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs → motion-dom/dist/es/animation/waapi/supports/partial-keyframes.mjs} +2 -2
- package/dist/es/motion-dom/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
- package/dist/es/motion-dom/dist/es/animation/waapi/utils/linear.mjs +1 -4
- package/dist/es/motion-dom/dist/es/animation/waapi/utils/px-values.mjs +39 -0
- package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +1 -1
- package/dist/es/motion-dom/dist/es/render/dom/style.mjs +15 -0
- package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +2 -7
- package/dist/es/motion-dom/dist/es/utils/supports/flags.mjs +1 -3
- package/dist/es/motion-dom/dist/es/utils/supports/memo.mjs +1 -1
- package/dist/es/motion-dom/dist/es/value/index.mjs +1 -1
- package/dist/es/motion-utils/dist/es/errors.mjs +2 -4
- package/dist/motion.dev.js +402 -352
- package/dist/motion.js +1 -1
- package/package.json +3 -3
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -116
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
- package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +0 -13
- package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -85
- package/dist/es/motion-dom/dist/es/animation/waapi/utils/easing.mjs +0 -44
package/dist/motion.dev.js
CHANGED
|
@@ -14,11 +14,8 @@
|
|
|
14
14
|
arr.splice(index, 1);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let warning = noop;
|
|
21
|
-
exports.invariant = noop;
|
|
17
|
+
let warning = () => { };
|
|
18
|
+
exports.invariant = () => { };
|
|
22
19
|
{
|
|
23
20
|
warning = (check, message) => {
|
|
24
21
|
if (!check && typeof console !== "undefined") {
|
|
@@ -47,6 +44,9 @@
|
|
|
47
44
|
};
|
|
48
45
|
}
|
|
49
46
|
|
|
47
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
48
|
+
const noop = (any) => any;
|
|
49
|
+
|
|
50
50
|
/*
|
|
51
51
|
Progress within given range
|
|
52
52
|
|
|
@@ -135,15 +135,14 @@
|
|
|
135
135
|
|
|
136
136
|
const supportsScrollTimeline = /* @__PURE__ */ memo(() => window.ScrollTimeline !== undefined);
|
|
137
137
|
|
|
138
|
-
class
|
|
138
|
+
class GroupAnimation {
|
|
139
139
|
constructor(animations) {
|
|
140
140
|
// Bound to accomodate common `return animation.stop` pattern
|
|
141
141
|
this.stop = () => this.runAll("stop");
|
|
142
142
|
this.animations = animations.filter(Boolean);
|
|
143
143
|
}
|
|
144
144
|
get finished() {
|
|
145
|
-
|
|
146
|
-
return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
|
|
145
|
+
return Promise.all(this.animations.map((animation) => animation.finished));
|
|
147
146
|
}
|
|
148
147
|
/**
|
|
149
148
|
* TODO: Filter out cancelled or stopped animations before returning
|
|
@@ -214,156 +213,122 @@
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
*/
|
|
221
|
-
class GroupPlaybackControls extends BaseGroupPlaybackControls {
|
|
222
|
-
then(onResolve, onReject) {
|
|
223
|
-
return Promise.all(this.animations).then(onResolve).catch(onReject);
|
|
216
|
+
class GroupAnimationWithThen extends GroupAnimation {
|
|
217
|
+
then(onResolve, _onReject) {
|
|
218
|
+
return this.finished.finally(onResolve).then(() => { });
|
|
224
219
|
}
|
|
225
220
|
}
|
|
226
221
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
function calcGeneratorDuration(generator) {
|
|
241
|
-
let duration = 0;
|
|
242
|
-
const timeStep = 50;
|
|
243
|
-
let state = generator.next(duration);
|
|
244
|
-
while (!state.done && duration < maxGeneratorDuration) {
|
|
245
|
-
duration += timeStep;
|
|
246
|
-
state = generator.next(duration);
|
|
247
|
-
}
|
|
248
|
-
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Create a progress => progress easing function from a generator.
|
|
253
|
-
*/
|
|
254
|
-
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
255
|
-
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
256
|
-
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
257
|
-
return {
|
|
258
|
-
type: "keyframes",
|
|
259
|
-
ease: (progress) => {
|
|
260
|
-
return generator.next(duration * progress).value / scale;
|
|
261
|
-
},
|
|
262
|
-
duration: millisecondsToSeconds(duration),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function isGenerator(type) {
|
|
267
|
-
return typeof type === "function";
|
|
268
|
-
}
|
|
222
|
+
const isCSSVar = (name) => name.startsWith("--");
|
|
223
|
+
const style = {
|
|
224
|
+
set: (element, name, value) => {
|
|
225
|
+
isCSSVar(name)
|
|
226
|
+
? element.style.setProperty(name, value)
|
|
227
|
+
: (element.style[name] = value);
|
|
228
|
+
},
|
|
229
|
+
get: (element, name) => {
|
|
230
|
+
return isCSSVar(name)
|
|
231
|
+
? element.style.getPropertyValue(name)
|
|
232
|
+
: element.style[name];
|
|
233
|
+
},
|
|
234
|
+
};
|
|
269
235
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
236
|
+
const isNotNull$1 = (value) => value !== null;
|
|
237
|
+
function getFinalKeyframe$1(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
238
|
+
const resolvedKeyframes = keyframes.filter(isNotNull$1);
|
|
239
|
+
const index = repeat && repeatType !== "loop" && repeat % 2 === 1
|
|
240
|
+
? 0
|
|
241
|
+
: resolvedKeyframes.length - 1;
|
|
242
|
+
return !index || finalKeyframe === undefined
|
|
243
|
+
? resolvedKeyframes[index]
|
|
244
|
+
: finalKeyframe;
|
|
273
245
|
}
|
|
274
246
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
get duration() {
|
|
280
|
-
var _a, _b, _c;
|
|
281
|
-
const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
|
|
282
|
-
((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
|
|
283
|
-
300;
|
|
284
|
-
return millisecondsToSeconds(Number(durationInMs));
|
|
285
|
-
}
|
|
286
|
-
get time() {
|
|
287
|
-
var _a;
|
|
288
|
-
if (this.animation) {
|
|
289
|
-
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
290
|
-
}
|
|
291
|
-
return 0;
|
|
292
|
-
}
|
|
293
|
-
set time(newTime) {
|
|
294
|
-
if (this.animation) {
|
|
295
|
-
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
get speed() {
|
|
299
|
-
return this.animation ? this.animation.playbackRate : 1;
|
|
300
|
-
}
|
|
301
|
-
set speed(newSpeed) {
|
|
302
|
-
if (this.animation) {
|
|
303
|
-
this.animation.playbackRate = newSpeed;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
get state() {
|
|
307
|
-
return this.animation ? this.animation.playState : "finished";
|
|
308
|
-
}
|
|
309
|
-
get startTime() {
|
|
310
|
-
return this.animation ? this.animation.startTime : null;
|
|
311
|
-
}
|
|
312
|
-
get finished() {
|
|
313
|
-
return this.animation ? this.animation.finished : Promise.resolve();
|
|
247
|
+
const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
|
|
248
|
+
try {
|
|
249
|
+
document.createElement("div").animate({ opacity: [1] });
|
|
314
250
|
}
|
|
315
|
-
|
|
316
|
-
|
|
251
|
+
catch (e) {
|
|
252
|
+
return false;
|
|
317
253
|
}
|
|
318
|
-
|
|
319
|
-
|
|
254
|
+
return true;
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const pxValues = new Set([
|
|
258
|
+
// Border props
|
|
259
|
+
"borderWidth",
|
|
260
|
+
"borderTopWidth",
|
|
261
|
+
"borderRightWidth",
|
|
262
|
+
"borderBottomWidth",
|
|
263
|
+
"borderLeftWidth",
|
|
264
|
+
"borderRadius",
|
|
265
|
+
"radius",
|
|
266
|
+
"borderTopLeftRadius",
|
|
267
|
+
"borderTopRightRadius",
|
|
268
|
+
"borderBottomRightRadius",
|
|
269
|
+
"borderBottomLeftRadius",
|
|
270
|
+
// Positioning props
|
|
271
|
+
"width",
|
|
272
|
+
"maxWidth",
|
|
273
|
+
"height",
|
|
274
|
+
"maxHeight",
|
|
275
|
+
"top",
|
|
276
|
+
"right",
|
|
277
|
+
"bottom",
|
|
278
|
+
"left",
|
|
279
|
+
// Spacing props
|
|
280
|
+
"padding",
|
|
281
|
+
"paddingTop",
|
|
282
|
+
"paddingRight",
|
|
283
|
+
"paddingBottom",
|
|
284
|
+
"paddingLeft",
|
|
285
|
+
"margin",
|
|
286
|
+
"marginTop",
|
|
287
|
+
"marginRight",
|
|
288
|
+
"marginBottom",
|
|
289
|
+
"marginLeft",
|
|
290
|
+
// Misc
|
|
291
|
+
"backgroundPositionX",
|
|
292
|
+
"backgroundPositionY",
|
|
293
|
+
]);
|
|
294
|
+
|
|
295
|
+
function hydrateKeyframes(element, name, keyframes, pseudoElement) {
|
|
296
|
+
if (!Array.isArray(keyframes)) {
|
|
297
|
+
keyframes = [keyframes];
|
|
320
298
|
}
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
299
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
300
|
+
if (keyframes[i] === null) {
|
|
301
|
+
keyframes[i] =
|
|
302
|
+
i === 0 && !pseudoElement
|
|
303
|
+
? style.get(element, name)
|
|
304
|
+
: keyframes[i - 1];
|
|
326
305
|
}
|
|
327
|
-
if (
|
|
328
|
-
|
|
306
|
+
if (typeof keyframes[i] === "number" && pxValues.has(name)) {
|
|
307
|
+
keyframes[i] = keyframes[i] + "px";
|
|
329
308
|
}
|
|
330
|
-
this.cancel();
|
|
331
|
-
}
|
|
332
|
-
flatten() {
|
|
333
|
-
var _a, _b;
|
|
334
|
-
if (!this.animation || !((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowFlatten))
|
|
335
|
-
return;
|
|
336
|
-
(_b = this.animation.effect) === null || _b === void 0 ? void 0 : _b.updateTiming({ easing: "linear" });
|
|
337
|
-
}
|
|
338
|
-
attachTimeline(timeline) {
|
|
339
|
-
if (this.animation)
|
|
340
|
-
attachTimeline(this.animation, timeline);
|
|
341
|
-
return noop;
|
|
342
309
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
cancel() {
|
|
347
|
-
try {
|
|
348
|
-
this.animation && this.animation.cancel();
|
|
349
|
-
}
|
|
350
|
-
catch (e) { }
|
|
310
|
+
if (!pseudoElement && !supportsPartialKeyframes() && keyframes.length < 2) {
|
|
311
|
+
keyframes.unshift(style.get(element, name));
|
|
351
312
|
}
|
|
313
|
+
return keyframes;
|
|
352
314
|
}
|
|
353
315
|
|
|
316
|
+
const statsBuffer = {
|
|
317
|
+
value: null,
|
|
318
|
+
addProjectionMetrics: null,
|
|
319
|
+
};
|
|
320
|
+
|
|
354
321
|
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
|
355
322
|
|
|
356
323
|
/**
|
|
357
324
|
* Add the ability for test suites to manually set support flags
|
|
358
325
|
* to better test more environments.
|
|
359
326
|
*/
|
|
360
|
-
const supportsFlags = {
|
|
361
|
-
linearEasing: undefined,
|
|
362
|
-
};
|
|
327
|
+
const supportsFlags = {};
|
|
363
328
|
|
|
364
329
|
function memoSupports(callback, supportsFlag) {
|
|
365
330
|
const memoized = memo(callback);
|
|
366
|
-
return () =>
|
|
331
|
+
return () => supportsFlags[supportsFlag] ?? memoized();
|
|
367
332
|
}
|
|
368
333
|
|
|
369
334
|
const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
|
|
@@ -384,20 +349,13 @@
|
|
|
384
349
|
let points = "";
|
|
385
350
|
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
386
351
|
for (let i = 0; i < numPoints; i++) {
|
|
387
|
-
points += easing(
|
|
352
|
+
points += easing(i / (numPoints - 1)) + ", ";
|
|
388
353
|
}
|
|
389
354
|
return `linear(${points.substring(0, points.length - 2)})`;
|
|
390
355
|
};
|
|
391
356
|
|
|
392
|
-
function isWaapiSupportedEasing(easing) {
|
|
393
|
-
return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
|
|
394
|
-
!easing ||
|
|
395
|
-
(typeof easing === "string" &&
|
|
396
|
-
(easing in supportedWaapiEasing || supportsLinearEasing())) ||
|
|
397
|
-
isBezierDefinition(easing) ||
|
|
398
|
-
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
399
|
-
}
|
|
400
357
|
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
358
|
+
|
|
401
359
|
const supportedWaapiEasing = {
|
|
402
360
|
linear: "linear",
|
|
403
361
|
ease: "ease",
|
|
@@ -409,6 +367,7 @@
|
|
|
409
367
|
backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
|
|
410
368
|
backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
|
|
411
369
|
};
|
|
370
|
+
|
|
412
371
|
function mapEasingToNativeEasing(easing, duration) {
|
|
413
372
|
if (!easing) {
|
|
414
373
|
return undefined;
|
|
@@ -428,6 +387,247 @@
|
|
|
428
387
|
}
|
|
429
388
|
}
|
|
430
389
|
|
|
390
|
+
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
|
|
391
|
+
const keyframeOptions = {
|
|
392
|
+
[valueName]: keyframes,
|
|
393
|
+
};
|
|
394
|
+
if (times)
|
|
395
|
+
keyframeOptions.offset = times;
|
|
396
|
+
const easing = mapEasingToNativeEasing(ease, duration);
|
|
397
|
+
/**
|
|
398
|
+
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
399
|
+
*/
|
|
400
|
+
if (Array.isArray(easing))
|
|
401
|
+
keyframeOptions.easing = easing;
|
|
402
|
+
const animation = element.animate(keyframeOptions, {
|
|
403
|
+
delay,
|
|
404
|
+
duration,
|
|
405
|
+
easing: !Array.isArray(easing) ? easing : "linear",
|
|
406
|
+
fill: "both",
|
|
407
|
+
iterations: repeat + 1,
|
|
408
|
+
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
409
|
+
pseudoElement,
|
|
410
|
+
});
|
|
411
|
+
return animation;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function isGenerator(type) {
|
|
415
|
+
return typeof type === "function" && "applyToOptions" in type;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function applyGeneratorOptions({ type, ...options }) {
|
|
419
|
+
if (isGenerator(type)) {
|
|
420
|
+
return type.applyToOptions(options);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
options.duration ?? (options.duration = 300);
|
|
424
|
+
options.ease ?? (options.ease = "easeOut");
|
|
425
|
+
}
|
|
426
|
+
return options;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const animationMaps = new WeakMap();
|
|
430
|
+
const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
|
|
431
|
+
function getAnimationMap(element) {
|
|
432
|
+
const map = animationMaps.get(element) || new Map();
|
|
433
|
+
animationMaps.set(element, map);
|
|
434
|
+
return map;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
|
|
438
|
+
*/
|
|
439
|
+
class NativeAnimation {
|
|
440
|
+
constructor(options) {
|
|
441
|
+
/**
|
|
442
|
+
* If we already have an animation, we don't need to instantiate one
|
|
443
|
+
* and can just use this as a controls interface.
|
|
444
|
+
*/
|
|
445
|
+
if ("animation" in options) {
|
|
446
|
+
this.animation = options.animation;
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
|
|
450
|
+
let { transition } = options;
|
|
451
|
+
this.allowFlatten = allowFlatten;
|
|
452
|
+
/**
|
|
453
|
+
* Stop any existing animations on the element before reading existing keyframes.
|
|
454
|
+
*
|
|
455
|
+
* TODO: Check for VisualElement before using animation state. This is a fallback
|
|
456
|
+
* for mini animate(). Do this when implementing NativeAnimationExtended.
|
|
457
|
+
*/
|
|
458
|
+
const animationMap = getAnimationMap(element);
|
|
459
|
+
const key = animationMapKey(name, pseudoElement || "");
|
|
460
|
+
const currentAnimation = animationMap.get(key);
|
|
461
|
+
currentAnimation && currentAnimation.stop();
|
|
462
|
+
/**
|
|
463
|
+
* TODO: If these keyframes aren't correctly hydrated then we want to throw
|
|
464
|
+
* run an instant animation.
|
|
465
|
+
*/
|
|
466
|
+
const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
|
|
467
|
+
exports.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
|
|
468
|
+
transition = applyGeneratorOptions(transition);
|
|
469
|
+
this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
|
|
470
|
+
if (transition.autoplay === false) {
|
|
471
|
+
this.animation.pause();
|
|
472
|
+
}
|
|
473
|
+
this.removeAnimation = () => animationMap.delete(key);
|
|
474
|
+
this.animation.onfinish = () => {
|
|
475
|
+
if (!pseudoElement) {
|
|
476
|
+
style.set(element, name, getFinalKeyframe$1(keyframes, transition));
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
this.commitStyles();
|
|
480
|
+
}
|
|
481
|
+
this.cancel();
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* TODO: Check for VisualElement before using animation state.
|
|
485
|
+
*/
|
|
486
|
+
animationMap.set(key, this);
|
|
487
|
+
}
|
|
488
|
+
play() {
|
|
489
|
+
this.animation.play();
|
|
490
|
+
}
|
|
491
|
+
pause() {
|
|
492
|
+
this.animation.pause();
|
|
493
|
+
}
|
|
494
|
+
complete() {
|
|
495
|
+
this.animation.finish();
|
|
496
|
+
}
|
|
497
|
+
cancel() {
|
|
498
|
+
try {
|
|
499
|
+
this.animation.cancel();
|
|
500
|
+
}
|
|
501
|
+
catch (e) { }
|
|
502
|
+
this.removeAnimation();
|
|
503
|
+
}
|
|
504
|
+
stop() {
|
|
505
|
+
const { state } = this;
|
|
506
|
+
if (state === "idle" || state === "finished") {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.commitStyles();
|
|
510
|
+
this.cancel();
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* WAAPI doesn't natively have any interruption capabilities.
|
|
514
|
+
*
|
|
515
|
+
* In this method, we commit styles back to the DOM before cancelling
|
|
516
|
+
* the animation.
|
|
517
|
+
*
|
|
518
|
+
* This is designed to be overridden by NativeAnimationExtended, which
|
|
519
|
+
* will create a renderless JS animation and sample it twice to calculate
|
|
520
|
+
* its current value, "previous" value, and therefore allow
|
|
521
|
+
* Motion to also correctly calculate velocity for any subsequent animation
|
|
522
|
+
* while deferring the commit until the next animation frame.
|
|
523
|
+
*/
|
|
524
|
+
commitStyles() {
|
|
525
|
+
this.animation.commitStyles?.();
|
|
526
|
+
}
|
|
527
|
+
get duration() {
|
|
528
|
+
console.log(this.animation.effect?.getComputedTiming());
|
|
529
|
+
const duration = this.animation.effect?.getComputedTiming().duration || 0;
|
|
530
|
+
return millisecondsToSeconds(Number(duration));
|
|
531
|
+
}
|
|
532
|
+
get time() {
|
|
533
|
+
return millisecondsToSeconds(Number(this.animation.currentTime) || 0);
|
|
534
|
+
}
|
|
535
|
+
set time(newTime) {
|
|
536
|
+
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* The playback speed of the animation.
|
|
540
|
+
* 1 = normal speed, 2 = double speed, 0.5 = half speed.
|
|
541
|
+
*/
|
|
542
|
+
get speed() {
|
|
543
|
+
return this.animation.playbackRate;
|
|
544
|
+
}
|
|
545
|
+
set speed(newSpeed) {
|
|
546
|
+
this.animation.playbackRate = newSpeed;
|
|
547
|
+
}
|
|
548
|
+
get state() {
|
|
549
|
+
return this.animation.playState;
|
|
550
|
+
}
|
|
551
|
+
get startTime() {
|
|
552
|
+
return Number(this.animation.startTime);
|
|
553
|
+
}
|
|
554
|
+
get finished() {
|
|
555
|
+
return this.animation.finished;
|
|
556
|
+
}
|
|
557
|
+
flatten() {
|
|
558
|
+
if (this.allowFlatten) {
|
|
559
|
+
this.animation.effect?.updateTiming({ easing: "linear" });
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Attaches a timeline to the animation, for instance the `ScrollTimeline`.
|
|
564
|
+
*/
|
|
565
|
+
attachTimeline(timeline) {
|
|
566
|
+
this.animation.timeline = timeline;
|
|
567
|
+
this.animation.onfinish = null;
|
|
568
|
+
return noop;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Allows the animation to be awaited.
|
|
572
|
+
*
|
|
573
|
+
* @deprecated Use `finished` instead.
|
|
574
|
+
*/
|
|
575
|
+
then(onResolve, onReject) {
|
|
576
|
+
return this.finished.then(onResolve).catch(onReject);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function getValueTransition$1(transition, key) {
|
|
581
|
+
return (transition?.[key] ??
|
|
582
|
+
transition?.["default"] ??
|
|
583
|
+
transition);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Implement a practical max duration for keyframe generation
|
|
588
|
+
* to prevent infinite loops
|
|
589
|
+
*/
|
|
590
|
+
const maxGeneratorDuration = 20000;
|
|
591
|
+
function calcGeneratorDuration(generator) {
|
|
592
|
+
let duration = 0;
|
|
593
|
+
const timeStep = 50;
|
|
594
|
+
let state = generator.next(duration);
|
|
595
|
+
while (!state.done && duration < maxGeneratorDuration) {
|
|
596
|
+
duration += timeStep;
|
|
597
|
+
state = generator.next(duration);
|
|
598
|
+
}
|
|
599
|
+
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Create a progress => progress easing function from a generator.
|
|
604
|
+
*/
|
|
605
|
+
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
606
|
+
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
607
|
+
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
608
|
+
return {
|
|
609
|
+
type: "keyframes",
|
|
610
|
+
ease: (progress) => {
|
|
611
|
+
return generator.next(duration * progress).value / scale;
|
|
612
|
+
},
|
|
613
|
+
duration: millisecondsToSeconds(duration),
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function isWaapiSupportedEasing(easing) {
|
|
618
|
+
return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
|
|
619
|
+
!easing ||
|
|
620
|
+
(typeof easing === "string" &&
|
|
621
|
+
(easing in supportedWaapiEasing || supportsLinearEasing())) ||
|
|
622
|
+
isBezierDefinition(easing) ||
|
|
623
|
+
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function attachTimeline(animation, timeline) {
|
|
627
|
+
animation.timeline = timeline;
|
|
628
|
+
animation.onfinish = null;
|
|
629
|
+
}
|
|
630
|
+
|
|
431
631
|
const stepsOrder = [
|
|
432
632
|
"read", // Read
|
|
433
633
|
"resolveKeyframes", // Write/Read/Write/Read
|
|
@@ -437,11 +637,6 @@
|
|
|
437
637
|
"postRender", // Compute
|
|
438
638
|
];
|
|
439
639
|
|
|
440
|
-
const statsBuffer = {
|
|
441
|
-
value: null,
|
|
442
|
-
addProjectionMetrics: null,
|
|
443
|
-
};
|
|
444
|
-
|
|
445
640
|
function createRenderStep(runNextFrame, stepName) {
|
|
446
641
|
/**
|
|
447
642
|
* We create and reuse two queues, one to queue jobs for the current frame
|
|
@@ -631,21 +826,16 @@
|
|
|
631
826
|
}
|
|
632
827
|
|
|
633
828
|
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
634
|
-
var _a;
|
|
635
829
|
if (elementOrSelector instanceof EventTarget) {
|
|
636
830
|
return [elementOrSelector];
|
|
637
831
|
}
|
|
638
832
|
else if (typeof elementOrSelector === "string") {
|
|
639
833
|
let root = document;
|
|
640
834
|
if (scope) {
|
|
641
|
-
// TODO: Refactor to utils package
|
|
642
|
-
// invariant(
|
|
643
|
-
// Boolean(scope.current),
|
|
644
|
-
// "Scope provided, but no element detected."
|
|
645
|
-
// )
|
|
646
835
|
root = scope.current;
|
|
647
836
|
}
|
|
648
|
-
const elements =
|
|
837
|
+
const elements = selectorCache?.[elementOrSelector] ??
|
|
838
|
+
root.querySelectorAll(elementOrSelector);
|
|
649
839
|
return elements ? Array.from(elements) : [];
|
|
650
840
|
}
|
|
651
841
|
return Array.from(elementOrSelector);
|
|
@@ -844,7 +1034,7 @@
|
|
|
844
1034
|
if (target instanceof HTMLElement) {
|
|
845
1035
|
target.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions));
|
|
846
1036
|
if (!isElementKeyboardAccessible(target) &&
|
|
847
|
-
target.
|
|
1037
|
+
!target.hasAttribute("tabindex")) {
|
|
848
1038
|
target.tabIndex = 0;
|
|
849
1039
|
}
|
|
850
1040
|
}
|
|
@@ -877,7 +1067,7 @@
|
|
|
877
1067
|
* This will be replaced by the build step with the latest version number.
|
|
878
1068
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
879
1069
|
*/
|
|
880
|
-
this.version = "12.6.3
|
|
1070
|
+
this.version = "12.6.3";
|
|
881
1071
|
/**
|
|
882
1072
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
883
1073
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1426,9 +1616,17 @@
|
|
|
1426
1616
|
const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
|
|
1427
1617
|
return calculatedDuration + "ms " + easing;
|
|
1428
1618
|
},
|
|
1619
|
+
toTransition: () => { },
|
|
1429
1620
|
};
|
|
1430
1621
|
return generator;
|
|
1431
1622
|
}
|
|
1623
|
+
spring.applyToOptions = (options) => {
|
|
1624
|
+
const generatorOptions = createGeneratorEasing(options, 100, spring);
|
|
1625
|
+
options.ease = supportsLinearEasing() ? generatorOptions.ease : "easeOut";
|
|
1626
|
+
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
1627
|
+
options.type = "keyframes";
|
|
1628
|
+
return options;
|
|
1629
|
+
};
|
|
1432
1630
|
|
|
1433
1631
|
const wrap = (min, max, v) => {
|
|
1434
1632
|
const rangeSize = max - min;
|
|
@@ -1512,7 +1710,6 @@
|
|
|
1512
1710
|
* calculate an absolute time for the next keyframes.
|
|
1513
1711
|
*/
|
|
1514
1712
|
function calcNextTime(current, next, prev, labels) {
|
|
1515
|
-
var _a;
|
|
1516
1713
|
if (typeof next === "number") {
|
|
1517
1714
|
return next;
|
|
1518
1715
|
}
|
|
@@ -1523,7 +1720,7 @@
|
|
|
1523
1720
|
return prev;
|
|
1524
1721
|
}
|
|
1525
1722
|
else {
|
|
1526
|
-
return
|
|
1723
|
+
return labels.get(next) ?? current;
|
|
1527
1724
|
}
|
|
1528
1725
|
}
|
|
1529
1726
|
|
|
@@ -1636,7 +1833,7 @@
|
|
|
1636
1833
|
const numKeyframes = valueKeyframesAsList.length;
|
|
1637
1834
|
const createGenerator = isGenerator(type)
|
|
1638
1835
|
? type
|
|
1639
|
-
: generators
|
|
1836
|
+
: generators?.[type];
|
|
1640
1837
|
if (numKeyframes <= 2 && createGenerator) {
|
|
1641
1838
|
/**
|
|
1642
1839
|
* As we're creating an easing function from a spring,
|
|
@@ -1658,7 +1855,7 @@
|
|
|
1658
1855
|
ease = springEasing.ease;
|
|
1659
1856
|
duration = springEasing.duration;
|
|
1660
1857
|
}
|
|
1661
|
-
duration
|
|
1858
|
+
duration ?? (duration = defaultDuration);
|
|
1662
1859
|
const startTime = currentTime + calculatedDelay;
|
|
1663
1860
|
/**
|
|
1664
1861
|
* If there's only one time offset of 0, fill in a second with length 1
|
|
@@ -1867,7 +2064,7 @@
|
|
|
1867
2064
|
|
|
1868
2065
|
function getValueState(visualElement) {
|
|
1869
2066
|
const state = [{}, {}];
|
|
1870
|
-
visualElement
|
|
2067
|
+
visualElement?.values.forEach((value, key) => {
|
|
1871
2068
|
state[0][key] = value.get();
|
|
1872
2069
|
state[1][key] = value.getVelocity();
|
|
1873
2070
|
});
|
|
@@ -1940,11 +2137,6 @@
|
|
|
1940
2137
|
if (isWillChangeMotionValue(willChange)) {
|
|
1941
2138
|
return willChange.add(key);
|
|
1942
2139
|
}
|
|
1943
|
-
else if (!willChange && MotionGlobalConfig.WillChange) {
|
|
1944
|
-
const newWillChange = new MotionGlobalConfig.WillChange("auto");
|
|
1945
|
-
visualElement.addValue("willChange", newWillChange);
|
|
1946
|
-
newWillChange.add(key);
|
|
1947
|
-
}
|
|
1948
2140
|
}
|
|
1949
2141
|
|
|
1950
2142
|
/**
|
|
@@ -2204,11 +2396,10 @@
|
|
|
2204
2396
|
const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
|
|
2205
2397
|
|
|
2206
2398
|
function test(v) {
|
|
2207
|
-
var _a, _b;
|
|
2208
2399
|
return (isNaN(v) &&
|
|
2209
2400
|
typeof v === "string" &&
|
|
2210
|
-
(
|
|
2211
|
-
(
|
|
2401
|
+
(v.match(floatRegex)?.length || 0) +
|
|
2402
|
+
(v.match(colorRegex)?.length || 0) >
|
|
2212
2403
|
0);
|
|
2213
2404
|
}
|
|
2214
2405
|
const NUMBER_TOKEN = "number";
|
|
@@ -2596,8 +2787,7 @@
|
|
|
2596
2787
|
const restore = transformsToRestore.get(element);
|
|
2597
2788
|
if (restore) {
|
|
2598
2789
|
restore.forEach(([key, value]) => {
|
|
2599
|
-
|
|
2600
|
-
(_a = element.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(value);
|
|
2790
|
+
element.getValue(key)?.set(value);
|
|
2601
2791
|
});
|
|
2602
2792
|
}
|
|
2603
2793
|
});
|
|
@@ -2684,7 +2874,7 @@
|
|
|
2684
2874
|
* If the first keyframe is null, we need to find its value by sampling the element
|
|
2685
2875
|
*/
|
|
2686
2876
|
if (i === 0) {
|
|
2687
|
-
const currentValue = motionValue
|
|
2877
|
+
const currentValue = motionValue?.get();
|
|
2688
2878
|
const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
|
|
2689
2879
|
if (currentValue !== undefined) {
|
|
2690
2880
|
unresolvedKeyframes[0] = currentValue;
|
|
@@ -2765,7 +2955,7 @@
|
|
|
2765
2955
|
if (!match)
|
|
2766
2956
|
return [,];
|
|
2767
2957
|
const [, token1, token2, fallback] = match;
|
|
2768
|
-
return [`--${token1
|
|
2958
|
+
return [`--${token1 ?? token2}`, fallback];
|
|
2769
2959
|
}
|
|
2770
2960
|
const maxDepth = 4;
|
|
2771
2961
|
function getVariableValue(current, element, depth = 1) {
|
|
@@ -2904,7 +3094,6 @@
|
|
|
2904
3094
|
}
|
|
2905
3095
|
}
|
|
2906
3096
|
measureEndState() {
|
|
2907
|
-
var _a;
|
|
2908
3097
|
const { element, name, unresolvedKeyframes } = this;
|
|
2909
3098
|
if (!element || !element.current)
|
|
2910
3099
|
return;
|
|
@@ -2917,7 +3106,7 @@
|
|
|
2917
3106
|
this.finalKeyframe = finalKeyframe;
|
|
2918
3107
|
}
|
|
2919
3108
|
// If we removed transform values, reapply them before the next render
|
|
2920
|
-
if (
|
|
3109
|
+
if (this.removedTransforms?.length) {
|
|
2921
3110
|
this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
|
|
2922
3111
|
element
|
|
2923
3112
|
.getValue(unsetTransformName)
|
|
@@ -3273,13 +3462,12 @@
|
|
|
3273
3462
|
};
|
|
3274
3463
|
}
|
|
3275
3464
|
function matchOrder(origin, target) {
|
|
3276
|
-
var _a;
|
|
3277
3465
|
const orderedOrigin = [];
|
|
3278
3466
|
const pointers = { color: 0, var: 0, number: 0 };
|
|
3279
3467
|
for (let i = 0; i < target.values.length; i++) {
|
|
3280
3468
|
const type = target.types[i];
|
|
3281
3469
|
const originIndex = origin.indexes[type][pointers[type]];
|
|
3282
|
-
const originValue =
|
|
3470
|
+
const originValue = origin.values[originIndex] ?? 0;
|
|
3283
3471
|
orderedOrigin[i] = originValue;
|
|
3284
3472
|
pointers[type]++;
|
|
3285
3473
|
}
|
|
@@ -3506,7 +3694,7 @@
|
|
|
3506
3694
|
return offset.map((o) => o * duration);
|
|
3507
3695
|
}
|
|
3508
3696
|
|
|
3509
|
-
function defaultEasing
|
|
3697
|
+
function defaultEasing(values, easing) {
|
|
3510
3698
|
return values.map(() => easing || easeInOut).splice(0, values.length - 1);
|
|
3511
3699
|
}
|
|
3512
3700
|
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
|
|
@@ -3537,7 +3725,7 @@
|
|
|
3537
3725
|
const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
|
|
3538
3726
|
ease: Array.isArray(easingFunctions)
|
|
3539
3727
|
? easingFunctions
|
|
3540
|
-
: defaultEasing
|
|
3728
|
+
: defaultEasing(keyframeValues, easingFunctions),
|
|
3541
3729
|
});
|
|
3542
3730
|
return {
|
|
3543
3731
|
calculatedDuration: duration,
|
|
@@ -3619,7 +3807,7 @@
|
|
|
3619
3807
|
onStop && onStop();
|
|
3620
3808
|
};
|
|
3621
3809
|
const { name, motionValue, element, keyframes } = this.options;
|
|
3622
|
-
const KeyframeResolver$1 =
|
|
3810
|
+
const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
|
|
3623
3811
|
const onResolved = (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe);
|
|
3624
3812
|
this.resolver = new KeyframeResolver$1(keyframes, onResolved, name, motionValue, element);
|
|
3625
3813
|
this.resolver.scheduleResolve();
|
|
@@ -3867,7 +4055,7 @@
|
|
|
3867
4055
|
this.startTime = now - this.holdTime;
|
|
3868
4056
|
}
|
|
3869
4057
|
else if (!this.startTime) {
|
|
3870
|
-
this.startTime = startTime
|
|
4058
|
+
this.startTime = startTime ?? this.calcStartTime();
|
|
3871
4059
|
}
|
|
3872
4060
|
else if (this.state === "finished") {
|
|
3873
4061
|
this.startTime = now;
|
|
@@ -3885,13 +4073,12 @@
|
|
|
3885
4073
|
this.driver.start();
|
|
3886
4074
|
}
|
|
3887
4075
|
pause() {
|
|
3888
|
-
var _a;
|
|
3889
4076
|
if (!this._resolved) {
|
|
3890
4077
|
this.pendingPlayState = "paused";
|
|
3891
4078
|
return;
|
|
3892
4079
|
}
|
|
3893
4080
|
this.state = "paused";
|
|
3894
|
-
this.holdTime =
|
|
4081
|
+
this.holdTime = this.currentTime ?? 0;
|
|
3895
4082
|
}
|
|
3896
4083
|
complete() {
|
|
3897
4084
|
if (this.state !== "running") {
|
|
@@ -3931,6 +4118,9 @@
|
|
|
3931
4118
|
this.startTime = 0;
|
|
3932
4119
|
return this.tick(time, true);
|
|
3933
4120
|
}
|
|
4121
|
+
get finished() {
|
|
4122
|
+
return this.currentFinishedPromise;
|
|
4123
|
+
}
|
|
3934
4124
|
}
|
|
3935
4125
|
|
|
3936
4126
|
/**
|
|
@@ -3946,27 +4136,6 @@
|
|
|
3946
4136
|
// "background-color"
|
|
3947
4137
|
]);
|
|
3948
4138
|
|
|
3949
|
-
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
|
|
3950
|
-
const keyframeOptions = { [valueName]: keyframes };
|
|
3951
|
-
if (times)
|
|
3952
|
-
keyframeOptions.offset = times;
|
|
3953
|
-
const easing = mapEasingToNativeEasing(ease, duration);
|
|
3954
|
-
/**
|
|
3955
|
-
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
3956
|
-
*/
|
|
3957
|
-
if (Array.isArray(easing))
|
|
3958
|
-
keyframeOptions.easing = easing;
|
|
3959
|
-
const animation = element.animate(keyframeOptions, {
|
|
3960
|
-
delay,
|
|
3961
|
-
duration,
|
|
3962
|
-
easing: !Array.isArray(easing) ? easing : "linear",
|
|
3963
|
-
fill: "both",
|
|
3964
|
-
iterations: repeat + 1,
|
|
3965
|
-
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
3966
|
-
});
|
|
3967
|
-
return animation;
|
|
3968
|
-
}
|
|
3969
|
-
|
|
3970
4139
|
const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
3971
4140
|
|
|
3972
4141
|
/**
|
|
@@ -4077,7 +4246,7 @@
|
|
|
4077
4246
|
const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
|
|
4078
4247
|
// Override the browser calculated startTime with one synchronised to other JS
|
|
4079
4248
|
// and WAAPI animations starting this event loop.
|
|
4080
|
-
animation.startTime = startTime
|
|
4249
|
+
animation.startTime = startTime ?? this.calcStartTime();
|
|
4081
4250
|
if (this.pendingTimeline) {
|
|
4082
4251
|
attachTimeline(animation, this.pendingTimeline);
|
|
4083
4252
|
this.pendingTimeline = undefined;
|
|
@@ -4136,6 +4305,9 @@
|
|
|
4136
4305
|
const { animation } = resolved;
|
|
4137
4306
|
return animation.playbackRate;
|
|
4138
4307
|
}
|
|
4308
|
+
get finished() {
|
|
4309
|
+
return this.resolved.animation.finished;
|
|
4310
|
+
}
|
|
4139
4311
|
set speed(newSpeed) {
|
|
4140
4312
|
const { resolved } = this;
|
|
4141
4313
|
if (!resolved)
|
|
@@ -4401,7 +4573,7 @@
|
|
|
4401
4573
|
});
|
|
4402
4574
|
// We still want to return some animation controls here rather
|
|
4403
4575
|
// than returning undefined
|
|
4404
|
-
return new
|
|
4576
|
+
return new GroupAnimationWithThen([]);
|
|
4405
4577
|
}
|
|
4406
4578
|
}
|
|
4407
4579
|
/**
|
|
@@ -4429,7 +4601,6 @@
|
|
|
4429
4601
|
return shouldBlock;
|
|
4430
4602
|
}
|
|
4431
4603
|
function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
|
|
4432
|
-
var _a;
|
|
4433
4604
|
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
|
|
4434
4605
|
if (transitionOverride)
|
|
4435
4606
|
transition = transitionOverride;
|
|
@@ -4438,7 +4609,7 @@
|
|
|
4438
4609
|
visualElement.animationState &&
|
|
4439
4610
|
visualElement.animationState.getState()[type];
|
|
4440
4611
|
for (const key in target) {
|
|
4441
|
-
const value = visualElement.getValue(key,
|
|
4612
|
+
const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
|
|
4442
4613
|
const valueTarget = target[key];
|
|
4443
4614
|
if (valueTarget === undefined ||
|
|
4444
4615
|
(animationTypeState &&
|
|
@@ -4597,7 +4768,7 @@
|
|
|
4597
4768
|
* and warn against mismatches.
|
|
4598
4769
|
*/
|
|
4599
4770
|
{
|
|
4600
|
-
warnOnce(nextValue.version === "12.6.3
|
|
4771
|
+
warnOnce(nextValue.version === "12.6.3", `Attempting to mix Motion versions ${nextValue.version} with 12.6.3 may not work as expected.`);
|
|
4601
4772
|
}
|
|
4602
4773
|
}
|
|
4603
4774
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5021,10 +5192,10 @@
|
|
|
5021
5192
|
* directly from the instance (which might have performance implications).
|
|
5022
5193
|
*/
|
|
5023
5194
|
readValue(key, target) {
|
|
5024
|
-
var _a;
|
|
5025
5195
|
let value = this.latestValues[key] !== undefined || !this.current
|
|
5026
5196
|
? this.latestValues[key]
|
|
5027
|
-
:
|
|
5197
|
+
: this.getBaseTargetFromProps(this.props, key) ??
|
|
5198
|
+
this.readValueFromInstance(this.current, key, this.options);
|
|
5028
5199
|
if (value !== undefined && value !== null) {
|
|
5029
5200
|
if (typeof value === "string" &&
|
|
5030
5201
|
(isNumericalString(value) || isZeroValueString(value))) {
|
|
@@ -5050,11 +5221,10 @@
|
|
|
5050
5221
|
* props.
|
|
5051
5222
|
*/
|
|
5052
5223
|
getBaseTarget(key) {
|
|
5053
|
-
var _a;
|
|
5054
5224
|
const { initial } = this.props;
|
|
5055
5225
|
let valueFromInitial;
|
|
5056
5226
|
if (typeof initial === "string" || typeof initial === "object") {
|
|
5057
|
-
const variant = resolveVariantFromProps(this.props, initial,
|
|
5227
|
+
const variant = resolveVariantFromProps(this.props, initial, this.presenceContext?.custom);
|
|
5058
5228
|
if (variant) {
|
|
5059
5229
|
valueFromInitial = variant[key];
|
|
5060
5230
|
}
|
|
@@ -5421,7 +5591,6 @@
|
|
|
5421
5591
|
}
|
|
5422
5592
|
|
|
5423
5593
|
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
5424
|
-
var _a;
|
|
5425
5594
|
const { style } = props;
|
|
5426
5595
|
const newValues = {};
|
|
5427
5596
|
for (const key in style) {
|
|
@@ -5429,7 +5598,7 @@
|
|
|
5429
5598
|
(prevProps.style &&
|
|
5430
5599
|
isMotionValue(prevProps.style[key])) ||
|
|
5431
5600
|
isForcedMotionValue(key, props) ||
|
|
5432
|
-
|
|
5601
|
+
visualElement?.getValue(key)?.liveStyle !== undefined) {
|
|
5433
5602
|
newValues[key] = style[key];
|
|
5434
5603
|
}
|
|
5435
5604
|
}
|
|
@@ -5708,7 +5877,7 @@
|
|
|
5708
5877
|
else {
|
|
5709
5878
|
animations = animateSubject(subjectOrSequence, optionsOrKeyframes, options, scope);
|
|
5710
5879
|
}
|
|
5711
|
-
const animation = new
|
|
5880
|
+
const animation = new GroupAnimationWithThen(animations);
|
|
5712
5881
|
if (scope) {
|
|
5713
5882
|
scope.animations.push(animation);
|
|
5714
5883
|
}
|
|
@@ -5718,125 +5887,6 @@
|
|
|
5718
5887
|
}
|
|
5719
5888
|
const animate = createScopedAnimate();
|
|
5720
5889
|
|
|
5721
|
-
function setCSSVar(element, name, value) {
|
|
5722
|
-
element.style.setProperty(name, value);
|
|
5723
|
-
}
|
|
5724
|
-
function setStyle(element, name, value) {
|
|
5725
|
-
element.style[name] = value;
|
|
5726
|
-
}
|
|
5727
|
-
|
|
5728
|
-
const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
|
|
5729
|
-
try {
|
|
5730
|
-
document.createElement("div").animate({ opacity: [1] });
|
|
5731
|
-
}
|
|
5732
|
-
catch (e) {
|
|
5733
|
-
return false;
|
|
5734
|
-
}
|
|
5735
|
-
return true;
|
|
5736
|
-
});
|
|
5737
|
-
|
|
5738
|
-
const state = new WeakMap();
|
|
5739
|
-
function hydrateKeyframes(valueName, keyframes, read) {
|
|
5740
|
-
for (let i = 0; i < keyframes.length; i++) {
|
|
5741
|
-
if (keyframes[i] === null) {
|
|
5742
|
-
keyframes[i] = i === 0 ? read() : keyframes[i - 1];
|
|
5743
|
-
}
|
|
5744
|
-
if (typeof keyframes[i] === "number" &&
|
|
5745
|
-
browserNumberValueTypes[valueName]) {
|
|
5746
|
-
keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
|
|
5747
|
-
}
|
|
5748
|
-
}
|
|
5749
|
-
if (!supportsPartialKeyframes() && keyframes.length < 2) {
|
|
5750
|
-
keyframes.unshift(read());
|
|
5751
|
-
}
|
|
5752
|
-
}
|
|
5753
|
-
const defaultEasing = "easeOut";
|
|
5754
|
-
function getElementAnimationState(element) {
|
|
5755
|
-
const animationState = state.get(element) || new Map();
|
|
5756
|
-
state.set(element, animationState);
|
|
5757
|
-
return state.get(element);
|
|
5758
|
-
}
|
|
5759
|
-
class NativeAnimation extends NativeAnimationControls {
|
|
5760
|
-
constructor(element, valueName, valueKeyframes, options) {
|
|
5761
|
-
const isCSSVar = valueName.startsWith("--");
|
|
5762
|
-
exports.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
|
|
5763
|
-
const existingAnimation = getElementAnimationState(element).get(valueName);
|
|
5764
|
-
existingAnimation && existingAnimation.stop();
|
|
5765
|
-
const readInitialKeyframe = () => {
|
|
5766
|
-
return valueName.startsWith("--")
|
|
5767
|
-
? element.style.getPropertyValue(valueName)
|
|
5768
|
-
: window.getComputedStyle(element)[valueName];
|
|
5769
|
-
};
|
|
5770
|
-
if (!Array.isArray(valueKeyframes)) {
|
|
5771
|
-
valueKeyframes = [valueKeyframes];
|
|
5772
|
-
}
|
|
5773
|
-
hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
|
|
5774
|
-
// TODO: Replace this with toString()?
|
|
5775
|
-
if (isGenerator(options.type)) {
|
|
5776
|
-
const generatorOptions = createGeneratorEasing(options, 100, options.type);
|
|
5777
|
-
options.ease = supportsLinearEasing()
|
|
5778
|
-
? generatorOptions.ease
|
|
5779
|
-
: defaultEasing;
|
|
5780
|
-
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
5781
|
-
options.type = "keyframes";
|
|
5782
|
-
}
|
|
5783
|
-
else {
|
|
5784
|
-
options.ease = options.ease || defaultEasing;
|
|
5785
|
-
}
|
|
5786
|
-
const onFinish = () => {
|
|
5787
|
-
this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
|
|
5788
|
-
this.cancel();
|
|
5789
|
-
this.resolveFinishedPromise();
|
|
5790
|
-
};
|
|
5791
|
-
const init = () => {
|
|
5792
|
-
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
5793
|
-
this.options = options;
|
|
5794
|
-
this.updateFinishedPromise();
|
|
5795
|
-
this.removeAnimation = () => {
|
|
5796
|
-
const elementState = state.get(element);
|
|
5797
|
-
elementState && elementState.delete(valueName);
|
|
5798
|
-
};
|
|
5799
|
-
};
|
|
5800
|
-
if (!supportsWaapi()) {
|
|
5801
|
-
super();
|
|
5802
|
-
init();
|
|
5803
|
-
onFinish();
|
|
5804
|
-
}
|
|
5805
|
-
else {
|
|
5806
|
-
super(startWaapiAnimation(element, valueName, valueKeyframes, options));
|
|
5807
|
-
init();
|
|
5808
|
-
if (options.autoplay === false) {
|
|
5809
|
-
this.animation.pause();
|
|
5810
|
-
}
|
|
5811
|
-
this.animation.onfinish = onFinish;
|
|
5812
|
-
getElementAnimationState(element).set(valueName, this);
|
|
5813
|
-
}
|
|
5814
|
-
}
|
|
5815
|
-
/**
|
|
5816
|
-
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
5817
|
-
* resolves when the animation finishes at all but in a future update could/should
|
|
5818
|
-
* reject if its cancels.
|
|
5819
|
-
*/
|
|
5820
|
-
then(resolve, reject) {
|
|
5821
|
-
return this.currentFinishedPromise.then(resolve, reject);
|
|
5822
|
-
}
|
|
5823
|
-
updateFinishedPromise() {
|
|
5824
|
-
this.currentFinishedPromise = new Promise((resolve) => {
|
|
5825
|
-
this.resolveFinishedPromise = resolve;
|
|
5826
|
-
});
|
|
5827
|
-
}
|
|
5828
|
-
play() {
|
|
5829
|
-
if (this.state === "finished") {
|
|
5830
|
-
this.updateFinishedPromise();
|
|
5831
|
-
}
|
|
5832
|
-
super.play();
|
|
5833
|
-
}
|
|
5834
|
-
cancel() {
|
|
5835
|
-
this.removeAnimation();
|
|
5836
|
-
super.cancel();
|
|
5837
|
-
}
|
|
5838
|
-
}
|
|
5839
|
-
|
|
5840
5890
|
function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
5841
5891
|
const elements = resolveElements(elementOrSelector, scope);
|
|
5842
5892
|
const numElements = elements.length;
|
|
@@ -5856,13 +5906,15 @@
|
|
|
5856
5906
|
const valueOptions = {
|
|
5857
5907
|
...getValueTransition$1(elementTransition, valueName),
|
|
5858
5908
|
};
|
|
5859
|
-
valueOptions.duration = valueOptions.duration
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5909
|
+
valueOptions.duration && (valueOptions.duration = secondsToMilliseconds(valueOptions.duration));
|
|
5910
|
+
valueOptions.delay && (valueOptions.delay = secondsToMilliseconds(valueOptions.delay));
|
|
5911
|
+
animations.push(new NativeAnimation({
|
|
5912
|
+
element,
|
|
5913
|
+
name: valueName,
|
|
5914
|
+
keyframes: valueKeyframes,
|
|
5915
|
+
transition: valueOptions,
|
|
5916
|
+
allowFlatten: !elementTransition.type && !elementTransition.ease,
|
|
5917
|
+
}));
|
|
5866
5918
|
}
|
|
5867
5919
|
}
|
|
5868
5920
|
return animations;
|
|
@@ -5870,7 +5922,7 @@
|
|
|
5870
5922
|
|
|
5871
5923
|
const createScopedWaapiAnimate = (scope) => {
|
|
5872
5924
|
function scopedAnimate(elementOrSelector, keyframes, options) {
|
|
5873
|
-
return new
|
|
5925
|
+
return new GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
|
|
5874
5926
|
}
|
|
5875
5927
|
return scopedAnimate;
|
|
5876
5928
|
};
|
|
@@ -5909,8 +5961,7 @@
|
|
|
5909
5961
|
}
|
|
5910
5962
|
}
|
|
5911
5963
|
function notifyTarget({ target, contentRect, borderBoxSize, }) {
|
|
5912
|
-
|
|
5913
|
-
(_a = resizeHandlers.get(target)) === null || _a === void 0 ? void 0 : _a.forEach((handler) => {
|
|
5964
|
+
resizeHandlers.get(target)?.forEach((handler) => {
|
|
5914
5965
|
handler({
|
|
5915
5966
|
target,
|
|
5916
5967
|
contentSize: contentRect,
|
|
@@ -5939,14 +5990,14 @@
|
|
|
5939
5990
|
resizeHandlers.set(element, elementHandlers);
|
|
5940
5991
|
}
|
|
5941
5992
|
elementHandlers.add(handler);
|
|
5942
|
-
observer
|
|
5993
|
+
observer?.observe(element);
|
|
5943
5994
|
});
|
|
5944
5995
|
return () => {
|
|
5945
5996
|
elements.forEach((element) => {
|
|
5946
5997
|
const elementHandlers = resizeHandlers.get(element);
|
|
5947
|
-
elementHandlers
|
|
5948
|
-
if (!
|
|
5949
|
-
observer
|
|
5998
|
+
elementHandlers?.delete(handler);
|
|
5999
|
+
if (!elementHandlers?.size) {
|
|
6000
|
+
observer?.unobserve(element);
|
|
5950
6001
|
}
|
|
5951
6002
|
});
|
|
5952
6003
|
};
|
|
@@ -6325,7 +6376,6 @@
|
|
|
6325
6376
|
const listener = scrollListeners.get(container);
|
|
6326
6377
|
frame.read(listener, false, true);
|
|
6327
6378
|
return () => {
|
|
6328
|
-
var _a;
|
|
6329
6379
|
cancelFrame(listener);
|
|
6330
6380
|
/**
|
|
6331
6381
|
* Check if we even have any handlers for this container.
|
|
@@ -6343,7 +6393,7 @@
|
|
|
6343
6393
|
scrollListeners.delete(container);
|
|
6344
6394
|
if (scrollListener) {
|
|
6345
6395
|
getEventTarget(container).removeEventListener("scroll", scrollListener);
|
|
6346
|
-
|
|
6396
|
+
resizeListeners.get(container)?.();
|
|
6347
6397
|
window.removeEventListener("resize", scrollListener);
|
|
6348
6398
|
}
|
|
6349
6399
|
};
|