framer-motion 7.0.3 → 7.1.2

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 (186) hide show
  1. package/dist/cjs/index.js +2090 -2304
  2. package/dist/es/animation/animate.mjs +4 -5
  3. package/dist/es/animation/animation-controls.mjs +22 -24
  4. package/dist/es/animation/use-animated-state.mjs +23 -25
  5. package/dist/es/animation/use-animation.mjs +2 -2
  6. package/dist/es/animation/utils/default-transitions.mjs +13 -14
  7. package/dist/es/animation/utils/easing.mjs +20 -21
  8. package/dist/es/animation/utils/is-animatable.mjs +1 -1
  9. package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
  10. package/dist/es/animation/utils/transitions.mjs +30 -31
  11. package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
  12. package/dist/es/components/AnimatePresence/index.mjs +33 -35
  13. package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
  14. package/dist/es/components/AnimateSharedLayout.mjs +4 -5
  15. package/dist/es/components/LayoutGroup/index.mjs +12 -16
  16. package/dist/es/components/LazyMotion/index.mjs +9 -10
  17. package/dist/es/components/MotionConfig/index.mjs +5 -5
  18. package/dist/es/components/Reorder/Group.mjs +16 -16
  19. package/dist/es/components/Reorder/Item.mjs +14 -18
  20. package/dist/es/components/Reorder/index.mjs +3 -3
  21. package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
  22. package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
  23. package/dist/es/context/LayoutGroupContext.mjs +1 -1
  24. package/dist/es/context/LazyContext.mjs +1 -1
  25. package/dist/es/context/MotionConfigContext.mjs +2 -2
  26. package/dist/es/context/MotionContext/create.mjs +2 -2
  27. package/dist/es/context/MotionContext/index.mjs +1 -1
  28. package/dist/es/context/MotionContext/utils.mjs +1 -1
  29. package/dist/es/context/PresenceContext.mjs +1 -1
  30. package/dist/es/context/ReorderContext.mjs +1 -1
  31. package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
  32. package/dist/es/events/event-info.mjs +11 -17
  33. package/dist/es/events/use-dom-event.mjs +4 -5
  34. package/dist/es/events/use-pointer-event.mjs +2 -2
  35. package/dist/es/events/utils.mjs +3 -9
  36. package/dist/es/gestures/PanSession.mjs +42 -47
  37. package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
  38. package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
  39. package/dist/es/gestures/drag/use-drag.mjs +4 -4
  40. package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
  41. package/dist/es/gestures/drag/utils/lock.mjs +17 -17
  42. package/dist/es/gestures/use-focus-gesture.mjs +3 -4
  43. package/dist/es/gestures/use-hover-gesture.mjs +2 -3
  44. package/dist/es/gestures/use-pan-gesture.mjs +9 -10
  45. package/dist/es/gestures/use-tap-gesture.mjs +5 -6
  46. package/dist/es/gestures/utils/event-type.mjs +1 -1
  47. package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
  48. package/dist/es/index.mjs +1 -0
  49. package/dist/es/motion/features/animations.mjs +9 -11
  50. package/dist/es/motion/features/definitions.mjs +5 -5
  51. package/dist/es/motion/features/drag.mjs +1 -1
  52. package/dist/es/motion/features/gestures.mjs +1 -1
  53. package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
  54. package/dist/es/motion/features/layout/index.mjs +1 -1
  55. package/dist/es/motion/features/use-features.mjs +8 -9
  56. package/dist/es/motion/features/use-projection.mjs +10 -11
  57. package/dist/es/motion/features/viewport/observers.mjs +12 -12
  58. package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
  59. package/dist/es/motion/index.mjs +13 -16
  60. package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
  61. package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
  62. package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
  63. package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
  64. package/dist/es/motion/utils/use-visual-element.mjs +13 -13
  65. package/dist/es/motion/utils/use-visual-state.mjs +26 -31
  66. package/dist/es/motion/utils/valid-prop.mjs +1 -1
  67. package/dist/es/projection/animation/mix-values.mjs +12 -16
  68. package/dist/es/projection/geometry/conversion.mjs +4 -6
  69. package/dist/es/projection/geometry/delta-apply.mjs +14 -20
  70. package/dist/es/projection/geometry/delta-calc.mjs +2 -5
  71. package/dist/es/projection/geometry/delta-remove.mjs +6 -13
  72. package/dist/es/projection/geometry/models.mjs +7 -7
  73. package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
  74. package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
  75. package/dist/es/projection/node/create-projection-node.mjs +283 -307
  76. package/dist/es/projection/node/group.mjs +6 -8
  77. package/dist/es/projection/node/id.mjs +2 -2
  78. package/dist/es/projection/node/state.mjs +1 -1
  79. package/dist/es/projection/shared/stack.mjs +26 -27
  80. package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
  81. package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
  82. package/dist/es/projection/styles/scale-correction.mjs +1 -1
  83. package/dist/es/projection/styles/transform.mjs +12 -12
  84. package/dist/es/projection/use-reset-projection.mjs +2 -2
  85. package/dist/es/projection/utils/has-transform.mjs +1 -2
  86. package/dist/es/projection/utils/measure.mjs +2 -2
  87. package/dist/es/render/dom/create-visual-element.mjs +1 -1
  88. package/dist/es/render/dom/features-animation.mjs +1 -2
  89. package/dist/es/render/dom/features-max.mjs +1 -2
  90. package/dist/es/render/dom/motion-minimal.mjs +1 -1
  91. package/dist/es/render/dom/motion-proxy.mjs +3 -4
  92. package/dist/es/render/dom/motion.mjs +2 -5
  93. package/dist/es/render/dom/use-render.mjs +6 -9
  94. package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
  95. package/dist/es/render/dom/utils/create-config.mjs +5 -5
  96. package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
  97. package/dist/es/render/dom/utils/filter-props.mjs +4 -6
  98. package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
  99. package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
  100. package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
  101. package/dist/es/render/dom/value-types/defaults.mjs +4 -5
  102. package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
  103. package/dist/es/render/dom/value-types/find.mjs +2 -3
  104. package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
  105. package/dist/es/render/dom/value-types/number.mjs +2 -2
  106. package/dist/es/render/dom/value-types/test.mjs +1 -1
  107. package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
  108. package/dist/es/render/dom/value-types/type-int.mjs +1 -2
  109. package/dist/es/render/html/config-motion.mjs +1 -1
  110. package/dist/es/render/html/use-props.mjs +11 -13
  111. package/dist/es/render/html/utils/build-styles.mjs +8 -8
  112. package/dist/es/render/html/utils/build-transform.mjs +11 -16
  113. package/dist/es/render/html/utils/create-render-state.mjs +2 -2
  114. package/dist/es/render/html/utils/render.mjs +2 -3
  115. package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
  116. package/dist/es/render/html/utils/transform.mjs +6 -10
  117. package/dist/es/render/html/visual-element.mjs +22 -23
  118. package/dist/es/render/index.mjs +359 -364
  119. package/dist/es/render/svg/config-motion.mjs +2 -3
  120. package/dist/es/render/svg/lowercase-elements.mjs +1 -1
  121. package/dist/es/render/svg/use-props.mjs +5 -6
  122. package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
  123. package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
  124. package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
  125. package/dist/es/render/svg/utils/path.mjs +7 -10
  126. package/dist/es/render/svg/utils/render.mjs +1 -1
  127. package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
  128. package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
  129. package/dist/es/render/svg/visual-element.mjs +6 -4
  130. package/dist/es/render/utils/animation-state.mjs +71 -87
  131. package/dist/es/render/utils/animation.mjs +48 -60
  132. package/dist/es/render/utils/compare-by-depth.mjs +1 -3
  133. package/dist/es/render/utils/flat-tree.mjs +9 -10
  134. package/dist/es/render/utils/lifecycles.mjs +12 -19
  135. package/dist/es/render/utils/motion-values.mjs +16 -8
  136. package/dist/es/render/utils/setters.mjs +19 -19
  137. package/dist/es/render/utils/variants.mjs +6 -8
  138. package/dist/es/utils/array.mjs +9 -10
  139. package/dist/es/utils/is-browser.mjs +1 -1
  140. package/dist/es/utils/is-numerical-string.mjs +1 -1
  141. package/dist/es/utils/is-zero-value-string.mjs +1 -1
  142. package/dist/es/utils/process.mjs +2 -2
  143. package/dist/es/utils/resolve-value.mjs +2 -2
  144. package/dist/es/utils/shallow-compare.mjs +2 -2
  145. package/dist/es/utils/subscription-manager.mjs +15 -17
  146. package/dist/es/utils/time-conversion.mjs +1 -1
  147. package/dist/es/utils/transform.mjs +10 -15
  148. package/dist/es/utils/use-animation-frame.mjs +5 -6
  149. package/dist/es/utils/use-constant.mjs +1 -1
  150. package/dist/es/utils/use-cycle.mjs +9 -10
  151. package/dist/es/utils/use-force-update.mjs +4 -5
  152. package/dist/es/utils/use-in-view.mjs +7 -9
  153. package/dist/es/utils/use-instant-transition-state.mjs +1 -1
  154. package/dist/es/utils/use-instant-transition.mjs +6 -9
  155. package/dist/es/utils/use-is-mounted.mjs +3 -3
  156. package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
  157. package/dist/es/utils/use-reduced-motion.mjs +8 -11
  158. package/dist/es/utils/use-unmount-effect.mjs +1 -1
  159. package/dist/es/utils/warn-once.mjs +1 -1
  160. package/dist/es/value/index.mjs +53 -59
  161. package/dist/es/value/use-combine-values.mjs +3 -3
  162. package/dist/es/value/use-inverted-scale.mjs +9 -11
  163. package/dist/es/value/use-motion-template.mjs +5 -9
  164. package/dist/es/value/use-motion-value.mjs +4 -5
  165. package/dist/es/value/use-on-change.mjs +4 -4
  166. package/dist/es/value/use-scroll.mjs +9 -11
  167. package/dist/es/value/use-spring.mjs +8 -10
  168. package/dist/es/value/use-time.mjs +2 -2
  169. package/dist/es/value/use-transform.mjs +6 -10
  170. package/dist/es/value/use-velocity.mjs +3 -3
  171. package/dist/es/value/use-will-change/index.mjs +50 -0
  172. package/dist/es/value/use-will-change/is.mjs +7 -0
  173. package/dist/es/value/utils/is-motion-value.mjs +1 -1
  174. package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
  175. package/dist/framer-motion.dev.js +2134 -2414
  176. package/dist/framer-motion.js +1 -1
  177. package/dist/index.d.ts +9 -2
  178. package/dist/projection.dev.js +1154 -1300
  179. package/dist/size-rollup-dom-animation.js +1 -1
  180. package/dist/size-rollup-dom-max.js +1 -1
  181. package/dist/size-rollup-m.js +1 -1
  182. package/dist/size-webpack-dom-animation.js +1 -1
  183. package/dist/size-webpack-dom-max.js +1 -1
  184. package/dist/size-webpack-m.js +1 -1
  185. package/dist/three-entry.d.ts +0 -1
  186. package/package.json +12 -12
@@ -1,4 +1,3 @@
1
- import { __assign } from 'tslib';
2
1
  import { invariant } from 'hey-listen';
3
2
  import { PanSession } from '../PanSession.mjs';
4
3
  import { getGlobalLock } from './utils/lock.mjs';
@@ -17,13 +16,13 @@ import { mix } from 'popmotion';
17
16
  import { percent } from 'style-value-types';
18
17
  import { calcLength } from '../../projection/geometry/delta-calc.mjs';
19
18
 
20
- var elementDragControls = new WeakMap();
19
+ const elementDragControls = new WeakMap();
21
20
  /**
22
21
  *
23
22
  */
24
23
  // let latestPointerEvent: AnyPointerEvent
25
- var VisualElementDragControls = /** @class */ (function () {
26
- function VisualElementDragControls(visualElement) {
24
+ class VisualElementDragControls {
25
+ constructor(visualElement) {
27
26
  // This is a reference to the global drag gesture lock, ensuring only one component
28
27
  // can "capture" the drag of one or both axes.
29
28
  // TODO: Look into moving this into pansession?
@@ -42,116 +41,112 @@ var VisualElementDragControls = /** @class */ (function () {
42
41
  this.elastic = createBox();
43
42
  this.visualElement = visualElement;
44
43
  }
45
- VisualElementDragControls.prototype.start = function (originEvent, _a) {
46
- var _this = this;
47
- var _b = _a === void 0 ? {} : _a, _c = _b.snapToCursor, snapToCursor = _c === void 0 ? false : _c;
44
+ start(originEvent, { snapToCursor = false } = {}) {
48
45
  /**
49
46
  * Don't start dragging if this component is exiting
50
47
  */
51
48
  if (this.visualElement.isPresent === false)
52
49
  return;
53
- var onSessionStart = function (event) {
50
+ const onSessionStart = (event) => {
54
51
  // Stop any animations on both axis values immediately. This allows the user to throw and catch
55
52
  // the component.
56
- _this.stopAnimation();
53
+ this.stopAnimation();
57
54
  if (snapToCursor) {
58
- _this.snapToCursor(extractEventInfo(event, "page").point);
55
+ this.snapToCursor(extractEventInfo(event, "page").point);
59
56
  }
60
57
  };
61
- var onStart = function (event, info) {
58
+ const onStart = (event, info) => {
62
59
  var _a;
63
60
  // Attempt to grab the global drag gesture lock - maybe make this part of PanSession
64
- var _b = _this.getProps(), drag = _b.drag, dragPropagation = _b.dragPropagation, onDragStart = _b.onDragStart;
61
+ const { drag, dragPropagation, onDragStart } = this.getProps();
65
62
  if (drag && !dragPropagation) {
66
- if (_this.openGlobalLock)
67
- _this.openGlobalLock();
68
- _this.openGlobalLock = getGlobalLock(drag);
63
+ if (this.openGlobalLock)
64
+ this.openGlobalLock();
65
+ this.openGlobalLock = getGlobalLock(drag);
69
66
  // If we don 't have the lock, don't start dragging
70
- if (!_this.openGlobalLock)
67
+ if (!this.openGlobalLock)
71
68
  return;
72
69
  }
73
- _this.isDragging = true;
74
- _this.currentDirection = null;
75
- _this.resolveConstraints();
76
- if (_this.visualElement.projection) {
77
- _this.visualElement.projection.isAnimationBlocked = true;
78
- _this.visualElement.projection.target = undefined;
70
+ this.isDragging = true;
71
+ this.currentDirection = null;
72
+ this.resolveConstraints();
73
+ if (this.visualElement.projection) {
74
+ this.visualElement.projection.isAnimationBlocked = true;
75
+ this.visualElement.projection.target = undefined;
79
76
  }
80
77
  /**
81
78
  * Record gesture origin
82
79
  */
83
- eachAxis(function (axis) {
80
+ eachAxis((axis) => {
84
81
  var _a, _b;
85
- var current = _this.getAxisMotionValue(axis).get() || 0;
82
+ let current = this.getAxisMotionValue(axis).get() || 0;
86
83
  /**
87
84
  * If the MotionValue is a percentage value convert to px
88
85
  */
89
86
  if (percent.test(current)) {
90
- var measuredAxis = (_b = (_a = _this.visualElement.projection) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.actual[axis];
87
+ const measuredAxis = (_b = (_a = this.visualElement.projection) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.actual[axis];
91
88
  if (measuredAxis) {
92
- var length_1 = calcLength(measuredAxis);
93
- current = length_1 * (parseFloat(current) / 100);
89
+ const length = calcLength(measuredAxis);
90
+ current = length * (parseFloat(current) / 100);
94
91
  }
95
92
  }
96
- _this.originPoint[axis] = current;
93
+ this.originPoint[axis] = current;
97
94
  });
98
95
  // Fire onDragStart event
99
96
  onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart(event, info);
100
- (_a = _this.visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Drag, true);
97
+ (_a = this.visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Drag, true);
101
98
  };
102
- var onMove = function (event, info) {
99
+ const onMove = (event, info) => {
103
100
  // latestPointerEvent = event
104
- var _a = _this.getProps(), dragPropagation = _a.dragPropagation, dragDirectionLock = _a.dragDirectionLock, onDirectionLock = _a.onDirectionLock, onDrag = _a.onDrag;
101
+ const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
105
102
  // If we didn't successfully receive the gesture lock, early return.
106
- if (!dragPropagation && !_this.openGlobalLock)
103
+ if (!dragPropagation && !this.openGlobalLock)
107
104
  return;
108
- var offset = info.offset;
105
+ const { offset } = info;
109
106
  // Attempt to detect drag direction if directionLock is true
110
- if (dragDirectionLock && _this.currentDirection === null) {
111
- _this.currentDirection = getCurrentDirection(offset);
107
+ if (dragDirectionLock && this.currentDirection === null) {
108
+ this.currentDirection = getCurrentDirection(offset);
112
109
  // If we've successfully set a direction, notify listener
113
- if (_this.currentDirection !== null) {
114
- onDirectionLock === null || onDirectionLock === void 0 ? void 0 : onDirectionLock(_this.currentDirection);
110
+ if (this.currentDirection !== null) {
111
+ onDirectionLock === null || onDirectionLock === void 0 ? void 0 : onDirectionLock(this.currentDirection);
115
112
  }
116
113
  return;
117
114
  }
118
115
  // Update each point with the latest position
119
- _this.updateAxis("x", info.point, offset);
120
- _this.updateAxis("y", info.point, offset);
116
+ this.updateAxis("x", info.point, offset);
117
+ this.updateAxis("y", info.point, offset);
121
118
  /**
122
119
  * Ideally we would leave the renderer to fire naturally at the end of
123
120
  * this frame but if the element is about to change layout as the result
124
121
  * of a re-render we want to ensure the browser can read the latest
125
122
  * bounding box to ensure the pointer and element don't fall out of sync.
126
123
  */
127
- _this.visualElement.syncRender();
124
+ this.visualElement.syncRender();
128
125
  /**
129
126
  * This must fire after the syncRender call as it might trigger a state
130
127
  * change which itself might trigger a layout update.
131
128
  */
132
129
  onDrag === null || onDrag === void 0 ? void 0 : onDrag(event, info);
133
130
  };
134
- var onSessionEnd = function (event, info) {
135
- return _this.stop(event, info);
136
- };
131
+ const onSessionEnd = (event, info) => this.stop(event, info);
137
132
  this.panSession = new PanSession(originEvent, {
138
- onSessionStart: onSessionStart,
139
- onStart: onStart,
140
- onMove: onMove,
141
- onSessionEnd: onSessionEnd,
133
+ onSessionStart,
134
+ onStart,
135
+ onMove,
136
+ onSessionEnd,
142
137
  }, { transformPagePoint: this.visualElement.getTransformPagePoint() });
143
- };
144
- VisualElementDragControls.prototype.stop = function (event, info) {
145
- var isDragging = this.isDragging;
138
+ }
139
+ stop(event, info) {
140
+ const isDragging = this.isDragging;
146
141
  this.cancel();
147
142
  if (!isDragging)
148
143
  return;
149
- var velocity = info.velocity;
144
+ const { velocity } = info;
150
145
  this.startAnimation(velocity);
151
- var onDragEnd = this.getProps().onDragEnd;
146
+ const { onDragEnd } = this.getProps();
152
147
  onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(event, info);
153
- };
154
- VisualElementDragControls.prototype.cancel = function () {
148
+ }
149
+ cancel() {
155
150
  var _a, _b;
156
151
  this.isDragging = false;
157
152
  if (this.visualElement.projection) {
@@ -159,31 +154,30 @@ var VisualElementDragControls = /** @class */ (function () {
159
154
  }
160
155
  (_a = this.panSession) === null || _a === void 0 ? void 0 : _a.end();
161
156
  this.panSession = undefined;
162
- var dragPropagation = this.getProps().dragPropagation;
157
+ const { dragPropagation } = this.getProps();
163
158
  if (!dragPropagation && this.openGlobalLock) {
164
159
  this.openGlobalLock();
165
160
  this.openGlobalLock = null;
166
161
  }
167
162
  (_b = this.visualElement.animationState) === null || _b === void 0 ? void 0 : _b.setActive(AnimationType.Drag, false);
168
- };
169
- VisualElementDragControls.prototype.updateAxis = function (axis, _point, offset) {
170
- var drag = this.getProps().drag;
163
+ }
164
+ updateAxis(axis, _point, offset) {
165
+ const { drag } = this.getProps();
171
166
  // If we're not dragging this axis, do an early return.
172
167
  if (!offset || !shouldDrag(axis, drag, this.currentDirection))
173
168
  return;
174
- var axisValue = this.getAxisMotionValue(axis);
175
- var next = this.originPoint[axis] + offset[axis];
169
+ const axisValue = this.getAxisMotionValue(axis);
170
+ let next = this.originPoint[axis] + offset[axis];
176
171
  // Apply constraints
177
172
  if (this.constraints && this.constraints[axis]) {
178
173
  next = applyConstraints(next, this.constraints[axis], this.elastic[axis]);
179
174
  }
180
175
  axisValue.set(next);
181
- };
182
- VisualElementDragControls.prototype.resolveConstraints = function () {
183
- var _this = this;
184
- var _a = this.getProps(), dragConstraints = _a.dragConstraints, dragElastic = _a.dragElastic;
185
- var layout = (this.visualElement.projection || {}).layout;
186
- var prevConstraints = this.constraints;
176
+ }
177
+ resolveConstraints() {
178
+ const { dragConstraints, dragElastic } = this.getProps();
179
+ const { layout } = this.visualElement.projection || {};
180
+ const prevConstraints = this.constraints;
187
181
  if (dragConstraints && isRefObject(dragConstraints)) {
188
182
  if (!this.constraints) {
189
183
  this.constraints = this.resolveRefConstraints();
@@ -206,48 +200,47 @@ var VisualElementDragControls = /** @class */ (function () {
206
200
  layout &&
207
201
  this.constraints &&
208
202
  !this.hasMutatedConstraints) {
209
- eachAxis(function (axis) {
210
- if (_this.getAxisMotionValue(axis)) {
211
- _this.constraints[axis] = rebaseAxisConstraints(layout.actual[axis], _this.constraints[axis]);
203
+ eachAxis((axis) => {
204
+ if (this.getAxisMotionValue(axis)) {
205
+ this.constraints[axis] = rebaseAxisConstraints(layout.actual[axis], this.constraints[axis]);
212
206
  }
213
207
  });
214
208
  }
215
- };
216
- VisualElementDragControls.prototype.resolveRefConstraints = function () {
217
- var _a = this.getProps(), constraints = _a.dragConstraints, onMeasureDragConstraints = _a.onMeasureDragConstraints;
209
+ }
210
+ resolveRefConstraints() {
211
+ const { dragConstraints: constraints, onMeasureDragConstraints } = this.getProps();
218
212
  if (!constraints || !isRefObject(constraints))
219
213
  return false;
220
- var constraintsElement = constraints.current;
214
+ const constraintsElement = constraints.current;
221
215
  invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
222
- var projection = this.visualElement.projection;
216
+ const { projection } = this.visualElement;
223
217
  // TODO
224
218
  if (!projection || !projection.layout)
225
219
  return false;
226
- var constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint());
227
- var measuredConstraints = calcViewportConstraints(projection.layout.actual, constraintsBox);
220
+ const constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint());
221
+ let measuredConstraints = calcViewportConstraints(projection.layout.actual, constraintsBox);
228
222
  /**
229
223
  * If there's an onMeasureDragConstraints listener we call it and
230
224
  * if different constraints are returned, set constraints to that
231
225
  */
232
226
  if (onMeasureDragConstraints) {
233
- var userConstraints = onMeasureDragConstraints(convertBoxToBoundingBox(measuredConstraints));
227
+ const userConstraints = onMeasureDragConstraints(convertBoxToBoundingBox(measuredConstraints));
234
228
  this.hasMutatedConstraints = !!userConstraints;
235
229
  if (userConstraints) {
236
230
  measuredConstraints = convertBoundingBoxToBox(userConstraints);
237
231
  }
238
232
  }
239
233
  return measuredConstraints;
240
- };
241
- VisualElementDragControls.prototype.startAnimation = function (velocity) {
242
- var _this = this;
243
- var _a = this.getProps(), drag = _a.drag, dragMomentum = _a.dragMomentum, dragElastic = _a.dragElastic, dragTransition = _a.dragTransition, dragSnapToOrigin = _a.dragSnapToOrigin, onDragTransitionEnd = _a.onDragTransitionEnd;
244
- var constraints = this.constraints || {};
245
- var momentumAnimations = eachAxis(function (axis) {
234
+ }
235
+ startAnimation(velocity) {
236
+ const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
237
+ const constraints = this.constraints || {};
238
+ const momentumAnimations = eachAxis((axis) => {
246
239
  var _a;
247
- if (!shouldDrag(axis, drag, _this.currentDirection)) {
240
+ if (!shouldDrag(axis, drag, this.currentDirection)) {
248
241
  return;
249
242
  }
250
- var transition = (_a = constraints === null || constraints === void 0 ? void 0 : constraints[axis]) !== null && _a !== void 0 ? _a : {};
243
+ let transition = (_a = constraints === null || constraints === void 0 ? void 0 : constraints[axis]) !== null && _a !== void 0 ? _a : {};
251
244
  if (dragSnapToOrigin)
252
245
  transition = { min: 0, max: 0 };
253
246
  /**
@@ -256,64 +249,62 @@ var VisualElementDragControls = /** @class */ (function () {
256
249
  * We could do something here where we affect the `bounceStiffness` and `bounceDamping`
257
250
  * using the value of `dragElastic`.
258
251
  */
259
- var bounceStiffness = dragElastic ? 200 : 1000000;
260
- var bounceDamping = dragElastic ? 40 : 10000000;
261
- var inertia = __assign(__assign({ type: "inertia", velocity: dragMomentum ? velocity[axis] : 0, bounceStiffness: bounceStiffness, bounceDamping: bounceDamping, timeConstant: 750, restDelta: 1, restSpeed: 10 }, dragTransition), transition);
252
+ const bounceStiffness = dragElastic ? 200 : 1000000;
253
+ const bounceDamping = dragElastic ? 40 : 10000000;
254
+ const inertia = Object.assign(Object.assign({ type: "inertia", velocity: dragMomentum ? velocity[axis] : 0, bounceStiffness,
255
+ bounceDamping, timeConstant: 750, restDelta: 1, restSpeed: 10 }, dragTransition), transition);
262
256
  // If we're not animating on an externally-provided `MotionValue` we can use the
263
257
  // component's animation controls which will handle interactions with whileHover (etc),
264
258
  // otherwise we just have to animate the `MotionValue` itself.
265
- return _this.startAxisValueAnimation(axis, inertia);
259
+ return this.startAxisValueAnimation(axis, inertia);
266
260
  });
267
261
  // Run all animations and then resolve the new drag constraints.
268
262
  return Promise.all(momentumAnimations).then(onDragTransitionEnd);
269
- };
270
- VisualElementDragControls.prototype.startAxisValueAnimation = function (axis, transition) {
271
- var axisValue = this.getAxisMotionValue(axis);
263
+ }
264
+ startAxisValueAnimation(axis, transition) {
265
+ const axisValue = this.getAxisMotionValue(axis);
272
266
  return startAnimation(axis, axisValue, 0, transition);
273
- };
274
- VisualElementDragControls.prototype.stopAnimation = function () {
275
- var _this = this;
276
- eachAxis(function (axis) { return _this.getAxisMotionValue(axis).stop(); });
277
- };
267
+ }
268
+ stopAnimation() {
269
+ eachAxis((axis) => this.getAxisMotionValue(axis).stop());
270
+ }
278
271
  /**
279
272
  * Drag works differently depending on which props are provided.
280
273
  *
281
274
  * - If _dragX and _dragY are provided, we output the gesture delta directly to those motion values.
282
275
  * - Otherwise, we apply the delta to the x/y motion values.
283
276
  */
284
- VisualElementDragControls.prototype.getAxisMotionValue = function (axis) {
277
+ getAxisMotionValue(axis) {
285
278
  var _a, _b;
286
- var dragKey = "_drag" + axis.toUpperCase();
287
- var externalMotionValue = this.visualElement.getProps()[dragKey];
279
+ const dragKey = "_drag" + axis.toUpperCase();
280
+ const externalMotionValue = this.visualElement.getProps()[dragKey];
288
281
  return externalMotionValue
289
282
  ? externalMotionValue
290
283
  : this.visualElement.getValue(axis, (_b = (_a = this.visualElement.getProps().initial) === null || _a === void 0 ? void 0 : _a[axis]) !== null && _b !== void 0 ? _b : 0);
291
- };
292
- VisualElementDragControls.prototype.snapToCursor = function (point) {
293
- var _this = this;
294
- eachAxis(function (axis) {
295
- var drag = _this.getProps().drag;
284
+ }
285
+ snapToCursor(point) {
286
+ eachAxis((axis) => {
287
+ const { drag } = this.getProps();
296
288
  // If we're not dragging this axis, do an early return.
297
- if (!shouldDrag(axis, drag, _this.currentDirection))
289
+ if (!shouldDrag(axis, drag, this.currentDirection))
298
290
  return;
299
- var projection = _this.visualElement.projection;
300
- var axisValue = _this.getAxisMotionValue(axis);
291
+ const { projection } = this.visualElement;
292
+ const axisValue = this.getAxisMotionValue(axis);
301
293
  if (projection && projection.layout) {
302
- var _a = projection.layout.actual[axis], min = _a.min, max = _a.max;
294
+ const { min, max } = projection.layout.actual[axis];
303
295
  axisValue.set(point[axis] - mix(min, max, 0.5));
304
296
  }
305
297
  });
306
- };
298
+ }
307
299
  /**
308
300
  * When the viewport resizes we want to check if the measured constraints
309
301
  * have changed and, if so, reposition the element within those new constraints
310
302
  * relative to where it was before the resize.
311
303
  */
312
- VisualElementDragControls.prototype.scalePositionWithinConstraints = function () {
313
- var _this = this;
304
+ scalePositionWithinConstraints() {
314
305
  var _a;
315
- var _b = this.getProps(), drag = _b.drag, dragConstraints = _b.dragConstraints;
316
- var projection = this.visualElement.projection;
306
+ const { drag, dragConstraints } = this.getProps();
307
+ const { projection } = this.visualElement;
317
308
  if (!isRefObject(dragConstraints) || !projection || !this.constraints)
318
309
  return;
319
310
  /**
@@ -325,18 +316,18 @@ var VisualElementDragControls = /** @class */ (function () {
325
316
  * Record the relative position of the dragged element relative to the
326
317
  * constraints box and save as a progress value.
327
318
  */
328
- var boxProgress = { x: 0, y: 0 };
329
- eachAxis(function (axis) {
330
- var axisValue = _this.getAxisMotionValue(axis);
319
+ const boxProgress = { x: 0, y: 0 };
320
+ eachAxis((axis) => {
321
+ const axisValue = this.getAxisMotionValue(axis);
331
322
  if (axisValue) {
332
- var latest = axisValue.get();
333
- boxProgress[axis] = calcOrigin({ min: latest, max: latest }, _this.constraints[axis]);
323
+ const latest = axisValue.get();
324
+ boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
334
325
  }
335
326
  });
336
327
  /**
337
328
  * Update the layout of this element and resolve the latest drag constraints
338
329
  */
339
- var transformTemplate = this.visualElement.getProps().transformTemplate;
330
+ const { transformTemplate } = this.visualElement.getProps();
340
331
  this.visualElement.getInstance().style.transform = transformTemplate
341
332
  ? transformTemplate({}, "")
342
333
  : "none";
@@ -347,37 +338,36 @@ var VisualElementDragControls = /** @class */ (function () {
347
338
  * For each axis, calculate the current progress of the layout axis
348
339
  * within the new constraints.
349
340
  */
350
- eachAxis(function (axis) {
341
+ eachAxis((axis) => {
351
342
  if (!shouldDrag(axis, drag, null))
352
343
  return;
353
344
  /**
354
345
  * Calculate a new transform based on the previous box progress
355
346
  */
356
- var axisValue = _this.getAxisMotionValue(axis);
357
- var _a = _this.constraints[axis], min = _a.min, max = _a.max;
347
+ const axisValue = this.getAxisMotionValue(axis);
348
+ const { min, max } = this.constraints[axis];
358
349
  axisValue.set(mix(min, max, boxProgress[axis]));
359
350
  });
360
- };
361
- VisualElementDragControls.prototype.addListeners = function () {
362
- var _this = this;
351
+ }
352
+ addListeners() {
363
353
  var _a;
364
354
  elementDragControls.set(this.visualElement, this);
365
- var element = this.visualElement.getInstance();
355
+ const element = this.visualElement.getInstance();
366
356
  /**
367
357
  * Attach a pointerdown event listener on this DOM element to initiate drag tracking.
368
358
  */
369
- var stopPointerListener = addPointerEvent(element, "pointerdown", function (event) {
370
- var _a = _this.getProps(), drag = _a.drag, _b = _a.dragListener, dragListener = _b === void 0 ? true : _b;
371
- drag && dragListener && _this.start(event);
359
+ const stopPointerListener = addPointerEvent(element, "pointerdown", (event) => {
360
+ const { drag, dragListener = true } = this.getProps();
361
+ drag && dragListener && this.start(event);
372
362
  });
373
- var measureDragConstraints = function () {
374
- var dragConstraints = _this.getProps().dragConstraints;
363
+ const measureDragConstraints = () => {
364
+ const { dragConstraints } = this.getProps();
375
365
  if (isRefObject(dragConstraints)) {
376
- _this.constraints = _this.resolveRefConstraints();
366
+ this.constraints = this.resolveRefConstraints();
377
367
  }
378
368
  };
379
- var projection = this.visualElement.projection;
380
- var stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints);
369
+ const { projection } = this.visualElement;
370
+ const stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints);
381
371
  if (projection && !projection.layout) {
382
372
  (_a = projection.root) === null || _a === void 0 ? void 0 : _a.updateScroll();
383
373
  projection.updateLayout();
@@ -387,40 +377,41 @@ var VisualElementDragControls = /** @class */ (function () {
387
377
  * Attach a window resize listener to scale the draggable target within its defined
388
378
  * constraints as the window resizes.
389
379
  */
390
- var stopResizeListener = addDomEvent(window, "resize", function () {
391
- return _this.scalePositionWithinConstraints();
392
- });
380
+ const stopResizeListener = addDomEvent(window, "resize", () => this.scalePositionWithinConstraints());
393
381
  /**
394
382
  * If the element's layout changes, calculate the delta and apply that to
395
383
  * the drag gesture's origin point.
396
384
  */
397
- var stopLayoutUpdateListener = projection.addEventListener("didUpdate", (function (_a) {
398
- var delta = _a.delta, hasLayoutChanged = _a.hasLayoutChanged;
399
- if (_this.isDragging && hasLayoutChanged) {
400
- eachAxis(function (axis) {
401
- var motionValue = _this.getAxisMotionValue(axis);
385
+ const stopLayoutUpdateListener = projection.addEventListener("didUpdate", (({ delta, hasLayoutChanged }) => {
386
+ if (this.isDragging && hasLayoutChanged) {
387
+ eachAxis((axis) => {
388
+ const motionValue = this.getAxisMotionValue(axis);
402
389
  if (!motionValue)
403
390
  return;
404
- _this.originPoint[axis] += delta[axis].translate;
391
+ this.originPoint[axis] += delta[axis].translate;
405
392
  motionValue.set(motionValue.get() + delta[axis].translate);
406
393
  });
407
- _this.visualElement.syncRender();
394
+ this.visualElement.syncRender();
408
395
  }
409
396
  }));
410
- return function () {
397
+ return () => {
411
398
  stopResizeListener();
412
399
  stopPointerListener();
413
400
  stopMeasureLayoutListener();
414
401
  stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
415
402
  };
416
- };
417
- VisualElementDragControls.prototype.getProps = function () {
418
- var props = this.visualElement.getProps();
419
- var _a = props.drag, drag = _a === void 0 ? false : _a, _b = props.dragDirectionLock, dragDirectionLock = _b === void 0 ? false : _b, _c = props.dragPropagation, dragPropagation = _c === void 0 ? false : _c, _d = props.dragConstraints, dragConstraints = _d === void 0 ? false : _d, _e = props.dragElastic, dragElastic = _e === void 0 ? defaultElastic : _e, _f = props.dragMomentum, dragMomentum = _f === void 0 ? true : _f;
420
- return __assign(__assign({}, props), { drag: drag, dragDirectionLock: dragDirectionLock, dragPropagation: dragPropagation, dragConstraints: dragConstraints, dragElastic: dragElastic, dragMomentum: dragMomentum });
421
- };
422
- return VisualElementDragControls;
423
- }());
403
+ }
404
+ getProps() {
405
+ const props = this.visualElement.getProps();
406
+ const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
407
+ return Object.assign(Object.assign({}, props), { drag,
408
+ dragDirectionLock,
409
+ dragPropagation,
410
+ dragConstraints,
411
+ dragElastic,
412
+ dragMomentum });
413
+ }
414
+ }
424
415
  function shouldDrag(direction, drag, currentDirection) {
425
416
  return ((drag === true || drag === direction) &&
426
417
  (currentDirection === null || currentDirection === direction));
@@ -432,9 +423,8 @@ function shouldDrag(direction, drag, currentDirection) {
432
423
  * @param offset - The x/y offset from origin.
433
424
  * @param lockThreshold - (Optional) - the minimum absolute offset before we can determine a drag direction.
434
425
  */
435
- function getCurrentDirection(offset, lockThreshold) {
436
- if (lockThreshold === void 0) { lockThreshold = 10; }
437
- var direction = null;
426
+ function getCurrentDirection(offset, lockThreshold = 10) {
427
+ let direction = null;
438
428
  if (Math.abs(offset.y) > lockThreshold) {
439
429
  direction = "y";
440
430
  }
@@ -20,8 +20,8 @@ import { useConstant } from '../../utils/use-constant.mjs';
20
20
  *
21
21
  * @public
22
22
  */
23
- var DragControls = /** @class */ (function () {
24
- function DragControls() {
23
+ class DragControls {
24
+ constructor() {
25
25
  this.componentControls = new Set();
26
26
  }
27
27
  /**
@@ -29,11 +29,10 @@ var DragControls = /** @class */ (function () {
29
29
  *
30
30
  * @internal
31
31
  */
32
- DragControls.prototype.subscribe = function (controls) {
33
- var _this = this;
32
+ subscribe(controls) {
34
33
  this.componentControls.add(controls);
35
- return function () { return _this.componentControls.delete(controls); };
36
- };
34
+ return () => this.componentControls.delete(controls);
35
+ }
37
36
  /**
38
37
  * Start a drag gesture on every `motion` component that has this set of drag controls
39
38
  * passed into it via the `dragControls` prop.
@@ -49,14 +48,13 @@ var DragControls = /** @class */ (function () {
49
48
  *
50
49
  * @public
51
50
  */
52
- DragControls.prototype.start = function (event, options) {
53
- this.componentControls.forEach(function (controls) {
51
+ start(event, options) {
52
+ this.componentControls.forEach((controls) => {
54
53
  controls.start(event.nativeEvent || event, options);
55
54
  });
56
- };
57
- return DragControls;
58
- }());
59
- var createDragControls = function () { return new DragControls(); };
55
+ }
56
+ }
57
+ const createDragControls = () => new DragControls();
60
58
  /**
61
59
  * Usually, dragging is initiated by pressing down on a `motion` component with a `drag` prop
62
60
  * and moving it. For some use-cases, for instance clicking at an arbitrary point on a video scrubber, we
@@ -8,13 +8,13 @@ import { useConstant } from '../../utils/use-constant.mjs';
8
8
  * @internal
9
9
  */
10
10
  function useDrag(props) {
11
- var groupDragControls = props.dragControls, visualElement = props.visualElement;
12
- var dragControls = useConstant(function () { return new VisualElementDragControls(visualElement); });
11
+ const { dragControls: groupDragControls, visualElement } = props;
12
+ const dragControls = useConstant(() => new VisualElementDragControls(visualElement));
13
13
  // If we've been provided a DragControls for manual control over the drag gesture,
14
14
  // subscribe this component to it on mount.
15
- useEffect(function () { return groupDragControls && groupDragControls.subscribe(dragControls); }, [dragControls, groupDragControls]);
15
+ useEffect(() => groupDragControls && groupDragControls.subscribe(dragControls), [dragControls, groupDragControls]);
16
16
  // Apply the event listeners to the element
17
- useEffect(function () { return dragControls.addListeners(); }, [dragControls]);
17
+ useEffect(() => dragControls.addListeners(), [dragControls]);
18
18
  }
19
19
 
20
20
  export { useDrag };