motion-dom 12.7.3 → 12.7.5-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2946 -475
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +178 -0
- package/dist/es/animation/GroupAnimation.mjs +6 -15
- package/dist/es/animation/JSAnimation.mjs +346 -0
- package/dist/es/animation/NativeAnimation.mjs +64 -67
- package/dist/es/animation/NativeAnimationExtended.mjs +65 -0
- package/dist/es/animation/NativeAnimationWrapper.mjs +14 -0
- package/dist/es/animation/drivers/driver-frameloop.mjs +17 -0
- package/dist/es/animation/generators/inertia.mjs +87 -0
- package/dist/es/animation/generators/keyframes.mjs +49 -0
- package/dist/es/animation/generators/spring/defaults.mjs +27 -0
- package/dist/es/animation/generators/spring/find.mjs +84 -0
- package/dist/es/animation/generators/spring/index.mjs +175 -0
- package/dist/es/animation/generators/utils/velocity.mjs +9 -0
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +131 -0
- package/dist/es/animation/keyframes/KeyframesResolver.mjs +156 -0
- package/dist/es/animation/keyframes/get-final.mjs +3 -4
- package/dist/es/animation/keyframes/offsets/default.mjs +9 -0
- package/dist/es/animation/keyframes/offsets/fill.mjs +12 -0
- package/dist/es/animation/keyframes/offsets/time.mjs +5 -0
- package/dist/es/animation/keyframes/utils/apply-px-defaults.mjs +11 -0
- package/dist/es/animation/keyframes/utils/fill-wildcards.mjs +7 -0
- package/dist/es/animation/keyframes/utils/is-none.mjs +15 -0
- package/dist/es/animation/keyframes/utils/make-none-animatable.mjs +30 -0
- package/dist/es/animation/keyframes/utils/unit-conversion.mjs +36 -0
- package/dist/es/animation/utils/WithPromise.mjs +28 -0
- package/dist/es/animation/utils/active-animations.mjs +9 -0
- package/dist/es/animation/utils/can-animate.mjs +42 -0
- package/dist/es/animation/utils/css-variables-conversion.mjs +41 -0
- package/dist/es/animation/utils/is-animatable.mjs +30 -0
- package/dist/es/animation/utils/is-css-variable.mjs +15 -0
- package/dist/es/animation/utils/replace-transition-type.mjs +18 -0
- package/dist/es/animation/waapi/easing/is-supported.mjs +1 -1
- package/dist/es/animation/waapi/easing/map-easing.mjs +5 -3
- package/dist/es/animation/waapi/start-waapi-animation.mjs +6 -4
- package/dist/es/animation/waapi/supports/waapi.mjs +39 -0
- package/dist/es/animation/waapi/utils/accelerated-values.mjs +14 -0
- package/dist/es/animation/waapi/utils/apply-generator.mjs +2 -1
- package/dist/es/animation/waapi/utils/unsupported-easing.mjs +18 -0
- package/dist/es/frameloop/batcher.mjs +2 -1
- package/dist/es/frameloop/order.mjs +1 -0
- package/dist/es/index.mjs +49 -2
- package/dist/es/render/dom/is-css-var.mjs +3 -0
- package/dist/es/render/dom/parse-transform.mjs +83 -0
- package/dist/es/render/dom/style-computed.mjs +10 -0
- package/dist/es/render/dom/style-set.mjs +9 -0
- package/dist/es/render/utils/keys-position.mjs +13 -0
- package/dist/es/render/utils/keys-transform.mjs +28 -0
- package/dist/es/scroll/observe.mjs +18 -0
- package/dist/es/stats/index.mjs +2 -0
- package/dist/es/utils/interpolate.mjs +74 -0
- package/dist/es/utils/mix/color.mjs +47 -0
- package/dist/es/utils/mix/complex.mjs +92 -0
- package/dist/es/utils/mix/immediate.mjs +5 -0
- package/dist/es/utils/mix/index.mjs +14 -0
- package/dist/es/utils/mix/number.mjs +26 -0
- package/dist/es/utils/mix/visibility.mjs +16 -0
- package/dist/es/value/index.mjs +3 -1
- package/dist/es/value/types/auto.mjs +9 -0
- package/dist/es/value/types/color/hex.mjs +40 -0
- package/dist/es/value/types/color/hsla-to-rgba.mjs +42 -0
- package/dist/es/value/types/color/hsla.mjs +22 -0
- package/dist/es/value/types/color/index.mjs +27 -0
- package/dist/es/value/types/color/rgba.mjs +25 -0
- package/dist/es/value/types/color/utils.mjs +29 -0
- package/dist/es/value/types/complex/filter.mjs +30 -0
- package/dist/es/value/types/complex/index.mjs +91 -0
- package/dist/es/value/types/dimensions.mjs +15 -0
- package/dist/es/value/types/int.mjs +8 -0
- package/dist/es/value/types/maps/defaults.mjs +30 -0
- package/dist/es/value/types/maps/number.mjs +51 -0
- package/dist/es/value/types/maps/transform.mjs +31 -0
- package/dist/es/value/types/numbers/index.mjs +17 -0
- package/dist/es/value/types/numbers/units.mjs +18 -0
- package/dist/es/value/types/test.mjs +6 -0
- package/dist/es/value/types/utils/animatable-none.mjs +15 -0
- package/dist/es/value/types/utils/color-regex.mjs +3 -0
- package/dist/es/value/types/utils/find.mjs +15 -0
- package/dist/es/value/types/utils/float-regex.mjs +3 -0
- package/dist/es/value/types/utils/get-as-type.mjs +10 -0
- package/dist/es/value/types/utils/is-nullish.mjs +5 -0
- package/dist/es/value/types/utils/sanitize.mjs +5 -0
- package/dist/es/value/types/utils/single-color-regex.mjs +3 -0
- package/dist/es/view/start.mjs +4 -3
- package/dist/index.d.ts +945 -444
- package/dist/motion-dom.dev.js +2945 -475
- package/dist/motion-dom.js +1 -1
- package/package.json +3 -3
- package/dist/es/animation/keyframes/hydrate.mjs +0 -26
- package/dist/es/animation/waapi/utils/attach-timeline.mjs +0 -6
- package/dist/es/render/dom/style.mjs +0 -15
- package/dist/es/utils/is-bezier-definition.mjs +0 -3
package/dist/motion-dom.dev.js
CHANGED
|
@@ -4,198 +4,1920 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MotionDom = {}, global.MotionUtils));
|
|
5
5
|
})(this, (function (exports, motionUtils) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const stepsOrder = [
|
|
8
|
+
"setup", // Compute
|
|
9
|
+
"read", // Read
|
|
10
|
+
"resolveKeyframes", // Write/Read/Write/Read
|
|
11
|
+
"update", // Compute
|
|
12
|
+
"preRender", // Compute
|
|
13
|
+
"render", // Write
|
|
14
|
+
"postRender", // Compute
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const statsBuffer = {
|
|
18
|
+
value: null,
|
|
19
|
+
addProjectionMetrics: null,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function createRenderStep(runNextFrame, stepName) {
|
|
23
|
+
/**
|
|
24
|
+
* We create and reuse two queues, one to queue jobs for the current frame
|
|
25
|
+
* and one for the next. We reuse to avoid triggering GC after x frames.
|
|
26
|
+
*/
|
|
27
|
+
let thisFrame = new Set();
|
|
28
|
+
let nextFrame = new Set();
|
|
29
|
+
/**
|
|
30
|
+
* Track whether we're currently processing jobs in this step. This way
|
|
31
|
+
* we can decide whether to schedule new jobs for this frame or next.
|
|
32
|
+
*/
|
|
33
|
+
let isProcessing = false;
|
|
34
|
+
let flushNextFrame = false;
|
|
35
|
+
/**
|
|
36
|
+
* A set of processes which were marked keepAlive when scheduled.
|
|
37
|
+
*/
|
|
38
|
+
const toKeepAlive = new WeakSet();
|
|
39
|
+
let latestFrameData = {
|
|
40
|
+
delta: 0.0,
|
|
41
|
+
timestamp: 0.0,
|
|
42
|
+
isProcessing: false,
|
|
43
|
+
};
|
|
44
|
+
let numCalls = 0;
|
|
45
|
+
function triggerCallback(callback) {
|
|
46
|
+
if (toKeepAlive.has(callback)) {
|
|
47
|
+
step.schedule(callback);
|
|
48
|
+
runNextFrame();
|
|
49
|
+
}
|
|
50
|
+
numCalls++;
|
|
51
|
+
callback(latestFrameData);
|
|
52
|
+
}
|
|
53
|
+
const step = {
|
|
54
|
+
/**
|
|
55
|
+
* Schedule a process to run on the next frame.
|
|
56
|
+
*/
|
|
57
|
+
schedule: (callback, keepAlive = false, immediate = false) => {
|
|
58
|
+
const addToCurrentFrame = immediate && isProcessing;
|
|
59
|
+
const queue = addToCurrentFrame ? thisFrame : nextFrame;
|
|
60
|
+
if (keepAlive)
|
|
61
|
+
toKeepAlive.add(callback);
|
|
62
|
+
if (!queue.has(callback))
|
|
63
|
+
queue.add(callback);
|
|
64
|
+
return callback;
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Cancel the provided callback from running on the next frame.
|
|
68
|
+
*/
|
|
69
|
+
cancel: (callback) => {
|
|
70
|
+
nextFrame.delete(callback);
|
|
71
|
+
toKeepAlive.delete(callback);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Execute all schedule callbacks.
|
|
75
|
+
*/
|
|
76
|
+
process: (frameData) => {
|
|
77
|
+
latestFrameData = frameData;
|
|
78
|
+
/**
|
|
79
|
+
* If we're already processing we've probably been triggered by a flushSync
|
|
80
|
+
* inside an existing process. Instead of executing, mark flushNextFrame
|
|
81
|
+
* as true and ensure we flush the following frame at the end of this one.
|
|
82
|
+
*/
|
|
83
|
+
if (isProcessing) {
|
|
84
|
+
flushNextFrame = true;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
isProcessing = true;
|
|
88
|
+
[thisFrame, nextFrame] = [nextFrame, thisFrame];
|
|
89
|
+
// Execute this frame
|
|
90
|
+
thisFrame.forEach(triggerCallback);
|
|
91
|
+
/**
|
|
92
|
+
* If we're recording stats then
|
|
93
|
+
*/
|
|
94
|
+
if (stepName && statsBuffer.value) {
|
|
95
|
+
statsBuffer.value.frameloop[stepName].push(numCalls);
|
|
96
|
+
}
|
|
97
|
+
numCalls = 0;
|
|
98
|
+
// Clear the frame so no callbacks remain. This is to avoid
|
|
99
|
+
// memory leaks should this render step not run for a while.
|
|
100
|
+
thisFrame.clear();
|
|
101
|
+
isProcessing = false;
|
|
102
|
+
if (flushNextFrame) {
|
|
103
|
+
flushNextFrame = false;
|
|
104
|
+
step.process(frameData);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
return step;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const maxElapsed = 40;
|
|
112
|
+
function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
|
|
113
|
+
let runNextFrame = false;
|
|
114
|
+
let useDefaultElapsed = true;
|
|
115
|
+
const state = {
|
|
116
|
+
delta: 0.0,
|
|
117
|
+
timestamp: 0.0,
|
|
118
|
+
isProcessing: false,
|
|
119
|
+
};
|
|
120
|
+
const flagRunNextFrame = () => (runNextFrame = true);
|
|
121
|
+
const steps = stepsOrder.reduce((acc, key) => {
|
|
122
|
+
acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
|
|
123
|
+
return acc;
|
|
124
|
+
}, {});
|
|
125
|
+
const { setup, read, resolveKeyframes, update, preRender, render, postRender, } = steps;
|
|
126
|
+
const processBatch = () => {
|
|
127
|
+
const timestamp = motionUtils.MotionGlobalConfig.useManualTiming
|
|
128
|
+
? state.timestamp
|
|
129
|
+
: performance.now();
|
|
130
|
+
runNextFrame = false;
|
|
131
|
+
if (!motionUtils.MotionGlobalConfig.useManualTiming) {
|
|
132
|
+
state.delta = useDefaultElapsed
|
|
133
|
+
? 1000 / 60
|
|
134
|
+
: Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
|
|
135
|
+
}
|
|
136
|
+
state.timestamp = timestamp;
|
|
137
|
+
state.isProcessing = true;
|
|
138
|
+
// Unrolled render loop for better per-frame performance
|
|
139
|
+
setup.process(state);
|
|
140
|
+
read.process(state);
|
|
141
|
+
resolveKeyframes.process(state);
|
|
142
|
+
update.process(state);
|
|
143
|
+
preRender.process(state);
|
|
144
|
+
render.process(state);
|
|
145
|
+
postRender.process(state);
|
|
146
|
+
state.isProcessing = false;
|
|
147
|
+
if (runNextFrame && allowKeepAlive) {
|
|
148
|
+
useDefaultElapsed = false;
|
|
149
|
+
scheduleNextBatch(processBatch);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const wake = () => {
|
|
153
|
+
runNextFrame = true;
|
|
154
|
+
useDefaultElapsed = true;
|
|
155
|
+
if (!state.isProcessing) {
|
|
156
|
+
scheduleNextBatch(processBatch);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const schedule = stepsOrder.reduce((acc, key) => {
|
|
160
|
+
const step = steps[key];
|
|
161
|
+
acc[key] = (process, keepAlive = false, immediate = false) => {
|
|
162
|
+
if (!runNextFrame)
|
|
163
|
+
wake();
|
|
164
|
+
return step.schedule(process, keepAlive, immediate);
|
|
165
|
+
};
|
|
166
|
+
return acc;
|
|
167
|
+
}, {});
|
|
168
|
+
const cancel = (process) => {
|
|
169
|
+
for (let i = 0; i < stepsOrder.length; i++) {
|
|
170
|
+
steps[stepsOrder[i]].cancel(process);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return { schedule, cancel, state, steps };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
|
|
177
|
+
|
|
178
|
+
let now;
|
|
179
|
+
function clearTime() {
|
|
180
|
+
now = undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* An eventloop-synchronous alternative to performance.now().
|
|
184
|
+
*
|
|
185
|
+
* Ensures that time measurements remain consistent within a synchronous context.
|
|
186
|
+
* Usually calling performance.now() twice within the same synchronous context
|
|
187
|
+
* will return different values which isn't useful for animations when we're usually
|
|
188
|
+
* trying to sync animations to the same frame.
|
|
189
|
+
*/
|
|
190
|
+
const time = {
|
|
191
|
+
now: () => {
|
|
192
|
+
if (now === undefined) {
|
|
193
|
+
time.set(frameData.isProcessing || motionUtils.MotionGlobalConfig.useManualTiming
|
|
194
|
+
? frameData.timestamp
|
|
195
|
+
: performance.now());
|
|
196
|
+
}
|
|
197
|
+
return now;
|
|
198
|
+
},
|
|
199
|
+
set: (newTime) => {
|
|
200
|
+
now = newTime;
|
|
201
|
+
queueMicrotask(clearTime);
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const activeAnimations = {
|
|
206
|
+
layout: 0,
|
|
207
|
+
mainThread: 0,
|
|
208
|
+
waapi: 0,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
212
|
+
const isCSSVariableName =
|
|
213
|
+
/*@__PURE__*/ checkStringStartsWith("--");
|
|
214
|
+
const startsAsVariableToken =
|
|
215
|
+
/*@__PURE__*/ checkStringStartsWith("var(--");
|
|
216
|
+
const isCSSVariableToken = (value) => {
|
|
217
|
+
const startsWithToken = startsAsVariableToken(value);
|
|
218
|
+
if (!startsWithToken)
|
|
219
|
+
return false;
|
|
220
|
+
// Ensure any comments are stripped from the value as this can harm performance of the regex.
|
|
221
|
+
return singleCssVariableRegex.test(value.split("/*")[0].trim());
|
|
222
|
+
};
|
|
223
|
+
const singleCssVariableRegex = /var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;
|
|
224
|
+
|
|
225
|
+
const number = {
|
|
226
|
+
test: (v) => typeof v === "number",
|
|
227
|
+
parse: parseFloat,
|
|
228
|
+
transform: (v) => v,
|
|
229
|
+
};
|
|
230
|
+
const alpha = {
|
|
231
|
+
...number,
|
|
232
|
+
transform: (v) => motionUtils.clamp(0, 1, v),
|
|
233
|
+
};
|
|
234
|
+
const scale = {
|
|
235
|
+
...number,
|
|
236
|
+
default: 1,
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// If this number is a decimal, make it just five decimal places
|
|
240
|
+
// to avoid exponents
|
|
241
|
+
const sanitize = (v) => Math.round(v * 100000) / 100000;
|
|
242
|
+
|
|
243
|
+
const floatRegex = /-?(?:\d+(?:\.\d+)?|\.\d+)/gu;
|
|
244
|
+
|
|
245
|
+
function isNullish(v) {
|
|
246
|
+
return v == null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const singleColorRegex = /^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))$/iu;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns true if the provided string is a color, ie rgba(0,0,0,0) or #000,
|
|
253
|
+
* but false if a number or multiple colors
|
|
254
|
+
*/
|
|
255
|
+
const isColorString = (type, testProp) => (v) => {
|
|
256
|
+
return Boolean((typeof v === "string" &&
|
|
257
|
+
singleColorRegex.test(v) &&
|
|
258
|
+
v.startsWith(type)) ||
|
|
259
|
+
(testProp &&
|
|
260
|
+
!isNullish(v) &&
|
|
261
|
+
Object.prototype.hasOwnProperty.call(v, testProp)));
|
|
262
|
+
};
|
|
263
|
+
const splitColor = (aName, bName, cName) => (v) => {
|
|
264
|
+
if (typeof v !== "string")
|
|
265
|
+
return v;
|
|
266
|
+
const [a, b, c, alpha] = v.match(floatRegex);
|
|
267
|
+
return {
|
|
268
|
+
[aName]: parseFloat(a),
|
|
269
|
+
[bName]: parseFloat(b),
|
|
270
|
+
[cName]: parseFloat(c),
|
|
271
|
+
alpha: alpha !== undefined ? parseFloat(alpha) : 1,
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const clampRgbUnit = (v) => motionUtils.clamp(0, 255, v);
|
|
276
|
+
const rgbUnit = {
|
|
277
|
+
...number,
|
|
278
|
+
transform: (v) => Math.round(clampRgbUnit(v)),
|
|
279
|
+
};
|
|
280
|
+
const rgba = {
|
|
281
|
+
test: /*@__PURE__*/ isColorString("rgb", "red"),
|
|
282
|
+
parse: /*@__PURE__*/ splitColor("red", "green", "blue"),
|
|
283
|
+
transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => "rgba(" +
|
|
284
|
+
rgbUnit.transform(red) +
|
|
285
|
+
", " +
|
|
286
|
+
rgbUnit.transform(green) +
|
|
287
|
+
", " +
|
|
288
|
+
rgbUnit.transform(blue) +
|
|
289
|
+
", " +
|
|
290
|
+
sanitize(alpha.transform(alpha$1)) +
|
|
291
|
+
")",
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
function parseHex(v) {
|
|
295
|
+
let r = "";
|
|
296
|
+
let g = "";
|
|
297
|
+
let b = "";
|
|
298
|
+
let a = "";
|
|
299
|
+
// If we have 6 characters, ie #FF0000
|
|
300
|
+
if (v.length > 5) {
|
|
301
|
+
r = v.substring(1, 3);
|
|
302
|
+
g = v.substring(3, 5);
|
|
303
|
+
b = v.substring(5, 7);
|
|
304
|
+
a = v.substring(7, 9);
|
|
305
|
+
// Or we have 3 characters, ie #F00
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
r = v.substring(1, 2);
|
|
309
|
+
g = v.substring(2, 3);
|
|
310
|
+
b = v.substring(3, 4);
|
|
311
|
+
a = v.substring(4, 5);
|
|
312
|
+
r += r;
|
|
313
|
+
g += g;
|
|
314
|
+
b += b;
|
|
315
|
+
a += a;
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
red: parseInt(r, 16),
|
|
319
|
+
green: parseInt(g, 16),
|
|
320
|
+
blue: parseInt(b, 16),
|
|
321
|
+
alpha: a ? parseInt(a, 16) / 255 : 1,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const hex = {
|
|
325
|
+
test: /*@__PURE__*/ isColorString("#"),
|
|
326
|
+
parse: parseHex,
|
|
327
|
+
transform: rgba.transform,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
331
|
+
const createUnitType = (unit) => ({
|
|
332
|
+
test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
|
|
333
|
+
parse: parseFloat,
|
|
334
|
+
transform: (v) => `${v}${unit}`,
|
|
335
|
+
});
|
|
336
|
+
const degrees = /*@__PURE__*/ createUnitType("deg");
|
|
337
|
+
const percent = /*@__PURE__*/ createUnitType("%");
|
|
338
|
+
const px = /*@__PURE__*/ createUnitType("px");
|
|
339
|
+
const vh = /*@__PURE__*/ createUnitType("vh");
|
|
340
|
+
const vw = /*@__PURE__*/ createUnitType("vw");
|
|
341
|
+
const progressPercentage = /*@__PURE__*/ (() => ({
|
|
342
|
+
...percent,
|
|
343
|
+
parse: (v) => percent.parse(v) / 100,
|
|
344
|
+
transform: (v) => percent.transform(v * 100),
|
|
345
|
+
}))();
|
|
346
|
+
|
|
347
|
+
const hsla = {
|
|
348
|
+
test: /*@__PURE__*/ isColorString("hsl", "hue"),
|
|
349
|
+
parse: /*@__PURE__*/ splitColor("hue", "saturation", "lightness"),
|
|
350
|
+
transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
|
|
351
|
+
return ("hsla(" +
|
|
352
|
+
Math.round(hue) +
|
|
353
|
+
", " +
|
|
354
|
+
percent.transform(sanitize(saturation)) +
|
|
355
|
+
", " +
|
|
356
|
+
percent.transform(sanitize(lightness)) +
|
|
357
|
+
", " +
|
|
358
|
+
sanitize(alpha.transform(alpha$1)) +
|
|
359
|
+
")");
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const color = {
|
|
364
|
+
test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
|
|
365
|
+
parse: (v) => {
|
|
366
|
+
if (rgba.test(v)) {
|
|
367
|
+
return rgba.parse(v);
|
|
368
|
+
}
|
|
369
|
+
else if (hsla.test(v)) {
|
|
370
|
+
return hsla.parse(v);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
return hex.parse(v);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
transform: (v) => {
|
|
377
|
+
return typeof v === "string"
|
|
378
|
+
? v
|
|
379
|
+
: v.hasOwnProperty("red")
|
|
380
|
+
? rgba.transform(v)
|
|
381
|
+
: hsla.transform(v);
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
const colorRegex = /(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\))/giu;
|
|
386
|
+
|
|
387
|
+
function test(v) {
|
|
388
|
+
return (isNaN(v) &&
|
|
389
|
+
typeof v === "string" &&
|
|
390
|
+
(v.match(floatRegex)?.length || 0) +
|
|
391
|
+
(v.match(colorRegex)?.length || 0) >
|
|
392
|
+
0);
|
|
393
|
+
}
|
|
394
|
+
const NUMBER_TOKEN = "number";
|
|
395
|
+
const COLOR_TOKEN = "color";
|
|
396
|
+
const VAR_TOKEN = "var";
|
|
397
|
+
const VAR_FUNCTION_TOKEN = "var(";
|
|
398
|
+
const SPLIT_TOKEN = "${}";
|
|
399
|
+
// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`
|
|
400
|
+
const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;
|
|
401
|
+
function analyseComplexValue(value) {
|
|
402
|
+
const originalValue = value.toString();
|
|
403
|
+
const values = [];
|
|
404
|
+
const indexes = {
|
|
405
|
+
color: [],
|
|
406
|
+
number: [],
|
|
407
|
+
var: [],
|
|
408
|
+
};
|
|
409
|
+
const types = [];
|
|
410
|
+
let i = 0;
|
|
411
|
+
const tokenised = originalValue.replace(complexRegex, (parsedValue) => {
|
|
412
|
+
if (color.test(parsedValue)) {
|
|
413
|
+
indexes.color.push(i);
|
|
414
|
+
types.push(COLOR_TOKEN);
|
|
415
|
+
values.push(color.parse(parsedValue));
|
|
416
|
+
}
|
|
417
|
+
else if (parsedValue.startsWith(VAR_FUNCTION_TOKEN)) {
|
|
418
|
+
indexes.var.push(i);
|
|
419
|
+
types.push(VAR_TOKEN);
|
|
420
|
+
values.push(parsedValue);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
indexes.number.push(i);
|
|
424
|
+
types.push(NUMBER_TOKEN);
|
|
425
|
+
values.push(parseFloat(parsedValue));
|
|
426
|
+
}
|
|
427
|
+
++i;
|
|
428
|
+
return SPLIT_TOKEN;
|
|
429
|
+
});
|
|
430
|
+
const split = tokenised.split(SPLIT_TOKEN);
|
|
431
|
+
return { values, split, indexes, types };
|
|
432
|
+
}
|
|
433
|
+
function parseComplexValue(v) {
|
|
434
|
+
return analyseComplexValue(v).values;
|
|
435
|
+
}
|
|
436
|
+
function createTransformer(source) {
|
|
437
|
+
const { split, types } = analyseComplexValue(source);
|
|
438
|
+
const numSections = split.length;
|
|
439
|
+
return (v) => {
|
|
440
|
+
let output = "";
|
|
441
|
+
for (let i = 0; i < numSections; i++) {
|
|
442
|
+
output += split[i];
|
|
443
|
+
if (v[i] !== undefined) {
|
|
444
|
+
const type = types[i];
|
|
445
|
+
if (type === NUMBER_TOKEN) {
|
|
446
|
+
output += sanitize(v[i]);
|
|
447
|
+
}
|
|
448
|
+
else if (type === COLOR_TOKEN) {
|
|
449
|
+
output += color.transform(v[i]);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
output += v[i];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return output;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const convertNumbersToZero = (v) => typeof v === "number" ? 0 : v;
|
|
460
|
+
function getAnimatableNone$1(v) {
|
|
461
|
+
const parsed = parseComplexValue(v);
|
|
462
|
+
const transformer = createTransformer(v);
|
|
463
|
+
return transformer(parsed.map(convertNumbersToZero));
|
|
464
|
+
}
|
|
465
|
+
const complex = {
|
|
466
|
+
test,
|
|
467
|
+
parse: parseComplexValue,
|
|
468
|
+
createTransformer,
|
|
469
|
+
getAnimatableNone: getAnimatableNone$1,
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
// Adapted from https://gist.github.com/mjackson/5311256
|
|
473
|
+
function hueToRgb(p, q, t) {
|
|
474
|
+
if (t < 0)
|
|
475
|
+
t += 1;
|
|
476
|
+
if (t > 1)
|
|
477
|
+
t -= 1;
|
|
478
|
+
if (t < 1 / 6)
|
|
479
|
+
return p + (q - p) * 6 * t;
|
|
480
|
+
if (t < 1 / 2)
|
|
481
|
+
return q;
|
|
482
|
+
if (t < 2 / 3)
|
|
483
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
484
|
+
return p;
|
|
485
|
+
}
|
|
486
|
+
function hslaToRgba({ hue, saturation, lightness, alpha }) {
|
|
487
|
+
hue /= 360;
|
|
488
|
+
saturation /= 100;
|
|
489
|
+
lightness /= 100;
|
|
490
|
+
let red = 0;
|
|
491
|
+
let green = 0;
|
|
492
|
+
let blue = 0;
|
|
493
|
+
if (!saturation) {
|
|
494
|
+
red = green = blue = lightness;
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
const q = lightness < 0.5
|
|
498
|
+
? lightness * (1 + saturation)
|
|
499
|
+
: lightness + saturation - lightness * saturation;
|
|
500
|
+
const p = 2 * lightness - q;
|
|
501
|
+
red = hueToRgb(p, q, hue + 1 / 3);
|
|
502
|
+
green = hueToRgb(p, q, hue);
|
|
503
|
+
blue = hueToRgb(p, q, hue - 1 / 3);
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
red: Math.round(red * 255),
|
|
507
|
+
green: Math.round(green * 255),
|
|
508
|
+
blue: Math.round(blue * 255),
|
|
509
|
+
alpha,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function mixImmediate(a, b) {
|
|
514
|
+
return (p) => (p > 0 ? b : a);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/*
|
|
518
|
+
Value in range from progress
|
|
519
|
+
|
|
520
|
+
Given a lower limit and an upper limit, we return the value within
|
|
521
|
+
that range as expressed by progress (usually a number from 0 to 1)
|
|
522
|
+
|
|
523
|
+
So progress = 0.5 would change
|
|
524
|
+
|
|
525
|
+
from -------- to
|
|
526
|
+
|
|
527
|
+
to
|
|
528
|
+
|
|
529
|
+
from ---- to
|
|
530
|
+
|
|
531
|
+
E.g. from = 10, to = 20, progress = 0.5 => 15
|
|
532
|
+
|
|
533
|
+
@param [number]: Lower limit of range
|
|
534
|
+
@param [number]: Upper limit of range
|
|
535
|
+
@param [number]: The progress between lower and upper limits expressed 0-1
|
|
536
|
+
@return [number]: Value as calculated from progress within range (not limited within range)
|
|
537
|
+
*/
|
|
538
|
+
const mixNumber$1 = (from, to, progress) => {
|
|
539
|
+
return from + (to - from) * progress;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// Linear color space blending
|
|
543
|
+
// Explained https://www.youtube.com/watch?v=LKnqECcg6Gw
|
|
544
|
+
// Demonstrated http://codepen.io/osublake/pen/xGVVaN
|
|
545
|
+
const mixLinearColor = (from, to, v) => {
|
|
546
|
+
const fromExpo = from * from;
|
|
547
|
+
const expo = v * (to * to - fromExpo) + fromExpo;
|
|
548
|
+
return expo < 0 ? 0 : Math.sqrt(expo);
|
|
549
|
+
};
|
|
550
|
+
const colorTypes = [hex, rgba, hsla];
|
|
551
|
+
const getColorType = (v) => colorTypes.find((type) => type.test(v));
|
|
552
|
+
function asRGBA(color) {
|
|
553
|
+
const type = getColorType(color);
|
|
554
|
+
motionUtils.warning(Boolean(type), `'${color}' is not an animatable color. Use the equivalent color code instead.`);
|
|
555
|
+
if (!Boolean(type))
|
|
556
|
+
return false;
|
|
557
|
+
let model = type.parse(color);
|
|
558
|
+
if (type === hsla) {
|
|
559
|
+
// TODO Remove this cast - needed since Motion's stricter typing
|
|
560
|
+
model = hslaToRgba(model);
|
|
561
|
+
}
|
|
562
|
+
return model;
|
|
563
|
+
}
|
|
564
|
+
const mixColor = (from, to) => {
|
|
565
|
+
const fromRGBA = asRGBA(from);
|
|
566
|
+
const toRGBA = asRGBA(to);
|
|
567
|
+
if (!fromRGBA || !toRGBA) {
|
|
568
|
+
return mixImmediate(from, to);
|
|
569
|
+
}
|
|
570
|
+
const blended = { ...fromRGBA };
|
|
571
|
+
return (v) => {
|
|
572
|
+
blended.red = mixLinearColor(fromRGBA.red, toRGBA.red, v);
|
|
573
|
+
blended.green = mixLinearColor(fromRGBA.green, toRGBA.green, v);
|
|
574
|
+
blended.blue = mixLinearColor(fromRGBA.blue, toRGBA.blue, v);
|
|
575
|
+
blended.alpha = mixNumber$1(fromRGBA.alpha, toRGBA.alpha, v);
|
|
576
|
+
return rgba.transform(blended);
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
const invisibleValues = new Set(["none", "hidden"]);
|
|
581
|
+
/**
|
|
582
|
+
* Returns a function that, when provided a progress value between 0 and 1,
|
|
583
|
+
* will return the "none" or "hidden" string only when the progress is that of
|
|
584
|
+
* the origin or target.
|
|
585
|
+
*/
|
|
586
|
+
function mixVisibility(origin, target) {
|
|
587
|
+
if (invisibleValues.has(origin)) {
|
|
588
|
+
return (p) => (p <= 0 ? origin : target);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
return (p) => (p >= 1 ? target : origin);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function mixNumber(a, b) {
|
|
596
|
+
return (p) => mixNumber$1(a, b, p);
|
|
597
|
+
}
|
|
598
|
+
function getMixer(a) {
|
|
599
|
+
if (typeof a === "number") {
|
|
600
|
+
return mixNumber;
|
|
601
|
+
}
|
|
602
|
+
else if (typeof a === "string") {
|
|
603
|
+
return isCSSVariableToken(a)
|
|
604
|
+
? mixImmediate
|
|
605
|
+
: color.test(a)
|
|
606
|
+
? mixColor
|
|
607
|
+
: mixComplex;
|
|
608
|
+
}
|
|
609
|
+
else if (Array.isArray(a)) {
|
|
610
|
+
return mixArray;
|
|
611
|
+
}
|
|
612
|
+
else if (typeof a === "object") {
|
|
613
|
+
return color.test(a) ? mixColor : mixObject;
|
|
614
|
+
}
|
|
615
|
+
return mixImmediate;
|
|
616
|
+
}
|
|
617
|
+
function mixArray(a, b) {
|
|
618
|
+
const output = [...a];
|
|
619
|
+
const numValues = output.length;
|
|
620
|
+
const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
|
|
621
|
+
return (p) => {
|
|
622
|
+
for (let i = 0; i < numValues; i++) {
|
|
623
|
+
output[i] = blendValue[i](p);
|
|
624
|
+
}
|
|
625
|
+
return output;
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function mixObject(a, b) {
|
|
629
|
+
const output = { ...a, ...b };
|
|
630
|
+
const blendValue = {};
|
|
631
|
+
for (const key in output) {
|
|
632
|
+
if (a[key] !== undefined && b[key] !== undefined) {
|
|
633
|
+
blendValue[key] = getMixer(a[key])(a[key], b[key]);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return (v) => {
|
|
637
|
+
for (const key in blendValue) {
|
|
638
|
+
output[key] = blendValue[key](v);
|
|
639
|
+
}
|
|
640
|
+
return output;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function matchOrder(origin, target) {
|
|
644
|
+
const orderedOrigin = [];
|
|
645
|
+
const pointers = { color: 0, var: 0, number: 0 };
|
|
646
|
+
for (let i = 0; i < target.values.length; i++) {
|
|
647
|
+
const type = target.types[i];
|
|
648
|
+
const originIndex = origin.indexes[type][pointers[type]];
|
|
649
|
+
const originValue = origin.values[originIndex] ?? 0;
|
|
650
|
+
orderedOrigin[i] = originValue;
|
|
651
|
+
pointers[type]++;
|
|
652
|
+
}
|
|
653
|
+
return orderedOrigin;
|
|
654
|
+
}
|
|
655
|
+
const mixComplex = (origin, target) => {
|
|
656
|
+
const template = complex.createTransformer(target);
|
|
657
|
+
const originStats = analyseComplexValue(origin);
|
|
658
|
+
const targetStats = analyseComplexValue(target);
|
|
659
|
+
const canInterpolate = originStats.indexes.var.length === targetStats.indexes.var.length &&
|
|
660
|
+
originStats.indexes.color.length === targetStats.indexes.color.length &&
|
|
661
|
+
originStats.indexes.number.length >= targetStats.indexes.number.length;
|
|
662
|
+
if (canInterpolate) {
|
|
663
|
+
if ((invisibleValues.has(origin) &&
|
|
664
|
+
!targetStats.values.length) ||
|
|
665
|
+
(invisibleValues.has(target) &&
|
|
666
|
+
!originStats.values.length)) {
|
|
667
|
+
return mixVisibility(origin, target);
|
|
668
|
+
}
|
|
669
|
+
return motionUtils.pipe(mixArray(matchOrder(originStats, targetStats), targetStats.values), template);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
motionUtils.warning(true, `Complex values '${origin}' and '${target}' too different to mix. Ensure all colors are of the same type, and that each contains the same quantity of number and color values. Falling back to instant transition.`);
|
|
673
|
+
return mixImmediate(origin, target);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
function mix(from, to, p) {
|
|
678
|
+
if (typeof from === "number" &&
|
|
679
|
+
typeof to === "number" &&
|
|
680
|
+
typeof p === "number") {
|
|
681
|
+
return mixNumber$1(from, to, p);
|
|
682
|
+
}
|
|
683
|
+
const mixer = getMixer(from);
|
|
684
|
+
return mixer(from, to);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const frameloopDriver = (update) => {
|
|
688
|
+
const passTimestamp = ({ timestamp }) => update(timestamp);
|
|
689
|
+
return {
|
|
690
|
+
start: () => frame.update(passTimestamp, true),
|
|
691
|
+
stop: () => cancelFrame(passTimestamp),
|
|
692
|
+
/**
|
|
693
|
+
* If we're processing this frame we can use the
|
|
694
|
+
* framelocked timestamp to keep things in sync.
|
|
695
|
+
*/
|
|
696
|
+
now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),
|
|
697
|
+
};
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
const generateLinearEasing = (easing, duration, // as milliseconds
|
|
701
|
+
resolution = 10 // as milliseconds
|
|
702
|
+
) => {
|
|
703
|
+
let points = "";
|
|
704
|
+
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
705
|
+
for (let i = 0; i < numPoints; i++) {
|
|
706
|
+
points += easing(i / (numPoints - 1)) + ", ";
|
|
707
|
+
}
|
|
708
|
+
return `linear(${points.substring(0, points.length - 2)})`;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Implement a practical max duration for keyframe generation
|
|
713
|
+
* to prevent infinite loops
|
|
714
|
+
*/
|
|
715
|
+
const maxGeneratorDuration = 20000;
|
|
716
|
+
function calcGeneratorDuration(generator) {
|
|
717
|
+
let duration = 0;
|
|
718
|
+
const timeStep = 50;
|
|
719
|
+
let state = generator.next(duration);
|
|
720
|
+
while (!state.done && duration < maxGeneratorDuration) {
|
|
721
|
+
duration += timeStep;
|
|
722
|
+
state = generator.next(duration);
|
|
723
|
+
}
|
|
724
|
+
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Create a progress => progress easing function from a generator.
|
|
729
|
+
*/
|
|
730
|
+
function createGeneratorEasing(options, scale = 100, createGenerator) {
|
|
731
|
+
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
732
|
+
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
733
|
+
return {
|
|
734
|
+
type: "keyframes",
|
|
735
|
+
ease: (progress) => {
|
|
736
|
+
return generator.next(duration * progress).value / scale;
|
|
737
|
+
},
|
|
738
|
+
duration: motionUtils.millisecondsToSeconds(duration),
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const velocitySampleDuration = 5; // ms
|
|
743
|
+
function calcGeneratorVelocity(resolveValue, t, current) {
|
|
744
|
+
const prevT = Math.max(t - velocitySampleDuration, 0);
|
|
745
|
+
return motionUtils.velocityPerSecond(current - resolveValue(prevT), t - prevT);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const springDefaults = {
|
|
749
|
+
// Default spring physics
|
|
750
|
+
stiffness: 100,
|
|
751
|
+
damping: 10,
|
|
752
|
+
mass: 1.0,
|
|
753
|
+
velocity: 0.0,
|
|
754
|
+
// Default duration/bounce-based options
|
|
755
|
+
duration: 800, // in ms
|
|
756
|
+
bounce: 0.3,
|
|
757
|
+
visualDuration: 0.3, // in seconds
|
|
758
|
+
// Rest thresholds
|
|
759
|
+
restSpeed: {
|
|
760
|
+
granular: 0.01,
|
|
761
|
+
default: 2,
|
|
762
|
+
},
|
|
763
|
+
restDelta: {
|
|
764
|
+
granular: 0.005,
|
|
765
|
+
default: 0.5,
|
|
766
|
+
},
|
|
767
|
+
// Limits
|
|
768
|
+
minDuration: 0.01, // in seconds
|
|
769
|
+
maxDuration: 10.0, // in seconds
|
|
770
|
+
minDamping: 0.05,
|
|
771
|
+
maxDamping: 1,
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
const safeMin = 0.001;
|
|
775
|
+
function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
|
|
776
|
+
let envelope;
|
|
777
|
+
let derivative;
|
|
778
|
+
motionUtils.warning(duration <= motionUtils.secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less");
|
|
779
|
+
let dampingRatio = 1 - bounce;
|
|
780
|
+
/**
|
|
781
|
+
* Restrict dampingRatio and duration to within acceptable ranges.
|
|
782
|
+
*/
|
|
783
|
+
dampingRatio = motionUtils.clamp(springDefaults.minDamping, springDefaults.maxDamping, dampingRatio);
|
|
784
|
+
duration = motionUtils.clamp(springDefaults.minDuration, springDefaults.maxDuration, motionUtils.millisecondsToSeconds(duration));
|
|
785
|
+
if (dampingRatio < 1) {
|
|
786
|
+
/**
|
|
787
|
+
* Underdamped spring
|
|
788
|
+
*/
|
|
789
|
+
envelope = (undampedFreq) => {
|
|
790
|
+
const exponentialDecay = undampedFreq * dampingRatio;
|
|
791
|
+
const delta = exponentialDecay * duration;
|
|
792
|
+
const a = exponentialDecay - velocity;
|
|
793
|
+
const b = calcAngularFreq(undampedFreq, dampingRatio);
|
|
794
|
+
const c = Math.exp(-delta);
|
|
795
|
+
return safeMin - (a / b) * c;
|
|
796
|
+
};
|
|
797
|
+
derivative = (undampedFreq) => {
|
|
798
|
+
const exponentialDecay = undampedFreq * dampingRatio;
|
|
799
|
+
const delta = exponentialDecay * duration;
|
|
800
|
+
const d = delta * velocity + velocity;
|
|
801
|
+
const e = Math.pow(dampingRatio, 2) * Math.pow(undampedFreq, 2) * duration;
|
|
802
|
+
const f = Math.exp(-delta);
|
|
803
|
+
const g = calcAngularFreq(Math.pow(undampedFreq, 2), dampingRatio);
|
|
804
|
+
const factor = -envelope(undampedFreq) + safeMin > 0 ? -1 : 1;
|
|
805
|
+
return (factor * ((d - e) * f)) / g;
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
/**
|
|
810
|
+
* Critically-damped spring
|
|
811
|
+
*/
|
|
812
|
+
envelope = (undampedFreq) => {
|
|
813
|
+
const a = Math.exp(-undampedFreq * duration);
|
|
814
|
+
const b = (undampedFreq - velocity) * duration + 1;
|
|
815
|
+
return -safeMin + a * b;
|
|
816
|
+
};
|
|
817
|
+
derivative = (undampedFreq) => {
|
|
818
|
+
const a = Math.exp(-undampedFreq * duration);
|
|
819
|
+
const b = (velocity - undampedFreq) * (duration * duration);
|
|
820
|
+
return a * b;
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
const initialGuess = 5 / duration;
|
|
824
|
+
const undampedFreq = approximateRoot(envelope, derivative, initialGuess);
|
|
825
|
+
duration = motionUtils.secondsToMilliseconds(duration);
|
|
826
|
+
if (isNaN(undampedFreq)) {
|
|
827
|
+
return {
|
|
828
|
+
stiffness: springDefaults.stiffness,
|
|
829
|
+
damping: springDefaults.damping,
|
|
830
|
+
duration,
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
const stiffness = Math.pow(undampedFreq, 2) * mass;
|
|
835
|
+
return {
|
|
836
|
+
stiffness,
|
|
837
|
+
damping: dampingRatio * 2 * Math.sqrt(mass * stiffness),
|
|
838
|
+
duration,
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
const rootIterations = 12;
|
|
843
|
+
function approximateRoot(envelope, derivative, initialGuess) {
|
|
844
|
+
let result = initialGuess;
|
|
845
|
+
for (let i = 1; i < rootIterations; i++) {
|
|
846
|
+
result = result - envelope(result) / derivative(result);
|
|
847
|
+
}
|
|
848
|
+
return result;
|
|
849
|
+
}
|
|
850
|
+
function calcAngularFreq(undampedFreq, dampingRatio) {
|
|
851
|
+
return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const durationKeys = ["duration", "bounce"];
|
|
855
|
+
const physicsKeys = ["stiffness", "damping", "mass"];
|
|
856
|
+
function isSpringType(options, keys) {
|
|
857
|
+
return keys.some((key) => options[key] !== undefined);
|
|
858
|
+
}
|
|
859
|
+
function getSpringOptions(options) {
|
|
860
|
+
let springOptions = {
|
|
861
|
+
velocity: springDefaults.velocity,
|
|
862
|
+
stiffness: springDefaults.stiffness,
|
|
863
|
+
damping: springDefaults.damping,
|
|
864
|
+
mass: springDefaults.mass,
|
|
865
|
+
isResolvedFromDuration: false,
|
|
866
|
+
...options,
|
|
867
|
+
};
|
|
868
|
+
// stiffness/damping/mass overrides duration/bounce
|
|
869
|
+
if (!isSpringType(options, physicsKeys) &&
|
|
870
|
+
isSpringType(options, durationKeys)) {
|
|
871
|
+
if (options.visualDuration) {
|
|
872
|
+
const visualDuration = options.visualDuration;
|
|
873
|
+
const root = (2 * Math.PI) / (visualDuration * 1.2);
|
|
874
|
+
const stiffness = root * root;
|
|
875
|
+
const damping = 2 *
|
|
876
|
+
motionUtils.clamp(0.05, 1, 1 - (options.bounce || 0)) *
|
|
877
|
+
Math.sqrt(stiffness);
|
|
878
|
+
springOptions = {
|
|
879
|
+
...springOptions,
|
|
880
|
+
mass: springDefaults.mass,
|
|
881
|
+
stiffness,
|
|
882
|
+
damping,
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
const derived = findSpring(options);
|
|
887
|
+
springOptions = {
|
|
888
|
+
...springOptions,
|
|
889
|
+
...derived,
|
|
890
|
+
mass: springDefaults.mass,
|
|
891
|
+
};
|
|
892
|
+
springOptions.isResolvedFromDuration = true;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return springOptions;
|
|
896
|
+
}
|
|
897
|
+
function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce = springDefaults.bounce) {
|
|
898
|
+
const options = typeof optionsOrVisualDuration !== "object"
|
|
899
|
+
? {
|
|
900
|
+
visualDuration: optionsOrVisualDuration,
|
|
901
|
+
keyframes: [0, 1],
|
|
902
|
+
bounce,
|
|
903
|
+
}
|
|
904
|
+
: optionsOrVisualDuration;
|
|
905
|
+
let { restSpeed, restDelta } = options;
|
|
906
|
+
const origin = options.keyframes[0];
|
|
907
|
+
const target = options.keyframes[options.keyframes.length - 1];
|
|
908
|
+
/**
|
|
909
|
+
* This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
|
|
910
|
+
* to reduce GC during animation.
|
|
911
|
+
*/
|
|
912
|
+
const state = { done: false, value: origin };
|
|
913
|
+
const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, } = getSpringOptions({
|
|
914
|
+
...options,
|
|
915
|
+
velocity: -motionUtils.millisecondsToSeconds(options.velocity || 0),
|
|
916
|
+
});
|
|
917
|
+
const initialVelocity = velocity || 0.0;
|
|
918
|
+
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
|
|
919
|
+
const initialDelta = target - origin;
|
|
920
|
+
const undampedAngularFreq = motionUtils.millisecondsToSeconds(Math.sqrt(stiffness / mass));
|
|
921
|
+
/**
|
|
922
|
+
* If we're working on a granular scale, use smaller defaults for determining
|
|
923
|
+
* when the spring is finished.
|
|
924
|
+
*
|
|
925
|
+
* These defaults have been selected emprically based on what strikes a good
|
|
926
|
+
* ratio between feeling good and finishing as soon as changes are imperceptible.
|
|
927
|
+
*/
|
|
928
|
+
const isGranularScale = Math.abs(initialDelta) < 5;
|
|
929
|
+
restSpeed || (restSpeed = isGranularScale
|
|
930
|
+
? springDefaults.restSpeed.granular
|
|
931
|
+
: springDefaults.restSpeed.default);
|
|
932
|
+
restDelta || (restDelta = isGranularScale
|
|
933
|
+
? springDefaults.restDelta.granular
|
|
934
|
+
: springDefaults.restDelta.default);
|
|
935
|
+
let resolveSpring;
|
|
936
|
+
if (dampingRatio < 1) {
|
|
937
|
+
const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
|
|
938
|
+
// Underdamped spring
|
|
939
|
+
resolveSpring = (t) => {
|
|
940
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
941
|
+
return (target -
|
|
942
|
+
envelope *
|
|
943
|
+
(((initialVelocity +
|
|
944
|
+
dampingRatio * undampedAngularFreq * initialDelta) /
|
|
945
|
+
angularFreq) *
|
|
946
|
+
Math.sin(angularFreq * t) +
|
|
947
|
+
initialDelta * Math.cos(angularFreq * t)));
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
else if (dampingRatio === 1) {
|
|
951
|
+
// Critically damped spring
|
|
952
|
+
resolveSpring = (t) => target -
|
|
953
|
+
Math.exp(-undampedAngularFreq * t) *
|
|
954
|
+
(initialDelta +
|
|
955
|
+
(initialVelocity + undampedAngularFreq * initialDelta) * t);
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
// Overdamped spring
|
|
959
|
+
const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
|
|
960
|
+
resolveSpring = (t) => {
|
|
961
|
+
const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
|
|
962
|
+
// When performing sinh or cosh values can hit Infinity so we cap them here
|
|
963
|
+
const freqForT = Math.min(dampedAngularFreq * t, 300);
|
|
964
|
+
return (target -
|
|
965
|
+
(envelope *
|
|
966
|
+
((initialVelocity +
|
|
967
|
+
dampingRatio * undampedAngularFreq * initialDelta) *
|
|
968
|
+
Math.sinh(freqForT) +
|
|
969
|
+
dampedAngularFreq *
|
|
970
|
+
initialDelta *
|
|
971
|
+
Math.cosh(freqForT))) /
|
|
972
|
+
dampedAngularFreq);
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
const generator = {
|
|
976
|
+
calculatedDuration: isResolvedFromDuration ? duration || null : null,
|
|
977
|
+
next: (t) => {
|
|
978
|
+
const current = resolveSpring(t);
|
|
979
|
+
if (!isResolvedFromDuration) {
|
|
980
|
+
let currentVelocity = 0.0;
|
|
981
|
+
/**
|
|
982
|
+
* We only need to calculate velocity for under-damped springs
|
|
983
|
+
* as over- and critically-damped springs can't overshoot, so
|
|
984
|
+
* checking only for displacement is enough.
|
|
985
|
+
*/
|
|
986
|
+
if (dampingRatio < 1) {
|
|
987
|
+
currentVelocity =
|
|
988
|
+
t === 0
|
|
989
|
+
? motionUtils.secondsToMilliseconds(initialVelocity)
|
|
990
|
+
: calcGeneratorVelocity(resolveSpring, t, current);
|
|
991
|
+
}
|
|
992
|
+
const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
|
|
993
|
+
const isBelowDisplacementThreshold = Math.abs(target - current) <= restDelta;
|
|
994
|
+
state.done =
|
|
995
|
+
isBelowVelocityThreshold && isBelowDisplacementThreshold;
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
state.done = t >= duration;
|
|
999
|
+
}
|
|
1000
|
+
state.value = state.done ? target : current;
|
|
1001
|
+
return state;
|
|
1002
|
+
},
|
|
1003
|
+
toString: () => {
|
|
1004
|
+
const calculatedDuration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
1005
|
+
const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
|
|
1006
|
+
return calculatedDuration + "ms " + easing;
|
|
1007
|
+
},
|
|
1008
|
+
toTransition: () => { },
|
|
1009
|
+
};
|
|
1010
|
+
return generator;
|
|
1011
|
+
}
|
|
1012
|
+
spring.applyToOptions = (options) => {
|
|
1013
|
+
const generatorOptions = createGeneratorEasing(options, 100, spring);
|
|
1014
|
+
options.ease = generatorOptions.ease;
|
|
1015
|
+
options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
|
|
1016
|
+
options.type = "keyframes";
|
|
1017
|
+
return options;
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
function inertia({ keyframes, velocity = 0.0, power = 0.8, timeConstant = 325, bounceDamping = 10, bounceStiffness = 500, modifyTarget, min, max, restDelta = 0.5, restSpeed, }) {
|
|
1021
|
+
const origin = keyframes[0];
|
|
1022
|
+
const state = {
|
|
1023
|
+
done: false,
|
|
1024
|
+
value: origin,
|
|
1025
|
+
};
|
|
1026
|
+
const isOutOfBounds = (v) => (min !== undefined && v < min) || (max !== undefined && v > max);
|
|
1027
|
+
const nearestBoundary = (v) => {
|
|
1028
|
+
if (min === undefined)
|
|
1029
|
+
return max;
|
|
1030
|
+
if (max === undefined)
|
|
1031
|
+
return min;
|
|
1032
|
+
return Math.abs(min - v) < Math.abs(max - v) ? min : max;
|
|
1033
|
+
};
|
|
1034
|
+
let amplitude = power * velocity;
|
|
1035
|
+
const ideal = origin + amplitude;
|
|
1036
|
+
const target = modifyTarget === undefined ? ideal : modifyTarget(ideal);
|
|
1037
|
+
/**
|
|
1038
|
+
* If the target has changed we need to re-calculate the amplitude, otherwise
|
|
1039
|
+
* the animation will start from the wrong position.
|
|
1040
|
+
*/
|
|
1041
|
+
if (target !== ideal)
|
|
1042
|
+
amplitude = target - origin;
|
|
1043
|
+
const calcDelta = (t) => -amplitude * Math.exp(-t / timeConstant);
|
|
1044
|
+
const calcLatest = (t) => target + calcDelta(t);
|
|
1045
|
+
const applyFriction = (t) => {
|
|
1046
|
+
const delta = calcDelta(t);
|
|
1047
|
+
const latest = calcLatest(t);
|
|
1048
|
+
state.done = Math.abs(delta) <= restDelta;
|
|
1049
|
+
state.value = state.done ? target : latest;
|
|
1050
|
+
};
|
|
1051
|
+
/**
|
|
1052
|
+
* Ideally this would resolve for t in a stateless way, we could
|
|
1053
|
+
* do that by always precalculating the animation but as we know
|
|
1054
|
+
* this will be done anyway we can assume that spring will
|
|
1055
|
+
* be discovered during that.
|
|
1056
|
+
*/
|
|
1057
|
+
let timeReachedBoundary;
|
|
1058
|
+
let spring$1;
|
|
1059
|
+
const checkCatchBoundary = (t) => {
|
|
1060
|
+
if (!isOutOfBounds(state.value))
|
|
1061
|
+
return;
|
|
1062
|
+
timeReachedBoundary = t;
|
|
1063
|
+
spring$1 = spring({
|
|
1064
|
+
keyframes: [state.value, nearestBoundary(state.value)],
|
|
1065
|
+
velocity: calcGeneratorVelocity(calcLatest, t, state.value), // TODO: This should be passing * 1000
|
|
1066
|
+
damping: bounceDamping,
|
|
1067
|
+
stiffness: bounceStiffness,
|
|
1068
|
+
restDelta,
|
|
1069
|
+
restSpeed,
|
|
1070
|
+
});
|
|
1071
|
+
};
|
|
1072
|
+
checkCatchBoundary(0);
|
|
1073
|
+
return {
|
|
1074
|
+
calculatedDuration: null,
|
|
1075
|
+
next: (t) => {
|
|
1076
|
+
/**
|
|
1077
|
+
* We need to resolve the friction to figure out if we need a
|
|
1078
|
+
* spring but we don't want to do this twice per frame. So here
|
|
1079
|
+
* we flag if we updated for this frame and later if we did
|
|
1080
|
+
* we can skip doing it again.
|
|
1081
|
+
*/
|
|
1082
|
+
let hasUpdatedFrame = false;
|
|
1083
|
+
if (!spring$1 && timeReachedBoundary === undefined) {
|
|
1084
|
+
hasUpdatedFrame = true;
|
|
1085
|
+
applyFriction(t);
|
|
1086
|
+
checkCatchBoundary(t);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* If we have a spring and the provided t is beyond the moment the friction
|
|
1090
|
+
* animation crossed the min/max boundary, use the spring.
|
|
1091
|
+
*/
|
|
1092
|
+
if (timeReachedBoundary !== undefined && t >= timeReachedBoundary) {
|
|
1093
|
+
return spring$1.next(t - timeReachedBoundary);
|
|
1094
|
+
}
|
|
1095
|
+
else {
|
|
1096
|
+
!hasUpdatedFrame && applyFriction(t);
|
|
1097
|
+
return state;
|
|
1098
|
+
}
|
|
1099
|
+
},
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
8
1102
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1103
|
+
function createMixers(output, ease, customMixer) {
|
|
1104
|
+
const mixers = [];
|
|
1105
|
+
const mixerFactory = customMixer || motionUtils.MotionGlobalConfig.mix || mix;
|
|
1106
|
+
const numMixers = output.length - 1;
|
|
1107
|
+
for (let i = 0; i < numMixers; i++) {
|
|
1108
|
+
let mixer = mixerFactory(output[i], output[i + 1]);
|
|
1109
|
+
if (ease) {
|
|
1110
|
+
const easingFunction = Array.isArray(ease) ? ease[i] || motionUtils.noop : ease;
|
|
1111
|
+
mixer = motionUtils.pipe(easingFunction, mixer);
|
|
1112
|
+
}
|
|
1113
|
+
mixers.push(mixer);
|
|
1114
|
+
}
|
|
1115
|
+
return mixers;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Create a function that maps from a numerical input array to a generic output array.
|
|
1119
|
+
*
|
|
1120
|
+
* Accepts:
|
|
1121
|
+
* - Numbers
|
|
1122
|
+
* - Colors (hex, hsl, hsla, rgb, rgba)
|
|
1123
|
+
* - Complex (combinations of one or more numbers or strings)
|
|
1124
|
+
*
|
|
1125
|
+
* ```jsx
|
|
1126
|
+
* const mixColor = interpolate([0, 1], ['#fff', '#000'])
|
|
1127
|
+
*
|
|
1128
|
+
* mixColor(0.5) // 'rgba(128, 128, 128, 1)'
|
|
1129
|
+
* ```
|
|
1130
|
+
*
|
|
1131
|
+
* TODO Revist this approach once we've moved to data models for values,
|
|
1132
|
+
* probably not needed to pregenerate mixer functions.
|
|
1133
|
+
*
|
|
1134
|
+
* @public
|
|
1135
|
+
*/
|
|
1136
|
+
function interpolate(input, output, { clamp: isClamp = true, ease, mixer } = {}) {
|
|
1137
|
+
const inputLength = input.length;
|
|
1138
|
+
motionUtils.invariant(inputLength === output.length, "Both input and output ranges must be the same length");
|
|
1139
|
+
/**
|
|
1140
|
+
* If we're only provided a single input, we can just make a function
|
|
1141
|
+
* that returns the output.
|
|
1142
|
+
*/
|
|
1143
|
+
if (inputLength === 1)
|
|
1144
|
+
return () => output[0];
|
|
1145
|
+
if (inputLength === 2 && output[0] === output[1])
|
|
1146
|
+
return () => output[1];
|
|
1147
|
+
const isZeroDeltaRange = input[0] === input[1];
|
|
1148
|
+
// If input runs highest -> lowest, reverse both arrays
|
|
1149
|
+
if (input[0] > input[inputLength - 1]) {
|
|
1150
|
+
input = [...input].reverse();
|
|
1151
|
+
output = [...output].reverse();
|
|
1152
|
+
}
|
|
1153
|
+
const mixers = createMixers(output, ease, mixer);
|
|
1154
|
+
const numMixers = mixers.length;
|
|
1155
|
+
const interpolator = (v) => {
|
|
1156
|
+
if (isZeroDeltaRange && v < input[0])
|
|
1157
|
+
return output[0];
|
|
1158
|
+
let i = 0;
|
|
1159
|
+
if (numMixers > 1) {
|
|
1160
|
+
for (; i < input.length - 2; i++) {
|
|
1161
|
+
if (v < input[i + 1])
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
const progressInRange = motionUtils.progress(input[i], input[i + 1], v);
|
|
1166
|
+
return mixers[i](progressInRange);
|
|
1167
|
+
};
|
|
1168
|
+
return isClamp
|
|
1169
|
+
? (v) => interpolator(motionUtils.clamp(input[0], input[inputLength - 1], v))
|
|
1170
|
+
: interpolator;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function fillOffset(offset, remaining) {
|
|
1174
|
+
const min = offset[offset.length - 1];
|
|
1175
|
+
for (let i = 1; i <= remaining; i++) {
|
|
1176
|
+
const offsetProgress = motionUtils.progress(0, remaining, i);
|
|
1177
|
+
offset.push(mixNumber$1(min, 1, offsetProgress));
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function defaultOffset(arr) {
|
|
1182
|
+
const offset = [0];
|
|
1183
|
+
fillOffset(offset, arr.length - 1);
|
|
1184
|
+
return offset;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function convertOffsetToTimes(offset, duration) {
|
|
1188
|
+
return offset.map((o) => o * duration);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function defaultEasing(values, easing) {
|
|
1192
|
+
return values.map(() => easing || motionUtils.easeInOut).splice(0, values.length - 1);
|
|
1193
|
+
}
|
|
1194
|
+
function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "easeInOut", }) {
|
|
1195
|
+
/**
|
|
1196
|
+
* Easing functions can be externally defined as strings. Here we convert them
|
|
1197
|
+
* into actual functions.
|
|
1198
|
+
*/
|
|
1199
|
+
const easingFunctions = motionUtils.isEasingArray(ease)
|
|
1200
|
+
? ease.map(motionUtils.easingDefinitionToFunction)
|
|
1201
|
+
: motionUtils.easingDefinitionToFunction(ease);
|
|
1202
|
+
/**
|
|
1203
|
+
* This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
|
|
1204
|
+
* to reduce GC during animation.
|
|
1205
|
+
*/
|
|
1206
|
+
const state = {
|
|
1207
|
+
done: false,
|
|
1208
|
+
value: keyframeValues[0],
|
|
1209
|
+
};
|
|
1210
|
+
/**
|
|
1211
|
+
* Create a times array based on the provided 0-1 offsets
|
|
1212
|
+
*/
|
|
1213
|
+
const absoluteTimes = convertOffsetToTimes(
|
|
1214
|
+
// Only use the provided offsets if they're the correct length
|
|
1215
|
+
// TODO Maybe we should warn here if there's a length mismatch
|
|
1216
|
+
times && times.length === keyframeValues.length
|
|
1217
|
+
? times
|
|
1218
|
+
: defaultOffset(keyframeValues), duration);
|
|
1219
|
+
const mapTimeToKeyframe = interpolate(absoluteTimes, keyframeValues, {
|
|
1220
|
+
ease: Array.isArray(easingFunctions)
|
|
1221
|
+
? easingFunctions
|
|
1222
|
+
: defaultEasing(keyframeValues, easingFunctions),
|
|
1223
|
+
});
|
|
1224
|
+
return {
|
|
1225
|
+
calculatedDuration: duration,
|
|
1226
|
+
next: (t) => {
|
|
1227
|
+
state.value = mapTimeToKeyframe(t);
|
|
1228
|
+
state.done = t >= duration;
|
|
1229
|
+
return state;
|
|
1230
|
+
},
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
const isNotNull = (value) => value !== null;
|
|
1235
|
+
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
1236
|
+
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
1237
|
+
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
1238
|
+
const index = useFirstKeyframe ? 0 : resolvedKeyframes.length - 1;
|
|
1239
|
+
return !index || finalKeyframe === undefined
|
|
1240
|
+
? resolvedKeyframes[index]
|
|
1241
|
+
: finalKeyframe;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
const transitionTypeMap = {
|
|
1245
|
+
decay: inertia,
|
|
1246
|
+
inertia,
|
|
1247
|
+
tween: keyframes,
|
|
1248
|
+
keyframes: keyframes,
|
|
1249
|
+
spring,
|
|
1250
|
+
};
|
|
1251
|
+
function replaceTransitionType(transition) {
|
|
1252
|
+
if (typeof transition.type === "string") {
|
|
1253
|
+
transition.type = transitionTypeMap[transition.type];
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
class WithPromise {
|
|
1258
|
+
constructor() {
|
|
1259
|
+
this.count = 0;
|
|
1260
|
+
this.updateFinished();
|
|
14
1261
|
}
|
|
15
1262
|
get finished() {
|
|
16
|
-
return
|
|
1263
|
+
return this._finished;
|
|
1264
|
+
}
|
|
1265
|
+
updateFinished() {
|
|
1266
|
+
this.count++;
|
|
1267
|
+
this._finished = new Promise((resolve) => {
|
|
1268
|
+
this.resolve = resolve;
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
notifyFinished() {
|
|
1272
|
+
this.resolve();
|
|
17
1273
|
}
|
|
18
1274
|
/**
|
|
19
|
-
*
|
|
1275
|
+
* Allows the animation to be awaited.
|
|
1276
|
+
*
|
|
1277
|
+
* @deprecated Use `finished` instead.
|
|
20
1278
|
*/
|
|
21
|
-
|
|
22
|
-
return this.
|
|
1279
|
+
then(onResolve, onReject) {
|
|
1280
|
+
return this.finished.then(onResolve, onReject);
|
|
23
1281
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
const percentToProgress = (percent) => percent / 100;
|
|
1285
|
+
class JSAnimation extends WithPromise {
|
|
1286
|
+
constructor(options) {
|
|
1287
|
+
super();
|
|
1288
|
+
this.state = "idle";
|
|
1289
|
+
this.startTime = null;
|
|
1290
|
+
this.isStopped = false;
|
|
1291
|
+
/**
|
|
1292
|
+
* The current time of the animation.
|
|
1293
|
+
*/
|
|
1294
|
+
this.currentTime = 0;
|
|
1295
|
+
/**
|
|
1296
|
+
* The time at which the animation was paused.
|
|
1297
|
+
*/
|
|
1298
|
+
this.holdTime = null;
|
|
1299
|
+
/**
|
|
1300
|
+
* Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed.
|
|
1301
|
+
*/
|
|
1302
|
+
this.playbackSpeed = 1;
|
|
1303
|
+
/**
|
|
1304
|
+
* This method is bound to the instance to fix a pattern where
|
|
1305
|
+
* animation.stop is returned as a reference from a useEffect.
|
|
1306
|
+
*/
|
|
1307
|
+
this.stop = () => {
|
|
1308
|
+
const { motionValue } = this.options;
|
|
1309
|
+
if (motionValue && motionValue.updatedAt !== time.now()) {
|
|
1310
|
+
this.tick(time.now());
|
|
1311
|
+
}
|
|
1312
|
+
this.isStopped = true;
|
|
1313
|
+
if (this.state === "idle")
|
|
1314
|
+
return;
|
|
1315
|
+
this.teardown();
|
|
1316
|
+
const { onStop } = this.options;
|
|
1317
|
+
onStop && onStop();
|
|
1318
|
+
};
|
|
1319
|
+
activeAnimations.mainThread++;
|
|
1320
|
+
this.options = options;
|
|
1321
|
+
this.initAnimation();
|
|
1322
|
+
this.play();
|
|
1323
|
+
if (options.autoplay === false)
|
|
1324
|
+
this.pause();
|
|
1325
|
+
}
|
|
1326
|
+
initAnimation() {
|
|
1327
|
+
const { options } = this;
|
|
1328
|
+
replaceTransitionType(options);
|
|
1329
|
+
const { type = keyframes, repeat = 0, repeatDelay = 0, repeatType, velocity = 0, } = options;
|
|
1330
|
+
let { keyframes: keyframes$1 } = options;
|
|
1331
|
+
const generatorFactory = type || keyframes;
|
|
1332
|
+
if (generatorFactory !== keyframes) {
|
|
1333
|
+
motionUtils.invariant(keyframes$1.length <= 2, `Only two keyframes currently supported with spring and inertia animations. Trying to animate ${keyframes$1}`);
|
|
1334
|
+
}
|
|
1335
|
+
if (generatorFactory !== keyframes &&
|
|
1336
|
+
typeof keyframes$1[0] !== "number") {
|
|
1337
|
+
this.mixKeyframes = motionUtils.pipe(percentToProgress, mix(keyframes$1[0], keyframes$1[1]));
|
|
1338
|
+
keyframes$1 = [0, 100];
|
|
1339
|
+
}
|
|
1340
|
+
const generator = generatorFactory({ ...options, keyframes: keyframes$1 });
|
|
1341
|
+
/**
|
|
1342
|
+
* If we have a mirror repeat type we need to create a second generator that outputs the
|
|
1343
|
+
* mirrored (not reversed) animation and later ping pong between the two generators.
|
|
1344
|
+
*/
|
|
1345
|
+
if (repeatType === "mirror") {
|
|
1346
|
+
this.mirroredGenerator = generatorFactory({
|
|
1347
|
+
...options,
|
|
1348
|
+
keyframes: [...keyframes$1].reverse(),
|
|
1349
|
+
velocity: -velocity,
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* If duration is undefined and we have repeat options,
|
|
1354
|
+
* we need to calculate a duration from the generator.
|
|
1355
|
+
*
|
|
1356
|
+
* We set it to the generator itself to cache the duration.
|
|
1357
|
+
* Any timeline resolver will need to have already precalculated
|
|
1358
|
+
* the duration by this step.
|
|
1359
|
+
*/
|
|
1360
|
+
if (generator.calculatedDuration === null) {
|
|
1361
|
+
generator.calculatedDuration = calcGeneratorDuration(generator);
|
|
1362
|
+
}
|
|
1363
|
+
const { calculatedDuration } = generator;
|
|
1364
|
+
this.calculatedDuration = calculatedDuration;
|
|
1365
|
+
this.resolvedDuration = calculatedDuration + repeatDelay;
|
|
1366
|
+
this.totalDuration = this.resolvedDuration * (repeat + 1) - repeatDelay;
|
|
1367
|
+
this.generator = generator;
|
|
1368
|
+
}
|
|
1369
|
+
updateTime(timestamp) {
|
|
1370
|
+
const animationTime = Math.round(timestamp - this.startTime) * this.playbackSpeed;
|
|
1371
|
+
// Update currentTime
|
|
1372
|
+
if (this.holdTime !== null) {
|
|
1373
|
+
this.currentTime = this.holdTime;
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
// Rounding the time because floating point arithmetic is not always accurate, e.g. 3000.367 - 1000.367 =
|
|
1377
|
+
// 2000.0000000000002. This is a problem when we are comparing the currentTime with the duration, for
|
|
1378
|
+
// example.
|
|
1379
|
+
this.currentTime = animationTime;
|
|
27
1380
|
}
|
|
28
1381
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
1382
|
+
tick(timestamp, sample = false) {
|
|
1383
|
+
const { generator, totalDuration, mixKeyframes, mirroredGenerator, resolvedDuration, calculatedDuration, } = this;
|
|
1384
|
+
if (this.startTime === null)
|
|
1385
|
+
return generator.next(0);
|
|
1386
|
+
const { delay = 0, keyframes, repeat, repeatType, repeatDelay, type, onUpdate, finalKeyframe, } = this.options;
|
|
1387
|
+
/**
|
|
1388
|
+
* requestAnimationFrame timestamps can come through as lower than
|
|
1389
|
+
* the startTime as set by performance.now(). Here we prevent this,
|
|
1390
|
+
* though in the future it could be possible to make setting startTime
|
|
1391
|
+
* a pending operation that gets resolved here.
|
|
1392
|
+
*/
|
|
1393
|
+
if (this.speed > 0) {
|
|
1394
|
+
this.startTime = Math.min(this.startTime, timestamp);
|
|
1395
|
+
}
|
|
1396
|
+
else if (this.speed < 0) {
|
|
1397
|
+
this.startTime = Math.min(timestamp - totalDuration / this.speed, this.startTime);
|
|
1398
|
+
}
|
|
1399
|
+
if (sample) {
|
|
1400
|
+
this.currentTime = timestamp;
|
|
1401
|
+
}
|
|
1402
|
+
else {
|
|
1403
|
+
this.updateTime(timestamp);
|
|
1404
|
+
}
|
|
1405
|
+
// Rebase on delay
|
|
1406
|
+
const timeWithoutDelay = this.currentTime - delay * (this.playbackSpeed >= 0 ? 1 : -1);
|
|
1407
|
+
const isInDelayPhase = this.playbackSpeed >= 0
|
|
1408
|
+
? timeWithoutDelay < 0
|
|
1409
|
+
: timeWithoutDelay > totalDuration;
|
|
1410
|
+
this.currentTime = Math.max(timeWithoutDelay, 0);
|
|
1411
|
+
// If this animation has finished, set the current time to the total duration.
|
|
1412
|
+
if (this.state === "finished" && this.holdTime === null) {
|
|
1413
|
+
this.currentTime = totalDuration;
|
|
1414
|
+
}
|
|
1415
|
+
let elapsed = this.currentTime;
|
|
1416
|
+
let frameGenerator = generator;
|
|
1417
|
+
if (repeat) {
|
|
1418
|
+
/**
|
|
1419
|
+
* Get the current progress (0-1) of the animation. If t is >
|
|
1420
|
+
* than duration we'll get values like 2.5 (midway through the
|
|
1421
|
+
* third iteration)
|
|
1422
|
+
*/
|
|
1423
|
+
const progress = Math.min(this.currentTime, totalDuration) / resolvedDuration;
|
|
1424
|
+
/**
|
|
1425
|
+
* Get the current iteration (0 indexed). For instance the floor of
|
|
1426
|
+
* 2.5 is 2.
|
|
1427
|
+
*/
|
|
1428
|
+
let currentIteration = Math.floor(progress);
|
|
1429
|
+
/**
|
|
1430
|
+
* Get the current progress of the iteration by taking the remainder
|
|
1431
|
+
* so 2.5 is 0.5 through iteration 2
|
|
1432
|
+
*/
|
|
1433
|
+
let iterationProgress = progress % 1.0;
|
|
1434
|
+
/**
|
|
1435
|
+
* If iteration progress is 1 we count that as the end
|
|
1436
|
+
* of the previous iteration.
|
|
1437
|
+
*/
|
|
1438
|
+
if (!iterationProgress && progress >= 1) {
|
|
1439
|
+
iterationProgress = 1;
|
|
33
1440
|
}
|
|
34
|
-
|
|
35
|
-
|
|
1441
|
+
iterationProgress === 1 && currentIteration--;
|
|
1442
|
+
currentIteration = Math.min(currentIteration, repeat + 1);
|
|
1443
|
+
/**
|
|
1444
|
+
* Reverse progress if we're not running in "normal" direction
|
|
1445
|
+
*/
|
|
1446
|
+
const isOddIteration = Boolean(currentIteration % 2);
|
|
1447
|
+
if (isOddIteration) {
|
|
1448
|
+
if (repeatType === "reverse") {
|
|
1449
|
+
iterationProgress = 1 - iterationProgress;
|
|
1450
|
+
if (repeatDelay) {
|
|
1451
|
+
iterationProgress -= repeatDelay / resolvedDuration;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
else if (repeatType === "mirror") {
|
|
1455
|
+
frameGenerator = mirroredGenerator;
|
|
1456
|
+
}
|
|
36
1457
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1458
|
+
elapsed = motionUtils.clamp(0, 1, iterationProgress) * resolvedDuration;
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* If we're in negative time, set state as the initial keyframe.
|
|
1462
|
+
* This prevents delay: x, duration: 0 animations from finishing
|
|
1463
|
+
* instantly.
|
|
1464
|
+
*/
|
|
1465
|
+
const state = isInDelayPhase
|
|
1466
|
+
? { done: false, value: keyframes[0] }
|
|
1467
|
+
: frameGenerator.next(elapsed);
|
|
1468
|
+
if (mixKeyframes) {
|
|
1469
|
+
state.value = mixKeyframes(state.value);
|
|
1470
|
+
}
|
|
1471
|
+
let { done } = state;
|
|
1472
|
+
if (!isInDelayPhase && calculatedDuration !== null) {
|
|
1473
|
+
done =
|
|
1474
|
+
this.playbackSpeed >= 0
|
|
1475
|
+
? this.currentTime >= totalDuration
|
|
1476
|
+
: this.currentTime <= 0;
|
|
1477
|
+
}
|
|
1478
|
+
const isAnimationFinished = this.holdTime === null &&
|
|
1479
|
+
(this.state === "finished" || (this.state === "running" && done));
|
|
1480
|
+
// TODO: The exception for inertia could be cleaner here
|
|
1481
|
+
if (isAnimationFinished && type !== inertia) {
|
|
1482
|
+
state.value = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
1483
|
+
}
|
|
1484
|
+
if (onUpdate) {
|
|
1485
|
+
onUpdate(state.value);
|
|
1486
|
+
}
|
|
1487
|
+
if (isAnimationFinished) {
|
|
1488
|
+
this.finish();
|
|
1489
|
+
}
|
|
1490
|
+
return state;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Allows the returned animation to be awaited or promise-chained. Currently
|
|
1494
|
+
* resolves when the animation finishes at all but in a future update could/should
|
|
1495
|
+
* reject if its cancels.
|
|
1496
|
+
*/
|
|
1497
|
+
then(resolve, reject) {
|
|
1498
|
+
return this.finished.then(resolve, reject);
|
|
1499
|
+
}
|
|
1500
|
+
get duration() {
|
|
1501
|
+
return motionUtils.millisecondsToSeconds(this.calculatedDuration);
|
|
44
1502
|
}
|
|
45
1503
|
get time() {
|
|
46
|
-
return this.
|
|
1504
|
+
return motionUtils.millisecondsToSeconds(this.currentTime);
|
|
47
1505
|
}
|
|
48
|
-
set time(
|
|
49
|
-
|
|
1506
|
+
set time(newTime) {
|
|
1507
|
+
newTime = motionUtils.secondsToMilliseconds(newTime);
|
|
1508
|
+
this.currentTime = newTime;
|
|
1509
|
+
if (this.startTime === null ||
|
|
1510
|
+
this.holdTime !== null ||
|
|
1511
|
+
this.playbackSpeed === 0) {
|
|
1512
|
+
this.holdTime = newTime;
|
|
1513
|
+
}
|
|
1514
|
+
else if (this.driver) {
|
|
1515
|
+
this.startTime = this.driver.now() - newTime / this.playbackSpeed;
|
|
1516
|
+
}
|
|
50
1517
|
}
|
|
51
1518
|
get speed() {
|
|
52
|
-
return this.
|
|
1519
|
+
return this.playbackSpeed;
|
|
53
1520
|
}
|
|
54
|
-
set speed(
|
|
55
|
-
this.
|
|
1521
|
+
set speed(newSpeed) {
|
|
1522
|
+
this.updateTime(time.now());
|
|
1523
|
+
const hasChanged = this.playbackSpeed !== newSpeed;
|
|
1524
|
+
this.playbackSpeed = newSpeed;
|
|
1525
|
+
if (hasChanged) {
|
|
1526
|
+
this.time = motionUtils.millisecondsToSeconds(this.currentTime);
|
|
1527
|
+
}
|
|
56
1528
|
}
|
|
57
|
-
|
|
58
|
-
|
|
1529
|
+
play() {
|
|
1530
|
+
if (this.isStopped)
|
|
1531
|
+
return;
|
|
1532
|
+
const { driver = frameloopDriver, onPlay, startTime } = this.options;
|
|
1533
|
+
if (!this.driver) {
|
|
1534
|
+
this.driver = driver((timestamp) => this.tick(timestamp));
|
|
1535
|
+
}
|
|
1536
|
+
onPlay && onPlay();
|
|
1537
|
+
const now = this.driver.now();
|
|
1538
|
+
if (this.holdTime !== null) {
|
|
1539
|
+
this.startTime = now - this.holdTime;
|
|
1540
|
+
}
|
|
1541
|
+
else if (this.state === "finished") {
|
|
1542
|
+
console.log("JSAnimation updateFinished");
|
|
1543
|
+
this.updateFinished();
|
|
1544
|
+
this.startTime = now;
|
|
1545
|
+
}
|
|
1546
|
+
else if (!this.startTime) {
|
|
1547
|
+
this.startTime = startTime ?? now;
|
|
1548
|
+
}
|
|
1549
|
+
if (this.state === "finished" && this.speed < 0) {
|
|
1550
|
+
this.startTime += this.calculatedDuration;
|
|
1551
|
+
}
|
|
1552
|
+
this.holdTime = null;
|
|
1553
|
+
/**
|
|
1554
|
+
* Set playState to running only after we've used it in
|
|
1555
|
+
* the previous logic.
|
|
1556
|
+
*/
|
|
1557
|
+
this.state = "running";
|
|
1558
|
+
this.driver.start();
|
|
59
1559
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1560
|
+
pause() {
|
|
1561
|
+
this.state = "paused";
|
|
1562
|
+
this.updateTime(time.now());
|
|
1563
|
+
this.holdTime = this.currentTime;
|
|
1564
|
+
}
|
|
1565
|
+
complete() {
|
|
1566
|
+
if (this.state !== "running") {
|
|
1567
|
+
this.play();
|
|
64
1568
|
}
|
|
65
|
-
|
|
1569
|
+
this.state = "finished";
|
|
1570
|
+
this.holdTime = null;
|
|
66
1571
|
}
|
|
67
|
-
|
|
68
|
-
this.
|
|
1572
|
+
finish() {
|
|
1573
|
+
this.notifyFinished();
|
|
1574
|
+
this.teardown();
|
|
1575
|
+
this.state = "finished";
|
|
1576
|
+
const { onComplete } = this.options;
|
|
1577
|
+
onComplete && onComplete();
|
|
69
1578
|
}
|
|
70
|
-
|
|
71
|
-
this.
|
|
1579
|
+
cancel() {
|
|
1580
|
+
this.holdTime = null;
|
|
1581
|
+
this.startTime = 0;
|
|
1582
|
+
this.tick(0);
|
|
1583
|
+
this.teardown();
|
|
72
1584
|
}
|
|
73
|
-
|
|
74
|
-
this.
|
|
1585
|
+
teardown() {
|
|
1586
|
+
this.state = "idle";
|
|
1587
|
+
this.stopDriver();
|
|
1588
|
+
this.startTime = this.holdTime = null;
|
|
1589
|
+
activeAnimations.mainThread--;
|
|
75
1590
|
}
|
|
76
|
-
|
|
77
|
-
this.
|
|
1591
|
+
stopDriver() {
|
|
1592
|
+
if (!this.driver)
|
|
1593
|
+
return;
|
|
1594
|
+
this.driver.stop();
|
|
1595
|
+
this.driver = undefined;
|
|
78
1596
|
}
|
|
79
|
-
|
|
80
|
-
this.
|
|
1597
|
+
sample(sampleTime) {
|
|
1598
|
+
this.startTime = 0;
|
|
1599
|
+
return this.tick(sampleTime, true);
|
|
81
1600
|
}
|
|
82
|
-
|
|
83
|
-
this.
|
|
1601
|
+
attachTimeline(timeline) {
|
|
1602
|
+
this.pause();
|
|
1603
|
+
if (this.options.allowFlatten) {
|
|
1604
|
+
this.options.type = "keyframes";
|
|
1605
|
+
this.options.ease = "linear";
|
|
1606
|
+
this.initAnimation();
|
|
1607
|
+
}
|
|
1608
|
+
return timeline.observe(this);
|
|
84
1609
|
}
|
|
85
1610
|
}
|
|
1611
|
+
// Legacy function support
|
|
1612
|
+
function animateValue(options) {
|
|
1613
|
+
return new JSAnimation(options);
|
|
1614
|
+
}
|
|
86
1615
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1616
|
+
function fillWildcards(keyframes) {
|
|
1617
|
+
for (let i = 1; i < keyframes.length; i++) {
|
|
1618
|
+
keyframes[i] ?? (keyframes[i] = keyframes[i - 1]);
|
|
90
1619
|
}
|
|
91
1620
|
}
|
|
92
1621
|
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
? element.style.setProperty(name, value)
|
|
98
|
-
: (element.style[name] = value);
|
|
99
|
-
},
|
|
100
|
-
get: (element, name) => {
|
|
101
|
-
return isCSSVar(name)
|
|
102
|
-
? element.style.getPropertyValue(name)
|
|
103
|
-
: element.style[name];
|
|
104
|
-
},
|
|
1622
|
+
const radToDeg = (rad) => (rad * 180) / Math.PI;
|
|
1623
|
+
const rotate = (v) => {
|
|
1624
|
+
const angle = radToDeg(Math.atan2(v[1], v[0]));
|
|
1625
|
+
return rebaseAngle(angle);
|
|
105
1626
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
1627
|
+
const matrix2dParsers = {
|
|
1628
|
+
x: 4,
|
|
1629
|
+
y: 5,
|
|
1630
|
+
translateX: 4,
|
|
1631
|
+
translateY: 5,
|
|
1632
|
+
scaleX: 0,
|
|
1633
|
+
scaleY: 3,
|
|
1634
|
+
scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
|
|
1635
|
+
rotate,
|
|
1636
|
+
rotateZ: rotate,
|
|
1637
|
+
skewX: (v) => radToDeg(Math.atan(v[1])),
|
|
1638
|
+
skewY: (v) => radToDeg(Math.atan(v[2])),
|
|
1639
|
+
skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,
|
|
1640
|
+
};
|
|
1641
|
+
const rebaseAngle = (angle) => {
|
|
1642
|
+
angle = angle % 360;
|
|
1643
|
+
if (angle < 0)
|
|
1644
|
+
angle += 360;
|
|
1645
|
+
return angle;
|
|
1646
|
+
};
|
|
1647
|
+
const rotateZ = rotate;
|
|
1648
|
+
const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
1649
|
+
const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
|
|
1650
|
+
const matrix3dParsers = {
|
|
1651
|
+
x: 12,
|
|
1652
|
+
y: 13,
|
|
1653
|
+
z: 14,
|
|
1654
|
+
translateX: 12,
|
|
1655
|
+
translateY: 13,
|
|
1656
|
+
translateZ: 14,
|
|
1657
|
+
scaleX,
|
|
1658
|
+
scaleY,
|
|
1659
|
+
scale: (v) => (scaleX(v) + scaleY(v)) / 2,
|
|
1660
|
+
rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
|
|
1661
|
+
rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
|
|
1662
|
+
rotateZ,
|
|
1663
|
+
rotate: rotateZ,
|
|
1664
|
+
skewX: (v) => radToDeg(Math.atan(v[4])),
|
|
1665
|
+
skewY: (v) => radToDeg(Math.atan(v[1])),
|
|
1666
|
+
skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,
|
|
1667
|
+
};
|
|
1668
|
+
function defaultTransformValue(name) {
|
|
1669
|
+
return name.includes("scale") ? 1 : 0;
|
|
116
1670
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
document.createElement("div").animate({ opacity: [1] });
|
|
1671
|
+
function parseValueFromTransform(transform, name) {
|
|
1672
|
+
if (!transform || transform === "none") {
|
|
1673
|
+
return defaultTransformValue(name);
|
|
121
1674
|
}
|
|
122
|
-
|
|
123
|
-
|
|
1675
|
+
const matrix3dMatch = transform.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);
|
|
1676
|
+
let parsers;
|
|
1677
|
+
let match;
|
|
1678
|
+
if (matrix3dMatch) {
|
|
1679
|
+
parsers = matrix3dParsers;
|
|
1680
|
+
match = matrix3dMatch;
|
|
124
1681
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
|
|
1682
|
+
else {
|
|
1683
|
+
const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
|
|
1684
|
+
parsers = matrix2dParsers;
|
|
1685
|
+
match = matrix2dMatch;
|
|
1686
|
+
}
|
|
1687
|
+
if (!match) {
|
|
1688
|
+
return defaultTransformValue(name);
|
|
1689
|
+
}
|
|
1690
|
+
const valueParser = parsers[name];
|
|
1691
|
+
const values = match[1].split(",").map(convertTransformToNumber);
|
|
1692
|
+
return typeof valueParser === "function"
|
|
1693
|
+
? valueParser(values)
|
|
1694
|
+
: values[valueParser];
|
|
1695
|
+
}
|
|
1696
|
+
const readTransformValue = (instance, name) => {
|
|
1697
|
+
const { transform = "none" } = getComputedStyle(instance);
|
|
1698
|
+
return parseValueFromTransform(transform, name);
|
|
1699
|
+
};
|
|
1700
|
+
function convertTransformToNumber(value) {
|
|
1701
|
+
return parseFloat(value.trim());
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
/**
|
|
1705
|
+
* Generate a list of every possible transform key.
|
|
1706
|
+
*/
|
|
1707
|
+
const transformPropOrder = [
|
|
1708
|
+
"transformPerspective",
|
|
1709
|
+
"x",
|
|
1710
|
+
"y",
|
|
1711
|
+
"z",
|
|
1712
|
+
"translateX",
|
|
1713
|
+
"translateY",
|
|
1714
|
+
"translateZ",
|
|
1715
|
+
"scale",
|
|
1716
|
+
"scaleX",
|
|
1717
|
+
"scaleY",
|
|
1718
|
+
"rotate",
|
|
1719
|
+
"rotateX",
|
|
1720
|
+
"rotateY",
|
|
1721
|
+
"rotateZ",
|
|
1722
|
+
"skew",
|
|
1723
|
+
"skewX",
|
|
1724
|
+
"skewY",
|
|
1725
|
+
];
|
|
1726
|
+
/**
|
|
1727
|
+
* A quick lookup for transform props.
|
|
1728
|
+
*/
|
|
1729
|
+
const transformProps = /*@__PURE__*/ (() => new Set(transformPropOrder))();
|
|
165
1730
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1731
|
+
const isNumOrPxType = (v) => v === number || v === px;
|
|
1732
|
+
const transformKeys = new Set(["x", "y", "z"]);
|
|
1733
|
+
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
1734
|
+
function removeNonTranslationalTransform(visualElement) {
|
|
1735
|
+
const removedTransforms = [];
|
|
1736
|
+
nonTranslationalTransformKeys.forEach((key) => {
|
|
1737
|
+
const value = visualElement.getValue(key);
|
|
1738
|
+
if (value !== undefined) {
|
|
1739
|
+
removedTransforms.push([key, value.get()]);
|
|
1740
|
+
value.set(key.startsWith("scale") ? 1 : 0);
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
return removedTransforms;
|
|
1744
|
+
}
|
|
1745
|
+
const positionalValues = {
|
|
1746
|
+
// Dimensions
|
|
1747
|
+
width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) => x.max - x.min - parseFloat(paddingLeft) - parseFloat(paddingRight),
|
|
1748
|
+
height: ({ y }, { paddingTop = "0", paddingBottom = "0" }) => y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom),
|
|
1749
|
+
top: (_bbox, { top }) => parseFloat(top),
|
|
1750
|
+
left: (_bbox, { left }) => parseFloat(left),
|
|
1751
|
+
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
1752
|
+
right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
|
|
1753
|
+
// Transform
|
|
1754
|
+
x: (_bbox, { transform }) => parseValueFromTransform(transform, "x"),
|
|
1755
|
+
y: (_bbox, { transform }) => parseValueFromTransform(transform, "y"),
|
|
1756
|
+
};
|
|
1757
|
+
// Alias translate longform names
|
|
1758
|
+
positionalValues.translateX = positionalValues.x;
|
|
1759
|
+
positionalValues.translateY = positionalValues.y;
|
|
1760
|
+
|
|
1761
|
+
const toResolve = new Set();
|
|
1762
|
+
let isScheduled = false;
|
|
1763
|
+
let anyNeedsMeasurement = false;
|
|
1764
|
+
let isForced = false;
|
|
1765
|
+
function measureAllKeyframes() {
|
|
1766
|
+
if (anyNeedsMeasurement) {
|
|
1767
|
+
const resolversToMeasure = Array.from(toResolve).filter((resolver) => resolver.needsMeasurement);
|
|
1768
|
+
const elementsToMeasure = new Set(resolversToMeasure.map((resolver) => resolver.element));
|
|
1769
|
+
const transformsToRestore = new Map();
|
|
1770
|
+
/**
|
|
1771
|
+
* Write pass
|
|
1772
|
+
* If we're measuring elements we want to remove bounding box-changing transforms.
|
|
1773
|
+
*/
|
|
1774
|
+
elementsToMeasure.forEach((element) => {
|
|
1775
|
+
const removedTransforms = removeNonTranslationalTransform(element);
|
|
1776
|
+
if (!removedTransforms.length)
|
|
1777
|
+
return;
|
|
1778
|
+
transformsToRestore.set(element, removedTransforms);
|
|
1779
|
+
element.render();
|
|
1780
|
+
});
|
|
1781
|
+
// Read
|
|
1782
|
+
resolversToMeasure.forEach((resolver) => resolver.measureInitialState());
|
|
1783
|
+
// Write
|
|
1784
|
+
elementsToMeasure.forEach((element) => {
|
|
1785
|
+
element.render();
|
|
1786
|
+
const restore = transformsToRestore.get(element);
|
|
1787
|
+
if (restore) {
|
|
1788
|
+
restore.forEach(([key, value]) => {
|
|
1789
|
+
element.getValue(key)?.set(value);
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
// Read
|
|
1794
|
+
resolversToMeasure.forEach((resolver) => resolver.measureEndState());
|
|
1795
|
+
// Write
|
|
1796
|
+
resolversToMeasure.forEach((resolver) => {
|
|
1797
|
+
if (resolver.suspendedScrollY !== undefined) {
|
|
1798
|
+
window.scrollTo(0, resolver.suspendedScrollY);
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
169
1801
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
1802
|
+
anyNeedsMeasurement = false;
|
|
1803
|
+
isScheduled = false;
|
|
1804
|
+
toResolve.forEach((resolver) => resolver.complete(isForced));
|
|
1805
|
+
toResolve.clear();
|
|
1806
|
+
}
|
|
1807
|
+
function readAllKeyframes() {
|
|
1808
|
+
toResolve.forEach((resolver) => {
|
|
1809
|
+
resolver.readKeyframes();
|
|
1810
|
+
if (resolver.needsMeasurement) {
|
|
1811
|
+
anyNeedsMeasurement = true;
|
|
176
1812
|
}
|
|
177
|
-
|
|
178
|
-
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
function flushKeyframeResolvers() {
|
|
1816
|
+
isForced = true;
|
|
1817
|
+
readAllKeyframes();
|
|
1818
|
+
measureAllKeyframes();
|
|
1819
|
+
isForced = false;
|
|
1820
|
+
}
|
|
1821
|
+
class KeyframeResolver {
|
|
1822
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element, isAsync = false) {
|
|
1823
|
+
/**
|
|
1824
|
+
* Track whether this resolver has completed. Once complete, it never
|
|
1825
|
+
* needs to attempt keyframe resolution again.
|
|
1826
|
+
*/
|
|
1827
|
+
this.isComplete = false;
|
|
1828
|
+
/**
|
|
1829
|
+
* Track whether this resolver is async. If it is, it'll be added to the
|
|
1830
|
+
* resolver queue and flushed in the next frame. Resolvers that aren't going
|
|
1831
|
+
* to trigger read/write thrashing don't need to be async.
|
|
1832
|
+
*/
|
|
1833
|
+
this.isAsync = false;
|
|
1834
|
+
/**
|
|
1835
|
+
* Track whether this resolver needs to perform a measurement
|
|
1836
|
+
* to resolve its keyframes.
|
|
1837
|
+
*/
|
|
1838
|
+
this.needsMeasurement = false;
|
|
1839
|
+
/**
|
|
1840
|
+
* Track whether this resolver is currently scheduled to resolve
|
|
1841
|
+
* to allow it to be cancelled and resumed externally.
|
|
1842
|
+
*/
|
|
1843
|
+
this.isScheduled = false;
|
|
1844
|
+
this.unresolvedKeyframes = [...unresolvedKeyframes];
|
|
1845
|
+
this.onComplete = onComplete;
|
|
1846
|
+
this.name = name;
|
|
1847
|
+
this.motionValue = motionValue;
|
|
1848
|
+
this.element = element;
|
|
1849
|
+
this.isAsync = isAsync;
|
|
1850
|
+
}
|
|
1851
|
+
scheduleResolve() {
|
|
1852
|
+
this.isScheduled = true;
|
|
1853
|
+
if (this.isAsync) {
|
|
1854
|
+
toResolve.add(this);
|
|
1855
|
+
if (!isScheduled) {
|
|
1856
|
+
isScheduled = true;
|
|
1857
|
+
frame.read(readAllKeyframes);
|
|
1858
|
+
frame.resolveKeyframes(measureAllKeyframes);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
else {
|
|
1862
|
+
this.readKeyframes();
|
|
1863
|
+
this.complete();
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
readKeyframes() {
|
|
1867
|
+
const { unresolvedKeyframes, name, element, motionValue } = this;
|
|
1868
|
+
// If initial keyframe is null we need to read it from the DOM
|
|
1869
|
+
if (unresolvedKeyframes[0] === null) {
|
|
1870
|
+
const currentValue = motionValue?.get();
|
|
1871
|
+
// TODO: This doesn't work if the final keyframe is a wildcard
|
|
1872
|
+
const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
|
|
1873
|
+
if (currentValue !== undefined) {
|
|
1874
|
+
unresolvedKeyframes[0] = currentValue;
|
|
1875
|
+
}
|
|
1876
|
+
else if (element && name) {
|
|
1877
|
+
const valueAsRead = element.readValue(name, finalKeyframe);
|
|
1878
|
+
if (valueAsRead !== undefined && valueAsRead !== null) {
|
|
1879
|
+
unresolvedKeyframes[0] = valueAsRead;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
if (unresolvedKeyframes[0] === undefined) {
|
|
1883
|
+
unresolvedKeyframes[0] = finalKeyframe;
|
|
1884
|
+
}
|
|
1885
|
+
if (motionValue && currentValue === undefined) {
|
|
1886
|
+
motionValue.set(unresolvedKeyframes[0]);
|
|
1887
|
+
}
|
|
179
1888
|
}
|
|
1889
|
+
fillWildcards(unresolvedKeyframes);
|
|
180
1890
|
}
|
|
181
|
-
|
|
182
|
-
|
|
1891
|
+
setFinalKeyframe() { }
|
|
1892
|
+
measureInitialState() { }
|
|
1893
|
+
renderEndStyles() { }
|
|
1894
|
+
measureEndState() { }
|
|
1895
|
+
complete(isForced = false) {
|
|
1896
|
+
this.isComplete = true;
|
|
1897
|
+
this.onComplete(this.unresolvedKeyframes, this.finalKeyframe, isForced);
|
|
1898
|
+
toResolve.delete(this);
|
|
1899
|
+
}
|
|
1900
|
+
cancel() {
|
|
1901
|
+
if (!this.isComplete) {
|
|
1902
|
+
this.isScheduled = false;
|
|
1903
|
+
toResolve.delete(this);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
resume() {
|
|
1907
|
+
if (!this.isComplete)
|
|
1908
|
+
this.scheduleResolve();
|
|
183
1909
|
}
|
|
184
|
-
return keyframes;
|
|
185
1910
|
}
|
|
186
1911
|
|
|
187
|
-
const
|
|
188
|
-
layout: 0,
|
|
189
|
-
mainThread: 0,
|
|
190
|
-
waapi: 0,
|
|
191
|
-
};
|
|
1912
|
+
const isCSSVar = (name) => name.startsWith("--");
|
|
192
1913
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
1914
|
+
function setStyle(element, name, value) {
|
|
1915
|
+
isCSSVar(name)
|
|
1916
|
+
? element.style.setProperty(name, value)
|
|
1917
|
+
: (element.style[name] = value);
|
|
1918
|
+
}
|
|
197
1919
|
|
|
198
|
-
const
|
|
1920
|
+
const supportsScrollTimeline = /* @__PURE__ */ motionUtils.memo(() => window.ScrollTimeline !== undefined);
|
|
199
1921
|
|
|
200
1922
|
/**
|
|
201
1923
|
* Add the ability for test suites to manually set support flags
|
|
@@ -220,17 +1942,6 @@
|
|
|
220
1942
|
return true;
|
|
221
1943
|
}, "linearEasing");
|
|
222
1944
|
|
|
223
|
-
const generateLinearEasing = (easing, duration, // as milliseconds
|
|
224
|
-
resolution = 10 // as milliseconds
|
|
225
|
-
) => {
|
|
226
|
-
let points = "";
|
|
227
|
-
const numPoints = Math.max(Math.round(duration / resolution), 2);
|
|
228
|
-
for (let i = 0; i < numPoints; i++) {
|
|
229
|
-
points += easing(i / (numPoints - 1)) + ", ";
|
|
230
|
-
}
|
|
231
|
-
return `linear(${points.substring(0, points.length - 2)})`;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
1945
|
const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
|
|
235
1946
|
|
|
236
1947
|
const supportedWaapiEasing = {
|
|
@@ -249,10 +1960,12 @@
|
|
|
249
1960
|
if (!easing) {
|
|
250
1961
|
return undefined;
|
|
251
1962
|
}
|
|
252
|
-
else if (typeof easing === "function"
|
|
253
|
-
return
|
|
1963
|
+
else if (typeof easing === "function") {
|
|
1964
|
+
return supportsLinearEasing()
|
|
1965
|
+
? generateLinearEasing(easing, duration)
|
|
1966
|
+
: "ease-out";
|
|
254
1967
|
}
|
|
255
|
-
else if (isBezierDefinition(easing)) {
|
|
1968
|
+
else if (motionUtils.isBezierDefinition(easing)) {
|
|
256
1969
|
return cubicBezierAsString(easing);
|
|
257
1970
|
}
|
|
258
1971
|
else if (Array.isArray(easing)) {
|
|
@@ -264,7 +1977,7 @@
|
|
|
264
1977
|
}
|
|
265
1978
|
}
|
|
266
1979
|
|
|
267
|
-
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "
|
|
1980
|
+
function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeOut", times, } = {}, pseudoElement = undefined) {
|
|
268
1981
|
const keyframeOptions = {
|
|
269
1982
|
[valueName]: keyframes,
|
|
270
1983
|
};
|
|
@@ -279,15 +1992,17 @@
|
|
|
279
1992
|
if (statsBuffer.value) {
|
|
280
1993
|
activeAnimations.waapi++;
|
|
281
1994
|
}
|
|
282
|
-
const
|
|
1995
|
+
const options = {
|
|
283
1996
|
delay,
|
|
284
1997
|
duration,
|
|
285
1998
|
easing: !Array.isArray(easing) ? easing : "linear",
|
|
286
1999
|
fill: "both",
|
|
287
2000
|
iterations: repeat + 1,
|
|
288
2001
|
direction: repeatType === "reverse" ? "alternate" : "normal",
|
|
289
|
-
|
|
290
|
-
|
|
2002
|
+
};
|
|
2003
|
+
if (pseudoElement)
|
|
2004
|
+
options.pseudoElement = pseudoElement;
|
|
2005
|
+
const animation = element.animate(keyframeOptions, options);
|
|
291
2006
|
if (statsBuffer.value) {
|
|
292
2007
|
animation.finished.finally(() => {
|
|
293
2008
|
activeAnimations.waapi--;
|
|
@@ -301,7 +2016,7 @@
|
|
|
301
2016
|
}
|
|
302
2017
|
|
|
303
2018
|
function applyGeneratorOptions({ type, ...options }) {
|
|
304
|
-
if (isGenerator(type)) {
|
|
2019
|
+
if (isGenerator(type) && supportsLinearEasing()) {
|
|
305
2020
|
return type.applyToOptions(options);
|
|
306
2021
|
}
|
|
307
2022
|
else {
|
|
@@ -311,62 +2026,476 @@
|
|
|
311
2026
|
return options;
|
|
312
2027
|
}
|
|
313
2028
|
|
|
314
|
-
const animationMaps = new WeakMap();
|
|
315
|
-
const animationMapKey = (name, pseudoElement) => `${name}:${pseudoElement}`;
|
|
316
|
-
function getAnimationMap(element) {
|
|
317
|
-
const map = animationMaps.get(element) || new Map();
|
|
318
|
-
animationMaps.set(element, map);
|
|
319
|
-
return map;
|
|
320
|
-
}
|
|
321
2029
|
/**
|
|
322
2030
|
* NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
|
|
323
2031
|
*/
|
|
324
|
-
class NativeAnimation {
|
|
2032
|
+
class NativeAnimation extends WithPromise {
|
|
325
2033
|
constructor(options) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if ("animation" in options) {
|
|
331
|
-
this.animation = options.animation;
|
|
2034
|
+
super();
|
|
2035
|
+
this.finishedTime = null;
|
|
2036
|
+
this.isStopped = false;
|
|
2037
|
+
if (!options)
|
|
332
2038
|
return;
|
|
333
|
-
}
|
|
334
|
-
const { element, name, keyframes: unresolvedKeyframes, pseudoElement, allowFlatten = false, } = options;
|
|
335
|
-
let { transition } = options;
|
|
2039
|
+
const { element, name, keyframes, pseudoElement, allowFlatten = false, finalKeyframe, } = options;
|
|
336
2040
|
this.isPseudoElement = Boolean(pseudoElement);
|
|
337
2041
|
this.allowFlatten = allowFlatten;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
* TODO: Check for VisualElement before using animation state. This is a fallback
|
|
342
|
-
* for mini animate(). Do this when implementing NativeAnimationExtended.
|
|
343
|
-
*/
|
|
344
|
-
const animationMap = getAnimationMap(element);
|
|
345
|
-
const key = animationMapKey(name, pseudoElement || "");
|
|
346
|
-
const currentAnimation = animationMap.get(key);
|
|
347
|
-
currentAnimation && currentAnimation.stop();
|
|
348
|
-
/**
|
|
349
|
-
* TODO: If these keyframes aren't correctly hydrated then we want to throw
|
|
350
|
-
* run an instant animation.
|
|
351
|
-
*/
|
|
352
|
-
const keyframes = hydrateKeyframes(element, name, unresolvedKeyframes, pseudoElement);
|
|
353
|
-
motionUtils.invariant(typeof transition.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
|
|
354
|
-
transition = applyGeneratorOptions(transition);
|
|
2042
|
+
this.options = options;
|
|
2043
|
+
motionUtils.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "motion"?`);
|
|
2044
|
+
const transition = applyGeneratorOptions(options);
|
|
355
2045
|
this.animation = startWaapiAnimation(element, name, keyframes, transition, pseudoElement);
|
|
356
2046
|
if (transition.autoplay === false) {
|
|
357
2047
|
this.animation.pause();
|
|
358
2048
|
}
|
|
359
|
-
this.removeAnimation = () => animationMap.delete(key);
|
|
360
2049
|
this.animation.onfinish = () => {
|
|
2050
|
+
this.finishedTime = this.time;
|
|
361
2051
|
if (!pseudoElement) {
|
|
362
|
-
|
|
363
|
-
this.
|
|
2052
|
+
const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
2053
|
+
if (this.updateMotionValue) {
|
|
2054
|
+
this.updateMotionValue(keyframe);
|
|
2055
|
+
}
|
|
2056
|
+
else {
|
|
2057
|
+
/**
|
|
2058
|
+
* If we can, we want to commit the final style as set by the user,
|
|
2059
|
+
* rather than the computed keyframe value supplied by the animation.
|
|
2060
|
+
*/
|
|
2061
|
+
setStyle(element, name, keyframe);
|
|
2062
|
+
}
|
|
2063
|
+
this.animation.cancel();
|
|
2064
|
+
}
|
|
2065
|
+
this.notifyFinished();
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
play() {
|
|
2069
|
+
if (this.isStopped)
|
|
2070
|
+
return;
|
|
2071
|
+
this.animation.play();
|
|
2072
|
+
if (this.state === "finished") {
|
|
2073
|
+
this.updateFinished();
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
pause() {
|
|
2077
|
+
this.animation.pause();
|
|
2078
|
+
}
|
|
2079
|
+
complete() {
|
|
2080
|
+
this.animation.finish?.();
|
|
2081
|
+
}
|
|
2082
|
+
cancel() {
|
|
2083
|
+
try {
|
|
2084
|
+
this.animation.cancel();
|
|
2085
|
+
}
|
|
2086
|
+
catch (e) { }
|
|
2087
|
+
}
|
|
2088
|
+
stop() {
|
|
2089
|
+
if (this.isStopped)
|
|
2090
|
+
return;
|
|
2091
|
+
this.isStopped = true;
|
|
2092
|
+
const { state } = this;
|
|
2093
|
+
if (state === "idle" || state === "finished") {
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
if (this.updateMotionValue) {
|
|
2097
|
+
this.updateMotionValue();
|
|
2098
|
+
}
|
|
2099
|
+
else {
|
|
2100
|
+
this.commitStyles();
|
|
2101
|
+
}
|
|
2102
|
+
if (!this.isPseudoElement)
|
|
2103
|
+
this.cancel();
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* WAAPI doesn't natively have any interruption capabilities.
|
|
2107
|
+
*
|
|
2108
|
+
* In this method, we commit styles back to the DOM before cancelling
|
|
2109
|
+
* the animation.
|
|
2110
|
+
*
|
|
2111
|
+
* This is designed to be overridden by NativeAnimationExtended, which
|
|
2112
|
+
* will create a renderless JS animation and sample it twice to calculate
|
|
2113
|
+
* its current value, "previous" value, and therefore allow
|
|
2114
|
+
* Motion to also correctly calculate velocity for any subsequent animation
|
|
2115
|
+
* while deferring the commit until the next animation frame.
|
|
2116
|
+
*/
|
|
2117
|
+
commitStyles() {
|
|
2118
|
+
if (!this.isPseudoElement) {
|
|
2119
|
+
this.animation.commitStyles?.();
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
get duration() {
|
|
2123
|
+
const duration = this.animation.effect?.getComputedTiming?.().duration || 0;
|
|
2124
|
+
return motionUtils.millisecondsToSeconds(Number(duration));
|
|
2125
|
+
}
|
|
2126
|
+
get time() {
|
|
2127
|
+
return motionUtils.millisecondsToSeconds(Number(this.animation.currentTime) || 0);
|
|
2128
|
+
}
|
|
2129
|
+
set time(newTime) {
|
|
2130
|
+
this.finishedTime = null;
|
|
2131
|
+
this.animation.currentTime = motionUtils.secondsToMilliseconds(newTime);
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* The playback speed of the animation.
|
|
2135
|
+
* 1 = normal speed, 2 = double speed, 0.5 = half speed.
|
|
2136
|
+
*/
|
|
2137
|
+
get speed() {
|
|
2138
|
+
return this.animation.playbackRate;
|
|
2139
|
+
}
|
|
2140
|
+
set speed(newSpeed) {
|
|
2141
|
+
// Allow backwards playback after finishing
|
|
2142
|
+
if (newSpeed < 0)
|
|
2143
|
+
this.finishedTime = null;
|
|
2144
|
+
this.animation.playbackRate = newSpeed;
|
|
2145
|
+
}
|
|
2146
|
+
get state() {
|
|
2147
|
+
return this.finishedTime !== null
|
|
2148
|
+
? "finished"
|
|
2149
|
+
: this.animation.playState;
|
|
2150
|
+
}
|
|
2151
|
+
get startTime() {
|
|
2152
|
+
return Number(this.animation.startTime);
|
|
2153
|
+
}
|
|
2154
|
+
set startTime(newStartTime) {
|
|
2155
|
+
this.animation.startTime = newStartTime;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Attaches a timeline to the animation, for instance the `ScrollTimeline`.
|
|
2159
|
+
*/
|
|
2160
|
+
attachTimeline({ timeline, observe }) {
|
|
2161
|
+
if (this.allowFlatten) {
|
|
2162
|
+
this.animation.effect?.updateTiming({ easing: "linear" });
|
|
2163
|
+
}
|
|
2164
|
+
this.animation.onfinish = null;
|
|
2165
|
+
if (supportsScrollTimeline()) {
|
|
2166
|
+
this.animation.timeline = timeline;
|
|
2167
|
+
return motionUtils.noop;
|
|
2168
|
+
}
|
|
2169
|
+
else {
|
|
2170
|
+
return observe(this);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
const unsupportedEasingFunctions = {
|
|
2176
|
+
anticipate: motionUtils.anticipate,
|
|
2177
|
+
backInOut: motionUtils.backInOut,
|
|
2178
|
+
circInOut: motionUtils.circInOut,
|
|
2179
|
+
};
|
|
2180
|
+
function isUnsupportedEase(key) {
|
|
2181
|
+
return key in unsupportedEasingFunctions;
|
|
2182
|
+
}
|
|
2183
|
+
function replaceStringEasing(transition) {
|
|
2184
|
+
if (typeof transition.ease === "string" &&
|
|
2185
|
+
isUnsupportedEase(transition.ease)) {
|
|
2186
|
+
transition.ease = unsupportedEasingFunctions[transition.ease];
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
/**
|
|
2191
|
+
* 10ms is chosen here as it strikes a balance between smooth
|
|
2192
|
+
* results (more than one keyframe per frame at 60fps) and
|
|
2193
|
+
* keyframe quantity.
|
|
2194
|
+
*/
|
|
2195
|
+
const sampleDelta = 10; //ms
|
|
2196
|
+
class NativeAnimationExtended extends NativeAnimation {
|
|
2197
|
+
constructor(options) {
|
|
2198
|
+
/**
|
|
2199
|
+
* The base NativeAnimation function only supports a subset
|
|
2200
|
+
* of Motion easings, and WAAPI also only supports some
|
|
2201
|
+
* easing functions via string/cubic-bezier definitions.
|
|
2202
|
+
*
|
|
2203
|
+
* This function replaces those unsupported easing functions
|
|
2204
|
+
* with a JS easing function. This will later get compiled
|
|
2205
|
+
* to a linear() easing function.
|
|
2206
|
+
*/
|
|
2207
|
+
replaceStringEasing(options);
|
|
2208
|
+
/**
|
|
2209
|
+
* Ensure we replace the transition type with a generator function
|
|
2210
|
+
* before passing to WAAPI.
|
|
2211
|
+
*
|
|
2212
|
+
* TODO: Does this have a better home? It could be shared with
|
|
2213
|
+
* JSAnimation.
|
|
2214
|
+
*/
|
|
2215
|
+
replaceTransitionType(options);
|
|
2216
|
+
super(options);
|
|
2217
|
+
if (options.startTime) {
|
|
2218
|
+
this.startTime = options.startTime;
|
|
2219
|
+
}
|
|
2220
|
+
this.options = options;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* WAAPI doesn't natively have any interruption capabilities.
|
|
2224
|
+
*
|
|
2225
|
+
* Rather than read commited styles back out of the DOM, we can
|
|
2226
|
+
* create a renderless JS animation and sample it twice to calculate
|
|
2227
|
+
* its current value, "previous" value, and therefore allow
|
|
2228
|
+
* Motion to calculate velocity for any subsequent animation.
|
|
2229
|
+
*/
|
|
2230
|
+
updateMotionValue(value) {
|
|
2231
|
+
const { motionValue, onUpdate, onComplete, element, ...options } = this.options;
|
|
2232
|
+
if (!motionValue)
|
|
2233
|
+
return;
|
|
2234
|
+
if (value !== undefined) {
|
|
2235
|
+
motionValue.set(value);
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
const sampleAnimation = new JSAnimation({
|
|
2239
|
+
...options,
|
|
2240
|
+
autoplay: false,
|
|
2241
|
+
});
|
|
2242
|
+
const sampleTime = motionUtils.secondsToMilliseconds(this.finishedTime ?? this.time);
|
|
2243
|
+
motionValue.setWithVelocity(sampleAnimation.sample(sampleTime - sampleDelta).value, sampleAnimation.sample(sampleTime).value, sampleDelta);
|
|
2244
|
+
sampleAnimation.stop();
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* Check if a value is animatable. Examples:
|
|
2250
|
+
*
|
|
2251
|
+
* ✅: 100, "100px", "#fff"
|
|
2252
|
+
* ❌: "block", "url(2.jpg)"
|
|
2253
|
+
* @param value
|
|
2254
|
+
*
|
|
2255
|
+
* @internal
|
|
2256
|
+
*/
|
|
2257
|
+
const isAnimatable = (value, name) => {
|
|
2258
|
+
// If the list of keys tat might be non-animatable grows, replace with Set
|
|
2259
|
+
if (name === "zIndex")
|
|
2260
|
+
return false;
|
|
2261
|
+
// If it's a number or a keyframes array, we can animate it. We might at some point
|
|
2262
|
+
// need to do a deep isAnimatable check of keyframes, or let Popmotion handle this,
|
|
2263
|
+
// but for now lets leave it like this for performance reasons
|
|
2264
|
+
if (typeof value === "number" || Array.isArray(value))
|
|
2265
|
+
return true;
|
|
2266
|
+
if (typeof value === "string" && // It's animatable if we have a string
|
|
2267
|
+
(complex.test(value) || value === "0") && // And it contains numbers and/or colors
|
|
2268
|
+
!value.startsWith("url(") // Unless it starts with "url("
|
|
2269
|
+
) {
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
return false;
|
|
2273
|
+
};
|
|
2274
|
+
|
|
2275
|
+
function hasKeyframesChanged(keyframes) {
|
|
2276
|
+
const current = keyframes[0];
|
|
2277
|
+
if (keyframes.length === 1)
|
|
2278
|
+
return true;
|
|
2279
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
2280
|
+
if (keyframes[i] !== current)
|
|
2281
|
+
return true;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
function canAnimate(keyframes, name, type, velocity) {
|
|
2285
|
+
/**
|
|
2286
|
+
* Check if we're able to animate between the start and end keyframes,
|
|
2287
|
+
* and throw a warning if we're attempting to animate between one that's
|
|
2288
|
+
* animatable and another that isn't.
|
|
2289
|
+
*/
|
|
2290
|
+
const originKeyframe = keyframes[0];
|
|
2291
|
+
if (originKeyframe === null)
|
|
2292
|
+
return false;
|
|
2293
|
+
/**
|
|
2294
|
+
* These aren't traditionally animatable but we do support them.
|
|
2295
|
+
* In future we could look into making this more generic or replacing
|
|
2296
|
+
* this function with mix() === mixImmediate
|
|
2297
|
+
*/
|
|
2298
|
+
if (name === "display" || name === "visibility")
|
|
2299
|
+
return true;
|
|
2300
|
+
const targetKeyframe = keyframes[keyframes.length - 1];
|
|
2301
|
+
const isOriginAnimatable = isAnimatable(originKeyframe, name);
|
|
2302
|
+
const isTargetAnimatable = isAnimatable(targetKeyframe, name);
|
|
2303
|
+
motionUtils.warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". ${originKeyframe} is not an animatable value - to enable this animation set ${originKeyframe} to a value animatable to ${targetKeyframe} via the \`style\` property.`);
|
|
2304
|
+
// Always skip if any of these are true
|
|
2305
|
+
if (!isOriginAnimatable || !isTargetAnimatable) {
|
|
2306
|
+
return false;
|
|
2307
|
+
}
|
|
2308
|
+
return (hasKeyframesChanged(keyframes) ||
|
|
2309
|
+
((type === "spring" || isGenerator(type)) && velocity));
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
/**
|
|
2313
|
+
* A list of values that can be hardware-accelerated.
|
|
2314
|
+
*/
|
|
2315
|
+
const acceleratedValues$1 = new Set([
|
|
2316
|
+
"opacity",
|
|
2317
|
+
"clipPath",
|
|
2318
|
+
"filter",
|
|
2319
|
+
"transform",
|
|
2320
|
+
// TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
|
|
2321
|
+
// or until we implement support for linear() easing.
|
|
2322
|
+
// "background-color"
|
|
2323
|
+
]);
|
|
2324
|
+
const supportsWaapi = /*@__PURE__*/ motionUtils.memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
2325
|
+
function supportsBrowserAnimation(options) {
|
|
2326
|
+
const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
|
|
2327
|
+
if (!motionValue ||
|
|
2328
|
+
!motionValue.owner ||
|
|
2329
|
+
!(motionValue.owner.current instanceof HTMLElement)) {
|
|
2330
|
+
return false;
|
|
2331
|
+
}
|
|
2332
|
+
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
2333
|
+
return (supportsWaapi() &&
|
|
2334
|
+
name &&
|
|
2335
|
+
acceleratedValues$1.has(name) &&
|
|
2336
|
+
(name !== "transform" || !transformTemplate) &&
|
|
2337
|
+
/**
|
|
2338
|
+
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
2339
|
+
* no way to read the value from WAAPI every frame.
|
|
2340
|
+
*/
|
|
2341
|
+
!onUpdate &&
|
|
2342
|
+
!repeatDelay &&
|
|
2343
|
+
repeatType !== "mirror" &&
|
|
2344
|
+
damping !== 0 &&
|
|
2345
|
+
type !== "inertia");
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
/**
|
|
2349
|
+
* Maximum time allowed between an animation being created and it being
|
|
2350
|
+
* resolved for us to use the latter as the start time.
|
|
2351
|
+
*
|
|
2352
|
+
* This is to ensure that while we prefer to "start" an animation as soon
|
|
2353
|
+
* as it's triggered, we also want to avoid a visual jump if there's a big delay
|
|
2354
|
+
* between these two moments.
|
|
2355
|
+
*/
|
|
2356
|
+
const MAX_RESOLVE_DELAY = 40;
|
|
2357
|
+
class AsyncMotionValueAnimation extends WithPromise {
|
|
2358
|
+
constructor({ autoplay = true, delay = 0, type = "keyframes", repeat = 0, repeatDelay = 0, repeatType = "loop", keyframes, name, motionValue, element, ...options }) {
|
|
2359
|
+
super();
|
|
2360
|
+
/**
|
|
2361
|
+
* Bound to support return animation.stop pattern
|
|
2362
|
+
*/
|
|
2363
|
+
this.stop = () => {
|
|
2364
|
+
if (this._animation) {
|
|
2365
|
+
this._animation.stop();
|
|
2366
|
+
this.stopTimeline?.();
|
|
2367
|
+
}
|
|
2368
|
+
else {
|
|
2369
|
+
this.keyframeResolver?.cancel();
|
|
364
2370
|
}
|
|
365
2371
|
};
|
|
2372
|
+
this.createdAt = time.now();
|
|
2373
|
+
const optionsWithDefaults = {
|
|
2374
|
+
autoplay,
|
|
2375
|
+
delay,
|
|
2376
|
+
type,
|
|
2377
|
+
repeat,
|
|
2378
|
+
repeatDelay,
|
|
2379
|
+
repeatType,
|
|
2380
|
+
name,
|
|
2381
|
+
motionValue,
|
|
2382
|
+
element,
|
|
2383
|
+
...options,
|
|
2384
|
+
};
|
|
2385
|
+
const KeyframeResolver$1 = element?.KeyframeResolver || KeyframeResolver;
|
|
2386
|
+
this.keyframeResolver = new KeyframeResolver$1(keyframes, (resolvedKeyframes, finalKeyframe, forced) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe, optionsWithDefaults, !forced), name, motionValue, element);
|
|
2387
|
+
this.keyframeResolver?.scheduleResolve();
|
|
2388
|
+
}
|
|
2389
|
+
onKeyframesResolved(keyframes, finalKeyframe, options, sync) {
|
|
2390
|
+
this.keyframeResolver = undefined;
|
|
2391
|
+
const { name, type, velocity, delay, isHandoff, onUpdate, onComplete } = options;
|
|
2392
|
+
this.resolvedAt = time.now();
|
|
2393
|
+
/**
|
|
2394
|
+
* If we can't animate this value with the resolved keyframes
|
|
2395
|
+
* then we should complete it immediately.
|
|
2396
|
+
*/
|
|
2397
|
+
if (!canAnimate(keyframes, name, type, velocity)) {
|
|
2398
|
+
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
2399
|
+
onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe));
|
|
2400
|
+
}
|
|
2401
|
+
keyframes[0] = keyframes[keyframes.length - 1];
|
|
2402
|
+
options.duration = 0;
|
|
2403
|
+
options.repeat = 0;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Resolve startTime for the animation.
|
|
2407
|
+
*
|
|
2408
|
+
* This method uses the createdAt and resolvedAt to calculate the
|
|
2409
|
+
* animation startTime. *Ideally*, we would use the createdAt time as t=0
|
|
2410
|
+
* as the following frame would then be the first frame of the animation in
|
|
2411
|
+
* progress, which would feel snappier.
|
|
2412
|
+
*
|
|
2413
|
+
* However, if there's a delay (main thread work) between the creation of
|
|
2414
|
+
* the animation and the first commited frame, we prefer to use resolvedAt
|
|
2415
|
+
* to avoid a sudden jump into the animation.
|
|
2416
|
+
*/
|
|
2417
|
+
const startTime = sync
|
|
2418
|
+
? !this.resolvedAt
|
|
2419
|
+
? this.createdAt
|
|
2420
|
+
: this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY
|
|
2421
|
+
? this.resolvedAt
|
|
2422
|
+
: this.createdAt
|
|
2423
|
+
: undefined;
|
|
2424
|
+
const resolvedOptions = {
|
|
2425
|
+
startTime,
|
|
2426
|
+
finalKeyframe,
|
|
2427
|
+
...options,
|
|
2428
|
+
keyframes,
|
|
2429
|
+
};
|
|
366
2430
|
/**
|
|
367
|
-
*
|
|
2431
|
+
* Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via
|
|
2432
|
+
* WAAPI. Therefore, this animation must be JS to ensure it runs "under" the
|
|
2433
|
+
* optimised animation.
|
|
368
2434
|
*/
|
|
369
|
-
|
|
2435
|
+
const animation = !isHandoff && supportsBrowserAnimation(resolvedOptions)
|
|
2436
|
+
? new NativeAnimationExtended({
|
|
2437
|
+
...resolvedOptions,
|
|
2438
|
+
element: resolvedOptions.motionValue.owner.current,
|
|
2439
|
+
})
|
|
2440
|
+
: new JSAnimation(resolvedOptions);
|
|
2441
|
+
animation.finished
|
|
2442
|
+
.then(() => {
|
|
2443
|
+
onComplete?.();
|
|
2444
|
+
this.notifyFinished();
|
|
2445
|
+
})
|
|
2446
|
+
.catch(motionUtils.noop);
|
|
2447
|
+
if (this.pendingTimeline) {
|
|
2448
|
+
this.stopTimeline = animation.attachTimeline(this.pendingTimeline);
|
|
2449
|
+
this.pendingTimeline = undefined;
|
|
2450
|
+
}
|
|
2451
|
+
this._animation = animation;
|
|
2452
|
+
}
|
|
2453
|
+
get finished() {
|
|
2454
|
+
if (!this._animation) {
|
|
2455
|
+
return this._finished;
|
|
2456
|
+
}
|
|
2457
|
+
else {
|
|
2458
|
+
return this.animation.finished;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
then(onResolve, _onReject) {
|
|
2462
|
+
return this.finished.finally(onResolve).then(() => { });
|
|
2463
|
+
}
|
|
2464
|
+
get animation() {
|
|
2465
|
+
if (!this._animation) {
|
|
2466
|
+
flushKeyframeResolvers();
|
|
2467
|
+
}
|
|
2468
|
+
return this._animation;
|
|
2469
|
+
}
|
|
2470
|
+
get duration() {
|
|
2471
|
+
return this.animation.duration;
|
|
2472
|
+
}
|
|
2473
|
+
get time() {
|
|
2474
|
+
return this.animation.time;
|
|
2475
|
+
}
|
|
2476
|
+
set time(newTime) {
|
|
2477
|
+
this.animation.time = newTime;
|
|
2478
|
+
}
|
|
2479
|
+
get speed() {
|
|
2480
|
+
return this.animation.speed;
|
|
2481
|
+
}
|
|
2482
|
+
get state() {
|
|
2483
|
+
return this.animation.state;
|
|
2484
|
+
}
|
|
2485
|
+
set speed(newSpeed) {
|
|
2486
|
+
this.animation.speed = newSpeed;
|
|
2487
|
+
}
|
|
2488
|
+
get startTime() {
|
|
2489
|
+
return this.animation.startTime;
|
|
2490
|
+
}
|
|
2491
|
+
attachTimeline(timeline) {
|
|
2492
|
+
if (this._animation) {
|
|
2493
|
+
this.stopTimeline = this.animation.attachTimeline(timeline);
|
|
2494
|
+
}
|
|
2495
|
+
else {
|
|
2496
|
+
this.pendingTimeline = timeline;
|
|
2497
|
+
}
|
|
2498
|
+
return () => this.stop();
|
|
370
2499
|
}
|
|
371
2500
|
play() {
|
|
372
2501
|
this.animation.play();
|
|
@@ -375,90 +2504,145 @@
|
|
|
375
2504
|
this.animation.pause();
|
|
376
2505
|
}
|
|
377
2506
|
complete() {
|
|
378
|
-
|
|
2507
|
+
console.log("async animation complete");
|
|
2508
|
+
this.animation.complete();
|
|
379
2509
|
}
|
|
380
2510
|
cancel() {
|
|
381
|
-
|
|
382
|
-
this.animation.cancel();
|
|
383
|
-
}
|
|
384
|
-
catch (e) { }
|
|
385
|
-
this.removeAnimation();
|
|
2511
|
+
this.animation.cancel();
|
|
386
2512
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
class GroupAnimation {
|
|
2516
|
+
constructor(animations) {
|
|
2517
|
+
// Bound to accomadate common `return animation.stop` pattern
|
|
2518
|
+
this.stop = () => this.runAll("stop");
|
|
2519
|
+
this.animations = animations.filter(Boolean);
|
|
2520
|
+
}
|
|
2521
|
+
get finished() {
|
|
2522
|
+
return Promise.all(this.animations.map((animation) => animation.finished));
|
|
394
2523
|
}
|
|
395
2524
|
/**
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* In this method, we commit styles back to the DOM before cancelling
|
|
399
|
-
* the animation.
|
|
400
|
-
*
|
|
401
|
-
* This is designed to be overridden by NativeAnimationExtended, which
|
|
402
|
-
* will create a renderless JS animation and sample it twice to calculate
|
|
403
|
-
* its current value, "previous" value, and therefore allow
|
|
404
|
-
* Motion to also correctly calculate velocity for any subsequent animation
|
|
405
|
-
* while deferring the commit until the next animation frame.
|
|
2525
|
+
* TODO: Filter out cancelled or stopped animations before returning
|
|
406
2526
|
*/
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
2527
|
+
getAll(propName) {
|
|
2528
|
+
return this.animations[0][propName];
|
|
2529
|
+
}
|
|
2530
|
+
setAll(propName, newValue) {
|
|
2531
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
2532
|
+
this.animations[i][propName] = newValue;
|
|
410
2533
|
}
|
|
411
2534
|
}
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
return
|
|
2535
|
+
attachTimeline(timeline) {
|
|
2536
|
+
const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
|
|
2537
|
+
return () => {
|
|
2538
|
+
subscriptions.forEach((cancel, i) => {
|
|
2539
|
+
cancel && cancel();
|
|
2540
|
+
this.animations[i].stop();
|
|
2541
|
+
});
|
|
2542
|
+
};
|
|
415
2543
|
}
|
|
416
2544
|
get time() {
|
|
417
|
-
return
|
|
2545
|
+
return this.getAll("time");
|
|
418
2546
|
}
|
|
419
|
-
set time(
|
|
420
|
-
this.
|
|
2547
|
+
set time(time) {
|
|
2548
|
+
this.setAll("time", time);
|
|
421
2549
|
}
|
|
422
|
-
/**
|
|
423
|
-
* The playback speed of the animation.
|
|
424
|
-
* 1 = normal speed, 2 = double speed, 0.5 = half speed.
|
|
425
|
-
*/
|
|
426
2550
|
get speed() {
|
|
427
|
-
return this.
|
|
2551
|
+
return this.getAll("speed");
|
|
428
2552
|
}
|
|
429
|
-
set speed(
|
|
430
|
-
this.
|
|
2553
|
+
set speed(speed) {
|
|
2554
|
+
this.setAll("speed", speed);
|
|
431
2555
|
}
|
|
432
2556
|
get state() {
|
|
433
|
-
return this.
|
|
2557
|
+
return this.getAll("state");
|
|
434
2558
|
}
|
|
435
2559
|
get startTime() {
|
|
436
|
-
return
|
|
437
|
-
}
|
|
438
|
-
get finished() {
|
|
439
|
-
return this.animation.finished;
|
|
2560
|
+
return this.getAll("startTime");
|
|
440
2561
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
2562
|
+
get duration() {
|
|
2563
|
+
let max = 0;
|
|
2564
|
+
for (let i = 0; i < this.animations.length; i++) {
|
|
2565
|
+
max = Math.max(max, this.animations[i].duration);
|
|
444
2566
|
}
|
|
2567
|
+
return max;
|
|
445
2568
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
*/
|
|
449
|
-
attachTimeline(timeline) {
|
|
450
|
-
this.animation.timeline = timeline;
|
|
451
|
-
this.animation.onfinish = null;
|
|
452
|
-
return motionUtils.noop;
|
|
2569
|
+
runAll(methodName) {
|
|
2570
|
+
this.animations.forEach((controls) => controls[methodName]());
|
|
453
2571
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
2572
|
+
play() {
|
|
2573
|
+
this.runAll("play");
|
|
2574
|
+
}
|
|
2575
|
+
pause() {
|
|
2576
|
+
this.runAll("pause");
|
|
2577
|
+
}
|
|
2578
|
+
cancel() {
|
|
2579
|
+
this.runAll("cancel");
|
|
2580
|
+
}
|
|
2581
|
+
complete() {
|
|
2582
|
+
this.runAll("complete");
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
class GroupAnimationWithThen extends GroupAnimation {
|
|
2587
|
+
then(onResolve, _onReject) {
|
|
2588
|
+
return this.finished.finally(onResolve).then(() => { });
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
class NativeAnimationWrapper extends NativeAnimation {
|
|
2593
|
+
constructor(animation) {
|
|
2594
|
+
super();
|
|
2595
|
+
this.animation = animation;
|
|
2596
|
+
animation.onfinish = () => {
|
|
2597
|
+
this.finishedTime = this.time;
|
|
2598
|
+
this.notifyFinished();
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
const animationMaps = new WeakMap();
|
|
2604
|
+
const animationMapKey = (name, pseudoElement = "") => `${name}:${pseudoElement}`;
|
|
2605
|
+
function getAnimationMap(element) {
|
|
2606
|
+
const map = animationMaps.get(element) || new Map();
|
|
2607
|
+
animationMaps.set(element, map);
|
|
2608
|
+
return map;
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
/**
|
|
2612
|
+
* Parse Framer's special CSS variable format into a CSS token and a fallback.
|
|
2613
|
+
*
|
|
2614
|
+
* ```
|
|
2615
|
+
* `var(--foo, #fff)` => [`--foo`, '#fff']
|
|
2616
|
+
* ```
|
|
2617
|
+
*
|
|
2618
|
+
* @param current
|
|
2619
|
+
*/
|
|
2620
|
+
const splitCSSVariableRegex =
|
|
2621
|
+
// eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
|
|
2622
|
+
/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;
|
|
2623
|
+
function parseCSSVariable(current) {
|
|
2624
|
+
const match = splitCSSVariableRegex.exec(current);
|
|
2625
|
+
if (!match)
|
|
2626
|
+
return [,];
|
|
2627
|
+
const [, token1, token2, fallback] = match;
|
|
2628
|
+
return [`--${token1 ?? token2}`, fallback];
|
|
2629
|
+
}
|
|
2630
|
+
const maxDepth = 4;
|
|
2631
|
+
function getVariableValue(current, element, depth = 1) {
|
|
2632
|
+
motionUtils.invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`);
|
|
2633
|
+
const [token, fallback] = parseCSSVariable(current);
|
|
2634
|
+
// No CSS variable detected
|
|
2635
|
+
if (!token)
|
|
2636
|
+
return;
|
|
2637
|
+
// Attempt to read this CSS variable off the element
|
|
2638
|
+
const resolved = window.getComputedStyle(element).getPropertyValue(token);
|
|
2639
|
+
if (resolved) {
|
|
2640
|
+
const trimmed = resolved.trim();
|
|
2641
|
+
return motionUtils.isNumericalString(trimmed) ? parseFloat(trimmed) : trimmed;
|
|
461
2642
|
}
|
|
2643
|
+
return isCSSVariableToken(fallback)
|
|
2644
|
+
? getVariableValue(fallback, element, depth + 1)
|
|
2645
|
+
: fallback;
|
|
462
2646
|
}
|
|
463
2647
|
|
|
464
2648
|
function getValueTransition(transition, key) {
|
|
@@ -467,244 +2651,415 @@
|
|
|
467
2651
|
transition);
|
|
468
2652
|
}
|
|
469
2653
|
|
|
2654
|
+
const positionalKeys = new Set([
|
|
2655
|
+
"width",
|
|
2656
|
+
"height",
|
|
2657
|
+
"top",
|
|
2658
|
+
"left",
|
|
2659
|
+
"right",
|
|
2660
|
+
"bottom",
|
|
2661
|
+
...transformPropOrder,
|
|
2662
|
+
]);
|
|
2663
|
+
|
|
470
2664
|
/**
|
|
471
|
-
*
|
|
472
|
-
* to prevent infinite loops
|
|
2665
|
+
* ValueType for "auto"
|
|
473
2666
|
*/
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
let state = generator.next(duration);
|
|
479
|
-
while (!state.done && duration < maxGeneratorDuration) {
|
|
480
|
-
duration += timeStep;
|
|
481
|
-
state = generator.next(duration);
|
|
482
|
-
}
|
|
483
|
-
return duration >= maxGeneratorDuration ? Infinity : duration;
|
|
484
|
-
}
|
|
2667
|
+
const auto = {
|
|
2668
|
+
test: (v) => v === "auto",
|
|
2669
|
+
parse: (v) => v,
|
|
2670
|
+
};
|
|
485
2671
|
|
|
486
2672
|
/**
|
|
487
|
-
*
|
|
2673
|
+
* Tests a provided value against a ValueType
|
|
488
2674
|
*/
|
|
489
|
-
|
|
490
|
-
const generator = createGenerator({ ...options, keyframes: [0, scale] });
|
|
491
|
-
const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
|
|
492
|
-
return {
|
|
493
|
-
type: "keyframes",
|
|
494
|
-
ease: (progress) => {
|
|
495
|
-
return generator.next(duration * progress).value / scale;
|
|
496
|
-
},
|
|
497
|
-
duration: motionUtils.millisecondsToSeconds(duration),
|
|
498
|
-
};
|
|
499
|
-
}
|
|
2675
|
+
const testValueType = (v) => (type) => type.test(v);
|
|
500
2676
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
2677
|
+
/**
|
|
2678
|
+
* A list of value types commonly used for dimensions
|
|
2679
|
+
*/
|
|
2680
|
+
const dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
|
|
2681
|
+
/**
|
|
2682
|
+
* Tests a dimensional value against the list of dimension ValueTypes
|
|
2683
|
+
*/
|
|
2684
|
+
const findDimensionValueType = (v) => dimensionValueTypes.find(testValueType(v));
|
|
2685
|
+
|
|
2686
|
+
function isNone(value) {
|
|
2687
|
+
if (typeof value === "number") {
|
|
2688
|
+
return value === 0;
|
|
2689
|
+
}
|
|
2690
|
+
else if (value !== null) {
|
|
2691
|
+
return value === "none" || value === "0" || motionUtils.isZeroValueString(value);
|
|
2692
|
+
}
|
|
2693
|
+
else {
|
|
2694
|
+
return true;
|
|
2695
|
+
}
|
|
508
2696
|
}
|
|
509
2697
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
2698
|
+
/**
|
|
2699
|
+
* Properties that should default to 1 or 100%
|
|
2700
|
+
*/
|
|
2701
|
+
const maxDefaults = new Set(["brightness", "contrast", "saturate", "opacity"]);
|
|
2702
|
+
function applyDefaultFilter(v) {
|
|
2703
|
+
const [name, value] = v.slice(0, -1).split("(");
|
|
2704
|
+
if (name === "drop-shadow")
|
|
2705
|
+
return v;
|
|
2706
|
+
const [number] = value.match(floatRegex) || [];
|
|
2707
|
+
if (!number)
|
|
2708
|
+
return v;
|
|
2709
|
+
const unit = value.replace(number, "");
|
|
2710
|
+
let defaultValue = maxDefaults.has(name) ? 1 : 0;
|
|
2711
|
+
if (number !== value)
|
|
2712
|
+
defaultValue *= 100;
|
|
2713
|
+
return name + "(" + defaultValue + unit + ")";
|
|
513
2714
|
}
|
|
2715
|
+
const functionRegex = /\b([a-z-]*)\(.*?\)/gu;
|
|
2716
|
+
const filter = {
|
|
2717
|
+
...complex,
|
|
2718
|
+
getAnimatableNone: (v) => {
|
|
2719
|
+
const functions = v.match(functionRegex);
|
|
2720
|
+
return functions ? functions.map(applyDefaultFilter).join(" ") : v;
|
|
2721
|
+
},
|
|
2722
|
+
};
|
|
514
2723
|
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
"preRender", // Compute
|
|
520
|
-
"render", // Write
|
|
521
|
-
"postRender", // Compute
|
|
522
|
-
];
|
|
2724
|
+
const int = {
|
|
2725
|
+
...number,
|
|
2726
|
+
transform: Math.round,
|
|
2727
|
+
};
|
|
523
2728
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
2729
|
+
const transformValueTypes = {
|
|
2730
|
+
rotate: degrees,
|
|
2731
|
+
rotateX: degrees,
|
|
2732
|
+
rotateY: degrees,
|
|
2733
|
+
rotateZ: degrees,
|
|
2734
|
+
scale,
|
|
2735
|
+
scaleX: scale,
|
|
2736
|
+
scaleY: scale,
|
|
2737
|
+
scaleZ: scale,
|
|
2738
|
+
skew: degrees,
|
|
2739
|
+
skewX: degrees,
|
|
2740
|
+
skewY: degrees,
|
|
2741
|
+
distance: px,
|
|
2742
|
+
translateX: px,
|
|
2743
|
+
translateY: px,
|
|
2744
|
+
translateZ: px,
|
|
2745
|
+
x: px,
|
|
2746
|
+
y: px,
|
|
2747
|
+
z: px,
|
|
2748
|
+
perspective: px,
|
|
2749
|
+
transformPerspective: px,
|
|
2750
|
+
opacity: alpha,
|
|
2751
|
+
originX: progressPercentage,
|
|
2752
|
+
originY: progressPercentage,
|
|
2753
|
+
originZ: px,
|
|
2754
|
+
};
|
|
2755
|
+
|
|
2756
|
+
const numberValueTypes = {
|
|
2757
|
+
// Border props
|
|
2758
|
+
borderWidth: px,
|
|
2759
|
+
borderTopWidth: px,
|
|
2760
|
+
borderRightWidth: px,
|
|
2761
|
+
borderBottomWidth: px,
|
|
2762
|
+
borderLeftWidth: px,
|
|
2763
|
+
borderRadius: px,
|
|
2764
|
+
radius: px,
|
|
2765
|
+
borderTopLeftRadius: px,
|
|
2766
|
+
borderTopRightRadius: px,
|
|
2767
|
+
borderBottomRightRadius: px,
|
|
2768
|
+
borderBottomLeftRadius: px,
|
|
2769
|
+
// Positioning props
|
|
2770
|
+
width: px,
|
|
2771
|
+
maxWidth: px,
|
|
2772
|
+
height: px,
|
|
2773
|
+
maxHeight: px,
|
|
2774
|
+
top: px,
|
|
2775
|
+
right: px,
|
|
2776
|
+
bottom: px,
|
|
2777
|
+
left: px,
|
|
2778
|
+
// Spacing props
|
|
2779
|
+
padding: px,
|
|
2780
|
+
paddingTop: px,
|
|
2781
|
+
paddingRight: px,
|
|
2782
|
+
paddingBottom: px,
|
|
2783
|
+
paddingLeft: px,
|
|
2784
|
+
margin: px,
|
|
2785
|
+
marginTop: px,
|
|
2786
|
+
marginRight: px,
|
|
2787
|
+
marginBottom: px,
|
|
2788
|
+
marginLeft: px,
|
|
2789
|
+
// Misc
|
|
2790
|
+
backgroundPositionX: px,
|
|
2791
|
+
backgroundPositionY: px,
|
|
2792
|
+
...transformValueTypes,
|
|
2793
|
+
zIndex: int,
|
|
2794
|
+
size: px,
|
|
2795
|
+
// SVG
|
|
2796
|
+
fillOpacity: alpha,
|
|
2797
|
+
strokeOpacity: alpha,
|
|
2798
|
+
numOctaves: int,
|
|
2799
|
+
};
|
|
2800
|
+
|
|
2801
|
+
/**
|
|
2802
|
+
* A map of default value types for common values
|
|
2803
|
+
*/
|
|
2804
|
+
const defaultValueTypes = {
|
|
2805
|
+
...numberValueTypes,
|
|
2806
|
+
// Color props
|
|
2807
|
+
color,
|
|
2808
|
+
backgroundColor: color,
|
|
2809
|
+
outlineColor: color,
|
|
2810
|
+
fill: color,
|
|
2811
|
+
stroke: color,
|
|
2812
|
+
// Border props
|
|
2813
|
+
borderColor: color,
|
|
2814
|
+
borderTopColor: color,
|
|
2815
|
+
borderRightColor: color,
|
|
2816
|
+
borderBottomColor: color,
|
|
2817
|
+
borderLeftColor: color,
|
|
2818
|
+
filter,
|
|
2819
|
+
WebkitFilter: filter,
|
|
2820
|
+
};
|
|
2821
|
+
/**
|
|
2822
|
+
* Gets the default ValueType for the provided value key
|
|
2823
|
+
*/
|
|
2824
|
+
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
2825
|
+
|
|
2826
|
+
function getAnimatableNone(key, value) {
|
|
2827
|
+
let defaultValueType = getDefaultValueType(key);
|
|
2828
|
+
if (defaultValueType !== filter)
|
|
2829
|
+
defaultValueType = complex;
|
|
2830
|
+
// If value is not recognised as animatable, ie "one", create an animatable version origin based on the target
|
|
2831
|
+
return defaultValueType.getAnimatableNone
|
|
2832
|
+
? defaultValueType.getAnimatableNone(value)
|
|
2833
|
+
: undefined;
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2836
|
+
/**
|
|
2837
|
+
* If we encounter keyframes like "none" or "0" and we also have keyframes like
|
|
2838
|
+
* "#fff" or "200px 200px" we want to find a keyframe to serve as a template for
|
|
2839
|
+
* the "none" keyframes. In this case "#fff" or "200px 200px" - then these get turned into
|
|
2840
|
+
* zero equivalents, i.e. "#fff0" or "0px 0px".
|
|
2841
|
+
*/
|
|
2842
|
+
const invalidTemplates = new Set(["auto", "none", "0"]);
|
|
2843
|
+
function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name) {
|
|
2844
|
+
let i = 0;
|
|
2845
|
+
let animatableTemplate = undefined;
|
|
2846
|
+
while (i < unresolvedKeyframes.length && !animatableTemplate) {
|
|
2847
|
+
const keyframe = unresolvedKeyframes[i];
|
|
2848
|
+
if (typeof keyframe === "string" &&
|
|
2849
|
+
!invalidTemplates.has(keyframe) &&
|
|
2850
|
+
analyseComplexValue(keyframe).values.length) {
|
|
2851
|
+
animatableTemplate = unresolvedKeyframes[i];
|
|
551
2852
|
}
|
|
552
|
-
|
|
553
|
-
callback(latestFrameData);
|
|
2853
|
+
i++;
|
|
554
2854
|
}
|
|
555
|
-
|
|
2855
|
+
if (animatableTemplate && name) {
|
|
2856
|
+
for (const noneIndex of noneKeyframeIndexes) {
|
|
2857
|
+
unresolvedKeyframes[noneIndex] = getAnimatableNone(name, animatableTemplate);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
class DOMKeyframesResolver extends KeyframeResolver {
|
|
2863
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
2864
|
+
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
2865
|
+
}
|
|
2866
|
+
readKeyframes() {
|
|
2867
|
+
const { unresolvedKeyframes, element, name } = this;
|
|
2868
|
+
if (!element || !element.current)
|
|
2869
|
+
return;
|
|
2870
|
+
super.readKeyframes();
|
|
556
2871
|
/**
|
|
557
|
-
*
|
|
2872
|
+
* If any keyframe is a CSS variable, we need to find its value by sampling the element
|
|
558
2873
|
*/
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
2874
|
+
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
2875
|
+
let keyframe = unresolvedKeyframes[i];
|
|
2876
|
+
if (typeof keyframe === "string") {
|
|
2877
|
+
keyframe = keyframe.trim();
|
|
2878
|
+
if (isCSSVariableToken(keyframe)) {
|
|
2879
|
+
const resolved = getVariableValue(keyframe, element.current);
|
|
2880
|
+
if (resolved !== undefined) {
|
|
2881
|
+
unresolvedKeyframes[i] = resolved;
|
|
2882
|
+
}
|
|
2883
|
+
if (i === unresolvedKeyframes.length - 1) {
|
|
2884
|
+
this.finalKeyframe = keyframe;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
568
2889
|
/**
|
|
569
|
-
*
|
|
2890
|
+
* Resolve "none" values. We do this potentially twice - once before and once after measuring keyframes.
|
|
2891
|
+
* This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which
|
|
2892
|
+
* have a far bigger performance impact.
|
|
570
2893
|
*/
|
|
571
|
-
|
|
572
|
-
nextFrame.delete(callback);
|
|
573
|
-
toKeepAlive.delete(callback);
|
|
574
|
-
},
|
|
2894
|
+
this.resolveNoneKeyframes();
|
|
575
2895
|
/**
|
|
576
|
-
*
|
|
2896
|
+
* Check to see if unit type has changed. If so schedule jobs that will
|
|
2897
|
+
* temporarily set styles to the destination keyframes.
|
|
2898
|
+
* Skip if we have more than two keyframes or this isn't a positional value.
|
|
2899
|
+
* TODO: We can throw if there are multiple keyframes and the value type changes.
|
|
577
2900
|
*/
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
2901
|
+
if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {
|
|
2902
|
+
return;
|
|
2903
|
+
}
|
|
2904
|
+
const [origin, target] = unresolvedKeyframes;
|
|
2905
|
+
const originType = findDimensionValueType(origin);
|
|
2906
|
+
const targetType = findDimensionValueType(target);
|
|
2907
|
+
/**
|
|
2908
|
+
* Either we don't recognise these value types or we can animate between them.
|
|
2909
|
+
*/
|
|
2910
|
+
if (originType === targetType)
|
|
2911
|
+
return;
|
|
2912
|
+
/**
|
|
2913
|
+
* If both values are numbers or pixels, we can animate between them by
|
|
2914
|
+
* converting them to numbers.
|
|
2915
|
+
*/
|
|
2916
|
+
if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {
|
|
2917
|
+
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
2918
|
+
const value = unresolvedKeyframes[i];
|
|
2919
|
+
if (typeof value === "string") {
|
|
2920
|
+
unresolvedKeyframes[i] = parseFloat(value);
|
|
2921
|
+
}
|
|
588
2922
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
// Execute this frame
|
|
592
|
-
thisFrame.forEach(triggerCallback);
|
|
2923
|
+
}
|
|
2924
|
+
else {
|
|
593
2925
|
/**
|
|
594
|
-
*
|
|
2926
|
+
* Else, the only way to resolve this is by measuring the element.
|
|
595
2927
|
*/
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
step.process(frameData);
|
|
2928
|
+
this.needsMeasurement = true;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
resolveNoneKeyframes() {
|
|
2932
|
+
const { unresolvedKeyframes, name } = this;
|
|
2933
|
+
const noneKeyframeIndexes = [];
|
|
2934
|
+
for (let i = 0; i < unresolvedKeyframes.length; i++) {
|
|
2935
|
+
if (unresolvedKeyframes[i] === null ||
|
|
2936
|
+
isNone(unresolvedKeyframes[i])) {
|
|
2937
|
+
noneKeyframeIndexes.push(i);
|
|
607
2938
|
}
|
|
608
|
-
},
|
|
609
|
-
};
|
|
610
|
-
return step;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const maxElapsed = 40;
|
|
614
|
-
function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
|
|
615
|
-
let runNextFrame = false;
|
|
616
|
-
let useDefaultElapsed = true;
|
|
617
|
-
const state = {
|
|
618
|
-
delta: 0.0,
|
|
619
|
-
timestamp: 0.0,
|
|
620
|
-
isProcessing: false,
|
|
621
|
-
};
|
|
622
|
-
const flagRunNextFrame = () => (runNextFrame = true);
|
|
623
|
-
const steps = stepsOrder.reduce((acc, key) => {
|
|
624
|
-
acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
|
|
625
|
-
return acc;
|
|
626
|
-
}, {});
|
|
627
|
-
const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
|
|
628
|
-
const processBatch = () => {
|
|
629
|
-
const timestamp = motionUtils.MotionGlobalConfig.useManualTiming
|
|
630
|
-
? state.timestamp
|
|
631
|
-
: performance.now();
|
|
632
|
-
runNextFrame = false;
|
|
633
|
-
if (!motionUtils.MotionGlobalConfig.useManualTiming) {
|
|
634
|
-
state.delta = useDefaultElapsed
|
|
635
|
-
? 1000 / 60
|
|
636
|
-
: Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
|
|
637
2939
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
// Unrolled render loop for better per-frame performance
|
|
641
|
-
read.process(state);
|
|
642
|
-
resolveKeyframes.process(state);
|
|
643
|
-
update.process(state);
|
|
644
|
-
preRender.process(state);
|
|
645
|
-
render.process(state);
|
|
646
|
-
postRender.process(state);
|
|
647
|
-
state.isProcessing = false;
|
|
648
|
-
if (runNextFrame && allowKeepAlive) {
|
|
649
|
-
useDefaultElapsed = false;
|
|
650
|
-
scheduleNextBatch(processBatch);
|
|
2940
|
+
if (noneKeyframeIndexes.length) {
|
|
2941
|
+
makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name);
|
|
651
2942
|
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
2943
|
+
}
|
|
2944
|
+
measureInitialState() {
|
|
2945
|
+
const { element, unresolvedKeyframes, name } = this;
|
|
2946
|
+
if (!element || !element.current)
|
|
2947
|
+
return;
|
|
2948
|
+
if (name === "height") {
|
|
2949
|
+
this.suspendedScrollY = window.pageYOffset;
|
|
658
2950
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
return step.schedule(process, keepAlive, immediate);
|
|
666
|
-
};
|
|
667
|
-
return acc;
|
|
668
|
-
}, {});
|
|
669
|
-
const cancel = (process) => {
|
|
670
|
-
for (let i = 0; i < stepsOrder.length; i++) {
|
|
671
|
-
steps[stepsOrder[i]].cancel(process);
|
|
2951
|
+
this.measuredOrigin = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
|
|
2952
|
+
unresolvedKeyframes[0] = this.measuredOrigin;
|
|
2953
|
+
// Set final key frame to measure after next render
|
|
2954
|
+
const measureKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
|
|
2955
|
+
if (measureKeyframe !== undefined) {
|
|
2956
|
+
element.getValue(name, measureKeyframe).jump(measureKeyframe, false);
|
|
672
2957
|
}
|
|
673
|
-
}
|
|
674
|
-
|
|
2958
|
+
}
|
|
2959
|
+
measureEndState() {
|
|
2960
|
+
const { element, name, unresolvedKeyframes } = this;
|
|
2961
|
+
if (!element || !element.current)
|
|
2962
|
+
return;
|
|
2963
|
+
const value = element.getValue(name);
|
|
2964
|
+
value && value.jump(this.measuredOrigin, false);
|
|
2965
|
+
const finalKeyframeIndex = unresolvedKeyframes.length - 1;
|
|
2966
|
+
const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex];
|
|
2967
|
+
unresolvedKeyframes[finalKeyframeIndex] = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
|
|
2968
|
+
if (finalKeyframe !== null && this.finalKeyframe === undefined) {
|
|
2969
|
+
this.finalKeyframe = finalKeyframe;
|
|
2970
|
+
}
|
|
2971
|
+
// If we removed transform values, reapply them before the next render
|
|
2972
|
+
if (this.removedTransforms?.length) {
|
|
2973
|
+
this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
|
|
2974
|
+
element
|
|
2975
|
+
.getValue(unsetTransformName)
|
|
2976
|
+
.set(unsetTransformValue);
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
this.resolveNoneKeyframes();
|
|
2980
|
+
}
|
|
675
2981
|
}
|
|
676
2982
|
|
|
677
|
-
const
|
|
2983
|
+
const pxValues = new Set([
|
|
2984
|
+
// Border props
|
|
2985
|
+
"borderWidth",
|
|
2986
|
+
"borderTopWidth",
|
|
2987
|
+
"borderRightWidth",
|
|
2988
|
+
"borderBottomWidth",
|
|
2989
|
+
"borderLeftWidth",
|
|
2990
|
+
"borderRadius",
|
|
2991
|
+
"radius",
|
|
2992
|
+
"borderTopLeftRadius",
|
|
2993
|
+
"borderTopRightRadius",
|
|
2994
|
+
"borderBottomRightRadius",
|
|
2995
|
+
"borderBottomLeftRadius",
|
|
2996
|
+
// Positioning props
|
|
2997
|
+
"width",
|
|
2998
|
+
"maxWidth",
|
|
2999
|
+
"height",
|
|
3000
|
+
"maxHeight",
|
|
3001
|
+
"top",
|
|
3002
|
+
"right",
|
|
3003
|
+
"bottom",
|
|
3004
|
+
"left",
|
|
3005
|
+
// Spacing props
|
|
3006
|
+
"padding",
|
|
3007
|
+
"paddingTop",
|
|
3008
|
+
"paddingRight",
|
|
3009
|
+
"paddingBottom",
|
|
3010
|
+
"paddingLeft",
|
|
3011
|
+
"margin",
|
|
3012
|
+
"marginTop",
|
|
3013
|
+
"marginRight",
|
|
3014
|
+
"marginBottom",
|
|
3015
|
+
"marginLeft",
|
|
3016
|
+
// Misc
|
|
3017
|
+
"backgroundPositionX",
|
|
3018
|
+
"backgroundPositionY",
|
|
3019
|
+
]);
|
|
678
3020
|
|
|
679
|
-
|
|
680
|
-
|
|
3021
|
+
function applyPxDefaults(keyframes, name) {
|
|
3022
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
3023
|
+
if (typeof keyframes[i] === "number" && pxValues.has(name)) {
|
|
3024
|
+
keyframes[i] = keyframes[i] + "px";
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
681
3028
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
3029
|
+
function isWaapiSupportedEasing(easing) {
|
|
3030
|
+
return Boolean((typeof easing === "function" && supportsLinearEasing()) ||
|
|
3031
|
+
!easing ||
|
|
3032
|
+
(typeof easing === "string" &&
|
|
3033
|
+
(easing in supportedWaapiEasing || supportsLinearEasing())) ||
|
|
3034
|
+
motionUtils.isBezierDefinition(easing) ||
|
|
3035
|
+
(Array.isArray(easing) && easing.every(isWaapiSupportedEasing)));
|
|
685
3036
|
}
|
|
3037
|
+
|
|
3038
|
+
const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
|
|
3039
|
+
try {
|
|
3040
|
+
document.createElement("div").animate({ opacity: [1] });
|
|
3041
|
+
}
|
|
3042
|
+
catch (e) {
|
|
3043
|
+
return false;
|
|
3044
|
+
}
|
|
3045
|
+
return true;
|
|
3046
|
+
});
|
|
3047
|
+
|
|
686
3048
|
/**
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
* Ensures that time measurements remain consistent within a synchronous context.
|
|
690
|
-
* Usually calling performance.now() twice within the same synchronous context
|
|
691
|
-
* will return different values which isn't useful for animations when we're usually
|
|
692
|
-
* trying to sync animations to the same frame.
|
|
3049
|
+
* A list of values that can be hardware-accelerated.
|
|
693
3050
|
*/
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
},
|
|
707
|
-
};
|
|
3051
|
+
const acceleratedValues = new Set([
|
|
3052
|
+
"opacity",
|
|
3053
|
+
"clipPath",
|
|
3054
|
+
"filter",
|
|
3055
|
+
"transform",
|
|
3056
|
+
// TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
|
|
3057
|
+
// or until we implement support for linear() easing.
|
|
3058
|
+
// "background-color"
|
|
3059
|
+
]);
|
|
3060
|
+
|
|
3061
|
+
const { schedule: microtask, cancel: cancelMicrotask } =
|
|
3062
|
+
/* @__PURE__ */ createRenderBatcher(queueMicrotask, false);
|
|
708
3063
|
|
|
709
3064
|
const isDragging = {
|
|
710
3065
|
x: false,
|
|
@@ -956,6 +3311,28 @@
|
|
|
956
3311
|
return cancelEvents;
|
|
957
3312
|
}
|
|
958
3313
|
|
|
3314
|
+
function getComputedStyle$1(element, name) {
|
|
3315
|
+
const computedStyle = window.getComputedStyle(element);
|
|
3316
|
+
return isCSSVar(name)
|
|
3317
|
+
? computedStyle.getPropertyValue(name)
|
|
3318
|
+
: computedStyle[name];
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
function observeTimeline(update, timeline) {
|
|
3322
|
+
let prevProgress;
|
|
3323
|
+
const onFrame = () => {
|
|
3324
|
+
const { currentTime } = timeline;
|
|
3325
|
+
const percentage = currentTime === null ? 0 : currentTime.value;
|
|
3326
|
+
const progress = percentage / 100;
|
|
3327
|
+
if (prevProgress !== progress) {
|
|
3328
|
+
update(progress);
|
|
3329
|
+
}
|
|
3330
|
+
prevProgress = progress;
|
|
3331
|
+
};
|
|
3332
|
+
frame.update(onFrame, true);
|
|
3333
|
+
return () => cancelFrame(onFrame);
|
|
3334
|
+
}
|
|
3335
|
+
|
|
959
3336
|
function record() {
|
|
960
3337
|
const { value } = statsBuffer;
|
|
961
3338
|
if (value === null) {
|
|
@@ -998,6 +3375,7 @@
|
|
|
998
3375
|
cancelFrame(record);
|
|
999
3376
|
const summary = {
|
|
1000
3377
|
frameloop: {
|
|
3378
|
+
setup: summarise(value.frameloop.setup),
|
|
1001
3379
|
rate: summarise(value.frameloop.rate),
|
|
1002
3380
|
read: summarise(value.frameloop.read),
|
|
1003
3381
|
resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
|
|
@@ -1035,6 +3413,7 @@
|
|
|
1035
3413
|
const newStatsBuffer = statsBuffer;
|
|
1036
3414
|
newStatsBuffer.value = {
|
|
1037
3415
|
frameloop: {
|
|
3416
|
+
setup: [],
|
|
1038
3417
|
rate: [],
|
|
1039
3418
|
read: [],
|
|
1040
3419
|
resolveKeyframes: [],
|
|
@@ -1092,7 +3471,7 @@
|
|
|
1092
3471
|
* This will be replaced by the build step with the latest version number.
|
|
1093
3472
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1094
3473
|
*/
|
|
1095
|
-
this.version = "12.7.
|
|
3474
|
+
this.version = "12.7.5-alpha.0";
|
|
1096
3475
|
/**
|
|
1097
3476
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
1098
3477
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1236,6 +3615,8 @@
|
|
|
1236
3615
|
* @public
|
|
1237
3616
|
*/
|
|
1238
3617
|
set(v, render = true) {
|
|
3618
|
+
if (v === "none")
|
|
3619
|
+
console.trace();
|
|
1239
3620
|
if (!render || !this.passiveEffect) {
|
|
1240
3621
|
this.updateAndNotify(v, render);
|
|
1241
3622
|
}
|
|
@@ -1370,6 +3751,24 @@
|
|
|
1370
3751
|
return new MotionValue(init, options);
|
|
1371
3752
|
}
|
|
1372
3753
|
|
|
3754
|
+
/**
|
|
3755
|
+
* A list of all ValueTypes
|
|
3756
|
+
*/
|
|
3757
|
+
const valueTypes = [...dimensionValueTypes, color, complex];
|
|
3758
|
+
/**
|
|
3759
|
+
* Tests a value against the list of ValueTypes
|
|
3760
|
+
*/
|
|
3761
|
+
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
3762
|
+
|
|
3763
|
+
/**
|
|
3764
|
+
* Provided a value and a ValueType, returns the value as that value type.
|
|
3765
|
+
*/
|
|
3766
|
+
const getValueAsType = (value, type) => {
|
|
3767
|
+
return type && typeof value === "number"
|
|
3768
|
+
? type.transform(value)
|
|
3769
|
+
: value;
|
|
3770
|
+
};
|
|
3771
|
+
|
|
1373
3772
|
function chooseLayerType(valueName) {
|
|
1374
3773
|
if (valueName === "layout")
|
|
1375
3774
|
return "group";
|
|
@@ -1508,11 +3907,11 @@
|
|
|
1508
3907
|
valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
|
|
1509
3908
|
valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
|
|
1510
3909
|
const animation = new NativeAnimation({
|
|
3910
|
+
...valueOptions,
|
|
1511
3911
|
element: document.documentElement,
|
|
1512
3912
|
name: valueName,
|
|
1513
3913
|
pseudoElement: `::view-transition-${type}(${target})`,
|
|
1514
3914
|
keyframes: valueKeyframes,
|
|
1515
|
-
transition: valueOptions,
|
|
1516
3915
|
});
|
|
1517
3916
|
animations.push(animation);
|
|
1518
3917
|
}
|
|
@@ -1553,14 +3952,14 @@
|
|
|
1553
3952
|
duration: animationTransition.duration,
|
|
1554
3953
|
easing,
|
|
1555
3954
|
});
|
|
1556
|
-
animations.push(new
|
|
3955
|
+
animations.push(new NativeAnimationWrapper(animation));
|
|
1557
3956
|
}
|
|
1558
3957
|
else if (hasOpacity(targetDefinition, "enter") &&
|
|
1559
3958
|
hasOpacity(targetDefinition, "exit") &&
|
|
1560
3959
|
effect
|
|
1561
3960
|
.getKeyframes()
|
|
1562
3961
|
.some((keyframe) => keyframe.mixBlendMode)) {
|
|
1563
|
-
animations.push(new
|
|
3962
|
+
animations.push(new NativeAnimationWrapper(animation));
|
|
1564
3963
|
}
|
|
1565
3964
|
else {
|
|
1566
3965
|
animation.cancel();
|
|
@@ -1697,50 +4096,121 @@
|
|
|
1697
4096
|
return acc;
|
|
1698
4097
|
}, {});
|
|
1699
4098
|
|
|
4099
|
+
exports.AsyncMotionValueAnimation = AsyncMotionValueAnimation;
|
|
4100
|
+
exports.DOMKeyframesResolver = DOMKeyframesResolver;
|
|
1700
4101
|
exports.GroupAnimation = GroupAnimation;
|
|
1701
4102
|
exports.GroupAnimationWithThen = GroupAnimationWithThen;
|
|
4103
|
+
exports.JSAnimation = JSAnimation;
|
|
4104
|
+
exports.KeyframeResolver = KeyframeResolver;
|
|
1702
4105
|
exports.MotionValue = MotionValue;
|
|
1703
4106
|
exports.NativeAnimation = NativeAnimation;
|
|
4107
|
+
exports.NativeAnimationExtended = NativeAnimationExtended;
|
|
4108
|
+
exports.NativeAnimationWrapper = NativeAnimationWrapper;
|
|
1704
4109
|
exports.ViewTransitionBuilder = ViewTransitionBuilder;
|
|
4110
|
+
exports.acceleratedValues = acceleratedValues;
|
|
1705
4111
|
exports.activeAnimations = activeAnimations;
|
|
4112
|
+
exports.alpha = alpha;
|
|
4113
|
+
exports.analyseComplexValue = analyseComplexValue;
|
|
4114
|
+
exports.animateValue = animateValue;
|
|
1706
4115
|
exports.animateView = animateView;
|
|
1707
|
-
exports.
|
|
4116
|
+
exports.animationMapKey = animationMapKey;
|
|
4117
|
+
exports.applyPxDefaults = applyPxDefaults;
|
|
1708
4118
|
exports.calcGeneratorDuration = calcGeneratorDuration;
|
|
1709
4119
|
exports.cancelFrame = cancelFrame;
|
|
1710
4120
|
exports.cancelMicrotask = cancelMicrotask;
|
|
1711
4121
|
exports.cancelSync = cancelSync;
|
|
1712
4122
|
exports.collectMotionValues = collectMotionValues;
|
|
4123
|
+
exports.color = color;
|
|
4124
|
+
exports.complex = complex;
|
|
4125
|
+
exports.convertOffsetToTimes = convertOffsetToTimes;
|
|
1713
4126
|
exports.createGeneratorEasing = createGeneratorEasing;
|
|
1714
4127
|
exports.createRenderBatcher = createRenderBatcher;
|
|
1715
4128
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
4129
|
+
exports.defaultEasing = defaultEasing;
|
|
4130
|
+
exports.defaultOffset = defaultOffset;
|
|
4131
|
+
exports.defaultValueTypes = defaultValueTypes;
|
|
4132
|
+
exports.degrees = degrees;
|
|
4133
|
+
exports.dimensionValueTypes = dimensionValueTypes;
|
|
4134
|
+
exports.fillOffset = fillOffset;
|
|
4135
|
+
exports.fillWildcards = fillWildcards;
|
|
4136
|
+
exports.findDimensionValueType = findDimensionValueType;
|
|
4137
|
+
exports.findValueType = findValueType;
|
|
4138
|
+
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
1716
4139
|
exports.frame = frame;
|
|
1717
4140
|
exports.frameData = frameData;
|
|
1718
4141
|
exports.frameSteps = frameSteps;
|
|
1719
4142
|
exports.generateLinearEasing = generateLinearEasing;
|
|
4143
|
+
exports.getAnimatableNone = getAnimatableNone;
|
|
4144
|
+
exports.getAnimationMap = getAnimationMap;
|
|
4145
|
+
exports.getComputedStyle = getComputedStyle$1;
|
|
4146
|
+
exports.getDefaultValueType = getDefaultValueType;
|
|
4147
|
+
exports.getMixer = getMixer;
|
|
4148
|
+
exports.getValueAsType = getValueAsType;
|
|
1720
4149
|
exports.getValueTransition = getValueTransition;
|
|
4150
|
+
exports.getVariableValue = getVariableValue;
|
|
4151
|
+
exports.hex = hex;
|
|
1721
4152
|
exports.hover = hover;
|
|
1722
|
-
exports.
|
|
4153
|
+
exports.hsla = hsla;
|
|
4154
|
+
exports.hslaToRgba = hslaToRgba;
|
|
4155
|
+
exports.inertia = inertia;
|
|
4156
|
+
exports.interpolate = interpolate;
|
|
4157
|
+
exports.invisibleValues = invisibleValues;
|
|
4158
|
+
exports.isCSSVariableName = isCSSVariableName;
|
|
4159
|
+
exports.isCSSVariableToken = isCSSVariableToken;
|
|
1723
4160
|
exports.isDragActive = isDragActive;
|
|
1724
4161
|
exports.isDragging = isDragging;
|
|
1725
4162
|
exports.isGenerator = isGenerator;
|
|
1726
4163
|
exports.isNodeOrChild = isNodeOrChild;
|
|
1727
4164
|
exports.isPrimaryPointer = isPrimaryPointer;
|
|
1728
4165
|
exports.isWaapiSupportedEasing = isWaapiSupportedEasing;
|
|
4166
|
+
exports.keyframes = keyframes;
|
|
1729
4167
|
exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
|
|
1730
4168
|
exports.maxGeneratorDuration = maxGeneratorDuration;
|
|
1731
4169
|
exports.microtask = microtask;
|
|
4170
|
+
exports.mix = mix;
|
|
4171
|
+
exports.mixArray = mixArray;
|
|
4172
|
+
exports.mixColor = mixColor;
|
|
4173
|
+
exports.mixComplex = mixComplex;
|
|
4174
|
+
exports.mixImmediate = mixImmediate;
|
|
4175
|
+
exports.mixLinearColor = mixLinearColor;
|
|
4176
|
+
exports.mixNumber = mixNumber$1;
|
|
4177
|
+
exports.mixObject = mixObject;
|
|
4178
|
+
exports.mixVisibility = mixVisibility;
|
|
1732
4179
|
exports.motionValue = motionValue;
|
|
4180
|
+
exports.number = number;
|
|
4181
|
+
exports.numberValueTypes = numberValueTypes;
|
|
4182
|
+
exports.observeTimeline = observeTimeline;
|
|
4183
|
+
exports.parseCSSVariable = parseCSSVariable;
|
|
4184
|
+
exports.parseValueFromTransform = parseValueFromTransform;
|
|
4185
|
+
exports.percent = percent;
|
|
4186
|
+
exports.positionalKeys = positionalKeys;
|
|
1733
4187
|
exports.press = press;
|
|
4188
|
+
exports.progressPercentage = progressPercentage;
|
|
4189
|
+
exports.px = px;
|
|
4190
|
+
exports.readTransformValue = readTransformValue;
|
|
1734
4191
|
exports.recordStats = recordStats;
|
|
1735
4192
|
exports.resolveElements = resolveElements;
|
|
4193
|
+
exports.rgbUnit = rgbUnit;
|
|
4194
|
+
exports.rgba = rgba;
|
|
4195
|
+
exports.scale = scale;
|
|
1736
4196
|
exports.setDragLock = setDragLock;
|
|
4197
|
+
exports.setStyle = setStyle;
|
|
4198
|
+
exports.spring = spring;
|
|
1737
4199
|
exports.startWaapiAnimation = startWaapiAnimation;
|
|
1738
4200
|
exports.statsBuffer = statsBuffer;
|
|
1739
4201
|
exports.supportedWaapiEasing = supportedWaapiEasing;
|
|
4202
|
+
exports.supportsBrowserAnimation = supportsBrowserAnimation;
|
|
1740
4203
|
exports.supportsFlags = supportsFlags;
|
|
1741
4204
|
exports.supportsLinearEasing = supportsLinearEasing;
|
|
4205
|
+
exports.supportsPartialKeyframes = supportsPartialKeyframes;
|
|
1742
4206
|
exports.supportsScrollTimeline = supportsScrollTimeline;
|
|
1743
4207
|
exports.sync = sync;
|
|
4208
|
+
exports.testValueType = testValueType;
|
|
1744
4209
|
exports.time = time;
|
|
4210
|
+
exports.transformPropOrder = transformPropOrder;
|
|
4211
|
+
exports.transformProps = transformProps;
|
|
4212
|
+
exports.transformValueTypes = transformValueTypes;
|
|
4213
|
+
exports.vh = vh;
|
|
4214
|
+
exports.vw = vw;
|
|
1745
4215
|
|
|
1746
4216
|
}));
|