motion-start 0.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 (233) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +39 -0
  3. package/package.json +64 -0
  4. package/src/animation/UseAnimatedState.svelte +86 -0
  5. package/src/animation/UseAnimation.svelte +61 -0
  6. package/src/animation/animate.ts +78 -0
  7. package/src/animation/animation-controls.ts +101 -0
  8. package/src/animation/types.ts +83 -0
  9. package/src/animation/use-animated-state.ts +1 -0
  10. package/src/animation/use-animation.ts +74 -0
  11. package/src/animation/utils/default-transitions.ts +70 -0
  12. package/src/animation/utils/easing.ts +55 -0
  13. package/src/animation/utils/is-animatable.ts +42 -0
  14. package/src/animation/utils/is-animation-controls.ts +17 -0
  15. package/src/animation/utils/is-keyframes-target.ts +17 -0
  16. package/src/animation/utils/transitions.ts +218 -0
  17. package/src/animation/utils/variant-resolvers.ts +15 -0
  18. package/src/components/AnimatePresence/AnimatePresence.svelte +180 -0
  19. package/src/components/AnimatePresence/PresenceChild/PresenceChild.svelte +78 -0
  20. package/src/components/AnimatePresence/PresenceChild/index.ts +7 -0
  21. package/src/components/AnimatePresence/PresenceChild/types.ts +10 -0
  22. package/src/components/AnimatePresence/index.ts +46 -0
  23. package/src/components/AnimatePresence/types.ts +79 -0
  24. package/src/components/AnimatePresence/use-presence.ts +90 -0
  25. package/src/components/AnimateSharedLayout/AnimateSharedLayout.svelte +239 -0
  26. package/src/components/AnimateSharedLayout/index.ts +11 -0
  27. package/src/components/AnimateSharedLayout/types.ts +111 -0
  28. package/src/components/AnimateSharedLayout/utils/batcher.ts +96 -0
  29. package/src/components/AnimateSharedLayout/utils/crossfader.ts +260 -0
  30. package/src/components/AnimateSharedLayout/utils/rotate.ts +48 -0
  31. package/src/components/AnimateSharedLayout/utils/stack.ts +160 -0
  32. package/src/components/LazyMotion/LazyMotion.svelte +82 -0
  33. package/src/components/LazyMotion/index.ts +42 -0
  34. package/src/components/LazyMotion/types.ts +58 -0
  35. package/src/components/MotionConfig/MotionConfig.svelte +56 -0
  36. package/src/components/MotionConfig/MotionConfigScaleCorrection.ts +47 -0
  37. package/src/components/MotionConfig/index.ts +20 -0
  38. package/src/components/MotionDiv.svelte +8 -0
  39. package/src/context/DOMcontext.ts +21 -0
  40. package/src/context/LayoutGroupContext.ts +13 -0
  41. package/src/context/LazyContext.ts +18 -0
  42. package/src/context/MotionConfigContext.ts +48 -0
  43. package/src/context/MotionContext/MotionContext.svelte +27 -0
  44. package/src/context/MotionContext/MotionContextProvider.svelte +22 -0
  45. package/src/context/MotionContext/UseCreateMotionContext.svelte +34 -0
  46. package/src/context/MotionContext/create.ts +1 -0
  47. package/src/context/MotionContext/index.ts +14 -0
  48. package/src/context/MotionContext/utils.ts +29 -0
  49. package/src/context/PresenceContext.ts +26 -0
  50. package/src/context/ScaleCorrectionProvider.svelte +27 -0
  51. package/src/context/SharedLayoutContext.ts +29 -0
  52. package/src/events/UseDomEvent.svelte +67 -0
  53. package/src/events/UsePointerEvent.svelte +76 -0
  54. package/src/events/event-info.ts +69 -0
  55. package/src/events/types.ts +15 -0
  56. package/src/events/use-dom-event.ts +48 -0
  57. package/src/events/use-pointer-event.ts +29 -0
  58. package/src/events/utils.ts +25 -0
  59. package/src/gestures/PanSession.ts +298 -0
  60. package/src/gestures/UseFocusGesture.svelte +31 -0
  61. package/src/gestures/UseGestures.svelte +17 -0
  62. package/src/gestures/UseHoverGesture.svelte +40 -0
  63. package/src/gestures/UsePanGesture.svelte +58 -0
  64. package/src/gestures/UseTapGesture.svelte +77 -0
  65. package/src/gestures/drag/UseDrag.svelte +55 -0
  66. package/src/gestures/drag/UseDragControls.svelte +145 -0
  67. package/src/gestures/drag/VisualElementDragControls.ts +632 -0
  68. package/src/gestures/drag/types.ts +307 -0
  69. package/src/gestures/drag/use-drag-controls.ts +148 -0
  70. package/src/gestures/drag/use-drag.ts +15 -0
  71. package/src/gestures/drag/utils/constraints.ts +157 -0
  72. package/src/gestures/drag/utils/lock.ts +69 -0
  73. package/src/gestures/types.ts +257 -0
  74. package/src/gestures/use-focus-gesture.ts +16 -0
  75. package/src/gestures/use-gestures.ts +2 -0
  76. package/src/gestures/use-hover-gesture.ts +10 -0
  77. package/src/gestures/use-pan-gesture.ts +22 -0
  78. package/src/gestures/use-tap-gesture.ts +14 -0
  79. package/src/gestures/utils/event-type.ts +24 -0
  80. package/src/gestures/utils/is-node-or-child.ts +31 -0
  81. package/src/index.ts +104 -0
  82. package/src/motion/Motion.svelte +246 -0
  83. package/src/motion/MotionSSR.svelte +244 -0
  84. package/src/motion/features/AnimationState.svelte +29 -0
  85. package/src/motion/features/Exit.svelte +32 -0
  86. package/src/motion/features/UseFeatures.svelte +39 -0
  87. package/src/motion/features/animations.ts +22 -0
  88. package/src/motion/features/definitions.ts +49 -0
  89. package/src/motion/features/drag.ts +24 -0
  90. package/src/motion/features/gestures.ts +24 -0
  91. package/src/motion/features/layout/Animate.svelte +314 -0
  92. package/src/motion/features/layout/Animate.ts +9 -0
  93. package/src/motion/features/layout/AnimateLayoutContextProvider.svelte +14 -0
  94. package/src/motion/features/layout/Measure.svelte +98 -0
  95. package/src/motion/features/layout/Measure.ts +9 -0
  96. package/src/motion/features/layout/MeasureContextProvider.svelte +32 -0
  97. package/src/motion/features/layout/index.ts +20 -0
  98. package/src/motion/features/layout/types.ts +71 -0
  99. package/src/motion/features/layout/utils.ts +40 -0
  100. package/src/motion/features/types.ts +53 -0
  101. package/src/motion/features/use-features.ts +16 -0
  102. package/src/motion/index.ts +64 -0
  103. package/src/motion/types.ts +278 -0
  104. package/src/motion/utils/UseLayoutId.svelte +18 -0
  105. package/src/motion/utils/UseVisualElement.svelte +104 -0
  106. package/src/motion/utils/UseVisualState.svelte +137 -0
  107. package/src/motion/utils/is-forced-motion-value.ts +23 -0
  108. package/src/motion/utils/make-renderless-component.ts +17 -0
  109. package/src/motion/utils/should-inhert-variant.ts +6 -0
  110. package/src/motion/utils/use-motion-ref.ts +41 -0
  111. package/src/motion/utils/use-visual-element.ts +13 -0
  112. package/src/motion/utils/use-visual-state.ts +24 -0
  113. package/src/motion/utils/valid-prop.ts +80 -0
  114. package/src/render/dom/M.svelte +16 -0
  115. package/src/render/dom/UseRender.svelte +37 -0
  116. package/src/render/dom/create-motion-class.ts +12 -0
  117. package/src/render/dom/create-visual-element.ts +22 -0
  118. package/src/render/dom/featureBundle.ts +22 -0
  119. package/src/render/dom/motion-minimal.ts +22 -0
  120. package/src/render/dom/motion-proxy.ts +107 -0
  121. package/src/render/dom/motion.ts +62 -0
  122. package/src/render/dom/projection/convert-to-relative.ts +40 -0
  123. package/src/render/dom/projection/default-scale-correctors.ts +138 -0
  124. package/src/render/dom/projection/measure.ts +28 -0
  125. package/src/render/dom/projection/relative-set.ts +27 -0
  126. package/src/render/dom/projection/scale-correction.ts +22 -0
  127. package/src/render/dom/projection/types.ts +13 -0
  128. package/src/render/dom/projection/utils.ts +69 -0
  129. package/src/render/dom/svg-visual-element.ts +114 -0
  130. package/src/render/dom/types.ts +32 -0
  131. package/src/render/dom/use-render.ts +11 -0
  132. package/src/render/dom/utils/UseInitialMotionProps.svelte +26 -0
  133. package/src/render/dom/utils/batch-layout.ts +77 -0
  134. package/src/render/dom/utils/camel-to-dash.ts +20 -0
  135. package/src/render/dom/utils/create-config.ts +33 -0
  136. package/src/render/dom/utils/css-variables-conversion.ts +121 -0
  137. package/src/render/dom/utils/filter-props.ts +55 -0
  138. package/src/render/dom/utils/is-css-variable.ts +18 -0
  139. package/src/render/dom/utils/is-svg-component.ts +41 -0
  140. package/src/render/dom/utils/parse-dom-variant.ts +26 -0
  141. package/src/render/dom/utils/unit-conversion.ts +258 -0
  142. package/src/render/dom/utils/use-html-props.ts +2 -0
  143. package/src/render/dom/utils/use-svg-props.ts +1 -0
  144. package/src/render/dom/value-types/animatable-none.ts +24 -0
  145. package/src/render/dom/value-types/defaults.ts +30 -0
  146. package/src/render/dom/value-types/dimensions.ts +27 -0
  147. package/src/render/dom/value-types/find.ts +31 -0
  148. package/src/render/dom/value-types/get-as-type.ts +21 -0
  149. package/src/render/dom/value-types/number.ts +83 -0
  150. package/src/render/dom/value-types/test.ts +17 -0
  151. package/src/render/dom/value-types/type-auto.ts +21 -0
  152. package/src/render/dom/value-types/type-int.ts +23 -0
  153. package/src/render/dom/value-types/types.ts +8 -0
  154. package/src/render/html/UseHTMLProps.svelte +33 -0
  155. package/src/render/html/UseInitialMotionValues.svelte +27 -0
  156. package/src/render/html/UseStyle.svelte +47 -0
  157. package/src/render/html/config-motion.ts +23 -0
  158. package/src/render/html/supported-elements.ts +10 -0
  159. package/src/render/html/types.ts +64 -0
  160. package/src/render/html/use-props.ts +14 -0
  161. package/src/render/html/utils/build-projection-transform.ts +53 -0
  162. package/src/render/html/utils/build-styles.ts +121 -0
  163. package/src/render/html/utils/build-transform.ts +79 -0
  164. package/src/render/html/utils/create-render-state.ts +18 -0
  165. package/src/render/html/utils/render.ts +22 -0
  166. package/src/render/html/utils/scrape-motion-values.ts +26 -0
  167. package/src/render/html/utils/transform.ts +51 -0
  168. package/src/render/html/visual-element.ts +129 -0
  169. package/src/render/index.ts +703 -0
  170. package/src/render/svg/UseSVGProps.svelte +34 -0
  171. package/src/render/svg/config-motion.ts +51 -0
  172. package/src/render/svg/lowercase-elements.ts +35 -0
  173. package/src/render/svg/supported-elements.ts +10 -0
  174. package/src/render/svg/types.ts +51 -0
  175. package/src/render/svg/use-props.ts +14 -0
  176. package/src/render/svg/utils/build-attrs.ts +58 -0
  177. package/src/render/svg/utils/camel-case-attrs.ts +27 -0
  178. package/src/render/svg/utils/create-render-state.ts +17 -0
  179. package/src/render/svg/utils/path.ts +49 -0
  180. package/src/render/svg/utils/render.ts +22 -0
  181. package/src/render/svg/utils/scrape-motion-values.ts +26 -0
  182. package/src/render/svg/utils/transform-origin.ts +30 -0
  183. package/src/render/svg/visual-element.ts +44 -0
  184. package/src/render/types.ts +148 -0
  185. package/src/render/utils/animation-state.ts +375 -0
  186. package/src/render/utils/animation.ts +167 -0
  187. package/src/render/utils/compare-by-depth.ts +18 -0
  188. package/src/render/utils/flat-tree.ts +35 -0
  189. package/src/render/utils/is-draggable.ts +17 -0
  190. package/src/render/utils/lifecycles.ts +172 -0
  191. package/src/render/utils/motion-values.ts +59 -0
  192. package/src/render/utils/projection.ts +38 -0
  193. package/src/render/utils/setters.ts +910 -0
  194. package/src/render/utils/state.ts +113 -0
  195. package/src/render/utils/types.ts +12 -0
  196. package/src/render/utils/variants.ts +76 -0
  197. package/src/types/geometry.ts +91 -0
  198. package/src/types.ts +1088 -0
  199. package/src/utils/UseUnmountEffect.svelte +11 -0
  200. package/src/utils/array.ts +18 -0
  201. package/src/utils/each-axis.ts +15 -0
  202. package/src/utils/errors.ts +22 -0
  203. package/src/utils/fix-process-env.ts +22 -0
  204. package/src/utils/geometry/delta-apply.ts +162 -0
  205. package/src/utils/geometry/delta-calc.ts +89 -0
  206. package/src/utils/geometry/index.ts +83 -0
  207. package/src/utils/is-browser.ts +12 -0
  208. package/src/utils/is-numerical-string.ts +15 -0
  209. package/src/utils/is-ref-object.ts +16 -0
  210. package/src/utils/noop.ts +15 -0
  211. package/src/utils/resolve-value.ts +23 -0
  212. package/src/utils/shallow-compare.ts +23 -0
  213. package/src/utils/subscription-manager.ts +49 -0
  214. package/src/utils/time-conversion.ts +18 -0
  215. package/src/utils/transform.ts +120 -0
  216. package/src/utils/use-constant.ts +23 -0
  217. package/src/utils/use-cycle.ts +78 -0
  218. package/src/utils/use-force-update.ts +7 -0
  219. package/src/utils/use-isomorphic-effect.ts +8 -0
  220. package/src/utils/use-reduced-motion.ts +70 -0
  221. package/src/utils/use-unmount-effect.ts +8 -0
  222. package/src/value/index.ts +409 -0
  223. package/src/value/scroll/use-element-scroll.ts +73 -0
  224. package/src/value/scroll/use-viewport-scroll.ts +81 -0
  225. package/src/value/scroll/utils.ts +76 -0
  226. package/src/value/use-combine-values.ts +53 -0
  227. package/src/value/use-motion-template.ts +57 -0
  228. package/src/value/use-motion-value.ts +27 -0
  229. package/src/value/use-spring.ts +84 -0
  230. package/src/value/use-transform.ts +216 -0
  231. package/src/value/use-velocity.ts +44 -0
  232. package/src/value/utils/is-motion-value.ts +15 -0
  233. package/src/value/utils/resolve-motion-value.ts +29 -0
@@ -0,0 +1,375 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VariantLabels } from "../../motion/types";
6
+ import type { TargetAndTransition } from "../../types";
7
+ import type { VisualElement } from "../types";
8
+ import type { AnimationOptions } from "./animation";
9
+ import { AnimationType } from "./types";
10
+ export interface AnimationState {
11
+ animateChanges: (options?: AnimationOptions, type?: AnimationType) => Promise<any>;
12
+ setActive: (type: AnimationType, isActive: boolean, options?: AnimationOptions) => Promise<any>;
13
+ setAnimateFunction: (fn: any) => void;
14
+ isAnimated(key: string): boolean;
15
+ getState: () => {
16
+ [key: string]: AnimationTypeState;
17
+ };
18
+ }
19
+ export type AnimationList = string[] | TargetAndTransition[];
20
+ // export declare const variantPriorityOrder: AnimationType[];
21
+ // export declare function createAnimationState(visualElement: VisualElement): AnimationState;
22
+ // export declare function variantsHaveChanged(prev: any, next: any): boolean;
23
+ export interface AnimationTypeState {
24
+ isActive: boolean;
25
+ protectedKeys: {
26
+ [key: string]: true;
27
+ };
28
+ needsAnimating: {
29
+ [key: string]: boolean;
30
+ };
31
+ prevResolvedValues: {
32
+ [key: string]: any;
33
+ };
34
+ prevProp?: VariantLabels | TargetAndTransition;
35
+ }
36
+
37
+
38
+ /**
39
+ based on framer-motion@4.0.3,
40
+ Copyright (c) 2018 Framer B.V.
41
+ */
42
+ import { __assign, __read, __rest, __spreadArray } from 'tslib';
43
+ import { isAnimationControls } from '../../animation/utils/is-animation-controls.js';
44
+ import { isKeyframesTarget } from '../../animation/utils/is-keyframes-target.js';
45
+ import { shallowCompare } from '../../utils/shallow-compare.js';
46
+ import { animateVisualElement } from './animation.js';
47
+ import { isVariantLabel, isVariantLabels, resolveVariant } from './variants.js';
48
+
49
+ var variantPriorityOrder = [
50
+ AnimationType.Animate,
51
+ AnimationType.Hover,
52
+ AnimationType.Tap,
53
+ AnimationType.Drag,
54
+ AnimationType.Focus,
55
+ AnimationType.Exit,
56
+ ];
57
+ var reversePriorityOrder = __spreadArray([], __read(variantPriorityOrder)).reverse();
58
+ var numAnimationTypes = variantPriorityOrder.length;
59
+ function animateList(visualElement: VisualElement) {
60
+ return function (animations) {
61
+ return Promise.all(animations.map(function (_a) {
62
+ var animation = _a.animation, options = _a.options;
63
+ return animateVisualElement(visualElement, animation, options);
64
+ }));
65
+ };
66
+ }
67
+ function createAnimationState(visualElement: VisualElement) {
68
+ var animate = animateList(visualElement);
69
+ var state = createState();
70
+ var allAnimatedKeys = {};
71
+ var isInitialRender = true;
72
+ /**
73
+ * This function will be used to reduce the animation definitions for
74
+ * each active animation type into an object of resolved values for it.
75
+ */
76
+ var buildResolvedTypeValues = function (acc, definition) {
77
+ var resolved = resolveVariant(visualElement, definition);
78
+ if (resolved) {
79
+ resolved.transition; var transitionEnd = resolved.transitionEnd, target = __rest(resolved, ["transition", "transitionEnd"]);
80
+ acc = __assign(__assign(__assign({}, acc), target), transitionEnd);
81
+ }
82
+ return acc;
83
+ };
84
+ function isAnimated(key) {
85
+ return allAnimatedKeys[key] !== undefined;
86
+ }
87
+ /**
88
+ * This just allows us to inject mocked animation functions
89
+ * @internal
90
+ */
91
+ function setAnimateFunction(makeAnimator) {
92
+ animate = makeAnimator(visualElement);
93
+ }
94
+ /**
95
+ * When we receive new props, we need to:
96
+ * 1. Create a list of protected keys for each type. This is a directory of
97
+ * value keys that are currently being "handled" by types of a higher priority
98
+ * so that whenever an animation is played of a given type, these values are
99
+ * protected from being animated.
100
+ * 2. Determine if an animation type needs animating.
101
+ * 3. Determine if any values have been removed from a type and figure out
102
+ * what to animate those to.
103
+ */
104
+ function animateChanges(options, changedActiveType) {
105
+ var _a;
106
+ var props = visualElement.getProps();
107
+ var context = visualElement.getVariantContext(true) || {};
108
+ /**
109
+ * A list of animations that we'll build into as we iterate through the animation
110
+ * types. This will get executed at the end of the function.
111
+ */
112
+ var animations = [];
113
+ /**
114
+ * Keep track of which values have been removed. Then, as we hit lower priority
115
+ * animation types, we can check if they contain removed values and animate to that.
116
+ */
117
+ var removedKeys = new Set();
118
+ /**
119
+ * A dictionary of all encountered keys. This is an object to let us build into and
120
+ * copy it without iteration. Each time we hit an animation type we set its protected
121
+ * keys - the keys its not allowed to animate - to the latest version of this object.
122
+ */
123
+ var encounteredKeys = {};
124
+ /**
125
+ * If a variant has been removed at a given index, and this component is controlling
126
+ * variant animations, we want to ensure lower-priority variants are forced to animate.
127
+ */
128
+ var removedVariantIndex = Infinity;
129
+ var _loop_1 = function (i) {
130
+ var type = reversePriorityOrder[i];
131
+ var typeState = state[type];
132
+ var prop = (_a = props[type]) !== null && _a !== void 0 ? _a : context[type];
133
+ var propIsVariant = isVariantLabel(prop);
134
+ /**
135
+ * If this type has *just* changed isActive status, set activeDelta
136
+ * to that status. Otherwise set to null.
137
+ */
138
+ var activeDelta = type === changedActiveType ? typeState.isActive : null;
139
+ if (activeDelta === false)
140
+ removedVariantIndex = i;
141
+ /**
142
+ * If this prop is an inherited variant, rather than been set directly on the
143
+ * component itself, we want to make sure we allow the parent to trigger animations.
144
+ *
145
+ * TODO: Can probably change this to a !isControllingVariants check
146
+ */
147
+ var isInherited = prop === context[type] && prop !== props[type] && propIsVariant;
148
+ /**
149
+ *
150
+ */
151
+ if (isInherited &&
152
+ isInitialRender &&
153
+ visualElement.manuallyAnimateOnMount) {
154
+ isInherited = false;
155
+ }
156
+ /**
157
+ * Set all encountered keys so far as the protected keys for this type. This will
158
+ * be any key that has been animated or otherwise handled by active, higher-priortiy types.
159
+ */
160
+ typeState.protectedKeys = __assign({}, encounteredKeys);
161
+ // Check if we can skip analysing this prop early
162
+ if (
163
+ // If it isn't active and hasn't *just* been set as inactive
164
+ (!typeState.isActive && activeDelta === null) ||
165
+ // If we didn't and don't have any defined prop for this animation type
166
+ (!prop && !typeState.prevProp) ||
167
+ // Or if the prop doesn't define an animation
168
+ isAnimationControls(prop) ||
169
+ typeof prop === "boolean") {
170
+ return "continue";
171
+ }
172
+ /**
173
+ * As we go look through the values defined on this type, if we detect
174
+ * a changed value or a value that was removed in a higher priority, we set
175
+ * this to true and add this prop to the animation list.
176
+ */
177
+ var shouldAnimateType = variantsHaveChanged(typeState.prevProp, prop) ||
178
+ // If we're making this variant active, we want to always make it active
179
+ (type === changedActiveType &&
180
+ typeState.isActive &&
181
+ !isInherited &&
182
+ propIsVariant) ||
183
+ // If we removed a higher-priority variant (i is in reverse order)
184
+ (i > removedVariantIndex && propIsVariant);
185
+ /**
186
+ * As animations can be set as variant lists, variants or target objects, we
187
+ * coerce everything to an array if it isn't one already
188
+ */
189
+ var definitionList = Array.isArray(prop) ? prop : [prop];
190
+ /**
191
+ * Build an object of all the resolved values. We'll use this in the subsequent
192
+ * animateChanges calls to determine whether a value has changed.
193
+ */
194
+ var resolvedValues = definitionList.reduce(buildResolvedTypeValues, {});
195
+ if (activeDelta === false)
196
+ resolvedValues = {};
197
+ /**
198
+ * Now we need to loop through all the keys in the prev prop and this prop,
199
+ * and decide:
200
+ * 1. If the value has changed, and needs animating
201
+ * 2. If it has been removed, and needs adding to the removedKeys set
202
+ * 3. If it has been removed in a higher priority type and needs animating
203
+ * 4. If it hasn't been removed in a higher priority but hasn't changed, and
204
+ * needs adding to the type's protectedKeys list.
205
+ */
206
+ var _b = typeState.prevResolvedValues, prevResolvedValues = _b === void 0 ? {} : _b;
207
+ var allKeys = __assign(__assign({}, prevResolvedValues), resolvedValues);
208
+ var markToAnimate = function (key) {
209
+ shouldAnimateType = true;
210
+ removedKeys.delete(key);
211
+ typeState.needsAnimating[key] = true;
212
+ };
213
+ for (var key in allKeys) {
214
+ var next = resolvedValues[key];
215
+ var prev = prevResolvedValues[key];
216
+ // If we've already handled this we can just skip ahead
217
+ if (encounteredKeys.hasOwnProperty(key))
218
+ continue;
219
+ /**
220
+ * If the value has changed, we probably want to animate it.
221
+ */
222
+ if (next !== prev) {
223
+ /**
224
+ * If both values are keyframes, we need to shallow compare them to
225
+ * detect whether any value has changed. If it has, we animate it.
226
+ */
227
+ if (isKeyframesTarget(next) && isKeyframesTarget(prev)) {
228
+ if (!shallowCompare(next, prev)) {
229
+ markToAnimate(key);
230
+ }
231
+ else {
232
+ /**
233
+ * If it hasn't changed, we want to ensure it doesn't animate by
234
+ * adding it to the list of protected keys.
235
+ */
236
+ typeState.protectedKeys[key] = true;
237
+ }
238
+ }
239
+ else if (next !== undefined) {
240
+ // If next is defined and doesn't equal prev, it needs animating
241
+ markToAnimate(key);
242
+ }
243
+ else {
244
+ // If it's undefined, it's been removed.
245
+ removedKeys.add(key);
246
+ }
247
+ }
248
+ else if (next !== undefined && removedKeys.has(key)) {
249
+ /**
250
+ * If next hasn't changed and it isn't undefined, we want to check if it's
251
+ * been removed by a higher priority
252
+ */
253
+ markToAnimate(key);
254
+ }
255
+ else {
256
+ /**
257
+ * If it hasn't changed, we add it to the list of protected values
258
+ * to ensure it doesn't get animated.
259
+ */
260
+ typeState.protectedKeys[key] = true;
261
+ }
262
+ }
263
+ /**
264
+ * Update the typeState so next time animateChanges is called we can compare the
265
+ * latest prop and resolvedValues to these.
266
+ */
267
+ typeState.prevProp = prop;
268
+ typeState.prevResolvedValues = resolvedValues;
269
+ /**
270
+ *
271
+ */
272
+ if (typeState.isActive) {
273
+ encounteredKeys = __assign(__assign({}, encounteredKeys), resolvedValues);
274
+ }
275
+ if (isInitialRender && visualElement.blockInitialAnimation) {
276
+ shouldAnimateType = false;
277
+ }
278
+ /**
279
+ * If this is an inherited prop we want to hard-block animations
280
+ * TODO: Test as this should probably still handle animations triggered
281
+ * by removed values?
282
+ */
283
+ if (shouldAnimateType && !isInherited) {
284
+ animations.push.apply(animations, __spreadArray([], __read(definitionList.map(function (animation) { return ({
285
+ animation: animation,
286
+ options: __assign({ type: type }, options),
287
+ }); }))));
288
+ }
289
+ };
290
+ /**
291
+ * Iterate through all animation types in reverse priority order. For each, we want to
292
+ * detect which values it's handling and whether or not they've changed (and therefore
293
+ * need to be animated). If any values have been removed, we want to detect those in
294
+ * lower priority props and flag for animation.
295
+ */
296
+ for (var i = 0; i < numAnimationTypes; i++) {
297
+ _loop_1(i);
298
+ }
299
+ allAnimatedKeys = __assign({}, encounteredKeys);
300
+ /**
301
+ * If there are some removed value that haven't been dealt with,
302
+ * we need to create a new animation that falls back either to the value
303
+ * defined in the style prop, or the last read value.
304
+ */
305
+ if (removedKeys.size) {
306
+ var fallbackAnimation_1 = {};
307
+ removedKeys.forEach(function (key) {
308
+ var fallbackTarget = visualElement.getBaseTarget(key);
309
+ if (fallbackTarget !== undefined) {
310
+ fallbackAnimation_1[key] = fallbackTarget;
311
+ }
312
+ });
313
+ animations.push({ animation: fallbackAnimation_1 });
314
+ }
315
+ var shouldAnimate = Boolean(animations.length);
316
+ if (isInitialRender &&
317
+ props.initial === false &&
318
+ !visualElement.manuallyAnimateOnMount) {
319
+ shouldAnimate = false;
320
+ }
321
+ isInitialRender = false;
322
+ return shouldAnimate ? animate(animations) : Promise.resolve();
323
+ }
324
+ /**
325
+ * Change whether a certain animation type is active.
326
+ */
327
+ function setActive(type, isActive, options) {
328
+ var _a;
329
+ // If the active state hasn't changed, we can safely do nothing here
330
+ if (state[type].isActive === isActive)
331
+ return Promise.resolve();
332
+ // Propagate active change to children
333
+ (_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach(function (child) { var _a; return (_a = child.animationState) === null || _a === void 0 ? void 0 : _a.setActive(type, isActive); });
334
+ state[type].isActive = isActive;
335
+ return animateChanges(options, type);
336
+ }
337
+ return {
338
+ isAnimated: isAnimated,
339
+ animateChanges: animateChanges,
340
+ setActive: setActive,
341
+ setAnimateFunction: setAnimateFunction,
342
+ getState: function () { return state; },
343
+ } as AnimationState;
344
+ }
345
+ function variantsHaveChanged(prev: any, next: any) {
346
+ if (typeof next === "string") {
347
+ return next !== prev;
348
+ }
349
+ else if (isVariantLabels(next)) {
350
+ return !shallowCompare(next, prev);
351
+ }
352
+ return false;
353
+ }
354
+ function createTypeState(isActive: boolean = false) {
355
+ return {
356
+ isActive: isActive,
357
+ protectedKeys: {},
358
+ needsAnimating: {},
359
+ prevResolvedValues: {},
360
+ };
361
+ }
362
+ function createState() {
363
+ var _a;
364
+ return _a = {},
365
+ _a[AnimationType.Animate] = createTypeState(true),
366
+ _a[AnimationType.Hover] = createTypeState(),
367
+ _a[AnimationType.Tap] = createTypeState(),
368
+ _a[AnimationType.Drag] = createTypeState(),
369
+ _a[AnimationType.Focus] = createTypeState(),
370
+ _a[AnimationType.Exit] = createTypeState(),
371
+ _a;
372
+ }
373
+
374
+ export { createAnimationState, variantPriorityOrder, variantsHaveChanged };
375
+
@@ -0,0 +1,167 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VariantLabels } from "../../motion/types";
6
+ import type { Target, TargetAndTransition, TargetResolver, TargetWithKeyframes, Transition } from "../../types";
7
+ import type { VisualElement } from "../types";
8
+ import { AnimationType } from "./types";
9
+ export type AnimationDefinition = VariantLabels | TargetAndTransition | TargetResolver;
10
+ export type AnimationOptions = {
11
+ delay?: number;
12
+ transitionOverride?: Transition;
13
+ custom?: any;
14
+ type?: AnimationType;
15
+ };
16
+ export type MakeTargetAnimatable = (visualElement: VisualElement, target: TargetWithKeyframes, origin?: Target, transitionEnd?: Target) => {
17
+ target: TargetWithKeyframes;
18
+ transitionEnd?: Target;
19
+ };
20
+
21
+
22
+ /**
23
+ based on framer-motion@4.0.3,
24
+ Copyright (c) 2018 Framer B.V.
25
+ */
26
+ import { __assign, __read, __rest } from 'tslib';
27
+ import { startAnimation } from '../../animation/utils/transitions.js';
28
+ import { setTarget } from './setters.js';
29
+ import { resolveVariant } from './variants.js';
30
+
31
+ /**
32
+ * @internal
33
+ */
34
+ function animateVisualElement(visualElement: VisualElement, definition: AnimationDefinition, options: AnimationOptions = {}) {
35
+ visualElement.notifyAnimationStart();
36
+ var animation;
37
+ if (Array.isArray(definition)) {
38
+ var animations = definition.map(function (variant) {
39
+ return animateVariant(visualElement, variant, options);
40
+ });
41
+ animation = Promise.all(animations);
42
+ }
43
+ else if (typeof definition === "string") {
44
+ animation = animateVariant(visualElement, definition, options);
45
+ }
46
+ else {
47
+ var resolvedDefinition = typeof definition === "function"
48
+ ? resolveVariant(visualElement, definition, options.custom)
49
+ : definition;
50
+ animation = animateTarget(visualElement, resolvedDefinition, options);
51
+ }
52
+ return animation.then(function () {
53
+ return visualElement.notifyAnimationComplete(definition);
54
+ }) as Promise<void>;
55
+ }
56
+ function animateVariant(visualElement: VisualElement, variant, options: AnimationOptions = {}) {
57
+ var _a;
58
+ if (options === void 0) { options = {}; }
59
+ var resolved = resolveVariant(visualElement, variant, options.custom);
60
+ var _b = (resolved || {}).transition, transition = _b === void 0 ? visualElement.getDefaultTransition() || {} : _b;
61
+ if (options.transitionOverride) {
62
+ transition = options.transitionOverride;
63
+ }
64
+ /**
65
+ * If we have a variant, create a callback that runs it as an animation.
66
+ * Otherwise, we resolve a Promise immediately for a composable no-op.
67
+ */
68
+ var getAnimation = resolved
69
+ ? function () { return animateTarget(visualElement, resolved, options); }
70
+ : function () { return Promise.resolve(); };
71
+ /**
72
+ * If we have children, create a callback that runs all their animations.
73
+ * Otherwise, we resolve a Promise immediately for a composable no-op.
74
+ */
75
+ var getChildAnimations = ((_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.size)
76
+ ? function (forwardDelay) {
77
+ if (forwardDelay === void 0) { forwardDelay = 0; }
78
+ var _a = transition.delayChildren, delayChildren = _a === void 0 ? 0 : _a, staggerChildren = transition.staggerChildren, staggerDirection = transition.staggerDirection;
79
+ return animateChildren(visualElement, variant, delayChildren + forwardDelay, staggerChildren, staggerDirection, options);
80
+ }
81
+ : function () { return Promise.resolve(); };
82
+ /**
83
+ * If the transition explicitly defines a "when" option, we need to resolve either
84
+ * this animation or all children animations before playing the other.
85
+ */
86
+ var when = transition.when;
87
+ if (when) {
88
+ var _c = __read(when === "beforeChildren"
89
+ ? [getAnimation, getChildAnimations]
90
+ : [getChildAnimations, getAnimation], 2), first = _c[0], last = _c[1];
91
+ return first().then(last);
92
+ }
93
+ else {
94
+ return Promise.all([getAnimation(), getChildAnimations(options.delay)]);
95
+ }
96
+ }
97
+ /**
98
+ * @internal
99
+ */
100
+ function animateTarget(visualElement: VisualElement, definition: AnimationDefinition, _a) {
101
+ var _b;
102
+ var _c = _a === void 0 ? {} : _a, _d = _c.delay, delay = _d === void 0 ? 0 : _d, transitionOverride = _c.transitionOverride, type = _c.type;
103
+ var _e = visualElement.makeTargetAnimatable(definition), _f = _e.transition, transition = _f === void 0 ? visualElement.getDefaultTransition() : _f, transitionEnd = _e.transitionEnd, target = __rest(_e, ["transition", "transitionEnd"]);
104
+ if (transitionOverride)
105
+ transition = transitionOverride;
106
+ var animations = [];
107
+ var animationTypeState = type && ((_b = visualElement.animationState) === null || _b === void 0 ? void 0 : _b.getState()[type]);
108
+ for (var key in target) {
109
+ var value = visualElement.getValue(key);
110
+ var valueTarget = target[key];
111
+ if (!value ||
112
+ valueTarget === undefined ||
113
+ (animationTypeState &&
114
+ shouldBlockAnimation(animationTypeState, key))) {
115
+ continue;
116
+ }
117
+ var animation = startAnimation(key, value, valueTarget, __assign({ delay: delay }, transition));
118
+ animations.push(animation);
119
+ }
120
+ return Promise.all(animations).then(function () {
121
+ transitionEnd && setTarget(visualElement, transitionEnd);
122
+ });
123
+ }
124
+ function animateChildren(visualElement, variant, delayChildren, staggerChildren, staggerDirection, options) {
125
+ if (delayChildren === void 0) { delayChildren = 0; }
126
+ if (staggerChildren === void 0) { staggerChildren = 0; }
127
+ if (staggerDirection === void 0) { staggerDirection = 1; }
128
+ var animations = [];
129
+ var maxStaggerDuration = (visualElement.variantChildren.size - 1) * staggerChildren;
130
+ var generateStaggerDuration = staggerDirection === 1
131
+ ? function (i) {
132
+ if (i === void 0) { i = 0; }
133
+ return i * staggerChildren;
134
+ }
135
+ : function (i) {
136
+ if (i === void 0) { i = 0; }
137
+ return maxStaggerDuration - i * staggerChildren;
138
+ };
139
+ Array.from(visualElement.variantChildren)
140
+ .sort(sortByTreeOrder)
141
+ .forEach(function (child, i) {
142
+ animations.push(animateVariant(child, variant, __assign(__assign({}, options), { delay: delayChildren + generateStaggerDuration(i) })).then(function () { return child.notifyAnimationComplete(variant); }));
143
+ });
144
+ return Promise.all(animations);
145
+ }
146
+ function stopAnimation(visualElement: VisualElement) {
147
+ visualElement.forEachValue(function (value) { return value.stop(); });
148
+ }
149
+ function sortByTreeOrder(a: VisualElement, b: VisualElement) {
150
+ return a.sortNodePosition(b);
151
+ }
152
+ /**
153
+ * Decide whether we should block this animation. Previously, we achieved this
154
+ * just by checking whether the key was listed in protectedKeys, but this
155
+ * posed problems if an animation was triggered by afterChildren and protectedKeys
156
+ * had been set to true in the meantime.
157
+ */
158
+ function shouldBlockAnimation(_a, key) {
159
+
160
+ var protectedKeys = _a.protectedKeys, needsAnimating = _a.needsAnimating;
161
+ var shouldBlock = protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true;
162
+ needsAnimating[key] = false;
163
+ return shouldBlock;
164
+ }
165
+
166
+ export { animateVisualElement, sortByTreeOrder, stopAnimation };
167
+
@@ -0,0 +1,18 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VisualElement } from "../types";
6
+ export interface WithDepth {
7
+ depth: number;
8
+ }
9
+
10
+ /**
11
+ based on framer-motion@4.0.3,
12
+ Copyright (c) 2018 Framer B.V.
13
+ */
14
+ var compareByDepth = function (a: VisualElement, b: VisualElement) {
15
+ return a.depth - b.depth;
16
+ };
17
+
18
+ export { compareByDepth };
@@ -0,0 +1,35 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { WithDepth } from "./compare-by-depth";
6
+
7
+ class FlatTree {
8
+ private children: any[] = [];
9
+ private isDirty = false;
10
+ add(child: WithDepth) {
11
+ addUniqueItem(this.children, child);
12
+ this.isDirty = true;
13
+ };
14
+ remove(child: WithDepth) {
15
+ removeItem(this.children, child);
16
+ this.isDirty = true;
17
+ }
18
+ forEach(callback: (child: WithDepth) => void) {
19
+ this.isDirty && this.children.sort(compareByDepth);
20
+ var numChildren = this.children.length;
21
+ for (var i = 0; i < numChildren; i++) {
22
+ callback(this.children[i]);
23
+ }
24
+ }
25
+ }
26
+
27
+
28
+ /**
29
+ based on framer-motion@4.0.3,
30
+ Copyright (c) 2018 Framer B.V.
31
+ */
32
+ import { addUniqueItem, removeItem } from '../../utils/array.js';
33
+ import { compareByDepth } from './compare-by-depth.js';
34
+
35
+ export { FlatTree };
@@ -0,0 +1,17 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VisualElement } from "../types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.1.11,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+ function isDraggable(visualElement: VisualElement) {
13
+ var _a = visualElement.getProps(), drag = _a.drag, _dragX = _a._dragX;
14
+ return drag && !_dragX;
15
+ }
16
+
17
+ export { isDraggable };