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,56 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { getContext, setContext } from "svelte";
6
+ import { get, writable, type Writable } from "svelte/store";
7
+ import { setDomContext } from "../../context/DOMcontext.js";
8
+ import {
9
+ MotionConfigContext,
10
+ type MotionConfigContextObject,
11
+ } from "../../context/MotionConfigContext.js";
12
+ import { provideScaleCorrection } from "../../context/ScaleCorrectionProvider.svelte";
13
+ import { scaleCorrection } from "./MotionConfigScaleCorrection.js";
14
+ import type { MotionConfigProps } from "./index.js";
15
+
16
+ type $$Props = MotionConfigProps;
17
+
18
+ export let transformPagePoint: $$Props["transformPagePoint"] = undefined,
19
+ isStatic: $$Props["isStatic"] = undefined,
20
+ transition: $$Props["transition"] = undefined,
21
+ isCustom = false;
22
+ const mcc: Writable<MotionConfigContextObject> =
23
+ getContext(MotionConfigContext) || MotionConfigContext(isCustom);
24
+ /**
25
+ * Inherit props from any parent MotionConfig components
26
+ */
27
+ let config = { ...get(mcc), ...{ transformPagePoint, isStatic, transition } };
28
+ $: config = { ...$mcc, ...{ transformPagePoint, isStatic, transition } };
29
+
30
+ // need to inform child layouts, or problems with scroll occur
31
+ provideScaleCorrection();
32
+ /**
33
+ * Don't allow isStatic to change between renders as it affects how many hooks
34
+ * motion components fire.
35
+ */
36
+ //config.isStatic = useConstant(() => config.isStatic)
37
+
38
+ /**
39
+ * Creating a new config context object will re-render every `motion` component
40
+ * every time it renders. So we only want to create a new one sparingly.
41
+ */
42
+ $: transitionDependency =
43
+ typeof config.transition === "object" ? config.transition.toString() : "";
44
+
45
+ let context = writable(config);
46
+ setContext(MotionConfigContext, context);
47
+ setDomContext("Motion", isCustom, context);
48
+ const memo = () => config;
49
+ const scaleCorrector = scaleCorrection();
50
+ $: {
51
+ context.set(memo(transitionDependency, config.transformPagePoint));
52
+ scaleCorrector.update();
53
+ }
54
+ </script>
55
+
56
+ <slot />
@@ -0,0 +1,47 @@
1
+ import { getContext } from "svelte";
2
+ import { get } from "svelte/store";
3
+ import {
4
+ ScaleCorrectionContext,
5
+ ScaleCorrectionParentContext,
6
+ } from "../../context/ScaleCorrectionProvider.svelte";
7
+
8
+
9
+ export const scaleCorrection = () => {
10
+
11
+ const scaleCorrectionContext = getContext(ScaleCorrectionContext);
12
+ const scaleCorrectionParentContext = getContext(
13
+ ScaleCorrectionParentContext
14
+ );
15
+ const afterU = (nc = false) => {
16
+ /* Second part of the updater calling in child layouts first.*/
17
+ const scc = get(scaleCorrectionContext);
18
+
19
+
20
+ scc.forEach((v, i) => {
21
+ v.afterU?.(true);
22
+ });
23
+ };
24
+
25
+ const updater = () => {
26
+ // in React the updater function is called on children first, in Svelte the child does not call it.
27
+ get(scaleCorrectionContext).forEach((v) => {
28
+ v.updater?.(true);
29
+ })
30
+ }
31
+
32
+ scaleCorrectionParentContext.update((v) =>
33
+ v.concat([
34
+ {
35
+ updater,
36
+ afterU,
37
+ },
38
+ ])
39
+ );
40
+
41
+ return {
42
+ update: updater
43
+ }
44
+ }
45
+
46
+
47
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { MotionConfigContextObject } from "../../context/MotionConfigContext.js";
6
+ export type MotionConfigProps = Partial<MotionConfigContextObject>;
7
+ /**
8
+ * `MotionConfig` is used to set configuration options for all children `motion` components.
9
+ *
10
+ * ```jsx
11
+ * import { MotionDiv, MotionConfig } from "svelte-motion"
12
+ *
13
+ * <MotionConfig transition={{ type: "spring" }}>
14
+ * <MotionDiv animate={{ x: 100 }} />
15
+ * </MotionConfig>
16
+ * ```
17
+ *
18
+ * @public
19
+ */
20
+ export {default as MotionConfig} from './MotionConfig.svelte';
@@ -0,0 +1,8 @@
1
+ <script lang="ts">
2
+ import Motion from "../motion/MotionSSR.svelte";
3
+ export let div = {};
4
+ </script>
5
+
6
+ <Motion {...$$restProps} let:motion={m} let:props>
7
+ <div {...props} {...div} use:m><slot /></div>
8
+ </Motion>
@@ -0,0 +1,21 @@
1
+ export const getDomContext = (name: string, el: any) => {
2
+ if (!el || !window){
3
+ return undefined;
4
+ }
5
+ let par = el;
6
+ while(par = par.parentNode){
7
+ if (par.motionDomContext && par.motionDomContext.has(name)){
8
+ return par.motionDomContext.get(name)
9
+ }
10
+ }
11
+ return undefined;
12
+ }
13
+
14
+ export const setDomContext = (name: string, el: any, value: any) => {
15
+ if (el && window){
16
+ if (!el.motionDomContext){
17
+ el.motionDomContext = new Map();
18
+ }
19
+ el.motionDomContext.set(name,value);
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Writable } from 'svelte/store'
6
+
7
+ import { writable } from "svelte/store";
8
+ import { getDomContext } from "./DOMcontext";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const LayoutGroupContext = (c?: any): Writable<string | null> => getDomContext("LayoutGroup",c)||writable(null);
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ based on framer-motion@4.1.17,
4
+ Copyright (c) 2018 Framer B.V.
5
+ */
6
+ import type { CreateVisualElement } from "../render/types";
7
+ export interface LazyContextProps {
8
+ renderer?: CreateVisualElement<any>;
9
+ strict: boolean;
10
+ }
11
+
12
+ import { writable, type Writable } from "svelte/store";
13
+ import { getDomContext } from "./DOMcontext";
14
+
15
+
16
+ const LazyContext = (c?: any): Writable<LazyContextProps> => getDomContext("Lazy",c) || writable({ strict: false });
17
+
18
+ export { LazyContext };
@@ -0,0 +1,48 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Writable } from "svelte/store";
6
+ import type { Transition } from "../types";
7
+ import type { TransformPoint2D } from "../types/geometry";
8
+ /**
9
+ * @public
10
+ */
11
+ export interface MotionConfigContextObject {
12
+ /**
13
+ * @internal
14
+ */
15
+ transformPagePoint: TransformPoint2D;
16
+ /**
17
+ * Determines whether this is a static context ie the Framer canvas. If so,
18
+ * it'll disable all dynamic functionality.
19
+ *
20
+ * @internal
21
+ */
22
+ isStatic: boolean;
23
+ /**
24
+ * Defines a new default transition for the entire tree.
25
+ *
26
+ * @public
27
+ */
28
+ transition?: Transition;
29
+ }
30
+ /**
31
+ * @public
32
+ */
33
+ // export declare const MotionConfigContext: () => Writable<MotionConfigContextObject>
34
+
35
+
36
+ import { writable } from "svelte/store";
37
+ import { getDomContext } from "./DOMcontext";
38
+
39
+
40
+ /**
41
+ * @public
42
+ */
43
+ var MotionConfigContext = (c?: any): Writable<MotionConfigContextObject> => getDomContext("MotionConfig",c)||writable({
44
+ transformPagePoint: function (p) { return p; },
45
+ isStatic: false,
46
+ });
47
+
48
+ export { MotionConfigContext };
@@ -0,0 +1,27 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts" module>
5
+ import { getContext } from "svelte";
6
+ import { writable, type Writable } from "svelte/store";
7
+ import type { VisualElement } from "../../render/types";
8
+ import { getDomContext } from "../DOMcontext";
9
+ import type { MotionContextProps } from "./index.js";
10
+ export const MotionContext = (c?: any): Writable<MotionContextProps> =>
11
+ getDomContext("Motion", c) || writable({});
12
+
13
+ export const useVisualElementContext = (c?: any) => {
14
+ return (getContext(MotionContext) || MotionContext(c)) as
15
+ | VisualElement<any, any>
16
+ | undefined;
17
+ };
18
+ </script>
19
+
20
+ <script lang="ts">
21
+ export let isCustom;
22
+ const motionContext =
23
+ getContext<Writable<MotionContextProps>>(MotionContext) ||
24
+ MotionContext(isCustom);
25
+ </script>
26
+
27
+ <slot parent={$motionContext.visualElement} />
@@ -0,0 +1,22 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts">
5
+ import { onDestroy, setContext } from "svelte";
6
+ import { writable } from "svelte/store";
7
+ import { setDomContext } from "../DOMcontext.js";
8
+ import { MotionContext } from "./index.js";
9
+
10
+ export let value, isCustom;
11
+ let store = writable(value);
12
+ $: store.set(value);
13
+ setContext(MotionContext, store);
14
+ setDomContext("Motion", isCustom, store);
15
+
16
+ // Since useMotionRef is not called on destroy, the visual element is unmounted here
17
+ onDestroy(() => {
18
+ value?.visualElement?.unmount();
19
+ });
20
+ </script>
21
+
22
+ <slot />
@@ -0,0 +1,34 @@
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 { get, type Writable } from 'svelte/store';
7
+ import { MotionContext, type MotionContextProps } from './index.js';
8
+ import { getCurrentTreeVariants } from './utils.js';
9
+
10
+ export let props: any,
11
+ isStatic: any,
12
+ isCustom: any = undefined;
13
+
14
+ let mc: Writable<MotionContextProps> = getContext(MotionContext)||MotionContext(isCustom);
15
+ let {initial, animate} = getCurrentTreeVariants(props, get(mc));
16
+ $: ({initial,animate} = getCurrentTreeVariants(props, $mc));
17
+
18
+ const variantLabelsAsDependency = (prop) => {
19
+ return Array.isArray(prop) ? prop.join(" ") : prop;
20
+ }
21
+
22
+ const memo = () => { return (
23
+ { initial: initial, animate: animate }
24
+ );
25
+ }
26
+ /**
27
+ * Only break memoisation in static mode
28
+ */
29
+ let value = memo();
30
+ $: if (isStatic){
31
+ value = memo(variantLabelsAsDependency(initial),variantLabelsAsDependency(animate))
32
+ }
33
+ </script>
34
+ <slot {value}/>
@@ -0,0 +1 @@
1
+ export { default as UseCreateMotionContext } from './UseCreateMotionContext.svelte';
@@ -0,0 +1,14 @@
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
+ export interface MotionContextProps {
7
+ visualElement?: VisualElement;
8
+ initial?: false | string | string[];
9
+ animate?: string | string[];
10
+ }
11
+
12
+
13
+ export { MotionContext, useVisualElementContext, default as UseVisualElementContext } from "./MotionContext.svelte";
14
+
@@ -0,0 +1,29 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { MotionContextProps } from ".";
6
+ import type { MotionProps } from "../../motion/types";
7
+
8
+
9
+ /**
10
+ based on framer-motion@4.0.3,
11
+ Copyright (c) 2018 Framer B.V.
12
+ */
13
+
14
+ import { checkIfControllingVariants, isVariantLabel } from '../../render/utils/variants.js';
15
+
16
+ function getCurrentTreeVariants(props: MotionProps, context: MotionContextProps) {
17
+ if (checkIfControllingVariants(props)) {
18
+ var initial = props.initial, animate = props.animate;
19
+ return {
20
+ initial: initial === false || isVariantLabel(initial)
21
+ ? initial
22
+ : undefined,
23
+ animate: isVariantLabel(animate) ? animate : undefined,
24
+ };
25
+ }
26
+ return props.inherit !== false ? (context||{}) : {};
27
+ }
28
+
29
+ export { getCurrentTreeVariants };
@@ -0,0 +1,26 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { VariantLabels } from "../motion/types";
6
+ import type { Writable } from 'svelte/store'
7
+ /**
8
+ * @public
9
+ */
10
+ export interface PresenceContextProps {
11
+ id: number;
12
+ isPresent: boolean;
13
+ register: (id: number) => () => void;
14
+ onExitComplete?: (id: number) => void;
15
+ initial?: false | VariantLabels;
16
+ custom?: any;
17
+ }
18
+
19
+ import { writable } from "svelte/store";
20
+ import { getDomContext } from "./DOMcontext";
21
+
22
+
23
+ /**
24
+ * @public
25
+ */
26
+ export const PresenceContext = (c?: any): Writable<PresenceContextProps | null> => getDomContext("Presence",c)||writable(null);
@@ -0,0 +1,27 @@
1
+ <script module lang="ts">
2
+ import type { Writable } from "svelte/store";
3
+ import { getContext, setContext } from "svelte";
4
+ import { writable } from "svelte/store";
5
+ import { getDomContext, setDomContext } from "./DOMcontext.js";
6
+ export const ScaleCorrectionContext = (isCustom?: any) =>
7
+ getDomContext("ScaleCorrection", isCustom) || writable([]);
8
+ export const ScaleCorrectionParentContext = () => writable([] as unknown[]);
9
+
10
+ export const provideScaleCorrection = (isCustom: any) => {
11
+ const fromParent =
12
+ getContext(ScaleCorrectionContext) || ScaleCorrectionContext(isCustom);
13
+
14
+ const ctx = ScaleCorrectionContext();
15
+ setContext(ScaleCorrectionContext, ctx);
16
+ setDomContext("ScaleCorrection", isCustom, ctx);
17
+
18
+ setContext(ScaleCorrectionParentContext, fromParent);
19
+ };
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ export let isCustom;
24
+ provideScaleCorrection(isCustom);
25
+ </script>
26
+
27
+ <slot />
@@ -0,0 +1,29 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { Writable } from 'svelte/store'
6
+ import type { SharedLayoutSyncMethods, SyncLayoutBatcher } from "../components/AnimateSharedLayout/types";
7
+
8
+
9
+ /**
10
+ based on framer-motion@4.0.3,
11
+ Copyright (c) 2018 Framer B.V.
12
+ */
13
+
14
+ import { writable } from 'svelte/store';
15
+ import { createBatcher } from '../components/AnimateSharedLayout/utils/batcher.js';
16
+ import { getDomContext } from './DOMcontext.js';
17
+
18
+ var SharedLayoutContext = (custom?: any): Writable<SyncLayoutBatcher | SharedLayoutSyncMethods> => getDomContext("SharedLayout",custom)||writable(createBatcher());
19
+
20
+ /**
21
+ * @internal
22
+ */
23
+ var FramerTreeLayoutContext = ()=> writable(createBatcher());
24
+
25
+ function isSharedLayout(context: SyncLayoutBatcher | SharedLayoutSyncMethods): context is SharedLayoutSyncMethods {
26
+ return !!context.forceUpdate;
27
+ }
28
+
29
+ export { FramerTreeLayoutContext, SharedLayoutContext, isSharedLayout };
@@ -0,0 +1,67 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts" module>
5
+ export function addDomEvent(
6
+ target: EventTarget,
7
+ eventName: string,
8
+ handler: EventListener,
9
+ options?: AddEventListenerOptions
10
+ ) {
11
+ target.addEventListener(eventName, handler, options);
12
+ return function () {
13
+ return target.removeEventListener(eventName, handler, options);
14
+ };
15
+ }
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { onDestroy } from "svelte";
20
+ import type { UseDomEventProps } from "./use-dom-event.js";
21
+
22
+ type $$Props = UseDomEventProps;
23
+
24
+ /**
25
+ * Attaches an event listener directly to the provided DOM element.
26
+ *
27
+ * Bypassing React's event system can be desirable, for instance when attaching non-passive
28
+ * event handlers.
29
+ *
30
+ * ```jsx
31
+ * const ref = useRef(null)
32
+ *
33
+ * useDomEvent(ref, 'wheel', onWheel, { passive: false })
34
+ *
35
+ * return <div ref={ref} />
36
+ * ```
37
+ *
38
+ * @param ref - React.RefObject that's been provided to the element you want to bind the listener to.
39
+ * @param eventName - Name of the event you want listen for.
40
+ * @param handler - Function to fire when receiving the event.
41
+ * @param options - Options to pass to `Event.addEventListener`.
42
+ *
43
+ * @public
44
+ */
45
+ export let ref: $$Props["ref"],
46
+ eventName: $$Props["eventName"],
47
+ handler: $$Props["handler"] = undefined,
48
+ options: $$Props["options"] = undefined;
49
+ let cleanup = () => {};
50
+ const effect = () => {
51
+ cleanup();
52
+ if (!ref) {
53
+ return () => {};
54
+ }
55
+ const element = ref.current;
56
+
57
+ if (handler && element) {
58
+ return addDomEvent(element, eventName, handler, options);
59
+ }
60
+ return () => {};
61
+ };
62
+
63
+ $: cleanup = effect(ref, eventName, handler, options);
64
+ onDestroy(cleanup);
65
+ </script>
66
+
67
+ <slot />
@@ -0,0 +1,76 @@
1
+ <!-- based on framer-motion@4.0.3,
2
+ Copyright (c) 2018 Framer B.V. -->
3
+
4
+ <script lang="ts" module>
5
+ import type { EventListenerWithPointInfo } from "./event-info.js";
6
+ import { UseDomEvent } from "./use-dom-event.js";
7
+ import {
8
+ supportsMouseEvents,
9
+ supportsPointerEvents,
10
+ supportsTouchEvents,
11
+ } from "./utils.js";
12
+
13
+ const mouseEventNames = {
14
+ pointerdown: "mousedown",
15
+ pointermove: "mousemove",
16
+ pointerup: "mouseup",
17
+ pointercancel: "mousecancel",
18
+ pointerover: "mouseover",
19
+ pointerout: "mouseout",
20
+ pointerenter: "mouseenter",
21
+ pointerleave: "mouseleave",
22
+ };
23
+
24
+ const touchEventNames = {
25
+ pointerdown: "touchstart",
26
+ pointermove: "touchmove",
27
+ pointerup: "touchend",
28
+ pointercancel: "touchcancel",
29
+ };
30
+ function getPointerEventName(name: string) {
31
+ if (supportsPointerEvents()) {
32
+ return name;
33
+ } else if (supportsTouchEvents()) {
34
+ return (touchEventNames as any)[name];
35
+ } else if (supportsMouseEvents()) {
36
+ return (mouseEventNames as any)[name];
37
+ }
38
+
39
+ return name;
40
+ }
41
+ export function addPointerEvent(
42
+ target: EventTarget,
43
+ eventName: string,
44
+ handler: EventListenerWithPointInfo,
45
+ options?: AddEventListenerOptions
46
+ ) {
47
+ return addDomEvent(
48
+ target,
49
+ getPointerEventName(eventName),
50
+ wrapHandler(handler, eventName === "pointerdown"),
51
+ options
52
+ );
53
+ }
54
+ </script>
55
+
56
+ <script lang="ts">
57
+ import { wrapHandler } from "./event-info.js";
58
+ import { addDomEvent } from "./use-dom-event.js";
59
+ import type { UsePointerEventProps } from "./use-pointer-event.js";
60
+
61
+ type $$Props = UsePointerEventProps;
62
+
63
+ export let ref: $$Props["ref"],
64
+ eventName: $$Props["eventName"],
65
+ handler: $$Props["handler"] = undefined,
66
+ options: $$Props["options"] = undefined;
67
+ </script>
68
+
69
+ <UseDomEvent
70
+ {ref}
71
+ eventName={getPointerEventName(eventName)}
72
+ handler={handler && wrapHandler(handler, eventName === "pointerdown")}
73
+ {options}
74
+ >
75
+ <slot />
76
+ </UseDomEvent>
@@ -0,0 +1,69 @@
1
+ /**
2
+ based on framer-motion@4.1.17,
3
+ Copyright (c) 2018 Framer B.V.
4
+ */
5
+ import type { EventInfo } from "./types";
6
+ export type EventListenerWithPointInfo = (e: PointerEvent, info: EventInfo) => void;
7
+
8
+
9
+ /**
10
+ based on framer-motion@4.0.3,
11
+ Copyright (c) 2018 Framer B.V.
12
+ */
13
+
14
+ import { isTouchEvent } from '../gestures/utils/event-type.js';
15
+
16
+ /**
17
+ * Filters out events not attached to the primary pointer (currently left mouse button)
18
+ * @param eventHandler
19
+ */
20
+ function filterPrimaryPointer(eventHandler) {
21
+ return function (event) {
22
+ var isMouseEvent = event instanceof MouseEvent;
23
+ var isPrimaryPointer = !isMouseEvent ||
24
+ (isMouseEvent && event.button === 0);
25
+ if (isPrimaryPointer) {
26
+ eventHandler(event);
27
+ }
28
+ };
29
+ }
30
+ var defaultPagePoint = { pageX: 0, pageY: 0 };
31
+ function pointFromTouch(e: TouchEvent, pointType?: "page" | "client") {
32
+ if (pointType === void 0) { pointType = "page"; }
33
+ var primaryTouch = e.touches[0] || e.changedTouches[0];
34
+ var point = primaryTouch as any || defaultPagePoint as any;
35
+ return {
36
+ x: point[pointType + "X"],
37
+ y: point[pointType + "Y"],
38
+ };
39
+ }
40
+ function pointFromMouse(point: any, pointType?: "page" | "client") {
41
+ if (pointType === void 0) { pointType = "page"; }
42
+ return {
43
+ x: point[pointType + "X"],
44
+ y: point[pointType + "Y"],
45
+ };
46
+ }
47
+ function extractEventInfo(event: MouseEvent | TouchEvent | PointerEvent, pointType?: "page" | "client"): EventInfo {
48
+ if (pointType === void 0) { pointType = "page"; }
49
+ return {
50
+ point: isTouchEvent(event)
51
+ ? pointFromTouch(event, pointType)
52
+ : pointFromMouse(event, pointType),
53
+ };
54
+ }
55
+ function getViewportPointFromEvent(event: MouseEvent | TouchEvent | PointerEvent) {
56
+ return extractEventInfo(event, "client");
57
+ }
58
+ var wrapHandler = function (handler: EventListenerWithPointInfo, shouldFilterPrimaryPointer?: boolean): EventListener {
59
+ if (shouldFilterPrimaryPointer === void 0) { shouldFilterPrimaryPointer = false; }
60
+ var listener = function (event) {
61
+ return handler(event, extractEventInfo(event));
62
+ };
63
+ return shouldFilterPrimaryPointer
64
+ ? filterPrimaryPointer(listener)
65
+ : listener;
66
+ };
67
+
68
+ export { extractEventInfo, getViewportPointFromEvent, wrapHandler };
69
+