motion 12.0.0-alpha.2 → 12.0.1

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 (157) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +7 -24
  3. package/dist/cjs/index.js +2792 -2446
  4. package/dist/cjs/mini.js +629 -193
  5. package/dist/cjs/react-client.js +3611 -3416
  6. package/dist/cjs/react-m.js +397 -351
  7. package/dist/cjs/react-mini.js +225 -191
  8. package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +3 -2
  9. package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +2 -1
  10. package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -1
  11. package/dist/es/framer-motion/dist/es/animation/animate/subject.mjs +1 -1
  12. package/dist/es/framer-motion/dist/es/animation/animators/AcceleratedAnimation.mjs +16 -12
  13. package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +3 -2
  14. package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +10 -10
  15. package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +2 -2
  16. package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +30 -89
  17. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +4 -4
  18. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +14 -0
  19. package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -1
  20. package/dist/es/framer-motion/dist/es/animation/animators/waapi/index.mjs +2 -1
  21. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +2 -1
  22. package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +2 -1
  23. package/dist/es/framer-motion/dist/es/animation/generators/spring/defaults.mjs +27 -0
  24. package/dist/es/framer-motion/dist/es/animation/generators/spring/find.mjs +10 -13
  25. package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +57 -18
  26. package/dist/es/framer-motion/dist/es/animation/hooks/animation-controls.mjs +1 -1
  27. package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +7 -6
  28. package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +6 -5
  29. package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +2 -1
  30. package/dist/es/framer-motion/dist/es/animation/optimized-appear/store-id.mjs +1 -1
  31. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +32 -6
  32. package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-repeat-duration.mjs +5 -0
  33. package/dist/es/framer-motion/dist/es/animation/sequence/utils/normalize-times.mjs +13 -0
  34. package/dist/es/framer-motion/dist/es/animation/utils/default-transitions.mjs +1 -1
  35. package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +10 -7
  36. package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +6 -3
  37. package/dist/es/framer-motion/dist/es/components/AnimateSharedLayout.mjs +1 -1
  38. package/dist/es/framer-motion/dist/es/components/Reorder/Group.mjs +1 -1
  39. package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +1 -1
  40. package/dist/es/framer-motion/dist/es/easing/cubic-bezier.mjs +2 -1
  41. package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +6 -6
  42. package/dist/es/framer-motion/dist/es/events/event-info.mjs +5 -4
  43. package/dist/es/framer-motion/dist/es/frameloop/frame.mjs +2 -1
  44. package/dist/es/framer-motion/dist/es/frameloop/render-step.mjs +3 -2
  45. package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +12 -15
  46. package/dist/es/framer-motion/dist/es/gestures/drag/index.mjs +2 -1
  47. package/dist/es/framer-motion/dist/es/gestures/drag/utils/constraints.mjs +2 -1
  48. package/dist/es/framer-motion/dist/es/gestures/hover.mjs +20 -22
  49. package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +6 -5
  50. package/dist/es/framer-motion/dist/es/gestures/pan/index.mjs +2 -1
  51. package/dist/es/framer-motion/dist/es/gestures/press.mjs +20 -119
  52. package/dist/es/framer-motion/dist/es/motion/index.mjs +11 -7
  53. package/dist/es/framer-motion/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
  54. package/dist/es/framer-motion/dist/es/motion/utils/use-motion-ref.mjs +3 -1
  55. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +1 -1
  56. package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +11 -5
  57. package/dist/es/framer-motion/dist/es/projection/animation/mix-values.mjs +3 -2
  58. package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +29 -23
  59. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +15 -13
  60. package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +4 -3
  61. package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +15 -0
  62. package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +2 -1
  63. package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +4 -4
  64. package/dist/es/framer-motion/dist/es/render/dom/scroll/info.mjs +2 -1
  65. package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/index.mjs +6 -5
  66. package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
  67. package/dist/es/framer-motion/dist/es/render/dom/utils/unit-conversion.mjs +2 -14
  68. package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +4 -3
  69. package/dist/es/framer-motion/dist/es/render/html/HTMLVisualElement.mjs +6 -20
  70. package/dist/es/framer-motion/dist/es/render/html/utils/build-styles.mjs +2 -2
  71. package/dist/es/framer-motion/dist/es/render/html/utils/build-transform.mjs +1 -1
  72. package/dist/es/framer-motion/dist/es/render/html/utils/keys-position.mjs +13 -0
  73. package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +6 -6
  74. package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +57 -24
  75. package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.mjs +1 -1
  76. package/dist/es/framer-motion/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
  77. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  78. package/dist/es/framer-motion/dist/es/utils/delay.mjs +2 -1
  79. package/dist/es/framer-motion/dist/es/utils/get-context-window.mjs +1 -1
  80. package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +8 -5
  81. package/dist/es/framer-motion/dist/es/utils/mix/color.mjs +1 -1
  82. package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -1
  83. package/dist/es/framer-motion/dist/es/utils/offsets/fill.mjs +2 -1
  84. package/dist/es/framer-motion/dist/es/utils/use-instant-transition.mjs +1 -1
  85. package/dist/es/framer-motion/dist/es/value/index.mjs +2 -2
  86. package/dist/es/framer-motion/dist/es/value/use-inverted-scale.mjs +1 -1
  87. package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +1 -1
  88. package/dist/es/framer-motion/dist/es/value/use-spring.mjs +3 -3
  89. package/dist/es/framer-motion/dist/es/value/use-will-change/get-will-change-name.mjs +1 -1
  90. package/dist/es/motion/lib/index.mjs +12 -7
  91. package/dist/es/motion/lib/mini.mjs +1 -0
  92. package/dist/es/motion/lib/react.mjs +41 -37
  93. package/dist/es/{framer-motion/dist/es/animation/GroupPlaybackControls.mjs → motion-dom/dist/es/animation/controls/BaseGroup.mjs} +7 -6
  94. package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +13 -0
  95. package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es/animation/generators}/utils/create-generator-easing.mjs +6 -3
  96. package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +85 -0
  97. package/dist/es/{framer-motion/dist/es/animation/animators/waapi → motion-dom/dist/es/animation/waapi/utils}/easing.mjs +3 -3
  98. package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/linear.mjs +4 -4
  99. package/dist/es/motion-dom/dist/es/gestures/drag/state/is-active.mjs +9 -0
  100. package/dist/es/motion-dom/dist/es/gestures/drag/state/set-active.mjs +28 -0
  101. package/dist/es/motion-dom/dist/es/gestures/hover.mjs +37 -0
  102. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +76 -0
  103. package/dist/es/motion-dom/dist/es/gestures/press/utils/is-keyboard-accessible.mjs +13 -0
  104. package/dist/es/motion-dom/dist/es/gestures/press/utils/keyboard.mjs +38 -0
  105. package/dist/es/motion-dom/dist/es/gestures/press/utils/state.mjs +3 -0
  106. package/dist/es/motion-dom/dist/es/gestures/utils/setup.mjs +15 -0
  107. package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +22 -0
  108. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-linear-easing.mjs → motion-dom/dist/es/utils/supports/linear-easing.mjs} +1 -1
  109. package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/memo-supports.mjs → motion-dom/dist/es/utils/supports/memo.mjs} +3 -2
  110. package/dist/es/motion-dom/dist/es/utils/supports/scroll-timeline.mjs +6 -0
  111. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/memo.mjs +1 -0
  112. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/noop.mjs +1 -0
  113. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/progress.mjs +1 -0
  114. package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/time-conversion.mjs +2 -0
  115. package/dist/motion.dev.js +2792 -2446
  116. package/dist/motion.js +1 -1
  117. package/package.json +6 -6
  118. package/.turbo/turbo-build.log +0 -47
  119. package/dist/es/framer-motion/dist/es/gestures/drag/utils/lock.mjs +0 -53
  120. package/dist/es/framer-motion/dist/es/render/dom/scroll/supports.mjs +0 -5
  121. package/dist/es/framer-motion/dist/es/render/dom/utils/resolve-element.mjs +0 -28
  122. package/lib/index.js +0 -2
  123. package/lib/index.js.map +0 -1
  124. package/lib/mini.js +0 -2
  125. package/lib/mini.js.map +0 -1
  126. package/lib/react-client.js +0 -3
  127. package/lib/react-client.js.map +0 -1
  128. package/lib/react-m.js +0 -3
  129. package/lib/react-m.js.map +0 -1
  130. package/lib/react-mini.js +0 -3
  131. package/lib/react-mini.js.map +0 -1
  132. package/lib/react.js +0 -3
  133. package/lib/react.js.map +0 -1
  134. package/rollup.config.mjs +0 -210
  135. package/src/index.ts +0 -1
  136. package/src/mini.ts +0 -1
  137. package/src/react-client.ts +0 -3
  138. package/src/react-m.ts +0 -3
  139. package/src/react-mini.ts +0 -3
  140. package/src/react.ts +0 -3
  141. package/tsconfig.json +0 -25
  142. package/types/index.d.ts +0 -1
  143. package/types/mini.d.ts +0 -1
  144. package/types/react-client.d.ts +0 -1
  145. package/types/react-m.d.ts +0 -1
  146. package/types/react-mini.d.ts +0 -1
  147. package/types/react.d.ts +0 -1
  148. /package/dist/es/framer-motion/dist/es/render/html/utils/{transform.mjs → keys-transform.mjs} +0 -0
  149. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/calc-duration.mjs +0 -0
  150. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/is-generator.mjs +0 -0
  151. /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/utils/get-value-transition.mjs +0 -0
  152. /package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/attach-timeline.mjs +0 -0
  153. /package/dist/es/{framer-motion → motion-dom}/dist/es/gestures/utils/is-node-or-child.mjs +0 -0
  154. /package/dist/es/{framer-motion/dist/es/events → motion-dom/dist/es/gestures}/utils/is-primary-pointer.mjs +0 -0
  155. /package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es}/utils/is-bezier-definition.mjs +0 -0
  156. /package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-flags.mjs → motion-dom/dist/es/utils/supports/flags.mjs} +0 -0
  157. /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/errors.mjs +0 -0
@@ -23,6 +23,19 @@ function useUnmountEffect(callback) {
23
23
  return react.useEffect(() => () => callback(), []);
24
24
  }
25
25
 
26
+ /*#__NO_SIDE_EFFECTS__*/
27
+ const noop = (any) => any;
28
+
29
+ let invariant = noop;
30
+ if (process.env.NODE_ENV !== "production") {
31
+ invariant = (check, message) => {
32
+ if (!check) {
33
+ throw new Error(message);
34
+ }
35
+ };
36
+ }
37
+
38
+ /*#__NO_SIDE_EFFECTS__*/
26
39
  function memo(callback) {
27
40
  let result;
28
41
  return () => {
@@ -32,16 +45,46 @@ function memo(callback) {
32
45
  };
33
46
  }
34
47
 
48
+ /*
49
+ Progress within given range
50
+
51
+ Given a lower limit and an upper limit, we return the progress
52
+ (expressed as a number 0-1) represented by the given value, and
53
+ limit that progress to within 0-1.
54
+
55
+ @param [number]: Lower limit
56
+ @param [number]: Upper limit
57
+ @param [number]: Value to find progress within given range
58
+ @return [number]: Progress of value within range as expressed 0-1
59
+ */
60
+ /*#__NO_SIDE_EFFECTS__*/
61
+ const progress = (from, to, value) => {
62
+ const toFromDifference = to - from;
63
+ return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
64
+ };
65
+
66
+ /**
67
+ * Converts seconds to milliseconds
68
+ *
69
+ * @param seconds - Time in seconds.
70
+ * @return milliseconds - Converted time in milliseconds.
71
+ */
72
+ /*#__NO_SIDE_EFFECTS__*/
73
+ const secondsToMilliseconds = (seconds) => seconds * 1000;
74
+ /*#__NO_SIDE_EFFECTS__*/
75
+ const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
76
+
35
77
  const supportsScrollTimeline = memo(() => window.ScrollTimeline !== undefined);
36
78
 
37
- class GroupPlaybackControls {
79
+ class BaseGroupPlaybackControls {
38
80
  constructor(animations) {
39
81
  // Bound to accomodate common `return animation.stop` pattern
40
82
  this.stop = () => this.runAll("stop");
41
83
  this.animations = animations.filter(Boolean);
42
84
  }
43
- then(onResolve, onReject) {
44
- return Promise.all(this.animations).then(onResolve).catch(onReject);
85
+ get finished() {
86
+ // Support for new finished Promise and legacy thennable API
87
+ return Promise.all(this.animations.map((animation) => "finished" in animation ? animation.finished : animation));
45
88
  }
46
89
  /**
47
90
  * TODO: Filter out cancelled or stopped animations before returning
@@ -59,7 +102,7 @@ class GroupPlaybackControls {
59
102
  if (supportsScrollTimeline() && animation.attachTimeline) {
60
103
  return animation.attachTimeline(timeline);
61
104
  }
62
- else {
105
+ else if (typeof fallback === "function") {
63
106
  return fallback(animation);
64
107
  }
65
108
  });
@@ -112,50 +155,15 @@ class GroupPlaybackControls {
112
155
  }
113
156
  }
114
157
 
115
- const noop = (any) => any;
116
-
117
- let invariant = noop;
118
- if (process.env.NODE_ENV !== "production") {
119
- invariant = (check, message) => {
120
- if (!check) {
121
- throw new Error(message);
122
- }
123
- };
124
- }
125
-
126
- function resolveElements(elements, scope, selectorCache) {
127
- var _a;
128
- if (typeof elements === "string") {
129
- let root = document;
130
- if (scope) {
131
- invariant(Boolean(scope.current), "Scope provided, but no element detected.");
132
- root = scope.current;
133
- }
134
- if (selectorCache) {
135
- (_a = selectorCache[elements]) !== null && _a !== void 0 ? _a : (selectorCache[elements] = root.querySelectorAll(elements));
136
- elements = selectorCache[elements];
137
- }
138
- else {
139
- elements = root.querySelectorAll(elements);
140
- }
141
- }
142
- else if (elements instanceof Element) {
143
- elements = [elements];
144
- }
145
- /**
146
- * Return an empty array
147
- */
148
- return Array.from(elements || []);
149
- }
150
-
151
158
  /**
152
- * Converts seconds to milliseconds
153
- *
154
- * @param seconds - Time in seconds.
155
- * @return milliseconds - Converted time in milliseconds.
159
+ * TODO: This is a temporary class to support the legacy
160
+ * thennable API
156
161
  */
157
- const secondsToMilliseconds = (seconds) => seconds * 1000;
158
- const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
162
+ class GroupPlaybackControls extends BaseGroupPlaybackControls {
163
+ then(onResolve, onReject) {
164
+ return Promise.all(this.animations).then(onResolve).catch(onReject);
165
+ }
166
+ }
159
167
 
160
168
  function getValueTransition(transition, key) {
161
169
  return transition
@@ -165,36 +173,126 @@ function getValueTransition(transition, key) {
165
173
  : undefined;
166
174
  }
167
175
 
168
- const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
176
+ /**
177
+ * Implement a practical max duration for keyframe generation
178
+ * to prevent infinite loops
179
+ */
180
+ const maxGeneratorDuration = 20000;
181
+ function calcGeneratorDuration(generator) {
182
+ let duration = 0;
183
+ const timeStep = 50;
184
+ let state = generator.next(duration);
185
+ while (!state.done && duration < maxGeneratorDuration) {
186
+ duration += timeStep;
187
+ state = generator.next(duration);
188
+ }
189
+ return duration >= maxGeneratorDuration ? Infinity : duration;
190
+ }
169
191
 
170
- /*
171
- Progress within given range
192
+ /**
193
+ * Create a progress => progress easing function from a generator.
194
+ */
195
+ function createGeneratorEasing(options, scale = 100, createGenerator) {
196
+ const generator = createGenerator({ ...options, keyframes: [0, scale] });
197
+ const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
198
+ return {
199
+ type: "keyframes",
200
+ ease: (progress) => {
201
+ return generator.next(duration * progress).value / scale;
202
+ },
203
+ duration: millisecondsToSeconds(duration),
204
+ };
205
+ }
172
206
 
173
- Given a lower limit and an upper limit, we return the progress
174
- (expressed as a number 0-1) represented by the given value, and
175
- limit that progress to within 0-1.
207
+ function isGenerator(type) {
208
+ return typeof type === "function";
209
+ }
176
210
 
177
- @param [number]: Lower limit
178
- @param [number]: Upper limit
179
- @param [number]: Value to find progress within given range
180
- @return [number]: Progress of value within range as expressed 0-1
181
- */
182
- const progress = (from, to, value) => {
183
- const toFromDifference = to - from;
184
- return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
185
- };
211
+ function attachTimeline(animation, timeline) {
212
+ animation.timeline = timeline;
213
+ animation.onfinish = null;
214
+ }
186
215
 
187
- // Create a linear easing point for every 10 ms
188
- const resolution = 10;
189
- const generateLinearEasing = (easing, duration // as milliseconds
190
- ) => {
191
- let points = "";
192
- const numPoints = Math.max(Math.round(duration / resolution), 2);
193
- for (let i = 0; i < numPoints; i++) {
194
- points += easing(progress(0, numPoints - 1, i)) + ", ";
216
+ class NativeAnimationControls {
217
+ constructor(animation) {
218
+ this.animation = animation;
195
219
  }
196
- return `linear(${points.substring(0, points.length - 2)})`;
197
- };
220
+ get duration() {
221
+ var _a, _b, _c;
222
+ const durationInMs = ((_b = (_a = this.animation) === null || _a === void 0 ? void 0 : _a.effect) === null || _b === void 0 ? void 0 : _b.getComputedTiming().duration) ||
223
+ ((_c = this.options) === null || _c === void 0 ? void 0 : _c.duration) ||
224
+ 300;
225
+ return millisecondsToSeconds(Number(durationInMs));
226
+ }
227
+ get time() {
228
+ var _a;
229
+ if (this.animation) {
230
+ return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
231
+ }
232
+ return 0;
233
+ }
234
+ set time(newTime) {
235
+ if (this.animation) {
236
+ this.animation.currentTime = secondsToMilliseconds(newTime);
237
+ }
238
+ }
239
+ get speed() {
240
+ return this.animation ? this.animation.playbackRate : 1;
241
+ }
242
+ set speed(newSpeed) {
243
+ if (this.animation) {
244
+ this.animation.playbackRate = newSpeed;
245
+ }
246
+ }
247
+ get state() {
248
+ return this.animation ? this.animation.playState : "finished";
249
+ }
250
+ get startTime() {
251
+ return this.animation ? this.animation.startTime : null;
252
+ }
253
+ get finished() {
254
+ return this.animation ? this.animation.finished : Promise.resolve();
255
+ }
256
+ play() {
257
+ this.animation && this.animation.play();
258
+ }
259
+ pause() {
260
+ this.animation && this.animation.pause();
261
+ }
262
+ stop() {
263
+ if (!this.animation ||
264
+ this.state === "idle" ||
265
+ this.state === "finished") {
266
+ return;
267
+ }
268
+ if (this.animation.commitStyles) {
269
+ this.animation.commitStyles();
270
+ }
271
+ this.cancel();
272
+ }
273
+ flatten() {
274
+ var _a;
275
+ if (!this.animation)
276
+ return;
277
+ (_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
278
+ }
279
+ attachTimeline(timeline) {
280
+ if (this.animation)
281
+ attachTimeline(this.animation, timeline);
282
+ return noop;
283
+ }
284
+ complete() {
285
+ this.animation && this.animation.finish();
286
+ }
287
+ cancel() {
288
+ try {
289
+ this.animation && this.animation.cancel();
290
+ }
291
+ catch (e) { }
292
+ }
293
+ }
294
+
295
+ const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
198
296
 
199
297
  /**
200
298
  * Add the ability for test suites to manually set support flags
@@ -221,6 +319,17 @@ const supportsLinearEasing = /*@__PURE__*/ memoSupports(() => {
221
319
  return true;
222
320
  }, "linearEasing");
223
321
 
322
+ const generateLinearEasing = (easing, duration, // as milliseconds
323
+ resolution = 10 // as milliseconds
324
+ ) => {
325
+ let points = "";
326
+ const numPoints = Math.max(Math.round(duration / resolution), 2);
327
+ for (let i = 0; i < numPoints; i++) {
328
+ points += easing(progress(0, numPoints - 1, i)) + ", ";
329
+ }
330
+ return `linear(${points.substring(0, points.length - 2)})`;
331
+ };
332
+
224
333
  const cubicBezierAsString = ([a, b, c, d]) => `cubic-bezier(${a}, ${b}, ${c}, ${d})`;
225
334
  const supportedWaapiEasing = {
226
335
  linear: "linear",
@@ -252,6 +361,27 @@ function mapEasingToNativeEasing(easing, duration) {
252
361
  }
253
362
  }
254
363
 
364
+ function resolveElements(elementOrSelector, scope, selectorCache) {
365
+ var _a;
366
+ if (elementOrSelector instanceof Element) {
367
+ return [elementOrSelector];
368
+ }
369
+ else if (typeof elementOrSelector === "string") {
370
+ let root = document;
371
+ if (scope) {
372
+ // TODO: Refactor to utils package
373
+ // invariant(
374
+ // Boolean(scope.current),
375
+ // "Scope provided, but no element detected."
376
+ // )
377
+ root = scope.current;
378
+ }
379
+ const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
380
+ return elements ? Array.from(elements) : [];
381
+ }
382
+ return Array.from(elementOrSelector);
383
+ }
384
+
255
385
  function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
256
386
  const keyframeOptions = { [valueName]: keyframes };
257
387
  if (times)
@@ -272,35 +402,6 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
272
402
  });
273
403
  }
274
404
 
275
- /**
276
- * Implement a practical max duration for keyframe generation
277
- * to prevent infinite loops
278
- */
279
- const maxGeneratorDuration = 20000;
280
- function calcGeneratorDuration(generator) {
281
- let duration = 0;
282
- const timeStep = 50;
283
- let state = generator.next(duration);
284
- while (!state.done && duration < maxGeneratorDuration) {
285
- duration += timeStep;
286
- state = generator.next(duration);
287
- }
288
- return duration >= maxGeneratorDuration ? Infinity : duration;
289
- }
290
-
291
- /**
292
- * Create a progress => progress easing function from a generator.
293
- */
294
- function createGeneratorEasing(options, scale = 100, createGenerator) {
295
- const generator = createGenerator({ ...options, keyframes: [0, scale] });
296
- const duration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
297
- return {
298
- type: "keyframes",
299
- ease: (progress) => generator.next(duration * progress).value / scale,
300
- duration: millisecondsToSeconds(duration),
301
- };
302
- }
303
-
304
405
  const createUnitType = (unit) => ({
305
406
  test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
306
407
  parse: parseFloat,
@@ -346,15 +447,6 @@ const browserNumberValueTypes = {
346
447
  backgroundPositionY: px,
347
448
  };
348
449
 
349
- function isGenerator(type) {
350
- return typeof type === "function";
351
- }
352
-
353
- function attachTimeline(animation, timeline) {
354
- animation.timeline = timeline;
355
- animation.onfinish = null;
356
- }
357
-
358
450
  const isNotNull = (value) => value !== null;
359
451
  function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
360
452
  const resolvedKeyframes = keyframes.filter(isNotNull);
@@ -406,12 +498,9 @@ function getElementAnimationState(element) {
406
498
  state.set(element, animationState);
407
499
  return state.get(element);
408
500
  }
409
- class NativeAnimation {
501
+ class NativeAnimation extends NativeAnimationControls {
410
502
  constructor(element, valueName, valueKeyframes, options) {
411
503
  const isCSSVar = valueName.startsWith("--");
412
- this.setValue = isCSSVar ? setCSSVar : setStyle;
413
- this.options = options;
414
- this.updateFinishedPromise();
415
504
  invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
416
505
  const existingAnimation = getElementAnimationState(element).get(valueName);
417
506
  existingAnimation && existingAnimation.stop();
@@ -424,6 +513,7 @@ class NativeAnimation {
424
513
  valueKeyframes = [valueKeyframes];
425
514
  }
426
515
  hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
516
+ // TODO: Replace this with toString()?
427
517
  if (isGenerator(options.type)) {
428
518
  const generatorOptions = createGeneratorEasing(options, 100, options.type);
429
519
  options.ease = supportsLinearEasing()
@@ -435,92 +525,35 @@ class NativeAnimation {
435
525
  else {
436
526
  options.ease = options.ease || defaultEasing;
437
527
  }
438
- this.removeAnimation = () => { var _a; return (_a = state.get(element)) === null || _a === void 0 ? void 0 : _a.delete(valueName); };
439
528
  const onFinish = () => {
440
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, this.options));
529
+ this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
441
530
  this.cancel();
442
531
  this.resolveFinishedPromise();
443
532
  };
533
+ const init = () => {
534
+ this.setValue = isCSSVar ? setCSSVar : setStyle;
535
+ this.options = options;
536
+ this.updateFinishedPromise();
537
+ this.removeAnimation = () => {
538
+ const elementState = state.get(element);
539
+ elementState && elementState.delete(valueName);
540
+ };
541
+ };
444
542
  if (!supportsWaapi()) {
543
+ super();
544
+ init();
445
545
  onFinish();
446
546
  }
447
547
  else {
448
- this.animation = startWaapiAnimation(element, valueName, valueKeyframes, options);
548
+ super(startWaapiAnimation(element, valueName, valueKeyframes, options));
549
+ init();
449
550
  if (options.autoplay === false) {
450
551
  this.animation.pause();
451
552
  }
452
553
  this.animation.onfinish = onFinish;
453
- if (this.pendingTimeline) {
454
- attachTimeline(this.animation, this.pendingTimeline);
455
- }
456
554
  getElementAnimationState(element).set(valueName, this);
457
555
  }
458
556
  }
459
- get duration() {
460
- return millisecondsToSeconds(this.options.duration || 300);
461
- }
462
- get time() {
463
- var _a;
464
- if (this.animation) {
465
- return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
466
- }
467
- return 0;
468
- }
469
- set time(newTime) {
470
- if (this.animation) {
471
- this.animation.currentTime = secondsToMilliseconds(newTime);
472
- }
473
- }
474
- get speed() {
475
- return this.animation ? this.animation.playbackRate : 1;
476
- }
477
- set speed(newSpeed) {
478
- if (this.animation) {
479
- this.animation.playbackRate = newSpeed;
480
- }
481
- }
482
- get state() {
483
- return this.animation ? this.animation.playState : "finished";
484
- }
485
- get startTime() {
486
- return this.animation ? this.animation.startTime : null;
487
- }
488
- flatten() {
489
- var _a;
490
- if (!this.animation)
491
- return;
492
- (_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
493
- }
494
- play() {
495
- if (this.state === "finished") {
496
- this.updateFinishedPromise();
497
- }
498
- this.animation && this.animation.play();
499
- }
500
- pause() {
501
- this.animation && this.animation.pause();
502
- }
503
- stop() {
504
- if (!this.animation ||
505
- this.state === "idle" ||
506
- this.state === "finished") {
507
- return;
508
- }
509
- if (this.animation.commitStyles) {
510
- this.animation.commitStyles();
511
- }
512
- this.cancel();
513
- }
514
- complete() {
515
- this.animation && this.animation.finish();
516
- }
517
- cancel() {
518
- this.removeAnimation();
519
- try {
520
- this.animation && this.animation.cancel();
521
- }
522
- catch (e) { }
523
- }
524
557
  /**
525
558
  * Allows the returned animation to be awaited or promise-chained. Currently
526
559
  * resolves when the animation finishes at all but in a future update could/should
@@ -534,14 +567,15 @@ class NativeAnimation {
534
567
  this.resolveFinishedPromise = resolve;
535
568
  });
536
569
  }
537
- attachTimeline(timeline) {
538
- if (!this.animation) {
539
- this.pendingTimeline = timeline;
540
- }
541
- else {
542
- attachTimeline(this.animation, timeline);
570
+ play() {
571
+ if (this.state === "finished") {
572
+ this.updateFinishedPromise();
543
573
  }
544
- return noop;
574
+ super.play();
575
+ }
576
+ cancel() {
577
+ this.removeAnimation();
578
+ super.cancel();
545
579
  }
546
580
  }
547
581
 
@@ -1,9 +1,10 @@
1
- import { GroupPlaybackControls } from '../GroupPlaybackControls.mjs';
1
+ import { GroupPlaybackControls } from '../../../../../motion-dom/dist/es/animation/controls/Group.mjs';
2
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
3
  import { animateSequence } from './sequence.mjs';
3
4
  import { animateSubject } from './subject.mjs';
4
5
 
5
6
  function isSequence(value) {
6
- return Array.isArray(value) && Array.isArray(value[0]);
7
+ return Array.isArray(value) && value.some(Array.isArray);
7
8
  }
8
9
  /**
9
10
  * Creates an animation function that is optionally scoped
@@ -1,4 +1,5 @@
1
- import { resolveElements } from '../../render/dom/utils/resolve-element.mjs';
1
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { resolveElements } from '../../../../../motion-dom/dist/es/utils/resolve-elements.mjs';
2
3
  import { isDOMKeyframes } from '../utils/is-dom-keyframes.mjs';
3
4
 
4
5
  function resolveSubjects(subject, keyframes, scope, selectorCache) {
@@ -1,6 +1,6 @@
1
- import { animateMotionValue } from '../interfaces/motion-value.mjs';
2
1
  import { motionValue } from '../../value/index.mjs';
3
2
  import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
3
+ import { animateMotionValue } from '../interfaces/motion-value.mjs';
4
4
 
5
5
  function animateSingleValue(value, keyframes, options) {
6
6
  const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
@@ -1,5 +1,5 @@
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
1
2
  import { visualElementStore } from '../../render/store.mjs';
2
- import { invariant } from '../../utils/errors.mjs';
3
3
  import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
4
4
  import { animateTarget } from '../interfaces/visual-element-target.mjs';
5
5
  import { createDOMVisualElement, createObjectVisualElement } from '../utils/create-visual-element.mjs';
@@ -1,18 +1,19 @@
1
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
3
+ import { millisecondsToSeconds, secondsToMilliseconds } from '../../../../../motion-utils/dist/es/time-conversion.mjs';
4
+ import { isGenerator } from '../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
5
+ import { attachTimeline } from '../../../../../motion-dom/dist/es/animation/waapi/utils/attach-timeline.mjs';
6
+ import { isWaapiSupportedEasing } from '../../../../../motion-dom/dist/es/animation/waapi/utils/easing.mjs';
7
+ import { supportsLinearEasing } from '../../../../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
1
8
  import { anticipate } from '../../easing/anticipate.mjs';
2
9
  import { backInOut } from '../../easing/back.mjs';
3
10
  import { circInOut } from '../../easing/circ.mjs';
4
11
  import { DOMKeyframesResolver } from '../../render/dom/DOMKeyframesResolver.mjs';
5
- import { noop } from '../../utils/noop.mjs';
6
- import { millisecondsToSeconds, secondsToMilliseconds } from '../../utils/time-conversion.mjs';
7
- import { isGenerator } from '../generators/utils/is-generator.mjs';
8
12
  import { BaseAnimation } from './BaseAnimation.mjs';
9
13
  import { MainThreadAnimation } from './MainThreadAnimation.mjs';
10
14
  import { acceleratedValues } from './utils/accelerated-values.mjs';
11
15
  import { startWaapiAnimation } from './waapi/index.mjs';
12
- import { isWaapiSupportedEasing } from './waapi/easing.mjs';
13
- import { attachTimeline } from './waapi/utils/attach-timeline.mjs';
14
16
  import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.mjs';
15
- import { supportsLinearEasing } from './waapi/utils/supports-linear-easing.mjs';
16
17
  import { supportsWaapi } from './waapi/utils/supports-waapi.mjs';
17
18
 
18
19
  /**
@@ -84,13 +85,12 @@ class AcceleratedAnimation extends BaseAnimation {
84
85
  this.resolver.scheduleResolve();
85
86
  }
86
87
  initPlayback(keyframes, finalKeyframe) {
87
- var _a;
88
88
  let { duration = 300, times, ease, type, motionValue, name, startTime, } = this.options;
89
89
  /**
90
90
  * If element has since been unmounted, return false to indicate
91
91
  * the animation failed to initialised.
92
92
  */
93
- if (!((_a = motionValue.owner) === null || _a === void 0 ? void 0 : _a.current)) {
93
+ if (!motionValue.owner || !motionValue.owner.current) {
94
94
  return false;
95
95
  }
96
96
  /**
@@ -297,17 +297,21 @@ class AcceleratedAnimation extends BaseAnimation {
297
297
  }
298
298
  static supports(options) {
299
299
  const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
300
+ if (!motionValue ||
301
+ !motionValue.owner ||
302
+ !(motionValue.owner.current instanceof HTMLElement)) {
303
+ return false;
304
+ }
305
+ const { onUpdate, transformTemplate } = motionValue.owner.getProps();
300
306
  return (supportsWaapi() &&
301
307
  name &&
302
308
  acceleratedValues.has(name) &&
303
- motionValue &&
304
- motionValue.owner &&
305
- motionValue.owner.current instanceof HTMLElement &&
306
309
  /**
307
310
  * If we're outputting values to onUpdate then we can't use WAAPI as there's
308
311
  * no way to read the value from WAAPI every frame.
309
312
  */
310
- !motionValue.owner.getProps().onUpdate &&
313
+ !onUpdate &&
314
+ !transformTemplate &&
311
315
  !repeatDelay &&
312
316
  repeatType !== "mirror" &&
313
317
  damping !== 0 &&
@@ -74,8 +74,9 @@ class BaseAnimation {
74
74
  if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
75
75
  // Finish immediately
76
76
  if (instantAnimationState.current || !delay) {
77
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
78
- onComplete === null || onComplete === void 0 ? void 0 : onComplete();
77
+ onUpdate &&
78
+ onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
79
+ onComplete && onComplete();
79
80
  this.resolveFinishedPromise();
80
81
  return;
81
82
  }