motion 11.11.13 → 11.11.15
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/.turbo/turbo-build.log +21 -12
- package/README.md +19 -14
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/mini.js +555 -0
- package/dist/cjs/react-client.js +2 -2
- package/dist/cjs/react-mini.js +587 -0
- package/dist/cjs/react.js +14 -0
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/index.mjs +1 -1
- package/dist/es/motion/lib/mini.mjs +1 -0
- package/dist/es/motion/lib/react-mini.mjs +2 -0
- package/dist/motion.dev.js +2 -2
- package/dist/motion.js +1 -1
- package/lib/mini.js +2 -0
- package/lib/mini.js.map +1 -0
- package/lib/react-mini.js +3 -0
- package/lib/react-mini.js.map +1 -0
- package/mini/package.json +6 -0
- package/package.json +15 -3
- package/react/package.json +1 -1
- package/react-client/package.json +1 -1
- package/react-m/package.json +1 -1
- package/rollup.config.mjs +7 -1
- package/src/mini.ts +1 -0
- package/src/react-mini.ts +3 -0
- package/types/mini.d.ts +1 -0
- package/types/react-mini.d.ts +1 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a constant value over the lifecycle of a component.
|
|
9
|
+
*
|
|
10
|
+
* Even if `useMemo` is provided an empty array as its final argument, it doesn't offer
|
|
11
|
+
* a guarantee that it won't re-run for performance reasons later on. By using `useConstant`
|
|
12
|
+
* you can ensure that initialisers don't execute twice or more.
|
|
13
|
+
*/
|
|
14
|
+
function useConstant(init) {
|
|
15
|
+
const ref = react.useRef(null);
|
|
16
|
+
if (ref.current === null) {
|
|
17
|
+
ref.current = init();
|
|
18
|
+
}
|
|
19
|
+
return ref.current;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function useUnmountEffect(callback) {
|
|
23
|
+
return react.useEffect(() => () => callback(), []);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function memo(callback) {
|
|
27
|
+
let result;
|
|
28
|
+
return () => {
|
|
29
|
+
if (result === undefined)
|
|
30
|
+
result = callback();
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const supportsScrollTimeline = memo(() => window.ScrollTimeline !== undefined);
|
|
36
|
+
|
|
37
|
+
class GroupPlaybackControls {
|
|
38
|
+
constructor(animations) {
|
|
39
|
+
// Bound to accomodate common `return animation.stop` pattern
|
|
40
|
+
this.stop = () => this.runAll("stop");
|
|
41
|
+
this.animations = animations.filter(Boolean);
|
|
42
|
+
}
|
|
43
|
+
then(onResolve, onReject) {
|
|
44
|
+
return Promise.all(this.animations).then(onResolve).catch(onReject);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* TODO: Filter out cancelled or stopped animations before returning
|
|
48
|
+
*/
|
|
49
|
+
getAll(propName) {
|
|
50
|
+
return this.animations[0][propName];
|
|
51
|
+
}
|
|
52
|
+
setAll(propName, newValue) {
|
|
53
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
54
|
+
this.animations[i][propName] = newValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
attachTimeline(timeline, fallback) {
|
|
58
|
+
const subscriptions = this.animations.map((animation) => {
|
|
59
|
+
if (supportsScrollTimeline() && animation.attachTimeline) {
|
|
60
|
+
return animation.attachTimeline(timeline);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return fallback(animation);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
subscriptions.forEach((cancel, i) => {
|
|
68
|
+
cancel && cancel();
|
|
69
|
+
this.animations[i].stop();
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
get time() {
|
|
74
|
+
return this.getAll("time");
|
|
75
|
+
}
|
|
76
|
+
set time(time) {
|
|
77
|
+
this.setAll("time", time);
|
|
78
|
+
}
|
|
79
|
+
get speed() {
|
|
80
|
+
return this.getAll("speed");
|
|
81
|
+
}
|
|
82
|
+
set speed(speed) {
|
|
83
|
+
this.setAll("speed", speed);
|
|
84
|
+
}
|
|
85
|
+
get startTime() {
|
|
86
|
+
return this.getAll("startTime");
|
|
87
|
+
}
|
|
88
|
+
get duration() {
|
|
89
|
+
let max = 0;
|
|
90
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
91
|
+
max = Math.max(max, this.animations[i].duration);
|
|
92
|
+
}
|
|
93
|
+
return max;
|
|
94
|
+
}
|
|
95
|
+
runAll(methodName) {
|
|
96
|
+
this.animations.forEach((controls) => controls[methodName]());
|
|
97
|
+
}
|
|
98
|
+
play() {
|
|
99
|
+
this.runAll("play");
|
|
100
|
+
}
|
|
101
|
+
pause() {
|
|
102
|
+
this.runAll("pause");
|
|
103
|
+
}
|
|
104
|
+
cancel() {
|
|
105
|
+
this.runAll("cancel");
|
|
106
|
+
}
|
|
107
|
+
complete() {
|
|
108
|
+
this.runAll("complete");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const noop = (any) => any;
|
|
113
|
+
|
|
114
|
+
let invariant = noop;
|
|
115
|
+
if (process.env.NODE_ENV !== "production") {
|
|
116
|
+
invariant = (check, message) => {
|
|
117
|
+
if (!check) {
|
|
118
|
+
throw new Error(message);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function resolveElements(elements, scope, selectorCache) {
|
|
124
|
+
var _a;
|
|
125
|
+
if (typeof elements === "string") {
|
|
126
|
+
let root = document;
|
|
127
|
+
if (scope) {
|
|
128
|
+
invariant(Boolean(scope.current), "Scope provided, but no element detected.");
|
|
129
|
+
root = scope.current;
|
|
130
|
+
}
|
|
131
|
+
if (selectorCache) {
|
|
132
|
+
(_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = root.querySelectorAll(elements));
|
|
133
|
+
elements = selectorCache[elements];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
elements = root.querySelectorAll(elements);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (elements instanceof Element) {
|
|
140
|
+
elements = [elements];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Return an empty array
|
|
144
|
+
*/
|
|
145
|
+
return Array.from(elements || []);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Converts seconds to milliseconds
|
|
150
|
+
*
|
|
151
|
+
* @param seconds - Time in seconds.
|
|
152
|
+
* @return milliseconds - Converted time in milliseconds.
|
|
153
|
+
*/
|
|
154
|
+
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
|
155
|
+
const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
|
|
156
|
+
|
|
157
|
+
function getValueTransition(transition, key) {
|
|
158
|
+
return transition
|
|
159
|
+
? transition[key] ||
|
|
160
|
+
transition["default"] ||
|
|
161
|
+
transition
|
|
162
|
+
: undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
Progress within given range
|
|
169
|
+
|
|
170
|
+
Given a lower limit and an upper limit, we return the progress
|
|
171
|
+
(expressed as a number 0-1) represented by the given value, and
|
|
172
|
+
limit that progress to within 0-1.
|
|
173
|
+
|
|
174
|
+
@param [number]: Lower limit
|
|
175
|
+
@param [number]: Upper limit
|
|
176
|
+
@param [number]: Value to find progress within given range
|
|
177
|
+
@return [number]: Progress of value within range as expressed 0-1
|
|
178
|
+
*/
|
|
179
|
+
const progress = (from, to, value) => {
|
|
180
|
+
const toFromDifference = to - from;
|
|
181
|
+
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// Create a linear easing point for every 10 ms
|
|
185
|
+
const resolution = 10;
|
|
186
|
+
const generateLinearEasing = (easing, duration // as milliseconds
|
|
187
|
+
) => {
|
|
188
|
+
let points = "";
|
|
189
|
+
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
190
|
+
for (let i = 0; i < numPoints; i++) {
|
|
191
|
+
points += easing(progress(0, numPoints - 1, i)) + ", ";
|
|
192
|
+
}
|
|
193
|
+
return `linear(${points.substring(0, points.length - 2)})`;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Add the ability for test suites to manually set support flags
|
|
198
|
+
* to better test more environments.
|
|
199
|
+
*/
|
|
200
|
+
const supportsFlags = {
|
|
201
|
+
linearEasing: undefined,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function memoSupports(callback, supportsFlag) {
|
|
205
|
+
const memoized = memo(callback);
|
|
206
|
+
return () => { var _a; return (_a = supportsFlags[supportsFlag]) !== null && _a !== void 0 ? _a : memoized(); };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
|
|
210
|
+
try {
|
|
211
|
+
document
|
|
212
|
+
.createElement("div")
|
|
213
|
+
.animate({ opacity: 0 }, { easing: "linear(0, 1)" });
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}, "linearEasing");
|
|
220
|
+
|
|
221
|
+
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
222
|
+
const supportedWaapiEasing = {
|
|
223
|
+
linear: "linear",
|
|
224
|
+
ease: "ease",
|
|
225
|
+
easeIn: "ease-in",
|
|
226
|
+
easeOut: "ease-out",
|
|
227
|
+
easeInOut: "ease-in-out",
|
|
228
|
+
circIn: /*@__PURE__*/ cubicBezierAsString([0, 0.65, 0.55, 1]),
|
|
229
|
+
circOut: /*@__PURE__*/ cubicBezierAsString([0.55, 0, 1, 0.45]),
|
|
230
|
+
backIn: /*@__PURE__*/ cubicBezierAsString([0.31, 0.01, 0.66, -0.59]),
|
|
231
|
+
backOut: /*@__PURE__*/ cubicBezierAsString([0.33, 1.53, 0.69, 0.99]),
|
|
232
|
+
};
|
|
233
|
+
function mapEasingToNativeEasing(easing, duration) {
|
|
234
|
+
if (!easing) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
else if (typeof easing === "function" && supportsLinearEasing()) {
|
|
238
|
+
return generateLinearEasing(easing, duration);
|
|
239
|
+
}
|
|
240
|
+
else if (isBezierDefinition(easing)) {
|
|
241
|
+
return cubicBezierAsString(easing);
|
|
242
|
+
}
|
|
243
|
+
else if (Array.isArray(easing)) {
|
|
244
|
+
return easing.map((segmentEasing) => mapEasingToNativeEasing(segmentEasing, duration) ||
|
|
245
|
+
supportedWaapiEasing.easeOut);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
return supportedWaapiEasing[easing];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
|
|
253
|
+
const keyframeOptions = { [valueName]: keyframes };
|
|
254
|
+
if (times)
|
|
255
|
+
keyframeOptions.offset = times;
|
|
256
|
+
const easing = mapEasingToNativeEasing(ease, duration);
|
|
257
|
+
/**
|
|
258
|
+
* If this is an easing array, apply to keyframes, not animation as a whole
|
|
259
|
+
*/
|
|
260
|
+
if (Array.isArray(easing))
|
|
261
|
+
keyframeOptions.easing = easing;
|
|
262
|
+
return element.animate(keyframeOptions, {
|
|
263
|
+
delay,
|
|
264
|
+
duration,
|
|
265
|
+
easing: !Array.isArray(easing) ? easing : "linear",
|
|
266
|
+
fill: "both",
|
|
267
|
+
iterations: repeat + 1,
|
|
268
|
+
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Implement a practical max duration for keyframe generation
|
|
274
|
+
* to prevent infinite loops
|
|
275
|
+
*/
|
|
276
|
+
const maxGeneratorDuration = 20000;
|
|
277
|
+
function calcGeneratorDuration(generator) {
|
|
278
|
+
let duration = 0;
|
|
279
|
+
const timeStep = 50;
|
|
280
|
+
let state = generator.next(duration);
|
|
281
|
+
while (!state.done && duration < maxGeneratorDuration) {
|
|
282
|
+
duration += timeStep;
|
|
283
|
+
state = generator.next(duration);
|
|
284
|
+
}
|
|
285
|
+
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Create a progress => progress easing function from a generator.
|
|
290
|
+
*/
|
|
291
|
+
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
292
|
+
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
293
|
+
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
294
|
+
return {
|
|
295
|
+
type: "keyframes",
|
|
296
|
+
ease: (progress) => generator.next(duration * progress).value / scale,
|
|
297
|
+
duration: millisecondsToSeconds(duration),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const createUnitType = (unit) => ({
|
|
302
|
+
test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
|
|
303
|
+
parse: parseFloat,
|
|
304
|
+
transform: (v) => `${v}${unit}`,
|
|
305
|
+
});
|
|
306
|
+
const px = /*@__PURE__*/ createUnitType("px");
|
|
307
|
+
|
|
308
|
+
const browserNumberValueTypes = {
|
|
309
|
+
// Border props
|
|
310
|
+
borderWidth: px,
|
|
311
|
+
borderTopWidth: px,
|
|
312
|
+
borderRightWidth: px,
|
|
313
|
+
borderBottomWidth: px,
|
|
314
|
+
borderLeftWidth: px,
|
|
315
|
+
borderRadius: px,
|
|
316
|
+
radius: px,
|
|
317
|
+
borderTopLeftRadius: px,
|
|
318
|
+
borderTopRightRadius: px,
|
|
319
|
+
borderBottomRightRadius: px,
|
|
320
|
+
borderBottomLeftRadius: px,
|
|
321
|
+
// Positioning props
|
|
322
|
+
width: px,
|
|
323
|
+
maxWidth: px,
|
|
324
|
+
height: px,
|
|
325
|
+
maxHeight: px,
|
|
326
|
+
top: px,
|
|
327
|
+
right: px,
|
|
328
|
+
bottom: px,
|
|
329
|
+
left: px,
|
|
330
|
+
// Spacing props
|
|
331
|
+
padding: px,
|
|
332
|
+
paddingTop: px,
|
|
333
|
+
paddingRight: px,
|
|
334
|
+
paddingBottom: px,
|
|
335
|
+
paddingLeft: px,
|
|
336
|
+
margin: px,
|
|
337
|
+
marginTop: px,
|
|
338
|
+
marginRight: px,
|
|
339
|
+
marginBottom: px,
|
|
340
|
+
marginLeft: px,
|
|
341
|
+
// Misc
|
|
342
|
+
backgroundPositionX: px,
|
|
343
|
+
backgroundPositionY: px,
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
function isGenerator(type) {
|
|
347
|
+
return typeof type === "function";
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function attachTimeline(animation, timeline) {
|
|
351
|
+
animation.timeline = timeline;
|
|
352
|
+
animation.onfinish = null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const isNotNull = (value) => value !== null;
|
|
356
|
+
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
357
|
+
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
358
|
+
const index = repeat && repeatType !== "loop" && repeat % 2 === 1
|
|
359
|
+
? 0
|
|
360
|
+
: resolvedKeyframes.length - 1;
|
|
361
|
+
return !index || finalKeyframe === undefined
|
|
362
|
+
? resolvedKeyframes[index]
|
|
363
|
+
: finalKeyframe;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function setCSSVar(element, name, value) {
|
|
367
|
+
element.style.setProperty(`--${name}`, value);
|
|
368
|
+
}
|
|
369
|
+
function setStyle(element, name, value) {
|
|
370
|
+
element.style[name] = value;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
|
|
374
|
+
try {
|
|
375
|
+
document.createElement("div").animate({ opacity: [1] });
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return true;
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
384
|
+
|
|
385
|
+
const state = new WeakMap();
|
|
386
|
+
function hydrateKeyframes(valueName, keyframes, read) {
|
|
387
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
388
|
+
if (keyframes[i] === null) {
|
|
389
|
+
keyframes[i] = i === 0 ? read() : keyframes[i - 1];
|
|
390
|
+
}
|
|
391
|
+
if (typeof keyframes[i] === "number" &&
|
|
392
|
+
browserNumberValueTypes[valueName]) {
|
|
393
|
+
keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (!supportsPartialKeyframes() && keyframes.length < 2) {
|
|
397
|
+
keyframes.unshift(read());
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const defaultEasing = "easeOut";
|
|
401
|
+
function getElementAnimationState(element) {
|
|
402
|
+
const animationState = state.get(element) || new Map();
|
|
403
|
+
state.set(element, animationState);
|
|
404
|
+
return state.get(element);
|
|
405
|
+
}
|
|
406
|
+
class NativeAnimation {
|
|
407
|
+
constructor(element, valueName, valueKeyframes, options) {
|
|
408
|
+
const isCSSVar = valueName.startsWith("--");
|
|
409
|
+
this.setValue = isCSSVar ? setCSSVar : setStyle;
|
|
410
|
+
this.options = options;
|
|
411
|
+
this.updateFinishedPromise();
|
|
412
|
+
invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
|
|
413
|
+
const existingAnimation = getElementAnimationState(element).get(valueName);
|
|
414
|
+
existingAnimation && existingAnimation.stop();
|
|
415
|
+
const readInitialKeyframe = () => {
|
|
416
|
+
return valueName.startsWith("--")
|
|
417
|
+
? element.style.getPropertyValue(valueName)
|
|
418
|
+
: window.getComputedStyle(element)[valueName];
|
|
419
|
+
};
|
|
420
|
+
if (!Array.isArray(valueKeyframes)) {
|
|
421
|
+
valueKeyframes = [valueKeyframes];
|
|
422
|
+
}
|
|
423
|
+
hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
|
|
424
|
+
if (isGenerator(options.type)) {
|
|
425
|
+
const generatorOptions = createGeneratorEasing(options, 100, options.type);
|
|
426
|
+
options.ease = supportsLinearEasing()
|
|
427
|
+
? generatorOptions.ease
|
|
428
|
+
: defaultEasing;
|
|
429
|
+
options.duration = secondsToMilliseconds(generatorOptions.duration);
|
|
430
|
+
options.type = "keyframes";
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
options.ease = options.ease || defaultEasing;
|
|
434
|
+
}
|
|
435
|
+
this.removeAnimation = () => { var _a; return (_a = state.get(element)) === null || _a === void 0 ? void 0 : _a.delete(valueName); };
|
|
436
|
+
const onFinish = () => {
|
|
437
|
+
this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, this.options));
|
|
438
|
+
this.cancel();
|
|
439
|
+
this.resolveFinishedPromise();
|
|
440
|
+
};
|
|
441
|
+
if (!supportsWaapi()) {
|
|
442
|
+
onFinish();
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
this.animation = startWaapiAnimation(element, valueName, valueKeyframes, options);
|
|
446
|
+
if (options.autoplay === false) {
|
|
447
|
+
this.animation.pause();
|
|
448
|
+
}
|
|
449
|
+
this.animation.onfinish = onFinish;
|
|
450
|
+
if (this.pendingTimeline) {
|
|
451
|
+
attachTimeline(this.animation, this.pendingTimeline);
|
|
452
|
+
}
|
|
453
|
+
getElementAnimationState(element).set(valueName, this);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
get duration() {
|
|
457
|
+
return millisecondsToSeconds(this.options.duration || 300);
|
|
458
|
+
}
|
|
459
|
+
get time() {
|
|
460
|
+
var _a;
|
|
461
|
+
if (this.animation) {
|
|
462
|
+
return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
|
|
463
|
+
}
|
|
464
|
+
return 0;
|
|
465
|
+
}
|
|
466
|
+
set time(newTime) {
|
|
467
|
+
if (this.animation) {
|
|
468
|
+
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
get speed() {
|
|
472
|
+
return this.animation ? this.animation.playbackRate : 1;
|
|
473
|
+
}
|
|
474
|
+
set speed(newSpeed) {
|
|
475
|
+
if (this.animation) {
|
|
476
|
+
this.animation.playbackRate = newSpeed;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
get state() {
|
|
480
|
+
return this.animation ? this.animation.playState : "finished";
|
|
481
|
+
}
|
|
482
|
+
get startTime() {
|
|
483
|
+
return this.animation ? this.animation.startTime : null;
|
|
484
|
+
}
|
|
485
|
+
play() {
|
|
486
|
+
if (this.state === "finished") {
|
|
487
|
+
this.updateFinishedPromise();
|
|
488
|
+
}
|
|
489
|
+
this.animation && this.animation.play();
|
|
490
|
+
}
|
|
491
|
+
pause() {
|
|
492
|
+
this.animation && this.animation.pause();
|
|
493
|
+
}
|
|
494
|
+
stop() {
|
|
495
|
+
if (!this.animation ||
|
|
496
|
+
this.state === "idle" ||
|
|
497
|
+
this.state === "finished") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (this.animation.commitStyles) {
|
|
501
|
+
this.animation.commitStyles();
|
|
502
|
+
}
|
|
503
|
+
this.cancel();
|
|
504
|
+
}
|
|
505
|
+
complete() {
|
|
506
|
+
this.animation && this.animation.finish();
|
|
507
|
+
}
|
|
508
|
+
cancel() {
|
|
509
|
+
this.removeAnimation();
|
|
510
|
+
try {
|
|
511
|
+
this.animation && this.animation.cancel();
|
|
512
|
+
}
|
|
513
|
+
catch (e) { }
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
517
|
+
* resolves when the animation finishes at all but in a future update could/should
|
|
518
|
+
* reject if its cancels.
|
|
519
|
+
*/
|
|
520
|
+
then(resolve, reject) {
|
|
521
|
+
return this.currentFinishedPromise.then(resolve, reject);
|
|
522
|
+
}
|
|
523
|
+
updateFinishedPromise() {
|
|
524
|
+
this.currentFinishedPromise = new Promise((resolve) => {
|
|
525
|
+
this.resolveFinishedPromise = resolve;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
attachTimeline(timeline) {
|
|
529
|
+
if (!this.animation) {
|
|
530
|
+
this.pendingTimeline = timeline;
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
attachTimeline(this.animation, timeline);
|
|
534
|
+
}
|
|
535
|
+
return noop;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
540
|
+
const elements = resolveElements(elementOrSelector, scope);
|
|
541
|
+
const numElements = elements.length;
|
|
542
|
+
invariant(Boolean(numElements), "No valid element provided.");
|
|
543
|
+
const animations = [];
|
|
544
|
+
for (let i = 0; i < numElements; i++) {
|
|
545
|
+
const element = elements[i];
|
|
546
|
+
const elementTransition = { ...options };
|
|
547
|
+
/**
|
|
548
|
+
* Resolve stagger function if provided.
|
|
549
|
+
*/
|
|
550
|
+
if (typeof elementTransition.delay === "function") {
|
|
551
|
+
elementTransition.delay = elementTransition.delay(i, numElements);
|
|
552
|
+
}
|
|
553
|
+
for (const valueName in keyframes) {
|
|
554
|
+
const valueKeyframes = keyframes[valueName];
|
|
555
|
+
const valueOptions = {
|
|
556
|
+
...getValueTransition(options, valueName),
|
|
557
|
+
};
|
|
558
|
+
valueOptions.duration = valueOptions.duration
|
|
559
|
+
? secondsToMilliseconds(valueOptions.duration)
|
|
560
|
+
: valueOptions.duration;
|
|
561
|
+
valueOptions.delay = secondsToMilliseconds(valueOptions.delay || 0);
|
|
562
|
+
animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return animations;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const createScopedWaapiAnimate = (scope) => {
|
|
569
|
+
function scopedAnimate(elementOrSelector, keyframes, options) {
|
|
570
|
+
return new GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
|
|
571
|
+
}
|
|
572
|
+
return scopedAnimate;
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
function useAnimateMini() {
|
|
576
|
+
const scope = useConstant(() => ({
|
|
577
|
+
current: null, // Will be hydrated by React
|
|
578
|
+
animations: [],
|
|
579
|
+
}));
|
|
580
|
+
const animate = useConstant(() => createScopedWaapiAnimate(scope));
|
|
581
|
+
useUnmountEffect(() => {
|
|
582
|
+
scope.animations.forEach((animation) => animation.stop());
|
|
583
|
+
});
|
|
584
|
+
return [scope, animate];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
exports.useAnimate = useAnimateMini;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var framerMotion = require('framer-motion');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.keys(framerMotion).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return framerMotion[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -17,7 +17,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
17
17
|
* and warn against mismatches.
|
|
18
18
|
*/
|
|
19
19
|
if (process.env.NODE_ENV === "development") {
|
|
20
|
-
warnOnce(nextValue.version === "11.11.
|
|
20
|
+
warnOnce(nextValue.version === "11.11.15", `Attempting to mix Motion versions ${nextValue.version} with 11.11.15 may not work as expected.`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
else if (isMotionValue(prevValue)) {
|
|
@@ -34,7 +34,7 @@ class MotionValue {
|
|
|
34
34
|
* This will be replaced by the build step with the latest version number.
|
|
35
35
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
36
36
|
*/
|
|
37
|
-
this.version = "11.11.
|
|
37
|
+
this.version = "11.11.15";
|
|
38
38
|
/**
|
|
39
39
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
40
40
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { animateMini as animate } from '../../framer-motion/dist/es/animation/animators/waapi/animate-style.mjs';
|
package/dist/motion.dev.js
CHANGED
|
@@ -281,7 +281,7 @@
|
|
|
281
281
|
* This will be replaced by the build step with the latest version number.
|
|
282
282
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
283
283
|
*/
|
|
284
|
-
this.version = "11.11.
|
|
284
|
+
this.version = "11.11.15";
|
|
285
285
|
/**
|
|
286
286
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
287
287
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -4091,7 +4091,7 @@
|
|
|
4091
4091
|
* and warn against mismatches.
|
|
4092
4092
|
*/
|
|
4093
4093
|
{
|
|
4094
|
-
warnOnce(nextValue.version === "11.11.
|
|
4094
|
+
warnOnce(nextValue.version === "11.11.15", `Attempting to mix Motion versions ${nextValue.version} with 11.11.15 may not work as expected.`);
|
|
4095
4095
|
}
|
|
4096
4096
|
}
|
|
4097
4097
|
else if (isMotionValue(prevValue)) {
|