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
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Michael Lucht
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Motion Start
2
+
3
+ An animation library based on [framer-motion](https://www.framer.com/motion/).
4
+
5
+ [Visit Project Page](https://svelte-motion.gradientdescent.de)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install --save-dev motion-start
11
+ ```
12
+
13
+ ```bash
14
+ pnpm install --save-dev motion-start
15
+ ```
16
+
17
+ ```bash
18
+ yarn install --save-dev motion-start
19
+ ```
20
+
21
+ ```bash
22
+ bun install --save-dev motion-start
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Corresponding to a `MotionDiv` in framer-motion is this:
28
+
29
+ ```javascript
30
+ import { Motion } from 'motion-start'
31
+
32
+ <Motion let:motion><div use:motion/></Motion>
33
+ ```
34
+ For svg elements like 'g', 'path' or 'circle', use:
35
+
36
+ ```javascript
37
+ <Motion let:motion isSVG><g use:motion/></Motion>
38
+ ```
39
+
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "motion-start",
3
+ "version": "0.0.1",
4
+ "description": "Svelte animation library based on the React library framer-motion.",
5
+ "main": "src/index.ts",
6
+ "files": [
7
+ "./src"
8
+ ],
9
+ "author": "JonathonRP",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@changesets/cli": "^2.27.8",
13
+ "@types/react": "^18.3.5",
14
+ "framesync": "^6.1.2",
15
+ "popmotion": "^11.0.5",
16
+ "style-value-types": "5.1.2",
17
+ "tslib": "^2.7.0"
18
+ },
19
+ "devDependencies": {
20
+ "@emotion/is-prop-valid": "^1.3.0",
21
+ "@sveltejs/package": "^2.3.5",
22
+ "@sveltejs/vite-plugin-svelte": "4.0.0-next.7",
23
+ "@tsconfig/svelte": "^5.0.4",
24
+ "@types/node": "^20.16.5",
25
+ "@vitest/ui": "latest",
26
+ "csstype": "^3.1.3",
27
+ "publint": "^0.2.10",
28
+ "svelte": "5.0.0-next.252",
29
+ "typescript": "^5.6.2",
30
+ "vite": "^5.4.5",
31
+ "vitest": "latest"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": ">=3.35.0 || ^4.0.0 || ^5.0.0 || ^5.0.0-next.0"
35
+ },
36
+ "type": "module",
37
+ "engines": {
38
+ "pnpm": ">=8.7.0",
39
+ "node": ">=20"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "ur": "https://github.com/JonathonRP/motion-start/"
44
+ },
45
+ "sideEffects": false,
46
+ "keywords": [
47
+ "svelte animation",
48
+ "svelte",
49
+ "animation",
50
+ "gestures",
51
+ "drag",
52
+ "spring",
53
+ "popmotion",
54
+ "framer-motion"
55
+ ],
56
+ "scripts": {
57
+ "test": "vitest --ui",
58
+ "test:types": "vitest --typecheck.only --ui",
59
+ "build": "svelte-package --input ./src && publint --strict",
60
+ "check": "pnpm build && svelte-check --tsconfig ./tsconfig.json",
61
+ "ci:version": "changeset version && pnpm -r generate:version && git add --all",
62
+ "ci:publish": "pnpm build && changeset publish"
63
+ }
64
+ }
@@ -0,0 +1,86 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script module lang="ts">
5
+ var createObject = function () {
6
+ return {};
7
+ };
8
+ var stateVisualElement = visualElement({
9
+ build: function () {},
10
+ measureViewportBox: axisBox,
11
+ resetTransform: function () {},
12
+ restoreTransform: function () {},
13
+ removeValueFromRenderState: function () {},
14
+ render: function () {},
15
+ scrapeMotionValuesFromProps: createObject,
16
+ readValueFromInstance: function (_state, key, options) {
17
+ return options.initialState[key] || 0;
18
+ },
19
+ makeTargetAnimatable: function (element, _a) {
20
+ var transition = _a.transition,
21
+ transitionEnd = _a.transitionEnd,
22
+ target = __rest(_a, ["transition", "transitionEnd"]);
23
+ var origin = getOrigin(target, transition || {}, element);
24
+ checkTargetForNewValues(element, target, origin);
25
+ return __assign(
26
+ { transition: transition, transitionEnd: transitionEnd },
27
+ target
28
+ );
29
+ },
30
+ });
31
+ </script>
32
+
33
+ <script lang="ts">
34
+ import { afterUpdate, getContext, onMount } from "svelte";
35
+ import type { Writable } from "svelte/store";
36
+ import { __assign, __rest } from "tslib";
37
+ import { ScaleCorrectionParentContext } from "../context/ScaleCorrectionProvider.svelte";
38
+ import { UseVisualState } from "../motion/utils/use-visual-state.js";
39
+ import { visualElement } from "../render/index.js";
40
+ import { animateVisualElement } from "../render/utils/animation";
41
+ import {
42
+ checkTargetForNewValues,
43
+ getOrigin,
44
+ } from "../render/utils/setters.js";
45
+ export let initialState;
46
+
47
+ let animationState = initialState;
48
+ const sve = stateVisualElement;
49
+ $: element = sve({ props: {}, visualState: state });
50
+ onMount(() => {
51
+ element.mount({});
52
+ return () => element.unmount();
53
+ });
54
+ const _afterUpdate = () => {
55
+ element.setProps({
56
+ onUpdate: (v) => (animationState = { ...v }),
57
+ });
58
+ };
59
+
60
+ afterUpdate(_afterUpdate);
61
+ const scaleCorrectionParentContext = getContext<Writable<Array<unknown>>>(
62
+ ScaleCorrectionParentContext
63
+ );
64
+ scaleCorrectionParentContext.update((v) =>
65
+ v.concat([
66
+ {
67
+ afterU: _afterUpdate,
68
+ },
69
+ ])
70
+ );
71
+ let startAnimation = (animationDefinition) => {
72
+ return animateVisualElement(element, animationDefinition);
73
+ };
74
+ </script>
75
+
76
+ <UseVisualState
77
+ config={{
78
+ scrapeMotionValuesFromProps: createObject,
79
+ createRenderState: createObject,
80
+ }}
81
+ props={{}}
82
+ isStatic={false}
83
+ let:state
84
+ >
85
+ <slot animatedState={[animationState, startAnimation]} />
86
+ </UseVisualState>
@@ -0,0 +1,61 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { onMount } from "svelte";
6
+
7
+ import { animationControls } from "./animation-controls.js";
8
+ /**
9
+ * Creates `AnimationControls`, which can be used to manually start, stop
10
+ * and sequence animations on one or more components.
11
+ *
12
+ * The returned `AnimationControls` should be passed to the `animate` property
13
+ * of the components you want to animate.
14
+ *
15
+ * These components can then be animated with the `start` method.
16
+ *
17
+ * @library
18
+ *
19
+ * ```jsx
20
+ * import * as React from 'react'
21
+ * import { Frame, useAnimation } from 'framer'
22
+ *
23
+ * export function MyComponent(props) {
24
+ * const controls = useAnimation()
25
+ *
26
+ * controls.start({
27
+ * x: 100,
28
+ * transition: { duration: 0.5 },
29
+ * })
30
+ *
31
+ * return <Frame animate={controls} />
32
+ * }
33
+ * ```
34
+ *
35
+ * @motion
36
+ *
37
+ * ```jsx
38
+ * import * as React from 'react'
39
+ * import { motion, useAnimation } from 'framer-motion'
40
+ *
41
+ * export function MyComponent(props) {
42
+ * const controls = useAnimation()
43
+ *
44
+ * controls.start({
45
+ * x: 100,
46
+ * transition: { duration: 0.5 },
47
+ * })
48
+ *
49
+ * return <MotionDiv animate={controls} />
50
+ * }
51
+ * ```
52
+ *
53
+ * @returns Animation controller with `start` and `stop` methods
54
+ *
55
+ * @public
56
+ */
57
+ let controls = animationControls();
58
+ onMount(controls.mount);
59
+ </script>
60
+
61
+ <slot {controls} />
@@ -0,0 +1,78 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { ResolvedValueTarget, Spring, Tween } from "../types";
6
+ import { MotionValue } from "../value";
7
+ /**
8
+ * @public
9
+ */
10
+ export interface AnimationPlaybackControls {
11
+ stop: () => void;
12
+ }
13
+ /**
14
+ * @public
15
+ */
16
+ export interface AnimationPlaybackLifecycles<V> {
17
+ onUpdate?: (latest: V) => void;
18
+ onPlay?: () => void;
19
+ onComplete?: () => void;
20
+ onRepeat?: () => void;
21
+ onStop?: () => void;
22
+ }
23
+ /**
24
+ * @public
25
+ */
26
+ export type AnimationOptions<V> = (Tween | Spring) & AnimationPlaybackLifecycles<V> & {
27
+ delay?: number;
28
+ type?: "tween" | "spring";
29
+ };
30
+
31
+
32
+ /**
33
+ based on framer-motion@4.0.3,
34
+ Copyright (c) 2018 Framer B.V.
35
+ */
36
+
37
+ import { motionValue } from '../value/index.js';
38
+ import { isMotionValue } from '../value/utils/is-motion-value.js';
39
+ import { startAnimation } from './utils/transitions.js';
40
+
41
+ /**
42
+ * Animate a single value or a `MotionValue`.
43
+ *
44
+ * The first argument is either a `MotionValue` to animate, or an initial animation value.
45
+ *
46
+ * The second is either a value to animate to, or an array of keyframes to animate through.
47
+ *
48
+ * The third argument can be either tween or spring options, and optional lifecycle methods: `onUpdate`, `onPlay`, `onComplete`, `onRepeat` and `onStop`.
49
+ *
50
+ * Returns `AnimationPlaybackControls`, currently just a `stop` method.
51
+ *
52
+ * ```javascript
53
+ * const x = useMotionValue(0)
54
+ *
55
+ * useEffect(() => {
56
+ * const controls = animate(x, 100, {
57
+ * type: "spring",
58
+ * stiffness: 2000,
59
+ * onComplete: v => {}
60
+ * })
61
+ *
62
+ * return controls.stop
63
+ * })
64
+ * ```
65
+ *
66
+ * @public
67
+ */
68
+ function animate<V>(from: MotionValue<V> | V, to: ResolvedValueTarget, transition?: AnimationOptions<V>) {
69
+ if (transition === void 0) { transition = {}; }
70
+ var value = isMotionValue(from) ? from : motionValue(from);
71
+ startAnimation("", value, to, transition);
72
+ return {
73
+ stop: function () { return value.stop(); },
74
+ } as AnimationPlaybackControls;
75
+ }
76
+
77
+ export { animate };
78
+
@@ -0,0 +1,101 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { AnimationControls } from "./types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.0.3,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+
13
+ import { __read, __spreadArray } from 'tslib';
14
+ // import { invariant } from '../utils/errors.js';
15
+ import { animateVisualElement, stopAnimation } from '../render/utils/animation.js';
16
+ import { setValues } from '../render/utils/setters.js';
17
+
18
+ /**
19
+ * @public
20
+ */
21
+ function animationControls(startStopNotifier?: () => () => void ) {
22
+ /**
23
+ * Track whether the host component has mounted.
24
+ */
25
+ var hasMounted = false;
26
+ /**
27
+ * Pending animations that are started before a component is mounted.
28
+ * TODO: Remove this as animations should only run in effects
29
+ */
30
+ var pendingAnimations: any[] = [];
31
+ /**
32
+ * A collection of linked component animation controls.
33
+ */
34
+ var subscribers = new Set<any>();
35
+ var stopNotification: undefined | (() => void);
36
+ var controls = {
37
+ subscribe: function (visualElement) {
38
+ if (subscribers.size === 0){
39
+ stopNotification = startStopNotifier?.();
40
+ }
41
+ subscribers.add(visualElement);
42
+ return function () {
43
+ subscribers.delete(visualElement);
44
+ if (subscribers.size===0){
45
+ stopNotification?.()
46
+ }
47
+ };
48
+ },
49
+ start: function (definition, transitionOverride) {
50
+ /**
51
+ * TODO: We only perform this hasMounted check because in Framer we used to
52
+ * encourage the ability to start an animation within the render phase. This
53
+ * isn't behaviour concurrent-safe so when we make Framer concurrent-safe
54
+ * we can ditch this.
55
+ */
56
+ if (hasMounted) {
57
+ var animations_1: any[] = [];
58
+ subscribers.forEach(function (visualElement) {
59
+ animations_1.push(animateVisualElement(visualElement, definition, {
60
+ transitionOverride: transitionOverride,
61
+ }));
62
+ });
63
+ return Promise.all(animations_1);
64
+ }
65
+ else {
66
+ return new Promise(function (resolve) {
67
+ pendingAnimations.push({
68
+ animation: [definition, transitionOverride],
69
+ resolve: resolve,
70
+ });
71
+ });
72
+ }
73
+ },
74
+ set: function (definition) {
75
+ //invariant(hasMounted, "controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook.");
76
+ return subscribers.forEach(function (visualElement) {
77
+ setValues(visualElement, definition);
78
+ });
79
+ },
80
+ stop: function () {
81
+ subscribers.forEach(function (visualElement) {
82
+ stopAnimation(visualElement);
83
+ });
84
+ },
85
+ mount: function () {
86
+ hasMounted = true;
87
+ pendingAnimations.forEach(function (_a) {
88
+ var animation = _a.animation, resolve = _a.resolve;
89
+ controls.start.apply(controls, __spreadArray([], __read(animation))).then(resolve);
90
+ });
91
+ return function () {
92
+ hasMounted = false;
93
+ controls.stop();
94
+ };
95
+ },
96
+ } as AnimationControls;
97
+ return controls;
98
+ }
99
+
100
+ export { animationControls };
101
+
@@ -0,0 +1,83 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VisualElement } from "../render/types";
6
+ import type { TargetAndTransition, TargetResolver, Transition } from "../types";
7
+ /**
8
+ * @public
9
+ */
10
+ export type ControlsAnimationDefinition = string | string[] | TargetAndTransition | TargetResolver;
11
+ /**
12
+ * @public
13
+ */
14
+ export type PendingAnimations = {
15
+ animation: [ControlsAnimationDefinition, Transition | undefined];
16
+ resolve: () => void;
17
+ };
18
+ /**
19
+ * @public
20
+ */
21
+ export interface AnimationControls {
22
+ /**
23
+ * Subscribes a component's animation controls to this.
24
+ *
25
+ * @param controls - The controls to subscribe
26
+ * @returns An unsubscribe function.
27
+ *
28
+ * @internal
29
+ */
30
+ subscribe(visualElement: VisualElement): () => void;
31
+ /**
32
+ * Starts an animation on all linked components.
33
+ *
34
+ * @remarks
35
+ *
36
+ * ```jsx
37
+ * controls.start("variantLabel")
38
+ * controls.start({
39
+ * x: 0,
40
+ * transition: { duration: 1 }
41
+ * })
42
+ * ```
43
+ *
44
+ * @param definition - Properties or variant label to animate to
45
+ * @param transition - Optional `transtion` to apply to a variant
46
+ * @returns - A `Promise` that resolves when all animations have completed.
47
+ *
48
+ * @public
49
+ */
50
+ start(definition: ControlsAnimationDefinition, transitionOverride?: Transition): Promise<any>;
51
+ /**
52
+ * Instantly set to a set of properties or a variant.
53
+ *
54
+ * ```jsx
55
+ * // With properties
56
+ * controls.set({ opacity: 0 })
57
+ *
58
+ * // With variants
59
+ * controls.set("hidden")
60
+ * ```
61
+ *
62
+ * @internalremarks
63
+ * We could perform a similar trick to `.start` where this can be called before mount
64
+ * and we maintain a list of of pending actions that get applied on mount. But the
65
+ * expectation of `set` is that it happens synchronously and this would be difficult
66
+ * to do before any children have even attached themselves. It's also poor practise
67
+ * and we should discourage render-synchronous `.start` calls rather than lean into this.
68
+ *
69
+ * @public
70
+ */
71
+ set(definition: ControlsAnimationDefinition): void;
72
+ /**
73
+ * Stops animations on all linked components.
74
+ *
75
+ * ```jsx
76
+ * controls.stop()
77
+ * ```
78
+ *
79
+ * @public
80
+ */
81
+ stop(): void;
82
+ mount(): () => void;
83
+ }
@@ -0,0 +1 @@
1
+ export {default as UseAnimatedState} from './UseAnimatedState.svelte';
@@ -0,0 +1,74 @@
1
+ /**
2
+ based on framer-motion@4.0.3,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+
6
+ import { tick } from "svelte";
7
+ import { animationControls } from "./animation-controls"
8
+
9
+ /**
10
+ * Creates `AnimationControls`, which can be used to manually start, stop
11
+ * and sequence animations on one or more components.
12
+ *
13
+ * The returned `AnimationControls` should be passed to the `animate` property
14
+ * of the components you want to animate.
15
+ *
16
+ * These components can then be animated with the `start` method.
17
+ *
18
+ * @library
19
+ *
20
+ * ```jsx
21
+ * import * as React from 'react'
22
+ * import { Frame, useAnimation } from 'framer'
23
+ *
24
+ * export function MyComponent(props) {
25
+ * const controls = useAnimation()
26
+ *
27
+ * controls.start({
28
+ * x: 100,
29
+ * transition: { duration: 0.5 },
30
+ * })
31
+ *
32
+ * return <Frame animate={controls} />
33
+ * }
34
+ * ```
35
+ *
36
+ * @motion
37
+ *
38
+ * ```jsx
39
+ * import * as React from 'react'
40
+ * import { motion, useAnimation } from 'framer-motion'
41
+ *
42
+ * export function MyComponent(props) {
43
+ * const controls = useAnimation()
44
+ *
45
+ * controls.start({
46
+ * x: 100,
47
+ * transition: { duration: 0.5 },
48
+ * })
49
+ *
50
+ * return <MotionDiv animate={controls} />
51
+ * }
52
+ * ```
53
+ *
54
+ * @returns Animation controller with `start` and `stop` methods
55
+ *
56
+ * @public
57
+ */
58
+ export const useAnimation = () =>{
59
+
60
+ const controls = animationControls(()=>{
61
+
62
+ const cleanup: any = {}
63
+ tick().then(v => cleanup.clean = controls.mount());
64
+ return ()=>{
65
+ cleanup.clean?.();
66
+ }
67
+ });
68
+
69
+ return controls;
70
+ }
71
+
72
+
73
+
74
+ export { default as UseAnimation } from "./UseAnimation.svelte";
@@ -0,0 +1,70 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { PopmotionTransitionProps, ValueTarget, SingleTarget, KeyframesTarget } from "../../types";
6
+
7
+
8
+ /**
9
+ based on framer-motion@4.0.3,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+
13
+ import { __assign } from 'tslib';
14
+ import { isKeyframesTarget } from './is-keyframes-target.js';
15
+
16
+ var underDampedSpring = function () { return ({
17
+ type: "spring",
18
+ stiffness: 500,
19
+ damping: 25,
20
+ restDelta: 0.5,
21
+ restSpeed: 10,
22
+ }); };
23
+ var criticallyDampedSpring = function (to: SingleTarget) { return ({
24
+ type: "spring",
25
+ stiffness: 550,
26
+ damping: to === 0 ? 2 * Math.sqrt(550) : 30,
27
+ restDelta: 0.01,
28
+ restSpeed: 10,
29
+ }); };
30
+ var linearTween = function () { return ({
31
+ type: "keyframes",
32
+ ease: "linear",
33
+ duration: 0.3,
34
+ }); };
35
+ var keyframes = function (values: KeyframesTarget) { return ({
36
+ type: "keyframes",
37
+ duration: 0.8,
38
+ values: values,
39
+ }); };
40
+ var defaultTransitions = {
41
+ x: underDampedSpring,
42
+ y: underDampedSpring,
43
+ z: underDampedSpring,
44
+ rotate: underDampedSpring,
45
+ rotateX: underDampedSpring,
46
+ rotateY: underDampedSpring,
47
+ rotateZ: underDampedSpring,
48
+ scaleX: criticallyDampedSpring,
49
+ scaleY: criticallyDampedSpring,
50
+ scale: criticallyDampedSpring,
51
+ opacity: linearTween,
52
+ backgroundColor: linearTween,
53
+ color: linearTween,
54
+ default: criticallyDampedSpring,
55
+ };
56
+
57
+ // TODO: need to bring closer to Transition - then can use keyof typeof defaultTransitions.
58
+ var getDefaultTransition = function (valueKey: string, to: ValueTarget): PopmotionTransitionProps {
59
+ var transitionFactory: (v: any) => any;
60
+ if (isKeyframesTarget(to)) {
61
+ transitionFactory = keyframes;
62
+ }
63
+ else {
64
+ transitionFactory =
65
+ (defaultTransitions as any)[valueKey] || defaultTransitions.default;
66
+ }
67
+ return __assign({ to: to }, transitionFactory(to));
68
+ };
69
+
70
+ export { criticallyDampedSpring, getDefaultTransition, linearTween, underDampedSpring };