framer-motion 7.5.3 → 7.6.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 CHANGED
@@ -1958,12 +1958,25 @@ const instantAnimationState = {
1958
1958
  current: false,
1959
1959
  };
1960
1960
 
1961
+ function delay(callback, timeout) {
1962
+ const start = performance.now();
1963
+ const checkElapsed = ({ timestamp }) => {
1964
+ const elapsed = timestamp - start;
1965
+ if (elapsed >= timeout) {
1966
+ sync.cancelSync.read(checkElapsed);
1967
+ callback(elapsed - timeout);
1968
+ }
1969
+ };
1970
+ sync__default["default"].read(checkElapsed, true);
1971
+ return () => sync.cancelSync.read(checkElapsed);
1972
+ }
1973
+
1961
1974
  /**
1962
1975
  * Decide whether a transition is defined on a given Transition.
1963
1976
  * This filters out orchestration options and returns true
1964
1977
  * if any options are left.
1965
1978
  */
1966
- function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
1979
+ function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
1967
1980
  return !!Object.keys(transition).length;
1968
1981
  }
1969
1982
  let legacyRepeatWarning = false;
@@ -2138,19 +2151,19 @@ function startAnimation(key, value, target, transition = {}) {
2138
2151
  transition = { type: false };
2139
2152
  }
2140
2153
  return value.start((onComplete) => {
2141
- let delayTimer;
2142
2154
  let controls;
2143
2155
  const animation = getAnimation(key, value, target, transition, onComplete);
2144
- const delay = getDelayFromTransition(transition, key);
2156
+ const delayBy = getDelayFromTransition(transition, key);
2145
2157
  const start = () => (controls = animation());
2146
- if (delay) {
2147
- delayTimer = window.setTimeout(start, secondsToMilliseconds(delay));
2158
+ let cancelDelay;
2159
+ if (delayBy) {
2160
+ cancelDelay = delay(start, secondsToMilliseconds(delayBy));
2148
2161
  }
2149
2162
  else {
2150
2163
  start();
2151
2164
  }
2152
2165
  return () => {
2153
- clearTimeout(delayTimer);
2166
+ cancelDelay && cancelDelay();
2154
2167
  controls && controls.stop();
2155
2168
  };
2156
2169
  });
@@ -2245,7 +2258,7 @@ class MotionValue {
2245
2258
  * This will be replaced by the build step with the latest version number.
2246
2259
  * When MotionValues are provided to motion components, warn if versions are mixed.
2247
2260
  */
2248
- this.version = "7.5.3";
2261
+ this.version = "7.6.0";
2249
2262
  /**
2250
2263
  * Duration, in milliseconds, since last updating frame.
2251
2264
  *
@@ -3533,14 +3546,16 @@ function hasScale({ scale, scaleX, scaleY }) {
3533
3546
  }
3534
3547
  function hasTransform(values) {
3535
3548
  return (hasScale(values) ||
3536
- hasTranslate(values.x) ||
3537
- hasTranslate(values.y) ||
3549
+ has2DTranslate(values) ||
3538
3550
  values.z ||
3539
3551
  values.rotate ||
3540
3552
  values.rotateX ||
3541
3553
  values.rotateY);
3542
3554
  }
3543
- function hasTranslate(value) {
3555
+ function has2DTranslate(values) {
3556
+ return is2DTranslate(values.x) || is2DTranslate(values.y);
3557
+ }
3558
+ function is2DTranslate(value) {
3544
3559
  return value && value !== "0%";
3545
3560
  }
3546
3561
 
@@ -4221,7 +4236,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4221
4236
  * and warn against mismatches.
4222
4237
  */
4223
4238
  if (process.env.NODE_ENV === "development") {
4224
- warnOnce(nextValue.version === "7.5.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.5.3 may not work as expected.`);
4239
+ warnOnce(nextValue.version === "7.6.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.6.0 may not work as expected.`);
4225
4240
  }
4226
4241
  }
4227
4242
  else if (isMotionValue(prevValue)) {
@@ -5926,12 +5941,12 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
5926
5941
  this.isLayoutDirty = true;
5927
5942
  }
5928
5943
  if (attachResizeListener) {
5929
- let unblockTimeout;
5944
+ let cancelDelay;
5930
5945
  const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
5931
5946
  attachResizeListener(instance, () => {
5932
5947
  this.root.updateBlockedByResize = true;
5933
- clearTimeout(unblockTimeout);
5934
- unblockTimeout = window.setTimeout(resizeUnblockUpdate, 250);
5948
+ cancelDelay && cancelDelay();
5949
+ cancelDelay = delay(resizeUnblockUpdate, 250);
5935
5950
  if (globalProjectionState.hasAnimatedSinceResize) {
5936
5951
  globalProjectionState.hasAnimatedSinceResize = false;
5937
5952
  this.nodes.forEach(finishAnimation);
@@ -5996,7 +6011,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
5996
6011
  */
5997
6012
  if (!hasLayoutChanged &&
5998
6013
  this.animationProgress === 0) {
5999
- this.finishAnimation();
6014
+ finishAnimation(this);
6000
6015
  }
6001
6016
  this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
6002
6017
  }
@@ -6405,7 +6420,9 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
6405
6420
  }
6406
6421
  }
6407
6422
  getClosestProjectingParent() {
6408
- if (!this.parent || hasTransform(this.parent.latestValues))
6423
+ if (!this.parent ||
6424
+ hasScale(this.parent.latestValues) ||
6425
+ has2DTranslate(this.parent.latestValues))
6409
6426
  return undefined;
6410
6427
  if ((this.parent.relativeTarget || this.parent.targetDelta) &&
6411
6428
  this.parent.layout) {
@@ -8430,6 +8447,7 @@ exports.checkTargetForNewValues = checkTargetForNewValues;
8430
8447
  exports.createBox = createBox;
8431
8448
  exports.createDomMotionComponent = createDomMotionComponent;
8432
8449
  exports.createMotionComponent = createMotionComponent;
8450
+ exports.delay = delay;
8433
8451
  exports.domAnimation = domAnimation;
8434
8452
  exports.domMax = domMax;
8435
8453
  exports.filterProps = filterProps;
@@ -7,13 +7,14 @@ import { warning } from 'hey-listen';
7
7
  import { getAnimatableNone } from '../../render/dom/value-types/animatable-none.mjs';
8
8
  import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
9
9
  import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
10
+ import { delay } from '../../utils/delay.mjs';
10
11
 
11
12
  /**
12
13
  * Decide whether a transition is defined on a given Transition.
13
14
  * This filters out orchestration options and returns true
14
15
  * if any options are left.
15
16
  */
16
- function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
17
+ function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
17
18
  return !!Object.keys(transition).length;
18
19
  }
19
20
  let legacyRepeatWarning = false;
@@ -188,19 +189,19 @@ function startAnimation(key, value, target, transition = {}) {
188
189
  transition = { type: false };
189
190
  }
190
191
  return value.start((onComplete) => {
191
- let delayTimer;
192
192
  let controls;
193
193
  const animation = getAnimation(key, value, target, transition, onComplete);
194
- const delay = getDelayFromTransition(transition, key);
194
+ const delayBy = getDelayFromTransition(transition, key);
195
195
  const start = () => (controls = animation());
196
- if (delay) {
197
- delayTimer = window.setTimeout(start, secondsToMilliseconds(delay));
196
+ let cancelDelay;
197
+ if (delayBy) {
198
+ cancelDelay = delay(start, secondsToMilliseconds(delayBy));
198
199
  }
199
200
  else {
200
201
  start();
201
202
  }
202
203
  return () => {
203
- clearTimeout(delayTimer);
204
+ cancelDelay && cancelDelay();
204
205
  controls && controls.stop();
205
206
  };
206
207
  });
package/dist/es/index.mjs CHANGED
@@ -42,6 +42,7 @@ export { addScaleCorrector } from './projection/styles/scale-correction.mjs';
42
42
  export { useInstantTransition } from './utils/use-instant-transition.mjs';
43
43
  export { useInstantLayoutTransition } from './projection/use-instant-layout-transition.mjs';
44
44
  export { useResetProjection } from './projection/use-reset-projection.mjs';
45
+ export { delay } from './utils/delay.mjs';
45
46
  export { MotionContext, useVisualElementContext } from './context/MotionContext/index.mjs';
46
47
  export { MotionConfigContext } from './context/MotionConfigContext.mjs';
47
48
  export { PresenceContext } from './context/PresenceContext.mjs';
@@ -14,10 +14,11 @@ import { NodeStack } from '../shared/stack.mjs';
14
14
  import { scaleCorrectors } from '../styles/scale-correction.mjs';
15
15
  import { buildProjectionTransform } from '../styles/transform.mjs';
16
16
  import { eachAxis } from '../utils/each-axis.mjs';
17
- import { hasTransform, hasScale } from '../utils/has-transform.mjs';
17
+ import { hasTransform, hasScale, has2DTranslate } from '../utils/has-transform.mjs';
18
18
  import { FlatTree } from '../../render/utils/flat-tree.mjs';
19
19
  import { resolveMotionValue } from '../../value/utils/resolve-motion-value.mjs';
20
20
  import { globalProjectionState } from './state.mjs';
21
+ import { delay } from '../../utils/delay.mjs';
21
22
 
22
23
  const transformAxes = ["", "X", "Y", "Z"];
23
24
  /**
@@ -160,12 +161,12 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
160
161
  this.isLayoutDirty = true;
161
162
  }
162
163
  if (attachResizeListener) {
163
- let unblockTimeout;
164
+ let cancelDelay;
164
165
  const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
165
166
  attachResizeListener(instance, () => {
166
167
  this.root.updateBlockedByResize = true;
167
- clearTimeout(unblockTimeout);
168
- unblockTimeout = window.setTimeout(resizeUnblockUpdate, 250);
168
+ cancelDelay && cancelDelay();
169
+ cancelDelay = delay(resizeUnblockUpdate, 250);
169
170
  if (globalProjectionState.hasAnimatedSinceResize) {
170
171
  globalProjectionState.hasAnimatedSinceResize = false;
171
172
  this.nodes.forEach(finishAnimation);
@@ -230,7 +231,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
230
231
  */
231
232
  if (!hasLayoutChanged &&
232
233
  this.animationProgress === 0) {
233
- this.finishAnimation();
234
+ finishAnimation(this);
234
235
  }
235
236
  this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
236
237
  }
@@ -639,7 +640,9 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
639
640
  }
640
641
  }
641
642
  getClosestProjectingParent() {
642
- if (!this.parent || hasTransform(this.parent.latestValues))
643
+ if (!this.parent ||
644
+ hasScale(this.parent.latestValues) ||
645
+ has2DTranslate(this.parent.latestValues))
643
646
  return undefined;
644
647
  if ((this.parent.relativeTarget || this.parent.targetDelta) &&
645
648
  this.parent.layout) {
@@ -8,15 +8,17 @@ function hasScale({ scale, scaleX, scaleY }) {
8
8
  }
9
9
  function hasTransform(values) {
10
10
  return (hasScale(values) ||
11
- hasTranslate(values.x) ||
12
- hasTranslate(values.y) ||
11
+ has2DTranslate(values) ||
13
12
  values.z ||
14
13
  values.rotate ||
15
14
  values.rotateX ||
16
15
  values.rotateY);
17
16
  }
18
- function hasTranslate(value) {
17
+ function has2DTranslate(values) {
18
+ return is2DTranslate(values.x) || is2DTranslate(values.y);
19
+ }
20
+ function is2DTranslate(value) {
19
21
  return value && value !== "0%";
20
22
  }
21
23
 
22
- export { hasScale, hasTransform };
24
+ export { has2DTranslate, hasScale, hasTransform };
@@ -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 === "7.5.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.5.3 may not work as expected.`);
25
+ warnOnce(nextValue.version === "7.6.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.6.0 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -0,0 +1,16 @@
1
+ import sync, { cancelSync } from 'framesync';
2
+
3
+ function delay(callback, timeout) {
4
+ const start = performance.now();
5
+ const checkElapsed = ({ timestamp }) => {
6
+ const elapsed = timestamp - start;
7
+ if (elapsed >= timeout) {
8
+ cancelSync.read(checkElapsed);
9
+ callback(elapsed - timeout);
10
+ }
11
+ };
12
+ sync.read(checkElapsed, true);
13
+ return () => cancelSync.read(checkElapsed);
14
+ }
15
+
16
+ export { delay };
@@ -24,7 +24,7 @@ class MotionValue {
24
24
  * This will be replaced by the build step with the latest version number.
25
25
  * When MotionValues are provided to motion components, warn if versions are mixed.
26
26
  */
27
- this.version = "7.5.3";
27
+ this.version = "7.6.0";
28
28
  /**
29
29
  * Duration, in milliseconds, since last updating frame.
30
30
  *
@@ -3126,12 +3126,25 @@
3126
3126
  current: false,
3127
3127
  };
3128
3128
 
3129
+ function delay(callback, timeout) {
3130
+ const start = performance.now();
3131
+ const checkElapsed = ({ timestamp }) => {
3132
+ const elapsed = timestamp - start;
3133
+ if (elapsed >= timeout) {
3134
+ cancelSync.read(checkElapsed);
3135
+ callback(elapsed - timeout);
3136
+ }
3137
+ };
3138
+ sync.read(checkElapsed, true);
3139
+ return () => cancelSync.read(checkElapsed);
3140
+ }
3141
+
3129
3142
  /**
3130
3143
  * Decide whether a transition is defined on a given Transition.
3131
3144
  * This filters out orchestration options and returns true
3132
3145
  * if any options are left.
3133
3146
  */
3134
- function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
3147
+ function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
3135
3148
  return !!Object.keys(transition).length;
3136
3149
  }
3137
3150
  let legacyRepeatWarning = false;
@@ -3306,19 +3319,19 @@
3306
3319
  transition = { type: false };
3307
3320
  }
3308
3321
  return value.start((onComplete) => {
3309
- let delayTimer;
3310
3322
  let controls;
3311
3323
  const animation = getAnimation(key, value, target, transition, onComplete);
3312
- const delay = getDelayFromTransition(transition, key);
3324
+ const delayBy = getDelayFromTransition(transition, key);
3313
3325
  const start = () => (controls = animation());
3314
- if (delay) {
3315
- delayTimer = window.setTimeout(start, secondsToMilliseconds(delay));
3326
+ let cancelDelay;
3327
+ if (delayBy) {
3328
+ cancelDelay = delay(start, secondsToMilliseconds(delayBy));
3316
3329
  }
3317
3330
  else {
3318
3331
  start();
3319
3332
  }
3320
3333
  return () => {
3321
- clearTimeout(delayTimer);
3334
+ cancelDelay && cancelDelay();
3322
3335
  controls && controls.stop();
3323
3336
  };
3324
3337
  });
@@ -3413,7 +3426,7 @@
3413
3426
  * This will be replaced by the build step with the latest version number.
3414
3427
  * When MotionValues are provided to motion components, warn if versions are mixed.
3415
3428
  */
3416
- this.version = "7.5.3";
3429
+ this.version = "7.6.0";
3417
3430
  /**
3418
3431
  * Duration, in milliseconds, since last updating frame.
3419
3432
  *
@@ -4701,14 +4714,16 @@
4701
4714
  }
4702
4715
  function hasTransform(values) {
4703
4716
  return (hasScale(values) ||
4704
- hasTranslate(values.x) ||
4705
- hasTranslate(values.y) ||
4717
+ has2DTranslate(values) ||
4706
4718
  values.z ||
4707
4719
  values.rotate ||
4708
4720
  values.rotateX ||
4709
4721
  values.rotateY);
4710
4722
  }
4711
- function hasTranslate(value) {
4723
+ function has2DTranslate(values) {
4724
+ return is2DTranslate(values.x) || is2DTranslate(values.y);
4725
+ }
4726
+ function is2DTranslate(value) {
4712
4727
  return value && value !== "0%";
4713
4728
  }
4714
4729
 
@@ -5389,7 +5404,7 @@
5389
5404
  * and warn against mismatches.
5390
5405
  */
5391
5406
  {
5392
- warnOnce(nextValue.version === "7.5.3", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.5.3 may not work as expected.`);
5407
+ warnOnce(nextValue.version === "7.6.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.6.0 may not work as expected.`);
5393
5408
  }
5394
5409
  }
5395
5410
  else if (isMotionValue(prevValue)) {
@@ -7094,12 +7109,12 @@
7094
7109
  this.isLayoutDirty = true;
7095
7110
  }
7096
7111
  if (attachResizeListener) {
7097
- let unblockTimeout;
7112
+ let cancelDelay;
7098
7113
  const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
7099
7114
  attachResizeListener(instance, () => {
7100
7115
  this.root.updateBlockedByResize = true;
7101
- clearTimeout(unblockTimeout);
7102
- unblockTimeout = window.setTimeout(resizeUnblockUpdate, 250);
7116
+ cancelDelay && cancelDelay();
7117
+ cancelDelay = delay(resizeUnblockUpdate, 250);
7103
7118
  if (globalProjectionState.hasAnimatedSinceResize) {
7104
7119
  globalProjectionState.hasAnimatedSinceResize = false;
7105
7120
  this.nodes.forEach(finishAnimation);
@@ -7164,7 +7179,7 @@
7164
7179
  */
7165
7180
  if (!hasLayoutChanged &&
7166
7181
  this.animationProgress === 0) {
7167
- this.finishAnimation();
7182
+ finishAnimation(this);
7168
7183
  }
7169
7184
  this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
7170
7185
  }
@@ -7573,7 +7588,9 @@
7573
7588
  }
7574
7589
  }
7575
7590
  getClosestProjectingParent() {
7576
- if (!this.parent || hasTransform(this.parent.latestValues))
7591
+ if (!this.parent ||
7592
+ hasScale(this.parent.latestValues) ||
7593
+ has2DTranslate(this.parent.latestValues))
7577
7594
  return undefined;
7578
7595
  if ((this.parent.relativeTarget || this.parent.targetDelta) &&
7579
7596
  this.parent.layout) {
@@ -10179,6 +10196,7 @@
10179
10196
  exports.createBox = createBox;
10180
10197
  exports.createDomMotionComponent = createDomMotionComponent;
10181
10198
  exports.createMotionComponent = createMotionComponent;
10199
+ exports.delay = delay;
10182
10200
  exports.domAnimation = domAnimation;
10183
10201
  exports.domMax = domMax;
10184
10202
  exports.filterProps = filterProps;