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,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { SharedLayoutAnimationConfig } from "../../components/AnimateSharedLayout/types";
|
|
6
|
+
import type { MotionProps } from "../../motion/types";
|
|
7
|
+
import type { AxisBox2D, BoxDelta } from "../../types/geometry";
|
|
8
|
+
import type { ResolvedValues } from "../types";
|
|
9
|
+
import type { AnimationDefinition } from "./animation";
|
|
10
|
+
export type LayoutMeasureListener = (layout: AxisBox2D, prevLayout: AxisBox2D) => void;
|
|
11
|
+
export type BeforeLayoutMeasureListener = (layout: AxisBox2D) => void;
|
|
12
|
+
export type LayoutUpdateListener = (layout: AxisBox2D, prevLayout: AxisBox2D, config?: SharedLayoutAnimationConfig) => void;
|
|
13
|
+
export type UpdateListener = (latest: ResolvedValues) => void;
|
|
14
|
+
export type AnimationStartListener = () => void;
|
|
15
|
+
export type AnimationCompleteListener = (definition: AnimationDefinition) => void;
|
|
16
|
+
export type LayoutAnimationCompleteListener = () => void;
|
|
17
|
+
export type SetAxisTargetListener = () => void;
|
|
18
|
+
export type RenderListener = () => void;
|
|
19
|
+
export type OnViewportBoxUpdate = (box: AxisBox2D, delta: BoxDelta) => void;
|
|
20
|
+
/**
|
|
21
|
+
* TODO: Make more of these lifecycle events available as props
|
|
22
|
+
*/
|
|
23
|
+
export interface VisualElementLifecycles {
|
|
24
|
+
/**
|
|
25
|
+
* A callback that fires whenever the viewport-relative bounding box updates.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
onViewportBoxUpdate?(box: AxisBox2D, delta: BoxDelta): void;
|
|
30
|
+
onBeforeLayoutMeasure?(box: AxisBox2D): void;
|
|
31
|
+
onLayoutMeasure?(box: AxisBox2D, prevBox: AxisBox2D): void;
|
|
32
|
+
/**
|
|
33
|
+
* Callback with latest motion values, fired max once per frame.
|
|
34
|
+
*
|
|
35
|
+
* @motion
|
|
36
|
+
*
|
|
37
|
+
* ```jsx
|
|
38
|
+
* function onUpdate(latest) {
|
|
39
|
+
* console.log(latest.x, latest.opacity)
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* <MotionDiv animate={{ x: 100, opacity: 0 }} onUpdate={onUpdate} />
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
onUpdate?(latest: ResolvedValues): void;
|
|
46
|
+
/**
|
|
47
|
+
* Callback when animation defined in `animate` begins.
|
|
48
|
+
*
|
|
49
|
+
* @motion
|
|
50
|
+
*
|
|
51
|
+
* ```jsx
|
|
52
|
+
* function onStart() {
|
|
53
|
+
* console.log("Animation started")
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* <MotionDiv animate={{ x: 100 }} onAnimationStart={onStart} />
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
onAnimationStart?(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Callback when animation defined in `animate` is complete.
|
|
62
|
+
*
|
|
63
|
+
* The provided callback will be called the triggering animation definition.
|
|
64
|
+
* If this is a variant, it'll be the variant name, and if a target object
|
|
65
|
+
* then it'll be the target object.
|
|
66
|
+
*
|
|
67
|
+
* This way, it's possible to figure out which animation has completed.
|
|
68
|
+
*
|
|
69
|
+
* @motion
|
|
70
|
+
*
|
|
71
|
+
* ```jsx
|
|
72
|
+
* function onComplete() {
|
|
73
|
+
* console.log("Animation completed")
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* <MotionDiv
|
|
77
|
+
* animate={{ x: 100 }}
|
|
78
|
+
* onAnimationComplete={definition => {
|
|
79
|
+
* console.log('Completed animating', definition)
|
|
80
|
+
* }}
|
|
81
|
+
* />
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
onAnimationComplete?(definition: AnimationDefinition): void;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
onLayoutAnimationComplete?(): void;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
onUnmount?(): void;
|
|
93
|
+
}
|
|
94
|
+
export interface LifecycleManager {
|
|
95
|
+
onLayoutMeasure: (callback: LayoutMeasureListener) => () => void;
|
|
96
|
+
notifyLayoutMeasure: LayoutMeasureListener;
|
|
97
|
+
onBeforeLayoutMeasure: (callback: BeforeLayoutMeasureListener) => () => void;
|
|
98
|
+
notifyBeforeLayoutMeasure: BeforeLayoutMeasureListener;
|
|
99
|
+
onLayoutUpdate: (callback: LayoutUpdateListener) => () => void;
|
|
100
|
+
notifyLayoutUpdate: LayoutUpdateListener;
|
|
101
|
+
onViewportBoxUpdate: (callback: OnViewportBoxUpdate) => () => void;
|
|
102
|
+
notifyViewportBoxUpdate: OnViewportBoxUpdate;
|
|
103
|
+
onUpdate: (callback: UpdateListener) => () => void;
|
|
104
|
+
notifyUpdate: UpdateListener;
|
|
105
|
+
onAnimationStart: (callback: AnimationStartListener) => () => void;
|
|
106
|
+
notifyAnimationStart: AnimationStartListener;
|
|
107
|
+
onAnimationComplete: (callback: AnimationCompleteListener) => () => void;
|
|
108
|
+
notifyAnimationComplete: AnimationCompleteListener;
|
|
109
|
+
onLayoutAnimationComplete: (callback: LayoutAnimationCompleteListener) => () => void;
|
|
110
|
+
notifyLayoutAnimationComplete: LayoutAnimationCompleteListener;
|
|
111
|
+
onSetAxisTarget: (callback: SetAxisTargetListener) => () => void;
|
|
112
|
+
notifySetAxisTarget: SetAxisTargetListener;
|
|
113
|
+
onRender: (callback: RenderListener) => () => void;
|
|
114
|
+
notifyRender: RenderListener;
|
|
115
|
+
onUnmount: (callback: () => void) => () => void;
|
|
116
|
+
notifyUnmount: () => void;
|
|
117
|
+
clearAllListeners: () => void;
|
|
118
|
+
updatePropListeners: (props: MotionProps) => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
based on framer-motion@4.0.3,
|
|
124
|
+
Copyright (c) 2018 Framer B.V.
|
|
125
|
+
*/
|
|
126
|
+
import { __spreadArray, __read } from 'tslib';
|
|
127
|
+
import { SubscriptionManager } from '../../utils/subscription-manager.js';
|
|
128
|
+
|
|
129
|
+
var names = [
|
|
130
|
+
"LayoutMeasure",
|
|
131
|
+
"BeforeLayoutMeasure",
|
|
132
|
+
"LayoutUpdate",
|
|
133
|
+
"ViewportBoxUpdate",
|
|
134
|
+
"Update",
|
|
135
|
+
"Render",
|
|
136
|
+
"AnimationComplete",
|
|
137
|
+
"LayoutAnimationComplete",
|
|
138
|
+
"AnimationStart",
|
|
139
|
+
"SetAxisTarget",
|
|
140
|
+
"Unmount",
|
|
141
|
+
];
|
|
142
|
+
function createLifecycles() {
|
|
143
|
+
var managers = names.map(function () { return new SubscriptionManager(); });
|
|
144
|
+
var propSubscriptions = {};
|
|
145
|
+
var lifecycles = {
|
|
146
|
+
clearAllListeners: function () { return managers.forEach(function (manager) { return manager.clear(); }); },
|
|
147
|
+
updatePropListeners: function (props) {
|
|
148
|
+
return names.forEach(function (name) {
|
|
149
|
+
var _a;
|
|
150
|
+
(_a = propSubscriptions[name]) === null || _a === void 0 ? void 0 : _a.call(propSubscriptions);
|
|
151
|
+
var on = "on" + name;
|
|
152
|
+
var propListener = props[on];
|
|
153
|
+
if (propListener) {
|
|
154
|
+
propSubscriptions[name] = lifecycles[on](propListener);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
managers.forEach(function (manager, i) {
|
|
160
|
+
lifecycles["on" + names[i]] = function (handler) { return manager.add(handler); };
|
|
161
|
+
lifecycles["notify" + names[i]] = function () {
|
|
162
|
+
var args = [];
|
|
163
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
164
|
+
args[_i] = arguments[_i];
|
|
165
|
+
}
|
|
166
|
+
return manager.notify.apply(manager, __spreadArray([], __read(args)));
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return lifecycles as LifecycleManager;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { createLifecycles };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionStyle } from "../../motion/types";
|
|
6
|
+
import type { VisualElement } from "../types";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
based on framer-motion@4.0.3,
|
|
11
|
+
Copyright (c) 2018 Framer B.V.
|
|
12
|
+
*/
|
|
13
|
+
import { motionValue } from '../../value/index.js';
|
|
14
|
+
import { isMotionValue } from '../../value/utils/is-motion-value.js';
|
|
15
|
+
|
|
16
|
+
function updateMotionValuesFromProps(element: VisualElement, next: MotionStyle, prev: MotionStyle) {
|
|
17
|
+
var _a;
|
|
18
|
+
for (var key in next) {
|
|
19
|
+
var nextValue = next[key];
|
|
20
|
+
var prevValue = prev[key];
|
|
21
|
+
if (isMotionValue(nextValue)) {
|
|
22
|
+
/**
|
|
23
|
+
* If this is a motion value found in props or style, we want to add it
|
|
24
|
+
* to our visual element's motion value map.
|
|
25
|
+
*/
|
|
26
|
+
element.addValue(key, nextValue);
|
|
27
|
+
}
|
|
28
|
+
else if (isMotionValue(prevValue)) {
|
|
29
|
+
/**
|
|
30
|
+
* If we're swapping to a new motion value, create a new motion value
|
|
31
|
+
* from that
|
|
32
|
+
*/
|
|
33
|
+
element.addValue(key, motionValue(nextValue));
|
|
34
|
+
}
|
|
35
|
+
else if (prevValue !== nextValue) {
|
|
36
|
+
/**
|
|
37
|
+
* If this is a flat value that has changed, update the motion value
|
|
38
|
+
* or create one if it doesn't exist. We only want to do this if we're
|
|
39
|
+
* not handling the value with our animation state.
|
|
40
|
+
*/
|
|
41
|
+
if (element.hasValue(key)) {
|
|
42
|
+
var existingValue = element.getValue(key);
|
|
43
|
+
// TODO: Only update values that aren't being animated or even looked at
|
|
44
|
+
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
element.addValue(key, motionValue((_a = element.getStaticValue(key)) !== null && _a !== void 0 ? _a : nextValue));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Handle removed values
|
|
52
|
+
for (var key in prev) {
|
|
53
|
+
if (next[key] === undefined)
|
|
54
|
+
element.removeValue(key);
|
|
55
|
+
}
|
|
56
|
+
return next;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { updateMotionValuesFromProps };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { ResolvedValues, VisualElement } from "../types";
|
|
6
|
+
import type { LayoutState, TargetProjection } from "./state";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { resetBox, applyTreeDeltas } from '../../utils/geometry/delta-apply.js';
|
|
13
|
+
import { updateBoxDelta } from '../../utils/geometry/delta-calc.js';
|
|
14
|
+
|
|
15
|
+
function updateLayoutDeltas({ delta, layout, layoutCorrected, treeScale }: LayoutState, { target }: TargetProjection, treePath: VisualElement[], transformOrigin: ResolvedValues) {
|
|
16
|
+
/**
|
|
17
|
+
* Reset the corrected box with the latest values from box, as we're then going
|
|
18
|
+
* to perform mutative operations on it.
|
|
19
|
+
*/
|
|
20
|
+
resetBox(layoutCorrected, layout);
|
|
21
|
+
/**
|
|
22
|
+
* Apply all the parent deltas to this box to produce the corrected box. This
|
|
23
|
+
* is the layout box, as it will appear on screen as a result of the transforms of its parents.
|
|
24
|
+
*/
|
|
25
|
+
applyTreeDeltas(layoutCorrected, treeScale, treePath);
|
|
26
|
+
/**
|
|
27
|
+
* Update the delta between the corrected box and the target box before user-set transforms were applied.
|
|
28
|
+
* This will allow us to calculate the corrected borderRadius and boxShadow to compensate
|
|
29
|
+
* for our layout reprojection, but still allow them to be scaled correctly by the user.
|
|
30
|
+
* It might be that to simplify this we may want to accept that user-set scale1 is also corrected
|
|
31
|
+
* and we wouldn't have to keep and calc both deltas, OR we could support a user setting
|
|
32
|
+
* to allow people to choose whether these styles are corrected based on just the
|
|
33
|
+
* layout reprojection or the final bounding box.
|
|
34
|
+
*/
|
|
35
|
+
updateBoxDelta(delta, layoutCorrected, target, transformOrigin);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { updateLayoutDeltas };
|