motion-v 0.4.1 → 0.5.0-beta.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/dist/cjs/index.js +287 -96
- package/dist/es/components/AnimatePresence.vue.mjs +13 -2
- package/dist/es/components/LayoutGroup.vue.mjs +3 -23
- package/dist/es/components/Motion.vue.mjs +16 -15
- package/dist/es/components/presence.mjs +5 -2
- package/dist/es/components/use-layout-group.mjs +34 -0
- package/dist/es/components/use-pop-layout.mjs +47 -0
- package/dist/es/components/utils.mjs +8 -0
- package/dist/es/constants/index.mjs +1 -1
- package/dist/es/features/gestures/hover.mjs +4 -0
- package/dist/es/features/gestures/in-view.mjs +4 -0
- package/dist/es/features/layout/layout.mjs +7 -4
- package/dist/es/state/animate-variants-children.mjs +72 -0
- package/dist/es/state/motion-state.mjs +67 -20
- package/dist/es/state/schedule.mjs +1 -1
- package/dist/src/components/AnimatePresence.d.ts +2 -7
- package/dist/src/components/LayoutGroup.d.ts +1 -5
- package/dist/src/components/Motion.d.ts +1 -3
- package/dist/src/components/presence.d.ts +2 -1
- package/dist/src/components/type.d.ts +5 -24
- package/dist/src/components/use-layout-group.d.ts +20 -0
- package/dist/src/components/use-pop-layout.d.ts +6 -0
- package/dist/src/components/utils.d.ts +1 -0
- package/dist/src/features/layout/types.d.ts +1 -1
- package/dist/src/index.d.ts +5 -3
- package/dist/src/state/animate-variants-children.d.ts +15 -0
- package/dist/src/state/motion-state.d.ts +7 -7
- package/dist/src/types/state.d.ts +11 -2
- package/package.json +1 -1
- /package/dist/es/external/.pnpm/{@vueuse_shared@12.0.0_typescript@5.5.4 → @vueuse_shared@12.0.0_typescript@5.7.2}/external/@vueuse/shared/index.mjs +0 -0
|
@@ -3,8 +3,8 @@ import { injectMotion, injectLayoutGroup, provideMotion } from "./context.mjs";
|
|
|
3
3
|
import { convertSvgStyleToAttributes, createStyles } from "../state/style.mjs";
|
|
4
4
|
import { Primitive } from "./Primitive.mjs";
|
|
5
5
|
import { MotionState } from "../state/motion-state.mjs";
|
|
6
|
-
import { isSVGElement } from "../state/utils.mjs";
|
|
7
6
|
import { injectAnimatePresence } from "./presence.mjs";
|
|
7
|
+
import { getMotionElement } from "./utils.mjs";
|
|
8
8
|
import { isMotionValue } from "../utils/motion-value.mjs";
|
|
9
9
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
10
10
|
...{
|
|
@@ -35,7 +35,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
35
35
|
onPressEnd: { type: Function },
|
|
36
36
|
onViewEnter: { type: Function },
|
|
37
37
|
onViewLeave: { type: Function },
|
|
38
|
-
layout: { type: Boolean },
|
|
38
|
+
layout: { type: [Boolean, String] },
|
|
39
39
|
layoutId: {},
|
|
40
40
|
layoutScroll: { type: Boolean },
|
|
41
41
|
layoutRoot: { type: Boolean },
|
|
@@ -66,16 +66,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
66
66
|
parentState
|
|
67
67
|
);
|
|
68
68
|
provideMotion(state);
|
|
69
|
-
const instance = getCurrentInstance();
|
|
69
|
+
const instance = getCurrentInstance().proxy;
|
|
70
70
|
onMounted(() => {
|
|
71
|
-
state.mount(instance
|
|
72
|
-
state.update({
|
|
71
|
+
state.mount(getMotionElement(instance.$el), {
|
|
73
72
|
...attrs,
|
|
74
|
-
...props
|
|
73
|
+
...props,
|
|
74
|
+
initial: presenceInitial.value === false ? presenceInitial.value : props.initial === true ? void 0 : props.initial
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
onUnmounted(() => {
|
|
78
|
-
if (safeUnmount(instance
|
|
78
|
+
if (safeUnmount(getMotionElement(instance.$el)))
|
|
79
79
|
state.unmount();
|
|
80
80
|
});
|
|
81
81
|
onUpdated(() => {
|
|
@@ -86,22 +86,23 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
function getProps() {
|
|
89
|
+
const isSVG = state.visualElement.type === "svg";
|
|
89
90
|
const attrsProps = { ...attrs };
|
|
90
91
|
Object.keys(attrs).forEach((key) => {
|
|
91
92
|
if (isMotionValue(attrs[key]))
|
|
92
93
|
attrsProps[key] = attrs[key].get();
|
|
93
94
|
});
|
|
94
95
|
let styleProps = {
|
|
95
|
-
...props.style
|
|
96
|
+
...props.style,
|
|
97
|
+
...isSVG ? {} : state.visualElement.latestValues
|
|
96
98
|
};
|
|
99
|
+
if (isSVG) {
|
|
100
|
+
const { attributes, style } = convertSvgStyleToAttributes(state.target);
|
|
101
|
+
Object.assign(attrsProps, attributes);
|
|
102
|
+
Object.assign(styleProps, style, props.style);
|
|
103
|
+
}
|
|
97
104
|
if (!state.isMounted()) {
|
|
98
|
-
|
|
99
|
-
const { attributes, style } = convertSvgStyleToAttributes(state.getTarget());
|
|
100
|
-
Object.assign(attrsProps, attributes);
|
|
101
|
-
Object.assign(styleProps, style, props.style);
|
|
102
|
-
} else {
|
|
103
|
-
Object.assign(styleProps, state.getTarget(), props.style);
|
|
104
|
-
}
|
|
105
|
+
Object.assign(styleProps, state.target, props.style);
|
|
105
106
|
}
|
|
106
107
|
styleProps = createStyles(styleProps);
|
|
107
108
|
attrsProps.style = styleProps;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
1
2
|
import { createContext } from "../utils/createContext.mjs";
|
|
2
|
-
const doneCallbacks = /* @__PURE__ */ new
|
|
3
|
+
const doneCallbacks = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
const unPresenceDom = ref(/* @__PURE__ */ new WeakMap());
|
|
3
5
|
function removeDoneCallback(element) {
|
|
4
6
|
const prevDoneCallback = doneCallbacks.get(element);
|
|
5
7
|
if (prevDoneCallback) {
|
|
@@ -12,5 +14,6 @@ export {
|
|
|
12
14
|
doneCallbacks,
|
|
13
15
|
injectAnimatePresence,
|
|
14
16
|
provideAnimatePresence,
|
|
15
|
-
removeDoneCallback
|
|
17
|
+
removeDoneCallback,
|
|
18
|
+
unPresenceDom
|
|
16
19
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { injectLayoutGroup, provideLayoutGroup } from "./context.mjs";
|
|
3
|
+
import { useForceUpdate } from "./use-force-update.mjs";
|
|
4
|
+
import { nodeGroup } from "./group.mjs";
|
|
5
|
+
function useLayoutGroup(props) {
|
|
6
|
+
const parentGroup = injectLayoutGroup(null);
|
|
7
|
+
const [forceRender, key] = useForceUpdate();
|
|
8
|
+
const context = {
|
|
9
|
+
id: getGroupId(props, parentGroup),
|
|
10
|
+
group: getGroup(props, parentGroup),
|
|
11
|
+
forceRender,
|
|
12
|
+
key
|
|
13
|
+
};
|
|
14
|
+
watch(key, () => {
|
|
15
|
+
context.id = getGroupId(props, parentGroup);
|
|
16
|
+
});
|
|
17
|
+
provideLayoutGroup(context);
|
|
18
|
+
return context;
|
|
19
|
+
}
|
|
20
|
+
function getGroupId(props, parentGroup) {
|
|
21
|
+
const shouldInherit = props.inherit === true || props.inherit === "id";
|
|
22
|
+
const parentId = parentGroup == null ? void 0 : parentGroup.id;
|
|
23
|
+
if (shouldInherit && parentId) {
|
|
24
|
+
return props.id ? `${parentId}-${props.id}` : parentId;
|
|
25
|
+
}
|
|
26
|
+
return props.id;
|
|
27
|
+
}
|
|
28
|
+
function getGroup(props, parentGroup) {
|
|
29
|
+
const shouldInherit = props.inherit === true || props.inherit === "group";
|
|
30
|
+
return shouldInherit ? (parentGroup == null ? void 0 : parentGroup.group) || nodeGroup() : nodeGroup();
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
useLayoutGroup
|
|
34
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function usePopLayout(props) {
|
|
2
|
+
const styles = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function addPopStyle(state) {
|
|
4
|
+
if (props.mode !== "popLayout")
|
|
5
|
+
return;
|
|
6
|
+
const size = {
|
|
7
|
+
height: state.element.offsetHeight || 0,
|
|
8
|
+
width: state.element.offsetWidth || 0,
|
|
9
|
+
top: state.element.offsetTop,
|
|
10
|
+
left: state.element.offsetLeft
|
|
11
|
+
};
|
|
12
|
+
state.element.dataset.motionPopId = state.id;
|
|
13
|
+
const style = document.createElement("style");
|
|
14
|
+
styles.set(state, style);
|
|
15
|
+
document.head.appendChild(style);
|
|
16
|
+
style.textContent = `
|
|
17
|
+
[data-motion-pop-id="${state.id}"] {
|
|
18
|
+
animation: pop 0.3s ease-in-out;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
if (style.sheet) {
|
|
22
|
+
style.sheet.insertRule(`
|
|
23
|
+
[data-motion-pop-id="${state.id}"] {
|
|
24
|
+
position: absolute !important;
|
|
25
|
+
width: ${size.width}px !important;
|
|
26
|
+
height: ${size.height}px !important;
|
|
27
|
+
top: ${size.top}px !important;
|
|
28
|
+
left: ${size.left}px !important;
|
|
29
|
+
}
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function removePopStyle(state) {
|
|
34
|
+
const style = styles.get(state);
|
|
35
|
+
if (style) {
|
|
36
|
+
styles.delete(state);
|
|
37
|
+
document.head.removeChild(style);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
addPopStyle,
|
|
42
|
+
removePopStyle
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
usePopLayout
|
|
47
|
+
};
|
|
@@ -20,7 +20,11 @@ class HoverGesture extends BaseGesture {
|
|
|
20
20
|
this.state.setActive("hover", true);
|
|
21
21
|
});
|
|
22
22
|
const onLeave = mouseEvent(element, "hoverend", () => {
|
|
23
|
+
var _a;
|
|
23
24
|
this.state.setActive("hover", false);
|
|
25
|
+
(_a = this.state.visualElement.variantChildren) == null ? void 0 : _a.forEach((child) => {
|
|
26
|
+
child.state.setActive("hover", false);
|
|
27
|
+
});
|
|
24
28
|
});
|
|
25
29
|
element.addEventListener("pointerenter", onEnter);
|
|
26
30
|
element.addEventListener("pointerleave", onLeave);
|
|
@@ -12,7 +12,11 @@ class InViewGesture extends BaseGesture {
|
|
|
12
12
|
const element = this.state.element;
|
|
13
13
|
const { once, ...viewOptions } = ((_a = this.state.getOptions()) == null ? void 0 : _a.inViewOptions) || {};
|
|
14
14
|
return inView(element, (enterEntry) => {
|
|
15
|
+
var _a2;
|
|
15
16
|
this.state.setActive("inView", true);
|
|
17
|
+
(_a2 = this.state.visualElement.variantChildren) == null ? void 0 : _a2.forEach((child) => {
|
|
18
|
+
child.state.setActive("inView", true);
|
|
19
|
+
});
|
|
16
20
|
dispatchPointerEvent(element, "viewenter", enterEntry);
|
|
17
21
|
if (!once) {
|
|
18
22
|
return (leaveEntry) => {
|
|
@@ -40,11 +40,8 @@ class LayoutFeature extends Feature {
|
|
|
40
40
|
(_a = visualElement.projection) == null ? void 0 : _a.root.didUpdate();
|
|
41
41
|
});
|
|
42
42
|
onBeforeUnmount(() => {
|
|
43
|
-
var _a;
|
|
44
43
|
if (visualElement.projection) {
|
|
45
|
-
visualElement.projection.
|
|
46
|
-
if ((_a = this.layoutGroup) == null ? void 0 : _a.group)
|
|
47
|
-
this.layoutGroup.group.remove(visualElement.projection);
|
|
44
|
+
visualElement.projection.willUpdate();
|
|
48
45
|
}
|
|
49
46
|
});
|
|
50
47
|
}
|
|
@@ -67,6 +64,12 @@ class LayoutFeature extends Feature {
|
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
unmount() {
|
|
67
|
+
var _a;
|
|
68
|
+
if (this.state.visualElement.projection) {
|
|
69
|
+
this.state.visualElement.projection.unmount();
|
|
70
|
+
if ((_a = this.layoutGroup) == null ? void 0 : _a.group)
|
|
71
|
+
this.layoutGroup.group.remove(this.state.visualElement.projection);
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
export {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { style } from "./style.mjs";
|
|
2
|
+
import { transformResetValue } from "./transform.mjs";
|
|
3
|
+
import { resolveVariant, hasChanged, getOptions } from "./utils.mjs";
|
|
4
|
+
import { animate } from "../external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/animation/animate/index.mjs";
|
|
5
|
+
function animateVariantsChildren(state, activeState) {
|
|
6
|
+
const variantChildren = state.visualElement.variantChildren;
|
|
7
|
+
if (!(variantChildren == null ? void 0 : variantChildren.size)) {
|
|
8
|
+
return {
|
|
9
|
+
animations: [],
|
|
10
|
+
getAnimations: () => Promise.resolve()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const animationFactories = [];
|
|
14
|
+
Array.from(variantChildren).forEach((child, index) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const prevTarget = child.state.target;
|
|
17
|
+
const childState = child.state;
|
|
18
|
+
childState.target = {};
|
|
19
|
+
for (const name in activeState) {
|
|
20
|
+
childState.activeStates[name] = true;
|
|
21
|
+
const { definition, transition } = activeState[name];
|
|
22
|
+
const { staggerChildren = 0, staggerDirection = 1, delayChildren = 0 } = transition;
|
|
23
|
+
const maxStaggerDuration = (variantChildren.size - 1) * staggerChildren;
|
|
24
|
+
const generateStaggerDuration = staggerDirection === 1 ? (i = 0) => i * staggerChildren : (i = 0) => maxStaggerDuration - i * staggerChildren;
|
|
25
|
+
const variant = resolveVariant(
|
|
26
|
+
definition,
|
|
27
|
+
child.props.variants,
|
|
28
|
+
child.props.custom
|
|
29
|
+
);
|
|
30
|
+
const animationOptions = {};
|
|
31
|
+
const allTarget = { ...prevTarget, ...variant };
|
|
32
|
+
for (const key in allTarget) {
|
|
33
|
+
if (key === "transition")
|
|
34
|
+
continue;
|
|
35
|
+
childState.target[key] = allTarget[key];
|
|
36
|
+
if (childState.target[key] === void 0) {
|
|
37
|
+
childState.target[key] = childState.baseTarget[key];
|
|
38
|
+
}
|
|
39
|
+
if (hasChanged(prevTarget[key], childState.target[key])) {
|
|
40
|
+
(_a = childState.baseTarget)[key] ?? (_a[key] = style.get(child.current, key));
|
|
41
|
+
animationOptions[key] = getOptions(
|
|
42
|
+
Object.assign({}, transition, allTarget.transition, child.props.transition),
|
|
43
|
+
key
|
|
44
|
+
);
|
|
45
|
+
const keyValue = childState.target[key] === "none" ? transformResetValue[key] : childState.target[key];
|
|
46
|
+
animationFactories.push(
|
|
47
|
+
() => {
|
|
48
|
+
var _a2;
|
|
49
|
+
return animate(
|
|
50
|
+
child.current,
|
|
51
|
+
{
|
|
52
|
+
[key]: keyValue
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
...animationOptions[key] || {},
|
|
56
|
+
delay: (((_a2 = animationOptions[key]) == null ? void 0 : _a2.delay) || 0) + delayChildren + generateStaggerDuration(index)
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
animations: animationFactories,
|
|
67
|
+
getAnimations: () => Promise.all(animationFactories.map((factory) => factory()))
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
animateVariantsChildren
|
|
72
|
+
};
|
|
@@ -7,10 +7,12 @@ import { transformResetValue } from "./transform.mjs";
|
|
|
7
7
|
import { scheduleAnimation, unscheduleAnimation } from "./schedule.mjs";
|
|
8
8
|
import { motionEvent } from "./event.mjs";
|
|
9
9
|
import { createVisualElement } from "./create-visual-element.mjs";
|
|
10
|
+
import { animateVariantsChildren } from "./animate-variants-children.mjs";
|
|
10
11
|
import { animate } from "../external/.pnpm/framer-motion@11.11.11/external/framer-motion/dist/es/animation/animate/index.mjs";
|
|
11
|
-
import { isDef } from "../external/.pnpm/@vueuse_shared@12.0.0_typescript@5.
|
|
12
|
+
import { isDef } from "../external/.pnpm/@vueuse_shared@12.0.0_typescript@5.7.2/external/@vueuse/shared/index.mjs";
|
|
12
13
|
const STATE_TYPES = ["initial", "animate", "inView", "hover", "press", "exit", "drag"];
|
|
13
14
|
const mountedStates = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
let id = 0;
|
|
14
16
|
class MotionState {
|
|
15
17
|
constructor(options, parent) {
|
|
16
18
|
this.element = null;
|
|
@@ -19,6 +21,7 @@ class MotionState {
|
|
|
19
21
|
animate: true
|
|
20
22
|
};
|
|
21
23
|
this._context = null;
|
|
24
|
+
this.id = `motion-state-${id++}`;
|
|
22
25
|
this.options = options;
|
|
23
26
|
this.parent = parent;
|
|
24
27
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
@@ -26,7 +29,10 @@ class MotionState {
|
|
|
26
29
|
presenceContext: null,
|
|
27
30
|
parent: parent == null ? void 0 : parent.visualElement,
|
|
28
31
|
props: {
|
|
29
|
-
...this.options
|
|
32
|
+
...this.options,
|
|
33
|
+
whileHover: this.options.hover,
|
|
34
|
+
whileTap: this.options.press,
|
|
35
|
+
whileInView: this.options.inView
|
|
30
36
|
},
|
|
31
37
|
visualState: {
|
|
32
38
|
renderState: {
|
|
@@ -62,19 +68,29 @@ class MotionState {
|
|
|
62
68
|
get initial() {
|
|
63
69
|
return isDef(this.options.initial) ? this.options.initial : this.context.initial;
|
|
64
70
|
}
|
|
65
|
-
|
|
71
|
+
updateOptions() {
|
|
66
72
|
var _a;
|
|
73
|
+
this.visualElement.update({
|
|
74
|
+
...this.options,
|
|
75
|
+
whileHover: this.options.hover,
|
|
76
|
+
whileTap: this.options.press,
|
|
77
|
+
whileInView: this.options.inView
|
|
78
|
+
}, (_a = this.parent) == null ? void 0 : _a.context);
|
|
79
|
+
}
|
|
80
|
+
mount(element, options) {
|
|
67
81
|
invariant(
|
|
68
82
|
Boolean(element),
|
|
69
83
|
"Animation state must be mounted with valid Element"
|
|
70
84
|
);
|
|
71
85
|
this.element = element;
|
|
86
|
+
this.options = options;
|
|
72
87
|
mountedStates.set(element, this);
|
|
73
88
|
if (!visualElementStore.get(element)) {
|
|
74
89
|
this.visualElement.mount(element);
|
|
75
90
|
visualElementStore.set(element, this.visualElement);
|
|
76
91
|
}
|
|
77
|
-
this.visualElement.
|
|
92
|
+
this.visualElement.state = this;
|
|
93
|
+
this.updateOptions();
|
|
78
94
|
if (typeof this.initial === "object") {
|
|
79
95
|
for (const key in this.initial) {
|
|
80
96
|
this.visualElement.setStaticValue(key, this.initial[key]);
|
|
@@ -85,6 +101,7 @@ class MotionState {
|
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
this.featureManager.mount();
|
|
104
|
+
scheduleAnimation(this);
|
|
88
105
|
}
|
|
89
106
|
unmount() {
|
|
90
107
|
var _a;
|
|
@@ -94,14 +111,13 @@ class MotionState {
|
|
|
94
111
|
this.featureManager.unmount();
|
|
95
112
|
}
|
|
96
113
|
update(options) {
|
|
97
|
-
var _a;
|
|
98
114
|
this.options = options;
|
|
99
|
-
this.
|
|
115
|
+
this.updateOptions();
|
|
100
116
|
this.featureManager.update();
|
|
101
117
|
scheduleAnimation(this);
|
|
102
118
|
}
|
|
103
119
|
setActive(name, isActive) {
|
|
104
|
-
if (!this.element)
|
|
120
|
+
if (!this.element || this.activeStates[name] === isActive)
|
|
105
121
|
return;
|
|
106
122
|
this.activeStates[name] = isActive;
|
|
107
123
|
scheduleAnimation(this);
|
|
@@ -109,15 +125,25 @@ class MotionState {
|
|
|
109
125
|
*animateUpdates() {
|
|
110
126
|
const prevTarget = this.target;
|
|
111
127
|
this.target = {};
|
|
128
|
+
const activeState = {};
|
|
112
129
|
const animationOptions = {};
|
|
130
|
+
let transition;
|
|
113
131
|
for (const name of STATE_TYPES) {
|
|
114
132
|
if (!this.activeStates[name])
|
|
115
133
|
continue;
|
|
134
|
+
const definition = isDef(this.options[name]) ? this.options[name] : this.context[name];
|
|
116
135
|
const variant = resolveVariant(
|
|
117
|
-
|
|
136
|
+
definition,
|
|
118
137
|
this.options.variants,
|
|
119
138
|
this.options.custom
|
|
120
139
|
);
|
|
140
|
+
transition = Object.assign({}, this.options.transition, variant == null ? void 0 : variant.transition);
|
|
141
|
+
if (typeof definition === "string") {
|
|
142
|
+
activeState[name] = {
|
|
143
|
+
definition,
|
|
144
|
+
transition
|
|
145
|
+
};
|
|
146
|
+
}
|
|
121
147
|
if (!variant)
|
|
122
148
|
continue;
|
|
123
149
|
const allTarget = { ...prevTarget, ...variant };
|
|
@@ -126,7 +152,7 @@ class MotionState {
|
|
|
126
152
|
continue;
|
|
127
153
|
this.target[key] = variant[key];
|
|
128
154
|
animationOptions[key] = getOptions(
|
|
129
|
-
|
|
155
|
+
transition,
|
|
130
156
|
key
|
|
131
157
|
);
|
|
132
158
|
}
|
|
@@ -143,12 +169,13 @@ class MotionState {
|
|
|
143
169
|
}
|
|
144
170
|
if (hasChanged(prevTarget[key], this.target[key])) {
|
|
145
171
|
(_a = this.baseTarget)[key] ?? (_a[key] = style.get(this.element, key));
|
|
172
|
+
const keyValue = this.target[key] === "none" ? transformResetValue[key] : this.target[key];
|
|
146
173
|
animationFactories.push(
|
|
147
174
|
() => {
|
|
148
175
|
return animate(
|
|
149
176
|
this.element,
|
|
150
177
|
{
|
|
151
|
-
[key]:
|
|
178
|
+
[key]: keyValue
|
|
152
179
|
},
|
|
153
180
|
animationOptions[key] || {}
|
|
154
181
|
);
|
|
@@ -156,14 +183,40 @@ class MotionState {
|
|
|
156
183
|
);
|
|
157
184
|
}
|
|
158
185
|
});
|
|
186
|
+
let getChildAnimations = () => Promise.resolve();
|
|
187
|
+
let childAnimations = [];
|
|
188
|
+
if (Object.keys(activeState).length) {
|
|
189
|
+
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState);
|
|
190
|
+
getChildAnimations = getAnimations;
|
|
191
|
+
childAnimations = animations2;
|
|
192
|
+
}
|
|
159
193
|
yield;
|
|
160
|
-
|
|
161
|
-
|
|
194
|
+
let animations;
|
|
195
|
+
const getAnimation = () => {
|
|
196
|
+
animations = animationFactories.map((factory) => factory()).filter(Boolean);
|
|
197
|
+
return Promise.all(animations);
|
|
198
|
+
};
|
|
199
|
+
const { when } = transition;
|
|
200
|
+
let animationPromise;
|
|
201
|
+
if (when) {
|
|
202
|
+
const [first, last] = when === "beforeChildren" ? [getAnimation, getChildAnimations] : [getChildAnimations, getAnimation];
|
|
203
|
+
animationPromise = first().then(() => last());
|
|
204
|
+
} else {
|
|
205
|
+
animationPromise = Promise.all([getAnimation(), getChildAnimations()]);
|
|
206
|
+
}
|
|
207
|
+
const isExit = this.activeStates.exit;
|
|
208
|
+
if (!(animations == null ? void 0 : animations.length) && !childAnimations.length) {
|
|
209
|
+
if (isExit) {
|
|
210
|
+
this.element.dispatchEvent(motionEvent("motionstart", this.target));
|
|
211
|
+
this.element.dispatchEvent(motionEvent("motioncomplete", {
|
|
212
|
+
...this.target
|
|
213
|
+
}, isExit));
|
|
214
|
+
}
|
|
162
215
|
return;
|
|
216
|
+
}
|
|
163
217
|
const animationTarget = this.target;
|
|
164
218
|
this.element.dispatchEvent(motionEvent("motionstart", animationTarget));
|
|
165
|
-
|
|
166
|
-
Promise.all(animations).then(() => {
|
|
219
|
+
animationPromise.then(() => {
|
|
167
220
|
this.element.dispatchEvent(motionEvent("motioncomplete", {
|
|
168
221
|
...animationTarget
|
|
169
222
|
}, isExit));
|
|
@@ -172,15 +225,9 @@ class MotionState {
|
|
|
172
225
|
isMounted() {
|
|
173
226
|
return Boolean(this.element);
|
|
174
227
|
}
|
|
175
|
-
getDepth() {
|
|
176
|
-
return this.depth;
|
|
177
|
-
}
|
|
178
228
|
getOptions() {
|
|
179
229
|
return this.options;
|
|
180
230
|
}
|
|
181
|
-
getTarget() {
|
|
182
|
-
return this.target;
|
|
183
|
-
}
|
|
184
231
|
}
|
|
185
232
|
export {
|
|
186
233
|
MotionState,
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
mode?: 'wait' | 'sync';
|
|
3
|
-
initial?: boolean;
|
|
4
|
-
multiple?: boolean;
|
|
5
|
-
as?: string;
|
|
6
|
-
}
|
|
1
|
+
import { AnimatePresenceProps } from './type';
|
|
7
2
|
declare function __VLS_template(): {
|
|
8
3
|
slots: {
|
|
9
4
|
default?(_: {}): any;
|
|
@@ -21,7 +16,7 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_WithDefaults<
|
|
|
21
16
|
initial: boolean;
|
|
22
17
|
multiple: boolean;
|
|
23
18
|
}>>>, {
|
|
24
|
-
mode: "wait" | "sync";
|
|
19
|
+
mode: "wait" | "popLayout" | "sync";
|
|
25
20
|
initial: boolean;
|
|
26
21
|
multiple: boolean;
|
|
27
22
|
}, {}>;
|
|
@@ -12,9 +12,7 @@ declare const _default: <T extends ElementType = "div", K = unknown>(__VLS_props
|
|
|
12
12
|
default?(_: {}): any;
|
|
13
13
|
};
|
|
14
14
|
emit: {};
|
|
15
|
-
}>) => import('vue').VNode
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
}> & {
|
|
15
|
+
}>) => import('vue').VNode & {
|
|
18
16
|
__ctx?: Awaited<typeof __VLS_setup>;
|
|
19
17
|
};
|
|
20
18
|
export default _default;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
export declare const doneCallbacks:
|
|
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>>>;
|
|
3
4
|
export declare function removeDoneCallback(element: Element): void;
|
|
4
5
|
export interface PresenceContext {
|
|
5
6
|
initial: Ref<boolean>;
|
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
originY?: string | number;
|
|
7
|
-
originZ?: string | number;
|
|
8
|
-
};
|
|
9
|
-
attrs: Record<string, any>;
|
|
10
|
-
dimensions?: {
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
interface SVGProps {
|
|
18
|
-
attrX?: number;
|
|
19
|
-
attrY?: number;
|
|
20
|
-
attrScale?: number;
|
|
21
|
-
pathLength?: number;
|
|
22
|
-
pathSpacing?: number;
|
|
23
|
-
pathOffset?: number;
|
|
24
|
-
[key: string]: any;
|
|
1
|
+
export interface AnimatePresenceProps {
|
|
2
|
+
mode?: 'wait' | 'popLayout' | 'sync';
|
|
3
|
+
initial?: boolean;
|
|
4
|
+
multiple?: boolean;
|
|
5
|
+
as?: string;
|
|
25
6
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LayoutGroupState } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Props for configuring layout group behavior
|
|
4
|
+
*/
|
|
5
|
+
export interface LayoutGroupProps {
|
|
6
|
+
/** Optional ID for the layout group */
|
|
7
|
+
id?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Controls inheritance of parent group properties:
|
|
10
|
+
* - true: Inherit both id and group
|
|
11
|
+
* - 'id': Only inherit id
|
|
12
|
+
* - 'group': Only inherit group
|
|
13
|
+
*/
|
|
14
|
+
inherit?: boolean | 'id' | 'group';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hook to create and manage a layout group
|
|
18
|
+
* Handles group inheritance, force updates, and context management
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLayoutGroup(props: LayoutGroupProps): LayoutGroupState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMotionElement(el: HTMLElement): HTMLElement;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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 { default as AnimatePresence
|
|
5
|
-
export {
|
|
4
|
+
export { default as AnimatePresence } from './components/AnimatePresence';
|
|
5
|
+
export type { AnimatePresenceProps } from './components/type';
|
|
6
|
+
export { default as LayoutGroup } from './components/LayoutGroup';
|
|
7
|
+
export type { LayoutGroupProps } from './components/use-layout-group';
|
|
6
8
|
export * from './components/context';
|
|
7
9
|
export * from './value';
|
|
8
10
|
export * from './constants';
|
|
9
|
-
export
|
|
11
|
+
export * from './types';
|
|
10
12
|
export * from './animation';
|
|
11
13
|
export * from './utils';
|