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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
based on framer-motion@4.0.3,
|
|
8
|
+
Copyright (c) 2018 Framer B.V.
|
|
9
|
+
*/
|
|
10
|
+
function addUniqueItem<T>(arr: T[], item: T) {
|
|
11
|
+
arr.indexOf(item) === -1 && arr.push(item);
|
|
12
|
+
}
|
|
13
|
+
function removeItem<T>(arr: T[], item: T) {
|
|
14
|
+
var index = arr.indexOf(item);
|
|
15
|
+
index > -1 && arr.splice(index, 1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { addUniqueItem, removeItem };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
based on framer-motion@4.0.3,
|
|
8
|
+
Copyright (c) 2018 Framer B.V.
|
|
9
|
+
*/
|
|
10
|
+
// Call a handler once for each axis
|
|
11
|
+
function eachAxis<T>(handler: (axis: "x" | "y") => T): T[] {
|
|
12
|
+
return [handler("x"), handler("y")];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { eachAxis };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { noop } from "./noop"
|
|
2
|
+
|
|
3
|
+
export type DevMessage = (check: boolean, message: string) => void
|
|
4
|
+
|
|
5
|
+
let warning: DevMessage = noop
|
|
6
|
+
let invariant: DevMessage = noop
|
|
7
|
+
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
warning = (check, message) => {
|
|
10
|
+
if (!check && typeof console !== "undefined") {
|
|
11
|
+
console.warn(message)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
invariant = (check, message) => {
|
|
16
|
+
if (!check) {
|
|
17
|
+
throw new Error(message)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { invariant, warning }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
const fix = ()=>{
|
|
3
|
+
try{
|
|
4
|
+
|
|
5
|
+
if (!process.env){
|
|
6
|
+
process.env={};
|
|
7
|
+
}
|
|
8
|
+
return true;;
|
|
9
|
+
}catch(e){}
|
|
10
|
+
|
|
11
|
+
if (!window || (window.process && window.process.env)){
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!window.process){
|
|
16
|
+
window.process = <any>{}
|
|
17
|
+
}
|
|
18
|
+
window.process.env={};
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const fixed = fix();
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Axis, AxisBox2D, BoxDelta, Point2D } from "../../types/geometry";
|
|
6
|
+
import type { ResolvedValues, VisualElement } from "../../render/types";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
based on framer-motion@4.1.15,
|
|
12
|
+
Copyright (c) 2018 Framer B.V.
|
|
13
|
+
*/
|
|
14
|
+
import {fixed} from '../fix-process-env.js';
|
|
15
|
+
import { __read } from 'tslib';
|
|
16
|
+
import { mix } from 'popmotion';
|
|
17
|
+
import { isDraggable } from '../../render/utils/is-draggable.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reset an axis to the provided origin box.
|
|
21
|
+
*
|
|
22
|
+
* This is a mutative operation.
|
|
23
|
+
*/
|
|
24
|
+
function resetAxis(axis: Axis, originAxis: Axis) {
|
|
25
|
+
axis.min = originAxis.min;
|
|
26
|
+
axis.max = originAxis.max;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reset a box to the provided origin box.
|
|
30
|
+
*
|
|
31
|
+
* This is a mutative operation.
|
|
32
|
+
*/
|
|
33
|
+
function resetBox(box: AxisBox2D, originBox: AxisBox2D) {
|
|
34
|
+
resetAxis(box.x, originBox.x);
|
|
35
|
+
resetAxis(box.y, originBox.y);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Scales a point based on a factor and an originPoint
|
|
39
|
+
*/
|
|
40
|
+
function scalePoint(point: number, scale: number, originPoint: number) {
|
|
41
|
+
var distanceFromOrigin = point - originPoint;
|
|
42
|
+
var scaled = scale * distanceFromOrigin;
|
|
43
|
+
return originPoint + scaled;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Applies a translate/scale delta to a point
|
|
47
|
+
*/
|
|
48
|
+
function applyPointDelta(point: number, translate: number, scale: number, originPoint: number, boxScale?: number) {
|
|
49
|
+
if (boxScale !== undefined) {
|
|
50
|
+
point = scalePoint(point, boxScale, originPoint);
|
|
51
|
+
}
|
|
52
|
+
return scalePoint(point, scale, originPoint) + translate;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Applies a translate/scale delta to an axis
|
|
56
|
+
*/
|
|
57
|
+
function applyAxisDelta(axis: Axis, translate: number | undefined, scale: number | undefined, originPoint: number, boxScale?: number) {
|
|
58
|
+
if (translate === void 0) { translate = 0; }
|
|
59
|
+
if (scale === void 0) { scale = 1; }
|
|
60
|
+
axis.min = applyPointDelta(axis.min, translate, scale, originPoint, boxScale);
|
|
61
|
+
axis.max = applyPointDelta(axis.max, translate, scale, originPoint, boxScale);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Applies a translate/scale delta to a box
|
|
65
|
+
*/
|
|
66
|
+
function applyBoxDelta(box: AxisBox2D, { x, y }: BoxDelta) {
|
|
67
|
+
applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
|
|
68
|
+
applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Apply a transform to an axis from the latest resolved motion values.
|
|
72
|
+
* This function basically acts as a bridge between a flat motion value map
|
|
73
|
+
* and applyAxisDelta
|
|
74
|
+
*/
|
|
75
|
+
function applyAxisTransforms(final: Axis, axis: Axis, transforms: ResolvedValues, [key, scaleKey, originKey]: string[]) {
|
|
76
|
+
// Copy the current axis to the final axis before mutation
|
|
77
|
+
final.min = axis.min;
|
|
78
|
+
final.max = axis.max;
|
|
79
|
+
var axisOrigin = transforms[originKey] !== undefined ? transforms[originKey] : 0.5;
|
|
80
|
+
var originPoint = mix(axis.min, axis.max, axisOrigin);
|
|
81
|
+
// Apply the axis delta to the final axis
|
|
82
|
+
applyAxisDelta(final, transforms[key], transforms[scaleKey], originPoint, transforms.scale);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The names of the motion values we want to apply as translation, scale and origin.
|
|
86
|
+
*/
|
|
87
|
+
var xKeys = ["x", "scaleX", "originX"];
|
|
88
|
+
var yKeys = ["y", "scaleY", "originY"];
|
|
89
|
+
/**
|
|
90
|
+
* Apply a transform to a box from the latest resolved motion values.
|
|
91
|
+
*/
|
|
92
|
+
function applyBoxTransforms(finalBox: AxisBox2D, box: AxisBox2D, transforms: ResolvedValues) {
|
|
93
|
+
applyAxisTransforms(finalBox.x, box.x, transforms, xKeys);
|
|
94
|
+
applyAxisTransforms(finalBox.y, box.y, transforms, yKeys);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Remove a delta from a point. This is essentially the steps of applyPointDelta in reverse
|
|
98
|
+
*/
|
|
99
|
+
function removePointDelta(point: number, translate: number, scale: number, originPoint: number, boxScale?: number) {
|
|
100
|
+
point -= translate;
|
|
101
|
+
point = scalePoint(point, 1 / scale, originPoint);
|
|
102
|
+
if (boxScale !== undefined) {
|
|
103
|
+
point = scalePoint(point, 1 / boxScale, originPoint);
|
|
104
|
+
}
|
|
105
|
+
return point;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Remove a delta from an axis. This is essentially the steps of applyAxisDelta in reverse
|
|
109
|
+
*/
|
|
110
|
+
function removeAxisDelta(axis: Axis, translate?: number, scale?: number, origin?: number, boxScale?: number) {
|
|
111
|
+
if (translate === void 0) { translate = 0; }
|
|
112
|
+
if (scale === void 0) { scale = 1; }
|
|
113
|
+
if (origin === void 0) { origin = 0.5; }
|
|
114
|
+
var originPoint = mix(axis.min, axis.max, origin) - translate;
|
|
115
|
+
axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
|
|
116
|
+
axis.max = removePointDelta(axis.max, translate, scale, originPoint, boxScale);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove a transforms from an axis. This is essentially the steps of applyAxisTransforms in reverse
|
|
120
|
+
* and acts as a bridge between motion values and removeAxisDelta
|
|
121
|
+
*/
|
|
122
|
+
function removeAxisTransforms(axis: Axis, transforms: ResolvedValues, [key, scaleKey, originKey]: string[]) {
|
|
123
|
+
removeAxisDelta(axis, transforms[key], transforms[scaleKey], transforms[originKey], transforms.scale);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Remove a transforms from an box. This is essentially the steps of applyAxisBox in reverse
|
|
127
|
+
* and acts as a bridge between motion values and removeAxisDelta
|
|
128
|
+
*/
|
|
129
|
+
function removeBoxTransforms(box: AxisBox2D, transforms: ResolvedValues) {
|
|
130
|
+
removeAxisTransforms(box.x, transforms, xKeys);
|
|
131
|
+
removeAxisTransforms(box.y, transforms, yKeys);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Apply a tree of deltas to a box. We do this to calculate the effect of all the transforms
|
|
135
|
+
* in a tree upon our box before then calculating how to project it into our desired viewport-relative box
|
|
136
|
+
*
|
|
137
|
+
* This is the final nested loop within updateLayoutDelta for future refactoring
|
|
138
|
+
*/
|
|
139
|
+
function applyTreeDeltas(box: AxisBox2D, treeScale: Point2D, treePath: VisualElement[]) {
|
|
140
|
+
var treeLength = treePath.length;
|
|
141
|
+
if (!treeLength)
|
|
142
|
+
return;
|
|
143
|
+
// Reset the treeScale
|
|
144
|
+
treeScale.x = treeScale.y = 1;
|
|
145
|
+
var node;
|
|
146
|
+
var delta;
|
|
147
|
+
for (var i = 0; i < treeLength; i++) {
|
|
148
|
+
node = treePath[i];
|
|
149
|
+
delta = node.getLayoutState().delta;
|
|
150
|
+
// Incoporate each ancestor's scale into a culmulative treeScale for this component
|
|
151
|
+
treeScale.x *= delta.x.scale;
|
|
152
|
+
treeScale.y *= delta.y.scale;
|
|
153
|
+
// Apply each ancestor's calculated delta into this component's recorded layout box
|
|
154
|
+
applyBoxDelta(box, delta);
|
|
155
|
+
// If this is a draggable ancestor, also incorporate the node's transform to the layout box
|
|
156
|
+
if (isDraggable(node)) {
|
|
157
|
+
applyBoxTransforms(box, box, node.getLatestValues());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { applyAxisDelta, applyAxisTransforms, applyBoxDelta, applyBoxTransforms, applyPointDelta, applyTreeDeltas, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta, resetAxis, resetBox, scalePoint };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Axis, AxisDelta, BoxDelta, AxisBox2D } from "../../types/geometry";
|
|
6
|
+
import type { ResolvedValues } from "../../render/types";
|
|
7
|
+
import type { TargetProjection } from "../../render/utils/state";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
based on framer-motion@4.1.15,
|
|
12
|
+
Copyright (c) 2018 Framer B.V.
|
|
13
|
+
*/
|
|
14
|
+
import {fixed} from '../fix-process-env';
|
|
15
|
+
import { mix, distance, clamp, progress } from 'popmotion';
|
|
16
|
+
|
|
17
|
+
var clampProgress = function (v) { return clamp(0, 1, v); };
|
|
18
|
+
/**
|
|
19
|
+
* Returns true if the provided value is within maxDistance of the provided target
|
|
20
|
+
*/
|
|
21
|
+
function isNear(value: number, target?: number, maxDistance?: number) {
|
|
22
|
+
if (target === void 0) { target = 0; }
|
|
23
|
+
if (maxDistance === void 0) { maxDistance = 0.01; }
|
|
24
|
+
return distance(value, target) < maxDistance;
|
|
25
|
+
}
|
|
26
|
+
function calcLength(axis) {
|
|
27
|
+
return axis.max - axis.min;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculate a transform origin relative to the source axis, between 0-1, that results
|
|
31
|
+
* in an asthetically pleasing scale/transform needed to project from source to target.
|
|
32
|
+
*/
|
|
33
|
+
function calcOrigin(source: Axis, target: Axis) {
|
|
34
|
+
var origin = 0.5;
|
|
35
|
+
var sourceLength = calcLength(source);
|
|
36
|
+
var targetLength = calcLength(target);
|
|
37
|
+
if (targetLength > sourceLength) {
|
|
38
|
+
origin = progress(target.min, target.max - sourceLength, source.min);
|
|
39
|
+
}
|
|
40
|
+
else if (sourceLength > targetLength) {
|
|
41
|
+
origin = progress(source.min, source.max - targetLength, target.min);
|
|
42
|
+
}
|
|
43
|
+
return clampProgress(origin);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Update the AxisDelta with a transform that projects source into target.
|
|
47
|
+
*
|
|
48
|
+
* The transform `origin` is optional. If not provided, it'll be automatically
|
|
49
|
+
* calculated based on the relative positions of the two bounding boxes.
|
|
50
|
+
*/
|
|
51
|
+
function updateAxisDelta(delta: AxisDelta, source: Axis, target: Axis, origin?: number) {
|
|
52
|
+
if (origin === void 0) { origin = 0.5; }
|
|
53
|
+
delta.origin = origin;
|
|
54
|
+
delta.originPoint = mix(source.min, source.max, delta.origin);
|
|
55
|
+
delta.scale = calcLength(target) / calcLength(source);
|
|
56
|
+
if (isNear(delta.scale, 1, 0.0001))
|
|
57
|
+
delta.scale = 1;
|
|
58
|
+
delta.translate =
|
|
59
|
+
mix(target.min, target.max, delta.origin) - delta.originPoint;
|
|
60
|
+
if (isNear(delta.translate))
|
|
61
|
+
delta.translate = 0;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Update the BoxDelta with a transform that projects the source into the target.
|
|
65
|
+
*
|
|
66
|
+
* The transform `origin` is optional. If not provided, it'll be automatically
|
|
67
|
+
* calculated based on the relative positions of the two bounding boxes.
|
|
68
|
+
*/
|
|
69
|
+
function updateBoxDelta(delta: BoxDelta, source: AxisBox2D, target: AxisBox2D, origin: ResolvedValues) {
|
|
70
|
+
updateAxisDelta(delta.x, source.x, target.x, defaultOrigin(origin.originX));
|
|
71
|
+
updateAxisDelta(delta.y, source.y, target.y, defaultOrigin(origin.originY));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Currently this only accepts numerical origins, measured as 0-1, but could
|
|
75
|
+
* accept pixel values by comparing to the target axis.
|
|
76
|
+
*/
|
|
77
|
+
function defaultOrigin(origin) {
|
|
78
|
+
return typeof origin === "number" ? origin : 0.5;
|
|
79
|
+
}
|
|
80
|
+
function calcRelativeAxis(target: Axis, relative: Axis, parent: Axis) {
|
|
81
|
+
target.min = parent.min + relative.min;
|
|
82
|
+
target.max = target.min + calcLength(relative);
|
|
83
|
+
}
|
|
84
|
+
function calcRelativeBox(projection: TargetProjection, parentProjection: TargetProjection) {
|
|
85
|
+
calcRelativeAxis(projection.target.x, projection.relativeTarget.x, parentProjection.target.x);
|
|
86
|
+
calcRelativeAxis(projection.target.y, projection.relativeTarget.y, parentProjection.target.y);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { calcOrigin, calcRelativeAxis, calcRelativeBox, isNear, updateAxisDelta, updateBoxDelta };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Axis, AxisBox2D, BoundingBox2D, BoxDelta, TransformPoint2D } from "../../types/geometry";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Calculate the center point of the provided axis
|
|
9
|
+
*/
|
|
10
|
+
export type calcAxisCenter = ({ min, max }: Axis) => number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
based on framer-motion@4.1.15,
|
|
14
|
+
Copyright (c) 2018 Framer B.V.
|
|
15
|
+
*/
|
|
16
|
+
import { __assign } from 'tslib';
|
|
17
|
+
import { noop } from '../noop.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Bounding boxes tend to be defined as top, left, right, bottom. For various operations
|
|
21
|
+
* it's easier to consider each axis individually. This function returns a bounding box
|
|
22
|
+
* as a map of single-axis min/max values.
|
|
23
|
+
*/
|
|
24
|
+
function convertBoundingBoxToAxisBox({ top, left, right, bottom, }: BoundingBox2D) {
|
|
25
|
+
return {
|
|
26
|
+
x: { min: left, max: right },
|
|
27
|
+
y: { min: top, max: bottom },
|
|
28
|
+
} as AxisBox2D;
|
|
29
|
+
}
|
|
30
|
+
function convertAxisBoxToBoundingBox({ x, y, }: AxisBox2D) {
|
|
31
|
+
return {
|
|
32
|
+
top: y.min,
|
|
33
|
+
bottom: y.max,
|
|
34
|
+
left: x.min,
|
|
35
|
+
right: x.max,
|
|
36
|
+
} as BoundingBox2D;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Applies a TransformPoint function to a bounding box. TransformPoint is usually a function
|
|
40
|
+
* provided by Framer to allow measured points to be corrected for device scaling. This is used
|
|
41
|
+
* when measuring DOM elements and DOM event points.
|
|
42
|
+
*/
|
|
43
|
+
function transformBoundingBox({ top, left, bottom, right }: BoundingBox2D, transformPoint?: TransformPoint2D): BoundingBox2D {
|
|
44
|
+
if (transformPoint === void 0) { transformPoint = noop; }
|
|
45
|
+
var topLeft = transformPoint({ x: left, y: top });
|
|
46
|
+
var bottomRight = transformPoint({ x: right, y: bottom });
|
|
47
|
+
return {
|
|
48
|
+
top: topLeft.y,
|
|
49
|
+
left: topLeft.x,
|
|
50
|
+
bottom: bottomRight.y,
|
|
51
|
+
right: bottomRight.x,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create an empty axis box of zero size
|
|
56
|
+
*/
|
|
57
|
+
function axisBox(): AxisBox2D {
|
|
58
|
+
return { x: { min: 0, max: 1 }, y: { min: 0, max: 1 } };
|
|
59
|
+
}
|
|
60
|
+
function copyAxisBox(box: AxisBox2D): AxisBox2D {
|
|
61
|
+
return {
|
|
62
|
+
x: __assign({}, box.x),
|
|
63
|
+
y: __assign({}, box.y),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an empty box delta
|
|
68
|
+
*/
|
|
69
|
+
var zeroDelta = {
|
|
70
|
+
translate: 0,
|
|
71
|
+
scale: 1,
|
|
72
|
+
origin: 0,
|
|
73
|
+
originPoint: 0,
|
|
74
|
+
};
|
|
75
|
+
function delta(): BoxDelta {
|
|
76
|
+
return {
|
|
77
|
+
x: __assign({}, zeroDelta),
|
|
78
|
+
y: __assign({}, zeroDelta),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { axisBox, convertAxisBoxToBoundingBox, convertBoundingBoxToAxisBox, copyAxisBox, delta, transformBoundingBox };
|
|
83
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
based on framer-motion@4.0.3,
|
|
8
|
+
Copyright (c) 2018 Framer B.V.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
|
12
|
+
*/
|
|
13
|
+
var isNumericalString = function (v: string) { return /^\-?\d*\.?\d+$/.test(v); };
|
|
14
|
+
|
|
15
|
+
export { isNumericalString };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MutableRefObject } from "react";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
based on framer-motion@4.0.3,
|
|
9
|
+
Copyright (c) 2018 Framer B.V.
|
|
10
|
+
*/
|
|
11
|
+
function isRefObject<E = any>(ref: any): ref is MutableRefObject<E> {
|
|
12
|
+
return (typeof ref === "object" &&
|
|
13
|
+
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { isRefObject };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
// export declare function noop<T>(any: T): T;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
based on framer-motion@4.0.3,
|
|
9
|
+
Copyright (c) 2018 Framer B.V.
|
|
10
|
+
*/
|
|
11
|
+
function noop<T>(any: T) {
|
|
12
|
+
return any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { noop };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { CustomValueType, ValueTarget, SingleTarget } from "../types";
|
|
6
|
+
// export declare const isCustomValue: (v: any) => v is CustomValueType;
|
|
7
|
+
// export declare const resolveFinalValueInKeyframes: (v: ValueTarget) => SingleTarget;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
based on framer-motion@4.0.3,
|
|
11
|
+
Copyright (c) 2018 Framer B.V.
|
|
12
|
+
*/
|
|
13
|
+
import { isKeyframesTarget } from '../animation/utils/is-keyframes-target.js';
|
|
14
|
+
|
|
15
|
+
var isCustomValue = function (v: any): v is CustomValueType {
|
|
16
|
+
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
17
|
+
};
|
|
18
|
+
var resolveFinalValueInKeyframes = function (v: ValueTarget): SingleTarget {
|
|
19
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
20
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { isCustomValue, resolveFinalValueInKeyframes };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
based on framer-motion@4.0.3,
|
|
8
|
+
Copyright (c) 2018 Framer B.V.
|
|
9
|
+
*/
|
|
10
|
+
function shallowCompare(next: any[], prev: any[] | null) {
|
|
11
|
+
if (!Array.isArray(prev))
|
|
12
|
+
return false;
|
|
13
|
+
var prevLength = prev.length;
|
|
14
|
+
if (prevLength !== next.length)
|
|
15
|
+
return false;
|
|
16
|
+
for (var i = 0; i < prevLength; i++) {
|
|
17
|
+
if (prev[i] !== next[i])
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { shallowCompare };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
type GenericHandler = (...args: any) => void;
|
|
6
|
+
class SubscriptionManager<Handler extends GenericHandler> {
|
|
7
|
+
private subscriptions: Function[] = [];
|
|
8
|
+
add(handler: Handler) {
|
|
9
|
+
addUniqueItem(this.subscriptions, handler);
|
|
10
|
+
return () => { return removeItem(this.subscriptions, handler); };
|
|
11
|
+
}
|
|
12
|
+
notify(a?: Parameters<Handler>[0], b?: Parameters<Handler>[1], c?: Parameters<Handler>[2]) {
|
|
13
|
+
var numSubscriptions = this.subscriptions.length;
|
|
14
|
+
if (!numSubscriptions)
|
|
15
|
+
return;
|
|
16
|
+
if (numSubscriptions === 1) {
|
|
17
|
+
/**
|
|
18
|
+
* If there's only a single handler we can just call it without invoking a loop.
|
|
19
|
+
*/
|
|
20
|
+
this.subscriptions[0](a, b, c);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
for (var i = 0; i < numSubscriptions; i++) {
|
|
24
|
+
/**
|
|
25
|
+
* Check whether the handler exists before firing as it's possible
|
|
26
|
+
* the subscriptions were modified during this loop running.
|
|
27
|
+
*/
|
|
28
|
+
var handler = this.subscriptions[i];
|
|
29
|
+
handler && handler(a, b, c);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getSize() {
|
|
34
|
+
return this.subscriptions.length;
|
|
35
|
+
}
|
|
36
|
+
clear() {
|
|
37
|
+
this.subscriptions.length = 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
based on framer-motion@4.0.3,
|
|
43
|
+
Copyright (c) 2018 Framer B.V.
|
|
44
|
+
*/
|
|
45
|
+
import { addUniqueItem, removeItem } from './array.js';
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export { SubscriptionManager };
|
|
49
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
based on framer-motion@4.0.3,
|
|
8
|
+
Copyright (c) 2018 Framer B.V.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Converts seconds to milliseconds
|
|
12
|
+
*
|
|
13
|
+
* @param seconds - Time in seconds.
|
|
14
|
+
* @return milliseconds - Converted time in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
var secondsToMilliseconds = function (seconds: number) { return seconds * 1000; };
|
|
17
|
+
|
|
18
|
+
export { secondsToMilliseconds };
|