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,57 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import { MotionValue } from ".";
6
+
7
+ import { useCombineMotionValues } from "./use-combine-values"
8
+
9
+ /**
10
+ * Combine multiple motion values into a new one using a string template literal.
11
+ *
12
+ * ```jsx
13
+ * import {
14
+ * motion,
15
+ * useSpring,
16
+ * useMotionValue,
17
+ * useMotionTemplate
18
+ * } from "framer-motion"
19
+ *
20
+ * function Component() {
21
+ * const shadowX = useSpring(0)
22
+ * const shadowY = useMotionValue(0)
23
+ * const shadow = useMotionTemplate`drop-shadow(${shadowX}px ${shadowY}px 20px rgba(0,0,0,0.3))`
24
+ *
25
+ * return <MotionDiv style={{ filter: shadow }} />
26
+ * }
27
+ * ```
28
+ *
29
+ * @public
30
+ */
31
+
32
+ export const useMotionTemplate = (fragments: TemplateStringsArray, ...values: MotionValue[]) => {
33
+ /**
34
+ * Create a function that will build a string from the latest motion values.
35
+ */
36
+ let numFragments = fragments.length;
37
+ const buildValue = () => {
38
+ let output = ``
39
+
40
+ for (let i = 0; i < numFragments; i++) {
41
+ output += fragments[i]
42
+ const value = values[i]
43
+ if (value) output += values[i].get()
44
+ }
45
+
46
+ return output
47
+ }
48
+ const value = useCombineMotionValues(values, buildValue) as any;
49
+ value.resetInner = value.reset;
50
+
51
+ value.reset = (f: TemplateStringsArray, ...vs: MotionValue[]) => {
52
+ numFragments = f.length;
53
+ value.resetInner(vs,buildValue)
54
+ }
55
+
56
+ return value as MotionValue<string> & { reset: (fragments: TemplateStringsArray, ...values: MotionValue[]) => void };
57
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ /**
6
+ * Creates a `MotionValue` to track the state and velocity of a value.
7
+ *
8
+ * Usually, these are created automatically. For advanced use-cases, like use with `useTransform`, you can create `MotionValue`s externally and pass them into the animated component via the `style` prop.
9
+ *
10
+ * @motion
11
+ *
12
+ * ```jsx
13
+ * <script>
14
+ * const scale = useMotionValue(1)
15
+ * </script
16
+ *
17
+ * <Motion let:motion>
18
+ * <div style={{scale}} use:motion/>
19
+ * </Motion>
20
+ * ```
21
+ *
22
+ * @param initial - The initial state.
23
+ *
24
+ * @public
25
+ */
26
+ export { motionValue as useMotionValue } from './index.js';
27
+ // export { default as UseMotionValue } from './UseMotionValue.svelte';
@@ -0,0 +1,84 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { SpringOptions } from "popmotion";
6
+ import { MotionValue } from "../value";
7
+
8
+ /**
9
+ based on framer-motion@4.1.16,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+
13
+ import { fixed } from '../utils/fix-process-env';
14
+ import { getContext } from "svelte"
15
+ import { MotionConfigContext, type MotionConfigContextObject } from "../context/MotionConfigContext"
16
+ import { get, type Writable } from 'svelte/store';
17
+ import { useMotionValue } from "./use-motion-value";
18
+ import { isMotionValue } from "./utils/is-motion-value";
19
+ import { animate } from "popmotion"
20
+
21
+ /**
22
+ * Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state.
23
+ *
24
+ * It can either work as a stand-alone `MotionValue` by initialising it with a value, or as a subscriber
25
+ * to another `MotionValue`.
26
+ *
27
+ * @remarks
28
+ *
29
+ * ```jsx
30
+ * const x = useSpring(0, { stiffness: 300 })
31
+ * const y = useSpring(x, { damping: 10 })
32
+ * ```
33
+ *
34
+ * @param inputValue - `MotionValue` or number. If provided a `MotionValue`, when the input `MotionValue` changes, the created `MotionValue` will spring towards that value.
35
+ * @param springConfig - Configuration options for the spring.
36
+ * @returns `MotionValue`
37
+ *
38
+ * @public
39
+ */
40
+ export const useSpring = (source: MotionValue | number, config: SpringOptions = {}, isCustom = false) => {
41
+
42
+ const mcc: Writable<MotionConfigContextObject> = getContext(MotionConfigContext) || MotionConfigContext(isCustom);
43
+
44
+ let activeSpringAnimation: { stop: () => void } | null = null;
45
+
46
+ let value = useMotionValue(isMotionValue(source) ? source.get() : source) as MotionValue<any> & { reset: (_: any, config: SpringOptions) => void };
47
+
48
+ let cleanup: () => void;
49
+ const update = (_source: typeof source, _config: typeof config) => {
50
+ value.attach((v, set) => {
51
+
52
+
53
+ const { isStatic } = get(mcc);
54
+
55
+ if (isStatic) {
56
+ return set(v);
57
+ }
58
+ if (activeSpringAnimation) {
59
+ activeSpringAnimation.stop();
60
+ }
61
+ activeSpringAnimation = animate({
62
+ from: value.get(),
63
+ to: v,
64
+ velocity: value.getVelocity(),
65
+ ..._config,
66
+ onUpdate: set,
67
+ })
68
+
69
+ return value.get();
70
+ })
71
+ cleanup?.()
72
+ return isMotionValue(_source) ?
73
+ _source.onChange(v => value.set(parseFloat(v))) :
74
+ undefined
75
+ }
76
+
77
+ update(source, config);
78
+
79
+ value.reset = update;
80
+
81
+ return value;
82
+ }
83
+
84
+ //export { default as UseSpring } from './UseSpring.svelte';
@@ -0,0 +1,216 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import { MotionValue } from "../value";
6
+ import type { TransformOptions } from "../utils/transform";
7
+
8
+ import { transform } from "../utils/transform"
9
+ import { useCombineMotionValues } from "./use-combine-values"
10
+
11
+ export type InputRange = number[];
12
+ type SingleTransformer<I, O> = (input: I) => O;
13
+ type MultiTransformer<I, O> = (input: I[]) => O;
14
+ type Transformer<I, O> =
15
+ | SingleTransformer<I, O>
16
+ /**
17
+ * Ideally, this would be typed <I, O> in all instances, but to type this
18
+ * more accurately requires the tuple support in TypeScript 4:
19
+ * https://gist.github.com/InventingWithMonster/c4d23752a0fae7888596c4ff6d92733a
20
+ */
21
+ | MultiTransformer<string | number, O>
22
+ /**
23
+ * Create a `MotionValue` that transforms the output of another `MotionValue` by mapping it from one range of values into another.
24
+ *
25
+ * @remarks
26
+ *
27
+ * Given an input range of `[-200, -100, 100, 200]` and an output range of
28
+ * `[0, 1, 1, 0]`, the returned `MotionValue` will:
29
+ *
30
+ * - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
31
+ * - When provided a value between `-100` and `100`, will return `1`.
32
+ * - When provided a value between `100` and `200`, will return a value between `1` and `0`
33
+ *
34
+ *
35
+ * The input range must be a linear series of numbers. The output range
36
+ * can be any value type supported by Framer Motion: numbers, colors, shadows, etc.
37
+ *
38
+ * Every value in the output range must be of the same type and in the same format.
39
+ *
40
+ * @motion
41
+ *
42
+ * ```jsx
43
+ * <script>
44
+ * const x = useMotionValue(0)
45
+ * const xRange = [-200, -100, 100, 200]
46
+ * const opacityRange = [0, 1, 1, 0]
47
+ * const opacity = useTransform(x, xRange, opacityRange)
48
+ * </script>
49
+ *
50
+ * <Motion let:motion
51
+ * animate={{ x: 200 }}
52
+ * style={{ opacity, x }}
53
+ * >
54
+ * <div use:motion/>
55
+ * </Motion>
56
+ * ```
57
+ *
58
+ * @param inputValue - `MotionValue`
59
+ * @param inputRange - A linear series of numbers (either all increasing or decreasing)
60
+ * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
61
+ * @param options -
62
+ *
63
+ * - clamp: boolean. Clamp values to within the given range. Defaults to `true`
64
+ * - ease: EasingFunction[]. Easing functions to use on the interpolations between each value in the input and output ranges. If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition between each.
65
+ *
66
+ * @returns `MotionValue & { reset: (value: MotionValue<number>, inputRange: InputRange, outputRange: O[], options?: TransformOptions<O>) => void }`
67
+ *
68
+ * @public
69
+ */
70
+ export function useTransform<I, O>(value: MotionValue<number>, inputRange: InputRange, outputRange: O[], options?: TransformOptions<O>):
71
+ MotionValue<O> & { reset: (value: MotionValue<number>, inputRange: InputRange, outputRange: O[], options?: TransformOptions<O>) => void };
72
+ /**
73
+ * Create a `MotionValue` that transforms the output of another `MotionValue` through a function.
74
+ * In this example, `y` will always be double `x`.
75
+ *
76
+ * @motion
77
+ *
78
+ * ```jsx
79
+ * <script>
80
+ * const x = useMotionValue(10)
81
+ * const y = useTransform(x, value => value * 2)
82
+ * </script>
83
+ *
84
+ * <Motion let:motion style={{ x, y }}>
85
+ * <div use:motion/>
86
+ * </Motion>
87
+ * ```
88
+ *
89
+ * @param input - A `MotionValue` that will pass its latest value through `transform` to update the returned `MotionValue`.
90
+ * @param transform - A function that accepts the latest value from `input` and returns a new value.
91
+ * @returns `MotionValue`
92
+ *
93
+ * @public
94
+ */
95
+ export function useTransform<I, O>(input: MotionValue<I>, transformer: SingleTransformer<I, O>):
96
+ MotionValue<O> & { reset: (input: MotionValue<I>, transformer: SingleTransformer<I, O>) => void};
97
+ /**
98
+ * Pass an array of `MotionValue`s and a function to combine them. In this example, `z` will be the `x` multiplied by `y`.
99
+ *
100
+ * @motion
101
+ *
102
+ * ```jsx
103
+ * <script>
104
+ * const x = useMotionValue(0)
105
+ * const y = useMotionValue(0)
106
+ * const z = useTransform([x, y], [latestX, latestY] => latestX * latestY)
107
+ * </script>
108
+ *
109
+ * <Motion let:motion style={{ x, y, z }}>
110
+ * return <div use:motion/>
111
+ * </Motion>
112
+ * ```
113
+ *
114
+ * @param input - An array of `MotionValue`s that will pass their latest values through `transform` to update the returned `MotionValue`.
115
+ * @param transform - A function that accepts the latest values from `input` and returns a new value.
116
+ * @returns `MotionValue`
117
+ *
118
+ * @public
119
+ */
120
+ // export function useTransform<I, O>(input: MotionValue<string | number>[], transformer: MultiTransformer<I, O>):
121
+ // MotionValue<O> & { reset: (input: MotionValue<string | number>[], transformer: MultiTransformer<I, O>) => void };
122
+ // export function useTransform<I, O>(
123
+ // input: MotionValue<string>[] | MotionValue<number>[] | MotionValue<string | number>[],
124
+ // transformer: MultiTransformer<I, O>
125
+ // ): MotionValue<O> & { reset: (input: MotionValue<string>[] | MotionValue<number>[] | MotionValue<string | number>[], transformer: MultiTransformer<I, O>) => void };
126
+ // export function useTransform<I, O>(transformer: () => O): MotionValue<O>;
127
+ /**
128
+ * Pass an array of `MotionValue`s and a function to combine them. In this example, `z` will be the `x` multiplied by `y`.
129
+ *
130
+ * ```jsx
131
+ * export const MyComponent = () => {
132
+ * const x = useMotionValue(0)
133
+ * const y = useMotionValue(0)
134
+ * const z = useTransform([x, y], ([latestX, latestY]) => latestX * latestY)
135
+ *
136
+ * return <motion.div style={{ x, y, z }} />
137
+ * }
138
+ * ```
139
+ *
140
+ * @param input - An array of `MotionValue`s that will pass their latest values through `transform` to update the returned `MotionValue`.
141
+ * @param transform - A function that accepts the latest values from `input` and returns a new value.
142
+ * @returns `MotionValue`
143
+ *
144
+ * @public
145
+ */
146
+ export function useTransform<I, O>(
147
+ input:
148
+ | MotionValue<I>
149
+ | MotionValue<string>[]
150
+ | MotionValue<number>[]
151
+ | MotionValue<string | number>[]
152
+ | (() => O),
153
+ inputRangeOrTransformer?: InputRange | Transformer<I, O>,
154
+ outputRange?: O[],
155
+ options?: TransformOptions<O>
156
+ ): any {
157
+
158
+ const latest = <I[]>[];
159
+
160
+ const update = (
161
+ input:
162
+ | MotionValue<I>
163
+ | MotionValue<string>[]
164
+ | MotionValue<number>[]
165
+ | MotionValue<string | number>[]
166
+ | (() => O),
167
+ inputRangeOrTransformer?: InputRange | Transformer<I,O>,
168
+ outputRange?: O[],
169
+ options?: TransformOptions<O>
170
+ ) => {
171
+ const transformer = typeof inputRangeOrTransformer === "function"
172
+ ? inputRangeOrTransformer
173
+ : transform(inputRangeOrTransformer!, outputRange!, options);
174
+ const values = Array.isArray(input) ? input : [input];
175
+ const _transformer = Array.isArray(input) ? transformer :
176
+ ([latest]) =>
177
+ transformer(latest);
178
+ return [values, () => {
179
+ latest.length = 0
180
+ const numValues = values.length
181
+ for (let i = 0; i < numValues; i++) {
182
+ latest[i] = values[i].get()
183
+ }
184
+
185
+ return _transformer(latest)
186
+ }]
187
+
188
+ }
189
+ const comb = useCombineMotionValues(...update(input,
190
+ inputRangeOrTransformer,
191
+ outputRange,
192
+ options)) as any;
193
+
194
+ comb.updateInner = comb.reset;
195
+
196
+ comb.reset = (
197
+ input:
198
+ | MotionValue<I>
199
+ | MotionValue<string>[]
200
+ | MotionValue<number>[]
201
+ | MotionValue<string | number>[]
202
+ | (() => O),
203
+ inputRangeOrTransformer?: InputRange | Transformer<I,O>,
204
+ outputRange?: O[],
205
+ options?: TransformOptions<O>
206
+ ) => comb.updateInner(
207
+ ...update(
208
+ input,
209
+ inputRangeOrTransformer,
210
+ outputRange,
211
+ options
212
+ )
213
+ )
214
+ return comb;
215
+ }
216
+ // export { default as UseTransform } from './UseTransform.svelte';
@@ -0,0 +1,44 @@
1
+
2
+ /**
3
+ based on framer-motion@4.1.17,
4
+ Copyright (c) 2018 Framer B.V.
5
+ */
6
+ import { MotionValue } from "./index.js";
7
+ import { useMotionValue } from "./use-motion-value.js"
8
+ /**
9
+ * Creates a `MotionValue` that updates when the velocity of the provided `MotionValue` changes.
10
+ *
11
+ * ```javascript
12
+ * const x = useMotionValue(0)
13
+ * const xVelocity = useVelocity(x)
14
+ * const xAcceleration = useVelocity(xVelocity)
15
+ * ```
16
+ *
17
+ * @public
18
+ */
19
+ export const useVelocity = (value : MotionValue<number>) => {
20
+ let val = value;
21
+ let cleanup: () => void;
22
+
23
+ const reset = (value: MotionValue<number>) => {
24
+ cleanup?.();
25
+ val = value
26
+ cleanup = val.velocityUpdateSubscribers.add((newVelocity) => {
27
+ velocity.set(newVelocity);
28
+ })
29
+ }
30
+
31
+ const velocity = useMotionValue(value.getVelocity(), () => {
32
+ cleanup?.();
33
+ cleanup = val.velocityUpdateSubscribers.add((newVelocity) => {
34
+ velocity.set(newVelocity);
35
+ })
36
+ return () => {
37
+ cleanup?.()
38
+ }
39
+ }) as MotionValue<number> & { reset: typeof reset };
40
+
41
+ velocity.reset = reset;
42
+
43
+ return velocity;
44
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { MotionValue } from "../";
6
+
7
+ /**
8
+ based on framer-motion@4.0.3,
9
+ Copyright (c) 2018 Framer B.V.
10
+ */
11
+ var isMotionValue = function (value: any): value is MotionValue {
12
+ return value !== null && typeof value === "object" && value.getVelocity;
13
+ };
14
+
15
+ export { isMotionValue };
@@ -0,0 +1,29 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import { MotionValue } from "..";
6
+ import type { CustomValueType } from "../../types";
7
+
8
+ /**
9
+ based on framer-motion@4.0.3,
10
+ Copyright (c) 2018 Framer B.V.
11
+ */
12
+ import { isCustomValue } from '../../utils/resolve-value.js';
13
+ import { isMotionValue } from './is-motion-value.js';
14
+
15
+ /**
16
+ * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
17
+ *
18
+ * TODO: Remove and move to library
19
+ *
20
+ * @internal
21
+ */
22
+ function resolveMotionValue(value?: string | number | CustomValueType | MotionValue): string | number {
23
+ var unwrappedValue = isMotionValue(value) ? value.get() : value;
24
+ return isCustomValue(unwrappedValue)
25
+ ? unwrappedValue.toValue()
26
+ : unwrappedValue;
27
+ }
28
+
29
+ export { resolveMotionValue };