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.
- package/LICENSE.md +21 -0
- package/README.md +39 -0
- package/package.json +64 -0
- package/src/animation/UseAnimatedState.svelte +86 -0
- package/src/animation/UseAnimation.svelte +61 -0
- package/src/animation/animate.ts +78 -0
- package/src/animation/animation-controls.ts +101 -0
- package/src/animation/types.ts +83 -0
- package/src/animation/use-animated-state.ts +1 -0
- package/src/animation/use-animation.ts +74 -0
- package/src/animation/utils/default-transitions.ts +70 -0
- package/src/animation/utils/easing.ts +55 -0
- package/src/animation/utils/is-animatable.ts +42 -0
- package/src/animation/utils/is-animation-controls.ts +17 -0
- package/src/animation/utils/is-keyframes-target.ts +17 -0
- package/src/animation/utils/transitions.ts +218 -0
- package/src/animation/utils/variant-resolvers.ts +15 -0
- package/src/components/AnimatePresence/AnimatePresence.svelte +180 -0
- package/src/components/AnimatePresence/PresenceChild/PresenceChild.svelte +78 -0
- package/src/components/AnimatePresence/PresenceChild/index.ts +7 -0
- package/src/components/AnimatePresence/PresenceChild/types.ts +10 -0
- package/src/components/AnimatePresence/index.ts +46 -0
- package/src/components/AnimatePresence/types.ts +79 -0
- package/src/components/AnimatePresence/use-presence.ts +90 -0
- package/src/components/AnimateSharedLayout/AnimateSharedLayout.svelte +239 -0
- package/src/components/AnimateSharedLayout/index.ts +11 -0
- package/src/components/AnimateSharedLayout/types.ts +111 -0
- package/src/components/AnimateSharedLayout/utils/batcher.ts +96 -0
- package/src/components/AnimateSharedLayout/utils/crossfader.ts +260 -0
- package/src/components/AnimateSharedLayout/utils/rotate.ts +48 -0
- package/src/components/AnimateSharedLayout/utils/stack.ts +160 -0
- package/src/components/LazyMotion/LazyMotion.svelte +82 -0
- package/src/components/LazyMotion/index.ts +42 -0
- package/src/components/LazyMotion/types.ts +58 -0
- package/src/components/MotionConfig/MotionConfig.svelte +56 -0
- package/src/components/MotionConfig/MotionConfigScaleCorrection.ts +47 -0
- package/src/components/MotionConfig/index.ts +20 -0
- package/src/components/MotionDiv.svelte +8 -0
- package/src/context/DOMcontext.ts +21 -0
- package/src/context/LayoutGroupContext.ts +13 -0
- package/src/context/LazyContext.ts +18 -0
- package/src/context/MotionConfigContext.ts +48 -0
- package/src/context/MotionContext/MotionContext.svelte +27 -0
- package/src/context/MotionContext/MotionContextProvider.svelte +22 -0
- package/src/context/MotionContext/UseCreateMotionContext.svelte +34 -0
- package/src/context/MotionContext/create.ts +1 -0
- package/src/context/MotionContext/index.ts +14 -0
- package/src/context/MotionContext/utils.ts +29 -0
- package/src/context/PresenceContext.ts +26 -0
- package/src/context/ScaleCorrectionProvider.svelte +27 -0
- package/src/context/SharedLayoutContext.ts +29 -0
- package/src/events/UseDomEvent.svelte +67 -0
- package/src/events/UsePointerEvent.svelte +76 -0
- package/src/events/event-info.ts +69 -0
- package/src/events/types.ts +15 -0
- package/src/events/use-dom-event.ts +48 -0
- package/src/events/use-pointer-event.ts +29 -0
- package/src/events/utils.ts +25 -0
- package/src/gestures/PanSession.ts +298 -0
- package/src/gestures/UseFocusGesture.svelte +31 -0
- package/src/gestures/UseGestures.svelte +17 -0
- package/src/gestures/UseHoverGesture.svelte +40 -0
- package/src/gestures/UsePanGesture.svelte +58 -0
- package/src/gestures/UseTapGesture.svelte +77 -0
- package/src/gestures/drag/UseDrag.svelte +55 -0
- package/src/gestures/drag/UseDragControls.svelte +145 -0
- package/src/gestures/drag/VisualElementDragControls.ts +632 -0
- package/src/gestures/drag/types.ts +307 -0
- package/src/gestures/drag/use-drag-controls.ts +148 -0
- package/src/gestures/drag/use-drag.ts +15 -0
- package/src/gestures/drag/utils/constraints.ts +157 -0
- package/src/gestures/drag/utils/lock.ts +69 -0
- package/src/gestures/types.ts +257 -0
- package/src/gestures/use-focus-gesture.ts +16 -0
- package/src/gestures/use-gestures.ts +2 -0
- package/src/gestures/use-hover-gesture.ts +10 -0
- package/src/gestures/use-pan-gesture.ts +22 -0
- package/src/gestures/use-tap-gesture.ts +14 -0
- package/src/gestures/utils/event-type.ts +24 -0
- package/src/gestures/utils/is-node-or-child.ts +31 -0
- package/src/index.ts +104 -0
- package/src/motion/Motion.svelte +246 -0
- package/src/motion/MotionSSR.svelte +244 -0
- package/src/motion/features/AnimationState.svelte +29 -0
- package/src/motion/features/Exit.svelte +32 -0
- package/src/motion/features/UseFeatures.svelte +39 -0
- package/src/motion/features/animations.ts +22 -0
- package/src/motion/features/definitions.ts +49 -0
- package/src/motion/features/drag.ts +24 -0
- package/src/motion/features/gestures.ts +24 -0
- package/src/motion/features/layout/Animate.svelte +314 -0
- package/src/motion/features/layout/Animate.ts +9 -0
- package/src/motion/features/layout/AnimateLayoutContextProvider.svelte +14 -0
- package/src/motion/features/layout/Measure.svelte +98 -0
- package/src/motion/features/layout/Measure.ts +9 -0
- package/src/motion/features/layout/MeasureContextProvider.svelte +32 -0
- package/src/motion/features/layout/index.ts +20 -0
- package/src/motion/features/layout/types.ts +71 -0
- package/src/motion/features/layout/utils.ts +40 -0
- package/src/motion/features/types.ts +53 -0
- package/src/motion/features/use-features.ts +16 -0
- package/src/motion/index.ts +64 -0
- package/src/motion/types.ts +278 -0
- package/src/motion/utils/UseLayoutId.svelte +18 -0
- package/src/motion/utils/UseVisualElement.svelte +104 -0
- package/src/motion/utils/UseVisualState.svelte +137 -0
- package/src/motion/utils/is-forced-motion-value.ts +23 -0
- package/src/motion/utils/make-renderless-component.ts +17 -0
- package/src/motion/utils/should-inhert-variant.ts +6 -0
- package/src/motion/utils/use-motion-ref.ts +41 -0
- package/src/motion/utils/use-visual-element.ts +13 -0
- package/src/motion/utils/use-visual-state.ts +24 -0
- package/src/motion/utils/valid-prop.ts +80 -0
- package/src/render/dom/M.svelte +16 -0
- package/src/render/dom/UseRender.svelte +37 -0
- package/src/render/dom/create-motion-class.ts +12 -0
- package/src/render/dom/create-visual-element.ts +22 -0
- package/src/render/dom/featureBundle.ts +22 -0
- package/src/render/dom/motion-minimal.ts +22 -0
- package/src/render/dom/motion-proxy.ts +107 -0
- package/src/render/dom/motion.ts +62 -0
- package/src/render/dom/projection/convert-to-relative.ts +40 -0
- package/src/render/dom/projection/default-scale-correctors.ts +138 -0
- package/src/render/dom/projection/measure.ts +28 -0
- package/src/render/dom/projection/relative-set.ts +27 -0
- package/src/render/dom/projection/scale-correction.ts +22 -0
- package/src/render/dom/projection/types.ts +13 -0
- package/src/render/dom/projection/utils.ts +69 -0
- package/src/render/dom/svg-visual-element.ts +114 -0
- package/src/render/dom/types.ts +32 -0
- package/src/render/dom/use-render.ts +11 -0
- package/src/render/dom/utils/UseInitialMotionProps.svelte +26 -0
- package/src/render/dom/utils/batch-layout.ts +77 -0
- package/src/render/dom/utils/camel-to-dash.ts +20 -0
- package/src/render/dom/utils/create-config.ts +33 -0
- package/src/render/dom/utils/css-variables-conversion.ts +121 -0
- package/src/render/dom/utils/filter-props.ts +55 -0
- package/src/render/dom/utils/is-css-variable.ts +18 -0
- package/src/render/dom/utils/is-svg-component.ts +41 -0
- package/src/render/dom/utils/parse-dom-variant.ts +26 -0
- package/src/render/dom/utils/unit-conversion.ts +258 -0
- package/src/render/dom/utils/use-html-props.ts +2 -0
- package/src/render/dom/utils/use-svg-props.ts +1 -0
- package/src/render/dom/value-types/animatable-none.ts +24 -0
- package/src/render/dom/value-types/defaults.ts +30 -0
- package/src/render/dom/value-types/dimensions.ts +27 -0
- package/src/render/dom/value-types/find.ts +31 -0
- package/src/render/dom/value-types/get-as-type.ts +21 -0
- package/src/render/dom/value-types/number.ts +83 -0
- package/src/render/dom/value-types/test.ts +17 -0
- package/src/render/dom/value-types/type-auto.ts +21 -0
- package/src/render/dom/value-types/type-int.ts +23 -0
- package/src/render/dom/value-types/types.ts +8 -0
- package/src/render/html/UseHTMLProps.svelte +33 -0
- package/src/render/html/UseInitialMotionValues.svelte +27 -0
- package/src/render/html/UseStyle.svelte +47 -0
- package/src/render/html/config-motion.ts +23 -0
- package/src/render/html/supported-elements.ts +10 -0
- package/src/render/html/types.ts +64 -0
- package/src/render/html/use-props.ts +14 -0
- package/src/render/html/utils/build-projection-transform.ts +53 -0
- package/src/render/html/utils/build-styles.ts +121 -0
- package/src/render/html/utils/build-transform.ts +79 -0
- package/src/render/html/utils/create-render-state.ts +18 -0
- package/src/render/html/utils/render.ts +22 -0
- package/src/render/html/utils/scrape-motion-values.ts +26 -0
- package/src/render/html/utils/transform.ts +51 -0
- package/src/render/html/visual-element.ts +129 -0
- package/src/render/index.ts +703 -0
- package/src/render/svg/UseSVGProps.svelte +34 -0
- package/src/render/svg/config-motion.ts +51 -0
- package/src/render/svg/lowercase-elements.ts +35 -0
- package/src/render/svg/supported-elements.ts +10 -0
- package/src/render/svg/types.ts +51 -0
- package/src/render/svg/use-props.ts +14 -0
- package/src/render/svg/utils/build-attrs.ts +58 -0
- package/src/render/svg/utils/camel-case-attrs.ts +27 -0
- package/src/render/svg/utils/create-render-state.ts +17 -0
- package/src/render/svg/utils/path.ts +49 -0
- package/src/render/svg/utils/render.ts +22 -0
- package/src/render/svg/utils/scrape-motion-values.ts +26 -0
- package/src/render/svg/utils/transform-origin.ts +30 -0
- package/src/render/svg/visual-element.ts +44 -0
- package/src/render/types.ts +148 -0
- package/src/render/utils/animation-state.ts +375 -0
- package/src/render/utils/animation.ts +167 -0
- package/src/render/utils/compare-by-depth.ts +18 -0
- package/src/render/utils/flat-tree.ts +35 -0
- package/src/render/utils/is-draggable.ts +17 -0
- package/src/render/utils/lifecycles.ts +172 -0
- package/src/render/utils/motion-values.ts +59 -0
- package/src/render/utils/projection.ts +38 -0
- package/src/render/utils/setters.ts +910 -0
- package/src/render/utils/state.ts +113 -0
- package/src/render/utils/types.ts +12 -0
- package/src/render/utils/variants.ts +76 -0
- package/src/types/geometry.ts +91 -0
- package/src/types.ts +1088 -0
- package/src/utils/UseUnmountEffect.svelte +11 -0
- package/src/utils/array.ts +18 -0
- package/src/utils/each-axis.ts +15 -0
- package/src/utils/errors.ts +22 -0
- package/src/utils/fix-process-env.ts +22 -0
- package/src/utils/geometry/delta-apply.ts +162 -0
- package/src/utils/geometry/delta-calc.ts +89 -0
- package/src/utils/geometry/index.ts +83 -0
- package/src/utils/is-browser.ts +12 -0
- package/src/utils/is-numerical-string.ts +15 -0
- package/src/utils/is-ref-object.ts +16 -0
- package/src/utils/noop.ts +15 -0
- package/src/utils/resolve-value.ts +23 -0
- package/src/utils/shallow-compare.ts +23 -0
- package/src/utils/subscription-manager.ts +49 -0
- package/src/utils/time-conversion.ts +18 -0
- package/src/utils/transform.ts +120 -0
- package/src/utils/use-constant.ts +23 -0
- package/src/utils/use-cycle.ts +78 -0
- package/src/utils/use-force-update.ts +7 -0
- package/src/utils/use-isomorphic-effect.ts +8 -0
- package/src/utils/use-reduced-motion.ts +70 -0
- package/src/utils/use-unmount-effect.ts +8 -0
- package/src/value/index.ts +409 -0
- package/src/value/scroll/use-element-scroll.ts +73 -0
- package/src/value/scroll/use-viewport-scroll.ts +81 -0
- package/src/value/scroll/utils.ts +76 -0
- package/src/value/use-combine-values.ts +53 -0
- package/src/value/use-motion-template.ts +57 -0
- package/src/value/use-motion-value.ts +27 -0
- package/src/value/use-spring.ts +84 -0
- package/src/value/use-transform.ts +216 -0
- package/src/value/use-velocity.ts +44 -0
- package/src/value/utils/is-motion-value.ts +15 -0
- package/src/value/utils/resolve-motion-value.ts +29 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionProps } from "../..";
|
|
6
|
+
export type isForcedMotionValue = (key: string, { layout, layoutId }: MotionProps) => boolean;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Load features via renderless components based on the provided MotionProps.
|
|
11
|
+
* TODO: Look into porting this to a component-less appraoch.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export { default as UseFeatures } from './UseFeatures.svelte';
|
|
16
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { CreateVisualElement } from "../render/types";
|
|
6
|
+
import type { FeatureBundle, RenderComponent } from "./features/types";
|
|
7
|
+
import type { UseVisualState } from "./utils/use-visual-state";
|
|
8
|
+
export type { MotionProps } from "./types";
|
|
9
|
+
|
|
10
|
+
export interface MotionComponentConfig<Instance, RenderState> {
|
|
11
|
+
preloadedFeatures?: FeatureBundle;
|
|
12
|
+
createVisualElement?: CreateVisualElement<Instance>;
|
|
13
|
+
useRender: RenderComponent<Instance, RenderState>;
|
|
14
|
+
useVisualState: UseVisualState<Instance, RenderState>;
|
|
15
|
+
Component: string | React.ComponentType;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
based on framer-motion@4.0.3,
|
|
21
|
+
Copyright (c) 2018 Framer B.V.
|
|
22
|
+
*/
|
|
23
|
+
import Motion from './Motion.svelte';
|
|
24
|
+
import { loadFeatures } from "./features/definitions";
|
|
25
|
+
import type { MotionProps } from "./types";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a `motion` component.
|
|
29
|
+
*
|
|
30
|
+
* This function accepts a Component argument, which can be either a string (ie "div"
|
|
31
|
+
* for `MotionDiv`), or an actual React component.
|
|
32
|
+
*
|
|
33
|
+
* Alongside this is a config option which provides a way of rendering the provided
|
|
34
|
+
* component "offline", or outside the React render cycle.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export const createMotionComponent = <Props extends {}, Instance, RenderState>(
|
|
39
|
+
{
|
|
40
|
+
preloadedFeatures,
|
|
41
|
+
createVisualElement,
|
|
42
|
+
useRender: forwardMotionProps,
|
|
43
|
+
useVisualState: visualStateConfig,
|
|
44
|
+
Component,
|
|
45
|
+
|
|
46
|
+
}: MotionComponentConfig<Instance, RenderState>
|
|
47
|
+
): React.ForwardRefExoticComponent<React.PropsWithoutRef<Props & MotionProps> & React.RefAttributes<Instance>> => {
|
|
48
|
+
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
49
|
+
|
|
50
|
+
return class MotionComponent extends Motion {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
const props = options.props;
|
|
53
|
+
options.props = {
|
|
54
|
+
props: props,
|
|
55
|
+
defaultFeatures: preloadedFeatures,
|
|
56
|
+
createVisualElement: createVisualElement,
|
|
57
|
+
forwardMotionProps: forwardMotionProps,
|
|
58
|
+
Component: Component,
|
|
59
|
+
visualStateConfig
|
|
60
|
+
}
|
|
61
|
+
super(options)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { CSSProperties } from "react";
|
|
6
|
+
import type { AnimationControls } from "../animation/types";
|
|
7
|
+
import type { DraggableProps } from "../gestures/drag/types";
|
|
8
|
+
import type { FocusHandlers, HoverHandlers, PanHandlers, TapHandlers } from "../gestures/types";
|
|
9
|
+
import type { VisualElementLifecycles } from "../render/utils/lifecycles";
|
|
10
|
+
import type { MakeCustomValueType, Omit, Target, TargetAndTransition, Transition, Variants } from "../types";
|
|
11
|
+
import { MotionValue } from "../value";
|
|
12
|
+
import type { LayoutProps } from "./features/layout/types";
|
|
13
|
+
|
|
14
|
+
export type MotionStyleProp = string | number | MotionValue;
|
|
15
|
+
/**
|
|
16
|
+
* Either a string, or array of strings, that reference variants defined via the `variants` prop.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export type VariantLabels = string | string[];
|
|
20
|
+
export interface TransformProperties {
|
|
21
|
+
x?: string | number;
|
|
22
|
+
y?: string | number;
|
|
23
|
+
z?: string | number;
|
|
24
|
+
translateX?: string | number;
|
|
25
|
+
translateY?: string | number;
|
|
26
|
+
translateZ?: string | number;
|
|
27
|
+
rotate?: string | number;
|
|
28
|
+
rotateX?: string | number;
|
|
29
|
+
rotateY?: string | number;
|
|
30
|
+
rotateZ?: string | number;
|
|
31
|
+
scale?: string | number;
|
|
32
|
+
scaleX?: string | number;
|
|
33
|
+
scaleY?: string | number;
|
|
34
|
+
scaleZ?: string | number;
|
|
35
|
+
skew?: string | number;
|
|
36
|
+
skewX?: string | number;
|
|
37
|
+
skewY?: string | number;
|
|
38
|
+
originX?: string | number;
|
|
39
|
+
originY?: string | number;
|
|
40
|
+
originZ?: string | number;
|
|
41
|
+
perspective?: string | number;
|
|
42
|
+
transformPerspective?: string | number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export interface SVGPathProperties {
|
|
48
|
+
pathLength?: number;
|
|
49
|
+
pathOffset?: number;
|
|
50
|
+
pathSpacing?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface CustomStyles {
|
|
53
|
+
/**
|
|
54
|
+
* Framer Library custom prop types. These are not actually supported in Motion - preferably
|
|
55
|
+
* we'd have a way of external consumers injecting supported styles into this library.
|
|
56
|
+
*/
|
|
57
|
+
size?: string | number;
|
|
58
|
+
radius?: string | number;
|
|
59
|
+
shadow?: string;
|
|
60
|
+
image?: string;
|
|
61
|
+
}
|
|
62
|
+
export type MakeMotion<T> = MakeCustomValueType<{
|
|
63
|
+
[K in keyof T]: T[K] | MotionValue<number> | MotionValue<string> | MotionValue<any>;
|
|
64
|
+
}>;
|
|
65
|
+
export type MotionCSS = MakeMotion<Omit<CSSProperties, "rotate" | "scale" | "perspective">>;
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export type MotionTransform = MakeMotion<TransformProperties>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export type MotionStyle = MotionCSS & MotionTransform & MakeMotion<SVGPathProperties> /* & MakeCustomValueType<CustomStyles>*/;
|
|
75
|
+
export type OnUpdate = (v: Target) => void;
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export interface RelayoutInfo {
|
|
80
|
+
delta: {
|
|
81
|
+
x: number;
|
|
82
|
+
y: number;
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export type ResolveLayoutTransition = (info: RelayoutInfo) => Transition | boolean;
|
|
91
|
+
/**
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export interface AnimationProps {
|
|
95
|
+
/**
|
|
96
|
+
* Values to animate to, variant label(s), or `AnimationControls`.
|
|
97
|
+
*
|
|
98
|
+
* @motion
|
|
99
|
+
*
|
|
100
|
+
* ```jsx
|
|
101
|
+
* // As values
|
|
102
|
+
* <MotionDiv animate={{ opacity: 1 }} />
|
|
103
|
+
*
|
|
104
|
+
* // As variant
|
|
105
|
+
* <MotionDiv animate="visible" variants={variants} />
|
|
106
|
+
*
|
|
107
|
+
* // Multiple variants
|
|
108
|
+
* <MotionDiv animate={["visible", "active"]} variants={variants} />
|
|
109
|
+
*
|
|
110
|
+
* // AnimationControls
|
|
111
|
+
* <MotionDiv animate={animation} />
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
animate?: AnimationControls | TargetAndTransition | VariantLabels | boolean;
|
|
115
|
+
/**
|
|
116
|
+
* A target to animate to when this component is removed from the tree.
|
|
117
|
+
*
|
|
118
|
+
* This component **must** be the first animatable child of an `AnimatePresence` to enable this exit animation.
|
|
119
|
+
*
|
|
120
|
+
* This limitation exists because React doesn't allow components to defer unmounting until after
|
|
121
|
+
* an animation is complete. Once this limitation is fixed, the `AnimatePresence` component will be unnecessary.
|
|
122
|
+
*
|
|
123
|
+
* @motion
|
|
124
|
+
*
|
|
125
|
+
* ```jsx
|
|
126
|
+
* import { AnimatePresence, motion } from 'svelte-motion'
|
|
127
|
+
*
|
|
128
|
+
*
|
|
129
|
+
* <AnimatePresence show={isVisible}>
|
|
130
|
+
* <MotionDiv
|
|
131
|
+
* initial={{ opacity: 0 }}
|
|
132
|
+
* animate={{ opacity: 1 }}
|
|
133
|
+
* exit={{ opacity: 0 }}
|
|
134
|
+
* />
|
|
135
|
+
* </AnimatePresence>
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
exit?: TargetAndTransition | VariantLabels;
|
|
139
|
+
/**
|
|
140
|
+
* Variants allow you to define animation states and organise them by name. They allow
|
|
141
|
+
* you to control animations throughout a component tree by switching a single `animate` prop.
|
|
142
|
+
*
|
|
143
|
+
* Using `transition` options like `delayChildren` and `staggerChildren`, you can orchestrate
|
|
144
|
+
* when children animations play relative to their parent.
|
|
145
|
+
*
|
|
146
|
+
* @motion
|
|
147
|
+
*
|
|
148
|
+
* After passing variants to one or more `motion` component's `variants` prop, these variants
|
|
149
|
+
* can be used in place of values on the `animate`, `initial`, `whileFocus`, `whileTap` and `whileHover` props.
|
|
150
|
+
*
|
|
151
|
+
* ```jsx
|
|
152
|
+
* const variants = {
|
|
153
|
+
* active: {
|
|
154
|
+
* backgroundColor: "#f00"
|
|
155
|
+
* },
|
|
156
|
+
* inactive: {
|
|
157
|
+
* backgroundColor: "#fff",
|
|
158
|
+
* transition: { duration: 2 }
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
*
|
|
162
|
+
* <MotionDiv variants={variants} animate="active" />
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
variants?: Variants;
|
|
166
|
+
/**
|
|
167
|
+
* Default transition. If no `transition` is defined in `animate`, it will use the transition defined here.
|
|
168
|
+
*
|
|
169
|
+
* @motion
|
|
170
|
+
*
|
|
171
|
+
* ```jsx
|
|
172
|
+
* const spring = {
|
|
173
|
+
* type: "spring",
|
|
174
|
+
* damping: 10,
|
|
175
|
+
* stiffness: 100
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* <MotionDiv transition={spring} animate={{ scale: 1.2 }} />
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
transition?: Transition;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
export interface MotionAdvancedProps {
|
|
187
|
+
/**
|
|
188
|
+
* Custom data to use to resolve dynamic variants differently for each animating component.
|
|
189
|
+
*
|
|
190
|
+
* @motion
|
|
191
|
+
*
|
|
192
|
+
* ```jsx
|
|
193
|
+
* const variants = {
|
|
194
|
+
* visible: (custom) => ({
|
|
195
|
+
* opacity: 1,
|
|
196
|
+
* transition: { delay: custom * 0.2 }
|
|
197
|
+
* })
|
|
198
|
+
* }
|
|
199
|
+
*
|
|
200
|
+
* <MotionDiv custom={0} animate="visible" variants={variants} />
|
|
201
|
+
* <MotionDiv custom={1} animate="visible" variants={variants} />
|
|
202
|
+
* <MotionDiv custom={2} animate="visible" variants={variants} />
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
custom?: any;
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
* Set to `false` to prevent inheriting variant changes from its parent.
|
|
211
|
+
*/
|
|
212
|
+
inherit?: boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Props for `motion` components.
|
|
216
|
+
*
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
export interface MotionProps extends AnimationProps, VisualElementLifecycles, PanHandlers, TapHandlers, HoverHandlers, FocusHandlers, DraggableProps, LayoutProps, MotionAdvancedProps {
|
|
220
|
+
/**
|
|
221
|
+
* Properties, variant label or array of variant labels to start in.
|
|
222
|
+
*
|
|
223
|
+
* Set to `false` to initialise with the values in `animate` (disabling the mount animation)
|
|
224
|
+
*
|
|
225
|
+
* @motion
|
|
226
|
+
*
|
|
227
|
+
* ```jsx
|
|
228
|
+
* // As values
|
|
229
|
+
* <MotionDiv initial={{ opacity: 1 }} />
|
|
230
|
+
*
|
|
231
|
+
* // As variant
|
|
232
|
+
* <MotionDiv initial="visible" variants={variants} />
|
|
233
|
+
*
|
|
234
|
+
* // Multiple variants
|
|
235
|
+
* <MotionDiv initial={["visible", "active"]} variants={variants} />
|
|
236
|
+
*
|
|
237
|
+
* // As false (disable mount animation)
|
|
238
|
+
* <MotionDiv initial={false} animate={{ opacity: 0 }} />
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
initial?: boolean | Target | VariantLabels;
|
|
242
|
+
/**
|
|
243
|
+
* @motion
|
|
244
|
+
*
|
|
245
|
+
* The React DOM `style` prop, enhanced with support for `MotionValue`s and separate `transform` values.
|
|
246
|
+
*
|
|
247
|
+
* ```jsx
|
|
248
|
+
* <script>
|
|
249
|
+
* const x = useMotionValue(0)
|
|
250
|
+
* </script>
|
|
251
|
+
*
|
|
252
|
+
* <MotionDiv style={{ x, opacity: 1, scale: 0.5 }} />
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
style?: MotionStyle;
|
|
256
|
+
/**
|
|
257
|
+
* By default, Svelte Motion generates a `transform` property with a sensible transform order. `transformTemplate`
|
|
258
|
+
* can be used to create a different order, or to append/preprend the automatically generated `transform` property.
|
|
259
|
+
*
|
|
260
|
+
* @motion
|
|
261
|
+
*
|
|
262
|
+
* ```jsx
|
|
263
|
+
* <MotionDiv
|
|
264
|
+
* style={{ x: 0, rotate: 180 }}
|
|
265
|
+
* transformTemplate={
|
|
266
|
+
* ({ x, rotate }) => `rotate(${rotate}deg) translateX(${x}px)`
|
|
267
|
+
* }
|
|
268
|
+
* />
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @param transform - The latest animated transform props.
|
|
272
|
+
* @param generatedTransform - The transform string as automatically generated by Framer Motion
|
|
273
|
+
*
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
transformTemplate?(transform: TransformProperties, generatedTransform: string): string;
|
|
277
|
+
}
|
|
278
|
+
export type TransformTemplate = (transform: TransformProperties, generatedTransform: string) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script lang="ts">
|
|
5
|
+
import { getContext } from "svelte";
|
|
6
|
+
import type { Writable } from "svelte/store";
|
|
7
|
+
import { LayoutGroupContext } from "../../context/LayoutGroupContext.js";
|
|
8
|
+
export let props, isCustom;
|
|
9
|
+
$: ({ layoutId } = props);
|
|
10
|
+
const layoutGroupId: Writable<string | null> =
|
|
11
|
+
getContext(LayoutGroupContext) || LayoutGroupContext(isCustom);
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<slot
|
|
15
|
+
layoutId={$layoutGroupId && layoutId !== undefined
|
|
16
|
+
? $layoutGroupId + "-" + layoutId
|
|
17
|
+
: layoutId}
|
|
18
|
+
/>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script module lang="ts">
|
|
5
|
+
export const ssr = false;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { afterUpdate, getContext, onDestroy, tick } from "svelte";
|
|
10
|
+
import { get, type Writable } from "svelte/store";
|
|
11
|
+
import { isPresent } from "../../components/AnimatePresence/use-presence.js";
|
|
12
|
+
import { LayoutGroupContext } from "../../context/LayoutGroupContext.js";
|
|
13
|
+
import {
|
|
14
|
+
LazyContext,
|
|
15
|
+
type LazyContextProps,
|
|
16
|
+
} from "../../context/LazyContext.js";
|
|
17
|
+
import {
|
|
18
|
+
MotionConfigContext,
|
|
19
|
+
type MotionConfigContextObject,
|
|
20
|
+
} from "../../context/MotionConfigContext.js";
|
|
21
|
+
import {
|
|
22
|
+
MotionContext,
|
|
23
|
+
type MotionContextProps,
|
|
24
|
+
} from "../../context/MotionContext/index.js";
|
|
25
|
+
import {
|
|
26
|
+
PresenceContext,
|
|
27
|
+
type PresenceContextProps,
|
|
28
|
+
} from "../../context/PresenceContext.js";
|
|
29
|
+
|
|
30
|
+
export let createVisualElement = undefined,
|
|
31
|
+
props,
|
|
32
|
+
Component,
|
|
33
|
+
visualState,
|
|
34
|
+
isCustom;
|
|
35
|
+
|
|
36
|
+
const config: Writable<MotionConfigContextObject> =
|
|
37
|
+
getContext(MotionConfigContext) || MotionConfigContext(isCustom);
|
|
38
|
+
const presenceContext: Writable<PresenceContextProps> =
|
|
39
|
+
getContext(PresenceContext) || PresenceContext(isCustom);
|
|
40
|
+
const lazyContext: Writable<LazyContextProps> =
|
|
41
|
+
getContext(LazyContext) || LazyContext(isCustom);
|
|
42
|
+
const mc: Writable<MotionContextProps> =
|
|
43
|
+
getContext(MotionContext) || MotionContext(isCustom);
|
|
44
|
+
let parent = get(mc).visualElement;
|
|
45
|
+
$: parent = $mc.visualElement;
|
|
46
|
+
const layoutGroupId: Writable<string | null> =
|
|
47
|
+
getContext(LayoutGroupContext) || LayoutGroupContext(isCustom);
|
|
48
|
+
let layoutId =
|
|
49
|
+
$layoutGroupId && props.layoutId !== undefined
|
|
50
|
+
? $layoutGroupId + "-" + props.layoutId
|
|
51
|
+
: props.layoutId;
|
|
52
|
+
$: layoutId =
|
|
53
|
+
$layoutGroupId && props.layoutId !== undefined
|
|
54
|
+
? $layoutGroupId + "-" + props.layoutId
|
|
55
|
+
: props.layoutId;
|
|
56
|
+
|
|
57
|
+
let visualElementRef: any = undefined;
|
|
58
|
+
/**
|
|
59
|
+
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
60
|
+
*/
|
|
61
|
+
if (!createVisualElement) {
|
|
62
|
+
createVisualElement = $lazyContext.renderer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
$: if (!visualElementRef && createVisualElement) {
|
|
66
|
+
visualElementRef = createVisualElement(Component, {
|
|
67
|
+
visualState,
|
|
68
|
+
parent: parent,
|
|
69
|
+
props: { ...props, layoutId },
|
|
70
|
+
presenceId: $presenceContext?.id,
|
|
71
|
+
blockInitialAnimation: $presenceContext?.initial === false,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
let visualElement = visualElementRef;
|
|
75
|
+
$: visualElement = visualElementRef;
|
|
76
|
+
|
|
77
|
+
$: if (visualElement) {
|
|
78
|
+
visualElement.setProps({
|
|
79
|
+
...$config,
|
|
80
|
+
...props,
|
|
81
|
+
layoutId,
|
|
82
|
+
});
|
|
83
|
+
visualElement.isPresent = isPresent($presenceContext);
|
|
84
|
+
visualElement.isPresenceRoot =
|
|
85
|
+
!parent || parent.presenceId !== $presenceContext?.id;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fire a render to ensure the latest state is reflected on-screen.
|
|
89
|
+
*/
|
|
90
|
+
visualElement.syncRender();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
afterUpdate(() => {
|
|
94
|
+
tick().then(() => {
|
|
95
|
+
visualElement.animationState?.animateChanges();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
onDestroy(() => {
|
|
100
|
+
visualElement?.notifyUnmount();
|
|
101
|
+
});
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<slot {visualElement} />
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script module lang="ts">
|
|
5
|
+
import { isAnimationControls } from "../../animation/utils/is-animation-controls.js";
|
|
6
|
+
import {
|
|
7
|
+
checkIfControllingVariants,
|
|
8
|
+
checkIfVariantNode,
|
|
9
|
+
resolveVariantFromProps,
|
|
10
|
+
} from "../../render/utils/variants.js";
|
|
11
|
+
import { resolveMotionValue } from "../../value/utils/resolve-motion-value.js";
|
|
12
|
+
|
|
13
|
+
type Instance = any;
|
|
14
|
+
type RenderState = any;
|
|
15
|
+
|
|
16
|
+
const makeState = (
|
|
17
|
+
{
|
|
18
|
+
scrapeMotionValuesFromProps,
|
|
19
|
+
createRenderState,
|
|
20
|
+
onMount,
|
|
21
|
+
}: UseVisualStateConfig<Instance, RenderState>,
|
|
22
|
+
props,
|
|
23
|
+
context,
|
|
24
|
+
presenceContext
|
|
25
|
+
) => {
|
|
26
|
+
const state: any = {
|
|
27
|
+
latestValues: makeLatestValues(
|
|
28
|
+
props,
|
|
29
|
+
context,
|
|
30
|
+
presenceContext,
|
|
31
|
+
scrapeMotionValuesFromProps
|
|
32
|
+
),
|
|
33
|
+
renderState: createRenderState(),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (onMount) {
|
|
37
|
+
state.mount = (instance) => onMount(props, instance, state);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return state;
|
|
41
|
+
};
|
|
42
|
+
function makeLatestValues(
|
|
43
|
+
props,
|
|
44
|
+
context,
|
|
45
|
+
presenceContext,
|
|
46
|
+
scrapeMotionValues
|
|
47
|
+
) {
|
|
48
|
+
const values: any = {};
|
|
49
|
+
const blockInitialAnimation = presenceContext?.initial === false;
|
|
50
|
+
|
|
51
|
+
const motionValues = scrapeMotionValues(props);
|
|
52
|
+
for (const key in motionValues) {
|
|
53
|
+
values[key] = resolveMotionValue(motionValues[key]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let { initial, animate } = props;
|
|
57
|
+
const isControllingVariants = checkIfControllingVariants(props);
|
|
58
|
+
const isVariantNode = checkIfVariantNode(props);
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
context &&
|
|
62
|
+
isVariantNode &&
|
|
63
|
+
!isControllingVariants &&
|
|
64
|
+
props.inherit !== false
|
|
65
|
+
) {
|
|
66
|
+
initial !== null && initial !== void 0
|
|
67
|
+
? initial
|
|
68
|
+
: (initial = context.initial);
|
|
69
|
+
animate !== null && animate !== void 0
|
|
70
|
+
? animate
|
|
71
|
+
: (animate = context.animate);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const variantToSet =
|
|
75
|
+
blockInitialAnimation || initial === false ? animate : initial;
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
variantToSet &&
|
|
79
|
+
typeof variantToSet !== "boolean" &&
|
|
80
|
+
!isAnimationControls(variantToSet)
|
|
81
|
+
) {
|
|
82
|
+
const list = Array.isArray(variantToSet) ? variantToSet : [variantToSet];
|
|
83
|
+
list.forEach((definition) => {
|
|
84
|
+
const resolved = resolveVariantFromProps(props, definition);
|
|
85
|
+
if (!resolved) return;
|
|
86
|
+
|
|
87
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
88
|
+
|
|
89
|
+
for (const key in target) values[key] = target[key];
|
|
90
|
+
for (const key in transitionEnd) values[key] = transitionEnd[key];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return values;
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<script lang="ts" generics="Instance, RenderState">
|
|
99
|
+
import type { UseVisualStateConfig } from "./use-visual-state.js";
|
|
100
|
+
|
|
101
|
+
import type { MotionProps } from "..";
|
|
102
|
+
|
|
103
|
+
import { getContext } from "svelte";
|
|
104
|
+
import { get, type Writable } from "svelte/store";
|
|
105
|
+
import {
|
|
106
|
+
MotionContext,
|
|
107
|
+
type MotionContextProps,
|
|
108
|
+
} from "../../context/MotionContext/index.js";
|
|
109
|
+
import {
|
|
110
|
+
PresenceContext,
|
|
111
|
+
type PresenceContextProps,
|
|
112
|
+
} from "../../context/PresenceContext.js";
|
|
113
|
+
|
|
114
|
+
type $$Props = {
|
|
115
|
+
config: UseVisualStateConfig<Instance, RenderState>;
|
|
116
|
+
props: MotionProps;
|
|
117
|
+
isStatic: boolean;
|
|
118
|
+
isCustom?: any;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export let config: $$Props["config"],
|
|
122
|
+
props: $$Props["props"],
|
|
123
|
+
isStatic: $$Props["isStatic"],
|
|
124
|
+
isCustom;
|
|
125
|
+
|
|
126
|
+
const context: Writable<MotionContextProps> =
|
|
127
|
+
getContext(MotionContext) || MotionContext(isCustom);
|
|
128
|
+
const presenceContext: Writable<PresenceContextProps> =
|
|
129
|
+
getContext(PresenceContext) || PresenceContext(isCustom);
|
|
130
|
+
let state = makeState(config, props, get(context), get(presenceContext));
|
|
131
|
+
const ms = makeState;
|
|
132
|
+
$: if (isStatic) {
|
|
133
|
+
state = ms(config, props, $context, $presenceContext);
|
|
134
|
+
}
|
|
135
|
+
</script>
|
|
136
|
+
|
|
137
|
+
<slot {state} />
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionProps } from "../..";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { valueScaleCorrection } from '../../render/dom/projection/scale-correction.js';
|
|
13
|
+
import { isTransformOriginProp, isTransformProp } from '../../render/html/utils/transform.js';
|
|
14
|
+
|
|
15
|
+
function isForcedMotionValue(key: string, _a: { layout?: MotionProps['layout'], layoutId?: MotionProps['layoutId'] }): boolean {
|
|
16
|
+
var layout = _a.layout, layoutId = _a.layoutId;
|
|
17
|
+
return (isTransformProp(key) ||
|
|
18
|
+
isTransformOriginProp(key) ||
|
|
19
|
+
((layout || layoutId !== undefined) && !!valueScaleCorrection[key]));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { isForcedMotionValue };
|
|
23
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { FeatureProps } from "../features/types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
based on framer-motion@4.0.3,
|
|
9
|
+
Copyright (c) 2018 Framer B.V.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var makeRenderlessComponent = function <P = FeatureProps>(hook: Function) { return function (props: P) {
|
|
13
|
+
hook(props);
|
|
14
|
+
return null;
|
|
15
|
+
}; };
|
|
16
|
+
|
|
17
|
+
export { makeRenderlessComponent };
|