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,24 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { FeatureComponents } from "./types";
6
+
7
+ /**
8
+ based on framer-motion@4.0.3,
9
+ Copyright (c) 2018 Framer B.V.
10
+ */
11
+
12
+ import { UseFocusGesture } from '../../gestures/use-focus-gesture.js';
13
+ import { UseHoverGesture } from '../../gestures/use-hover-gesture.js';
14
+ import { UseTapGesture } from '../../gestures/use-tap-gesture.js';
15
+ /**
16
+ * @public
17
+ */
18
+ const gestureAnimations = {
19
+ tap: UseTapGesture,
20
+ focus: UseFocusGesture,
21
+ hover: UseHoverGesture,
22
+ } satisfies FeatureComponents;
23
+
24
+ export { gestureAnimations };
@@ -0,0 +1,314 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script module lang="ts">
5
+ const progressTarget = 1000;
6
+
7
+ function hasMoved(a, b) {
8
+ return (
9
+ !isZeroBox(a) &&
10
+ !isZeroBox(b) &&
11
+ (!axisIsEqual(a.x, b.x) || !axisIsEqual(a.y, b.y))
12
+ );
13
+ }
14
+
15
+ const zeroAxis = { min: 0, max: 0 };
16
+ function isZeroBox(a) {
17
+ return axisIsEqual(a.x, zeroAxis) && axisIsEqual(a.y, zeroAxis);
18
+ }
19
+
20
+ function axisIsEqual(a, b) {
21
+ return a.min === b.min && a.max === b.max;
22
+ }
23
+
24
+ const defaultLayoutTransition = {
25
+ duration: 0.45,
26
+ ease: [0.4, 0, 0.1, 1],
27
+ };
28
+ </script>
29
+
30
+ <script lang="ts">
31
+ import { onDestroy, onMount } from "svelte";
32
+ import {
33
+ getValueTransition,
34
+ startAnimation,
35
+ } from "../../../animation/utils/transitions.js";
36
+ import { defaultScaleCorrectors } from "../../../render/dom/projection/default-scale-correctors.js";
37
+ import { addScaleCorrection } from "../../../render/dom/projection/scale-correction.js";
38
+ import { eachAxis } from "../../../utils/each-axis.js";
39
+ import { axisBox } from "../../../utils/geometry/index.js";
40
+ import { tweenAxis } from "./utils";
41
+
42
+ export let visualElement,
43
+ //initial = undefined,
44
+ //style = undefined,
45
+ //transformTemplate = undefined,
46
+ //transformValues = undefined,
47
+ //AnimationProps
48
+ //animate = undefined,
49
+ //exit = undefined,
50
+ //variants = undefined,
51
+ //transition = undefined,
52
+ //VisualElementLifecycles
53
+ //onViewportBoxUpdate = undefined,
54
+ //onBeforeLayoutMeasure = undefined,
55
+ //onLayoutMeasure = undefined,
56
+ //onUpdate = undefined,
57
+ //onAnimationStart = undefined,
58
+ //onAnimationComplete = undefined,
59
+ //onLayoutAnimationComplete = undefined,
60
+ //GestureHandlers
61
+ // PanHandlers
62
+ //onPan = undefined,
63
+ //onPanStart = undefined,
64
+ //onPanSessionStart = undefined,
65
+ //onPanEnd = undefined,
66
+ // TapHandlers
67
+ //onTap = undefined,
68
+ //onTapStart = undefined,
69
+ //onTapCancel = undefined,
70
+ //whileTap = undefined,
71
+ //HoverHandlers
72
+ //whileHover = undefined,
73
+ //onHoverStart = undefined,
74
+ //onHoverEnd = undefined,
75
+ //FocusHandlers
76
+ //whileFocus = undefined,
77
+ //DraggableProps
78
+ //drag = undefined,
79
+ //whileDrag = undefined,
80
+ //dragDirectionLock = undefined,
81
+ //dragPropagation = undefined,
82
+ //dragConstraints = undefined,
83
+ //dragElastic = undefined,
84
+ //dragMomentum = undefined,
85
+ //dragTransition = undefined,
86
+ //dragControls = undefined,
87
+ //dragListener = undefined,
88
+ //onMeasureDragConstraints = undefined,
89
+ //_dragX = undefined,
90
+ //_dragY = undefined,
91
+ //DragHandlers
92
+ //onDragStart = undefined,
93
+ //onDragEnd = undefined,
94
+ //onDrag = undefined,
95
+ //onDirectionLock = undefined,
96
+ //onDragTransitionEnd = undefined,
97
+ // LayoutProps
98
+ layout = undefined,
99
+ //layoutId = undefined,
100
+ //MotionAdvancedProps
101
+ //custom = undefined,
102
+ //inherit = undefined,
103
+ safeToRemove;
104
+
105
+ /**
106
+ * A mutable object that tracks the target viewport box
107
+ * for the current animation frame.
108
+ */
109
+ let frameTarget = axisBox();
110
+ /**
111
+ * The current animation target, we use this to check whether to start
112
+ * a new animation or continue the existing one.
113
+ */
114
+ let currentAnimationTarget = axisBox();
115
+ /**
116
+ * Track whether we're animating this axis.
117
+ */
118
+ let isAnimating = {
119
+ x: false,
120
+ y: false,
121
+ };
122
+ let stopAxisAnimation = {
123
+ x: undefined,
124
+ y: undefined,
125
+ };
126
+
127
+ let unsubLayoutReady;
128
+
129
+ let isAnimatingTree = false;
130
+
131
+ onMount(() => {
132
+ visualElement.animateMotionValue = startAnimation;
133
+ visualElement.enableLayoutProjection();
134
+ unsubLayoutReady = visualElement.onLayoutUpdate(animateF);
135
+ visualElement.layoutSafeToRemove = function () {
136
+ safeToRemove();
137
+ };
138
+
139
+ addScaleCorrection(defaultScaleCorrectors);
140
+ });
141
+
142
+ onDestroy(() => {
143
+ unsubLayoutReady();
144
+ eachAxis((axis) => stopAxisAnimation[axis]?.());
145
+ });
146
+
147
+ const animateF = (
148
+ target,
149
+ origin,
150
+ {
151
+ originBox,
152
+ targetBox,
153
+ visibilityAction,
154
+ shouldStackAnimate,
155
+ onComplete,
156
+ ...config
157
+ } = {}
158
+ ) => {
159
+ /**
160
+ * Early return if we've been instructed not to animate this render.
161
+ */
162
+ if (shouldStackAnimate === false) {
163
+ isAnimatingTree = false;
164
+ return safeToRemove();
165
+ }
166
+
167
+ /**
168
+ * Prioritise tree animations
169
+ */
170
+ if (isAnimatingTree && shouldStackAnimate !== true) {
171
+ return;
172
+ } else if (shouldStackAnimate) {
173
+ isAnimatingTree = true;
174
+ }
175
+
176
+ /**
177
+ * Allow the measured origin (prev bounding box) and target (actual layout) to be
178
+ * overridden by the provided config.
179
+ */
180
+ origin = originBox || origin;
181
+ target = targetBox || target;
182
+
183
+ const boxHasMoved = hasMoved(origin, target);
184
+
185
+ const animations = eachAxis((axis) => {
186
+ /**
187
+ * If layout is set to "position", we can resize the origin box based on the target
188
+ * box and only animate its position.
189
+ */
190
+ if (layout === "position") {
191
+ const targetLength = target[axis].max - target[axis].min;
192
+ origin[axis].max = origin[axis].min + targetLength;
193
+ }
194
+
195
+ if (visualElement.projection.isTargetLocked) {
196
+ return;
197
+ } else if (visibilityAction !== undefined) {
198
+ visualElement.setVisibility(visibilityAction === VisibilityAction.Show);
199
+ } else if (boxHasMoved) {
200
+ // If the box has moved, animate between it's current visual state and its
201
+ // final state
202
+ return animateAxis(axis, target[axis], origin[axis], config);
203
+ } else {
204
+ // If the box has remained in the same place, immediately set the axis target
205
+ // to the final desired state
206
+ return visualElement.setProjectionTargetAxis(
207
+ axis,
208
+ target[axis].min,
209
+ target[axis].max
210
+ );
211
+ }
212
+ });
213
+
214
+ // Force a render to ensure there's no flash of uncorrected bounding box.
215
+ visualElement.syncRender();
216
+
217
+ /**
218
+ * If this visualElement isn't present (ie it's been removed from the tree by the user but
219
+ * kept in by the tree by AnimatePresence) then call safeToRemove when all axis animations
220
+ * have successfully finished.
221
+ */
222
+ return Promise.all(animations).then(() => {
223
+ isAnimatingTree = false;
224
+ onComplete && onComplete();
225
+ visualElement.notifyLayoutAnimationComplete();
226
+ });
227
+ };
228
+
229
+ /**
230
+ * TODO: This manually performs animations on the visualElement's layout progress
231
+ * values. It'd be preferable to amend the startLayoutAxisAnimation
232
+ * API to accept more custom animations like
233
+ */
234
+ const animateAxis = (
235
+ axis,
236
+ target,
237
+ origin,
238
+ { transition: _transition } = {}
239
+ ) => {
240
+ stopAxisAnimation[axis]?.();
241
+ /**
242
+ * If we're not animating to a new target, don't run this animation
243
+ */
244
+ if (
245
+ isAnimating[axis] &&
246
+ axisIsEqual(target, currentAnimationTarget[axis])
247
+ ) {
248
+ return;
249
+ }
250
+
251
+ stopAxisAnimation[axis]?.();
252
+ isAnimating[axis] = true;
253
+
254
+ const _frameTarget = frameTarget[axis];
255
+ const layoutProgress = visualElement.getProjectionAnimationProgress()[axis];
256
+
257
+ /**
258
+ * Set layout progress back to 0. We set it twice to hard-reset any velocity that might
259
+ * be re-incoporated into a subsequent spring animation.
260
+ */
261
+ layoutProgress.clearListeners();
262
+ layoutProgress.set(0);
263
+ layoutProgress.set(0);
264
+
265
+ /**
266
+ * Create an animation function to run once per frame. This will tween the visual bounding box from
267
+ * origin to target using the latest progress value.
268
+ */
269
+ const frame = () => {
270
+ // Convert the latest layoutProgress, which is a value from 0-1000, into a 0-1 progress
271
+ const p = layoutProgress.get() / progressTarget;
272
+
273
+ // Tween the axis and update the visualElement with the latest values
274
+ tweenAxis(_frameTarget, origin, target, p);
275
+ visualElement.setProjectionTargetAxis(
276
+ axis,
277
+ _frameTarget.min,
278
+ _frameTarget.max
279
+ );
280
+ };
281
+
282
+ // Synchronously run a frame to ensure there's no flash of the uncorrected bounding box.
283
+ frame();
284
+
285
+ // Ensure that the layout delta is updated for this frame.
286
+ //visualElement.updateLayoutProjection();
287
+
288
+ // Create a function to stop animation on this specific axis
289
+ const unsubscribeProgress = layoutProgress.onChange(frame);
290
+
291
+ stopAxisAnimation[axis] = () => {
292
+ isAnimating[axis] = false;
293
+ layoutProgress.stop();
294
+ unsubscribeProgress();
295
+ };
296
+
297
+ currentAnimationTarget[axis] = target;
298
+
299
+ const layoutTransition =
300
+ _transition ||
301
+ visualElement.getDefaultTransition() ||
302
+ defaultLayoutTransition;
303
+
304
+ // Start the animation on this axis
305
+ const animation = startAnimation(
306
+ axis === "x" ? "layoutX" : "layoutY",
307
+ layoutProgress,
308
+ progressTarget,
309
+ layoutTransition && getValueTransition(layoutTransition, "layout")
310
+ ).then(stopAxisAnimation[axis]);
311
+
312
+ return animation;
313
+ };
314
+ </script>
@@ -0,0 +1,9 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { FeatureProps } from "../types";
6
+ // export declare function AnimateLayoutContextProvider(props: FeatureProps): JSX.Element;
7
+
8
+
9
+ export {default as AnimateLayoutContextProvider} from './AnimateLayoutContextProvider.svelte'
@@ -0,0 +1,14 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { usePresence } from "../../../components/AnimatePresence/use-presence.js";
6
+ import Animate from "./Animate.svelte";
7
+ export let visualElement, props, isCustom;
8
+
9
+ let { layout } = props;
10
+ $: ({ layout } = props);
11
+ const presence = usePresence(isCustom);
12
+ </script>
13
+
14
+ <Animate {visualElement} {layout} safeToRemove={$presence[1]} />
@@ -0,0 +1,98 @@
1
+ <!-- based on framer-motion@4.1.16,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { afterUpdate, beforeUpdate, getContext, onMount } from "svelte";
6
+ import { get } from "svelte/store";
7
+ import {
8
+ ScaleCorrectionContext,
9
+ ScaleCorrectionParentContext,
10
+ } from "../../../context/ScaleCorrectionProvider.svelte";
11
+ import { isSharedLayout } from "../../../context/SharedLayoutContext.js";
12
+ import { snapshotViewportBox } from "../../../render/dom/projection/utils.js";
13
+
14
+ export let visualElement, syncLayout, framerSyncLayout, update;
15
+
16
+ const scaleCorrectionContext: any = getContext(ScaleCorrectionContext);
17
+ const scaleCorrectionParentContext: any = getContext(
18
+ ScaleCorrectionParentContext
19
+ );
20
+
21
+ onMount(() => {
22
+ isSharedLayout(syncLayout) && syncLayout.register(visualElement);
23
+ isSharedLayout(framerSyncLayout) &&
24
+ framerSyncLayout.register(visualElement);
25
+
26
+ visualElement.onUnmount(() => {
27
+ if (isSharedLayout(syncLayout)) {
28
+ syncLayout.remove(visualElement);
29
+ }
30
+
31
+ if (isSharedLayout(framerSyncLayout)) {
32
+ framerSyncLayout.remove(visualElement);
33
+ }
34
+ });
35
+ });
36
+ /**
37
+ * If this is a child of a SyncContext, notify it that it needs to re-render. It will then
38
+ * handle the snapshotting.
39
+ *
40
+ * If it is stand-alone component, add it to the batcher.
41
+ */
42
+
43
+ let updated = false;
44
+ const updater = (nc = false) => {
45
+ if (updated) {
46
+ return null;
47
+ }
48
+ updated = true;
49
+
50
+ // in React the updater function is called on children first, in Svelte the child does not call it.
51
+ get(scaleCorrectionContext).forEach((v) => {
52
+ v.updater?.(true);
53
+ });
54
+
55
+ if (isSharedLayout(syncLayout)) {
56
+ syncLayout.syncUpdate();
57
+ } else {
58
+ snapshotViewportBox(visualElement, nc);
59
+ syncLayout.add(visualElement);
60
+ }
61
+
62
+ return null;
63
+ };
64
+
65
+ $: update !== undefined && updater(update);
66
+
67
+ if (update === undefined) {
68
+ beforeUpdate(updater);
69
+ }
70
+ const afterU = (nc = false) => {
71
+ updated = false;
72
+ /* Second part of the updater calling in child layouts first.*/
73
+ const scc = get(scaleCorrectionContext);
74
+
75
+ scc.forEach((v, i) => {
76
+ v.afterU?.(true);
77
+ });
78
+
79
+ if (!isSharedLayout(syncLayout)) {
80
+ syncLayout.flush();
81
+ }
82
+
83
+ /**
84
+ * If this axis isn't animating as a result of this render we want to reset the targetBox
85
+ * to the measured box
86
+ */
87
+ //setCurrentViewportBox(visualElement);
88
+ };
89
+ scaleCorrectionParentContext.update((v) =>
90
+ v.concat([
91
+ {
92
+ updater,
93
+ afterU,
94
+ },
95
+ ])
96
+ );
97
+ afterUpdate(afterU);
98
+ </script>
@@ -0,0 +1,9 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { FeatureProps } from "../types";
6
+ // export declare function MeasureContextProvider(props: FeatureProps): JSX.Element;
7
+
8
+
9
+ export {default as MeasureContextProvider} from './MeasureContextProvider.svelte'
@@ -0,0 +1,32 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { getContext } from "svelte";
6
+ import type { Writable } from "svelte/store";
7
+ import type {
8
+ SharedLayoutSyncMethods,
9
+ SyncLayoutBatcher,
10
+ } from "../../../components/AnimateSharedLayout/types.js";
11
+ import {
12
+ FramerTreeLayoutContext,
13
+ SharedLayoutContext,
14
+ } from "../../../context/SharedLayoutContext.js";
15
+ import Measure from "./Measure.svelte";
16
+
17
+ export let visualElement, props, isCustom;
18
+
19
+ $: ({ update } = props);
20
+ const syncLayout: Writable<SyncLayoutBatcher | SharedLayoutSyncMethods> =
21
+ getContext(SharedLayoutContext) || SharedLayoutContext(isCustom);
22
+
23
+ const framerSyncLayout: Writable<SyncLayoutBatcher> =
24
+ getContext(FramerTreeLayoutContext) || FramerTreeLayoutContext(isCustom);
25
+ </script>
26
+
27
+ <Measure
28
+ syncLayout={$syncLayout}
29
+ framerSyncLayout={$framerSyncLayout}
30
+ {visualElement}
31
+ {update}
32
+ />
@@ -0,0 +1,20 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { FeatureComponents } from "../types";
6
+
7
+ /**
8
+ based on framer-motion@4.0.3,
9
+ Copyright (c) 2018 Framer B.V.
10
+ */
11
+
12
+ import { AnimateLayoutContextProvider } from './Animate.js';
13
+ import { MeasureContextProvider } from './Measure.js';
14
+
15
+ var layoutAnimations = {
16
+ measureLayout: MeasureContextProvider,
17
+ layoutAnimation: AnimateLayoutContextProvider
18
+ } satisfies FeatureComponents;
19
+
20
+ export { layoutAnimations };
@@ -0,0 +1,71 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ /**
6
+ * @public
7
+ */
8
+ export interface LayoutProps {
9
+ /**
10
+ * If `true`, this component will automatically animate to its new position when
11
+ * its layout changes.
12
+ *
13
+ * ```jsx
14
+ * <MotionDiv layout />
15
+ * ```
16
+ *
17
+ * This will perform a layout animation using performant transforms. Part of this technique
18
+ * involved animating an element's scale. This can introduce visual distortions on children,
19
+ * `boxShadow` and `borderRadius`.
20
+ *
21
+ * To correct distortion on immediate children, add `layout` to those too.
22
+ *
23
+ * `boxShadow` and `borderRadius` will automatically be corrected if they are already being
24
+ * animated on this component. Otherwise, set them directly via the `initial` prop.
25
+ *
26
+ * If `layout` is set to `"position"`, the size of the component will change instantly and
27
+ * only its position will animate.
28
+ *
29
+ * @public
30
+ */
31
+ layout?: boolean | "position";
32
+ /**
33
+ * Enable shared layout transitions between components for children of `AnimateSharedLayout`.
34
+ *
35
+ * When a component with a layoutId is removed from the React tree, and then
36
+ * added elsewhere, it will visually animate from the previous component's bounding box
37
+ * and its latest animated values.
38
+ *
39
+ * ```jsx
40
+ * <AnimateSharedLayout>
41
+ * {items.map(item => (
42
+ * <motion.li layout>
43
+ * {item.name}
44
+ * {item.isSelected && <MotionDiv layoutId="underline" />}
45
+ * </motion.li>
46
+ * ))}
47
+ * </AnimateSharedLayout>
48
+ * ```
49
+ *
50
+ * If the previous component remains in the tree it will either get hidden immediately or,
51
+ * if `type="crossfade"` is set on `AnimateSharedLayout`, it will crossfade to the new component.
52
+ *
53
+ * @public
54
+ */
55
+ layoutId?: string;
56
+ /**
57
+ * This enables a component's transform to be reset during layout
58
+ * measurements. This is intended to be used independently of the
59
+ * layout prop, for instance if a parent component's transform is
60
+ * interfering with the measurement of a child.
61
+ *
62
+ * @internal
63
+ */
64
+ _layoutResetTransform?: boolean;
65
+ /**
66
+ * A callback that will fire when a layout animation on this component completes.
67
+ *
68
+ * @public
69
+ */
70
+ onLayoutAnimationComplete?(): void;
71
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Axis, AxisBox2D } from "../../../types/geometry";
6
+ interface WithLayoutId {
7
+ getLayoutId: () => undefined | string;
8
+ }
9
+
10
+ /**
11
+ based on framer-motion@4.1.11,
12
+ Copyright (c) 2018 Framer B.V.
13
+ */
14
+ import {fixed} from '../../../utils/fix-process-env';
15
+ import { mix } from 'popmotion';
16
+
17
+ function tweenAxis(target: Axis, prev: Axis, next: Axis, p: number) {
18
+ target.min = mix(prev.min, next.min, p);
19
+ target.max = mix(prev.max, next.max, p);
20
+ }
21
+ function calcRelativeOffsetAxis(parent: Axis, child: Axis) {
22
+ return {
23
+ min: child.min - parent.min,
24
+ max: child.max - parent.min,
25
+ };
26
+ }
27
+ function calcRelativeOffset(parent: AxisBox2D, child: AxisBox2D) {
28
+ return {
29
+ x: calcRelativeOffsetAxis(parent.x, child.x),
30
+ y: calcRelativeOffsetAxis(parent.y, child.y),
31
+ };
32
+ }
33
+ function checkIfParentHasChanged(prev: WithLayoutId, next: WithLayoutId) {
34
+ var prevId = prev.getLayoutId();
35
+ var nextId = next.getLayoutId();
36
+ return prevId !== nextId || (nextId === undefined && prev !== next);
37
+ }
38
+
39
+ export { calcRelativeOffset, calcRelativeOffsetAxis, checkIfParentHasChanged, tweenAxis };
40
+
@@ -0,0 +1,53 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Component, SvelteComponent } from "svelte";
6
+ import type { CreateVisualElement, VisualElement } from "../../render/types";
7
+ import type { MotionProps } from "../types";
8
+ import type { VisualState } from "../utils/use-visual-state";
9
+ /**
10
+ * @public
11
+ */
12
+ export interface FeatureProps {
13
+ props: MotionProps;
14
+ visualElement: VisualElement;
15
+ }
16
+ export type FeatureNames = {
17
+ animation: true;
18
+ exit: true;
19
+ drag: true;
20
+ tap: true;
21
+ focus: true;
22
+ hover: true;
23
+ pan: true;
24
+ layoutAnimation: true;
25
+ measureLayout: true;
26
+ };
27
+ export type FeatureComponent = Component<SvelteComponent<FeatureProps>>;
28
+ /**
29
+ * @public
30
+ */
31
+ export interface FeatureDefinition {
32
+ isEnabled: (props: MotionProps) => boolean;
33
+ Component?: FeatureComponent;
34
+ }
35
+ export interface FeatureComponents {
36
+ animation?: FeatureComponent;
37
+ exit?: FeatureComponent;
38
+ drag?: FeatureComponent;
39
+ tap?: FeatureComponent;
40
+ focus?: FeatureComponent;
41
+ hover?: FeatureComponent;
42
+ pan?: FeatureComponent;
43
+ layoutAnimation?: FeatureComponent;
44
+ measureLayout?: FeatureComponent;
45
+ }
46
+ export interface FeatureBundle extends FeatureComponents {
47
+ renderer: CreateVisualElement<any>;
48
+ }
49
+ export type LazyFeatureBundle = () => Promise<FeatureBundle>;
50
+ export type FeatureDefinitions = {
51
+ [K in keyof FeatureNames]: FeatureDefinition;
52
+ };
53
+ export type RenderComponent<Instance, RenderState> = (Component: string | React.ComponentType, props: MotionProps, ref: React.Ref<Instance>, visualState: VisualState<Instance, RenderState>, isStatic: boolean) => any;