motion-dom 14.10.0 → 14.11.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 +886 -126
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs +21 -15
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +15 -4
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +44 -16
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/get-final.mjs +18 -4
- package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +155 -42
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +4 -0
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
- package/dist/es/gestures/pinch/index.mjs +552 -0
- package/dist/es/gestures/pinch/index.mjs.map +1 -0
- package/dist/es/gestures/press/index.mjs +6 -2
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +39 -17
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/render/utils/get-variant-context.mjs.map +1 -1
- package/dist/es/render/utils/variant-props.mjs +1 -0
- package/dist/es/render/utils/variant-props.mjs.map +1 -1
- package/dist/es/value/index.mjs +24 -20
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/utils/animatable-none.mjs +13 -1
- package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
- package/dist/index.d.ts +360 -105
- package/dist/motion-dom.dev.js +886 -126
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-pinch.js +2 -0
- package/dist/size-rollup-pinch.js.map +1 -0
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +6 -2
|
@@ -46,7 +46,8 @@ const buildAhead = 100;
|
|
|
46
46
|
/**
|
|
47
47
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
48
48
|
*/
|
|
49
|
-
const
|
|
49
|
+
const nativeEasings = new Set(["linear", "easeIn", "easeOut", "easeInOut"]);
|
|
50
|
+
const isNativeEasing = (ease) => nativeEasings.has(ease);
|
|
50
51
|
/**
|
|
51
52
|
* The last trace of each easing WAAPI can't run into linear(), with its
|
|
52
53
|
* number of samples, so the elements of a sequence that share an easing
|
|
@@ -130,6 +131,54 @@ function canAccelerateTransform(options) {
|
|
|
130
131
|
*/
|
|
131
132
|
!needsMixer(options));
|
|
132
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Starting or stopping tells the group to update its WAAPI animation.
|
|
136
|
+
* The frame loop driver is only made once the group is on the main
|
|
137
|
+
* thread, as accelerated animations never tick.
|
|
138
|
+
*/
|
|
139
|
+
class TransformDriver {
|
|
140
|
+
constructor(element, update, makeDriver, animation) {
|
|
141
|
+
this.element = element;
|
|
142
|
+
this.update = update;
|
|
143
|
+
this.makeDriver = makeDriver;
|
|
144
|
+
this.animation = animation;
|
|
145
|
+
}
|
|
146
|
+
get js() {
|
|
147
|
+
return (this.driver || (this.driver = this.makeDriver(this.update)));
|
|
148
|
+
}
|
|
149
|
+
now() {
|
|
150
|
+
return this.driver || this.makeDriver !== frameloopDriver
|
|
151
|
+
? this.js.now()
|
|
152
|
+
: frameData.isProcessing
|
|
153
|
+
? frameData.timestamp
|
|
154
|
+
: time.now();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* keepAlive is false when seeking. Seeking the WAAPI animation is
|
|
158
|
+
* free, but if a seek needs a rebuild and keeps happening, the group
|
|
159
|
+
* moves to the main thread.
|
|
160
|
+
*/
|
|
161
|
+
start(keepAlive = true) {
|
|
162
|
+
const group = getGroup(this.element);
|
|
163
|
+
!group || group.isJS
|
|
164
|
+
? this.js.start(keepAlive)
|
|
165
|
+
: group.schedule(false, !keepAlive);
|
|
166
|
+
}
|
|
167
|
+
stopJS() {
|
|
168
|
+
this.driver?.stop();
|
|
169
|
+
}
|
|
170
|
+
stop() {
|
|
171
|
+
this.stopJS();
|
|
172
|
+
const group = getGroup(this.element);
|
|
173
|
+
group && !group.isFinishing && group.release(this.animation);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* JSAnimation's time setter, looked up on first use rather than at module
|
|
178
|
+
* load, so the module has no top-level side effects and stays
|
|
179
|
+
* tree-shakeable in flattened bundles.
|
|
180
|
+
*/
|
|
181
|
+
let setTime;
|
|
133
182
|
class TransformAnimation extends JSAnimation {
|
|
134
183
|
constructor(options) {
|
|
135
184
|
const element = getOwner(options).current;
|
|
@@ -141,35 +190,16 @@ class TransformAnimation extends JSAnimation {
|
|
|
141
190
|
const canAccelerate = canAccelerateTransform(options);
|
|
142
191
|
/**
|
|
143
192
|
* The driver ticks on the main thread only once the group has
|
|
144
|
-
* moved there
|
|
145
|
-
* update its WAAPI animation.
|
|
193
|
+
* moved there, so its frame loop driver is made then.
|
|
146
194
|
*/
|
|
147
|
-
options.driver = (update) =>
|
|
148
|
-
const js = driver(update);
|
|
149
|
-
return {
|
|
150
|
-
js,
|
|
151
|
-
now: js.now,
|
|
152
|
-
start: (keepAlive = true) => {
|
|
153
|
-
const group = getGroup(element);
|
|
154
|
-
const isJS = !group || group.isJS;
|
|
155
|
-
/**
|
|
156
|
-
* keepAlive is false when seeking. Seeking the WAAPI
|
|
157
|
-
* animation is free, but if a seek needs a rebuild and
|
|
158
|
-
* keeps happening, the group moves to the main thread.
|
|
159
|
-
*/
|
|
160
|
-
isJS
|
|
161
|
-
? js.start(keepAlive)
|
|
162
|
-
: group.schedule(false, !keepAlive);
|
|
163
|
-
},
|
|
164
|
-
stop: () => {
|
|
165
|
-
js.stop();
|
|
166
|
-
const group = getGroup(element);
|
|
167
|
-
group && !group.isFinishing && group.release(animation);
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
};
|
|
195
|
+
options.driver = (update) => new TransformDriver(element, update, driver, animation);
|
|
171
196
|
super(options);
|
|
172
197
|
animation = this;
|
|
198
|
+
/**
|
|
199
|
+
* The first driver is made in super(), before this was assigned.
|
|
200
|
+
*/
|
|
201
|
+
const firstDriver = this.driver;
|
|
202
|
+
firstDriver && (firstDriver.animation = this);
|
|
173
203
|
this.canAccelerate = canAccelerate;
|
|
174
204
|
/**
|
|
175
205
|
* stop is bound in JSAnimation, so wrap it rather than override.
|
|
@@ -183,12 +213,29 @@ class TransformAnimation extends JSAnimation {
|
|
|
183
213
|
stop();
|
|
184
214
|
};
|
|
185
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Each keyframe's offset, made once for the keyframes rather than on
|
|
218
|
+
* every build.
|
|
219
|
+
*/
|
|
220
|
+
offsets() {
|
|
221
|
+
const { keyframes, times } = this.options;
|
|
222
|
+
if (times)
|
|
223
|
+
return times;
|
|
224
|
+
if (this.offsetsOf !== keyframes) {
|
|
225
|
+
this.offsetsOf = keyframes;
|
|
226
|
+
this.cachedOffsets = defaultOffset(keyframes);
|
|
227
|
+
}
|
|
228
|
+
return this.cachedOffsets;
|
|
229
|
+
}
|
|
186
230
|
get group() {
|
|
187
231
|
return getGroup(getOwner(this.options).current);
|
|
188
232
|
}
|
|
189
233
|
get js() {
|
|
190
234
|
return this.driver?.js;
|
|
191
235
|
}
|
|
236
|
+
stopJS() {
|
|
237
|
+
this.driver?.stopJS();
|
|
238
|
+
}
|
|
192
239
|
get name() {
|
|
193
240
|
return this.options.name;
|
|
194
241
|
}
|
|
@@ -234,7 +281,7 @@ class TransformAnimation extends JSAnimation {
|
|
|
234
281
|
* exactly, otherwise its function, to trace.
|
|
235
282
|
*/
|
|
236
283
|
tween() {
|
|
237
|
-
const { keyframes: keyframes$1, type,
|
|
284
|
+
const { keyframes: keyframes$1, type, repeat, delay = 0 } = this.options;
|
|
238
285
|
let span = -1;
|
|
239
286
|
if (repeat || type !== keyframes || this.holdTime !== null) {
|
|
240
287
|
return;
|
|
@@ -249,7 +296,7 @@ class TransformAnimation extends JSAnimation {
|
|
|
249
296
|
let { ease } = this.options;
|
|
250
297
|
if (isEasingArray(ease))
|
|
251
298
|
ease = ease[span];
|
|
252
|
-
const offsets =
|
|
299
|
+
const offsets = this.offsets();
|
|
253
300
|
const at = (i) => this.startTime +
|
|
254
301
|
(delay + offsets[i] * this.totalDuration) / this.speed;
|
|
255
302
|
if (span >= 0) {
|
|
@@ -278,9 +325,9 @@ class TransformAnimation extends JSAnimation {
|
|
|
278
325
|
*/
|
|
279
326
|
boundaries(from, to) {
|
|
280
327
|
const { startTime, speed, resolvedDuration, options } = this;
|
|
281
|
-
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType,
|
|
328
|
+
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, type, } = options;
|
|
282
329
|
const offsets = (type || keyframes) === keyframes
|
|
283
|
-
?
|
|
330
|
+
? this.offsets()
|
|
284
331
|
: [0, 1];
|
|
285
332
|
const start = startTime + delay / speed;
|
|
286
333
|
const result = [];
|
|
@@ -357,8 +404,12 @@ class TransformAnimation extends JSAnimation {
|
|
|
357
404
|
}
|
|
358
405
|
return super.time;
|
|
359
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Calls JSAnimation's setter directly, as `super.time =` is a slow
|
|
409
|
+
* path in V8 and this runs for every animation of a seeked sequence.
|
|
410
|
+
*/
|
|
360
411
|
set time(newTime) {
|
|
361
|
-
|
|
412
|
+
(setTime ?? (setTime = Object.getOwnPropertyDescriptor(JSAnimation.prototype, "time").set)).call(this, newTime);
|
|
362
413
|
}
|
|
363
414
|
/**
|
|
364
415
|
* Scroll timelines set time every frame, so run these on the main
|
|
@@ -404,6 +455,12 @@ function createGroup(owner) {
|
|
|
404
455
|
let hasChurned = false;
|
|
405
456
|
let lastChurn = -Infinity;
|
|
406
457
|
let wake;
|
|
458
|
+
let wakeAt = Infinity;
|
|
459
|
+
/**
|
|
460
|
+
* While waiting to build a tween that starts later, how long after
|
|
461
|
+
* the last build to build it.
|
|
462
|
+
*/
|
|
463
|
+
let buildAt;
|
|
407
464
|
const has = (key) => {
|
|
408
465
|
for (const track of tracks)
|
|
409
466
|
if (track.name === key)
|
|
@@ -472,6 +529,8 @@ function createGroup(owner) {
|
|
|
472
529
|
*/
|
|
473
530
|
const stop = (shouldCommit = true) => {
|
|
474
531
|
clearTimeout(wake);
|
|
532
|
+
wakeAt = Infinity;
|
|
533
|
+
buildAt = undefined;
|
|
475
534
|
shouldCommit && commit();
|
|
476
535
|
segments.forEach(({ animation }) => cancel(animation));
|
|
477
536
|
segments = [];
|
|
@@ -701,7 +760,13 @@ function createGroup(owner) {
|
|
|
701
760
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
702
761
|
*/
|
|
703
762
|
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
704
|
-
|
|
763
|
+
/**
|
|
764
|
+
* With an easing given, there's nothing to sample, so no need
|
|
765
|
+
* for the boundaries.
|
|
766
|
+
*/
|
|
767
|
+
const bounds = nativeEasing
|
|
768
|
+
? []
|
|
769
|
+
: moving.flatMap((track) => track.boundaries(from, to));
|
|
705
770
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
706
771
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
707
772
|
const transform = times.map((t) => compose(t, settled));
|
|
@@ -724,6 +789,23 @@ function createGroup(owner) {
|
|
|
724
789
|
easing: easing || "linear",
|
|
725
790
|
});
|
|
726
791
|
};
|
|
792
|
+
/**
|
|
793
|
+
* Check whether it's time to build in this long. A check that's due
|
|
794
|
+
* sooner is kept, and checks again if it's early, so pausing and
|
|
795
|
+
* playing don't each replace a timer. One due later, after a seek or
|
|
796
|
+
* speed change while held, is replaced.
|
|
797
|
+
*/
|
|
798
|
+
const wakeIn = (delay) => {
|
|
799
|
+
const at = time.now() + delay;
|
|
800
|
+
if (at < wakeAt) {
|
|
801
|
+
clearTimeout(wake);
|
|
802
|
+
wakeAt = at;
|
|
803
|
+
wake = setTimeout(() => {
|
|
804
|
+
wakeAt = Infinity;
|
|
805
|
+
group.schedule(false);
|
|
806
|
+
}, delay);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
727
809
|
/**
|
|
728
810
|
* Replace the WAAPI animations with ones built from now. Returns
|
|
729
811
|
* undefined if the animations can't be composed.
|
|
@@ -799,7 +881,7 @@ function createGroup(owner) {
|
|
|
799
881
|
*/
|
|
800
882
|
if (from - now > buildAhead) {
|
|
801
883
|
moving.forEach((track) => track.sync());
|
|
802
|
-
|
|
884
|
+
wakeIn((buildAt = from - now - buildAhead));
|
|
803
885
|
return true;
|
|
804
886
|
}
|
|
805
887
|
easing =
|
|
@@ -854,9 +936,11 @@ function createGroup(owner) {
|
|
|
854
936
|
/**
|
|
855
937
|
* If every animation has been paused, played, seeked or sped up
|
|
856
938
|
* together since the WAAPI animation was built, do the same to it.
|
|
857
|
-
* Returns false if it needs rebuilding instead.
|
|
939
|
+
* Returns false if it needs rebuilding instead. Seeking to before a
|
|
940
|
+
* tween starts rebuilds, so a running group seeked every frame still
|
|
941
|
+
* moves to the main thread.
|
|
858
942
|
*/
|
|
859
|
-
const retime = (now) => {
|
|
943
|
+
const retime = (now, isSeek) => {
|
|
860
944
|
let elapsed;
|
|
861
945
|
let rate = 0;
|
|
862
946
|
for (const track of tracks) {
|
|
@@ -889,12 +973,33 @@ function createGroup(owner) {
|
|
|
889
973
|
}
|
|
890
974
|
if (elapsed === undefined)
|
|
891
975
|
return true;
|
|
892
|
-
|
|
893
|
-
|
|
976
|
+
/**
|
|
977
|
+
* Waiting to build a tween that starts later. Until then the
|
|
978
|
+
* values hold where they start, so only when to build changes.
|
|
979
|
+
* Held, it has nothing on the compositor, so it can be seeked.
|
|
980
|
+
*/
|
|
981
|
+
if (!segments.length) {
|
|
982
|
+
if (buildAt === undefined || (isSeek && rate))
|
|
983
|
+
return false;
|
|
984
|
+
if (rate) {
|
|
985
|
+
const delay = (buildAt - elapsed) / rate;
|
|
986
|
+
if (delay < 1)
|
|
987
|
+
return false;
|
|
988
|
+
wakeIn(delay);
|
|
989
|
+
}
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Only a tween is built to start later, and it holds its first
|
|
994
|
+
* keyframe until then, so it can be paused and played before it
|
|
995
|
+
* starts.
|
|
996
|
+
*/
|
|
894
997
|
for (const { offset, end, isDone } of segments) {
|
|
895
998
|
const local = elapsed - offset;
|
|
896
999
|
if (end < Infinity &&
|
|
897
|
-
(isDone
|
|
1000
|
+
(isDone
|
|
1001
|
+
? local < end - 1
|
|
1002
|
+
: (local < 0 && (isSeek || offset <= 0)) || local >= end)) {
|
|
898
1003
|
return false;
|
|
899
1004
|
}
|
|
900
1005
|
}
|
|
@@ -915,7 +1020,8 @@ function createGroup(owner) {
|
|
|
915
1020
|
animation.updatePlaybackRate(rate);
|
|
916
1021
|
}
|
|
917
1022
|
else if (rate) {
|
|
918
|
-
animation.playbackRate
|
|
1023
|
+
animation.playbackRate !== rate &&
|
|
1024
|
+
(animation.playbackRate = rate);
|
|
919
1025
|
animation.startTime = now - local / rate;
|
|
920
1026
|
}
|
|
921
1027
|
else {
|
|
@@ -989,12 +1095,12 @@ function createGroup(owner) {
|
|
|
989
1095
|
if (group.isJS) {
|
|
990
1096
|
group.isJS = false;
|
|
991
1097
|
needsBuild = true;
|
|
992
|
-
tracks.forEach((track) => track.
|
|
1098
|
+
tracks.forEach((track) => track.stopJS());
|
|
993
1099
|
}
|
|
994
1100
|
const shouldBuild = needsBuild;
|
|
995
1101
|
const churned = hasChurned;
|
|
996
1102
|
needsBuild = hasChurned = false;
|
|
997
|
-
if (shouldBuild || !retime(now)) {
|
|
1103
|
+
if (shouldBuild || !retime(now, churned)) {
|
|
998
1104
|
if (churned) {
|
|
999
1105
|
if (now - lastChurn < churnWindow)
|
|
1000
1106
|
return group.demote();
|
|
@@ -1003,6 +1109,13 @@ function createGroup(owner) {
|
|
|
1003
1109
|
if (!animate(now))
|
|
1004
1110
|
return group.demote();
|
|
1005
1111
|
}
|
|
1112
|
+
else if (buildAt !== undefined && !churned) {
|
|
1113
|
+
/**
|
|
1114
|
+
* Still waiting to build, so the values still hold where
|
|
1115
|
+
* they start.
|
|
1116
|
+
*/
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1006
1119
|
/**
|
|
1007
1120
|
* Held animations don't move, so set their motion values to where
|
|
1008
1121
|
* they're held, as a JSAnimation would on its next tick. Pausing
|