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,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { VisualElement } from "../../render/types";
|
|
6
|
+
import type { VisualState } from "./use-visual-state";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
based on framer-motion@4.0.3,
|
|
11
|
+
Copyright (c) 2018 Framer B.V.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { isRefObject } from '../../utils/is-ref-object.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a ref function that, when called, hydrates the provided
|
|
18
|
+
* external ref and VisualElement.
|
|
19
|
+
*/
|
|
20
|
+
function useMotionRef<Instance, RenderState>(visualState: VisualState<Instance, RenderState>, visualElement?: VisualElement<Instance> | null, externalRef?: React.Ref<Instance>): React.Ref<Instance> {
|
|
21
|
+
return function (instance) {
|
|
22
|
+
var _a;
|
|
23
|
+
instance && ((_a = visualState.mount) === null || _a === void 0 ? void 0 : _a.call(visualState, instance));
|
|
24
|
+
if (visualElement) {
|
|
25
|
+
instance
|
|
26
|
+
? visualElement.mount(instance)
|
|
27
|
+
: visualElement.unmount();
|
|
28
|
+
}
|
|
29
|
+
if (externalRef) {
|
|
30
|
+
if (typeof externalRef === "function") {
|
|
31
|
+
externalRef(instance);
|
|
32
|
+
}
|
|
33
|
+
else if (isRefObject(externalRef)) {
|
|
34
|
+
externalRef.current = instance;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { useMotionRef };
|
|
41
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionProps } from "../../motion/types";
|
|
6
|
+
import type { CreateVisualElement, VisualElement } from "../../render/types";
|
|
7
|
+
import type { VisualState } from "./use-visual-state";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export type useVisualElement = <Instance, RenderState>(Component: string | React.ComponentType, visualState: VisualState<Instance, RenderState>, props: MotionProps, createVisualElement?: CreateVisualElement<Instance>) => VisualElement<Instance> | undefined;
|
|
11
|
+
|
|
12
|
+
export { default as UseVisualElement } from './UseVisualElement.svelte';
|
|
13
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { ResolvedValues, ScrapeMotionValuesFromProps } from "../../render/types";
|
|
6
|
+
import type { MotionProps } from "../types";
|
|
7
|
+
import type UseVisualState from "./UseVisualState.svelte";
|
|
8
|
+
|
|
9
|
+
export interface VisualState<Instance, RenderState> {
|
|
10
|
+
renderState: RenderState;
|
|
11
|
+
latestValues: ResolvedValues;
|
|
12
|
+
mount?: (instance: Instance) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// type UseVisualState<Instance, RenderState> = (props: MotionProps, isStatic: boolean) => VisualState<Instance, RenderState>;
|
|
16
|
+
export interface UseVisualStateConfig<Instance, RenderState> {
|
|
17
|
+
scrapeMotionValuesFromProps: ScrapeMotionValuesFromProps;
|
|
18
|
+
createRenderState: () => RenderState;
|
|
19
|
+
onMount?: (props: MotionProps, instance: Instance, visualState: VisualState<Instance, RenderState>) => void;
|
|
20
|
+
}
|
|
21
|
+
export type makeUseVisualState = <I, RS>(config: UseVisualStateConfig<I, RS>) => typeof UseVisualState<I, RS>;
|
|
22
|
+
|
|
23
|
+
export { default as UseVisualState } from './UseVisualState.svelte';
|
|
24
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
based on framer-motion@4.0.3,
|
|
9
|
+
Copyright (c) 2018 Framer B.V.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A list of all valid MotionProps.
|
|
13
|
+
*
|
|
14
|
+
* @internalremarks
|
|
15
|
+
* This doesn't throw if a `MotionProp` name is missing - it should.
|
|
16
|
+
*/
|
|
17
|
+
var validMotionProps = new Set([
|
|
18
|
+
"initial",
|
|
19
|
+
"animate",
|
|
20
|
+
"exit",
|
|
21
|
+
"style",
|
|
22
|
+
"variants",
|
|
23
|
+
"transition",
|
|
24
|
+
"transformTemplate",
|
|
25
|
+
"transformValues",
|
|
26
|
+
"custom",
|
|
27
|
+
"inherit",
|
|
28
|
+
"layout",
|
|
29
|
+
"layoutId",
|
|
30
|
+
"onLayoutAnimationComplete",
|
|
31
|
+
"onViewportBoxUpdate",
|
|
32
|
+
"onLayoutMeasure",
|
|
33
|
+
"onBeforeLayoutMeasure",
|
|
34
|
+
"onAnimationStart",
|
|
35
|
+
"onAnimationComplete",
|
|
36
|
+
"onUpdate",
|
|
37
|
+
"onDragStart",
|
|
38
|
+
"onDrag",
|
|
39
|
+
"onDragEnd",
|
|
40
|
+
"onMeasureDragConstraints",
|
|
41
|
+
"onDirectionLock",
|
|
42
|
+
"onDragTransitionEnd",
|
|
43
|
+
"drag",
|
|
44
|
+
"dragControls",
|
|
45
|
+
"dragListener",
|
|
46
|
+
"dragConstraints",
|
|
47
|
+
"dragDirectionLock",
|
|
48
|
+
"_dragX",
|
|
49
|
+
"_dragY",
|
|
50
|
+
"dragElastic",
|
|
51
|
+
"dragMomentum",
|
|
52
|
+
"dragPropagation",
|
|
53
|
+
"dragTransition",
|
|
54
|
+
"whileDrag",
|
|
55
|
+
"onPan",
|
|
56
|
+
"onPanStart",
|
|
57
|
+
"onPanEnd",
|
|
58
|
+
"onPanSessionStart",
|
|
59
|
+
"onTap",
|
|
60
|
+
"onTapStart",
|
|
61
|
+
"onTapCancel",
|
|
62
|
+
"onHoverStart",
|
|
63
|
+
"onHoverEnd",
|
|
64
|
+
"whileFocus",
|
|
65
|
+
"whileTap",
|
|
66
|
+
"whileHover",
|
|
67
|
+
]);
|
|
68
|
+
/**
|
|
69
|
+
* Check whether a prop name is a valid `MotionProp` key.
|
|
70
|
+
*
|
|
71
|
+
* @param key - Name of the property to check
|
|
72
|
+
* @returns `true` is key is a valid `MotionProp`.
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
function isValidMotionProp(key: string): boolean {
|
|
77
|
+
return validMotionProps.has(key);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { isValidMotionProp };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- <svelte:options runes={true}/> -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import type { SvelteHTMLElements } from "svelte/elements";
|
|
4
|
+
import type { Snippet } from "svelte";
|
|
5
|
+
import type { MotionProps } from "../../motion";
|
|
6
|
+
import Motion from "../../motion/Motion.svelte";
|
|
7
|
+
|
|
8
|
+
// let {as, class: className, children, ...restProps}: {as: keyof SvelteHTMLElements, children: Snippet, class: string } & MotionProps = $props();
|
|
9
|
+
export let ___tag: keyof SvelteHTMLElements;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<Motion {...$$restProps} let:props let:motion>
|
|
13
|
+
<svelte:element this={___tag} class={props.class} use:motion {...props}>
|
|
14
|
+
<slot />
|
|
15
|
+
</svelte:element>
|
|
16
|
+
</Motion>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!-- based on framer-motion@4.0.3,
|
|
2
|
+
Copyright (c) 2018 Framer B.V. -->
|
|
3
|
+
|
|
4
|
+
<script lang="ts">
|
|
5
|
+
import { UseHTMLProps } from "../html/use-props.js";
|
|
6
|
+
import { UseSVGProps } from "../svg/use-props.js";
|
|
7
|
+
import { filterProps } from "./utils/filter-props.js";
|
|
8
|
+
|
|
9
|
+
export let props,
|
|
10
|
+
visualState,
|
|
11
|
+
Component,
|
|
12
|
+
forwardMotionProps = false,
|
|
13
|
+
isStatic,
|
|
14
|
+
ref,
|
|
15
|
+
targetEl = undefined;
|
|
16
|
+
const motion = (node) => {
|
|
17
|
+
ref(node);
|
|
18
|
+
};
|
|
19
|
+
$: filteredProps = filterProps(
|
|
20
|
+
props,
|
|
21
|
+
typeof Component === "string",
|
|
22
|
+
forwardMotionProps
|
|
23
|
+
);
|
|
24
|
+
$: if (targetEl) {
|
|
25
|
+
motion(targetEl);
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<svelte:component
|
|
30
|
+
this={Component === "SVG" ? UseSVGProps : UseHTMLProps}
|
|
31
|
+
{visualState}
|
|
32
|
+
{isStatic}
|
|
33
|
+
{props}
|
|
34
|
+
let:visualProps
|
|
35
|
+
>
|
|
36
|
+
<slot {motion} props={{ ...filteredProps, ...visualProps }} />
|
|
37
|
+
</svelte:component>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.0.3,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import Motion from '../../motion/Motion.svelte';
|
|
6
|
+
import { loadFeatures } from "../../motion/features/definitions"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const createMotionClass = (features)=>{
|
|
10
|
+
features && loadFeatures(features)
|
|
11
|
+
return Motion;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { CreateVisualElement } from "../types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
based on framer-motion@4.0.3,
|
|
9
|
+
Copyright (c) 2018 Framer B.V.
|
|
10
|
+
*/
|
|
11
|
+
import { htmlVisualElement } from '../html/visual-element.js';
|
|
12
|
+
import { svgVisualElement } from '../svg/visual-element.js';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var createDomVisualElement: CreateVisualElement<HTMLElement | SVGElement> = function (Component, options) {
|
|
16
|
+
|
|
17
|
+
return Component === "SVG"
|
|
18
|
+
? svgVisualElement(options, { enableHardwareAcceleration: false })
|
|
19
|
+
: htmlVisualElement(options, { enableHardwareAcceleration: true });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { createDomVisualElement };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
// import type { FeatureBundle } from "../../motion/features/types";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { animations } from "../../motion/features/animations";
|
|
13
|
+
import { drag } from "../../motion/features/drag";
|
|
14
|
+
import { gestureAnimations } from "../../motion/features/gestures";
|
|
15
|
+
import { layoutAnimations } from "../../motion/features/layout";
|
|
16
|
+
|
|
17
|
+
export const featureBundle = {
|
|
18
|
+
...animations,
|
|
19
|
+
...gestureAnimations,
|
|
20
|
+
...drag,
|
|
21
|
+
...layoutAnimations,
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
based on framer-motion@4.1.17,
|
|
4
|
+
Copyright (c) 2018 Framer B.V.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { layoutAnimations } from '../../motion/features/layout/index.js';
|
|
13
|
+
//import { createMotionProxy } from './motion-proxy.js';
|
|
14
|
+
import {createMotionClass} from './create-motion-class.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
var m = /*@__PURE__*/ //createMotionProxy([MeasureLayout]);
|
|
20
|
+
createMotionClass({...layoutAnimations}) as unknown as (<Props>(Component: string | import("react").ComponentType<Props>, customMotionComponentConfig?: import("./motion-proxy").CustomMotionComponentConfig) => import("./motion-proxy").CustomDomComponent<Props>) & import("../html/types").HTMLMotionComponents & import("../svg/types").SVGMotionComponents
|
|
21
|
+
|
|
22
|
+
export { m as M };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { MotionComponentConfig } from "../../motion/index.js";
|
|
6
|
+
import type { MotionProps } from "../../motion/types.js";
|
|
7
|
+
/**
|
|
8
|
+
* I'd rather the return type of `custom` to be implicit but this throws
|
|
9
|
+
* incorrect relative paths in the exported types and API Extractor throws
|
|
10
|
+
* a wobbly.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export type CustomDomComponent<Props> = React.ForwardRefExoticComponent<React.PropsWithoutRef<Props & MotionProps> & React.RefAttributes<SVGElement | HTMLElement>>;
|
|
15
|
+
export interface CustomMotionComponentConfig {
|
|
16
|
+
forwardMotionProps?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type CreateConfig = <Instance, RenderState, Props>(Component: string | React.ComponentType<Props>, config: CustomMotionComponentConfig) => MotionComponentConfig<Instance, RenderState>;
|
|
19
|
+
/**
|
|
20
|
+
* Convert any React component into a `motion` component. The provided component
|
|
21
|
+
* **must** use `React.forwardRef` to the underlying DOM component you want to animate.
|
|
22
|
+
*
|
|
23
|
+
* ```jsx
|
|
24
|
+
* const Component = React.forwardRef((props, ref) => {
|
|
25
|
+
* return <div ref={ref} />
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* const MotionComponent = motion(Component)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
// export declare function createMotionProxy(createConfig: CreateConfig): (<Props>(Component: string | React.ComponentType<Props>, customMotionComponentConfig?: CustomMotionComponentConfig) => CustomDomComponent<Props>) & import("../html/types").HTMLMotionComponents & import("../svg/types").SVGMotionComponents;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
based on framer-motion@4.0.3,
|
|
38
|
+
Copyright (c) 2018 Framer B.V.
|
|
39
|
+
*/
|
|
40
|
+
import type { Component, Snippet } from 'svelte';
|
|
41
|
+
import type { SvelteHTMLElements } from 'svelte/elements';
|
|
42
|
+
import Mo from './M.svelte';
|
|
43
|
+
import { isSVGComponent } from './utils/is-svg-component.js';
|
|
44
|
+
|
|
45
|
+
type M<Element extends keyof SvelteHTMLElements> = MotionProps & {children: Snippet, class: string} & Omit<SvelteHTMLElements[Element], 'style'>;
|
|
46
|
+
type motion<Element extends keyof SvelteHTMLElements> = Component<M<Element>>;
|
|
47
|
+
/**
|
|
48
|
+
* Convert any React component into a `motion` component. The provided component
|
|
49
|
+
* **must** use `React.forwardRef` to the underlying DOM component you want to animate.
|
|
50
|
+
*
|
|
51
|
+
* ```jsx
|
|
52
|
+
* const Component = React.forwardRef((props, ref) => {
|
|
53
|
+
* return <div ref={ref} />
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* const MotionComponent = motion(Component)
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function createMotionProxy(): { [P in keyof SvelteHTMLElements]: motion<P> } {
|
|
62
|
+
return new Proxy(
|
|
63
|
+
{},
|
|
64
|
+
{
|
|
65
|
+
get(_target, key: string) {
|
|
66
|
+
let type = false;
|
|
67
|
+
if (key.toString().slice(0, 1) === key.toString().slice(0, 1).toLowerCase()) {
|
|
68
|
+
type = isSVGComponent(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return new Proxy(Mo, {
|
|
72
|
+
construct(target, args) {
|
|
73
|
+
if (!args || !args[0]) {
|
|
74
|
+
args.push({});
|
|
75
|
+
}
|
|
76
|
+
if (!args[0]?.props) {
|
|
77
|
+
args[0].props = { ___tag: key, isSVG: type };
|
|
78
|
+
} else {
|
|
79
|
+
args[0].props.___tag = key;
|
|
80
|
+
args[0].props.isSVG = type;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log(target, args);
|
|
84
|
+
|
|
85
|
+
return new target(...args);
|
|
86
|
+
},
|
|
87
|
+
// support svelte 5
|
|
88
|
+
apply(target, thisArg, args) {
|
|
89
|
+
if (!args[1]) {
|
|
90
|
+
args[1] = { ___tag: key, isSVG: type };
|
|
91
|
+
} else {
|
|
92
|
+
args[1].___tag = key;
|
|
93
|
+
args[1].isSVG = type;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return target(...args);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
) as { [P in keyof SvelteHTMLElements]: motion<P> };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const M = createMotionProxy();
|
|
105
|
+
|
|
106
|
+
export { M, createMotionProxy };
|
|
107
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
// import { SvelteComponent } from "svelte";
|
|
6
|
+
import type { DOMMotionComponents } from "./types.js";
|
|
7
|
+
// import type { CustomMotionComponentConfig} from './motion-proxy.js'
|
|
8
|
+
// import type { MotionProps } from "../../motion/types.js";
|
|
9
|
+
|
|
10
|
+
export interface IsSVG{
|
|
11
|
+
/** set to true if the component receiving the motion action is an svg-element like `circle` or `path`. Should not be set to true for `svg` tags. */
|
|
12
|
+
isSVG?:boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
based on framer-motion@4.0.3,
|
|
17
|
+
Copyright (c) 2018 Framer B.V.
|
|
18
|
+
*/
|
|
19
|
+
import { createMotionComponent } from '../../motion/index.js';
|
|
20
|
+
import { createMotionClass } from './create-motion-class.js';
|
|
21
|
+
import { createDomVisualElement } from './create-visual-element.js';
|
|
22
|
+
import { featureBundle } from './featureBundle.js';
|
|
23
|
+
//import { createMotionProxy } from './motion-proxy.js';
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
29
|
+
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
var motion = /*@__PURE__*/ //createMotionProxy(allMotionFeatures);
|
|
34
|
+
createMotionClass(featureBundle)
|
|
35
|
+
/**
|
|
36
|
+
* Create a DOM `motion` component with the provided string. This is primarily intended
|
|
37
|
+
* as a full alternative to `motion` for consumers who have to support environments that don't
|
|
38
|
+
* support `Proxy`.
|
|
39
|
+
*
|
|
40
|
+
* ```javascript
|
|
41
|
+
* import { createDomMotionComponent } from "framer-motion"
|
|
42
|
+
*
|
|
43
|
+
* const motion = {
|
|
44
|
+
* div: createDomMotionComponent('div')
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
function createDomMotionComponent<T extends keyof DOMMotionComponents>(key: T): DOMMotionComponents[T] {
|
|
51
|
+
var config = {
|
|
52
|
+
createVisualElement: createDomVisualElement(key),
|
|
53
|
+
//useRender: createUseRender(key, false),
|
|
54
|
+
forwardMotionProps: key.forwardMotionProps,
|
|
55
|
+
Component: key.Component,
|
|
56
|
+
defaultFeatures: allMotionFeatures,
|
|
57
|
+
};
|
|
58
|
+
return createMotionComponent(config);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { motion as Motion, createDomMotionComponent };
|
|
62
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { VisualElement } from "../../types";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.1.11,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { calcRelativeOffset } from '../../../motion/features/layout/utils.js';
|
|
14
|
+
import { eachAxis } from '../../../utils/each-axis.js';
|
|
15
|
+
import { removeBoxTransforms } from '../../../utils/geometry/delta-apply.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns a boolean stating whether or not we converted the projection
|
|
19
|
+
* to relative projection.
|
|
20
|
+
*/
|
|
21
|
+
function convertToRelativeProjection(visualElement: VisualElement, isLayoutDrag?: boolean) {
|
|
22
|
+
if (isLayoutDrag === void 0) { isLayoutDrag = true; }
|
|
23
|
+
var projectionParent = visualElement.getProjectionParent();
|
|
24
|
+
if (!projectionParent)
|
|
25
|
+
return false;
|
|
26
|
+
var offset;
|
|
27
|
+
if (isLayoutDrag) {
|
|
28
|
+
offset = calcRelativeOffset(projectionParent.projection.target, visualElement.projection.target);
|
|
29
|
+
removeBoxTransforms(offset, projectionParent.getLatestValues());
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
offset = calcRelativeOffset(projectionParent.getLayoutState().layout, visualElement.getLayoutState().layout);
|
|
33
|
+
}
|
|
34
|
+
eachAxis(function (axis) {
|
|
35
|
+
return visualElement.setProjectionTargetAxis(axis, offset[axis].min, offset[axis].max, true);
|
|
36
|
+
});
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { convertToRelativeProjection };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { Axis } from "../../../types/geometry";
|
|
6
|
+
import type { LayoutState, TargetProjection } from "../../utils/state";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
based on framer-motion@4.0.3,
|
|
11
|
+
Copyright (c) 2018 Framer B.V.
|
|
12
|
+
*/
|
|
13
|
+
import {fixed} from '../../../utils/fix-process-env.js';
|
|
14
|
+
import { __assign } from 'tslib';
|
|
15
|
+
import { complex, px } from 'style-value-types';
|
|
16
|
+
import { mix } from 'popmotion';
|
|
17
|
+
import { cssVariableRegex } from '../utils/css-variables-conversion.js';
|
|
18
|
+
|
|
19
|
+
function pixelsToPercent(pixels: number, axis: Axis) {
|
|
20
|
+
return (pixels / (axis.max - axis.min)) * 100;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* We always correct borderRadius as a percentage rather than pixels to reduce paints.
|
|
24
|
+
* For example, if you are projecting a box that is 100px wide with a 10px borderRadius
|
|
25
|
+
* into a box that is 200px wide with a 20px borderRadius, that is actually a 10%
|
|
26
|
+
* borderRadius in both states. If we animate between the two in pixels that will trigger
|
|
27
|
+
* a paint each time. If we animate between the two in percentage we'll avoid a paint.
|
|
28
|
+
*/
|
|
29
|
+
function correctBorderRadius(latest: string | number, _layoutState: LayoutState, { target }: TargetProjection) {
|
|
30
|
+
/**
|
|
31
|
+
* If latest is a string, if it's a percentage we can return immediately as it's
|
|
32
|
+
* going to be stretched appropriately. Otherwise, if it's a pixel, convert it to a number.
|
|
33
|
+
*/
|
|
34
|
+
if (typeof latest === "string") {
|
|
35
|
+
if (px.test(latest)) {
|
|
36
|
+
latest = parseFloat(latest);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return latest;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
|
|
44
|
+
* pixel value as a percentage of each axis
|
|
45
|
+
*/
|
|
46
|
+
var x = pixelsToPercent(latest, target.x);
|
|
47
|
+
var y = pixelsToPercent(latest, target.y);
|
|
48
|
+
return x + "% " + y + "%";
|
|
49
|
+
}
|
|
50
|
+
var varToken = "_$css";
|
|
51
|
+
function correctBoxShadow(latest: string, { delta, treeScale }: LayoutState) {
|
|
52
|
+
var original = latest;
|
|
53
|
+
/**
|
|
54
|
+
* We need to first strip and store CSS variables from the string.
|
|
55
|
+
*/
|
|
56
|
+
var containsCSSVariables = latest.includes("var(");
|
|
57
|
+
var cssVariables = [];
|
|
58
|
+
if (containsCSSVariables) {
|
|
59
|
+
latest = latest.replace(cssVariableRegex, function (match) {
|
|
60
|
+
cssVariables.push(match);
|
|
61
|
+
return varToken;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var shadow = complex.parse(latest);
|
|
65
|
+
// TODO: Doesn't support multiple shadows
|
|
66
|
+
if (shadow.length > 5)
|
|
67
|
+
return original;
|
|
68
|
+
var template = complex.createTransformer(latest);
|
|
69
|
+
var offset = typeof shadow[0] !== "number" ? 1 : 0;
|
|
70
|
+
// Calculate the overall context scale
|
|
71
|
+
var xScale = delta.x.scale * treeScale.x;
|
|
72
|
+
var yScale = delta.y.scale * treeScale.y;
|
|
73
|
+
shadow[0 + offset] /= xScale;
|
|
74
|
+
shadow[1 + offset] /= yScale;
|
|
75
|
+
/**
|
|
76
|
+
* Ideally we'd correct x and y scales individually, but because blur and
|
|
77
|
+
* spread apply to both we have to take a scale average and apply that instead.
|
|
78
|
+
* We could potentially improve the outcome of this by incorporating the ratio between
|
|
79
|
+
* the two scales.
|
|
80
|
+
*/
|
|
81
|
+
var averageScale = mix(xScale, yScale, 0.5);
|
|
82
|
+
// Blur
|
|
83
|
+
if (typeof shadow[2 + offset] === "number")
|
|
84
|
+
shadow[2 + offset] /= averageScale;
|
|
85
|
+
// Spread
|
|
86
|
+
if (typeof shadow[3 + offset] === "number")
|
|
87
|
+
shadow[3 + offset] /= averageScale;
|
|
88
|
+
var output = template(shadow);
|
|
89
|
+
if (containsCSSVariables) {
|
|
90
|
+
var i_1 = 0;
|
|
91
|
+
output = output.replace(varToken, function () {
|
|
92
|
+
var cssVariable = cssVariables[i_1];
|
|
93
|
+
i_1++;
|
|
94
|
+
return cssVariable;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return output;
|
|
98
|
+
}
|
|
99
|
+
var borderCorrectionDefinition = {
|
|
100
|
+
process: correctBorderRadius,
|
|
101
|
+
};
|
|
102
|
+
var defaultScaleCorrectors = {
|
|
103
|
+
borderRadius: __assign(__assign({}, borderCorrectionDefinition), { applyTo: [
|
|
104
|
+
"borderTopLeftRadius",
|
|
105
|
+
"borderTopRightRadius",
|
|
106
|
+
"borderBottomLeftRadius",
|
|
107
|
+
"borderBottomRightRadius",
|
|
108
|
+
] }),
|
|
109
|
+
borderTopLeftRadius: borderCorrectionDefinition,
|
|
110
|
+
borderTopRightRadius: borderCorrectionDefinition,
|
|
111
|
+
borderBottomLeftRadius: borderCorrectionDefinition,
|
|
112
|
+
borderBottomRightRadius: borderCorrectionDefinition,
|
|
113
|
+
boxShadow: {
|
|
114
|
+
process: correctBoxShadow,
|
|
115
|
+
},
|
|
116
|
+
} as {
|
|
117
|
+
borderRadius: {
|
|
118
|
+
applyTo: string[];
|
|
119
|
+
process: typeof correctBorderRadius;
|
|
120
|
+
};
|
|
121
|
+
borderTopLeftRadius: {
|
|
122
|
+
process: typeof correctBorderRadius;
|
|
123
|
+
};
|
|
124
|
+
borderTopRightRadius: {
|
|
125
|
+
process: typeof correctBorderRadius;
|
|
126
|
+
};
|
|
127
|
+
borderBottomLeftRadius: {
|
|
128
|
+
process: typeof correctBorderRadius;
|
|
129
|
+
};
|
|
130
|
+
borderBottomRightRadius: {
|
|
131
|
+
process: typeof correctBorderRadius;
|
|
132
|
+
};
|
|
133
|
+
boxShadow: {
|
|
134
|
+
process: typeof correctBoxShadow;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export { correctBorderRadius, correctBoxShadow, defaultScaleCorrectors, pixelsToPercent };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
based on framer-motion@4.1.17,
|
|
3
|
+
Copyright (c) 2018 Framer B.V.
|
|
4
|
+
*/
|
|
5
|
+
import type { TransformPoint2D, AxisBox2D } from "../../../types/geometry";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
based on framer-motion@4.0.3,
|
|
10
|
+
Copyright (c) 2018 Framer B.V.
|
|
11
|
+
*/
|
|
12
|
+
import { convertBoundingBoxToAxisBox, transformBoundingBox } from '../../../utils/geometry/index.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Measure and return the element bounding box.
|
|
16
|
+
*
|
|
17
|
+
* We convert the box into an AxisBox2D to make it easier to work with each axis
|
|
18
|
+
* individually and programmatically.
|
|
19
|
+
*
|
|
20
|
+
* This function optionally accepts a transformPagePoint function which allows us to compensate
|
|
21
|
+
* for, for instance, measuring the element within a scaled plane like a Framer devivce preview component.
|
|
22
|
+
*/
|
|
23
|
+
function getBoundingBox(element: Element, transformPagePoint?: TransformPoint2D) {
|
|
24
|
+
var box = element.getBoundingClientRect();
|
|
25
|
+
return convertBoundingBoxToAxisBox(transformBoundingBox(box, transformPagePoint));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { getBoundingBox };
|