motion-v 0.5.2-beta.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 +205 -147
- package/dist/es/components/LayoutGroup.vue.mjs +1 -3
- package/dist/es/components/Motion.vue.mjs +35 -30
- package/dist/es/components/{AnimatePresence.vue.mjs → animate-presence/AnimatePresence.vue.mjs} +37 -14
- package/dist/es/components/{use-pop-layout.mjs → animate-presence/use-pop-layout.mjs} +1 -1
- package/dist/es/components/group.mjs +5 -2
- package/dist/es/components/presence.mjs +0 -2
- package/dist/es/components/utils.mjs +7 -0
- package/dist/es/constants/index.mjs +2 -1
- package/dist/es/features/layout/layout.mjs +17 -8
- package/dist/es/features/layout/projection.mjs +17 -1
- package/dist/es/index.mjs +4 -4
- package/dist/es/state/animate-variants-children.mjs +5 -3
- package/dist/es/state/motion-state.mjs +49 -22
- package/dist/es/state/schedule.mjs +2 -26
- package/dist/es/state/utils.mjs +0 -9
- 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 -0
- 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/presence.d.ts +3 -5
- package/dist/src/components/utils.d.ts +7 -0
- package/dist/src/index.d.ts +1 -3
- 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 +6 -2
- package/package.json +3 -2
- /package/dist/es/components/{AnimatePresence.vue2.mjs → animate-presence/AnimatePresence.vue2.mjs} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent,
|
|
1
|
+
import { defineComponent, onBeforeUpdate, renderSlot, unref } from "vue";
|
|
2
2
|
import { useLayoutGroupProvider } from "./use-layout-group.mjs";
|
|
3
3
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
4
4
|
__name: "LayoutGroup",
|
|
@@ -9,8 +9,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
9
9
|
setup(__props) {
|
|
10
10
|
const props = __props;
|
|
11
11
|
const { forceRender, key, group } = useLayoutGroupProvider(props);
|
|
12
|
-
onUpdated(() => {
|
|
13
|
-
});
|
|
14
12
|
onBeforeUpdate(() => {
|
|
15
13
|
group.dirty();
|
|
16
14
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defineComponent, mergeDefaults,
|
|
1
|
+
import { defineComponent, mergeDefaults, useAttrs, getCurrentInstance, onBeforeMount, onMounted, onBeforeUnmount, onUnmounted, onBeforeUpdate, onUpdated, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot } from "vue";
|
|
2
2
|
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
6
|
import { injectAnimatePresence } from "./presence.mjs";
|
|
7
|
-
import { getMotionElement } from "./utils.mjs";
|
|
7
|
+
import { getMotionElement, checkMotionIsHidden } from "./utils.mjs";
|
|
8
8
|
import { useMotionConfig } from "./motion-config/context.mjs";
|
|
9
9
|
import { isMotionValue } from "../utils/motion-value.mjs";
|
|
10
10
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -27,6 +27,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
27
27
|
transition: {},
|
|
28
28
|
layoutGroup: {},
|
|
29
29
|
motionConfig: {},
|
|
30
|
+
onAnimationComplete: { type: Function },
|
|
31
|
+
onUpdate: { type: Function },
|
|
30
32
|
layout: { type: [Boolean, String] },
|
|
31
33
|
layoutId: {},
|
|
32
34
|
layoutScroll: { type: Boolean },
|
|
@@ -80,22 +82,33 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
80
82
|
dragElastic: 0.2,
|
|
81
83
|
dragMomentum: true,
|
|
82
84
|
whileDrag: void 0,
|
|
83
|
-
crossfade:
|
|
85
|
+
crossfade: true
|
|
84
86
|
}),
|
|
85
87
|
setup(__props) {
|
|
86
88
|
const props = __props;
|
|
87
|
-
const
|
|
89
|
+
const animatePresenceContext = injectAnimatePresence({});
|
|
88
90
|
const parentState = injectMotion(null);
|
|
89
91
|
const attrs = useAttrs();
|
|
90
92
|
const layoutGroup = injectLayoutGroup({});
|
|
91
93
|
const config = useMotionConfig();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
function getLayoutId() {
|
|
95
|
+
if (layoutGroup.id && props.layoutId)
|
|
96
|
+
return `${layoutGroup.id}-${props.layoutId}`;
|
|
97
|
+
return props.layoutId || void 0;
|
|
98
|
+
}
|
|
99
|
+
function getMotionProps() {
|
|
100
|
+
return {
|
|
94
101
|
...attrs,
|
|
95
102
|
...props,
|
|
103
|
+
layoutId: getLayoutId(),
|
|
104
|
+
transition: props.transition ?? config.value.transition,
|
|
96
105
|
layoutGroup,
|
|
97
|
-
motionConfig: config.value
|
|
98
|
-
|
|
106
|
+
motionConfig: config.value,
|
|
107
|
+
initial: animatePresenceContext.initial === false ? animatePresenceContext.initial : props.initial === true ? void 0 : props.initial
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const state = new MotionState(
|
|
111
|
+
getMotionProps(),
|
|
99
112
|
parentState
|
|
100
113
|
);
|
|
101
114
|
provideMotion(state);
|
|
@@ -104,29 +117,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
104
117
|
state.beforeMount();
|
|
105
118
|
});
|
|
106
119
|
onMounted(() => {
|
|
107
|
-
state.mount(getMotionElement(instance.$el),
|
|
108
|
-
...attrs,
|
|
109
|
-
...props,
|
|
110
|
-
transition: props.transition ?? config.value.transition,
|
|
111
|
-
layoutGroup,
|
|
112
|
-
motionConfig: config.value,
|
|
113
|
-
initial: presenceInitial.value === false ? presenceInitial.value : props.initial === true ? void 0 : props.initial
|
|
114
|
-
});
|
|
120
|
+
state.mount(getMotionElement(instance.$el), getMotionProps(), checkMotionIsHidden(instance));
|
|
115
121
|
});
|
|
116
122
|
onBeforeUnmount(() => state.beforeUnmount());
|
|
117
123
|
onUnmounted(() => {
|
|
118
|
-
|
|
124
|
+
const el = getMotionElement(instance.$el);
|
|
125
|
+
if (!(el == null ? void 0 : el.isConnected)) {
|
|
119
126
|
state.unmount();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
onBeforeUpdate(() => {
|
|
130
|
+
state.beforeUpdate();
|
|
120
131
|
});
|
|
121
|
-
onBeforeUpdate(() => state.beforeUpdate());
|
|
122
132
|
onUpdated(() => {
|
|
123
|
-
state.update(
|
|
124
|
-
...attrs,
|
|
125
|
-
...props,
|
|
126
|
-
transition: props.transition ?? config.value.transition,
|
|
127
|
-
motionConfig: config.value,
|
|
128
|
-
initial: presenceInitial.value === false ? presenceInitial.value : props.initial === true ? void 0 : props.initial
|
|
129
|
-
});
|
|
133
|
+
state.update(getMotionProps());
|
|
130
134
|
});
|
|
131
135
|
function getProps() {
|
|
132
136
|
const isSVG = state.visualElement.type === "svg";
|
|
@@ -145,7 +149,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
145
149
|
Object.assign(styleProps, style);
|
|
146
150
|
}
|
|
147
151
|
if (!state.isMounted()) {
|
|
148
|
-
Object.assign(styleProps, state.
|
|
152
|
+
Object.assign(styleProps, state.baseTarget);
|
|
149
153
|
}
|
|
150
154
|
if (props.drag && props.dragListener !== false) {
|
|
151
155
|
Object.assign(styleProps, {
|
|
@@ -163,15 +167,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
163
167
|
return attrsProps;
|
|
164
168
|
}
|
|
165
169
|
return (_ctx, _cache) => {
|
|
166
|
-
return openBlock(), createBlock(unref(Primitive), mergeProps({
|
|
170
|
+
return openBlock(), createBlock(unref(Primitive), mergeProps(getProps(), {
|
|
167
171
|
as: _ctx.as,
|
|
168
|
-
"as-child": _ctx.asChild
|
|
169
|
-
|
|
172
|
+
"as-child": _ctx.asChild,
|
|
173
|
+
"data-motion-id": unref(state).id
|
|
174
|
+
}), {
|
|
170
175
|
default: withCtx(() => [
|
|
171
176
|
renderSlot(_ctx.$slots, "default")
|
|
172
177
|
]),
|
|
173
178
|
_: 3
|
|
174
|
-
}, 16, ["as", "as-child"]);
|
|
179
|
+
}, 16, ["as", "as-child", "data-motion-id"]);
|
|
175
180
|
};
|
|
176
181
|
}
|
|
177
182
|
});
|
package/dist/es/components/{AnimatePresence.vue.mjs → animate-presence/AnimatePresence.vue.mjs}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { defineComponent,
|
|
2
|
-
import { mountedStates } from "
|
|
3
|
-
import { provideAnimatePresence,
|
|
1
|
+
import { defineComponent, onMounted, onUnmounted, openBlock, createBlock, resolveDynamicComponent, TransitionGroup, Transition, withCtx, renderSlot } from "vue";
|
|
2
|
+
import { mountedStates } from "../../state/motion-state.mjs";
|
|
3
|
+
import { provideAnimatePresence, removeDoneCallback, doneCallbacks } from "../presence.mjs";
|
|
4
4
|
import { usePopLayout } from "./use-pop-layout.mjs";
|
|
5
|
+
import { createStyles } from "../../state/style.mjs";
|
|
5
6
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
7
|
...{
|
|
7
8
|
name: "AnimatePresence",
|
|
@@ -12,19 +13,28 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
12
13
|
mode: { default: "sync" },
|
|
13
14
|
initial: { type: Boolean, default: true },
|
|
14
15
|
multiple: { type: Boolean, default: false },
|
|
15
|
-
as: {}
|
|
16
|
+
as: {},
|
|
17
|
+
custom: {},
|
|
18
|
+
onExitComplete: {}
|
|
16
19
|
},
|
|
17
20
|
setup(__props) {
|
|
18
21
|
const props = __props;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const presenceContext = {
|
|
23
|
+
initial: props.initial,
|
|
24
|
+
custom: props.custom
|
|
25
|
+
};
|
|
26
|
+
provideAnimatePresence(presenceContext);
|
|
27
|
+
onMounted(() => {
|
|
28
|
+
presenceContext.initial = void 0;
|
|
25
29
|
});
|
|
26
30
|
function enter(el) {
|
|
27
31
|
const state = mountedStates.get(el);
|
|
32
|
+
const motionStateId = el.dataset.motionId;
|
|
33
|
+
const motionState = mountedStates.get(motionStateId);
|
|
34
|
+
if (motionState) {
|
|
35
|
+
const baseStyle = createStyles(motionState.baseTarget);
|
|
36
|
+
Object.assign(el.style, baseStyle);
|
|
37
|
+
}
|
|
28
38
|
if (!state) {
|
|
29
39
|
return;
|
|
30
40
|
}
|
|
@@ -32,22 +42,35 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
32
42
|
state.setActive("exit", false);
|
|
33
43
|
}
|
|
34
44
|
const { addPopStyle, removePopStyle } = usePopLayout(props);
|
|
45
|
+
const exitDom = /* @__PURE__ */ new Map();
|
|
46
|
+
onUnmounted(() => {
|
|
47
|
+
exitDom.clear();
|
|
48
|
+
});
|
|
35
49
|
function exit(el, done) {
|
|
36
50
|
const state = mountedStates.get(el);
|
|
37
51
|
if (!state) {
|
|
38
52
|
return done();
|
|
39
53
|
}
|
|
54
|
+
exitDom.set(el, true);
|
|
40
55
|
removeDoneCallback(el);
|
|
41
56
|
addPopStyle(state);
|
|
42
57
|
function doneCallback(e) {
|
|
43
58
|
var _a, _b;
|
|
44
|
-
removePopStyle(state);
|
|
45
59
|
if ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.isExit) {
|
|
60
|
+
const projection = state.visualElement.projection;
|
|
61
|
+
if ((projection == null ? void 0 : projection.animationProgress) > 0 && !state.isSafeToRemove) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
state.willUpdate("done");
|
|
65
|
+
removePopStyle(state);
|
|
46
66
|
removeDoneCallback(el);
|
|
47
|
-
|
|
67
|
+
exitDom.delete(el);
|
|
68
|
+
if (exitDom.size === 0) {
|
|
69
|
+
(_b = props.onExitComplete) == null ? void 0 : _b.call(props);
|
|
70
|
+
}
|
|
48
71
|
done();
|
|
49
|
-
if (!el.isConnected) {
|
|
50
|
-
state.unmount();
|
|
72
|
+
if (!(el == null ? void 0 : el.isConnected)) {
|
|
73
|
+
state.unmount(true);
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
}
|
|
@@ -20,9 +20,12 @@ function nodeGroup() {
|
|
|
20
20
|
unsubscribe();
|
|
21
21
|
subscriptions.delete(node);
|
|
22
22
|
}
|
|
23
|
-
dirtyAll();
|
|
24
23
|
},
|
|
25
|
-
dirty: dirtyAll
|
|
24
|
+
dirty: dirtyAll,
|
|
25
|
+
didUpdate: () => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = nodes[0]) == null ? void 0 : _a.didUpdate();
|
|
28
|
+
}
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
export {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
1
|
import { createContext } from "../utils/createContext.mjs";
|
|
3
2
|
const doneCallbacks = /* @__PURE__ */ new WeakMap();
|
|
4
|
-
ref(/* @__PURE__ */ new WeakMap());
|
|
5
3
|
function removeDoneCallback(element) {
|
|
6
4
|
const prevDoneCallback = doneCallbacks.get(element);
|
|
7
5
|
if (prevDoneCallback) {
|
|
@@ -3,6 +3,13 @@ function getMotionElement(el) {
|
|
|
3
3
|
return getMotionElement(el.nextSibling);
|
|
4
4
|
return el;
|
|
5
5
|
}
|
|
6
|
+
function checkMotionIsHidden(instance) {
|
|
7
|
+
var _a;
|
|
8
|
+
const isHidden = ((_a = getMotionElement(instance.$el)) == null ? void 0 : _a.style.display) === "none";
|
|
9
|
+
const hasTransition = instance.$.vnode.transition;
|
|
10
|
+
return hasTransition && isHidden;
|
|
11
|
+
}
|
|
6
12
|
export {
|
|
13
|
+
checkMotionIsHidden,
|
|
7
14
|
getMotionElement
|
|
8
15
|
};
|
|
@@ -8,8 +8,7 @@ class LayoutFeature extends Feature {
|
|
|
8
8
|
addScaleCorrector(defaultScaleCorrector);
|
|
9
9
|
}
|
|
10
10
|
beforeUpdate() {
|
|
11
|
-
|
|
12
|
-
(_a = this.state.visualElement.projection) == null ? void 0 : _a.willUpdate();
|
|
11
|
+
this.state.willUpdate("beforeUpdate");
|
|
13
12
|
}
|
|
14
13
|
update() {
|
|
15
14
|
var _a;
|
|
@@ -31,15 +30,25 @@ class LayoutFeature extends Feature {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
beforeUnmount() {
|
|
33
|
+
const projection = this.state.visualElement.projection;
|
|
34
|
+
if (projection) {
|
|
35
|
+
this.state.willUpdate("beforeUnmount");
|
|
36
|
+
if (this.state.options.layoutId) {
|
|
37
|
+
projection.isPresent = false;
|
|
38
|
+
projection.relegate();
|
|
39
|
+
} else if (this.state.options.layout) {
|
|
40
|
+
this.state.isSafeToRemove = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
34
43
|
}
|
|
35
44
|
unmount() {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const layoutGroup = this.state.options.layoutGroup;
|
|
36
47
|
const projection = this.state.visualElement.projection;
|
|
37
|
-
if (projection)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (layoutGroup == null ? void 0 : layoutGroup.group)
|
|
42
|
-
layoutGroup.group.remove(projection);
|
|
48
|
+
if ((layoutGroup == null ? void 0 : layoutGroup.group) && projection)
|
|
49
|
+
layoutGroup.group.remove(projection);
|
|
50
|
+
if (this.state.options.layoutId || this.state.options.layout) {
|
|
51
|
+
(_b = (_a = this.state.visualElement.projection) == null ? void 0 : _a.root) == null ? void 0 : _b.didUpdate();
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
54
|
}
|
|
@@ -3,6 +3,7 @@ import { HTMLProjectionNode } from "../../external/.pnpm/framer-motion@11.15.0/e
|
|
|
3
3
|
import { getClosestProjectingNode } from "./utils.mjs";
|
|
4
4
|
import { addScaleCorrector } from "../../external/.pnpm/framer-motion@11.15.0/external/framer-motion/dist/es/projection/styles/scale-correction.mjs";
|
|
5
5
|
import { defaultScaleCorrector } from "./config.mjs";
|
|
6
|
+
import { doneCallbacks } from "../../components/presence.mjs";
|
|
6
7
|
class ProjectionFeature extends Feature {
|
|
7
8
|
constructor(state) {
|
|
8
9
|
super(state);
|
|
@@ -14,6 +15,7 @@ class ProjectionFeature extends Feature {
|
|
|
14
15
|
this.state.visualElement.latestValues,
|
|
15
16
|
options["data-framer-portal-id"] ? void 0 : getClosestProjectingNode(this.state.visualElement.parent)
|
|
16
17
|
);
|
|
18
|
+
this.state.visualElement.projection.isPresent = true;
|
|
17
19
|
this.state.visualElement.projection.setOptions({
|
|
18
20
|
layout: options.layout,
|
|
19
21
|
layoutId: options.layoutId,
|
|
@@ -24,7 +26,21 @@ class ProjectionFeature extends Feature {
|
|
|
24
26
|
// initialPromotionConfig
|
|
25
27
|
layoutRoot: options.layoutRoot,
|
|
26
28
|
layoutScroll: options.layoutScroll,
|
|
27
|
-
crossfade: options.crossfade
|
|
29
|
+
crossfade: options.crossfade,
|
|
30
|
+
onExitComplete: () => {
|
|
31
|
+
var _a;
|
|
32
|
+
if (!((_a = this.state.visualElement.projection) == null ? void 0 : _a.isPresent)) {
|
|
33
|
+
const done = doneCallbacks.get(this.state.element);
|
|
34
|
+
this.state.isSafeToRemove = true;
|
|
35
|
+
if (done) {
|
|
36
|
+
done({
|
|
37
|
+
detail: {
|
|
38
|
+
isExit: true
|
|
39
|
+
}
|
|
40
|
+
}, true);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
});
|
|
29
45
|
}
|
|
30
46
|
beforeMount() {
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { default as default2 } from "./components/Motion.vue.mjs";
|
|
2
|
-
import { default as default3 } from "./components/
|
|
3
|
-
import { default as default4 } from "./components/LayoutGroup.vue.mjs";
|
|
2
|
+
import { default as default3 } from "./components/LayoutGroup.vue.mjs";
|
|
4
3
|
import { useLayoutGroup } from "./components/use-layout-group.mjs";
|
|
5
4
|
import { injectLayoutGroup, injectMotion, provideLayoutGroup, provideMotion } from "./components/context.mjs";
|
|
6
5
|
import { components, utilities } from "./constants/index.mjs";
|
|
6
|
+
import { default as default4 } from "./components/animate-presence/AnimatePresence.vue.mjs";
|
|
7
7
|
import { default as default5 } from "./components/motion-config/MotionConfig.vue.mjs";
|
|
8
8
|
import { MotionValue, motionValue, motionValue as motionValue2 } from "./external/.pnpm/framer-motion@11.15.0/external/framer-motion/dist/es/value/index.mjs";
|
|
9
9
|
import { invariant } from "./external/.pnpm/motion-utils@11.14.3/external/motion-utils/dist/es/errors.mjs";
|
|
@@ -56,8 +56,8 @@ import { useAnimationFrame } from "./utils/use-animation-frame.mjs";
|
|
|
56
56
|
import { millisecondsToSeconds, secondsToMilliseconds } from "./utils/time-conversion.mjs";
|
|
57
57
|
import { getContextWindow } from "./utils/get-context-window.mjs";
|
|
58
58
|
export {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
default4 as AnimatePresence,
|
|
60
|
+
default3 as LayoutGroup,
|
|
61
61
|
default2 as Motion,
|
|
62
62
|
default5 as MotionConfig,
|
|
63
63
|
MotionValue,
|
|
@@ -2,7 +2,7 @@ import { style } from "./style.mjs";
|
|
|
2
2
|
import { transformResetValue } from "./transform.mjs";
|
|
3
3
|
import { resolveVariant, hasChanged, getOptions } from "./utils.mjs";
|
|
4
4
|
import { animate } from "../external/.pnpm/framer-motion@11.15.0/external/framer-motion/dist/es/animation/animate/index.mjs";
|
|
5
|
-
function animateVariantsChildren(state, activeState) {
|
|
5
|
+
function animateVariantsChildren(state, activeState, isFirstAnimate = false) {
|
|
6
6
|
const variantChildren = state.visualElement.variantChildren;
|
|
7
7
|
if (!(variantChildren == null ? void 0 : variantChildren.size)) {
|
|
8
8
|
return {
|
|
@@ -13,11 +13,13 @@ function animateVariantsChildren(state, activeState) {
|
|
|
13
13
|
const animationFactories = [];
|
|
14
14
|
Array.from(variantChildren).forEach((child, index) => {
|
|
15
15
|
var _a;
|
|
16
|
-
const prevTarget = child.state.target;
|
|
16
|
+
const prevTarget = isFirstAnimate ? child.state.baseTarget : child.state.target;
|
|
17
17
|
const childState = child.state;
|
|
18
18
|
childState.target = {};
|
|
19
19
|
for (const name in activeState) {
|
|
20
|
-
|
|
20
|
+
if (name === "initial" && !isFirstAnimate) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
21
23
|
const { definition, transition } = activeState[name];
|
|
22
24
|
const { staggerChildren = 0, staggerDirection = 1, delayChildren = 0 } = transition || {};
|
|
23
25
|
const maxStaggerDuration = (variantChildren.size - 1) * staggerChildren;
|
|
@@ -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,
|
|
@@ -51,8 +56,8 @@ class MotionState {
|
|
|
51
56
|
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
52
57
|
});
|
|
53
58
|
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
54
|
-
this.featureManager = new FeatureManager(this);
|
|
55
59
|
this.initTarget(initialVariantSource);
|
|
60
|
+
this.featureManager = new FeatureManager(this);
|
|
56
61
|
}
|
|
57
62
|
get context() {
|
|
58
63
|
if (!this._context) {
|
|
@@ -68,7 +73,7 @@ class MotionState {
|
|
|
68
73
|
}
|
|
69
74
|
initTarget(initialVariantSource) {
|
|
70
75
|
this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
|
|
71
|
-
this.target = {
|
|
76
|
+
this.target = {};
|
|
72
77
|
}
|
|
73
78
|
get initial() {
|
|
74
79
|
return isDef(this.options.initial) ? this.options.initial : this.context.initial;
|
|
@@ -87,7 +92,7 @@ class MotionState {
|
|
|
87
92
|
beforeMount() {
|
|
88
93
|
this.featureManager.beforeMount();
|
|
89
94
|
}
|
|
90
|
-
mount(element, options) {
|
|
95
|
+
mount(element, options, notAnimate = false) {
|
|
91
96
|
invariant(
|
|
92
97
|
Boolean(element),
|
|
93
98
|
"Animation state must be mounted with valid Element"
|
|
@@ -111,38 +116,57 @@ class MotionState {
|
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
this.featureManager.mount();
|
|
114
|
-
|
|
119
|
+
if (!notAnimate) {
|
|
120
|
+
this.animateUpdates(true);
|
|
121
|
+
}
|
|
115
122
|
}
|
|
116
123
|
beforeUnmount() {
|
|
117
124
|
this.featureManager.beforeUnmount();
|
|
118
125
|
}
|
|
119
|
-
unmount() {
|
|
120
|
-
var _a;
|
|
126
|
+
unmount(unMountChildren = false) {
|
|
127
|
+
var _a, _b;
|
|
121
128
|
mountedStates.delete(this.element);
|
|
122
|
-
|
|
123
|
-
(_a = visualElementStore.get(this.element)) == null ? void 0 : _a.unmount();
|
|
129
|
+
mountedStates.delete(this.id);
|
|
124
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
|
+
}
|
|
125
140
|
}
|
|
126
141
|
beforeUpdate() {
|
|
127
142
|
this.featureManager.beforeUpdate();
|
|
128
143
|
}
|
|
129
|
-
update(options) {
|
|
144
|
+
update(options, notAnimate = false) {
|
|
145
|
+
const prevAnimate = JSON.stringify(this.options.animate);
|
|
130
146
|
this.options = options;
|
|
147
|
+
let hasAnimateChange = false;
|
|
148
|
+
if (prevAnimate !== JSON.stringify(options.animate)) {
|
|
149
|
+
hasAnimateChange = true;
|
|
150
|
+
}
|
|
131
151
|
this.updateOptions();
|
|
132
152
|
this.featureManager.update();
|
|
133
|
-
|
|
153
|
+
if (hasAnimateChange && !notAnimate) {
|
|
154
|
+
scheduleAnimation(this);
|
|
155
|
+
}
|
|
134
156
|
}
|
|
135
|
-
setActive(name, isActive) {
|
|
157
|
+
setActive(name, isActive, isAnimate = true) {
|
|
136
158
|
var _a;
|
|
137
159
|
if (!this.element || this.activeStates[name] === isActive)
|
|
138
160
|
return;
|
|
139
161
|
this.activeStates[name] = isActive;
|
|
140
162
|
(_a = this.visualElement.variantChildren) == null ? void 0 : _a.forEach((child) => {
|
|
141
|
-
child.state.setActive(name, isActive);
|
|
163
|
+
child.state.setActive(name, isActive, false);
|
|
142
164
|
});
|
|
143
|
-
|
|
165
|
+
if (isAnimate) {
|
|
166
|
+
scheduleAnimation(this);
|
|
167
|
+
}
|
|
144
168
|
}
|
|
145
|
-
|
|
169
|
+
animateUpdates(isInitial = false) {
|
|
146
170
|
const prevTarget = this.target;
|
|
147
171
|
this.target = {};
|
|
148
172
|
const activeState = {};
|
|
@@ -150,13 +174,13 @@ class MotionState {
|
|
|
150
174
|
let transition;
|
|
151
175
|
for (const name of STATE_TYPES) {
|
|
152
176
|
if (name === "initial") {
|
|
153
|
-
if (!
|
|
177
|
+
if (!isInitial) {
|
|
154
178
|
continue;
|
|
155
179
|
}
|
|
156
|
-
this.isFirstAnimate = false;
|
|
157
180
|
}
|
|
158
|
-
if (!this.activeStates[name])
|
|
181
|
+
if (!this.activeStates[name] && name !== "initial") {
|
|
159
182
|
continue;
|
|
183
|
+
}
|
|
160
184
|
const definition = isDef(this.options[name]) ? this.options[name] : this.context[name];
|
|
161
185
|
const variant = resolveVariant(
|
|
162
186
|
definition,
|
|
@@ -212,11 +236,10 @@ class MotionState {
|
|
|
212
236
|
let getChildAnimations = () => Promise.resolve();
|
|
213
237
|
let childAnimations = [];
|
|
214
238
|
if (Object.keys(activeState).length) {
|
|
215
|
-
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState);
|
|
239
|
+
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState, isInitial);
|
|
216
240
|
getChildAnimations = getAnimations;
|
|
217
241
|
childAnimations = animations2;
|
|
218
242
|
}
|
|
219
|
-
yield;
|
|
220
243
|
let animations;
|
|
221
244
|
const getAnimation = () => {
|
|
222
245
|
animations = animationFactories.map((factory) => factory()).filter(Boolean);
|
|
@@ -254,6 +277,10 @@ class MotionState {
|
|
|
254
277
|
getOptions() {
|
|
255
278
|
return this.options;
|
|
256
279
|
}
|
|
280
|
+
willUpdate(label) {
|
|
281
|
+
var _a;
|
|
282
|
+
(_a = this.visualElement.projection) == null ? void 0 : _a.willUpdate();
|
|
283
|
+
}
|
|
257
284
|
}
|
|
258
285
|
export {
|
|
259
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
|