framer-motion 5.5.5 → 5.5.8

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
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
- var useMotionValue = require('./use-motion-value-3615b5bb.js');
6
+ var useMotionValue = require('./use-motion-value-742e9825.js');
7
7
  var React = require('react');
8
8
  var styleValueTypes = require('style-value-types');
9
9
  var popmotion = require('popmotion');
@@ -274,6 +274,9 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
274
274
  else if (transformTemplate) {
275
275
  style.transform = transformTemplate({}, "");
276
276
  }
277
+ else if (!latestValues.transform && style.transform) {
278
+ style.transform = "none";
279
+ }
277
280
  if (hasTransformOrigin) {
278
281
  style.transformOrigin = buildTransformOrigin(transformOrigin);
279
282
  }
@@ -2695,13 +2698,7 @@ function MotionConfig(_a) {
2695
2698
  * Creating a new config context object will re-render every `motion` component
2696
2699
  * every time it renders. So we only want to create a new one sparingly.
2697
2700
  */
2698
- var transitionDependency = typeof config.transition === "object"
2699
- ? config.transition.toString()
2700
- : "";
2701
- var context = React.useMemo(function () { return config; }, [
2702
- transitionDependency,
2703
- config.transformPagePoint,
2704
- ]);
2701
+ var context = React.useMemo(function () { return config; }, [JSON.stringify(config.transition), config.transformPagePoint]);
2705
2702
  return (React__namespace.createElement(useMotionValue.MotionConfigContext.Provider, { value: context }, children));
2706
2703
  }
2707
2704
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
- var useMotionValue = require('./use-motion-value-3615b5bb.js');
6
+ var useMotionValue = require('./use-motion-value-742e9825.js');
7
7
  var React = require('react');
8
8
  var popmotion = require('popmotion');
9
9
  var three = require('three');
@@ -1139,6 +1139,12 @@ function animate(from, to, transition) {
1139
1139
 
1140
1140
  var borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
1141
1141
  var numBorders = borders.length;
1142
+ var asNumber = function (value) {
1143
+ return typeof value === "string" ? parseFloat(value) : value;
1144
+ };
1145
+ var isPx = function (value) {
1146
+ return typeof value === "number" || styleValueTypes.px.test(value);
1147
+ };
1142
1148
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
1143
1149
  var _a, _b, _c, _d;
1144
1150
  if (shouldCrossfadeOpacity) {
@@ -1162,15 +1168,17 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
1162
1168
  continue;
1163
1169
  followRadius || (followRadius = 0);
1164
1170
  leadRadius || (leadRadius = 0);
1165
- /**
1166
- * Currently we're only crossfading between numerical border radius.
1167
- * It would be possible to crossfade between percentages for a little
1168
- * extra bundle size.
1169
- */
1170
- if (typeof followRadius === "number" &&
1171
- typeof leadRadius === "number") {
1172
- var radius = Math.max(popmotion.mix(followRadius, leadRadius, progress), 0);
1173
- target[borderLabel] = radius;
1171
+ var canMix = followRadius === 0 ||
1172
+ leadRadius === 0 ||
1173
+ isPx(followRadius) === isPx(leadRadius);
1174
+ if (canMix) {
1175
+ target[borderLabel] = Math.max(popmotion.mix(asNumber(followRadius), asNumber(leadRadius), progress), 0);
1176
+ if (styleValueTypes.percent.test(leadRadius) || styleValueTypes.percent.test(followRadius)) {
1177
+ target[borderLabel] += "%";
1178
+ }
1179
+ }
1180
+ else {
1181
+ target[borderLabel] = leadRadius;
1174
1182
  }
1175
1183
  }
1176
1184
  /**
@@ -4580,6 +4588,9 @@ var visualElement = function (_a) {
4580
4588
  * added to our map, old ones removed, and listeners updated.
4581
4589
  */
4582
4590
  setProps: function (newProps) {
4591
+ if (newProps.transformTemplate || props.transformTemplate) {
4592
+ element.scheduleRender();
4593
+ }
4583
4594
  props = newProps;
4584
4595
  lifecycles.updatePropListeners(newProps);
4585
4596
  prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
@@ -36,13 +36,7 @@ function MotionConfig(_a) {
36
36
  * Creating a new config context object will re-render every `motion` component
37
37
  * every time it renders. So we only want to create a new one sparingly.
38
38
  */
39
- var transitionDependency = typeof config.transition === "object"
40
- ? config.transition.toString()
41
- : "";
42
- var context = useMemo(function () { return config; }, [
43
- transitionDependency,
44
- config.transformPagePoint,
45
- ]);
39
+ var context = useMemo(function () { return config; }, [JSON.stringify(config.transition), config.transformPagePoint]);
46
40
  return (React.createElement(MotionConfigContext.Provider, { value: context }, children));
47
41
  }
48
42
 
@@ -1,7 +1,14 @@
1
1
  import { mix, progress, linear, circOut } from 'popmotion';
2
+ import { px, percent } from 'style-value-types';
2
3
 
3
4
  var borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
4
5
  var numBorders = borders.length;
6
+ var asNumber = function (value) {
7
+ return typeof value === "string" ? parseFloat(value) : value;
8
+ };
9
+ var isPx = function (value) {
10
+ return typeof value === "number" || px.test(value);
11
+ };
5
12
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
6
13
  var _a, _b, _c, _d;
7
14
  if (shouldCrossfadeOpacity) {
@@ -25,15 +32,17 @@ function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnl
25
32
  continue;
26
33
  followRadius || (followRadius = 0);
27
34
  leadRadius || (leadRadius = 0);
28
- /**
29
- * Currently we're only crossfading between numerical border radius.
30
- * It would be possible to crossfade between percentages for a little
31
- * extra bundle size.
32
- */
33
- if (typeof followRadius === "number" &&
34
- typeof leadRadius === "number") {
35
- var radius = Math.max(mix(followRadius, leadRadius, progress), 0);
36
- target[borderLabel] = radius;
35
+ var canMix = followRadius === 0 ||
36
+ leadRadius === 0 ||
37
+ isPx(followRadius) === isPx(leadRadius);
38
+ if (canMix) {
39
+ target[borderLabel] = Math.max(mix(asNumber(followRadius), asNumber(leadRadius), progress), 0);
40
+ if (percent.test(leadRadius) || percent.test(followRadius)) {
41
+ target[borderLabel] += "%";
42
+ }
43
+ }
44
+ else {
45
+ target[borderLabel] = leadRadius;
37
46
  }
38
47
  }
39
48
  /**
@@ -61,6 +61,9 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
61
61
  else if (transformTemplate) {
62
62
  style.transform = transformTemplate({}, "");
63
63
  }
64
+ else if (!latestValues.transform && style.transform) {
65
+ style.transform = "none";
66
+ }
64
67
  if (hasTransformOrigin) {
65
68
  style.transformOrigin = buildTransformOrigin(transformOrigin);
66
69
  }
@@ -349,6 +349,9 @@ var visualElement = function (_a) {
349
349
  * added to our map, old ones removed, and listeners updated.
350
350
  */
351
351
  setProps: function (newProps) {
352
+ if (newProps.transformTemplate || props.transformTemplate) {
353
+ element.scheduleRender();
354
+ }
352
355
  props = newProps;
353
356
  lifecycles.updatePropListeners(newProps);
354
357
  prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
@@ -2374,6 +2374,12 @@
2374
2374
 
2375
2375
  var borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
2376
2376
  var numBorders = borders.length;
2377
+ var asNumber = function (value) {
2378
+ return typeof value === "string" ? parseFloat(value) : value;
2379
+ };
2380
+ var isPx = function (value) {
2381
+ return typeof value === "number" || px.test(value);
2382
+ };
2377
2383
  function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
2378
2384
  var _a, _b, _c, _d;
2379
2385
  if (shouldCrossfadeOpacity) {
@@ -2397,15 +2403,17 @@
2397
2403
  continue;
2398
2404
  followRadius || (followRadius = 0);
2399
2405
  leadRadius || (leadRadius = 0);
2400
- /**
2401
- * Currently we're only crossfading between numerical border radius.
2402
- * It would be possible to crossfade between percentages for a little
2403
- * extra bundle size.
2404
- */
2405
- if (typeof followRadius === "number" &&
2406
- typeof leadRadius === "number") {
2407
- var radius = Math.max(mix(followRadius, leadRadius, progress), 0);
2408
- target[borderLabel] = radius;
2406
+ var canMix = followRadius === 0 ||
2407
+ leadRadius === 0 ||
2408
+ isPx(followRadius) === isPx(leadRadius);
2409
+ if (canMix) {
2410
+ target[borderLabel] = Math.max(mix(asNumber(followRadius), asNumber(leadRadius), progress), 0);
2411
+ if (percent.test(leadRadius) || percent.test(followRadius)) {
2412
+ target[borderLabel] += "%";
2413
+ }
2414
+ }
2415
+ else {
2416
+ target[borderLabel] = leadRadius;
2409
2417
  }
2410
2418
  }
2411
2419
  /**
@@ -4498,6 +4506,9 @@
4498
4506
  else if (transformTemplate) {
4499
4507
  style.transform = transformTemplate({}, "");
4500
4508
  }
4509
+ else if (!latestValues.transform && style.transform) {
4510
+ style.transform = "none";
4511
+ }
4501
4512
  if (hasTransformOrigin) {
4502
4513
  style.transformOrigin = buildTransformOrigin(transformOrigin);
4503
4514
  }
@@ -7426,6 +7437,9 @@
7426
7437
  * added to our map, old ones removed, and listeners updated.
7427
7438
  */
7428
7439
  setProps: function (newProps) {
7440
+ if (newProps.transformTemplate || props.transformTemplate) {
7441
+ element.scheduleRender();
7442
+ }
7429
7443
  props = newProps;
7430
7444
  lifecycles.updatePropListeners(newProps);
7431
7445
  prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
@@ -8535,13 +8549,7 @@
8535
8549
  * Creating a new config context object will re-render every `motion` component
8536
8550
  * every time it renders. So we only want to create a new one sparingly.
8537
8551
  */
8538
- var transitionDependency = typeof config.transition === "object"
8539
- ? config.transition.toString()
8540
- : "";
8541
- var context = React.useMemo(function () { return config; }, [
8542
- transitionDependency,
8543
- config.transformPagePoint,
8544
- ]);
8552
+ var context = React.useMemo(function () { return config; }, [JSON.stringify(config.transition), config.transformPagePoint]);
8545
8553
  return (React__namespace.createElement(MotionConfigContext.Provider, { value: context }, children));
8546
8554
  }
8547
8555