motion 11.11.17 → 11.12.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.
@@ -1,47 +1,45 @@
1
- (node:86403) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
2
- (Use `node --trace-warnings ...` to show where the warning was created)
3
1
  
4
2
  lib/index.js → dist/motion.dev.js...
5
- created dist/motion.dev.js in 945ms
3
+ created dist/motion.dev.js in 737ms
6
4
  
7
5
  lib/index.js → dist/motion.js...
8
- created dist/motion.js in 1.3s
6
+ created dist/motion.js in 825ms
9
7
  
10
8
  lib/index.js → dist/cjs...
11
- created dist/cjs in 287ms
9
+ created dist/cjs in 227ms
12
10
  
13
11
  lib/react-client.js → dist/cjs...
14
- created dist/cjs in 320ms
12
+ created dist/cjs in 271ms
15
13
  
16
14
  lib/react.js → dist/cjs...
17
- created dist/cjs in 4ms
15
+ created dist/cjs in 3ms
18
16
  
19
17
  lib/mini.js → dist/cjs...
20
- created dist/cjs in 93ms
18
+ created dist/cjs in 24ms
21
19
  
22
20
  lib/react-mini.js → dist/cjs...
23
- created dist/cjs in 83ms
21
+ created dist/cjs in 34ms
24
22
  
25
23
  lib/react-m.js → dist/cjs...
26
- created dist/cjs in 94ms
24
+ created dist/cjs in 70ms
27
25
  
28
26
  lib/index.js, lib/mini.js, lib/react.js, lib/react-mini.js, lib/react-client.js, lib/react-m.js → dist/es...
29
- created dist/es in 683ms
27
+ created dist/es in 636ms
30
28
  
31
29
  types/index.d.ts → dist/index.d.ts...
32
- created dist/index.d.ts in 19ms
30
+ created dist/index.d.ts in 21ms
33
31
  
34
32
  types/react.d.ts → dist/react.d.ts...
35
- created dist/react.d.ts in 7ms
33
+ created dist/react.d.ts in 13ms
36
34
  
37
35
  types/react-mini.d.ts → dist/react-mini.d.ts...
38
- created dist/react-mini.d.ts in 2ms
36
+ created dist/react-mini.d.ts in 12ms
39
37
  
40
38
  types/react-m.d.ts → dist/react-m.d.ts...
41
- created dist/react-m.d.ts in 3ms
39
+ created dist/react-m.d.ts in 58ms
42
40
  
43
41
  types/mini.d.ts → dist/mini.d.ts...
44
- created dist/mini.d.ts in 2ms
42
+ created dist/mini.d.ts in 13ms
45
43
  
46
44
  types/react-client.d.ts → dist/react-client.d.ts...
47
- created dist/react-client.d.ts in 2ms
45
+ created dist/react-client.d.ts in 6ms
package/README.md CHANGED
@@ -38,14 +38,14 @@ It does all this:
38
38
 
39
39
  - [Springs](https://motion.dev/docs/react-transitions#spring)
40
40
  - [Keyframes](https://motion.dev/docs/react-animation#keyframes)
41
- - [Layout animations](https://motion/dev/docs/react-layout-animations)
41
+ - [Layout animations](https://motion.dev/docs/react-layout-animations)
42
42
  - [Shared layout animations](https://motion.dev/docs/react-layout-animations#shared-layout-animations)
43
43
  - [Gestures (drag/tap/hover)](https://motion.dev/docs/react-gestures)
44
44
  - [Scroll animations](https://motion.dev/docs/react-scroll-animations)
45
45
  - [SVG paths](https://motion.dev/docs/react-animation#svg-line-drawing)
46
46
  - [Exit animations](https://motion.dev/docs/react-animation#exit-animations)
47
- - [Server-side rendering](https://motion.dev//docs/react-motion-component#server-side-rendering)
48
- - [Independent transforms](https://motion.dev/docs/react-motion-component#independent-transforms)
47
+ - [Server-side rendering](https://motion.dev/docs/react-motion-component#server-side-rendering)
48
+ - [Independent transforms](https://motion.dev/docs/react-motion-component#style)
49
49
  - [Orchestrate animations across components](https://motion.dev/docs/react-animation#orchestration)
50
50
  - [CSS variables](https://motion.dev/docs/react-animation#css-variables)
51
51
 
@@ -101,6 +101,10 @@ Motion powers Framer animations, the web builder for creative pros. Design and s
101
101
 
102
102
  <a href="https://linear.app"><img alt="Linear" src="https://github.com/user-attachments/assets/a93710bb-d8ed-40e3-b0fb-1c5b3e2b16bb" width="300px" height="200px"></a>
103
103
 
104
+ ### Gold
105
+
106
+ <a href="https://liveblocks.io"><img alt="Liveblocks" src="https://github.com/user-attachments/assets/31436a47-951e-4eab-9a68-bdd54ccf9444" width="225px" height="150px"></a>
107
+
104
108
  ### Silver
105
109
 
106
110
  <a href="https://www.frontend.fyi/?utm_source=motion"><img alt="Frontend.fyi" src="https://github.com/user-attachments/assets/07d23aa5-69db-44a0-849d-90177e6fc817" width="150px" height="100px"></a>
@@ -109,7 +113,16 @@ Motion powers Framer animations, the web builder for creative pros. Design and s
109
113
 
110
114
  <a href="https://firecrawl.dev"><img alt="Firecrawl" src="https://github.com/user-attachments/assets/cba90e54-1329-4353-8fba-85beef4d2ee9" width="150px" height="100px"></a>
111
115
 
116
+ <a href="https://puzzmo.com"><img alt="Puzzmo" src="https://github.com/user-attachments/assets/aa2d5586-e5e2-43b9-8446-db456e4b0758" width="150px" height="100px"></a>
117
+
118
+ <a href="https://buildui.com"><img alt="Build UI" src="https://github.com/user-attachments/assets/024bfcd5-50e8-4b3d-a115-d5c6d6030d1c" width="150px" height="100px"></a>
119
+
120
+ <a href="https://hover.dev"><img alt="Hover" src="https://github.com/user-attachments/assets/4715b555-d2ac-4cb7-9f35-d36d708827b3" width="150px" height="100px"></a>
121
+
112
122
  ### Personal
113
123
 
114
124
  - [Nusu](https://x.com/nusualabuga)
115
125
  - [OlegWock](https://sinja.io)
126
+ - [Lambert Weller](https://github.com/l-mbert)
127
+ - [Jake LeBoeuf](https://jklb.wf)
128
+ - [Han Lee](https://github.com/hahnlee)
package/dist/cjs/index.js CHANGED
@@ -279,7 +279,7 @@ class MotionValue {
279
279
  * This will be replaced by the build step with the latest version number.
280
280
  * When MotionValues are provided to motion components, warn if versions are mixed.
281
281
  */
282
- this.version = "11.11.17";
282
+ this.version = "11.12.0";
283
283
  /**
284
284
  * Tracks whether this value can output a velocity. Currently this is only true
285
285
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -647,6 +647,34 @@ class GroupPlaybackControls {
647
647
  }
648
648
  }
649
649
 
650
+ /*
651
+ Progress within given range
652
+
653
+ Given a lower limit and an upper limit, we return the progress
654
+ (expressed as a number 0-1) represented by the given value, and
655
+ limit that progress to within 0-1.
656
+
657
+ @param [number]: Lower limit
658
+ @param [number]: Upper limit
659
+ @param [number]: Value to find progress within given range
660
+ @return [number]: Progress of value within range as expressed 0-1
661
+ */
662
+ const progress = (from, to, value) => {
663
+ const toFromDifference = to - from;
664
+ return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
665
+ };
666
+
667
+ const generateLinearEasing = (easing, duration, // as milliseconds
668
+ resolution = 10 // as milliseconds
669
+ ) => {
670
+ let points = "";
671
+ const numPoints = Math.max(Math.round(duration / resolution), 2);
672
+ for (let i = 0; i < numPoints; i++) {
673
+ points += easing(progress(0, numPoints - 1, i)) + ", ";
674
+ }
675
+ return `linear(${points.substring(0, points.length - 2)})`;
676
+ };
677
+
650
678
  /**
651
679
  * Converts seconds to milliseconds
652
680
  *
@@ -685,21 +713,43 @@ const clamp = (min, max, v) => {
685
713
  return v;
686
714
  };
687
715
 
716
+ const springDefaults = {
717
+ // Default spring physics
718
+ stiffness: 100,
719
+ damping: 10,
720
+ mass: 1.0,
721
+ velocity: 0.0,
722
+ // Default duration/bounce-based options
723
+ duration: 800, // in ms
724
+ bounce: 0.3,
725
+ visualDuration: 0.3, // in seconds
726
+ // Rest thresholds
727
+ restSpeed: {
728
+ granular: 0.01,
729
+ default: 2,
730
+ },
731
+ restDelta: {
732
+ granular: 0.005,
733
+ default: 0.5,
734
+ },
735
+ // Limits
736
+ minDuration: 0.01, // in seconds
737
+ maxDuration: 10.0, // in seconds
738
+ minDamping: 0.05,
739
+ maxDamping: 1,
740
+ };
741
+
688
742
  const safeMin = 0.001;
689
- const minDuration = 0.01;
690
- const maxDuration$1 = 10.0;
691
- const minDamping = 0.05;
692
- const maxDamping = 1;
693
- function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, }) {
743
+ function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
694
744
  let envelope;
695
745
  let derivative;
696
- exports.warning(duration <= secondsToMilliseconds(maxDuration$1), "Spring duration must be 10 seconds or less");
746
+ exports.warning(duration <= secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less");
697
747
  let dampingRatio = 1 - bounce;
698
748
  /**
699
749
  * Restrict dampingRatio and duration to within acceptable ranges.
700
750
  */
701
- dampingRatio = clamp(minDamping, maxDamping, dampingRatio);
702
- duration = clamp(minDuration, maxDuration$1, millisecondsToSeconds(duration));
751
+ dampingRatio = clamp(springDefaults.minDamping, springDefaults.maxDamping, dampingRatio);
752
+ duration = clamp(springDefaults.minDuration, springDefaults.maxDuration, millisecondsToSeconds(duration));
703
753
  if (dampingRatio < 1) {
704
754
  /**
705
755
  * Underdamped spring
@@ -743,8 +793,8 @@ function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, })
743
793
  duration = secondsToMilliseconds(duration);
744
794
  if (isNaN(undampedFreq)) {
745
795
  return {
746
- stiffness: 100,
747
- damping: 10,
796
+ stiffness: springDefaults.stiffness,
797
+ damping: springDefaults.damping,
748
798
  duration,
749
799
  };
750
800
  }
@@ -769,6 +819,22 @@ function calcAngularFreq(undampedFreq, dampingRatio) {
769
819
  return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
770
820
  }
771
821
 
822
+ /**
823
+ * Implement a practical max duration for keyframe generation
824
+ * to prevent infinite loops
825
+ */
826
+ const maxGeneratorDuration = 20000;
827
+ function calcGeneratorDuration(generator) {
828
+ let duration = 0;
829
+ const timeStep = 50;
830
+ let state = generator.next(duration);
831
+ while (!state.done && duration < maxGeneratorDuration) {
832
+ duration += timeStep;
833
+ state = generator.next(duration);
834
+ }
835
+ return duration >= maxGeneratorDuration ? Infinity : duration;
836
+ }
837
+
772
838
  const durationKeys = ["duration", "bounce"];
773
839
  const physicsKeys = ["stiffness", "damping", "mass"];
774
840
  function isSpringType(options, keys) {
@@ -776,29 +842,51 @@ function isSpringType(options, keys) {
776
842
  }
777
843
  function getSpringOptions(options) {
778
844
  let springOptions = {
779
- velocity: 0.0,
780
- stiffness: 100,
781
- damping: 10,
782
- mass: 1.0,
845
+ velocity: springDefaults.velocity,
846
+ stiffness: springDefaults.stiffness,
847
+ damping: springDefaults.damping,
848
+ mass: springDefaults.mass,
783
849
  isResolvedFromDuration: false,
784
850
  ...options,
785
851
  };
786
852
  // stiffness/damping/mass overrides duration/bounce
787
853
  if (!isSpringType(options, physicsKeys) &&
788
854
  isSpringType(options, durationKeys)) {
789
- const derived = findSpring(options);
790
- springOptions = {
791
- ...springOptions,
792
- ...derived,
793
- mass: 1.0,
794
- };
795
- springOptions.isResolvedFromDuration = true;
855
+ if (options.visualDuration) {
856
+ const visualDuration = options.visualDuration;
857
+ const root = (2 * Math.PI) / (visualDuration * 1.2);
858
+ const stiffness = root * root;
859
+ const damping = 2 * clamp(0.05, 1, 1 - options.bounce) * Math.sqrt(stiffness);
860
+ springOptions = {
861
+ ...springOptions,
862
+ mass: springDefaults.mass,
863
+ stiffness,
864
+ damping,
865
+ };
866
+ }
867
+ else {
868
+ const derived = findSpring(options);
869
+ springOptions = {
870
+ ...springOptions,
871
+ ...derived,
872
+ mass: springDefaults.mass,
873
+ };
874
+ springOptions.isResolvedFromDuration = true;
875
+ }
796
876
  }
797
877
  return springOptions;
798
878
  }
799
- function spring({ keyframes, restDelta, restSpeed, ...options }) {
800
- const origin = keyframes[0];
801
- const target = keyframes[keyframes.length - 1];
879
+ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce = springDefaults.bounce) {
880
+ const options = typeof optionsOrVisualDuration !== "object"
881
+ ? {
882
+ visualDuration: optionsOrVisualDuration,
883
+ keyframes: [0, 1],
884
+ bounce,
885
+ }
886
+ : optionsOrVisualDuration;
887
+ let { restSpeed, restDelta } = options;
888
+ const origin = options.keyframes[0];
889
+ const target = options.keyframes[options.keyframes.length - 1];
802
890
  /**
803
891
  * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
804
892
  * to reduce GC during animation.
@@ -820,8 +908,12 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
820
908
  * ratio between feeling good and finishing as soon as changes are imperceptible.
821
909
  */
822
910
  const isGranularScale = Math.abs(initialDelta) < 5;
823
- restSpeed || (restSpeed = isGranularScale ? 0.01 : 2);
824
- restDelta || (restDelta = isGranularScale ? 0.005 : 0.5);
911
+ restSpeed || (restSpeed = isGranularScale
912
+ ? springDefaults.restSpeed.granular
913
+ : springDefaults.restSpeed.default);
914
+ restDelta || (restDelta = isGranularScale
915
+ ? springDefaults.restDelta.granular
916
+ : springDefaults.restDelta.default);
825
917
  let resolveSpring;
826
918
  if (dampingRatio < 1) {
827
919
  const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
@@ -862,7 +954,7 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
862
954
  dampedAngularFreq);
863
955
  };
864
956
  }
865
- return {
957
+ const generator = {
866
958
  calculatedDuration: isResolvedFromDuration ? duration || null : null,
867
959
  next: (t) => {
868
960
  const current = resolveSpring(t);
@@ -890,23 +982,13 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
890
982
  state.value = state.done ? target : current;
891
983
  return state;
892
984
  },
985
+ toString: () => {
986
+ const calculatedDuration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
987
+ const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
988
+ return calculatedDuration + "ms " + easing;
989
+ },
893
990
  };
894
- }
895
-
896
- /**
897
- * Implement a practical max duration for keyframe generation
898
- * to prevent infinite loops
899
- */
900
- const maxGeneratorDuration = 20000;
901
- function calcGeneratorDuration(generator) {
902
- let duration = 0;
903
- const timeStep = 50;
904
- let state = generator.next(duration);
905
- while (!state.done && duration < maxGeneratorDuration) {
906
- duration += timeStep;
907
- state = generator.next(duration);
908
- }
909
- return duration >= maxGeneratorDuration ? Infinity : duration;
991
+ return generator;
910
992
  }
911
993
 
912
994
  /**
@@ -947,23 +1029,6 @@ const mixNumber$1 = (from, to, progress) => {
947
1029
  return from + (to - from) * progress;
948
1030
  };
949
1031
 
950
- /*
951
- Progress within given range
952
-
953
- Given a lower limit and an upper limit, we return the progress
954
- (expressed as a number 0-1) represented by the given value, and
955
- limit that progress to within 0-1.
956
-
957
- @param [number]: Lower limit
958
- @param [number]: Upper limit
959
- @param [number]: Value to find progress within given range
960
- @return [number]: Progress of value within range as expressed 0-1
961
- */
962
- const progress = (from, to, value) => {
963
- const toFromDifference = to - from;
964
- return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
965
- };
966
-
967
1032
  function fillOffset(offset, remaining) {
968
1033
  const min = offset[offset.length - 1];
969
1034
  for (let i = 1; i <= remaining; i++) {
@@ -3322,18 +3387,6 @@ const acceleratedValues = new Set([
3322
3387
  // "background-color"
3323
3388
  ]);
3324
3389
 
3325
- // Create a linear easing point for every 10 ms
3326
- const resolution = 10;
3327
- const generateLinearEasing = (easing, duration // as milliseconds
3328
- ) => {
3329
- let points = "";
3330
- const numPoints = Math.max(Math.round(duration / resolution), 2);
3331
- for (let i = 0; i < numPoints; i++) {
3332
- points += easing(progress(0, numPoints - 1, i)) + ", ";
3333
- }
3334
- return `linear(${points.substring(0, points.length - 2)})`;
3335
- };
3336
-
3337
3390
  /**
3338
3391
  * Add the ability for test suites to manually set support flags
3339
3392
  * to better test more environments.
@@ -4103,7 +4156,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4103
4156
  * and warn against mismatches.
4104
4157
  */
4105
4158
  if (process.env.NODE_ENV === "development") {
4106
- warnOnce(nextValue.version === "11.11.17", `Attempting to mix Motion versions ${nextValue.version} with 11.11.17 may not work as expected.`);
4159
+ warnOnce(nextValue.version === "11.12.0", `Attempting to mix Motion versions ${nextValue.version} with 11.12.0 may not work as expected.`);
4107
4160
  }
4108
4161
  }
4109
4162
  else if (isMotionValue(prevValue)) {
@@ -5251,6 +5304,7 @@ class NativeAnimation {
5251
5304
  valueKeyframes = [valueKeyframes];
5252
5305
  }
5253
5306
  hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
5307
+ // TODO: Replace this with toString()?
5254
5308
  if (isGenerator(options.type)) {
5255
5309
  const generatorOptions = createGeneratorEasing(options, 100, options.type);
5256
5310
  options.ease = supportsLinearEasing()
package/dist/cjs/mini.js CHANGED
@@ -163,9 +163,8 @@ const progress = (from, to, value) => {
163
163
  return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
164
164
  };
165
165
 
166
- // Create a linear easing point for every 10 ms
167
- const resolution = 10;
168
- const generateLinearEasing = (easing, duration // as milliseconds
166
+ const generateLinearEasing = (easing, duration, // as milliseconds
167
+ resolution = 10 // as milliseconds
169
168
  ) => {
170
169
  let points = "";
171
170
  const numPoints = Math.max(Math.round(duration / resolution), 2);
@@ -403,6 +402,7 @@ class NativeAnimation {
403
402
  valueKeyframes = [valueKeyframes];
404
403
  }
405
404
  hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
405
+ // TODO: Replace this with toString()?
406
406
  if (isGenerator(options.type)) {
407
407
  const generatorOptions = createGeneratorEasing(options, 100, options.type);
408
408
  options.ease = supportsLinearEasing()