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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
// TODO: import type { EasingFunction } from "svelte/transition"; future idea, maybe use svelte built in easing function...
|
|
6
|
+
import type { Easing, EasingFunction } from "../../types";
|
|
7
|
+
// export declare const easingDefinitionToFunction: (definition: Easing) => import("../../types").EasingFunction;
|
|
8
|
+
// export declare const isEasingArray: (ease: any) => ease is Easing[];
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
based on framer-motion@4.0.3,
|
|
14
|
+
Copyright (c) 2018 Framer B.V.
|
|
15
|
+
*/
|
|
16
|
+
import { anticipate, backIn, backInOut, backOut, bounceIn, bounceInOut, bounceOut, circIn, circInOut, circOut, cubicBezier, easeIn, easeInOut, easeOut, linear } from 'popmotion';
|
|
17
|
+
import { __read } from 'tslib';
|
|
18
|
+
// import { invariant } from '../../utils/errors.js';
|
|
19
|
+
|
|
20
|
+
var easingLookup = {
|
|
21
|
+
linear: linear,
|
|
22
|
+
easeIn: easeIn,
|
|
23
|
+
easeInOut: easeInOut,
|
|
24
|
+
easeOut: easeOut,
|
|
25
|
+
circIn: circIn,
|
|
26
|
+
circInOut: circInOut,
|
|
27
|
+
circOut: circOut,
|
|
28
|
+
backIn: backIn,
|
|
29
|
+
backInOut: backInOut,
|
|
30
|
+
backOut: backOut,
|
|
31
|
+
anticipate: anticipate,
|
|
32
|
+
bounceIn: bounceIn,
|
|
33
|
+
bounceInOut: bounceInOut,
|
|
34
|
+
bounceOut: bounceOut,
|
|
35
|
+
};
|
|
36
|
+
var easingDefinitionToFunction = function (definition: Easing): EasingFunction {
|
|
37
|
+
if (Array.isArray(definition)) {
|
|
38
|
+
// If cubic bezier definition, create bezier curve
|
|
39
|
+
//invariant(definition.length === 4, "Cubic bezier arrays must contain four numerical values.");
|
|
40
|
+
var _a = __read(definition, 4), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
|
|
41
|
+
return cubicBezier(x1, y1, x2, y2);
|
|
42
|
+
}
|
|
43
|
+
else if (typeof definition === "string") {
|
|
44
|
+
// Else lookup from table
|
|
45
|
+
//invariant(easingLookup[definition] !== undefined, "Invalid easing type '" + definition + "'");
|
|
46
|
+
return easingLookup[definition];
|
|
47
|
+
}
|
|
48
|
+
return definition;
|
|
49
|
+
};
|
|
50
|
+
const isEasingArray = (ease: any): ease is Easing[] => {
|
|
51
|
+
return Array.isArray(ease) && typeof ease[0] !== "number";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { easingDefinitionToFunction, isEasingArray };
|
|
55
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { ResolvedValueTarget } from "../../types";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import {fixed} from '../../utils/fix-process-env';
|
|
13
|
+
import { complex } from 'style-value-types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if a value is animatable. Examples:
|
|
17
|
+
*
|
|
18
|
+
* ✅: 100, "100px", "#fff"
|
|
19
|
+
* ❌: "block", "url(2.jpg)"
|
|
20
|
+
* @param value
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
var isAnimatable = function (key: string, value: ResolvedValueTarget) {
|
|
25
|
+
// If the list of keys tat might be non-animatable grows, replace with Set
|
|
26
|
+
if (key === "zIndex")
|
|
27
|
+
return false;
|
|
28
|
+
// If it's a number or a keyframes array, we can animate it. We might at some point
|
|
29
|
+
// need to do a deep isAnimatable check of keyframes, or let Popmotion handle this,
|
|
30
|
+
// but for now lets leave it like this for performance reasons
|
|
31
|
+
if (typeof value === "number" || Array.isArray(value))
|
|
32
|
+
return true;
|
|
33
|
+
if (typeof value === "string" && // It's animatable if we have a string
|
|
34
|
+
complex.test(value) && // And it contains numbers and/or colors
|
|
35
|
+
!value.startsWith("url(") // Unless it starts with "url("
|
|
36
|
+
) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { isAnimatable };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { AnimationControls } from "../types";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const isAnimationControls = (v?: any): v is AnimationControls => {
|
|
14
|
+
return typeof v === "object" && typeof (v)?.start === "function"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { isAnimationControls };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { ValueTarget, KeyframesTarget } from "../../types";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const isKeyframesTarget = (v: ValueTarget): v is KeyframesTarget => {
|
|
14
|
+
return Array.isArray(v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { isKeyframesTarget };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { AnimationOptions } from "popmotion";
|
|
6
|
+
import type { PermissiveTransitionDefinition, ResolvedValueTarget, Transition } from "../../types";
|
|
7
|
+
import { MotionValue } from "../../value";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
based on framer-motion@4.1.15,
|
|
12
|
+
Copyright (c) 2018 Framer B.V.
|
|
13
|
+
*/
|
|
14
|
+
import { animate, inertia } from 'popmotion';
|
|
15
|
+
import { __assign, __read, __rest, __spreadArray } from 'tslib';
|
|
16
|
+
import { getAnimatableNone } from '../../render/dom/value-types/animatable-none.js';
|
|
17
|
+
import { warning } from '../../utils/errors.js';
|
|
18
|
+
import { secondsToMilliseconds } from '../../utils/time-conversion.js';
|
|
19
|
+
import { getDefaultTransition } from './default-transitions.js';
|
|
20
|
+
import { easingDefinitionToFunction, isEasingArray } from './easing.js';
|
|
21
|
+
import { isAnimatable } from './is-animatable.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decide whether a transition is defined on a given Transition.
|
|
25
|
+
* This filters out orchestration options and returns true
|
|
26
|
+
* if any options are left.
|
|
27
|
+
*/
|
|
28
|
+
function isTransitionDefined(_a: Transition) {
|
|
29
|
+
_a.when; _a.delay; _a.delayChildren; _a.staggerChildren; _a.staggerDirection; _a.repeat; _a.repeatType; _a.repeatDelay; _a.from; var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
30
|
+
return !!Object.keys(transition).length;
|
|
31
|
+
}
|
|
32
|
+
var legacyRepeatWarning = false;
|
|
33
|
+
/**
|
|
34
|
+
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
35
|
+
*/
|
|
36
|
+
function convertTransitionToAnimationOptions<T>(_a: PermissiveTransitionDefinition): AnimationOptions<T> {
|
|
37
|
+
var ease = _a.ease, times = _a.times, yoyo = _a.yoyo, flip = _a.flip, loop = _a.loop, transition = __rest(_a, ["ease", "times", "yoyo", "flip", "loop"]);
|
|
38
|
+
var options = __assign({}, transition);
|
|
39
|
+
if (times)
|
|
40
|
+
options["offset"] = times;
|
|
41
|
+
/**
|
|
42
|
+
* Convert any existing durations from seconds to milliseconds
|
|
43
|
+
*/
|
|
44
|
+
if (transition.duration)
|
|
45
|
+
options["duration"] = secondsToMilliseconds(transition.duration);
|
|
46
|
+
if (transition.repeatDelay)
|
|
47
|
+
options.repeatDelay = secondsToMilliseconds(transition.repeatDelay);
|
|
48
|
+
/**
|
|
49
|
+
* Map easing names to Popmotion's easing functions
|
|
50
|
+
*/
|
|
51
|
+
if (ease) {
|
|
52
|
+
options["ease"] = isEasingArray(ease)
|
|
53
|
+
? ease.map(easingDefinitionToFunction)
|
|
54
|
+
: easingDefinitionToFunction(ease);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Support legacy transition API
|
|
58
|
+
*/
|
|
59
|
+
if (transition.type === "tween")
|
|
60
|
+
options.type = "keyframes";
|
|
61
|
+
/**
|
|
62
|
+
* TODO: These options are officially removed from the API.
|
|
63
|
+
*/
|
|
64
|
+
if (yoyo || loop || flip) {
|
|
65
|
+
warning(!legacyRepeatWarning, "yoyo, loop and flip have been removed from the API. Replace with repeat and repeatType options.");
|
|
66
|
+
legacyRepeatWarning = true;
|
|
67
|
+
if (yoyo) {
|
|
68
|
+
options.repeatType = "reverse";
|
|
69
|
+
}
|
|
70
|
+
else if (loop) {
|
|
71
|
+
options.repeatType = "loop";
|
|
72
|
+
}
|
|
73
|
+
else if (flip) {
|
|
74
|
+
options.repeatType = "mirror";
|
|
75
|
+
}
|
|
76
|
+
options.repeat = loop || yoyo || flip || transition.repeat;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* TODO: Popmotion 9 has the ability to automatically detect whether to use
|
|
80
|
+
* a keyframes or spring animation, but does so by detecting velocity and other spring options.
|
|
81
|
+
* It'd be good to introduce a similar thing here.
|
|
82
|
+
*/
|
|
83
|
+
if (transition.type !== "spring")
|
|
84
|
+
options.type = "keyframes";
|
|
85
|
+
return options;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the delay for a value by checking Transition with decreasing specificity.
|
|
89
|
+
*/
|
|
90
|
+
function getDelayFromTransition(transition: Transition, key: keyof Transition | "layoutX" | "layoutY" | "" | string) {
|
|
91
|
+
var _a;
|
|
92
|
+
var valueTransition = getValueTransition(transition, key) || {};
|
|
93
|
+
return (_a = valueTransition.delay) !== null && _a !== void 0 ? _a : 0;
|
|
94
|
+
}
|
|
95
|
+
function hydrateKeyframes(options: PermissiveTransitionDefinition) {
|
|
96
|
+
if (Array.isArray(options.to) && options.to[0] === null) {
|
|
97
|
+
options.to = __spreadArray([], __read(options.to));
|
|
98
|
+
options.to[0] = options.from;
|
|
99
|
+
}
|
|
100
|
+
return options;
|
|
101
|
+
}
|
|
102
|
+
function getPopmotionAnimationOptions(transition: PermissiveTransitionDefinition, options: any, key: string) {
|
|
103
|
+
var _a;
|
|
104
|
+
if (Array.isArray(options.to)) {
|
|
105
|
+
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
106
|
+
}
|
|
107
|
+
hydrateKeyframes(options);
|
|
108
|
+
/**
|
|
109
|
+
* Get a default transition if none is determined to be defined.
|
|
110
|
+
*/
|
|
111
|
+
if (!isTransitionDefined(transition)) {
|
|
112
|
+
transition = __assign(__assign({}, transition), getDefaultTransition(key, options.to));
|
|
113
|
+
}
|
|
114
|
+
return __assign(__assign({}, options), convertTransitionToAnimationOptions(transition));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
function getAnimation(key: string, value: MotionValue, target: ResolvedValueTarget, transition: Transition, onComplete) {
|
|
120
|
+
var _a;
|
|
121
|
+
var valueTransition = getValueTransition(transition, key);
|
|
122
|
+
var origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
123
|
+
var isTargetAnimatable = isAnimatable(key, target);
|
|
124
|
+
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
125
|
+
/**
|
|
126
|
+
* If we're trying to animate from "none", try and get an animatable version
|
|
127
|
+
* of the target. This could be improved to work both ways.
|
|
128
|
+
*/
|
|
129
|
+
origin = getAnimatableNone(key, target);
|
|
130
|
+
}
|
|
131
|
+
else if (isZero(origin) && typeof target === "string") {
|
|
132
|
+
origin = getZeroUnit(target);
|
|
133
|
+
}
|
|
134
|
+
else if (!Array.isArray(target) &&
|
|
135
|
+
isZero(target) &&
|
|
136
|
+
typeof origin === "string") {
|
|
137
|
+
target = getZeroUnit(origin);
|
|
138
|
+
}
|
|
139
|
+
var isOriginAnimatable = isAnimatable(key, origin);
|
|
140
|
+
warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
|
|
141
|
+
function start() {
|
|
142
|
+
var options = {
|
|
143
|
+
from: origin,
|
|
144
|
+
to: target,
|
|
145
|
+
velocity: value.getVelocity(),
|
|
146
|
+
onComplete: onComplete,
|
|
147
|
+
onUpdate: function (v) { return value.set(v); },
|
|
148
|
+
};
|
|
149
|
+
return valueTransition.type === "inertia" ||
|
|
150
|
+
valueTransition.type === "decay"
|
|
151
|
+
? inertia(__assign(__assign({}, options), valueTransition))
|
|
152
|
+
: animate(__assign(__assign({}, getPopmotionAnimationOptions(valueTransition, options, key)), { onUpdate: function (v) {
|
|
153
|
+
var _a;
|
|
154
|
+
options.onUpdate(v);
|
|
155
|
+
(_a = valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, v);
|
|
156
|
+
}, onComplete: function () {
|
|
157
|
+
var _a;
|
|
158
|
+
options.onComplete();
|
|
159
|
+
(_a = valueTransition.onComplete) === null || _a === void 0 ? void 0 : _a.call(valueTransition);
|
|
160
|
+
} }));
|
|
161
|
+
}
|
|
162
|
+
function set() {
|
|
163
|
+
var _a;
|
|
164
|
+
value.set(target);
|
|
165
|
+
onComplete();
|
|
166
|
+
(_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _a === void 0 ? void 0 : _a.call(valueTransition);
|
|
167
|
+
return { stop: function () { } };
|
|
168
|
+
}
|
|
169
|
+
return !isOriginAnimatable ||
|
|
170
|
+
!isTargetAnimatable ||
|
|
171
|
+
valueTransition.type === false
|
|
172
|
+
? set
|
|
173
|
+
: start;
|
|
174
|
+
}
|
|
175
|
+
function isZero(value: string | number) {
|
|
176
|
+
return (value === 0 ||
|
|
177
|
+
(typeof value === "string" &&
|
|
178
|
+
parseFloat(value) === 0 &&
|
|
179
|
+
value.indexOf(" ") === -1));
|
|
180
|
+
}
|
|
181
|
+
function getZeroUnit(potentialUnitType: string | number) {
|
|
182
|
+
return typeof potentialUnitType === "number"
|
|
183
|
+
? 0
|
|
184
|
+
: getAnimatableNone("", potentialUnitType);
|
|
185
|
+
}
|
|
186
|
+
function getValueTransition(transition: Transition, key: string) {
|
|
187
|
+
let tran = transition as any
|
|
188
|
+
return tran[key] || tran["default"] || tran;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Start animation on a MotionValue. This function is an interface between
|
|
192
|
+
* Framer Motion and Popmotion
|
|
193
|
+
*
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
function startAnimation(key: string, value: MotionValue, target: ResolvedValueTarget, transition?: Transition) {
|
|
197
|
+
if (transition === void 0) { transition = {}; }
|
|
198
|
+
return value.start(function (onComplete) {
|
|
199
|
+
var delayTimer;
|
|
200
|
+
var controls;
|
|
201
|
+
var animation = getAnimation(key, value, target, transition, onComplete);
|
|
202
|
+
var delay = getDelayFromTransition(transition, key);
|
|
203
|
+
var start = function () { return (controls = animation()); };
|
|
204
|
+
if (delay) {
|
|
205
|
+
delayTimer = setTimeout(start, secondsToMilliseconds(delay));
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
start();
|
|
209
|
+
}
|
|
210
|
+
return function () {
|
|
211
|
+
clearTimeout(delayTimer);
|
|
212
|
+
controls === null || controls === void 0 ? void 0 : controls.stop();
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { convertTransitionToAnimationOptions, getDelayFromTransition, getPopmotionAnimationOptions, getValueTransition, getZeroUnit, hydrateKeyframes, isTransitionDefined, isZero, startAnimation };
|
|
218
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import { MotionValue } from "../../value";
|
|
6
|
+
type VariantNameList = string[];
|
|
7
|
+
type VariantName = string | VariantNameList;
|
|
8
|
+
type UnresolvedVariant = VariantName | MotionValue;
|
|
9
|
+
export type resolveVariantLabels = (variant?: UnresolvedVariant | undefined) => VariantNameList;
|
|
10
|
+
/**
|
|
11
|
+
* Hooks in React sometimes accept a dependency array as their final argument. (ie useEffect/useMemo)
|
|
12
|
+
* When values in this array change, React re-runs the dependency. However if the array
|
|
13
|
+
* contains a variable number of items, React throws an error.
|
|
14
|
+
*/
|
|
15
|
+
export type asDependencyList = (list: VariantNameList) => string[];
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script lang="ts" generics="T extends {key:any}">
|
|
5
|
+
import type { ConditionalGeneric, AnimatePresenceProps } from "./index.js";
|
|
6
|
+
import { getContext } from "svelte";
|
|
7
|
+
import {
|
|
8
|
+
SharedLayoutContext,
|
|
9
|
+
isSharedLayout,
|
|
10
|
+
} from "../../context/SharedLayoutContext.js";
|
|
11
|
+
import PresenceChild from "./PresenceChild/PresenceChild.svelte";
|
|
12
|
+
|
|
13
|
+
type $$Props = AnimatePresenceProps<ConditionalGeneric<T>>;
|
|
14
|
+
|
|
15
|
+
export let list: $$Props["list"] = undefined,
|
|
16
|
+
custom: $$Props["custom"] = undefined,
|
|
17
|
+
initial: $$Props["initial"] = true,
|
|
18
|
+
onExitComplete: $$Props["onExitComplete"] = undefined,
|
|
19
|
+
exitBeforeEnter: $$Props["exitBeforeEnter"] = undefined,
|
|
20
|
+
presenceAffectsLayout = true,
|
|
21
|
+
show: $$Props["show"] = undefined,
|
|
22
|
+
isCustom = false;
|
|
23
|
+
|
|
24
|
+
let _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
|
|
25
|
+
$: _list = list !== undefined ? list : show ? [{ key: 1 }] : [];
|
|
26
|
+
|
|
27
|
+
const layoutContext =
|
|
28
|
+
getContext(SharedLayoutContext) || SharedLayoutContext(isCustom);
|
|
29
|
+
|
|
30
|
+
$: isl = isSharedLayout($layoutContext);
|
|
31
|
+
|
|
32
|
+
$: forceRender = () => {
|
|
33
|
+
if (isl) {
|
|
34
|
+
$layoutContext.forceUpdate();
|
|
35
|
+
}
|
|
36
|
+
_list = [..._list];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function getChildKey(child) {
|
|
40
|
+
return child.key || "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let isInitialRender = true;
|
|
44
|
+
let filteredChildren = _list;
|
|
45
|
+
$: filteredChildren = _list;
|
|
46
|
+
|
|
47
|
+
let presentChildren = filteredChildren;
|
|
48
|
+
let allChildren = new Map();
|
|
49
|
+
let exiting = new Set();
|
|
50
|
+
const updateChildLookup = (children, allChild) => {
|
|
51
|
+
children.forEach((child) => {
|
|
52
|
+
const key = getChildKey(child);
|
|
53
|
+
allChild.set(key, child);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
$: updateChildLookup(filteredChildren, allChildren);
|
|
57
|
+
|
|
58
|
+
let childrenToRender: {
|
|
59
|
+
present: boolean;
|
|
60
|
+
item: any;
|
|
61
|
+
key: any;
|
|
62
|
+
onExit: undefined | (() => void);
|
|
63
|
+
}[] = [
|
|
64
|
+
...filteredChildren.map((v) => ({
|
|
65
|
+
present: true,
|
|
66
|
+
item: v,
|
|
67
|
+
key: v.key,
|
|
68
|
+
onExit: undefined,
|
|
69
|
+
})),
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
$: if (!isInitialRender) {
|
|
73
|
+
// If this is a subsequent render, deal with entering and exiting children
|
|
74
|
+
childrenToRender = [
|
|
75
|
+
...filteredChildren.map((v) => ({
|
|
76
|
+
present: true,
|
|
77
|
+
item: v,
|
|
78
|
+
key: v.key,
|
|
79
|
+
onExit: undefined,
|
|
80
|
+
})),
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
// Diff the keys of the currently-present and target children to update our
|
|
84
|
+
// exiting list.
|
|
85
|
+
const presentKeys = presentChildren.map(getChildKey);
|
|
86
|
+
const targetKeys = filteredChildren.map(getChildKey);
|
|
87
|
+
// Diff the present children with our target children and mark those that are exiting
|
|
88
|
+
const numPresent = presentKeys.length;
|
|
89
|
+
for (let i = 0; i < numPresent; i++) {
|
|
90
|
+
const key = presentKeys[i];
|
|
91
|
+
if (targetKeys.indexOf(key) === -1) {
|
|
92
|
+
exiting.add(key);
|
|
93
|
+
} else {
|
|
94
|
+
// In case this key has re-entered, remove from the exiting list
|
|
95
|
+
exiting.delete(key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// If we currently have exiting children, and we're deferring rendering incoming children
|
|
100
|
+
// until after all current children have exiting, empty the childrenToRender array
|
|
101
|
+
if (exitBeforeEnter && exiting.size) {
|
|
102
|
+
childrenToRender = [];
|
|
103
|
+
}
|
|
104
|
+
// Loop through all currently exiting components and clone them to overwrite `animate`
|
|
105
|
+
// with any `exit` prop they might have defined.
|
|
106
|
+
exiting.forEach((key) => {
|
|
107
|
+
// If this component is actually entering again, early return
|
|
108
|
+
if (targetKeys.indexOf(key) !== -1) return;
|
|
109
|
+
|
|
110
|
+
const child = allChildren.get(key);
|
|
111
|
+
if (!child) return;
|
|
112
|
+
|
|
113
|
+
const insertionIndex = presentKeys.indexOf(key);
|
|
114
|
+
|
|
115
|
+
const onExit = () => {
|
|
116
|
+
allChildren.delete(key);
|
|
117
|
+
exiting.delete(key);
|
|
118
|
+
|
|
119
|
+
// Remove this child from the present children
|
|
120
|
+
const removeIndex = presentChildren.findIndex(
|
|
121
|
+
(presentChild) => presentChild.key === key,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (removeIndex < 0) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
presentChildren.splice(removeIndex, 1);
|
|
128
|
+
|
|
129
|
+
// Defer re-rendering until all exiting children have indeed left
|
|
130
|
+
if (!exiting.size) {
|
|
131
|
+
presentChildren = [...filteredChildren];
|
|
132
|
+
forceRender();
|
|
133
|
+
onExitComplete && onExitComplete();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
childrenToRender.splice(insertionIndex, 0, {
|
|
138
|
+
present: false,
|
|
139
|
+
item: child,
|
|
140
|
+
key: getChildKey(child),
|
|
141
|
+
onExit,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
// Add `MotionContext` even to children that don't need it to ensure we're rendering
|
|
145
|
+
// the same tree between renders
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
childrenToRender = childrenToRender.map((child) => {
|
|
149
|
+
const key = child.key as string | number;
|
|
150
|
+
return exiting.has(key) ? (
|
|
151
|
+
child
|
|
152
|
+
) : (
|
|
153
|
+
<PresenceChild
|
|
154
|
+
key={getChildKey(child)}
|
|
155
|
+
isPresent
|
|
156
|
+
presenceAffectsLayout={presenceAffectsLayout}
|
|
157
|
+
>
|
|
158
|
+
{child}
|
|
159
|
+
</PresenceChild>
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
*/
|
|
163
|
+
presentChildren = childrenToRender;
|
|
164
|
+
} else {
|
|
165
|
+
isInitialRender = false;
|
|
166
|
+
}
|
|
167
|
+
</script>
|
|
168
|
+
|
|
169
|
+
{#each childrenToRender as child (getChildKey(child))}
|
|
170
|
+
<PresenceChild
|
|
171
|
+
isPresent={child.present}
|
|
172
|
+
initial={initial ? undefined : false}
|
|
173
|
+
custom={child.onExit ? custom : undefined}
|
|
174
|
+
{presenceAffectsLayout}
|
|
175
|
+
onExitComplete={child.onExit}
|
|
176
|
+
{isCustom}
|
|
177
|
+
>
|
|
178
|
+
<slot item={child.item} />
|
|
179
|
+
</PresenceChild>
|
|
180
|
+
{/each}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script module>
|
|
5
|
+
let presenceId = 0;
|
|
6
|
+
function getPresenceId() {
|
|
7
|
+
const id = presenceId;
|
|
8
|
+
presenceId++;
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
function newChildrenMap() {
|
|
12
|
+
return new Map();
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import { afterUpdate, setContext, tick } from "svelte";
|
|
18
|
+
import { setDomContext } from "../../../context/DOMcontext.js";
|
|
19
|
+
import { PresenceContext } from "../../../context/PresenceContext.js";
|
|
20
|
+
import type { PresenceChildProps } from "./index.js";
|
|
21
|
+
|
|
22
|
+
type $$Props = PresenceChildProps;
|
|
23
|
+
|
|
24
|
+
export let isPresent: $$Props['isPresent'],
|
|
25
|
+
onExitComplete: $$Props['onExitComplete'] = undefined,
|
|
26
|
+
initial: $$Props['initial'] = undefined,
|
|
27
|
+
custom: $$Props['custom'] = undefined,
|
|
28
|
+
presenceAffectsLayout: $$Props['presenceAffectsLayout'],
|
|
29
|
+
isCustom: $$Props['isCustom'];
|
|
30
|
+
|
|
31
|
+
const presenceChildren = newChildrenMap();
|
|
32
|
+
const id = getPresenceId();
|
|
33
|
+
|
|
34
|
+
$: refresh = presenceAffectsLayout ? undefined : isPresent;
|
|
35
|
+
|
|
36
|
+
const memoContext = () => {
|
|
37
|
+
return {
|
|
38
|
+
id,
|
|
39
|
+
initial,
|
|
40
|
+
isPresent,
|
|
41
|
+
custom,
|
|
42
|
+
onExitComplete: (childId) => {
|
|
43
|
+
presenceChildren.set(childId, true);
|
|
44
|
+
let allComplete = true;
|
|
45
|
+
presenceChildren.forEach((isComplete) => {
|
|
46
|
+
if (!isComplete) allComplete = false;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
allComplete && onExitComplete?.();
|
|
50
|
+
},
|
|
51
|
+
register: (childId) => {
|
|
52
|
+
presenceChildren.set(childId, false);
|
|
53
|
+
return () => presenceChildren.delete(childId);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
let context = PresenceContext();
|
|
58
|
+
|
|
59
|
+
afterUpdate(() => {
|
|
60
|
+
if (presenceAffectsLayout) {
|
|
61
|
+
context.set(memoContext());
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
$: context.set(memoContext(refresh));
|
|
66
|
+
|
|
67
|
+
const keyset = () => {
|
|
68
|
+
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
69
|
+
};
|
|
70
|
+
$: keyset(isPresent);
|
|
71
|
+
$: tick().then(() => {
|
|
72
|
+
!isPresent && !presenceChildren.size && onExitComplete?.();
|
|
73
|
+
});
|
|
74
|
+
setContext(PresenceContext, context);
|
|
75
|
+
setDomContext("Presence",isCustom,context)
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<slot />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VariantLabels } from "../../../motion/types";
|
|
2
|
+
export interface PresenceChildProps {
|
|
3
|
+
// children: React.ReactElement<any>;
|
|
4
|
+
isPresent: boolean;
|
|
5
|
+
onExitComplete?: () => void;
|
|
6
|
+
initial?: false | VariantLabels;
|
|
7
|
+
custom?: any;
|
|
8
|
+
presenceAffectsLayout: boolean;
|
|
9
|
+
isCustom: boolean
|
|
10
|
+
}
|