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
@@ -1,17 +1,17 @@
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { millisecondsToSeconds, secondsToMilliseconds } from '../../../../../motion-utils/dist/es/time-conversion.mjs';
3
+ import { calcGeneratorDuration } from '../../../../../motion-dom/dist/es/animation/generators/utils/calc-duration.mjs';
4
+ import { isGenerator } from '../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
1
5
  import { KeyframeResolver } from '../../render/utils/KeyframesResolver.mjs';
2
- import { spring } from '../generators/spring/index.mjs';
6
+ import { clamp } from '../../utils/clamp.mjs';
7
+ import { mix } from '../../utils/mix/index.mjs';
8
+ import { pipe } from '../../utils/pipe.mjs';
3
9
  import { inertia } from '../generators/inertia.mjs';
4
10
  import { keyframes } from '../generators/keyframes.mjs';
11
+ import { spring } from '../generators/spring/index.mjs';
5
12
  import { BaseAnimation } from './BaseAnimation.mjs';
6
- import { pipe } from '../../utils/pipe.mjs';
7
- import { mix } from '../../utils/mix/index.mjs';
8
- import { calcGeneratorDuration } from '../generators/utils/calc-duration.mjs';
9
- import { millisecondsToSeconds, secondsToMilliseconds } from '../../utils/time-conversion.mjs';
10
- import { clamp } from '../../utils/clamp.mjs';
11
- import { invariant } from '../../utils/errors.mjs';
12
13
  import { frameloopDriver } from './drivers/driver-frameloop.mjs';
13
14
  import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.mjs';
14
- import { isGenerator } from '../generators/utils/is-generator.mjs';
15
15
 
16
16
  const generators = {
17
17
  decay: inertia,
@@ -61,13 +61,13 @@ class MainThreadAnimation extends BaseAnimation {
61
61
  * animation.stop is returned as a reference from a useEffect.
62
62
  */
63
63
  this.stop = () => {
64
- const { onStop } = this.options;
65
- onStop && onStop();
66
64
  this.resolver.cancel();
67
65
  this.isStopped = true;
68
66
  if (this.state === "idle")
69
67
  return;
70
68
  this.teardown();
69
+ const { onStop } = this.options;
70
+ onStop && onStop();
71
71
  };
72
72
  const { name, motionValue, element, keyframes } = this.options;
73
73
  const KeyframeResolver$1 = (element === null || element === void 0 ? void 0 : element.KeyframeResolver) || KeyframeResolver;
@@ -1,5 +1,5 @@
1
- import { warning } from '../../../utils/errors.mjs';
2
- import { isGenerator } from '../../generators/utils/is-generator.mjs';
1
+ import { warning } from '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { isGenerator } from '../../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
3
3
  import { isAnimatable } from '../../utils/is-animatable.mjs';
4
4
 
5
5
  function hasKeyframesChanged(keyframes) {
@@ -1,14 +1,13 @@
1
+ import { invariant } from '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { secondsToMilliseconds } from '../../../../../../motion-utils/dist/es/time-conversion.mjs';
3
+ import { createGeneratorEasing } from '../../../../../../motion-dom/dist/es/animation/generators/utils/create-generator-easing.mjs';
4
+ import { isGenerator } from '../../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
5
+ import { NativeAnimationControls } from '../../../../../../motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs';
6
+ import { supportsLinearEasing } from '../../../../../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
1
7
  import { startWaapiAnimation } from './index.mjs';
2
- import { createGeneratorEasing } from '../../../easing/utils/create-generator-easing.mjs';
3
8
  import { browserNumberValueTypes } from '../../../render/dom/value-types/number-browser.mjs';
4
- import { invariant } from '../../../utils/errors.mjs';
5
- import { noop } from '../../../utils/noop.mjs';
6
- import { secondsToMilliseconds, millisecondsToSeconds } from '../../../utils/time-conversion.mjs';
7
- import { isGenerator } from '../../generators/utils/is-generator.mjs';
8
- import { attachTimeline } from './utils/attach-timeline.mjs';
9
9
  import { getFinalKeyframe } from './utils/get-final-keyframe.mjs';
10
10
  import { setCSSVar, setStyle } from './utils/style.mjs';
11
- import { supportsLinearEasing } from './utils/supports-linear-easing.mjs';
12
11
  import { supportsPartialKeyframes } from './utils/supports-partial-keyframes.mjs';
13
12
  import { supportsWaapi } from './utils/supports-waapi.mjs';
14
13
 
@@ -33,12 +32,9 @@ function getElementAnimationState(element) {
33
32
  state.set(element, animationState);
34
33
  return state.get(element);
35
34
  }
36
- class NativeAnimation {
35
+ class NativeAnimation extends NativeAnimationControls {
37
36
  constructor(element, valueName, valueKeyframes, options) {
38
37
  const isCSSVar = valueName.startsWith("--");
39
- this.setValue = isCSSVar ? setCSSVar : setStyle;
40
- this.options = options;
41
- this.updateFinishedPromise();
42
38
  invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
43
39
  const existingAnimation = getElementAnimationState(element).get(valueName);
44
40
  existingAnimation && existingAnimation.stop();
@@ -51,6 +47,7 @@ class NativeAnimation {
51
47
  valueKeyframes = [valueKeyframes];
52
48
  }
53
49
  hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
50
+ // TODO: Replace this with toString()?
54
51
  if (isGenerator(options.type)) {
55
52
  const generatorOptions = createGeneratorEasing(options, 100, options.type);
56
53
  options.ease = supportsLinearEasing()
@@ -62,92 +59,35 @@ class NativeAnimation {
62
59
  else {
63
60
  options.ease = options.ease || defaultEasing;
64
61
  }
65
- this.removeAnimation = () => { var _a; return (_a = state.get(element)) === null || _a === void 0 ? void 0 : _a.delete(valueName); };
66
62
  const onFinish = () => {
67
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, this.options));
63
+ this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
68
64
  this.cancel();
69
65
  this.resolveFinishedPromise();
70
66
  };
67
+ const init = () => {
68
+ this.setValue = isCSSVar ? setCSSVar : setStyle;
69
+ this.options = options;
70
+ this.updateFinishedPromise();
71
+ this.removeAnimation = () => {
72
+ const elementState = state.get(element);
73
+ elementState && elementState.delete(valueName);
74
+ };
75
+ };
71
76
  if (!supportsWaapi()) {
77
+ super();
78
+ init();
72
79
  onFinish();
73
80
  }
74
81
  else {
75
- this.animation = startWaapiAnimation(element, valueName, valueKeyframes, options);
82
+ super(startWaapiAnimation(element, valueName, valueKeyframes, options));
83
+ init();
76
84
  if (options.autoplay === false) {
77
85
  this.animation.pause();
78
86
  }
79
87
  this.animation.onfinish = onFinish;
80
- if (this.pendingTimeline) {
81
- attachTimeline(this.animation, this.pendingTimeline);
82
- }
83
88
  getElementAnimationState(element).set(valueName, this);
84
89
  }
85
90
  }
86
- get duration() {
87
- return millisecondsToSeconds(this.options.duration || 300);
88
- }
89
- get time() {
90
- var _a;
91
- if (this.animation) {
92
- return millisecondsToSeconds(((_a = this.animation) === null || _a === void 0 ? void 0 : _a.currentTime) || 0);
93
- }
94
- return 0;
95
- }
96
- set time(newTime) {
97
- if (this.animation) {
98
- this.animation.currentTime = secondsToMilliseconds(newTime);
99
- }
100
- }
101
- get speed() {
102
- return this.animation ? this.animation.playbackRate : 1;
103
- }
104
- set speed(newSpeed) {
105
- if (this.animation) {
106
- this.animation.playbackRate = newSpeed;
107
- }
108
- }
109
- get state() {
110
- return this.animation ? this.animation.playState : "finished";
111
- }
112
- get startTime() {
113
- return this.animation ? this.animation.startTime : null;
114
- }
115
- flatten() {
116
- var _a;
117
- if (!this.animation)
118
- return;
119
- (_a = this.animation.effect) === null || _a === void 0 ? void 0 : _a.updateTiming({ easing: "linear" });
120
- }
121
- play() {
122
- if (this.state === "finished") {
123
- this.updateFinishedPromise();
124
- }
125
- this.animation && this.animation.play();
126
- }
127
- pause() {
128
- this.animation && this.animation.pause();
129
- }
130
- stop() {
131
- if (!this.animation ||
132
- this.state === "idle" ||
133
- this.state === "finished") {
134
- return;
135
- }
136
- if (this.animation.commitStyles) {
137
- this.animation.commitStyles();
138
- }
139
- this.cancel();
140
- }
141
- complete() {
142
- this.animation && this.animation.finish();
143
- }
144
- cancel() {
145
- this.removeAnimation();
146
- try {
147
- this.animation && this.animation.cancel();
148
- }
149
- catch (e) { }
150
- }
151
91
  /**
152
92
  * Allows the returned animation to be awaited or promise-chained. Currently
153
93
  * resolves when the animation finishes at all but in a future update could/should
@@ -161,14 +101,15 @@ class NativeAnimation {
161
101
  this.resolveFinishedPromise = resolve;
162
102
  });
163
103
  }
164
- attachTimeline(timeline) {
165
- if (!this.animation) {
166
- this.pendingTimeline = timeline;
167
- }
168
- else {
169
- attachTimeline(this.animation, timeline);
104
+ play() {
105
+ if (this.state === "finished") {
106
+ this.updateFinishedPromise();
170
107
  }
171
- return noop;
108
+ super.play();
109
+ }
110
+ cancel() {
111
+ this.removeAnimation();
112
+ super.cancel();
172
113
  }
173
114
  }
174
115
 
@@ -1,7 +1,7 @@
1
- import { resolveElements } from '../../../render/dom/utils/resolve-element.mjs';
2
- import { invariant } from '../../../utils/errors.mjs';
3
- import { secondsToMilliseconds } from '../../../utils/time-conversion.mjs';
4
- import { getValueTransition } from '../../utils/get-value-transition.mjs';
1
+ import { invariant } from '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { secondsToMilliseconds } from '../../../../../../motion-utils/dist/es/time-conversion.mjs';
3
+ import { getValueTransition } from '../../../../../../motion-dom/dist/es/animation/utils/get-value-transition.mjs';
4
+ import { resolveElements } from '../../../../../../motion-dom/dist/es/utils/resolve-elements.mjs';
5
5
  import { NativeAnimation } from './NativeAnimation.mjs';
6
6
 
7
7
  function animateElements(elementOrSelector, keyframes, options, scope) {
@@ -0,0 +1,14 @@
1
+ import { GroupPlaybackControls } from '../../../../../../motion-dom/dist/es/animation/controls/Group.mjs';
2
+ import '../../../../../../motion-utils/dist/es/errors.mjs';
3
+ import { createAnimationsFromSequence } from '../../sequence/create.mjs';
4
+ import { animateElements } from './animate-elements.mjs';
5
+
6
+ function animateSequence(definition, options) {
7
+ const animations = [];
8
+ createAnimationsFromSequence(definition, options).forEach(({ keyframes, transition }, element) => {
9
+ animations.push(...animateElements(element, keyframes, transition));
10
+ });
11
+ return new GroupPlaybackControls(animations);
12
+ }
13
+
14
+ export { animateSequence };
@@ -1,4 +1,5 @@
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 { animateElements } from './animate-elements.mjs';
3
4
 
4
5
  const createScopedWaapiAnimate = (scope) => {
@@ -1,4 +1,5 @@
1
- import { mapEasingToNativeEasing } from './easing.mjs';
1
+ import '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { mapEasingToNativeEasing } from '../../../../../../motion-dom/dist/es/animation/waapi/utils/easing.mjs';
2
3
 
3
4
  function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
4
5
  const keyframeOptions = { [valueName]: keyframes };
@@ -1,4 +1,5 @@
1
- import { memo } from '../../../../utils/memo.mjs';
1
+ import '../../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { memo } from '../../../../../../../motion-utils/dist/es/memo.mjs';
2
3
 
3
4
  const supportsPartialKeyframes = /*@__PURE__*/ memo(() => {
4
5
  try {
@@ -1,4 +1,5 @@
1
- import { memo } from '../../../../utils/memo.mjs';
1
+ import '../../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { memo } from '../../../../../../../motion-utils/dist/es/memo.mjs';
2
3
 
3
4
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
4
5
 
@@ -0,0 +1,27 @@
1
+ const springDefaults = {
2
+ // Default spring physics
3
+ stiffness: 100,
4
+ damping: 10,
5
+ mass: 1.0,
6
+ velocity: 0.0,
7
+ // Default duration/bounce-based options
8
+ duration: 800, // in ms
9
+ bounce: 0.3,
10
+ visualDuration: 0.3, // in seconds
11
+ // Rest thresholds
12
+ restSpeed: {
13
+ granular: 0.01,
14
+ default: 2,
15
+ },
16
+ restDelta: {
17
+ granular: 0.005,
18
+ default: 0.5,
19
+ },
20
+ // Limits
21
+ minDuration: 0.01, // in seconds
22
+ maxDuration: 10.0, // in seconds
23
+ minDamping: 0.05,
24
+ maxDamping: 1,
25
+ };
26
+
27
+ export { springDefaults };
@@ -1,22 +1,19 @@
1
- import { warning } from '../../../utils/errors.mjs';
1
+ import { warning } from '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { secondsToMilliseconds, millisecondsToSeconds } from '../../../../../../motion-utils/dist/es/time-conversion.mjs';
2
3
  import { clamp } from '../../../utils/clamp.mjs';
3
- import { secondsToMilliseconds, millisecondsToSeconds } from '../../../utils/time-conversion.mjs';
4
+ import { springDefaults } from './defaults.mjs';
4
5
 
5
6
  const safeMin = 0.001;
6
- const minDuration = 0.01;
7
- const maxDuration = 10.0;
8
- const minDamping = 0.05;
9
- const maxDamping = 1;
10
- function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, }) {
7
+ function findSpring({ duration = springDefaults.duration, bounce = springDefaults.bounce, velocity = springDefaults.velocity, mass = springDefaults.mass, }) {
11
8
  let envelope;
12
9
  let derivative;
13
- warning(duration <= secondsToMilliseconds(maxDuration), "Spring duration must be 10 seconds or less");
10
+ warning(duration <= secondsToMilliseconds(springDefaults.maxDuration), "Spring duration must be 10 seconds or less");
14
11
  let dampingRatio = 1 - bounce;
15
12
  /**
16
13
  * Restrict dampingRatio and duration to within acceptable ranges.
17
14
  */
18
- dampingRatio = clamp(minDamping, maxDamping, dampingRatio);
19
- duration = clamp(minDuration, maxDuration, millisecondsToSeconds(duration));
15
+ dampingRatio = clamp(springDefaults.minDamping, springDefaults.maxDamping, dampingRatio);
16
+ duration = clamp(springDefaults.minDuration, springDefaults.maxDuration, millisecondsToSeconds(duration));
20
17
  if (dampingRatio < 1) {
21
18
  /**
22
19
  * Underdamped spring
@@ -60,8 +57,8 @@ function findSpring({ duration = 800, bounce = 0.25, velocity = 0, mass = 1, })
60
57
  duration = secondsToMilliseconds(duration);
61
58
  if (isNaN(undampedFreq)) {
62
59
  return {
63
- stiffness: 100,
64
- damping: 10,
60
+ stiffness: springDefaults.stiffness,
61
+ damping: springDefaults.damping,
65
62
  duration,
66
63
  };
67
64
  }
@@ -86,4 +83,4 @@ function calcAngularFreq(undampedFreq, dampingRatio) {
86
83
  return undampedFreq * Math.sqrt(1 - dampingRatio * dampingRatio);
87
84
  }
88
85
 
89
- export { calcAngularFreq, findSpring, maxDamping, maxDuration, minDamping, minDuration };
86
+ export { calcAngularFreq, findSpring };
@@ -1,5 +1,10 @@
1
- import { millisecondsToSeconds, secondsToMilliseconds } from '../../../utils/time-conversion.mjs';
1
+ import '../../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { millisecondsToSeconds, secondsToMilliseconds } from '../../../../../../motion-utils/dist/es/time-conversion.mjs';
3
+ import { calcGeneratorDuration, maxGeneratorDuration } from '../../../../../../motion-dom/dist/es/animation/generators/utils/calc-duration.mjs';
4
+ import { generateLinearEasing } from '../../../../../../motion-dom/dist/es/animation/waapi/utils/linear.mjs';
5
+ import { clamp } from '../../../utils/clamp.mjs';
2
6
  import { calcGeneratorVelocity } from '../utils/velocity.mjs';
7
+ import { springDefaults } from './defaults.mjs';
3
8
  import { findSpring, calcAngularFreq } from './find.mjs';
4
9
 
5
10
  const durationKeys = ["duration", "bounce"];
@@ -9,29 +14,53 @@ function isSpringType(options, keys) {
9
14
  }
10
15
  function getSpringOptions(options) {
11
16
  let springOptions = {
12
- velocity: 0.0,
13
- stiffness: 100,
14
- damping: 10,
15
- mass: 1.0,
17
+ velocity: springDefaults.velocity,
18
+ stiffness: springDefaults.stiffness,
19
+ damping: springDefaults.damping,
20
+ mass: springDefaults.mass,
16
21
  isResolvedFromDuration: false,
17
22
  ...options,
18
23
  };
19
24
  // stiffness/damping/mass overrides duration/bounce
20
25
  if (!isSpringType(options, physicsKeys) &&
21
26
  isSpringType(options, durationKeys)) {
22
- const derived = findSpring(options);
23
- springOptions = {
24
- ...springOptions,
25
- ...derived,
26
- mass: 1.0,
27
- };
28
- springOptions.isResolvedFromDuration = true;
27
+ if (options.visualDuration) {
28
+ const visualDuration = options.visualDuration;
29
+ const root = (2 * Math.PI) / (visualDuration * 1.2);
30
+ const stiffness = root * root;
31
+ const damping = 2 *
32
+ clamp(0.05, 1, 1 - (options.bounce || 0)) *
33
+ Math.sqrt(stiffness);
34
+ springOptions = {
35
+ ...springOptions,
36
+ mass: springDefaults.mass,
37
+ stiffness,
38
+ damping,
39
+ };
40
+ }
41
+ else {
42
+ const derived = findSpring(options);
43
+ springOptions = {
44
+ ...springOptions,
45
+ ...derived,
46
+ mass: springDefaults.mass,
47
+ };
48
+ springOptions.isResolvedFromDuration = true;
49
+ }
29
50
  }
30
51
  return springOptions;
31
52
  }
32
- function spring({ keyframes, restDelta, restSpeed, ...options }) {
33
- const origin = keyframes[0];
34
- const target = keyframes[keyframes.length - 1];
53
+ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce = springDefaults.bounce) {
54
+ const options = typeof optionsOrVisualDuration !== "object"
55
+ ? {
56
+ visualDuration: optionsOrVisualDuration,
57
+ keyframes: [0, 1],
58
+ bounce,
59
+ }
60
+ : optionsOrVisualDuration;
61
+ let { restSpeed, restDelta } = options;
62
+ const origin = options.keyframes[0];
63
+ const target = options.keyframes[options.keyframes.length - 1];
35
64
  /**
36
65
  * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
37
66
  * to reduce GC during animation.
@@ -53,8 +82,12 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
53
82
  * ratio between feeling good and finishing as soon as changes are imperceptible.
54
83
  */
55
84
  const isGranularScale = Math.abs(initialDelta) < 5;
56
- restSpeed || (restSpeed = isGranularScale ? 0.01 : 2);
57
- restDelta || (restDelta = isGranularScale ? 0.005 : 0.5);
85
+ restSpeed || (restSpeed = isGranularScale
86
+ ? springDefaults.restSpeed.granular
87
+ : springDefaults.restSpeed.default);
88
+ restDelta || (restDelta = isGranularScale
89
+ ? springDefaults.restDelta.granular
90
+ : springDefaults.restDelta.default);
58
91
  let resolveSpring;
59
92
  if (dampingRatio < 1) {
60
93
  const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
@@ -95,7 +128,7 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
95
128
  dampedAngularFreq);
96
129
  };
97
130
  }
98
- return {
131
+ const generator = {
99
132
  calculatedDuration: isResolvedFromDuration ? duration || null : null,
100
133
  next: (t) => {
101
134
  const current = resolveSpring(t);
@@ -123,7 +156,13 @@ function spring({ keyframes, restDelta, restSpeed, ...options }) {
123
156
  state.value = state.done ? target : current;
124
157
  return state;
125
158
  },
159
+ toString: () => {
160
+ const calculatedDuration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
161
+ const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
162
+ return calculatedDuration + "ms " + easing;
163
+ },
126
164
  };
165
+ return generator;
127
166
  }
128
167
 
129
168
  export { spring };
@@ -1,4 +1,4 @@
1
- import { invariant } from '../../utils/errors.mjs';
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
2
2
  import { setTarget } from '../../render/utils/setters.mjs';
3
3
  import { animateVisualElement } from '../interfaces/visual-element.mjs';
4
4
 
@@ -1,13 +1,14 @@
1
- import { secondsToMilliseconds } from '../../utils/time-conversion.mjs';
2
- import { getDefaultTransition } from '../utils/default-transitions.mjs';
3
- import { getValueTransition } from '../utils/get-value-transition.mjs';
1
+ import { GroupPlaybackControls } from '../../../../../motion-dom/dist/es/animation/controls/Group.mjs';
2
+ import { getValueTransition } from '../../../../../motion-dom/dist/es/animation/utils/get-value-transition.mjs';
3
+ import '../../../../../motion-utils/dist/es/errors.mjs';
4
+ import { secondsToMilliseconds } from '../../../../../motion-utils/dist/es/time-conversion.mjs';
5
+ import { frame } from '../../frameloop/frame.mjs';
4
6
  import { MotionGlobalConfig } from '../../utils/GlobalConfig.mjs';
5
7
  import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
6
- import { getFinalKeyframe } from '../animators/waapi/utils/get-final-keyframe.mjs';
7
- import { frame } from '../../frameloop/frame.mjs';
8
8
  import { AcceleratedAnimation } from '../animators/AcceleratedAnimation.mjs';
9
9
  import { MainThreadAnimation } from '../animators/MainThreadAnimation.mjs';
10
- import { GroupPlaybackControls } from '../GroupPlaybackControls.mjs';
10
+ import { getFinalKeyframe } from '../animators/waapi/utils/get-final-keyframe.mjs';
11
+ import { getDefaultTransition } from '../utils/default-transitions.mjs';
11
12
  import { isTransitionDefined } from '../utils/is-transition-defined.mjs';
12
13
 
13
14
  const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
@@ -1,9 +1,10 @@
1
- import { transformProps } from '../../render/html/utils/transform.mjs';
2
- import { animateMotionValue } from './motion-value.mjs';
1
+ import '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { getValueTransition } from '../../../../../motion-dom/dist/es/animation/utils/get-value-transition.mjs';
3
+ import { positionalKeys } from '../../render/html/utils/keys-position.mjs';
3
4
  import { setTarget } from '../../render/utils/setters.mjs';
4
- import { getValueTransition } from '../utils/get-value-transition.mjs';
5
- import { getOptimisedAppearId } from '../optimized-appear/get-appear-id.mjs';
6
5
  import { addValueToWillChange } from '../../value/use-will-change/add-will-change.mjs';
6
+ import { getOptimisedAppearId } from '../optimized-appear/get-appear-id.mjs';
7
+ import { animateMotionValue } from './motion-value.mjs';
7
8
  import { frame } from '../../frameloop/frame.mjs';
8
9
 
9
10
  /**
@@ -54,7 +55,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
54
55
  }
55
56
  }
56
57
  addValueToWillChange(visualElement, key);
57
- value.start(animateMotionValue(key, value, valueTarget, visualElement.shouldReduceMotion && transformProps.has(key)
58
+ value.start(animateMotionValue(key, value, valueTarget, visualElement.shouldReduceMotion && positionalKeys.has(key)
58
59
  ? { type: false }
59
60
  : valueTransition, visualElement, isHandoff));
60
61
  const animation = value.animation;
@@ -3,7 +3,8 @@ import { startWaapiAnimation } from '../animators/waapi/index.mjs';
3
3
  import { optimizedAppearDataId } from './data-id.mjs';
4
4
  import { handoffOptimizedAppearAnimation } from './handoff.mjs';
5
5
  import { appearAnimationStore, appearComplete } from './store.mjs';
6
- import { noop } from '../../utils/noop.mjs';
6
+ import '../../../../../motion-utils/dist/es/errors.mjs';
7
+ import { noop } from '../../../../../motion-utils/dist/es/noop.mjs';
7
8
  import { getOptimisedAppearId } from './get-appear-id.mjs';
8
9
 
9
10
  /**
@@ -1,4 +1,4 @@
1
- import { transformProps } from '../../render/html/utils/transform.mjs';
1
+ import { transformProps } from '../../render/html/utils/keys-transform.mjs';
2
2
 
3
3
  const appearStoreId = (elementId, valueName) => {
4
4
  const key = transformProps.has(valueName) ? "transform" : valueName;
@@ -1,16 +1,21 @@
1
- import { createGeneratorEasing } from '../../easing/utils/create-generator-easing.mjs';
1
+ import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
2
+ import { progress } from '../../../../../motion-utils/dist/es/progress.mjs';
3
+ import { secondsToMilliseconds } from '../../../../../motion-utils/dist/es/time-conversion.mjs';
4
+ import { createGeneratorEasing } from '../../../../../motion-dom/dist/es/animation/generators/utils/create-generator-easing.mjs';
5
+ import { isGenerator } from '../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
6
+ import { getEasingForSegment } from '../../easing/utils/get-easing-for-segment.mjs';
2
7
  import { defaultOffset } from '../../utils/offsets/default.mjs';
3
8
  import { fillOffset } from '../../utils/offsets/fill.mjs';
4
- import { progress } from '../../utils/progress.mjs';
5
- import { secondsToMilliseconds } from '../../utils/time-conversion.mjs';
6
9
  import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
7
10
  import { resolveSubjects } from '../animate/resolve-subjects.mjs';
8
- import { isGenerator } from '../generators/utils/is-generator.mjs';
11
+ import { calculateRepeatDuration } from './utils/calc-repeat-duration.mjs';
9
12
  import { calcNextTime } from './utils/calc-time.mjs';
10
13
  import { addKeyframes } from './utils/edit.mjs';
14
+ import { normalizeTimes } from './utils/normalize-times.mjs';
11
15
  import { compareByTime } from './utils/sort.mjs';
12
16
 
13
17
  const defaultSegmentEasing = "easeInOut";
18
+ const MAX_REPEAT = 20;
14
19
  function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...sequenceTransition } = {}, scope, generators) {
15
20
  const defaultDuration = defaultTransition.duration || 0.3;
16
21
  const animationDefinitions = new Map();
@@ -53,7 +58,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
53
58
  let maxDuration = 0;
54
59
  const resolveValueSequence = (valueKeyframes, valueTransition, valueSequence, elementIndex = 0, numSubjects = 0) => {
55
60
  const valueKeyframesAsList = keyframesAsList(valueKeyframes);
56
- const { delay = 0, times = defaultOffset(valueKeyframesAsList), type = "keyframes", ...remainingTransition } = valueTransition;
61
+ const { delay = 0, times = defaultOffset(valueKeyframesAsList), type = "keyframes", repeat, repeatType, repeatDelay = 0, ...remainingTransition } = valueTransition;
57
62
  let { ease = defaultTransition.ease || "easeOut", duration } = valueTransition;
58
63
  /**
59
64
  * Resolve stagger() if defined.
@@ -91,7 +96,6 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
91
96
  }
92
97
  duration !== null && duration !== void 0 ? duration : (duration = defaultDuration);
93
98
  const startTime = currentTime + calculatedDelay;
94
- const targetTime = startTime + duration;
95
99
  /**
96
100
  * If there's only one time offset of 0, fill in a second with length 1
97
101
  */
@@ -110,6 +114,28 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
110
114
  */
111
115
  valueKeyframesAsList.length === 1 &&
112
116
  valueKeyframesAsList.unshift(null);
117
+ /**
118
+ * Handle repeat options
119
+ */
120
+ if (repeat) {
121
+ invariant(repeat < MAX_REPEAT, "Repeat count too high, must be less than 20");
122
+ duration = calculateRepeatDuration(duration, repeat);
123
+ const originalKeyframes = [...valueKeyframesAsList];
124
+ const originalTimes = [...times];
125
+ ease = Array.isArray(ease) ? [...ease] : [ease];
126
+ const originalEase = [...ease];
127
+ for (let repeatIndex = 0; repeatIndex < repeat; repeatIndex++) {
128
+ valueKeyframesAsList.push(...originalKeyframes);
129
+ for (let keyframeIndex = 0; keyframeIndex < originalKeyframes.length; keyframeIndex++) {
130
+ times.push(originalTimes[keyframeIndex] + (repeatIndex + 1));
131
+ ease.push(keyframeIndex === 0
132
+ ? "linear"
133
+ : getEasingForSegment(originalEase, keyframeIndex - 1));
134
+ }
135
+ }
136
+ normalizeTimes(times, repeat);
137
+ }
138
+ const targetTime = startTime + duration;
113
139
  /**
114
140
  * Add keyframes, mapping offsets to absolute time.
115
141
  */
@@ -0,0 +1,5 @@
1
+ function calculateRepeatDuration(duration, repeat, _repeatDelay) {
2
+ return duration * (repeat + 1);
3
+ }
4
+
5
+ export { calculateRepeatDuration };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Take an array of times that represent repeated keyframes. For instance
3
+ * if we have original times of [0, 0.5, 1] then our repeated times will
4
+ * be [0, 0.5, 1, 1, 1.5, 2]. Loop over the times and scale them back
5
+ * down to a 0-1 scale.
6
+ */
7
+ function normalizeTimes(times, repeat) {
8
+ for (let i = 0; i < times.length; i++) {
9
+ times[i] = times[i] / (repeat + 1);
10
+ }
11
+ }
12
+
13
+ export { normalizeTimes };