framer-motion 10.1.0-alpha.4 → 10.2.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var wrap = require('./wrap-e83e4b10.js');
5
+ var wrap = require('./wrap-752dc0be.js');
6
6
 
7
7
 
8
8
 
package/dist/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var wrap = require('./wrap-e83e4b10.js');
6
+ var wrap = require('./wrap-752dc0be.js');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
@@ -1249,7 +1249,7 @@ function addHoverEvent(node, isActive) {
1249
1249
  node.animationState.setActive("whileHover", isActive);
1250
1250
  }
1251
1251
  if (props[callbackName]) {
1252
- props[callbackName](event, info);
1252
+ wrap.sync.update(() => props[callbackName](event, info));
1253
1253
  }
1254
1254
  };
1255
1255
  return addPointerEvent(node.current, eventName, handleEvent, {
@@ -1339,13 +1339,15 @@ class PressGesture extends Feature {
1339
1339
  if (!this.checkPressEnd())
1340
1340
  return;
1341
1341
  const { onTap, onTapCancel } = this.node.getProps();
1342
- /**
1343
- * We only count this as a tap gesture if the event.target is the same
1344
- * as, or a child of, this component's element
1345
- */
1346
- !isNodeOrChild(this.node.current, endEvent.target)
1347
- ? onTapCancel && onTapCancel(endEvent, endInfo)
1348
- : onTap && onTap(endEvent, endInfo);
1342
+ wrap.sync.update(() => {
1343
+ /**
1344
+ * We only count this as a tap gesture if the event.target is the same
1345
+ * as, or a child of, this component's element
1346
+ */
1347
+ !isNodeOrChild(this.node.current, endEvent.target)
1348
+ ? onTapCancel && onTapCancel(endEvent, endInfo)
1349
+ : onTap && onTap(endEvent, endInfo);
1350
+ });
1349
1351
  };
1350
1352
  const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, { passive: !(props.onTap || props["onPointerUp"]) });
1351
1353
  const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), { passive: !(props.onTapCancel || props["onPointerCancel"]) });
@@ -1359,7 +1361,12 @@ class PressGesture extends Feature {
1359
1361
  const handleKeyup = (keyupEvent) => {
1360
1362
  if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
1361
1363
  return;
1362
- fireSyntheticPointerEvent("up", this.node.getProps().onTap);
1364
+ fireSyntheticPointerEvent("up", (event, info) => {
1365
+ const { onTap } = this.node.getProps();
1366
+ if (onTap) {
1367
+ wrap.sync.update(() => onTap(event, info));
1368
+ }
1369
+ });
1363
1370
  };
1364
1371
  this.removeEndListeners();
1365
1372
  this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
@@ -1386,7 +1393,9 @@ class PressGesture extends Feature {
1386
1393
  if (whileTap && this.node.animationState) {
1387
1394
  this.node.animationState.setActive("whileTap", true);
1388
1395
  }
1389
- onTapStart && onTapStart(event, info);
1396
+ if (onTapStart) {
1397
+ wrap.sync.update(() => onTapStart(event, info));
1398
+ }
1390
1399
  }
1391
1400
  checkPressEnd() {
1392
1401
  this.removeEndListeners();
@@ -1401,7 +1410,9 @@ class PressGesture extends Feature {
1401
1410
  if (!this.checkPressEnd())
1402
1411
  return;
1403
1412
  const { onTapCancel } = this.node.getProps();
1404
- onTapCancel && onTapCancel(event, info);
1413
+ if (onTapCancel) {
1414
+ wrap.sync.update(() => onTapCancel(event, info));
1415
+ }
1405
1416
  }
1406
1417
  mount() {
1407
1418
  const props = this.node.getProps();
@@ -2840,7 +2851,9 @@ class VisualElementDragControls {
2840
2851
  this.originPoint[axis] = current;
2841
2852
  });
2842
2853
  // Fire onDragStart event
2843
- onDragStart && onDragStart(event, info);
2854
+ if (onDragStart) {
2855
+ wrap.sync.update(() => onDragStart(event, info));
2856
+ }
2844
2857
  const { animationState } = this.visualElement;
2845
2858
  animationState && animationState.setActive("whileDrag", true);
2846
2859
  };
@@ -2892,7 +2905,9 @@ class VisualElementDragControls {
2892
2905
  const { velocity } = info;
2893
2906
  this.startAnimation(velocity);
2894
2907
  const { onDragEnd } = this.getProps();
2895
- onDragEnd && onDragEnd(event, info);
2908
+ if (onDragEnd) {
2909
+ wrap.sync.update(() => onDragEnd(event, info));
2910
+ }
2896
2911
  }
2897
2912
  cancel() {
2898
2913
  this.isDragging = false;
@@ -3217,6 +3232,11 @@ class DragGesture extends Feature {
3217
3232
  }
3218
3233
  }
3219
3234
 
3235
+ const asyncHandler = (handler) => (event, info) => {
3236
+ if (handler) {
3237
+ wrap.sync.update(() => handler(event, info));
3238
+ }
3239
+ };
3220
3240
  class PanGesture extends Feature {
3221
3241
  constructor() {
3222
3242
  super(...arguments);
@@ -3228,12 +3248,14 @@ class PanGesture extends Feature {
3228
3248
  createPanHandlers() {
3229
3249
  const { onPanSessionStart, onPanStart, onPan, onPanEnd } = this.node.getProps();
3230
3250
  return {
3231
- onSessionStart: onPanSessionStart,
3232
- onStart: onPanStart,
3251
+ onSessionStart: asyncHandler(onPanSessionStart),
3252
+ onStart: asyncHandler(onPanStart),
3233
3253
  onMove: onPan,
3234
3254
  onEnd: (event, info) => {
3235
3255
  delete this.session;
3236
- onPanEnd && onPanEnd(event, info);
3256
+ if (onPanEnd) {
3257
+ wrap.sync.update(() => onPanEnd(event, info));
3258
+ }
3237
3259
  },
3238
3260
  };
3239
3261
  }
@@ -5494,7 +5516,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5494
5516
  * and warn against mismatches.
5495
5517
  */
5496
5518
  if (process.env.NODE_ENV === "development") {
5497
- wrap.warnOnce(nextValue.version === "10.1.0-alpha.4", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.1.0-alpha.4 may not work as expected.`);
5519
+ wrap.warnOnce(nextValue.version === "10.2.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.2.0 may not work as expected.`);
5498
5520
  }
5499
5521
  }
5500
5522
  else if (wrap.isMotionValue(prevValue)) {
@@ -157,13 +157,6 @@ const numberValueTypes = {
157
157
  const combineFunctions = (a, b) => (v) => b(a(v));
158
158
  const pipe = (...transformers) => transformers.reduce(combineFunctions);
159
159
 
160
- const noop = (any) => any;
161
-
162
- const frameData = {
163
- delta: 0,
164
- timestamp: 0,
165
- };
166
-
167
160
  /*
168
161
  Detect and load appropriate clock setting for the execution environment
169
162
  */
@@ -262,6 +255,11 @@ function createRenderStep(runNextFrame) {
262
255
  return step;
263
256
  }
264
257
 
258
+ const frameData = {
259
+ delta: 0,
260
+ timestamp: 0,
261
+ };
262
+
265
263
  const maxElapsed$1 = 40;
266
264
  let useDefaultElapsed = true;
267
265
  let runNextFrame = false;
@@ -316,6 +314,8 @@ const startLoop = () => {
316
314
  onNextFrame(processFrame);
317
315
  };
318
316
 
317
+ const noop = (any) => any;
318
+
319
319
  function addUniqueItem(arr, item) {
320
320
  if (arr.indexOf(item) === -1)
321
321
  arr.push(item);
@@ -415,7 +415,7 @@ class MotionValue {
415
415
  * This will be replaced by the build step with the latest version number.
416
416
  * When MotionValues are provided to motion components, warn if versions are mixed.
417
417
  */
418
- this.version = "10.1.0-alpha.4";
418
+ this.version = "10.2.0";
419
419
  /**
420
420
  * Duration, in milliseconds, since last updating frame.
421
421
  *
@@ -1828,7 +1828,10 @@ function mapEasingToNativeEasing(easing) {
1828
1828
  }
1829
1829
 
1830
1830
  function animateStyle(element, valueName, keyframes, { delay = 0, duration, repeat = 0, repeatType = "loop", ease, times, } = {}) {
1831
- return element.animate({ [valueName]: keyframes, offset: times }, {
1831
+ const keyframeOptions = { [valueName]: keyframes };
1832
+ if (times)
1833
+ keyframeOptions.offset = times;
1834
+ return element.animate(keyframeOptions, {
1832
1835
  delay,
1833
1836
  duration,
1834
1837
  easing: mapEasingToNativeEasing(ease),
@@ -414,9 +414,14 @@ interface MotionValueEventCallbacks<V> {
414
414
  renderRequest: () => void;
415
415
  velocityChange: (latestVelocity: number) => void;
416
416
  }
417
+ interface ResolvedValues {
418
+ [key: string]: string | number;
419
+ }
417
420
  interface Owner {
418
421
  current: HTMLElement | unknown;
419
- getProps: () => any;
422
+ getProps: () => {
423
+ onUpdate?: (latest: ResolvedValues) => void;
424
+ };
420
425
  }
421
426
  interface MotionValueOptions {
422
427
  owner?: Owner;
@@ -1,7 +1,10 @@
1
1
  import { mapEasingToNativeEasing } from './easing.mjs';
2
2
 
3
3
  function animateStyle(element, valueName, keyframes, { delay = 0, duration, repeat = 0, repeatType = "loop", ease, times, } = {}) {
4
- return element.animate({ [valueName]: keyframes, offset: times }, {
4
+ const keyframeOptions = { [valueName]: keyframes };
5
+ if (times)
6
+ keyframeOptions.offset = times;
7
+ return element.animate(keyframeOptions, {
5
8
  delay,
6
9
  duration,
7
10
  easing: mapEasingToNativeEasing(ease),
@@ -14,6 +14,7 @@ import { calcLength } from '../../projection/geometry/delta-calc.mjs';
14
14
  import { mix } from '../../utils/mix.mjs';
15
15
  import { percent } from '../../value/types/numbers/units.mjs';
16
16
  import { createMotionValueAnimation } from '../../animation/index.mjs';
17
+ import { sync } from '../../frameloop/index.mjs';
17
18
 
18
19
  const elementDragControls = new WeakMap();
19
20
  /**
@@ -94,7 +95,9 @@ class VisualElementDragControls {
94
95
  this.originPoint[axis] = current;
95
96
  });
96
97
  // Fire onDragStart event
97
- onDragStart && onDragStart(event, info);
98
+ if (onDragStart) {
99
+ sync.update(() => onDragStart(event, info));
100
+ }
98
101
  const { animationState } = this.visualElement;
99
102
  animationState && animationState.setActive("whileDrag", true);
100
103
  };
@@ -146,7 +149,9 @@ class VisualElementDragControls {
146
149
  const { velocity } = info;
147
150
  this.startAnimation(velocity);
148
151
  const { onDragEnd } = this.getProps();
149
- onDragEnd && onDragEnd(event, info);
152
+ if (onDragEnd) {
153
+ sync.update(() => onDragEnd(event, info));
154
+ }
150
155
  }
151
156
  cancel() {
152
157
  this.isDragging = false;
@@ -2,6 +2,7 @@ import { addPointerEvent } from '../events/add-pointer-event.mjs';
2
2
  import { pipe } from '../utils/pipe.mjs';
3
3
  import { isDragActive } from './drag/utils/lock.mjs';
4
4
  import { Feature } from '../motion/features/Feature.mjs';
5
+ import { sync } from '../frameloop/index.mjs';
5
6
 
6
7
  function addHoverEvent(node, isActive) {
7
8
  const eventName = "pointer" + (isActive ? "enter" : "leave");
@@ -14,7 +15,7 @@ function addHoverEvent(node, isActive) {
14
15
  node.animationState.setActive("whileHover", isActive);
15
16
  }
16
17
  if (props[callbackName]) {
17
- props[callbackName](event, info);
18
+ sync.update(() => props[callbackName](event, info));
18
19
  }
19
20
  };
20
21
  return addPointerEvent(node.current, eventName, handleEvent, {
@@ -2,7 +2,13 @@ import { PanSession } from './PanSession.mjs';
2
2
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
3
3
  import { Feature } from '../../motion/features/Feature.mjs';
4
4
  import { noop } from '../../utils/noop.mjs';
5
+ import { sync } from '../../frameloop/index.mjs';
5
6
 
7
+ const asyncHandler = (handler) => (event, info) => {
8
+ if (handler) {
9
+ sync.update(() => handler(event, info));
10
+ }
11
+ };
6
12
  class PanGesture extends Feature {
7
13
  constructor() {
8
14
  super(...arguments);
@@ -14,12 +20,14 @@ class PanGesture extends Feature {
14
20
  createPanHandlers() {
15
21
  const { onPanSessionStart, onPanStart, onPan, onPanEnd } = this.node.getProps();
16
22
  return {
17
- onSessionStart: onPanSessionStart,
18
- onStart: onPanStart,
23
+ onSessionStart: asyncHandler(onPanSessionStart),
24
+ onStart: asyncHandler(onPanStart),
19
25
  onMove: onPan,
20
26
  onEnd: (event, info) => {
21
27
  delete this.session;
22
- onPanEnd && onPanEnd(event, info);
28
+ if (onPanEnd) {
29
+ sync.update(() => onPanEnd(event, info));
30
+ }
23
31
  },
24
32
  };
25
33
  }
@@ -6,6 +6,7 @@ import { pipe } from '../utils/pipe.mjs';
6
6
  import { isDragActive } from './drag/utils/lock.mjs';
7
7
  import { isNodeOrChild } from './utils/is-node-or-child.mjs';
8
8
  import { noop } from '../utils/noop.mjs';
9
+ import { sync } from '../frameloop/index.mjs';
9
10
 
10
11
  function fireSyntheticPointerEvent(name, handler) {
11
12
  if (!handler)
@@ -28,13 +29,15 @@ class PressGesture extends Feature {
28
29
  if (!this.checkPressEnd())
29
30
  return;
30
31
  const { onTap, onTapCancel } = this.node.getProps();
31
- /**
32
- * We only count this as a tap gesture if the event.target is the same
33
- * as, or a child of, this component's element
34
- */
35
- !isNodeOrChild(this.node.current, endEvent.target)
36
- ? onTapCancel && onTapCancel(endEvent, endInfo)
37
- : onTap && onTap(endEvent, endInfo);
32
+ sync.update(() => {
33
+ /**
34
+ * We only count this as a tap gesture if the event.target is the same
35
+ * as, or a child of, this component's element
36
+ */
37
+ !isNodeOrChild(this.node.current, endEvent.target)
38
+ ? onTapCancel && onTapCancel(endEvent, endInfo)
39
+ : onTap && onTap(endEvent, endInfo);
40
+ });
38
41
  };
39
42
  const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, { passive: !(props.onTap || props["onPointerUp"]) });
40
43
  const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), { passive: !(props.onTapCancel || props["onPointerCancel"]) });
@@ -48,7 +51,12 @@ class PressGesture extends Feature {
48
51
  const handleKeyup = (keyupEvent) => {
49
52
  if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
50
53
  return;
51
- fireSyntheticPointerEvent("up", this.node.getProps().onTap);
54
+ fireSyntheticPointerEvent("up", (event, info) => {
55
+ const { onTap } = this.node.getProps();
56
+ if (onTap) {
57
+ sync.update(() => onTap(event, info));
58
+ }
59
+ });
52
60
  };
53
61
  this.removeEndListeners();
54
62
  this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
@@ -75,7 +83,9 @@ class PressGesture extends Feature {
75
83
  if (whileTap && this.node.animationState) {
76
84
  this.node.animationState.setActive("whileTap", true);
77
85
  }
78
- onTapStart && onTapStart(event, info);
86
+ if (onTapStart) {
87
+ sync.update(() => onTapStart(event, info));
88
+ }
79
89
  }
80
90
  checkPressEnd() {
81
91
  this.removeEndListeners();
@@ -90,7 +100,9 @@ class PressGesture extends Feature {
90
100
  if (!this.checkPressEnd())
91
101
  return;
92
102
  const { onTapCancel } = this.node.getProps();
93
- onTapCancel && onTapCancel(event, info);
103
+ if (onTapCancel) {
104
+ sync.update(() => onTapCancel(event, info));
105
+ }
94
106
  }
95
107
  mount() {
96
108
  const props = this.node.getProps();
@@ -22,7 +22,7 @@ function updateMotionValuesFromProps(element, next, prev) {
22
22
  * and warn against mismatches.
23
23
  */
24
24
  if (process.env.NODE_ENV === "development") {
25
- warnOnce(nextValue.version === "10.1.0-alpha.4", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.1.0-alpha.4 may not work as expected.`);
25
+ warnOnce(nextValue.version === "10.2.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.2.0 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -26,7 +26,7 @@ class MotionValue {
26
26
  * This will be replaced by the build step with the latest version number.
27
27
  * When MotionValues are provided to motion components, warn if versions are mixed.
28
28
  */
29
- this.version = "10.1.0-alpha.4";
29
+ this.version = "10.2.0";
30
30
  /**
31
31
  * Duration, in milliseconds, since last updating frame.
32
32
  *