framer-motion 12.34.5 → 12.35.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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client.js +1 -1
  3. package/dist/cjs/dom.js +108 -10
  4. package/dist/cjs/dom.js.map +1 -1
  5. package/dist/cjs/{feature-bundle-CGU3mAvs.js → feature-bundle-jADFMKLx.js} +4 -4
  6. package/dist/cjs/{feature-bundle-CGU3mAvs.js.map → feature-bundle-jADFMKLx.js.map} +1 -1
  7. package/dist/cjs/index.js +126 -17
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/m.js +3 -3
  10. package/dist/cjs/m.js.map +1 -1
  11. package/dist/dom-mini.js +1 -1
  12. package/dist/dom.js +1 -1
  13. package/dist/es/motion/utils/use-motion-ref.mjs +3 -3
  14. package/dist/es/motion/utils/use-motion-ref.mjs.map +1 -1
  15. package/dist/es/render/dom/scroll/attach-animation.mjs +20 -1
  16. package/dist/es/render/dom/scroll/attach-animation.mjs.map +1 -1
  17. package/dist/es/render/dom/scroll/offsets/presets.mjs +12 -0
  18. package/dist/es/render/dom/scroll/offsets/presets.mjs.map +1 -1
  19. package/dist/es/render/dom/scroll/utils/can-use-native-timeline.mjs +4 -2
  20. package/dist/es/render/dom/scroll/utils/can-use-native-timeline.mjs.map +1 -1
  21. package/dist/es/render/dom/scroll/utils/get-timeline.mjs +38 -7
  22. package/dist/es/render/dom/scroll/utils/get-timeline.mjs.map +1 -1
  23. package/dist/es/render/dom/scroll/utils/offset-to-range.mjs +41 -0
  24. package/dist/es/render/dom/scroll/utils/offset-to-range.mjs.map +1 -0
  25. package/dist/es/value/use-scroll.mjs +19 -8
  26. package/dist/es/value/use-scroll.mjs.map +1 -1
  27. package/dist/framer-motion.dev.js +143 -22
  28. package/dist/framer-motion.js +1 -1
  29. package/dist/mini.js +1 -1
  30. package/dist/size-rollup-animate.js +1 -1
  31. package/dist/size-rollup-animate.js.map +1 -1
  32. package/dist/size-rollup-dom-animation-assets.js +1 -1
  33. package/dist/size-rollup-dom-animation-m.js +1 -1
  34. package/dist/size-rollup-dom-max-assets.js +1 -1
  35. package/dist/size-rollup-dom-max.js +1 -1
  36. package/dist/size-rollup-m.js +1 -1
  37. package/dist/size-rollup-m.js.map +1 -1
  38. package/dist/size-rollup-motion.js +1 -1
  39. package/dist/size-rollup-motion.js.map +1 -1
  40. package/dist/size-rollup-scroll.js +1 -1
  41. package/dist/size-rollup-scroll.js.map +1 -1
  42. package/dist/size-rollup-waapi-animate.js +1 -1
  43. package/dist/size-rollup-waapi-animate.js.map +1 -1
  44. package/package.json +3 -3
package/README.md CHANGED
@@ -128,7 +128,7 @@ Motion drives the animations on the Cursor homepage, and is working with Cursor
128
128
 
129
129
  ### Gold
130
130
 
131
- <a href="https://lottiefiles.com"><img alt="LottieFiles" src="https://github.com/user-attachments/assets/4e99d8c7-4cba-43ee-93c5-93861ae708ec" width="200px" height="120px"></a>
131
+ <a href="https://lottiefiles.com"><img alt="LottieFiles" src="https://github.com/user-attachments/assets/4e99d8c7-4cba-43ee-93c5-93861ae708ec" width="200px" height="120px"></a> <a href="https://mintlify.com"><img alt="Mintlify" src="https://github.com/user-attachments/assets/2740db2f-1877-49ae-ae80-ba5d19ef1587" width="200px" height="120px"></a>
132
132
 
133
133
  ### Silver
134
134
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var featureBundle = require('./feature-bundle-CGU3mAvs.js');
5
+ var featureBundle = require('./feature-bundle-jADFMKLx.js');
6
6
  require('motion-dom');
7
7
  require('react');
8
8
  require('react/jsx-runtime');
package/dist/cjs/dom.js CHANGED
@@ -629,6 +629,12 @@ const createScopedWaapiAnimate = (scope) => {
629
629
  };
630
630
  const animateMini = /*@__PURE__*/ createScopedWaapiAnimate();
631
631
 
632
+ function canUseNativeTimeline(target) {
633
+ if (typeof window === "undefined")
634
+ return false;
635
+ return target ? motionDom.supportsViewTimeline() : motionDom.supportsScrollTimeline();
636
+ }
637
+
632
638
  /**
633
639
  * A time in milliseconds, beyond which we consider the scroll velocity to be 0.
634
640
  */
@@ -802,6 +808,18 @@ function resolveOffset(offset, containerLength, targetLength, targetInset) {
802
808
  }
803
809
 
804
810
  const ScrollOffset = {
811
+ Enter: [
812
+ [0, 1],
813
+ [1, 1],
814
+ ],
815
+ Exit: [
816
+ [0, 0],
817
+ [1, 0],
818
+ ],
819
+ Any: [
820
+ [1, 0],
821
+ [0, 1],
822
+ ],
805
823
  All: [
806
824
  [0, 0],
807
825
  [1, 1],
@@ -1011,8 +1029,41 @@ function scrollInfo(onScroll, { container = document.scrollingElement, trackCont
1011
1029
  };
1012
1030
  }
1013
1031
 
1014
- function canUseNativeTimeline(target) {
1015
- return (typeof window !== "undefined" && !target && motionDom.supportsScrollTimeline());
1032
+ /**
1033
+ * Maps from ProgressIntersection pairs used by Motion's preset offsets to
1034
+ * ViewTimeline named ranges. Returns undefined for unrecognised patterns,
1035
+ * which signals the caller to fall back to JS-based scroll tracking.
1036
+ */
1037
+ const presets = [
1038
+ [ScrollOffset.Enter, "entry"],
1039
+ [ScrollOffset.Exit, "exit"],
1040
+ [ScrollOffset.Any, "cover"],
1041
+ [ScrollOffset.All, "contain"],
1042
+ ];
1043
+ function matchesPreset(offset, preset) {
1044
+ if (offset.length !== 2)
1045
+ return false;
1046
+ for (let i = 0; i < 2; i++) {
1047
+ const o = offset[i];
1048
+ const p = preset[i];
1049
+ if (!Array.isArray(o) ||
1050
+ o.length !== 2 ||
1051
+ o[0] !== p[0] ||
1052
+ o[1] !== p[1])
1053
+ return false;
1054
+ }
1055
+ return true;
1056
+ }
1057
+ function offsetToViewTimelineRange(offset) {
1058
+ if (!offset) {
1059
+ return { rangeStart: "contain 0%", rangeEnd: "contain 100%" };
1060
+ }
1061
+ for (const [preset, name] of presets) {
1062
+ if (matchesPreset(offset, preset)) {
1063
+ return { rangeStart: `${name} 0%`, rangeEnd: `${name} 100%` };
1064
+ }
1065
+ }
1066
+ return undefined;
1016
1067
  }
1017
1068
 
1018
1069
  const timelineCache = new Map();
@@ -1027,24 +1078,71 @@ function getTimeline({ source, container, ...options }) {
1027
1078
  const { axis } = options;
1028
1079
  if (source)
1029
1080
  container = source;
1030
- const containerCache = timelineCache.get(container) ?? new Map();
1031
- timelineCache.set(container, containerCache);
1081
+ let containerCache = timelineCache.get(container);
1082
+ if (!containerCache) {
1083
+ containerCache = new Map();
1084
+ timelineCache.set(container, containerCache);
1085
+ }
1032
1086
  const targetKey = options.target ?? "self";
1033
- const targetCache = containerCache.get(targetKey) ?? {};
1087
+ let targetCache = containerCache.get(targetKey);
1088
+ if (!targetCache) {
1089
+ targetCache = {};
1090
+ containerCache.set(targetKey, targetCache);
1091
+ }
1034
1092
  const axisKey = axis + (options.offset ?? []).join(",");
1035
1093
  if (!targetCache[axisKey]) {
1036
- targetCache[axisKey] =
1037
- canUseNativeTimeline(options.target)
1038
- ? new ScrollTimeline({ source: container, axis })
1039
- : scrollTimelineFallback({ container, ...options });
1094
+ if (options.target && canUseNativeTimeline(options.target)) {
1095
+ const range = offsetToViewTimelineRange(options.offset);
1096
+ if (range) {
1097
+ targetCache[axisKey] = new ViewTimeline({
1098
+ subject: options.target,
1099
+ axis,
1100
+ });
1101
+ }
1102
+ else {
1103
+ targetCache[axisKey] = scrollTimelineFallback({
1104
+ container,
1105
+ ...options,
1106
+ });
1107
+ }
1108
+ }
1109
+ else if (canUseNativeTimeline()) {
1110
+ targetCache[axisKey] = new ScrollTimeline({
1111
+ source: container,
1112
+ axis,
1113
+ });
1114
+ }
1115
+ else {
1116
+ targetCache[axisKey] = scrollTimelineFallback({
1117
+ container,
1118
+ ...options,
1119
+ });
1120
+ }
1040
1121
  }
1041
1122
  return targetCache[axisKey];
1042
1123
  }
1043
1124
 
1044
1125
  function attachToAnimation(animation, options) {
1045
1126
  const timeline = getTimeline(options);
1127
+ const range = options.target
1128
+ ? offsetToViewTimelineRange(options.offset)
1129
+ : undefined;
1130
+ /**
1131
+ * Use native timeline when:
1132
+ * - No target: ScrollTimeline (existing behaviour)
1133
+ * - Target with mappable offset: ViewTimeline with named range
1134
+ * - Target with unmappable offset: fall back to JS observe
1135
+ */
1136
+ const useNative = options.target
1137
+ ? canUseNativeTimeline(options.target) && !!range
1138
+ : canUseNativeTimeline();
1046
1139
  return animation.attachTimeline({
1047
- timeline: options.target ? undefined : timeline,
1140
+ timeline: useNative ? timeline : undefined,
1141
+ ...(range &&
1142
+ useNative && {
1143
+ rangeStart: range.rangeStart,
1144
+ rangeEnd: range.rangeEnd,
1145
+ }),
1048
1146
  observe: (valueAnimation) => {
1049
1147
  valueAnimation.pause();
1050
1148
  return motionDom.observeTimeline((progress) => {