motion-v 0.5.1 → 0.6.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/cjs/index.js +322 -201
- package/dist/es/components/LayoutGroup.vue.mjs +10 -4
- package/dist/es/components/Motion.vue.mjs +40 -30
- package/dist/es/components/{AnimatePresence.vue.mjs → animate-presence/AnimatePresence.vue.mjs} +38 -18
- package/dist/es/components/{use-pop-layout.mjs → animate-presence/use-pop-layout.mjs} +5 -0
- package/dist/es/components/context.mjs +1 -9
- package/dist/es/components/group.mjs +5 -2
- package/dist/es/components/motion-config/MotionConfig.vue.mjs +30 -0
- package/dist/es/components/motion-config/MotionConfig.vue2.mjs +4 -0
- package/dist/es/components/motion-config/context.mjs +17 -0
- package/dist/es/components/presence.mjs +0 -2
- package/dist/es/components/use-layout-group.mjs +8 -6
- package/dist/es/components/utils.mjs +7 -0
- package/dist/es/constants/index.mjs +4 -2
- package/dist/es/features/layout/layout.mjs +19 -12
- package/dist/es/features/layout/projection.mjs +33 -1
- package/dist/es/index.mjs +12 -7
- package/dist/es/state/animate-variants-children.mjs +6 -4
- package/dist/es/state/motion-state.mjs +53 -24
- package/dist/es/state/schedule.mjs +2 -26
- package/dist/es/state/utils.mjs +0 -9
- package/dist/src/components/LayoutGroup.d.ts +4 -1
- package/dist/src/components/Motion.d.ts +1 -0
- package/dist/src/components/{AnimatePresence.d.ts → animate-presence/AnimatePresence.d.ts} +1 -1
- package/dist/src/components/animate-presence/index.d.ts +2 -0
- package/dist/src/components/{type.d.ts → animate-presence/types.d.ts} +2 -0
- package/dist/src/components/{use-pop-layout.d.ts → animate-presence/use-pop-layout.d.ts} +2 -2
- package/dist/src/components/animate-presence/use-presence.d.ts +2 -0
- package/dist/src/components/context.d.ts +1 -3
- package/dist/src/components/group.d.ts +1 -0
- package/dist/src/components/hooks/use-motion-elm.d.ts +13 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/motion-config/MotionConfig.d.ts +39 -0
- package/dist/src/components/motion-config/context.d.ts +11 -0
- package/dist/src/components/motion-config/index.d.ts +2 -0
- package/dist/src/components/motion-config/types.d.ts +14 -0
- package/dist/src/components/presence.d.ts +3 -5
- package/dist/src/components/use-layout-group.d.ts +4 -1
- package/dist/src/components/use-slot-change-index.d.ts +1 -0
- package/dist/src/components/utils.d.ts +7 -0
- package/dist/src/features/gestures/drag/types.d.ts +5 -3
- package/dist/src/features/gestures/types.d.ts +0 -5
- package/dist/src/features/layout/projection.d.ts +1 -0
- package/dist/src/features/layout/types.d.ts +1 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/state/animate-variants-children.d.ts +1 -1
- package/dist/src/state/event.d.ts +1 -1
- package/dist/src/state/motion-state.d.ts +10 -7
- package/dist/src/types/state.d.ts +8 -2
- package/package.json +3 -2
- /package/dist/es/components/{AnimatePresence.vue2.mjs → animate-presence/AnimatePresence.vue2.mjs} +0 -0
|
@@ -4,7 +4,7 @@ import { resolveVariant, getOptions, hasChanged } from "./utils.mjs";
|
|
|
4
4
|
import { FeatureManager } from "../features/feature-manager.mjs";
|
|
5
5
|
import { style } from "./style.mjs";
|
|
6
6
|
import { transformResetValue } from "./transform.mjs";
|
|
7
|
-
import { scheduleAnimation
|
|
7
|
+
import { scheduleAnimation } from "./schedule.mjs";
|
|
8
8
|
import { motionEvent } from "./event.mjs";
|
|
9
9
|
import { createVisualElement } from "./create-visual-element.mjs";
|
|
10
10
|
import { animateVariantsChildren } from "./animate-variants-children.mjs";
|
|
@@ -14,20 +14,25 @@ import "../external/.pnpm/motion-utils@11.14.3/external/motion-utils/dist/es/err
|
|
|
14
14
|
import { animate } from "../external/.pnpm/framer-motion@11.15.0/external/framer-motion/dist/es/animation/animate/index.mjs";
|
|
15
15
|
import { isDef } from "../external/.pnpm/@vueuse_shared@12.0.0_typescript@5.7.2/external/@vueuse/shared/index.mjs";
|
|
16
16
|
const STATE_TYPES = ["initial", "animate", "inView", "hover", "press", "whileDrag", "exit"];
|
|
17
|
-
const mountedStates = /* @__PURE__ */ new
|
|
17
|
+
const mountedStates = /* @__PURE__ */ new Map();
|
|
18
18
|
let id = 0;
|
|
19
19
|
class MotionState {
|
|
20
20
|
constructor(options, parent) {
|
|
21
|
+
var _a;
|
|
21
22
|
this.element = null;
|
|
23
|
+
this.isSafeToRemove = false;
|
|
22
24
|
this.isFirstAnimate = true;
|
|
25
|
+
this.children = /* @__PURE__ */ new Set();
|
|
23
26
|
this.activeStates = {
|
|
24
|
-
initial: true,
|
|
27
|
+
// initial: true,
|
|
25
28
|
animate: true
|
|
26
29
|
};
|
|
27
30
|
this._context = null;
|
|
28
31
|
this.id = `motion-state-${id++}`;
|
|
32
|
+
mountedStates.set(this.id, this);
|
|
29
33
|
this.options = options;
|
|
30
34
|
this.parent = parent;
|
|
35
|
+
(_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.add(this);
|
|
31
36
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
32
37
|
this.visualElement = createVisualElement(this.options.as, {
|
|
33
38
|
presenceContext: null,
|
|
@@ -47,11 +52,12 @@ class MotionState {
|
|
|
47
52
|
attrs: {}
|
|
48
53
|
},
|
|
49
54
|
latestValues: {}
|
|
50
|
-
}
|
|
55
|
+
},
|
|
56
|
+
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
51
57
|
});
|
|
52
58
|
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
53
|
-
this.featureManager = new FeatureManager(this);
|
|
54
59
|
this.initTarget(initialVariantSource);
|
|
60
|
+
this.featureManager = new FeatureManager(this);
|
|
55
61
|
}
|
|
56
62
|
get context() {
|
|
57
63
|
if (!this._context) {
|
|
@@ -67,7 +73,7 @@ class MotionState {
|
|
|
67
73
|
}
|
|
68
74
|
initTarget(initialVariantSource) {
|
|
69
75
|
this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
|
|
70
|
-
this.target = {
|
|
76
|
+
this.target = {};
|
|
71
77
|
}
|
|
72
78
|
get initial() {
|
|
73
79
|
return isDef(this.options.initial) ? this.options.initial : this.context.initial;
|
|
@@ -77,7 +83,8 @@ class MotionState {
|
|
|
77
83
|
...this.options,
|
|
78
84
|
whileHover: this.options.hover,
|
|
79
85
|
whileTap: this.options.press,
|
|
80
|
-
whileInView: this.options.inView
|
|
86
|
+
whileInView: this.options.inView,
|
|
87
|
+
reducedMotionConfig: this.options.motionConfig.reduceMotion
|
|
81
88
|
}, {
|
|
82
89
|
isPresent: !doneCallbacks.has(this.element)
|
|
83
90
|
});
|
|
@@ -85,7 +92,7 @@ class MotionState {
|
|
|
85
92
|
beforeMount() {
|
|
86
93
|
this.featureManager.beforeMount();
|
|
87
94
|
}
|
|
88
|
-
mount(element, options) {
|
|
95
|
+
mount(element, options, notAnimate = false) {
|
|
89
96
|
invariant(
|
|
90
97
|
Boolean(element),
|
|
91
98
|
"Animation state must be mounted with valid Element"
|
|
@@ -109,38 +116,57 @@ class MotionState {
|
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
this.featureManager.mount();
|
|
112
|
-
|
|
119
|
+
if (!notAnimate) {
|
|
120
|
+
this.animateUpdates(true);
|
|
121
|
+
}
|
|
113
122
|
}
|
|
114
123
|
beforeUnmount() {
|
|
115
124
|
this.featureManager.beforeUnmount();
|
|
116
125
|
}
|
|
117
|
-
unmount() {
|
|
118
|
-
var _a;
|
|
126
|
+
unmount(unMountChildren = false) {
|
|
127
|
+
var _a, _b;
|
|
119
128
|
mountedStates.delete(this.element);
|
|
120
|
-
|
|
121
|
-
(_a = visualElementStore.get(this.element)) == null ? void 0 : _a.unmount();
|
|
129
|
+
mountedStates.delete(this.id);
|
|
122
130
|
this.featureManager.unmount();
|
|
131
|
+
(_a = this.visualElement) == null ? void 0 : _a.unmount();
|
|
132
|
+
if (unMountChildren) {
|
|
133
|
+
const unmountChild = (child) => {
|
|
134
|
+
var _a2;
|
|
135
|
+
child.unmount(true);
|
|
136
|
+
(_a2 = child.children) == null ? void 0 : _a2.forEach(unmountChild);
|
|
137
|
+
};
|
|
138
|
+
(_b = this.children) == null ? void 0 : _b.forEach(unmountChild);
|
|
139
|
+
}
|
|
123
140
|
}
|
|
124
141
|
beforeUpdate() {
|
|
125
142
|
this.featureManager.beforeUpdate();
|
|
126
143
|
}
|
|
127
|
-
update(options) {
|
|
144
|
+
update(options, notAnimate = false) {
|
|
145
|
+
const prevAnimate = JSON.stringify(this.options.animate);
|
|
128
146
|
this.options = options;
|
|
147
|
+
let hasAnimateChange = false;
|
|
148
|
+
if (prevAnimate !== JSON.stringify(options.animate)) {
|
|
149
|
+
hasAnimateChange = true;
|
|
150
|
+
}
|
|
129
151
|
this.updateOptions();
|
|
130
152
|
this.featureManager.update();
|
|
131
|
-
|
|
153
|
+
if (hasAnimateChange && !notAnimate) {
|
|
154
|
+
scheduleAnimation(this);
|
|
155
|
+
}
|
|
132
156
|
}
|
|
133
|
-
setActive(name, isActive) {
|
|
157
|
+
setActive(name, isActive, isAnimate = true) {
|
|
134
158
|
var _a;
|
|
135
159
|
if (!this.element || this.activeStates[name] === isActive)
|
|
136
160
|
return;
|
|
137
161
|
this.activeStates[name] = isActive;
|
|
138
162
|
(_a = this.visualElement.variantChildren) == null ? void 0 : _a.forEach((child) => {
|
|
139
|
-
child.state.setActive(name, isActive);
|
|
163
|
+
child.state.setActive(name, isActive, false);
|
|
140
164
|
});
|
|
141
|
-
|
|
165
|
+
if (isAnimate) {
|
|
166
|
+
scheduleAnimation(this);
|
|
167
|
+
}
|
|
142
168
|
}
|
|
143
|
-
|
|
169
|
+
animateUpdates(isInitial = false) {
|
|
144
170
|
const prevTarget = this.target;
|
|
145
171
|
this.target = {};
|
|
146
172
|
const activeState = {};
|
|
@@ -148,13 +174,13 @@ class MotionState {
|
|
|
148
174
|
let transition;
|
|
149
175
|
for (const name of STATE_TYPES) {
|
|
150
176
|
if (name === "initial") {
|
|
151
|
-
if (!
|
|
177
|
+
if (!isInitial) {
|
|
152
178
|
continue;
|
|
153
179
|
}
|
|
154
|
-
this.isFirstAnimate = false;
|
|
155
180
|
}
|
|
156
|
-
if (!this.activeStates[name])
|
|
181
|
+
if (!this.activeStates[name] && name !== "initial") {
|
|
157
182
|
continue;
|
|
183
|
+
}
|
|
158
184
|
const definition = isDef(this.options[name]) ? this.options[name] : this.context[name];
|
|
159
185
|
const variant = resolveVariant(
|
|
160
186
|
definition,
|
|
@@ -210,11 +236,10 @@ class MotionState {
|
|
|
210
236
|
let getChildAnimations = () => Promise.resolve();
|
|
211
237
|
let childAnimations = [];
|
|
212
238
|
if (Object.keys(activeState).length) {
|
|
213
|
-
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState);
|
|
239
|
+
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState, isInitial);
|
|
214
240
|
getChildAnimations = getAnimations;
|
|
215
241
|
childAnimations = animations2;
|
|
216
242
|
}
|
|
217
|
-
yield;
|
|
218
243
|
let animations;
|
|
219
244
|
const getAnimation = () => {
|
|
220
245
|
animations = animationFactories.map((factory) => factory()).filter(Boolean);
|
|
@@ -252,6 +277,10 @@ class MotionState {
|
|
|
252
277
|
getOptions() {
|
|
253
278
|
return this.options;
|
|
254
279
|
}
|
|
280
|
+
willUpdate(label) {
|
|
281
|
+
var _a;
|
|
282
|
+
(_a = this.visualElement.projection) == null ? void 0 : _a.willUpdate();
|
|
283
|
+
}
|
|
255
284
|
}
|
|
256
285
|
export {
|
|
257
286
|
MotionState,
|
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import { addUniqueItem, removeItem } from "./utils.mjs";
|
|
2
|
-
let scheduled;
|
|
3
|
-
const fireNext = (iterator) => iterator.next();
|
|
4
|
-
const fireAnimateUpdates = (state) => state.animateUpdates();
|
|
5
|
-
function processScheduledAnimations() {
|
|
6
|
-
if (!scheduled)
|
|
7
|
-
return;
|
|
8
|
-
const generators = scheduled.sort(compareByDepth).map(fireAnimateUpdates);
|
|
9
|
-
generators.forEach(fireNext);
|
|
10
|
-
generators.forEach(fireNext);
|
|
11
|
-
scheduled = void 0;
|
|
12
|
-
}
|
|
13
1
|
function scheduleAnimation(state) {
|
|
14
|
-
|
|
15
|
-
scheduled = [state];
|
|
16
|
-
requestAnimationFrame(processScheduledAnimations);
|
|
17
|
-
} else {
|
|
18
|
-
addUniqueItem(scheduled, state);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function unscheduleAnimation(state) {
|
|
22
|
-
scheduled && removeItem(scheduled, state);
|
|
23
|
-
}
|
|
24
|
-
function compareByDepth(a, b) {
|
|
25
|
-
return a.depth - b.depth;
|
|
2
|
+
state.animateUpdates();
|
|
26
3
|
}
|
|
27
4
|
export {
|
|
28
|
-
scheduleAnimation
|
|
29
|
-
unscheduleAnimation
|
|
5
|
+
scheduleAnimation
|
|
30
6
|
};
|
package/dist/es/state/utils.mjs
CHANGED
|
@@ -23,13 +23,6 @@ function shallowCompare(next, prev) {
|
|
|
23
23
|
}
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
|
-
function addUniqueItem(array, item) {
|
|
27
|
-
!array.includes(item) && array.push(item);
|
|
28
|
-
}
|
|
29
|
-
function removeItem(array, item) {
|
|
30
|
-
const index = array.indexOf(item);
|
|
31
|
-
index !== -1 && array.splice(index, 1);
|
|
32
|
-
}
|
|
33
26
|
function getOptions(options, key) {
|
|
34
27
|
return options[key] ? { ...options, ...options[key] } : { ...options };
|
|
35
28
|
}
|
|
@@ -102,14 +95,12 @@ function isSVGElement(as) {
|
|
|
102
95
|
return svgElementSet.has(as);
|
|
103
96
|
}
|
|
104
97
|
export {
|
|
105
|
-
addUniqueItem,
|
|
106
98
|
getOptions,
|
|
107
99
|
hasChanged,
|
|
108
100
|
isCssVar,
|
|
109
101
|
isNumber,
|
|
110
102
|
isSVGElement,
|
|
111
103
|
noopReturn,
|
|
112
|
-
removeItem,
|
|
113
104
|
resolveVariant,
|
|
114
105
|
shallowCompare,
|
|
115
106
|
svgElements
|
|
@@ -3,6 +3,7 @@ import { ElementType, Options, SVGAttributesWithMotionValues, SetMotionValueType
|
|
|
3
3
|
export interface MotionProps<T extends ElementType = 'div', K = unknown> extends Options<K> {
|
|
4
4
|
as?: T;
|
|
5
5
|
asChild?: boolean;
|
|
6
|
+
whileDrag?: Options['whileDrag'];
|
|
6
7
|
}
|
|
7
8
|
declare const _default: <T extends ElementType = "div", K = unknown>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
8
9
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & Readonly<import('vue').ExtractPropTypes<{}>>, never>, never> & (Omit<SetMotionValueType<IntrinsicElementAttributes, keyof SVGAttributesWithMotionValues>[T], "asChild" | keyof Options<any>> & MotionProps<T, K>)> & import('vue').PublicProps;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnimatePresenceProps } from './
|
|
2
|
-
import { MotionState } from '
|
|
1
|
+
import { AnimatePresenceProps } from './types';
|
|
2
|
+
import { MotionState } from '../../state';
|
|
3
3
|
export declare function usePopLayout(props: AnimatePresenceProps): {
|
|
4
4
|
addPopStyle: (state: MotionState) => void;
|
|
5
5
|
removePopStyle: (state: MotionState) => void;
|
|
@@ -6,6 +6,7 @@ export interface NodeGroup {
|
|
|
6
6
|
add: (node: IProjectionNode) => void;
|
|
7
7
|
remove: (node: IProjectionNode) => void;
|
|
8
8
|
dirty: VoidFunction;
|
|
9
|
+
didUpdate: VoidFunction;
|
|
9
10
|
}
|
|
10
11
|
export interface LayoutGroupState {
|
|
11
12
|
id?: string;
|
|
@@ -14,6 +15,3 @@ export interface LayoutGroupState {
|
|
|
14
15
|
key?: Ref<number>;
|
|
15
16
|
}
|
|
16
17
|
export declare const injectLayoutGroup: <T extends LayoutGroupState = LayoutGroupState>(fallback?: T) => T extends null ? LayoutGroupState : LayoutGroupState, provideLayoutGroup: (contextValue: LayoutGroupState) => LayoutGroupState;
|
|
17
|
-
export type InheritOption = boolean | 'id';
|
|
18
|
-
export declare function shouldInheritGroup(inherit: InheritOption): inherit is true;
|
|
19
|
-
export declare function shouldInheritId(inherit: InheritOption): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the actual motion element, skipping text and comment nodes
|
|
3
|
+
* @param el - The HTML element to check
|
|
4
|
+
* @returns The first non-text/comment element
|
|
5
|
+
*/
|
|
6
|
+
export declare function getMotionElement(el: HTMLElement): HTMLElement;
|
|
7
|
+
/**
|
|
8
|
+
* Hook to get the motion element of current component instance
|
|
9
|
+
* @returns Function that returns the motion element
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMotionElm(): {
|
|
12
|
+
value: HTMLElement | null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare function __VLS_template(): {
|
|
2
|
+
slots: {
|
|
3
|
+
default?(_: {}): any;
|
|
4
|
+
};
|
|
5
|
+
refs: {};
|
|
6
|
+
attrs: Partial<{}>;
|
|
7
|
+
};
|
|
8
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
9
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<import('./types').MotionConfigState>, {
|
|
10
|
+
reduceMotion: "user" | "never" | "always";
|
|
11
|
+
}>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<import('./types').MotionConfigState>, {
|
|
12
|
+
reduceMotion: "user" | "never" | "always";
|
|
13
|
+
}>>>, {
|
|
14
|
+
reduceMotion: "user" | "never" | "always";
|
|
15
|
+
}, {}>;
|
|
16
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
17
|
+
export default _default;
|
|
18
|
+
type __VLS_WithDefaults<P, D> = {
|
|
19
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
|
|
20
|
+
default: D[K];
|
|
21
|
+
}> : P[K];
|
|
22
|
+
};
|
|
23
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
24
|
+
type __VLS_TypePropsToOption<T> = {
|
|
25
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
26
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
27
|
+
} : {
|
|
28
|
+
type: import('vue').PropType<T[K]>;
|
|
29
|
+
required: true;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
33
|
+
new (): {
|
|
34
|
+
$slots: S;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
type __VLS_PrettifyLocal<T> = {
|
|
38
|
+
[K in keyof T]: T[K];
|
|
39
|
+
} & {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MotionConfigState } from './types';
|
|
2
|
+
import { ComputedRef } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* Default motion configuration
|
|
5
|
+
*/
|
|
6
|
+
export declare const defaultConfig: MotionConfigState;
|
|
7
|
+
/**
|
|
8
|
+
* Context for sharing motion configuration with child components
|
|
9
|
+
*/
|
|
10
|
+
export declare const injectMotionConfig: <T extends ComputedRef<MotionConfigState> = ComputedRef<MotionConfigState>>(fallback?: T) => T extends null ? ComputedRef<MotionConfigState> : ComputedRef<MotionConfigState>, provideMotionConfig: (contextValue: ComputedRef<MotionConfigState>) => ComputedRef<MotionConfigState>;
|
|
11
|
+
export declare function useMotionConfig(): ComputedRef<MotionConfigState>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Options } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Motion configuration state shared through context
|
|
4
|
+
*/
|
|
5
|
+
export interface MotionConfigState {
|
|
6
|
+
/** Default transition settings for animations */
|
|
7
|
+
transition?: Options['transition'];
|
|
8
|
+
/** Controls motion reduction based on user preference or explicit setting */
|
|
9
|
+
reduceMotion?: 'user' | 'never' | 'always';
|
|
10
|
+
/** Custom nonce for CSP compliance with inline styles */
|
|
11
|
+
nonce?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Props interface matching the config state */
|
|
14
|
+
export type MotionConfigProps = MotionConfigState;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const doneCallbacks: WeakMap<Element, VoidFunction>;
|
|
3
|
-
export declare const unPresenceDom: Ref<WeakMap<Element, boolean> & Omit<WeakMap<Element, boolean>, keyof WeakMap<any, any>>>;
|
|
1
|
+
export declare const doneCallbacks: WeakMap<Element, (v?: any, safeUnmount?: boolean) => void>;
|
|
4
2
|
export declare function removeDoneCallback(element: Element): void;
|
|
5
3
|
export interface PresenceContext {
|
|
6
|
-
initial
|
|
7
|
-
|
|
4
|
+
initial?: boolean;
|
|
5
|
+
custom?: any;
|
|
8
6
|
}
|
|
9
7
|
export declare const injectAnimatePresence: <T extends PresenceContext = PresenceContext>(fallback?: T) => T extends null ? PresenceContext : PresenceContext, provideAnimatePresence: (contextValue: PresenceContext) => PresenceContext;
|
|
@@ -17,4 +17,7 @@ export interface LayoutGroupProps {
|
|
|
17
17
|
* Hook to create and manage a layout group
|
|
18
18
|
* Handles group inheritance, force updates, and context management
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function useLayoutGroupProvider(props: LayoutGroupProps): LayoutGroupState;
|
|
21
|
+
export declare function useLayoutGroup(): {
|
|
22
|
+
forceRender: VoidFunction;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useSlotChangeIndex(): import('vue').ComputedRef<number>;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
import { ComponentPublicInstance } from 'vue';
|
|
1
2
|
export declare function getMotionElement(el: HTMLElement): HTMLElement;
|
|
3
|
+
/**
|
|
4
|
+
* 检查是否是隐藏的 motion 元素
|
|
5
|
+
* @param instance
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkMotionIsHidden(instance: ComponentPublicInstance): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DragControls } from './use-drag-controls';
|
|
2
|
+
import { Variant } from '../../../types';
|
|
2
3
|
import { Axis, BoundingBox, DragElastic, InertiaOptions, PanInfo } from 'framer-motion';
|
|
3
4
|
export interface ResolvedConstraints {
|
|
4
5
|
x: Partial<Axis>;
|
|
@@ -22,7 +23,7 @@ export interface DragHandlers {
|
|
|
22
23
|
*
|
|
23
24
|
* @public
|
|
24
25
|
*/
|
|
25
|
-
onDragStart?: (event:
|
|
26
|
+
onDragStart?: (event: PointerEvent, info: PanInfo) => void;
|
|
26
27
|
/**
|
|
27
28
|
* Callback function that fires when dragging ends.
|
|
28
29
|
*
|
|
@@ -37,7 +38,7 @@ export interface DragHandlers {
|
|
|
37
38
|
*
|
|
38
39
|
* @public
|
|
39
40
|
*/
|
|
40
|
-
onDragEnd?: (event:
|
|
41
|
+
onDragEnd?: (event: PointerEvent, info: PanInfo) => void;
|
|
41
42
|
/**
|
|
42
43
|
* Callback function that fires when the component is dragged.
|
|
43
44
|
*
|
|
@@ -52,7 +53,7 @@ export interface DragHandlers {
|
|
|
52
53
|
*
|
|
53
54
|
* @public
|
|
54
55
|
*/
|
|
55
|
-
onDrag?: (event:
|
|
56
|
+
onDrag?: (event: PointerEvent, info: PanInfo) => void;
|
|
56
57
|
/**
|
|
57
58
|
* Callback function that fires a drag direction is determined.
|
|
58
59
|
*
|
|
@@ -220,4 +221,5 @@ export interface DragProps extends DragHandlers {
|
|
|
220
221
|
* ```
|
|
221
222
|
*/
|
|
222
223
|
dragControls?: DragControls;
|
|
224
|
+
whileDrag?: string | Variant;
|
|
223
225
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from 'framer-motion/dom';
|
|
2
2
|
export { motionValue as useMotionValue } from 'framer-motion/dom';
|
|
3
3
|
export { default as Motion, type MotionProps } from './components/Motion';
|
|
4
|
-
export
|
|
5
|
-
export type { AnimatePresenceProps } from './components/type';
|
|
4
|
+
export * from './components';
|
|
6
5
|
export { default as LayoutGroup } from './components/LayoutGroup';
|
|
6
|
+
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';
|
|
@@ -6,7 +6,7 @@ export type ActiveVariant = {
|
|
|
6
6
|
transition: AnimateOptions;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
export declare function animateVariantsChildren(state: MotionState, activeState: ActiveVariant): {
|
|
9
|
+
export declare function animateVariantsChildren(state: MotionState, activeState: ActiveVariant, isFirstAnimate?: boolean): {
|
|
10
10
|
animations: any[];
|
|
11
11
|
getAnimations: () => Promise<void>;
|
|
12
12
|
} | {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Variant } from '../types';
|
|
2
|
-
export type MotionEventNames = 'motionstart' | 'motioncomplete'
|
|
2
|
+
export type MotionEventNames = 'motionstart' | 'motioncomplete';
|
|
3
3
|
export declare function motionEvent(name: MotionEventNames, target: Variant, isExit?: boolean): CustomEvent<{
|
|
4
4
|
target: Variant;
|
|
5
5
|
isExit: boolean;
|
|
@@ -2,13 +2,15 @@ import { MotionStateContext, Options } from '../types';
|
|
|
2
2
|
import { DOMKeyframesDefinition, VisualElement } from 'framer-motion';
|
|
3
3
|
declare const STATE_TYPES: readonly ["initial", "animate", "inView", "hover", "press", "whileDrag", "exit"];
|
|
4
4
|
type StateType = typeof STATE_TYPES[number];
|
|
5
|
-
export declare const mountedStates:
|
|
5
|
+
export declare const mountedStates: Map<string | Element, MotionState>;
|
|
6
6
|
export declare class MotionState {
|
|
7
7
|
readonly id: string;
|
|
8
8
|
element: HTMLElement | null;
|
|
9
9
|
private parent?;
|
|
10
10
|
options: Options;
|
|
11
|
-
|
|
11
|
+
isSafeToRemove: boolean;
|
|
12
|
+
isFirstAnimate: boolean;
|
|
13
|
+
private children?;
|
|
12
14
|
activeStates: Partial<Record<StateType, boolean>>;
|
|
13
15
|
depth: number;
|
|
14
16
|
baseTarget: DOMKeyframesDefinition;
|
|
@@ -22,14 +24,15 @@ export declare class MotionState {
|
|
|
22
24
|
get initial(): string | boolean | import('../types').Variant;
|
|
23
25
|
updateOptions(): void;
|
|
24
26
|
beforeMount(): void;
|
|
25
|
-
mount(element: HTMLElement, options: Options): void;
|
|
27
|
+
mount(element: HTMLElement, options: Options, notAnimate?: boolean): void;
|
|
26
28
|
beforeUnmount(): void;
|
|
27
|
-
unmount(): void;
|
|
29
|
+
unmount(unMountChildren?: boolean): void;
|
|
28
30
|
beforeUpdate(): void;
|
|
29
|
-
update(options: Options): void;
|
|
30
|
-
setActive(name: StateType, isActive: boolean): void;
|
|
31
|
-
animateUpdates():
|
|
31
|
+
update(options: Options, notAnimate?: boolean): void;
|
|
32
|
+
setActive(name: StateType, isActive: boolean, isAnimate?: boolean): void;
|
|
33
|
+
animateUpdates(isInitial?: boolean): void;
|
|
32
34
|
isMounted(): boolean;
|
|
33
35
|
getOptions(): Options<any>;
|
|
36
|
+
willUpdate(label: string): void;
|
|
34
37
|
}
|
|
35
38
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOMKeyframesDefinition, DynamicAnimationOptions, Target, TargetAndTransition } from 'framer-motion';
|
|
1
|
+
import { DOMKeyframesDefinition, DynamicAnimationOptions, ResolvedValues, Target, TargetAndTransition } from 'framer-motion';
|
|
2
2
|
import { MotionValue, animate } from 'framer-motion/dom';
|
|
3
3
|
import { IntrinsicElementAttributes } from 'vue';
|
|
4
4
|
import { TransformProperties } from './transform';
|
|
@@ -9,6 +9,7 @@ import { HoverProps } from '../features/gestures/hover/types';
|
|
|
9
9
|
import { InViewProps } from '../features/gestures/in-view/types';
|
|
10
10
|
import { LayoutGroupState } from '../components/context';
|
|
11
11
|
import { PanProps } from '../features/gestures/pan/types';
|
|
12
|
+
import { MotionConfigState } from '../components/motion-config/types';
|
|
12
13
|
type AnimationPlaybackControls = ReturnType<typeof animate>;
|
|
13
14
|
export interface Orchestration {
|
|
14
15
|
delay?: number;
|
|
@@ -49,8 +50,13 @@ export interface Options<T = any> extends LayoutOptions, PressProps, HoverProps,
|
|
|
49
50
|
};
|
|
50
51
|
style?: MotionStyle;
|
|
51
52
|
transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
|
|
52
|
-
transition?: AnimateOptions
|
|
53
|
+
transition?: AnimateOptions & {
|
|
54
|
+
layout?: DynamicAnimationOptions;
|
|
55
|
+
};
|
|
53
56
|
layoutGroup?: LayoutGroupState;
|
|
57
|
+
motionConfig?: MotionConfigState;
|
|
58
|
+
onAnimationComplete?: (definition: AnimateOptions) => void;
|
|
59
|
+
onUpdate?: (latest: ResolvedValues) => void;
|
|
54
60
|
}
|
|
55
61
|
export interface MotionStateContext {
|
|
56
62
|
initial?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "motion-v",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@vitest/coverage-v8": "^1.4.0",
|
|
64
64
|
"@vue/test-utils": "^2.4.5",
|
|
65
65
|
"framer-motion": "^11.15.0",
|
|
66
|
+
"happy-dom": "^16.0.1",
|
|
66
67
|
"jsdom": "^24.0.0",
|
|
67
68
|
"vite": "^5.4.8",
|
|
68
69
|
"vite-plugin-dts": "^4.2.4",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"scripts": {
|
|
72
73
|
"dev": "vite build --watch",
|
|
73
74
|
"build": "rm -rf dist && vite build",
|
|
74
|
-
"test": "vitest",
|
|
75
|
+
"test": "vitest --dom",
|
|
75
76
|
"coverage": "vitest run --coverage",
|
|
76
77
|
"pub:release": "pnpm publish --access public"
|
|
77
78
|
}
|
/package/dist/es/components/{AnimatePresence.vue2.mjs → animate-presence/AnimatePresence.vue2.mjs}
RENAMED
|
File without changes
|