motion-dom 12.4.10 → 12.5.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 +662 -29
- package/dist/es/animation/waapi/NativeAnimationControls.mjs +3 -3
- package/dist/es/frameloop/batcher.mjs +69 -0
- package/dist/es/frameloop/frame.mjs +6 -0
- package/dist/es/frameloop/microtask.mjs +6 -0
- package/dist/es/frameloop/order.mjs +10 -0
- package/dist/es/frameloop/render-step.mjs +92 -0
- package/dist/es/frameloop/sync-time.mjs +31 -0
- package/dist/es/index.mjs +12 -4
- package/dist/es/stats/animation-count.mjs +7 -0
- package/dist/es/stats/buffer.mjs +6 -0
- package/dist/es/stats/index.mjs +113 -0
- package/dist/es/utils/supports/scroll-timeline.mjs +1 -1
- package/dist/es/value/index.mjs +311 -0
- package/dist/index.d.ts +341 -20
- package/dist/motion-dom.dev.js +662 -29
- package/dist/motion-dom.js +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { warnOnce, SubscriptionManager, velocityPerSecond } from 'motion-utils';
|
|
2
|
+
import { frame } from '../frameloop/frame.mjs';
|
|
3
|
+
import { time } from '../frameloop/sync-time.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Maximum time between the value of two frames, beyond which we
|
|
7
|
+
* assume the velocity has since been 0.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_VELOCITY_DELTA = 30;
|
|
10
|
+
const isFloat = (value) => {
|
|
11
|
+
return !isNaN(parseFloat(value));
|
|
12
|
+
};
|
|
13
|
+
const collectMotionValues = {
|
|
14
|
+
current: undefined,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `MotionValue` is used to track the state and velocity of motion values.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class MotionValue {
|
|
22
|
+
/**
|
|
23
|
+
* @param init - The initiating value
|
|
24
|
+
* @param config - Optional configuration options
|
|
25
|
+
*
|
|
26
|
+
* - `transformer`: A function to transform incoming values with.
|
|
27
|
+
*/
|
|
28
|
+
constructor(init, options = {}) {
|
|
29
|
+
/**
|
|
30
|
+
* This will be replaced by the build step with the latest version number.
|
|
31
|
+
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
32
|
+
*/
|
|
33
|
+
this.version = "12.5.0";
|
|
34
|
+
/**
|
|
35
|
+
* Tracks whether this value can output a velocity. Currently this is only true
|
|
36
|
+
* if the value is numerical, but we might be able to widen the scope here and support
|
|
37
|
+
* other value types.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
this.canTrackVelocity = null;
|
|
42
|
+
/**
|
|
43
|
+
* An object containing a SubscriptionManager for each active event.
|
|
44
|
+
*/
|
|
45
|
+
this.events = {};
|
|
46
|
+
this.updateAndNotify = (v, render = true) => {
|
|
47
|
+
const currentTime = time.now();
|
|
48
|
+
/**
|
|
49
|
+
* If we're updating the value during another frame or eventloop
|
|
50
|
+
* than the previous frame, then the we set the previous frame value
|
|
51
|
+
* to current.
|
|
52
|
+
*/
|
|
53
|
+
if (this.updatedAt !== currentTime) {
|
|
54
|
+
this.setPrevFrameValue();
|
|
55
|
+
}
|
|
56
|
+
this.prev = this.current;
|
|
57
|
+
this.setCurrent(v);
|
|
58
|
+
// Update update subscribers
|
|
59
|
+
if (this.current !== this.prev && this.events.change) {
|
|
60
|
+
this.events.change.notify(this.current);
|
|
61
|
+
}
|
|
62
|
+
// Update render subscribers
|
|
63
|
+
if (render && this.events.renderRequest) {
|
|
64
|
+
this.events.renderRequest.notify(this.current);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.hasAnimated = false;
|
|
68
|
+
this.setCurrent(init);
|
|
69
|
+
this.owner = options.owner;
|
|
70
|
+
}
|
|
71
|
+
setCurrent(current) {
|
|
72
|
+
this.current = current;
|
|
73
|
+
this.updatedAt = time.now();
|
|
74
|
+
if (this.canTrackVelocity === null && current !== undefined) {
|
|
75
|
+
this.canTrackVelocity = isFloat(this.current);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
setPrevFrameValue(prevFrameValue = this.current) {
|
|
79
|
+
this.prevFrameValue = prevFrameValue;
|
|
80
|
+
this.prevUpdatedAt = this.updatedAt;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Adds a function that will be notified when the `MotionValue` is updated.
|
|
84
|
+
*
|
|
85
|
+
* It returns a function that, when called, will cancel the subscription.
|
|
86
|
+
*
|
|
87
|
+
* When calling `onChange` inside a React component, it should be wrapped with the
|
|
88
|
+
* `useEffect` hook. As it returns an unsubscribe function, this should be returned
|
|
89
|
+
* from the `useEffect` function to ensure you don't add duplicate subscribers..
|
|
90
|
+
*
|
|
91
|
+
* ```jsx
|
|
92
|
+
* export const MyComponent = () => {
|
|
93
|
+
* const x = useMotionValue(0)
|
|
94
|
+
* const y = useMotionValue(0)
|
|
95
|
+
* const opacity = useMotionValue(1)
|
|
96
|
+
*
|
|
97
|
+
* useEffect(() => {
|
|
98
|
+
* function updateOpacity() {
|
|
99
|
+
* const maxXY = Math.max(x.get(), y.get())
|
|
100
|
+
* const newOpacity = transform(maxXY, [0, 100], [1, 0])
|
|
101
|
+
* opacity.set(newOpacity)
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* const unsubscribeX = x.on("change", updateOpacity)
|
|
105
|
+
* const unsubscribeY = y.on("change", updateOpacity)
|
|
106
|
+
*
|
|
107
|
+
* return () => {
|
|
108
|
+
* unsubscribeX()
|
|
109
|
+
* unsubscribeY()
|
|
110
|
+
* }
|
|
111
|
+
* }, [])
|
|
112
|
+
*
|
|
113
|
+
* return <motion.div style={{ x }} />
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @param subscriber - A function that receives the latest value.
|
|
118
|
+
* @returns A function that, when called, will cancel this subscription.
|
|
119
|
+
*
|
|
120
|
+
* @deprecated
|
|
121
|
+
*/
|
|
122
|
+
onChange(subscription) {
|
|
123
|
+
if (process.env.NODE_ENV !== "production") {
|
|
124
|
+
warnOnce(false, `value.onChange(callback) is deprecated. Switch to value.on("change", callback).`);
|
|
125
|
+
}
|
|
126
|
+
return this.on("change", subscription);
|
|
127
|
+
}
|
|
128
|
+
on(eventName, callback) {
|
|
129
|
+
if (!this.events[eventName]) {
|
|
130
|
+
this.events[eventName] = new SubscriptionManager();
|
|
131
|
+
}
|
|
132
|
+
const unsubscribe = this.events[eventName].add(callback);
|
|
133
|
+
if (eventName === "change") {
|
|
134
|
+
return () => {
|
|
135
|
+
unsubscribe();
|
|
136
|
+
/**
|
|
137
|
+
* If we have no more change listeners by the start
|
|
138
|
+
* of the next frame, stop active animations.
|
|
139
|
+
*/
|
|
140
|
+
frame.read(() => {
|
|
141
|
+
if (!this.events.change.getSize()) {
|
|
142
|
+
this.stop();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return unsubscribe;
|
|
148
|
+
}
|
|
149
|
+
clearListeners() {
|
|
150
|
+
for (const eventManagers in this.events) {
|
|
151
|
+
this.events[eventManagers].clear();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Attaches a passive effect to the `MotionValue`.
|
|
156
|
+
*/
|
|
157
|
+
attach(passiveEffect, stopPassiveEffect) {
|
|
158
|
+
this.passiveEffect = passiveEffect;
|
|
159
|
+
this.stopPassiveEffect = stopPassiveEffect;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets the state of the `MotionValue`.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
*
|
|
166
|
+
* ```jsx
|
|
167
|
+
* const x = useMotionValue(0)
|
|
168
|
+
* x.set(10)
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @param latest - Latest value to set.
|
|
172
|
+
* @param render - Whether to notify render subscribers. Defaults to `true`
|
|
173
|
+
*
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
set(v, render = true) {
|
|
177
|
+
if (!render || !this.passiveEffect) {
|
|
178
|
+
this.updateAndNotify(v, render);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.passiveEffect(v, this.updateAndNotify);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
setWithVelocity(prev, current, delta) {
|
|
185
|
+
this.set(current);
|
|
186
|
+
this.prev = undefined;
|
|
187
|
+
this.prevFrameValue = prev;
|
|
188
|
+
this.prevUpdatedAt = this.updatedAt - delta;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Set the state of the `MotionValue`, stopping any active animations,
|
|
192
|
+
* effects, and resets velocity to `0`.
|
|
193
|
+
*/
|
|
194
|
+
jump(v, endAnimation = true) {
|
|
195
|
+
this.updateAndNotify(v);
|
|
196
|
+
this.prev = v;
|
|
197
|
+
this.prevUpdatedAt = this.prevFrameValue = undefined;
|
|
198
|
+
endAnimation && this.stop();
|
|
199
|
+
if (this.stopPassiveEffect)
|
|
200
|
+
this.stopPassiveEffect();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Returns the latest state of `MotionValue`
|
|
204
|
+
*
|
|
205
|
+
* @returns - The latest state of `MotionValue`
|
|
206
|
+
*
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
get() {
|
|
210
|
+
if (collectMotionValues.current) {
|
|
211
|
+
collectMotionValues.current.push(this);
|
|
212
|
+
}
|
|
213
|
+
return this.current;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* @public
|
|
217
|
+
*/
|
|
218
|
+
getPrevious() {
|
|
219
|
+
return this.prev;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Returns the latest velocity of `MotionValue`
|
|
223
|
+
*
|
|
224
|
+
* @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
|
|
225
|
+
*
|
|
226
|
+
* @public
|
|
227
|
+
*/
|
|
228
|
+
getVelocity() {
|
|
229
|
+
const currentTime = time.now();
|
|
230
|
+
if (!this.canTrackVelocity ||
|
|
231
|
+
this.prevFrameValue === undefined ||
|
|
232
|
+
currentTime - this.updatedAt > MAX_VELOCITY_DELTA) {
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
const delta = Math.min(this.updatedAt - this.prevUpdatedAt, MAX_VELOCITY_DELTA);
|
|
236
|
+
// Casts because of parseFloat's poor typing
|
|
237
|
+
return velocityPerSecond(parseFloat(this.current) -
|
|
238
|
+
parseFloat(this.prevFrameValue), delta);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Registers a new animation to control this `MotionValue`. Only one
|
|
242
|
+
* animation can drive a `MotionValue` at one time.
|
|
243
|
+
*
|
|
244
|
+
* ```jsx
|
|
245
|
+
* value.start()
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* @param animation - A function that starts the provided animation
|
|
249
|
+
*/
|
|
250
|
+
start(startAnimation) {
|
|
251
|
+
this.stop();
|
|
252
|
+
return new Promise((resolve) => {
|
|
253
|
+
this.hasAnimated = true;
|
|
254
|
+
this.animation = startAnimation(resolve);
|
|
255
|
+
if (this.events.animationStart) {
|
|
256
|
+
this.events.animationStart.notify();
|
|
257
|
+
}
|
|
258
|
+
}).then(() => {
|
|
259
|
+
if (this.events.animationComplete) {
|
|
260
|
+
this.events.animationComplete.notify();
|
|
261
|
+
}
|
|
262
|
+
this.clearAnimation();
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Stop the currently active animation.
|
|
267
|
+
*
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
stop() {
|
|
271
|
+
if (this.animation) {
|
|
272
|
+
this.animation.stop();
|
|
273
|
+
if (this.events.animationCancel) {
|
|
274
|
+
this.events.animationCancel.notify();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.clearAnimation();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns `true` if this value is currently animating.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
isAnimating() {
|
|
285
|
+
return !!this.animation;
|
|
286
|
+
}
|
|
287
|
+
clearAnimation() {
|
|
288
|
+
delete this.animation;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Destroy and clean up subscribers to this `MotionValue`.
|
|
292
|
+
*
|
|
293
|
+
* The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
|
|
294
|
+
* handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
|
|
295
|
+
* created a `MotionValue` via the `motionValue` function.
|
|
296
|
+
*
|
|
297
|
+
* @public
|
|
298
|
+
*/
|
|
299
|
+
destroy() {
|
|
300
|
+
this.clearListeners();
|
|
301
|
+
this.stop();
|
|
302
|
+
if (this.stopPassiveEffect) {
|
|
303
|
+
this.stopPassiveEffect();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function motionValue(init, options) {
|
|
308
|
+
return new MotionValue(init, options);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export { MotionValue, collectMotionValues, motionValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -329,6 +329,7 @@ interface ValueAnimationOptions<V extends string | number = number> extends Valu
|
|
|
329
329
|
name?: string;
|
|
330
330
|
from?: V;
|
|
331
331
|
isGenerator?: boolean;
|
|
332
|
+
allowFlatten?: boolean;
|
|
332
333
|
}
|
|
333
334
|
type GeneratorFactory = (options: ValueAnimationOptions<any>) => KeyframeGenerator<any>;
|
|
334
335
|
type AnimationGeneratorType = GeneratorFactory | "decay" | "spring" | "keyframes" | "tween" | "inertia";
|
|
@@ -580,6 +581,63 @@ declare function mapEasingToNativeEasing(easing: Easing | Easing[] | undefined,
|
|
|
580
581
|
|
|
581
582
|
declare const generateLinearEasing: (easing: EasingFunction, duration: number, resolution?: number) => string;
|
|
582
583
|
|
|
584
|
+
declare const frame: Batcher;
|
|
585
|
+
declare const cancelFrame: (process: Process) => void;
|
|
586
|
+
declare const frameData: FrameData;
|
|
587
|
+
declare const frameSteps: Steps;
|
|
588
|
+
|
|
589
|
+
type Process = (data: FrameData) => void;
|
|
590
|
+
type Schedule = (process: Process, keepAlive?: boolean, immediate?: boolean) => Process;
|
|
591
|
+
interface Step {
|
|
592
|
+
schedule: Schedule;
|
|
593
|
+
cancel: (process: Process) => void;
|
|
594
|
+
process: (data: FrameData) => void;
|
|
595
|
+
}
|
|
596
|
+
type StepId = "read" | "resolveKeyframes" | "update" | "preRender" | "render" | "postRender";
|
|
597
|
+
type CancelProcess = (process: Process) => void;
|
|
598
|
+
type Batcher = {
|
|
599
|
+
[key in StepId]: Schedule;
|
|
600
|
+
};
|
|
601
|
+
type Steps = {
|
|
602
|
+
[key in StepId]: Step;
|
|
603
|
+
};
|
|
604
|
+
interface FrameData {
|
|
605
|
+
delta: number;
|
|
606
|
+
timestamp: number;
|
|
607
|
+
isProcessing: boolean;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
declare function createRenderBatcher(scheduleNextBatch: (callback: Function) => void, allowKeepAlive: boolean): {
|
|
611
|
+
schedule: Batcher;
|
|
612
|
+
cancel: (process: Process) => void;
|
|
613
|
+
state: FrameData;
|
|
614
|
+
steps: Steps;
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
declare const microtask: Batcher;
|
|
618
|
+
declare const cancelMicrotask: (process: Process) => void;
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* An eventloop-synchronous alternative to performance.now().
|
|
622
|
+
*
|
|
623
|
+
* Ensures that time measurements remain consistent within a synchronous context.
|
|
624
|
+
* Usually calling performance.now() twice within the same synchronous context
|
|
625
|
+
* will return different values which isn't useful for animations when we're usually
|
|
626
|
+
* trying to sync animations to the same frame.
|
|
627
|
+
*/
|
|
628
|
+
declare const time: {
|
|
629
|
+
now: () => number;
|
|
630
|
+
set: (newTime: number) => void;
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
declare const isDragging: {
|
|
634
|
+
x: boolean;
|
|
635
|
+
y: boolean;
|
|
636
|
+
};
|
|
637
|
+
declare function isDragActive(): boolean;
|
|
638
|
+
|
|
639
|
+
declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
|
|
640
|
+
|
|
583
641
|
type ElementOrSelector = Element | Element[] | NodeListOf<Element> | string;
|
|
584
642
|
interface WithQuerySelectorAll {
|
|
585
643
|
querySelectorAll: Element["querySelectorAll"];
|
|
@@ -670,6 +728,69 @@ declare function press(targetOrSelector: ElementOrSelector, onPressStart: OnPres
|
|
|
670
728
|
|
|
671
729
|
declare function capturePointer(event: PointerEvent, action: "set" | "release"): void;
|
|
672
730
|
|
|
731
|
+
/**
|
|
732
|
+
* Recursively traverse up the tree to check whether the provided child node
|
|
733
|
+
* is the parent or a descendant of it.
|
|
734
|
+
*
|
|
735
|
+
* @param parent - Element to find
|
|
736
|
+
* @param child - Element to test against parent
|
|
737
|
+
*/
|
|
738
|
+
declare const isNodeOrChild: (parent: Element | null, child?: Element | null) => boolean;
|
|
739
|
+
|
|
740
|
+
declare const isPrimaryPointer: (event: PointerEvent) => boolean;
|
|
741
|
+
|
|
742
|
+
declare const stepsOrder: StepId[];
|
|
743
|
+
type StepNames = (typeof stepsOrder)[number];
|
|
744
|
+
|
|
745
|
+
interface Summary {
|
|
746
|
+
min: number;
|
|
747
|
+
max: number;
|
|
748
|
+
avg: number;
|
|
749
|
+
}
|
|
750
|
+
type FrameloopStatNames = "rate" | StepNames;
|
|
751
|
+
interface Stats<T> {
|
|
752
|
+
frameloop: {
|
|
753
|
+
[key in FrameloopStatNames]: T;
|
|
754
|
+
};
|
|
755
|
+
animations: {
|
|
756
|
+
mainThread: T;
|
|
757
|
+
waapi: T;
|
|
758
|
+
layout: T;
|
|
759
|
+
};
|
|
760
|
+
layoutProjection: {
|
|
761
|
+
nodes: T;
|
|
762
|
+
calculatedTargetDeltas: T;
|
|
763
|
+
calculatedProjections: T;
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
type StatsBuffer = number[];
|
|
767
|
+
type FrameStats = Stats<number>;
|
|
768
|
+
type StatsRecording = Stats<StatsBuffer>;
|
|
769
|
+
type StatsSummary = Stats<Summary>;
|
|
770
|
+
|
|
771
|
+
declare function reportStats(): StatsSummary;
|
|
772
|
+
declare function recordStats(): typeof reportStats;
|
|
773
|
+
|
|
774
|
+
declare const activeAnimations: {
|
|
775
|
+
layout: number;
|
|
776
|
+
mainThread: number;
|
|
777
|
+
waapi: number;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
type InactiveStatsBuffer = {
|
|
781
|
+
value: null;
|
|
782
|
+
addProjectionMetrics: null;
|
|
783
|
+
};
|
|
784
|
+
type ActiveStatsBuffer = {
|
|
785
|
+
value: StatsRecording;
|
|
786
|
+
addProjectionMetrics: (metrics: {
|
|
787
|
+
nodes: number;
|
|
788
|
+
calculatedTargetDeltas: number;
|
|
789
|
+
calculatedProjections: number;
|
|
790
|
+
}) => void;
|
|
791
|
+
};
|
|
792
|
+
declare const statsBuffer: InactiveStatsBuffer | ActiveStatsBuffer;
|
|
793
|
+
|
|
673
794
|
declare const isBezierDefinition: (easing: Easing | Easing[]) => easing is BezierDefinition;
|
|
674
795
|
|
|
675
796
|
/**
|
|
@@ -694,6 +815,225 @@ declare class ScrollTimeline implements ProgressTimeline {
|
|
|
694
815
|
}
|
|
695
816
|
declare const supportsScrollTimeline: () => boolean;
|
|
696
817
|
|
|
818
|
+
type Transformer<T> = (v: T) => T;
|
|
819
|
+
/**
|
|
820
|
+
* @public
|
|
821
|
+
*/
|
|
822
|
+
type Subscriber<T> = (v: T) => void;
|
|
823
|
+
/**
|
|
824
|
+
* @public
|
|
825
|
+
*/
|
|
826
|
+
type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void;
|
|
827
|
+
type StartAnimation = (complete: () => void) => AnimationPlaybackControls | undefined;
|
|
828
|
+
interface MotionValueEventCallbacks<V> {
|
|
829
|
+
animationStart: () => void;
|
|
830
|
+
animationComplete: () => void;
|
|
831
|
+
animationCancel: () => void;
|
|
832
|
+
change: (latestValue: V) => void;
|
|
833
|
+
renderRequest: () => void;
|
|
834
|
+
}
|
|
835
|
+
interface ResolvedValues {
|
|
836
|
+
[key: string]: string | number;
|
|
837
|
+
}
|
|
838
|
+
interface Owner {
|
|
839
|
+
current: HTMLElement | unknown;
|
|
840
|
+
getProps: () => {
|
|
841
|
+
onUpdate?: (latest: ResolvedValues) => void;
|
|
842
|
+
transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
interface MotionValueOptions {
|
|
846
|
+
owner?: Owner;
|
|
847
|
+
}
|
|
848
|
+
declare const collectMotionValues: {
|
|
849
|
+
current: MotionValue[] | undefined;
|
|
850
|
+
};
|
|
851
|
+
/**
|
|
852
|
+
* `MotionValue` is used to track the state and velocity of motion values.
|
|
853
|
+
*
|
|
854
|
+
* @public
|
|
855
|
+
*/
|
|
856
|
+
declare class MotionValue<V = any> {
|
|
857
|
+
/**
|
|
858
|
+
* This will be replaced by the build step with the latest version number.
|
|
859
|
+
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
860
|
+
*/
|
|
861
|
+
version: string;
|
|
862
|
+
/**
|
|
863
|
+
* If a MotionValue has an owner, it was created internally within Motion
|
|
864
|
+
* and therefore has no external listeners. It is therefore safe to animate via WAAPI.
|
|
865
|
+
*/
|
|
866
|
+
owner?: Owner;
|
|
867
|
+
/**
|
|
868
|
+
* The current state of the `MotionValue`.
|
|
869
|
+
*/
|
|
870
|
+
private current;
|
|
871
|
+
/**
|
|
872
|
+
* The previous state of the `MotionValue`.
|
|
873
|
+
*/
|
|
874
|
+
private prev;
|
|
875
|
+
/**
|
|
876
|
+
* The previous state of the `MotionValue` at the end of the previous frame.
|
|
877
|
+
*/
|
|
878
|
+
private prevFrameValue;
|
|
879
|
+
/**
|
|
880
|
+
* The last time the `MotionValue` was updated.
|
|
881
|
+
*/
|
|
882
|
+
updatedAt: number;
|
|
883
|
+
/**
|
|
884
|
+
* The time `prevFrameValue` was updated.
|
|
885
|
+
*/
|
|
886
|
+
prevUpdatedAt: number | undefined;
|
|
887
|
+
private stopPassiveEffect?;
|
|
888
|
+
/**
|
|
889
|
+
* A reference to the currently-controlling animation.
|
|
890
|
+
*/
|
|
891
|
+
animation?: AnimationPlaybackControls;
|
|
892
|
+
/**
|
|
893
|
+
* Tracks whether this value should be removed
|
|
894
|
+
*/
|
|
895
|
+
liveStyle?: boolean;
|
|
896
|
+
/**
|
|
897
|
+
* @param init - The initiating value
|
|
898
|
+
* @param config - Optional configuration options
|
|
899
|
+
*
|
|
900
|
+
* - `transformer`: A function to transform incoming values with.
|
|
901
|
+
*/
|
|
902
|
+
constructor(init: V, options?: MotionValueOptions);
|
|
903
|
+
setCurrent(current: V): void;
|
|
904
|
+
setPrevFrameValue(prevFrameValue?: V | undefined): void;
|
|
905
|
+
/**
|
|
906
|
+
* Adds a function that will be notified when the `MotionValue` is updated.
|
|
907
|
+
*
|
|
908
|
+
* It returns a function that, when called, will cancel the subscription.
|
|
909
|
+
*
|
|
910
|
+
* When calling `onChange` inside a React component, it should be wrapped with the
|
|
911
|
+
* `useEffect` hook. As it returns an unsubscribe function, this should be returned
|
|
912
|
+
* from the `useEffect` function to ensure you don't add duplicate subscribers..
|
|
913
|
+
*
|
|
914
|
+
* ```jsx
|
|
915
|
+
* export const MyComponent = () => {
|
|
916
|
+
* const x = useMotionValue(0)
|
|
917
|
+
* const y = useMotionValue(0)
|
|
918
|
+
* const opacity = useMotionValue(1)
|
|
919
|
+
*
|
|
920
|
+
* useEffect(() => {
|
|
921
|
+
* function updateOpacity() {
|
|
922
|
+
* const maxXY = Math.max(x.get(), y.get())
|
|
923
|
+
* const newOpacity = transform(maxXY, [0, 100], [1, 0])
|
|
924
|
+
* opacity.set(newOpacity)
|
|
925
|
+
* }
|
|
926
|
+
*
|
|
927
|
+
* const unsubscribeX = x.on("change", updateOpacity)
|
|
928
|
+
* const unsubscribeY = y.on("change", updateOpacity)
|
|
929
|
+
*
|
|
930
|
+
* return () => {
|
|
931
|
+
* unsubscribeX()
|
|
932
|
+
* unsubscribeY()
|
|
933
|
+
* }
|
|
934
|
+
* }, [])
|
|
935
|
+
*
|
|
936
|
+
* return <motion.div style={{ x }} />
|
|
937
|
+
* }
|
|
938
|
+
* ```
|
|
939
|
+
*
|
|
940
|
+
* @param subscriber - A function that receives the latest value.
|
|
941
|
+
* @returns A function that, when called, will cancel this subscription.
|
|
942
|
+
*
|
|
943
|
+
* @deprecated
|
|
944
|
+
*/
|
|
945
|
+
onChange(subscription: Subscriber<V>): () => void;
|
|
946
|
+
/**
|
|
947
|
+
* An object containing a SubscriptionManager for each active event.
|
|
948
|
+
*/
|
|
949
|
+
private events;
|
|
950
|
+
on<EventName extends keyof MotionValueEventCallbacks<V>>(eventName: EventName, callback: MotionValueEventCallbacks<V>[EventName]): VoidFunction;
|
|
951
|
+
clearListeners(): void;
|
|
952
|
+
/**
|
|
953
|
+
* Attaches a passive effect to the `MotionValue`.
|
|
954
|
+
*/
|
|
955
|
+
attach(passiveEffect: PassiveEffect<V>, stopPassiveEffect: VoidFunction): void;
|
|
956
|
+
/**
|
|
957
|
+
* Sets the state of the `MotionValue`.
|
|
958
|
+
*
|
|
959
|
+
* @remarks
|
|
960
|
+
*
|
|
961
|
+
* ```jsx
|
|
962
|
+
* const x = useMotionValue(0)
|
|
963
|
+
* x.set(10)
|
|
964
|
+
* ```
|
|
965
|
+
*
|
|
966
|
+
* @param latest - Latest value to set.
|
|
967
|
+
* @param render - Whether to notify render subscribers. Defaults to `true`
|
|
968
|
+
*
|
|
969
|
+
* @public
|
|
970
|
+
*/
|
|
971
|
+
set(v: V, render?: boolean): void;
|
|
972
|
+
setWithVelocity(prev: V, current: V, delta: number): void;
|
|
973
|
+
/**
|
|
974
|
+
* Set the state of the `MotionValue`, stopping any active animations,
|
|
975
|
+
* effects, and resets velocity to `0`.
|
|
976
|
+
*/
|
|
977
|
+
jump(v: V, endAnimation?: boolean): void;
|
|
978
|
+
updateAndNotify: (v: V, render?: boolean) => void;
|
|
979
|
+
/**
|
|
980
|
+
* Returns the latest state of `MotionValue`
|
|
981
|
+
*
|
|
982
|
+
* @returns - The latest state of `MotionValue`
|
|
983
|
+
*
|
|
984
|
+
* @public
|
|
985
|
+
*/
|
|
986
|
+
get(): NonNullable<V>;
|
|
987
|
+
/**
|
|
988
|
+
* @public
|
|
989
|
+
*/
|
|
990
|
+
getPrevious(): V | undefined;
|
|
991
|
+
/**
|
|
992
|
+
* Returns the latest velocity of `MotionValue`
|
|
993
|
+
*
|
|
994
|
+
* @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
|
|
995
|
+
*
|
|
996
|
+
* @public
|
|
997
|
+
*/
|
|
998
|
+
getVelocity(): number;
|
|
999
|
+
hasAnimated: boolean;
|
|
1000
|
+
/**
|
|
1001
|
+
* Registers a new animation to control this `MotionValue`. Only one
|
|
1002
|
+
* animation can drive a `MotionValue` at one time.
|
|
1003
|
+
*
|
|
1004
|
+
* ```jsx
|
|
1005
|
+
* value.start()
|
|
1006
|
+
* ```
|
|
1007
|
+
*
|
|
1008
|
+
* @param animation - A function that starts the provided animation
|
|
1009
|
+
*/
|
|
1010
|
+
start(startAnimation: StartAnimation): Promise<void>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Stop the currently active animation.
|
|
1013
|
+
*
|
|
1014
|
+
* @public
|
|
1015
|
+
*/
|
|
1016
|
+
stop(): void;
|
|
1017
|
+
/**
|
|
1018
|
+
* Returns `true` if this value is currently animating.
|
|
1019
|
+
*
|
|
1020
|
+
* @public
|
|
1021
|
+
*/
|
|
1022
|
+
isAnimating(): boolean;
|
|
1023
|
+
private clearAnimation;
|
|
1024
|
+
/**
|
|
1025
|
+
* Destroy and clean up subscribers to this `MotionValue`.
|
|
1026
|
+
*
|
|
1027
|
+
* The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
|
|
1028
|
+
* handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
|
|
1029
|
+
* created a `MotionValue` via the `motionValue` function.
|
|
1030
|
+
*
|
|
1031
|
+
* @public
|
|
1032
|
+
*/
|
|
1033
|
+
destroy(): void;
|
|
1034
|
+
}
|
|
1035
|
+
declare function motionValue<V>(init: V, options?: MotionValueOptions): MotionValue<V>;
|
|
1036
|
+
|
|
697
1037
|
type ViewTransitionAnimationDefinition = {
|
|
698
1038
|
keyframes: DOMKeyframesDefinition;
|
|
699
1039
|
options: AnimationOptions;
|
|
@@ -733,23 +1073,4 @@ declare class ViewTransitionBuilder {
|
|
|
733
1073
|
}
|
|
734
1074
|
declare function view(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
|
|
735
1075
|
|
|
736
|
-
|
|
737
|
-
x: boolean;
|
|
738
|
-
y: boolean;
|
|
739
|
-
};
|
|
740
|
-
declare function isDragActive(): boolean;
|
|
741
|
-
|
|
742
|
-
declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Recursively traverse up the tree to check whether the provided child node
|
|
746
|
-
* is the parent or a descendant of it.
|
|
747
|
-
*
|
|
748
|
-
* @param parent - Element to find
|
|
749
|
-
* @param child - Element to test against parent
|
|
750
|
-
*/
|
|
751
|
-
declare const isNodeOrChild: (parent: Element | null, child?: Element | null) => boolean;
|
|
752
|
-
|
|
753
|
-
declare const isPrimaryPointer: (event: PointerEvent) => boolean;
|
|
754
|
-
|
|
755
|
-
export { type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type BezierDefinition, type CSSStyleDeclarationWithTransform, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type GeneratorFactory, GroupPlaybackControls, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type PointerEventOptions, type PressGestureInfo, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type SelectorCache, type SpringOptions, type StyleKeyframesDefinition, type StyleTransitions, type Target, type TransformProperties, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, attachTimeline, calcGeneratorDuration, capturePointer, createGeneratorEasing, cubicBezierAsString, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, press, resolveElements, setDragLock, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, view };
|
|
1076
|
+
export { type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, GroupPlaybackControls, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask, capturePointer, collectMotionValues, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, frame, frameData, frameSteps, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, microtask, motionValue, press, recordStats, resolveElements, setDragLock, statsBuffer, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, time, view };
|