motion-v 2.0.1 → 2.2.0
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/dist/es/components/reorder/index.d.ts +4 -4
- package/dist/es/index.d.ts +2 -2
- package/dist/es/index.mjs +4 -3
- package/dist/es/types/framer-motion.d.ts +10 -0
- package/dist/es/types/index.d.ts +1 -1
- package/dist/es/value/index.d.ts +1 -0
- package/dist/es/value/scroll/offsets.d.ts +31 -0
- package/dist/es/value/scroll/offsets.mjs +56 -0
- package/dist/es/value/use-combine-values.mjs +2 -2
- package/dist/es/value/use-scroll.d.ts +3 -3
- package/dist/es/value/use-scroll.mjs +34 -7
- package/dist/es/value/use-spring.d.ts +6 -3
- package/dist/es/value/use-spring.mjs +21 -42
- package/dist/es/value/use-transform.mjs +18 -4
- package/package.json +4 -4
|
@@ -747,6 +747,7 @@ export declare const ReorderGroup: <T, K, V>(__VLS_props: NonNullable<Awaited<ty
|
|
|
747
747
|
inViewOptions?: import('../../features/gestures/in-view/types').InViewOptions & {
|
|
748
748
|
once?: boolean;
|
|
749
749
|
};
|
|
750
|
+
inherit?: boolean;
|
|
750
751
|
onUpdate?: (latest: import('motion-dom').ResolvedValues) => void;
|
|
751
752
|
onDragTransitionEnd?: () => void;
|
|
752
753
|
onDragEnd?: (event: PointerEvent, info: import('motion-dom').PanInfo) => void;
|
|
@@ -757,7 +758,6 @@ export declare const ReorderGroup: <T, K, V>(__VLS_props: NonNullable<Awaited<ty
|
|
|
757
758
|
dragTransition?: import('motion-dom').InertiaOptions;
|
|
758
759
|
transformTemplate?: (transform: import('motion-dom').TransformProperties, generatedTransform: string) => string;
|
|
759
760
|
dragDirectionLock?: boolean;
|
|
760
|
-
inherit?: boolean;
|
|
761
761
|
onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
|
|
762
762
|
onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
|
|
763
763
|
onBeforeLayoutMeasure?: (box: import('motion-utils').Box) => void;
|
|
@@ -1532,6 +1532,7 @@ export declare const ReorderItem: <T extends import('../..').ElementType = "li",
|
|
|
1532
1532
|
inViewOptions?: import('../../features/gestures/in-view/types').InViewOptions & {
|
|
1533
1533
|
once?: boolean;
|
|
1534
1534
|
};
|
|
1535
|
+
inherit?: boolean;
|
|
1535
1536
|
onUpdate?: (latest: import('motion-dom').ResolvedValues) => void;
|
|
1536
1537
|
onDragTransitionEnd?: () => void;
|
|
1537
1538
|
onDragEnd?: (event: PointerEvent, info: import('motion-dom').PanInfo) => void;
|
|
@@ -1542,7 +1543,6 @@ export declare const ReorderItem: <T extends import('../..').ElementType = "li",
|
|
|
1542
1543
|
dragTransition?: import('motion-dom').InertiaOptions;
|
|
1543
1544
|
transformTemplate?: (transform: import('motion-dom').TransformProperties, generatedTransform: string) => string;
|
|
1544
1545
|
dragDirectionLock?: boolean;
|
|
1545
|
-
inherit?: boolean;
|
|
1546
1546
|
onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
|
|
1547
1547
|
onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
|
|
1548
1548
|
onBeforeLayoutMeasure?: (box: import('motion-utils').Box) => void;
|
|
@@ -2320,6 +2320,7 @@ export declare const Reorder: {
|
|
|
2320
2320
|
inViewOptions?: import('../../features/gestures/in-view/types').InViewOptions & {
|
|
2321
2321
|
once?: boolean;
|
|
2322
2322
|
};
|
|
2323
|
+
inherit?: boolean;
|
|
2323
2324
|
onUpdate?: (latest: import('motion-dom').ResolvedValues) => void;
|
|
2324
2325
|
onDragTransitionEnd?: () => void;
|
|
2325
2326
|
onDragEnd?: (event: PointerEvent, info: import('motion-dom').PanInfo) => void;
|
|
@@ -2330,7 +2331,6 @@ export declare const Reorder: {
|
|
|
2330
2331
|
dragTransition?: import('motion-dom').InertiaOptions;
|
|
2331
2332
|
transformTemplate?: (transform: import('motion-dom').TransformProperties, generatedTransform: string) => string;
|
|
2332
2333
|
dragDirectionLock?: boolean;
|
|
2333
|
-
inherit?: boolean;
|
|
2334
2334
|
onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
|
|
2335
2335
|
onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
|
|
2336
2336
|
onBeforeLayoutMeasure?: (box: import('motion-utils').Box) => void;
|
|
@@ -3105,6 +3105,7 @@ export declare const Reorder: {
|
|
|
3105
3105
|
inViewOptions?: import('../../features/gestures/in-view/types').InViewOptions & {
|
|
3106
3106
|
once?: boolean;
|
|
3107
3107
|
};
|
|
3108
|
+
inherit?: boolean;
|
|
3108
3109
|
onUpdate?: (latest: import('motion-dom').ResolvedValues) => void;
|
|
3109
3110
|
onDragTransitionEnd?: () => void;
|
|
3110
3111
|
onDragEnd?: (event: PointerEvent, info: import('motion-dom').PanInfo) => void;
|
|
@@ -3115,7 +3116,6 @@ export declare const Reorder: {
|
|
|
3115
3116
|
dragTransition?: import('motion-dom').InertiaOptions;
|
|
3116
3117
|
transformTemplate?: (transform: import('motion-dom').TransformProperties, generatedTransform: string) => string;
|
|
3117
3118
|
dragDirectionLock?: boolean;
|
|
3118
|
-
inherit?: boolean;
|
|
3119
3119
|
onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
|
|
3120
3120
|
onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
|
|
3121
3121
|
onBeforeLayoutMeasure?: (box: import('motion-utils').Box) => void;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from 'framer-motion/dom';
|
|
2
|
-
export { delay as delayInMs, addScaleCorrector } from 'motion-dom';
|
|
2
|
+
export { delay as delayInMs, addScaleCorrector, attachFollow, attachSpring } from 'motion-dom';
|
|
3
3
|
export { motionValue as useMotionValue } from 'motion-dom';
|
|
4
4
|
export * from './components';
|
|
5
5
|
export { default as LayoutGroup } from './components/LayoutGroup';
|
|
@@ -7,7 +7,7 @@ export { useLayoutGroup } from './components/use-layout-group';
|
|
|
7
7
|
export type { LayoutGroupProps } from './components/use-layout-group';
|
|
8
8
|
export * from './components/context';
|
|
9
9
|
export * from './value';
|
|
10
|
-
export * from './types';
|
|
10
|
+
export type * from './types';
|
|
11
11
|
export * from './animation';
|
|
12
12
|
export * from './utils';
|
|
13
13
|
export { useDragControls } from './features/gestures/drag/use-drag-controls';
|
package/dist/es/index.mjs
CHANGED
|
@@ -19,7 +19,8 @@ import { useTransform } from "./value/use-transform.mjs";
|
|
|
19
19
|
import { useTime } from "./value/use-time.mjs";
|
|
20
20
|
import { useMotionTemplate } from "./value/use-motion-template.mjs";
|
|
21
21
|
import { useMotionValueEvent } from "./value/use-motion-value-event.mjs";
|
|
22
|
-
import { useSpring } from "./value/use-spring.mjs";
|
|
22
|
+
import { useFollowValue, useSpring } from "./value/use-spring.mjs";
|
|
23
|
+
import { ScrollOffset, offsetToViewTimelineRange } from "./value/scroll/offsets.mjs";
|
|
23
24
|
import { useScroll } from "./value/use-scroll.mjs";
|
|
24
25
|
import { useVelocity } from "./value/use-velocity.mjs";
|
|
25
26
|
import { Reorder, ReorderGroup, ReorderItem } from "./components/reorder/index.mjs";
|
|
@@ -34,6 +35,6 @@ import { useReducedMotion } from "./animation/hooks/use-reduced-motion.mjs";
|
|
|
34
35
|
import { useDragControls } from "./features/gestures/drag/use-drag-controls.mjs";
|
|
35
36
|
import { domAnimation } from "./features/dom-animation.mjs";
|
|
36
37
|
import { MotionPlugin, createMotionDirective, createPresetDirective, vMotion } from "./directive/index.mjs";
|
|
37
|
-
import { addScaleCorrector, delay as delayInMs, motionValue as useMotionValue } from "motion-dom";
|
|
38
|
+
import { addScaleCorrector, attachFollow, attachSpring, delay as delayInMs, motionValue as useMotionValue } from "motion-dom";
|
|
38
39
|
export * from "framer-motion/dom";
|
|
39
|
-
export { AnimatePresence_default as AnimatePresence, LayoutGroup_default as LayoutGroup, LazyMotion, M, Motion, MotionConfig_default as MotionConfig, MotionPlugin, Reorder, ReorderGroup, ReorderItem, RowValue_default as RowValue, addScaleCorrector, createContext, createMotionDirective, createPresetDirective, delayInMs, domAnimation, domMax, getContextWindow, injectLayoutGroup, injectMotion, layoutGroupInjectionKey, m, motion, motionGlobalConfig, motionInjectionKey, mountedStates, provideLayoutGroup, provideMotion, provideMotionConfig, resolveMotionProps, useAnimate, useAnimationControls, useAnimationFrame, useCombineMotionValues, useComputed, useDomRef, useDragControls, useInView, useLayoutGroup, useMotionConfig, useMotionTemplate, useMotionValue, useMotionValueEvent, usePageInView, useReducedMotion, useScroll, useSpring, useTime, useTransform, useVelocity, vMotion };
|
|
40
|
+
export { AnimatePresence_default as AnimatePresence, LayoutGroup_default as LayoutGroup, LazyMotion, M, Motion, MotionConfig_default as MotionConfig, MotionPlugin, Reorder, ReorderGroup, ReorderItem, RowValue_default as RowValue, ScrollOffset, addScaleCorrector, attachFollow, attachSpring, createContext, createMotionDirective, createPresetDirective, delayInMs, domAnimation, domMax, getContextWindow, injectLayoutGroup, injectMotion, layoutGroupInjectionKey, m, motion, motionGlobalConfig, motionInjectionKey, mountedStates, offsetToViewTimelineRange, provideLayoutGroup, provideMotion, provideMotionConfig, resolveMotionProps, useAnimate, useAnimationControls, useAnimationFrame, useCombineMotionValues, useComputed, useDomRef, useDragControls, useFollowValue, useInView, useLayoutGroup, useMotionConfig, useMotionTemplate, useMotionValue, useMotionValueEvent, usePageInView, useReducedMotion, useScroll, useSpring, useTime, useTransform, useVelocity, vMotion };
|
|
@@ -6,11 +6,21 @@ export type EdgeString = NamedEdges | EdgeUnit | `${number}`;
|
|
|
6
6
|
export type Edge = EdgeString | number;
|
|
7
7
|
export type ProgressIntersection = [number, number];
|
|
8
8
|
export type Intersection = `${Edge} ${Edge}`;
|
|
9
|
+
/**
|
|
10
|
+
* Scroll offset definition for useScroll.
|
|
11
|
+
* Public value export (const presets) lives in value/scroll/offsets.ts.
|
|
12
|
+
*/
|
|
9
13
|
export type ScrollOffset = Array<Edge | Intersection | ProgressIntersection>;
|
|
10
14
|
export interface ScrollInfoOptions {
|
|
11
15
|
container?: HTMLElement;
|
|
12
16
|
target?: Element;
|
|
13
17
|
axis?: 'x' | 'y';
|
|
14
18
|
offset?: ScrollOffset;
|
|
19
|
+
/**
|
|
20
|
+
* When true, enables per-frame checking of scrollWidth/scrollHeight
|
|
21
|
+
* to detect content size changes and recalculate scroll progress.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
trackContentSize?: boolean;
|
|
15
25
|
}
|
|
16
26
|
export type $Transition = MotionNodeOptions['transition'];
|
package/dist/es/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type { SupportedEdgeUnit, EdgeUnit, NamedEdges, EdgeString, Edge, ProgressIntersection, Intersection, ScrollInfoOptions, $Transition, } from './framer-motion';
|
|
2
2
|
export * from './motion-values';
|
|
3
3
|
export * from './state';
|
|
4
4
|
export * from './common';
|
package/dist/es/value/index.d.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Edge, Intersection, ProgressIntersection } from '../../types';
|
|
2
|
+
type ScrollOffsetType = Array<Edge | Intersection | ProgressIntersection>;
|
|
3
|
+
/**
|
|
4
|
+
* Preset scroll offsets matching framer-motion's ScrollOffset presets.
|
|
5
|
+
* Use with useScroll's offset option to define scroll-linked animation ranges.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* useScroll({ target: el, offset: ScrollOffset.Enter })
|
|
9
|
+
*/
|
|
10
|
+
export declare const ScrollOffset: {
|
|
11
|
+
/** Progress 0→1 as target enters the container */
|
|
12
|
+
Enter: readonly [readonly [0, 1], readonly [1, 1]];
|
|
13
|
+
/** Progress 0→1 as target exits the container */
|
|
14
|
+
Exit: readonly [readonly [0, 0], readonly [1, 0]];
|
|
15
|
+
/** Progress 0→1 across any overlap between target and container */
|
|
16
|
+
Any: readonly [readonly [1, 0], readonly [0, 1]];
|
|
17
|
+
/** Progress 0→1 while target is fully contained within the container */
|
|
18
|
+
All: readonly [readonly [0, 0], readonly [1, 1]];
|
|
19
|
+
};
|
|
20
|
+
export type ScrollOffset = ScrollOffsetType;
|
|
21
|
+
/**
|
|
22
|
+
* Maps a ScrollOffset array to a ViewTimeline named range.
|
|
23
|
+
* Returns undefined for unrecognised patterns — signals fallback to JS scroll tracking.
|
|
24
|
+
*
|
|
25
|
+
* Ported from framer-motion's internal render/dom/scroll/utils/offset-to-range.mjs
|
|
26
|
+
*/
|
|
27
|
+
export declare function offsetToViewTimelineRange(offset: ScrollOffsetType | undefined): {
|
|
28
|
+
rangeStart: string;
|
|
29
|
+
rangeEnd: string;
|
|
30
|
+
} | undefined;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const ScrollOffset = {
|
|
2
|
+
Enter: [[0, 1], [1, 1]],
|
|
3
|
+
Exit: [[0, 0], [1, 0]],
|
|
4
|
+
Any: [[1, 0], [0, 1]],
|
|
5
|
+
All: [[0, 0], [1, 1]]
|
|
6
|
+
};
|
|
7
|
+
var presets = [
|
|
8
|
+
[ScrollOffset.Enter, "entry"],
|
|
9
|
+
[ScrollOffset.Exit, "exit"],
|
|
10
|
+
[ScrollOffset.Any, "cover"],
|
|
11
|
+
[ScrollOffset.All, "contain"]
|
|
12
|
+
];
|
|
13
|
+
var stringToProgress = {
|
|
14
|
+
start: 0,
|
|
15
|
+
end: 1
|
|
16
|
+
};
|
|
17
|
+
function parseStringOffset(s) {
|
|
18
|
+
const parts = s.trim().split(/\s+/);
|
|
19
|
+
if (parts.length !== 2) return void 0;
|
|
20
|
+
const a = stringToProgress[parts[0]];
|
|
21
|
+
const b = stringToProgress[parts[1]];
|
|
22
|
+
if (a === void 0 || b === void 0) return void 0;
|
|
23
|
+
return [a, b];
|
|
24
|
+
}
|
|
25
|
+
function normaliseOffset(offset) {
|
|
26
|
+
if (offset.length !== 2) return void 0;
|
|
27
|
+
const result = [];
|
|
28
|
+
for (const item of offset) if (Array.isArray(item)) result.push(item);
|
|
29
|
+
else if (typeof item === "string") {
|
|
30
|
+
const parsed = parseStringOffset(item);
|
|
31
|
+
if (!parsed) return void 0;
|
|
32
|
+
result.push(parsed);
|
|
33
|
+
} else return;
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function matchesPreset(offset, preset) {
|
|
37
|
+
const normalised = normaliseOffset(offset);
|
|
38
|
+
if (!normalised) return false;
|
|
39
|
+
for (let i = 0; i < 2; i++) {
|
|
40
|
+
const o = normalised[i];
|
|
41
|
+
const p = preset[i];
|
|
42
|
+
if (o[0] !== p[0] || o[1] !== p[1]) return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function offsetToViewTimelineRange(offset) {
|
|
47
|
+
if (!offset) return {
|
|
48
|
+
rangeStart: "contain 0%",
|
|
49
|
+
rangeEnd: "contain 100%"
|
|
50
|
+
};
|
|
51
|
+
for (const [preset, name] of presets) if (matchesPreset(offset, preset)) return {
|
|
52
|
+
rangeStart: `${name} 0%`,
|
|
53
|
+
rangeEnd: `${name} 100%`
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { ScrollOffset, offsetToViewTimelineRange };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cancelFrame, frame, motionValue } from "motion-dom";
|
|
2
|
-
import { onUnmounted } from "vue";
|
|
2
|
+
import { getCurrentInstance, onUnmounted } from "vue";
|
|
3
3
|
function useCombineMotionValues(combineValues) {
|
|
4
4
|
const value = motionValue(combineValues());
|
|
5
5
|
const updateValue = () => value.set(combineValues());
|
|
@@ -12,7 +12,7 @@ function useCombineMotionValues(combineValues) {
|
|
|
12
12
|
subscriptions.forEach((unsubscribe$1) => unsubscribe$1());
|
|
13
13
|
cancelFrame(updateValue);
|
|
14
14
|
};
|
|
15
|
-
onUnmounted(() => {
|
|
15
|
+
if (getCurrentInstance()) onUnmounted(() => {
|
|
16
16
|
unsubscribe();
|
|
17
17
|
});
|
|
18
18
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
1
2
|
import { ScrollInfoOptions } from '../types';
|
|
2
3
|
import { MaybeComputedElementRef } from '@vueuse/core';
|
|
3
|
-
|
|
4
|
-
export interface UseScrollOptions extends Omit<ToRefs<ScrollInfoOptions>, 'container' | 'target'> {
|
|
4
|
+
export interface UseScrollOptions extends Omit<ScrollInfoOptions, 'container' | 'target'> {
|
|
5
5
|
container?: MaybeComputedElementRef;
|
|
6
6
|
target?: MaybeComputedElementRef;
|
|
7
7
|
}
|
|
8
|
-
export declare function useScroll(
|
|
8
|
+
export declare function useScroll(options?: MaybeRefOrGetter<UseScrollOptions>): {
|
|
9
9
|
scrollX: import('motion-dom').MotionValue<number>;
|
|
10
10
|
scrollY: import('motion-dom').MotionValue<number>;
|
|
11
11
|
scrollXProgress: import('motion-dom').MotionValue<number>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { getElement } from "../components/hooks/use-motion-elm.mjs";
|
|
2
2
|
import { isSSR } from "../utils/is.mjs";
|
|
3
|
+
import { offsetToViewTimelineRange } from "./scroll/offsets.mjs";
|
|
3
4
|
import { scroll } from "framer-motion/dom";
|
|
4
|
-
import { motionValue as motionValue$1 } from "motion-dom";
|
|
5
|
-
import {
|
|
5
|
+
import { motionValue as motionValue$1, supportsScrollTimeline, supportsViewTimeline } from "motion-dom";
|
|
6
|
+
import { toValue, watchEffect } from "vue";
|
|
6
7
|
function createScrollMotionValues() {
|
|
7
8
|
return {
|
|
8
9
|
scrollX: motionValue$1(0),
|
|
@@ -11,20 +12,46 @@ function createScrollMotionValues() {
|
|
|
11
12
|
scrollYProgress: motionValue$1(0)
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
+
function canAccelerateScroll(target, offset) {
|
|
16
|
+
if (isSSR) return false;
|
|
17
|
+
return target ? supportsViewTimeline() && !!offsetToViewTimelineRange(offset) : supportsScrollTimeline();
|
|
18
|
+
}
|
|
19
|
+
function makeAccelerateConfig(axis, options) {
|
|
20
|
+
return {
|
|
21
|
+
factory: (animation) => {
|
|
22
|
+
const { container, target, ...rest } = toValue(options);
|
|
23
|
+
return scroll(animation, {
|
|
24
|
+
...rest,
|
|
25
|
+
axis,
|
|
26
|
+
container: getElement(container),
|
|
27
|
+
target: getElement(target)
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
times: [0, 1],
|
|
31
|
+
keyframes: [0, 1],
|
|
32
|
+
ease: (v) => v,
|
|
33
|
+
duration: 1
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function useScroll(options = {}) {
|
|
15
37
|
const values = createScrollMotionValues();
|
|
38
|
+
const { target, offset } = toValue(options);
|
|
39
|
+
if (canAccelerateScroll(target, offset)) {
|
|
40
|
+
values.scrollXProgress.accelerate = makeAccelerateConfig("x", options);
|
|
41
|
+
values.scrollYProgress.accelerate = makeAccelerateConfig("y", options);
|
|
42
|
+
}
|
|
16
43
|
watchEffect((onCleanup) => {
|
|
17
44
|
if (isSSR) return;
|
|
45
|
+
const { container, target: target$1, ...rest } = toValue(options);
|
|
18
46
|
const cleanup = scroll((_progress, { x, y }) => {
|
|
19
47
|
values.scrollX.set(x.current);
|
|
20
48
|
values.scrollXProgress.set(x.progress);
|
|
21
49
|
values.scrollY.set(y.current);
|
|
22
50
|
values.scrollYProgress.set(y.progress);
|
|
23
51
|
}, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
target: getElement(scrollOptions.target)
|
|
52
|
+
...rest,
|
|
53
|
+
container: getElement(container),
|
|
54
|
+
target: getElement(target$1)
|
|
28
55
|
});
|
|
29
56
|
onCleanup(() => {
|
|
30
57
|
cleanup();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeRef } from 'vue';
|
|
2
2
|
import { MotionValue } from 'framer-motion/dom';
|
|
3
|
-
import { SpringOptions } from 'motion-dom';
|
|
4
|
-
|
|
3
|
+
import { FollowValueOptions, SpringOptions } from 'motion-dom';
|
|
4
|
+
type AnyResolvedKeyframe = string | number;
|
|
5
|
+
export declare function useFollowValue<T extends AnyResolvedKeyframe>(source: T | MotionValue<T>, options?: MaybeRef<FollowValueOptions>): MotionValue<T>;
|
|
6
|
+
export declare function useSpring(source: MotionValue<string> | MotionValue<number> | number, config?: MaybeRef<SpringOptions>): MotionValue<string | number>;
|
|
7
|
+
export {};
|
|
@@ -1,49 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { isMotionValue, motionValue } from "framer-motion/dom";
|
|
2
|
+
import { attachFollow } from "motion-dom";
|
|
3
|
+
import { toValue, watch } from "vue";
|
|
4
|
+
function useFollowValue(source, options = {}) {
|
|
5
|
+
const value = motionValue(isMotionValue(source) ? source.get() : source);
|
|
6
|
+
let cleanup;
|
|
7
|
+
watch(() => toValue(options), (_1, _2, onCleanup) => {
|
|
8
|
+
cleanup = attachFollow(value, source, toValue(options));
|
|
9
|
+
onCleanup(() => {
|
|
10
|
+
cleanup?.();
|
|
11
|
+
});
|
|
12
|
+
}, { immediate: true });
|
|
13
|
+
return value;
|
|
6
14
|
}
|
|
7
15
|
function useSpring(source, config = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let latestSetter = () => {};
|
|
12
|
-
const stopAnimation = () => {
|
|
13
|
-
if (activeSpringAnimation) {
|
|
14
|
-
activeSpringAnimation.stop();
|
|
15
|
-
activeSpringAnimation = null;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const startAnimation = () => {
|
|
19
|
-
const animation = activeSpringAnimation;
|
|
20
|
-
if (animation?.time === 0) animation.sample(frameData.delta);
|
|
21
|
-
stopAnimation();
|
|
22
|
-
const springConfig = isRef(config) ? config.value : config;
|
|
23
|
-
activeSpringAnimation = animateValue({
|
|
24
|
-
keyframes: [value.get(), latestValue],
|
|
25
|
-
velocity: value.getVelocity(),
|
|
16
|
+
const value = motionValue(isMotionValue(source) ? source.get() : source);
|
|
17
|
+
watch(() => toValue(config), (_1, _2, onCleanup) => {
|
|
18
|
+
const cleanup = attachFollow(value, source, {
|
|
26
19
|
type: "spring",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
...toValue(config)
|
|
21
|
+
});
|
|
22
|
+
onCleanup(() => {
|
|
23
|
+
cleanup?.();
|
|
31
24
|
});
|
|
32
|
-
};
|
|
33
|
-
watch(() => {
|
|
34
|
-
if (isRef(config)) return config.value;
|
|
35
|
-
return config;
|
|
36
|
-
}, () => {
|
|
37
|
-
value.attach((v, set) => {
|
|
38
|
-
latestValue = v;
|
|
39
|
-
latestSetter = set;
|
|
40
|
-
frame.update(startAnimation);
|
|
41
|
-
return value.get();
|
|
42
|
-
}, stopAnimation);
|
|
43
25
|
}, { immediate: true });
|
|
44
|
-
if (isMotionValue(source)) source.on("change", (v) => {
|
|
45
|
-
value.set(toNumber(v));
|
|
46
|
-
});
|
|
47
26
|
return value;
|
|
48
27
|
}
|
|
49
|
-
export { useSpring };
|
|
28
|
+
export { useFollowValue, useSpring };
|
|
@@ -5,12 +5,12 @@ import { isRef, watch } from "vue";
|
|
|
5
5
|
function useTransform(input, inputRangeOrTransformer, outputRange, options) {
|
|
6
6
|
if (typeof input === "function") return useComputed(input);
|
|
7
7
|
if (outputRange && !Array.isArray(outputRange) && typeof outputRange === "object") {
|
|
8
|
-
const result = {};
|
|
8
|
+
const result$1 = {};
|
|
9
9
|
for (const key in outputRange) if (Object.prototype.hasOwnProperty.call(outputRange, key)) {
|
|
10
10
|
const keyOutputRange = outputRange[key];
|
|
11
|
-
result[key] = useTransform(input, inputRangeOrTransformer, keyOutputRange, options);
|
|
11
|
+
result$1[key] = useTransform(input, inputRangeOrTransformer, keyOutputRange, options);
|
|
12
12
|
}
|
|
13
|
-
return result;
|
|
13
|
+
return result$1;
|
|
14
14
|
}
|
|
15
15
|
let inputValues;
|
|
16
16
|
let transformer;
|
|
@@ -32,9 +32,23 @@ function useTransform(input, inputRangeOrTransformer, outputRange, options) {
|
|
|
32
32
|
transformer = transform(inputRangeOrTransformer, outputRange, options);
|
|
33
33
|
inputValues = Array.isArray(input) ? input : [input];
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
const result = Array.isArray(input) ? useListTransform(inputValues, transformer) : useListTransform(inputValues, (values) => {
|
|
36
36
|
return transformer(values[0]);
|
|
37
37
|
});
|
|
38
|
+
if (!Array.isArray(input)) {
|
|
39
|
+
const inputAccelerate = input.accelerate;
|
|
40
|
+
if (inputAccelerate && !inputAccelerate.isTransformed && typeof inputRangeOrTransformer !== "function" && Array.isArray(outputRange) && options?.clamp !== false) {
|
|
41
|
+
const resolvedInputRange = isRef(inputRangeOrTransformer) ? inputRangeOrTransformer.value : inputRangeOrTransformer;
|
|
42
|
+
result.accelerate = {
|
|
43
|
+
...inputAccelerate,
|
|
44
|
+
times: resolvedInputRange,
|
|
45
|
+
keyframes: outputRange,
|
|
46
|
+
isTransformed: true,
|
|
47
|
+
...options?.ease ? { ease: options.ease } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
38
52
|
}
|
|
39
53
|
function useListTransform(values, transformer) {
|
|
40
54
|
const latest = [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-v",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"vue": ">=3.0.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"framer-motion": "^12.
|
|
58
|
+
"framer-motion": "^12.38.0",
|
|
59
59
|
"hey-listen": "^1.0.8",
|
|
60
|
-
"motion-dom": "^12.
|
|
61
|
-
"motion-utils": "^12.
|
|
60
|
+
"motion-dom": "^12.38.0",
|
|
61
|
+
"motion-utils": "^12.36.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"dev": "vite build --watch",
|