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,401 +1,396 @@
1
- import { __assign, __spreadArray, __read } from 'tslib';
1
+ import { __rest } from 'tslib';
2
2
  import sync, { cancelSync } from 'framesync';
3
3
  import { motionValue } from '../value/index.mjs';
4
+ import { isWillChangeMotionValue } from '../value/use-will-change/is.mjs';
4
5
  import { isMotionValue } from '../value/utils/is-motion-value.mjs';
5
6
  import { variantPriorityOrder } from './utils/animation-state.mjs';
6
7
  import { createLifecycles } from './utils/lifecycles.mjs';
7
8
  import { updateMotionValuesFromProps } from './utils/motion-values.mjs';
8
9
  import { checkIfControllingVariants, checkIfVariantNode, isVariantLabel } from './utils/variants.mjs';
9
10
 
10
- var visualElement = function (_a) {
11
- var _b = _a.treeType, treeType = _b === void 0 ? "" : _b, build = _a.build, getBaseTarget = _a.getBaseTarget, makeTargetAnimatable = _a.makeTargetAnimatable, measureViewportBox = _a.measureViewportBox, renderInstance = _a.render, readValueFromInstance = _a.readValueFromInstance, removeValueFromRenderState = _a.removeValueFromRenderState, sortNodePosition = _a.sortNodePosition, scrapeMotionValuesFromProps = _a.scrapeMotionValuesFromProps;
12
- return function (_a, options) {
13
- var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState, shouldReduceMotion = _a.shouldReduceMotion;
14
- if (options === void 0) { options = {}; }
15
- var isMounted = false;
16
- var latestValues = visualState.latestValues, renderState = visualState.renderState;
11
+ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, shouldReduceMotion, }, options = {}) => {
12
+ let isMounted = false;
13
+ const { latestValues, renderState } = visualState;
14
+ /**
15
+ * The instance of the render-specific node that will be hydrated by the
16
+ * exposed React ref. So for example, this visual element can host a
17
+ * HTMLElement, plain object, or Three.js object. The functions provided
18
+ * in VisualElementConfig allow us to interface with this instance.
19
+ */
20
+ let instance;
21
+ /**
22
+ * Manages the subscriptions for a visual element's lifecycle, for instance
23
+ * onRender
24
+ */
25
+ const lifecycles = createLifecycles();
26
+ /**
27
+ * A map of all motion values attached to this visual element. Motion
28
+ * values are source of truth for any given animated value. A motion
29
+ * value might be provided externally by the component via props.
30
+ */
31
+ const values = new Map();
32
+ /**
33
+ * A map of every subscription that binds the provided or generated
34
+ * motion values onChange listeners to this visual element.
35
+ */
36
+ const valueSubscriptions = new Map();
37
+ /**
38
+ * A reference to the previously-provided motion values as returned
39
+ * from scrapeMotionValuesFromProps. We use the keys in here to determine
40
+ * if any motion values need to be removed after props are updated.
41
+ */
42
+ let prevMotionValues = {};
43
+ /**
44
+ * When values are removed from all animation props we need to search
45
+ * for a fallback value to animate to. These values are tracked in baseTarget.
46
+ */
47
+ const baseTarget = Object.assign({}, latestValues);
48
+ // Internal methods ========================
49
+ /**
50
+ * On mount, this will be hydrated with a callback to disconnect
51
+ * this visual element from its parent on unmount.
52
+ */
53
+ let removeFromVariantTree;
54
+ /**
55
+ * Render the element with the latest styles outside of the React
56
+ * render lifecycle
57
+ */
58
+ function render() {
59
+ if (!instance || !isMounted)
60
+ return;
61
+ triggerBuild();
62
+ renderInstance(instance, renderState, props.style, element.projection);
63
+ }
64
+ function triggerBuild() {
65
+ build(element, renderState, latestValues, options, props);
66
+ }
67
+ function update() {
68
+ lifecycles.notifyUpdate(latestValues);
69
+ }
70
+ /**
71
+ *
72
+ */
73
+ function bindToMotionValue(key, value) {
74
+ const removeOnChange = value.onChange((latestValue) => {
75
+ latestValues[key] = latestValue;
76
+ props.onUpdate && sync.update(update, false, true);
77
+ });
78
+ const removeOnRenderRequest = value.onRenderRequest(element.scheduleRender);
79
+ valueSubscriptions.set(key, () => {
80
+ removeOnChange();
81
+ removeOnRenderRequest();
82
+ });
83
+ }
84
+ /**
85
+ * Any motion values that are provided to the element when created
86
+ * aren't yet bound to the element, as this would technically be impure.
87
+ * However, we iterate through the motion values and set them to the
88
+ * initial values for this component.
89
+ *
90
+ * TODO: This is impure and we should look at changing this to run on mount.
91
+ * Doing so will break some tests but this isn't neccessarily a breaking change,
92
+ * more a reflection of the test.
93
+ */
94
+ const _a = scrapeMotionValuesFromProps(props), { willChange } = _a, initialMotionValues = __rest(_a, ["willChange"]);
95
+ for (const key in initialMotionValues) {
96
+ const value = initialMotionValues[key];
97
+ if (latestValues[key] !== undefined && isMotionValue(value)) {
98
+ value.set(latestValues[key], false);
99
+ if (isWillChangeMotionValue(willChange)) {
100
+ willChange.add(key);
101
+ }
102
+ }
103
+ }
104
+ /**
105
+ * Determine what role this visual element should take in the variant tree.
106
+ */
107
+ const isControllingVariants = checkIfControllingVariants(props);
108
+ const isVariantNode = checkIfVariantNode(props);
109
+ const element = Object.assign(Object.assign({ treeType,
17
110
  /**
18
- * The instance of the render-specific node that will be hydrated by the
19
- * exposed React ref. So for example, this visual element can host a
20
- * HTMLElement, plain object, or Three.js object. The functions provided
21
- * in VisualElementConfig allow us to interface with this instance.
111
+ * This is a mirror of the internal instance prop, which keeps
112
+ * VisualElement type-compatible with React's RefObject.
22
113
  */
23
- var instance;
114
+ current: null,
24
115
  /**
25
- * Manages the subscriptions for a visual element's lifecycle, for instance
26
- * onRender
116
+ * The depth of this visual element within the visual element tree.
27
117
  */
28
- var lifecycles = createLifecycles();
118
+ depth: parent ? parent.depth + 1 : 0, parent, children: new Set(),
29
119
  /**
30
- * A map of all motion values attached to this visual element. Motion
31
- * values are source of truth for any given animated value. A motion
32
- * value might be provided externally by the component via props.
120
+ *
33
121
  */
34
- var values = new Map();
122
+ presenceId,
123
+ shouldReduceMotion,
35
124
  /**
36
- * A map of every subscription that binds the provided or generated
37
- * motion values onChange listeners to this visual element.
125
+ * If this component is part of the variant tree, it should track
126
+ * any children that are also part of the tree. This is essentially
127
+ * a shadow tree to simplify logic around how to stagger over children.
38
128
  */
39
- var valueSubscriptions = new Map();
129
+ variantChildren: isVariantNode ? new Set() : undefined,
40
130
  /**
41
- * A reference to the previously-provided motion values as returned
42
- * from scrapeMotionValuesFromProps. We use the keys in here to determine
43
- * if any motion values need to be removed after props are updated.
131
+ * Whether this instance is visible. This can be changed imperatively
132
+ * by the projection tree, is analogous to CSS's visibility in that
133
+ * hidden elements should take up layout, and needs enacting by the configured
134
+ * render function.
44
135
  */
45
- var prevMotionValues = {};
136
+ isVisible: undefined,
46
137
  /**
47
- * When values are removed from all animation props we need to search
48
- * for a fallback value to animate to. These values are tracked in baseTarget.
138
+ * Normally, if a component is controlled by a parent's variants, it can
139
+ * rely on that ancestor to trigger animations further down the tree.
140
+ * However, if a component is created after its parent is mounted, the parent
141
+ * won't trigger that mount animation so the child needs to.
142
+ *
143
+ * TODO: This might be better replaced with a method isParentMounted
49
144
  */
50
- var baseTarget = __assign({}, latestValues);
51
- // Internal methods ========================
145
+ manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
52
146
  /**
53
- * On mount, this will be hydrated with a callback to disconnect
54
- * this visual element from its parent on unmount.
147
+ * This can be set by AnimatePresence to force components that mount
148
+ * at the same time as it to mount as if they have initial={false} set.
55
149
  */
56
- var removeFromVariantTree;
150
+ blockInitialAnimation,
57
151
  /**
58
- * Render the element with the latest styles outside of the React
59
- * render lifecycle
152
+ * Determine whether this component has mounted yet. This is mostly used
153
+ * by variant children to determine whether they need to trigger their
154
+ * own animations on mount.
60
155
  */
61
- function render() {
62
- if (!instance || !isMounted)
63
- return;
64
- triggerBuild();
65
- renderInstance(instance, renderState, props.style, element.projection);
66
- }
67
- function triggerBuild() {
68
- build(element, renderState, latestValues, options, props);
69
- }
70
- function update() {
71
- lifecycles.notifyUpdate(latestValues);
72
- }
156
+ isMounted: () => Boolean(instance), mount(newInstance) {
157
+ isMounted = true;
158
+ instance = element.current = newInstance;
159
+ if (element.projection) {
160
+ element.projection.mount(newInstance);
161
+ }
162
+ if (isVariantNode && parent && !isControllingVariants) {
163
+ removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
164
+ }
165
+ values.forEach((value, key) => bindToMotionValue(key, value));
166
+ parent === null || parent === void 0 ? void 0 : parent.children.add(element);
167
+ element.setProps(props);
168
+ },
73
169
  /**
74
170
  *
75
171
  */
76
- function bindToMotionValue(key, value) {
77
- var removeOnChange = value.onChange(function (latestValue) {
78
- latestValues[key] = latestValue;
79
- props.onUpdate && sync.update(update, false, true);
80
- });
81
- var removeOnRenderRequest = value.onRenderRequest(element.scheduleRender);
82
- valueSubscriptions.set(key, function () {
83
- removeOnChange();
84
- removeOnRenderRequest();
85
- });
86
- }
172
+ unmount() {
173
+ var _a;
174
+ (_a = element.projection) === null || _a === void 0 ? void 0 : _a.unmount();
175
+ cancelSync.update(update);
176
+ cancelSync.render(render);
177
+ valueSubscriptions.forEach((remove) => remove());
178
+ removeFromVariantTree === null || removeFromVariantTree === void 0 ? void 0 : removeFromVariantTree();
179
+ parent === null || parent === void 0 ? void 0 : parent.children.delete(element);
180
+ lifecycles.clearAllListeners();
181
+ instance = undefined;
182
+ isMounted = false;
183
+ },
87
184
  /**
88
- * Any motion values that are provided to the element when created
89
- * aren't yet bound to the element, as this would technically be impure.
90
- * However, we iterate through the motion values and set them to the
91
- * initial values for this component.
92
- *
93
- * TODO: This is impure and we should look at changing this to run on mount.
94
- * Doing so will break some tests but this isn't neccessarily a breaking change,
95
- * more a reflection of the test.
96
- */
97
- var initialMotionValues = scrapeMotionValuesFromProps(props);
98
- for (var key in initialMotionValues) {
99
- var value = initialMotionValues[key];
100
- if (latestValues[key] !== undefined && isMotionValue(value)) {
101
- value.set(latestValues[key], false);
102
- }
103
- }
104
- /**
105
- * Determine what role this visual element should take in the variant tree.
185
+ * Add a child visual element to our set of children.
106
186
  */
107
- var isControllingVariants = checkIfControllingVariants(props);
108
- var isVariantNode = checkIfVariantNode(props);
109
- var element = __assign(__assign({ treeType: treeType,
110
- /**
111
- * This is a mirror of the internal instance prop, which keeps
112
- * VisualElement type-compatible with React's RefObject.
113
- */
114
- current: null,
115
- /**
116
- * The depth of this visual element within the visual element tree.
117
- */
118
- depth: parent ? parent.depth + 1 : 0, parent: parent, children: new Set(),
119
- /**
120
- *
121
- */
122
- presenceId: presenceId, shouldReduceMotion: shouldReduceMotion,
123
- /**
124
- * If this component is part of the variant tree, it should track
125
- * any children that are also part of the tree. This is essentially
126
- * a shadow tree to simplify logic around how to stagger over children.
127
- */
128
- variantChildren: isVariantNode ? new Set() : undefined,
129
- /**
130
- * Whether this instance is visible. This can be changed imperatively
131
- * by the projection tree, is analogous to CSS's visibility in that
132
- * hidden elements should take up layout, and needs enacting by the configured
133
- * render function.
134
- */
135
- isVisible: undefined,
136
- /**
137
- * Normally, if a component is controlled by a parent's variants, it can
138
- * rely on that ancestor to trigger animations further down the tree.
139
- * However, if a component is created after its parent is mounted, the parent
140
- * won't trigger that mount animation so the child needs to.
141
- *
142
- * TODO: This might be better replaced with a method isParentMounted
143
- */
144
- manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
145
- /**
146
- * This can be set by AnimatePresence to force components that mount
147
- * at the same time as it to mount as if they have initial={false} set.
148
- */
149
- blockInitialAnimation: blockInitialAnimation,
150
- /**
151
- * Determine whether this component has mounted yet. This is mostly used
152
- * by variant children to determine whether they need to trigger their
153
- * own animations on mount.
154
- */
155
- isMounted: function () { return Boolean(instance); }, mount: function (newInstance) {
156
- isMounted = true;
157
- instance = element.current = newInstance;
158
- if (element.projection) {
159
- element.projection.mount(newInstance);
160
- }
161
- if (isVariantNode && parent && !isControllingVariants) {
162
- removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
163
- }
164
- values.forEach(function (value, key) { return bindToMotionValue(key, value); });
165
- parent === null || parent === void 0 ? void 0 : parent.children.add(element);
166
- element.setProps(props);
167
- },
168
- /**
169
- *
170
- */
171
- unmount: function () {
172
- var _a;
173
- (_a = element.projection) === null || _a === void 0 ? void 0 : _a.unmount();
174
- cancelSync.update(update);
175
- cancelSync.render(render);
176
- valueSubscriptions.forEach(function (remove) { return remove(); });
177
- removeFromVariantTree === null || removeFromVariantTree === void 0 ? void 0 : removeFromVariantTree();
178
- parent === null || parent === void 0 ? void 0 : parent.children.delete(element);
179
- lifecycles.clearAllListeners();
180
- instance = undefined;
181
- isMounted = false;
182
- },
183
- /**
184
- * Add a child visual element to our set of children.
185
- */
186
- addVariantChild: function (child) {
187
- var _a;
188
- var closestVariantNode = element.getClosestVariantNode();
189
- if (closestVariantNode) {
190
- (_a = closestVariantNode.variantChildren) === null || _a === void 0 ? void 0 : _a.add(child);
191
- return function () {
192
- return closestVariantNode.variantChildren.delete(child);
193
- };
194
- }
195
- }, sortNodePosition: function (other) {
196
- /**
197
- * If these nodes aren't even of the same type we can't compare their depth.
198
- */
199
- if (!sortNodePosition || treeType !== other.treeType)
200
- return 0;
201
- return sortNodePosition(element.getInstance(), other.getInstance());
202
- },
203
- /**
204
- * Returns the closest variant node in the tree starting from
205
- * this visual element.
206
- */
207
- getClosestVariantNode: function () {
208
- return isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode();
209
- },
210
- /**
211
- * Expose the latest layoutId prop.
212
- */
213
- getLayoutId: function () { return props.layoutId; },
214
- /**
215
- * Returns the current instance.
216
- */
217
- getInstance: function () { return instance; },
218
- /**
219
- * Get/set the latest static values.
220
- */
221
- getStaticValue: function (key) { return latestValues[key]; }, setStaticValue: function (key, value) { return (latestValues[key] = value); },
222
- /**
223
- * Returns the latest motion value state. Currently only used to take
224
- * a snapshot of the visual element - perhaps this can return the whole
225
- * visual state
226
- */
227
- getLatestValues: function () { return latestValues; },
187
+ addVariantChild(child) {
188
+ var _a;
189
+ const closestVariantNode = element.getClosestVariantNode();
190
+ if (closestVariantNode) {
191
+ (_a = closestVariantNode.variantChildren) === null || _a === void 0 ? void 0 : _a.add(child);
192
+ return () => closestVariantNode.variantChildren.delete(child);
193
+ }
194
+ },
195
+ sortNodePosition(other) {
228
196
  /**
229
- * Set the visiblity of the visual element. If it's changed, schedule
230
- * a render to reflect these changes.
197
+ * If these nodes aren't even of the same type we can't compare their depth.
231
198
  */
232
- setVisibility: function (visibility) {
233
- if (element.isVisible === visibility)
234
- return;
235
- element.isVisible = visibility;
199
+ if (!sortNodePosition || treeType !== other.treeType)
200
+ return 0;
201
+ return sortNodePosition(element.getInstance(), other.getInstance());
202
+ },
203
+ /**
204
+ * Returns the closest variant node in the tree starting from
205
+ * this visual element.
206
+ */
207
+ getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
208
+ /**
209
+ * Expose the latest layoutId prop.
210
+ */
211
+ getLayoutId: () => props.layoutId,
212
+ /**
213
+ * Returns the current instance.
214
+ */
215
+ getInstance: () => instance,
216
+ /**
217
+ * Get/set the latest static values.
218
+ */
219
+ getStaticValue: (key) => latestValues[key], setStaticValue: (key, value) => (latestValues[key] = value),
220
+ /**
221
+ * Returns the latest motion value state. Currently only used to take
222
+ * a snapshot of the visual element - perhaps this can return the whole
223
+ * visual state
224
+ */
225
+ getLatestValues: () => latestValues,
226
+ /**
227
+ * Set the visiblity of the visual element. If it's changed, schedule
228
+ * a render to reflect these changes.
229
+ */
230
+ setVisibility(visibility) {
231
+ if (element.isVisible === visibility)
232
+ return;
233
+ element.isVisible = visibility;
234
+ element.scheduleRender();
235
+ },
236
+ /**
237
+ * Make a target animatable by Popmotion. For instance, if we're
238
+ * trying to animate width from 100px to 100vw we need to measure 100vw
239
+ * in pixels to determine what we really need to animate to. This is also
240
+ * pluggable to support Framer's custom value types like Color,
241
+ * and CSS variables.
242
+ */
243
+ makeTargetAnimatable(target, canMutate = true) {
244
+ return makeTargetAnimatable(element, target, props, canMutate);
245
+ },
246
+ /**
247
+ * Measure the current viewport box with or without transforms.
248
+ * Only measures axis-aligned boxes, rotate and skew must be manually
249
+ * removed with a re-render to work.
250
+ */
251
+ measureViewportBox() {
252
+ return measureViewportBox(instance, props);
253
+ },
254
+ // Motion values ========================
255
+ /**
256
+ * Add a motion value and bind it to this visual element.
257
+ */
258
+ addValue(key, value) {
259
+ // Remove existing value if it exists
260
+ if (element.hasValue(key))
261
+ element.removeValue(key);
262
+ values.set(key, value);
263
+ latestValues[key] = value.get();
264
+ bindToMotionValue(key, value);
265
+ },
266
+ /**
267
+ * Remove a motion value and unbind any active subscriptions.
268
+ */
269
+ removeValue(key) {
270
+ var _a;
271
+ values.delete(key);
272
+ (_a = valueSubscriptions.get(key)) === null || _a === void 0 ? void 0 : _a();
273
+ valueSubscriptions.delete(key);
274
+ delete latestValues[key];
275
+ removeValueFromRenderState(key, renderState);
276
+ },
277
+ /**
278
+ * Check whether we have a motion value for this key
279
+ */
280
+ hasValue: (key) => values.has(key),
281
+ /**
282
+ * Get a motion value for this key. If called with a default
283
+ * value, we'll create one if none exists.
284
+ */
285
+ getValue(key, defaultValue) {
286
+ let value = values.get(key);
287
+ if (value === undefined && defaultValue !== undefined) {
288
+ value = motionValue(defaultValue);
289
+ element.addValue(key, value);
290
+ }
291
+ return value;
292
+ },
293
+ /**
294
+ * Iterate over our motion values.
295
+ */
296
+ forEachValue: (callback) => values.forEach(callback),
297
+ /**
298
+ * If we're trying to animate to a previously unencountered value,
299
+ * we need to check for it in our state and as a last resort read it
300
+ * directly from the instance (which might have performance implications).
301
+ */
302
+ readValue: (key) => {
303
+ var _a;
304
+ return (_a = latestValues[key]) !== null && _a !== void 0 ? _a : readValueFromInstance(instance, key, options);
305
+ },
306
+ /**
307
+ * Set the base target to later animate back to. This is currently
308
+ * only hydrated on creation and when we first read a value.
309
+ */
310
+ setBaseTarget(key, value) {
311
+ baseTarget[key] = value;
312
+ },
313
+ /**
314
+ * Find the base target for a value thats been removed from all animation
315
+ * props.
316
+ */
317
+ getBaseTarget(key) {
318
+ if (getBaseTarget) {
319
+ const target = getBaseTarget(props, key);
320
+ if (target !== undefined && !isMotionValue(target))
321
+ return target;
322
+ }
323
+ return baseTarget[key];
324
+ } }, lifecycles), {
325
+ /**
326
+ * Build the renderer state based on the latest visual state.
327
+ */
328
+ build() {
329
+ triggerBuild();
330
+ return renderState;
331
+ },
332
+ /**
333
+ * Schedule a render on the next animation frame.
334
+ */
335
+ scheduleRender() {
336
+ sync.render(render, false, true);
337
+ },
338
+ /**
339
+ * Synchronously fire render. It's prefered that we batch renders but
340
+ * in many circumstances, like layout measurement, we need to run this
341
+ * synchronously. However in those instances other measures should be taken
342
+ * to batch reads/writes.
343
+ */
344
+ syncRender: render,
345
+ /**
346
+ * Update the provided props. Ensure any newly-added motion values are
347
+ * added to our map, old ones removed, and listeners updated.
348
+ */
349
+ setProps(newProps) {
350
+ if (newProps.transformTemplate || props.transformTemplate) {
236
351
  element.scheduleRender();
237
- },
238
- /**
239
- * Make a target animatable by Popmotion. For instance, if we're
240
- * trying to animate width from 100px to 100vw we need to measure 100vw
241
- * in pixels to determine what we really need to animate to. This is also
242
- * pluggable to support Framer's custom value types like Color,
243
- * and CSS variables.
244
- */
245
- makeTargetAnimatable: function (target, canMutate) {
246
- if (canMutate === void 0) { canMutate = true; }
247
- return makeTargetAnimatable(element, target, props, canMutate);
248
- },
249
- /**
250
- * Measure the current viewport box with or without transforms.
251
- * Only measures axis-aligned boxes, rotate and skew must be manually
252
- * removed with a re-render to work.
253
- */
254
- measureViewportBox: function () {
255
- return measureViewportBox(instance, props);
256
- },
257
- // Motion values ========================
258
- /**
259
- * Add a motion value and bind it to this visual element.
260
- */
261
- addValue: function (key, value) {
262
- // Remove existing value if it exists
263
- if (element.hasValue(key))
264
- element.removeValue(key);
265
- values.set(key, value);
266
- latestValues[key] = value.get();
267
- bindToMotionValue(key, value);
268
- },
269
- /**
270
- * Remove a motion value and unbind any active subscriptions.
271
- */
272
- removeValue: function (key) {
273
- var _a;
274
- values.delete(key);
275
- (_a = valueSubscriptions.get(key)) === null || _a === void 0 ? void 0 : _a();
276
- valueSubscriptions.delete(key);
277
- delete latestValues[key];
278
- removeValueFromRenderState(key, renderState);
279
- },
280
- /**
281
- * Check whether we have a motion value for this key
282
- */
283
- hasValue: function (key) { return values.has(key); },
284
- /**
285
- * Get a motion value for this key. If called with a default
286
- * value, we'll create one if none exists.
287
- */
288
- getValue: function (key, defaultValue) {
289
- var value = values.get(key);
290
- if (value === undefined && defaultValue !== undefined) {
291
- value = motionValue(defaultValue);
292
- element.addValue(key, value);
293
- }
294
- return value;
295
- },
296
- /**
297
- * Iterate over our motion values.
298
- */
299
- forEachValue: function (callback) { return values.forEach(callback); },
300
- /**
301
- * If we're trying to animate to a previously unencountered value,
302
- * we need to check for it in our state and as a last resort read it
303
- * directly from the instance (which might have performance implications).
304
- */
305
- readValue: function (key) {
306
- var _a;
307
- return (_a = latestValues[key]) !== null && _a !== void 0 ? _a : readValueFromInstance(instance, key, options);
308
- },
309
- /**
310
- * Set the base target to later animate back to. This is currently
311
- * only hydrated on creation and when we first read a value.
312
- */
313
- setBaseTarget: function (key, value) {
314
- baseTarget[key] = value;
315
- },
316
- /**
317
- * Find the base target for a value thats been removed from all animation
318
- * props.
319
- */
320
- getBaseTarget: function (key) {
321
- if (getBaseTarget) {
322
- var target = getBaseTarget(props, key);
323
- if (target !== undefined && !isMotionValue(target))
324
- return target;
325
- }
326
- return baseTarget[key];
327
- } }, lifecycles), {
328
- /**
329
- * Build the renderer state based on the latest visual state.
330
- */
331
- build: function () {
332
- triggerBuild();
333
- return renderState;
334
- },
335
- /**
336
- * Schedule a render on the next animation frame.
337
- */
338
- scheduleRender: function () {
339
- sync.render(render, false, true);
340
- },
341
- /**
342
- * Synchronously fire render. It's prefered that we batch renders but
343
- * in many circumstances, like layout measurement, we need to run this
344
- * synchronously. However in those instances other measures should be taken
345
- * to batch reads/writes.
346
- */
347
- syncRender: render,
348
- /**
349
- * Update the provided props. Ensure any newly-added motion values are
350
- * added to our map, old ones removed, and listeners updated.
351
- */
352
- setProps: function (newProps) {
353
- if (newProps.transformTemplate || props.transformTemplate) {
354
- element.scheduleRender();
355
- }
356
- props = newProps;
357
- lifecycles.updatePropListeners(newProps);
358
- prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
359
- }, getProps: function () { return props; },
360
- // Variants ==============================
361
- /**
362
- * Returns the variant definition with a given name.
363
- */
364
- getVariant: function (name) { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
365
- /**
366
- * Returns the defined default transition on this component.
367
- */
368
- getDefaultTransition: function () { return props.transition; }, getTransformPagePoint: function () {
369
- return props.transformPagePoint;
370
- },
371
- /**
372
- * Used by child variant nodes to get the closest ancestor variant props.
373
- */
374
- getVariantContext: function (startAtParent) {
375
- if (startAtParent === void 0) { startAtParent = false; }
376
- if (startAtParent)
377
- return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
378
- if (!isControllingVariants) {
379
- var context_1 = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
380
- if (props.initial !== undefined) {
381
- context_1.initial = props.initial;
382
- }
383
- return context_1;
384
- }
385
- var context = {};
386
- for (var i = 0; i < numVariantProps; i++) {
387
- var name_1 = variantProps[i];
388
- var prop = props[name_1];
389
- if (isVariantLabel(prop) || prop === false) {
390
- context[name_1] = prop;
391
- }
352
+ }
353
+ props = newProps;
354
+ lifecycles.updatePropListeners(newProps);
355
+ prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
356
+ }, getProps: () => props,
357
+ // Variants ==============================
358
+ /**
359
+ * Returns the variant definition with a given name.
360
+ */
361
+ getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
362
+ /**
363
+ * Returns the defined default transition on this component.
364
+ */
365
+ getDefaultTransition: () => props.transition, getTransformPagePoint: () => {
366
+ return props.transformPagePoint;
367
+ },
368
+ /**
369
+ * Used by child variant nodes to get the closest ancestor variant props.
370
+ */
371
+ getVariantContext(startAtParent = false) {
372
+ if (startAtParent)
373
+ return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
374
+ if (!isControllingVariants) {
375
+ const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
376
+ if (props.initial !== undefined) {
377
+ context.initial = props.initial;
392
378
  }
393
379
  return context;
394
- } });
395
- return element;
396
- };
380
+ }
381
+ const context = {};
382
+ for (let i = 0; i < numVariantProps; i++) {
383
+ const name = variantProps[i];
384
+ const prop = props[name];
385
+ if (isVariantLabel(prop) || prop === false) {
386
+ context[name] = prop;
387
+ }
388
+ }
389
+ return context;
390
+ } });
391
+ return element;
397
392
  };
398
- var variantProps = __spreadArray(["initial"], __read(variantPriorityOrder), false);
399
- var numVariantProps = variantProps.length;
393
+ const variantProps = ["initial", ...variantPriorityOrder];
394
+ const numVariantProps = variantProps.length;
400
395
 
401
396
  export { visualElement };