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
package/dist/cjs/index.js
CHANGED
|
@@ -5193,7 +5193,11 @@ class HoverGesture extends BaseGesture {
|
|
|
5193
5193
|
this.state.setActive("hover", true);
|
|
5194
5194
|
});
|
|
5195
5195
|
const onLeave = mouseEvent(element, "hoverend", () => {
|
|
5196
|
+
var _a;
|
|
5196
5197
|
this.state.setActive("hover", false);
|
|
5198
|
+
(_a = this.state.visualElement.variantChildren) == null ? void 0 : _a.forEach((child) => {
|
|
5199
|
+
child.state.setActive("hover", false);
|
|
5200
|
+
});
|
|
5197
5201
|
});
|
|
5198
5202
|
element.addEventListener("pointerenter", onEnter);
|
|
5199
5203
|
element.addEventListener("pointerleave", onLeave);
|
|
@@ -5253,7 +5257,11 @@ class InViewGesture extends BaseGesture {
|
|
|
5253
5257
|
const element = this.state.element;
|
|
5254
5258
|
const { once, ...viewOptions } = ((_a = this.state.getOptions()) == null ? void 0 : _a.inViewOptions) || {};
|
|
5255
5259
|
return inView(element, (enterEntry) => {
|
|
5260
|
+
var _a2;
|
|
5256
5261
|
this.state.setActive("inView", true);
|
|
5262
|
+
(_a2 = this.state.visualElement.variantChildren) == null ? void 0 : _a2.forEach((child) => {
|
|
5263
|
+
child.state.setActive("inView", true);
|
|
5264
|
+
});
|
|
5257
5265
|
dispatchPointerEvent(element, "viewenter", enterEntry);
|
|
5258
5266
|
if (!once) {
|
|
5259
5267
|
return (leaveEntry) => {
|
|
@@ -5635,7 +5643,7 @@ const isDebug = typeof window !== "undefined" && window.MotionDebug !== void 0;
|
|
|
5635
5643
|
const transformAxes = ["", "X", "Y", "Z"];
|
|
5636
5644
|
const hiddenVisibility = { visibility: "hidden" };
|
|
5637
5645
|
const animationTarget = 1e3;
|
|
5638
|
-
let id = 0;
|
|
5646
|
+
let id$1 = 0;
|
|
5639
5647
|
function resetDistortingTransform(key, visualElement, values, sharedAnimationValues) {
|
|
5640
5648
|
const { latestValues } = visualElement;
|
|
5641
5649
|
if (latestValues[key]) {
|
|
@@ -5666,7 +5674,7 @@ function cancelTreeOptimisedTransformAnimations(projectionNode) {
|
|
|
5666
5674
|
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform }) {
|
|
5667
5675
|
return class ProjectionNode {
|
|
5668
5676
|
constructor(latestValues = {}, parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent()) {
|
|
5669
|
-
this.id = id++;
|
|
5677
|
+
this.id = id$1++;
|
|
5670
5678
|
this.animationId = 0;
|
|
5671
5679
|
this.children = /* @__PURE__ */ new Set();
|
|
5672
5680
|
this.options = {};
|
|
@@ -6806,11 +6814,8 @@ class LayoutFeature extends Feature {
|
|
|
6806
6814
|
(_a = visualElement.projection) == null ? void 0 : _a.root.didUpdate();
|
|
6807
6815
|
});
|
|
6808
6816
|
vue.onBeforeUnmount(() => {
|
|
6809
|
-
var _a;
|
|
6810
6817
|
if (visualElement.projection) {
|
|
6811
|
-
visualElement.projection.
|
|
6812
|
-
if ((_a = this.layoutGroup) == null ? void 0 : _a.group)
|
|
6813
|
-
this.layoutGroup.group.remove(visualElement.projection);
|
|
6818
|
+
visualElement.projection.willUpdate();
|
|
6814
6819
|
}
|
|
6815
6820
|
});
|
|
6816
6821
|
}
|
|
@@ -6833,6 +6838,12 @@ class LayoutFeature extends Feature {
|
|
|
6833
6838
|
}
|
|
6834
6839
|
}
|
|
6835
6840
|
unmount() {
|
|
6841
|
+
var _a;
|
|
6842
|
+
if (this.state.visualElement.projection) {
|
|
6843
|
+
this.state.visualElement.projection.unmount();
|
|
6844
|
+
if ((_a = this.layoutGroup) == null ? void 0 : _a.group)
|
|
6845
|
+
this.layoutGroup.group.remove(this.state.visualElement.projection);
|
|
6846
|
+
}
|
|
6836
6847
|
}
|
|
6837
6848
|
}
|
|
6838
6849
|
class FeatureManager {
|
|
@@ -6880,7 +6891,7 @@ function unscheduleAnimation(state2) {
|
|
|
6880
6891
|
scheduled && removeItem(scheduled, state2);
|
|
6881
6892
|
}
|
|
6882
6893
|
function compareByDepth(a, b) {
|
|
6883
|
-
return a.
|
|
6894
|
+
return a.depth - b.depth;
|
|
6884
6895
|
}
|
|
6885
6896
|
function motionEvent(name, target, isExit) {
|
|
6886
6897
|
return new CustomEvent(name, { detail: { target, isExit } });
|
|
@@ -6888,8 +6899,74 @@ function motionEvent(name, target, isExit) {
|
|
|
6888
6899
|
function createVisualElement(Component, options) {
|
|
6889
6900
|
return isSVGElement$1(Component) ? new SVGVisualElement(options) : new HTMLVisualElement(options);
|
|
6890
6901
|
}
|
|
6902
|
+
function animateVariantsChildren(state2, activeState) {
|
|
6903
|
+
const variantChildren = state2.visualElement.variantChildren;
|
|
6904
|
+
if (!(variantChildren == null ? void 0 : variantChildren.size)) {
|
|
6905
|
+
return {
|
|
6906
|
+
animations: [],
|
|
6907
|
+
getAnimations: () => Promise.resolve()
|
|
6908
|
+
};
|
|
6909
|
+
}
|
|
6910
|
+
const animationFactories = [];
|
|
6911
|
+
Array.from(variantChildren).forEach((child, index) => {
|
|
6912
|
+
var _a;
|
|
6913
|
+
const prevTarget = child.state.target;
|
|
6914
|
+
const childState = child.state;
|
|
6915
|
+
childState.target = {};
|
|
6916
|
+
for (const name in activeState) {
|
|
6917
|
+
childState.activeStates[name] = true;
|
|
6918
|
+
const { definition, transition } = activeState[name];
|
|
6919
|
+
const { staggerChildren = 0, staggerDirection = 1, delayChildren = 0 } = transition;
|
|
6920
|
+
const maxStaggerDuration = (variantChildren.size - 1) * staggerChildren;
|
|
6921
|
+
const generateStaggerDuration = staggerDirection === 1 ? (i = 0) => i * staggerChildren : (i = 0) => maxStaggerDuration - i * staggerChildren;
|
|
6922
|
+
const variant = resolveVariant(
|
|
6923
|
+
definition,
|
|
6924
|
+
child.props.variants,
|
|
6925
|
+
child.props.custom
|
|
6926
|
+
);
|
|
6927
|
+
const animationOptions = {};
|
|
6928
|
+
const allTarget = { ...prevTarget, ...variant };
|
|
6929
|
+
for (const key in allTarget) {
|
|
6930
|
+
if (key === "transition")
|
|
6931
|
+
continue;
|
|
6932
|
+
childState.target[key] = allTarget[key];
|
|
6933
|
+
if (childState.target[key] === void 0) {
|
|
6934
|
+
childState.target[key] = childState.baseTarget[key];
|
|
6935
|
+
}
|
|
6936
|
+
if (hasChanged(prevTarget[key], childState.target[key])) {
|
|
6937
|
+
(_a = childState.baseTarget)[key] ?? (_a[key] = style.get(child.current, key));
|
|
6938
|
+
animationOptions[key] = getOptions(
|
|
6939
|
+
Object.assign({}, transition, allTarget.transition, child.props.transition),
|
|
6940
|
+
key
|
|
6941
|
+
);
|
|
6942
|
+
const keyValue = childState.target[key] === "none" ? transformResetValue[key] : childState.target[key];
|
|
6943
|
+
animationFactories.push(
|
|
6944
|
+
() => {
|
|
6945
|
+
var _a2;
|
|
6946
|
+
return animate(
|
|
6947
|
+
child.current,
|
|
6948
|
+
{
|
|
6949
|
+
[key]: keyValue
|
|
6950
|
+
},
|
|
6951
|
+
{
|
|
6952
|
+
...animationOptions[key] || {},
|
|
6953
|
+
delay: (((_a2 = animationOptions[key]) == null ? void 0 : _a2.delay) || 0) + delayChildren + generateStaggerDuration(index)
|
|
6954
|
+
}
|
|
6955
|
+
);
|
|
6956
|
+
}
|
|
6957
|
+
);
|
|
6958
|
+
}
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
});
|
|
6962
|
+
return {
|
|
6963
|
+
animations: animationFactories,
|
|
6964
|
+
getAnimations: () => Promise.all(animationFactories.map((factory) => factory()))
|
|
6965
|
+
};
|
|
6966
|
+
}
|
|
6891
6967
|
const STATE_TYPES = ["initial", "animate", "inView", "hover", "press", "exit", "drag"];
|
|
6892
6968
|
const mountedStates = /* @__PURE__ */ new WeakMap();
|
|
6969
|
+
let id = 0;
|
|
6893
6970
|
class MotionState {
|
|
6894
6971
|
constructor(options, parent) {
|
|
6895
6972
|
this.element = null;
|
|
@@ -6898,6 +6975,7 @@ class MotionState {
|
|
|
6898
6975
|
animate: true
|
|
6899
6976
|
};
|
|
6900
6977
|
this._context = null;
|
|
6978
|
+
this.id = `motion-state-${id++}`;
|
|
6901
6979
|
this.options = options;
|
|
6902
6980
|
this.parent = parent;
|
|
6903
6981
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
@@ -6905,7 +6983,10 @@ class MotionState {
|
|
|
6905
6983
|
presenceContext: null,
|
|
6906
6984
|
parent: parent == null ? void 0 : parent.visualElement,
|
|
6907
6985
|
props: {
|
|
6908
|
-
...this.options
|
|
6986
|
+
...this.options,
|
|
6987
|
+
whileHover: this.options.hover,
|
|
6988
|
+
whileTap: this.options.press,
|
|
6989
|
+
whileInView: this.options.inView
|
|
6909
6990
|
},
|
|
6910
6991
|
visualState: {
|
|
6911
6992
|
renderState: {
|
|
@@ -6941,19 +7022,29 @@ class MotionState {
|
|
|
6941
7022
|
get initial() {
|
|
6942
7023
|
return isDef(this.options.initial) ? this.options.initial : this.context.initial;
|
|
6943
7024
|
}
|
|
6944
|
-
|
|
7025
|
+
updateOptions() {
|
|
6945
7026
|
var _a;
|
|
7027
|
+
this.visualElement.update({
|
|
7028
|
+
...this.options,
|
|
7029
|
+
whileHover: this.options.hover,
|
|
7030
|
+
whileTap: this.options.press,
|
|
7031
|
+
whileInView: this.options.inView
|
|
7032
|
+
}, (_a = this.parent) == null ? void 0 : _a.context);
|
|
7033
|
+
}
|
|
7034
|
+
mount(element, options) {
|
|
6946
7035
|
invariant(
|
|
6947
7036
|
Boolean(element),
|
|
6948
7037
|
"Animation state must be mounted with valid Element"
|
|
6949
7038
|
);
|
|
6950
7039
|
this.element = element;
|
|
7040
|
+
this.options = options;
|
|
6951
7041
|
mountedStates.set(element, this);
|
|
6952
7042
|
if (!visualElementStore.get(element)) {
|
|
6953
7043
|
this.visualElement.mount(element);
|
|
6954
7044
|
visualElementStore.set(element, this.visualElement);
|
|
6955
7045
|
}
|
|
6956
|
-
this.visualElement.
|
|
7046
|
+
this.visualElement.state = this;
|
|
7047
|
+
this.updateOptions();
|
|
6957
7048
|
if (typeof this.initial === "object") {
|
|
6958
7049
|
for (const key in this.initial) {
|
|
6959
7050
|
this.visualElement.setStaticValue(key, this.initial[key]);
|
|
@@ -6964,6 +7055,7 @@ class MotionState {
|
|
|
6964
7055
|
}
|
|
6965
7056
|
}
|
|
6966
7057
|
this.featureManager.mount();
|
|
7058
|
+
scheduleAnimation(this);
|
|
6967
7059
|
}
|
|
6968
7060
|
unmount() {
|
|
6969
7061
|
var _a;
|
|
@@ -6973,14 +7065,13 @@ class MotionState {
|
|
|
6973
7065
|
this.featureManager.unmount();
|
|
6974
7066
|
}
|
|
6975
7067
|
update(options) {
|
|
6976
|
-
var _a;
|
|
6977
7068
|
this.options = options;
|
|
6978
|
-
this.
|
|
7069
|
+
this.updateOptions();
|
|
6979
7070
|
this.featureManager.update();
|
|
6980
7071
|
scheduleAnimation(this);
|
|
6981
7072
|
}
|
|
6982
7073
|
setActive(name, isActive) {
|
|
6983
|
-
if (!this.element)
|
|
7074
|
+
if (!this.element || this.activeStates[name] === isActive)
|
|
6984
7075
|
return;
|
|
6985
7076
|
this.activeStates[name] = isActive;
|
|
6986
7077
|
scheduleAnimation(this);
|
|
@@ -6988,15 +7079,25 @@ class MotionState {
|
|
|
6988
7079
|
*animateUpdates() {
|
|
6989
7080
|
const prevTarget = this.target;
|
|
6990
7081
|
this.target = {};
|
|
7082
|
+
const activeState = {};
|
|
6991
7083
|
const animationOptions = {};
|
|
7084
|
+
let transition;
|
|
6992
7085
|
for (const name of STATE_TYPES) {
|
|
6993
7086
|
if (!this.activeStates[name])
|
|
6994
7087
|
continue;
|
|
7088
|
+
const definition = isDef(this.options[name]) ? this.options[name] : this.context[name];
|
|
6995
7089
|
const variant = resolveVariant(
|
|
6996
|
-
|
|
7090
|
+
definition,
|
|
6997
7091
|
this.options.variants,
|
|
6998
7092
|
this.options.custom
|
|
6999
7093
|
);
|
|
7094
|
+
transition = Object.assign({}, this.options.transition, variant == null ? void 0 : variant.transition);
|
|
7095
|
+
if (typeof definition === "string") {
|
|
7096
|
+
activeState[name] = {
|
|
7097
|
+
definition,
|
|
7098
|
+
transition
|
|
7099
|
+
};
|
|
7100
|
+
}
|
|
7000
7101
|
if (!variant)
|
|
7001
7102
|
continue;
|
|
7002
7103
|
const allTarget = { ...prevTarget, ...variant };
|
|
@@ -7005,7 +7106,7 @@ class MotionState {
|
|
|
7005
7106
|
continue;
|
|
7006
7107
|
this.target[key] = variant[key];
|
|
7007
7108
|
animationOptions[key] = getOptions(
|
|
7008
|
-
|
|
7109
|
+
transition,
|
|
7009
7110
|
key
|
|
7010
7111
|
);
|
|
7011
7112
|
}
|
|
@@ -7022,12 +7123,13 @@ class MotionState {
|
|
|
7022
7123
|
}
|
|
7023
7124
|
if (hasChanged(prevTarget[key], this.target[key])) {
|
|
7024
7125
|
(_a = this.baseTarget)[key] ?? (_a[key] = style.get(this.element, key));
|
|
7126
|
+
const keyValue = this.target[key] === "none" ? transformResetValue[key] : this.target[key];
|
|
7025
7127
|
animationFactories.push(
|
|
7026
7128
|
() => {
|
|
7027
7129
|
return animate(
|
|
7028
7130
|
this.element,
|
|
7029
7131
|
{
|
|
7030
|
-
[key]:
|
|
7132
|
+
[key]: keyValue
|
|
7031
7133
|
},
|
|
7032
7134
|
animationOptions[key] || {}
|
|
7033
7135
|
);
|
|
@@ -7035,14 +7137,40 @@ class MotionState {
|
|
|
7035
7137
|
);
|
|
7036
7138
|
}
|
|
7037
7139
|
});
|
|
7140
|
+
let getChildAnimations = () => Promise.resolve();
|
|
7141
|
+
let childAnimations = [];
|
|
7142
|
+
if (Object.keys(activeState).length) {
|
|
7143
|
+
const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState);
|
|
7144
|
+
getChildAnimations = getAnimations;
|
|
7145
|
+
childAnimations = animations2;
|
|
7146
|
+
}
|
|
7038
7147
|
yield;
|
|
7039
|
-
|
|
7040
|
-
|
|
7148
|
+
let animations;
|
|
7149
|
+
const getAnimation = () => {
|
|
7150
|
+
animations = animationFactories.map((factory) => factory()).filter(Boolean);
|
|
7151
|
+
return Promise.all(animations);
|
|
7152
|
+
};
|
|
7153
|
+
const { when } = transition;
|
|
7154
|
+
let animationPromise;
|
|
7155
|
+
if (when) {
|
|
7156
|
+
const [first, last] = when === "beforeChildren" ? [getAnimation, getChildAnimations] : [getChildAnimations, getAnimation];
|
|
7157
|
+
animationPromise = first().then(() => last());
|
|
7158
|
+
} else {
|
|
7159
|
+
animationPromise = Promise.all([getAnimation(), getChildAnimations()]);
|
|
7160
|
+
}
|
|
7161
|
+
const isExit = this.activeStates.exit;
|
|
7162
|
+
if (!(animations == null ? void 0 : animations.length) && !childAnimations.length) {
|
|
7163
|
+
if (isExit) {
|
|
7164
|
+
this.element.dispatchEvent(motionEvent("motionstart", this.target));
|
|
7165
|
+
this.element.dispatchEvent(motionEvent("motioncomplete", {
|
|
7166
|
+
...this.target
|
|
7167
|
+
}, isExit));
|
|
7168
|
+
}
|
|
7041
7169
|
return;
|
|
7170
|
+
}
|
|
7042
7171
|
const animationTarget2 = this.target;
|
|
7043
7172
|
this.element.dispatchEvent(motionEvent("motionstart", animationTarget2));
|
|
7044
|
-
|
|
7045
|
-
Promise.all(animations).then(() => {
|
|
7173
|
+
animationPromise.then(() => {
|
|
7046
7174
|
this.element.dispatchEvent(motionEvent("motioncomplete", {
|
|
7047
7175
|
...animationTarget2
|
|
7048
7176
|
}, isExit));
|
|
@@ -7051,17 +7179,12 @@ class MotionState {
|
|
|
7051
7179
|
isMounted() {
|
|
7052
7180
|
return Boolean(this.element);
|
|
7053
7181
|
}
|
|
7054
|
-
getDepth() {
|
|
7055
|
-
return this.depth;
|
|
7056
|
-
}
|
|
7057
7182
|
getOptions() {
|
|
7058
7183
|
return this.options;
|
|
7059
7184
|
}
|
|
7060
|
-
getTarget() {
|
|
7061
|
-
return this.target;
|
|
7062
|
-
}
|
|
7063
7185
|
}
|
|
7064
|
-
const doneCallbacks = /* @__PURE__ */ new
|
|
7186
|
+
const doneCallbacks = /* @__PURE__ */ new WeakMap();
|
|
7187
|
+
const unPresenceDom = vue.ref(/* @__PURE__ */ new WeakMap());
|
|
7065
7188
|
function removeDoneCallback(element) {
|
|
7066
7189
|
const prevDoneCallback = doneCallbacks.get(element);
|
|
7067
7190
|
if (prevDoneCallback) {
|
|
@@ -7070,6 +7193,11 @@ function removeDoneCallback(element) {
|
|
|
7070
7193
|
doneCallbacks.delete(element);
|
|
7071
7194
|
}
|
|
7072
7195
|
const [injectAnimatePresence, provideAnimatePresence] = createContext("AnimatePresenceContext");
|
|
7196
|
+
function getMotionElement(el) {
|
|
7197
|
+
if ((el == null ? void 0 : el.nodeType) === 3 || (el == null ? void 0 : el.nodeType) === 8)
|
|
7198
|
+
return getMotionElement(el.nextSibling);
|
|
7199
|
+
return el;
|
|
7200
|
+
}
|
|
7073
7201
|
const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
7074
7202
|
...{
|
|
7075
7203
|
name: "Motion",
|
|
@@ -7099,7 +7227,7 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7099
7227
|
onPressEnd: { type: Function },
|
|
7100
7228
|
onViewEnter: { type: Function },
|
|
7101
7229
|
onViewLeave: { type: Function },
|
|
7102
|
-
layout: { type: Boolean },
|
|
7230
|
+
layout: { type: [Boolean, String] },
|
|
7103
7231
|
layoutId: {},
|
|
7104
7232
|
layoutScroll: { type: Boolean },
|
|
7105
7233
|
layoutRoot: { type: Boolean },
|
|
@@ -7130,16 +7258,16 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7130
7258
|
parentState
|
|
7131
7259
|
);
|
|
7132
7260
|
provideMotion(state2);
|
|
7133
|
-
const instance = vue.getCurrentInstance();
|
|
7261
|
+
const instance = vue.getCurrentInstance().proxy;
|
|
7134
7262
|
vue.onMounted(() => {
|
|
7135
|
-
state2.mount(instance
|
|
7136
|
-
state2.update({
|
|
7263
|
+
state2.mount(getMotionElement(instance.$el), {
|
|
7137
7264
|
...attrs,
|
|
7138
|
-
...props
|
|
7265
|
+
...props,
|
|
7266
|
+
initial: presenceInitial.value === false ? presenceInitial.value : props.initial === true ? void 0 : props.initial
|
|
7139
7267
|
});
|
|
7140
7268
|
});
|
|
7141
7269
|
vue.onUnmounted(() => {
|
|
7142
|
-
if (safeUnmount(instance
|
|
7270
|
+
if (safeUnmount(getMotionElement(instance.$el)))
|
|
7143
7271
|
state2.unmount();
|
|
7144
7272
|
});
|
|
7145
7273
|
vue.onUpdated(() => {
|
|
@@ -7150,22 +7278,23 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7150
7278
|
});
|
|
7151
7279
|
});
|
|
7152
7280
|
function getProps() {
|
|
7281
|
+
const isSVG = state2.visualElement.type === "svg";
|
|
7153
7282
|
const attrsProps = { ...attrs };
|
|
7154
7283
|
Object.keys(attrs).forEach((key) => {
|
|
7155
7284
|
if (isMotionValue(attrs[key]))
|
|
7156
7285
|
attrsProps[key] = attrs[key].get();
|
|
7157
7286
|
});
|
|
7158
7287
|
let styleProps = {
|
|
7159
|
-
...props.style
|
|
7288
|
+
...props.style,
|
|
7289
|
+
...isSVG ? {} : state2.visualElement.latestValues
|
|
7160
7290
|
};
|
|
7291
|
+
if (isSVG) {
|
|
7292
|
+
const { attributes, style: style2 } = convertSvgStyleToAttributes(state2.target);
|
|
7293
|
+
Object.assign(attrsProps, attributes);
|
|
7294
|
+
Object.assign(styleProps, style2, props.style);
|
|
7295
|
+
}
|
|
7161
7296
|
if (!state2.isMounted()) {
|
|
7162
|
-
|
|
7163
|
-
const { attributes, style: style2 } = convertSvgStyleToAttributes(state2.getTarget());
|
|
7164
|
-
Object.assign(attrsProps, attributes);
|
|
7165
|
-
Object.assign(styleProps, style2, props.style);
|
|
7166
|
-
} else {
|
|
7167
|
-
Object.assign(styleProps, state2.getTarget(), props.style);
|
|
7168
|
-
}
|
|
7297
|
+
Object.assign(styleProps, state2.target, props.style);
|
|
7169
7298
|
}
|
|
7170
7299
|
styleProps = createStyles(styleProps);
|
|
7171
7300
|
attrsProps.style = styleProps;
|
|
@@ -7187,6 +7316,111 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7187
7316
|
};
|
|
7188
7317
|
}
|
|
7189
7318
|
});
|
|
7319
|
+
function useForceUpdate() {
|
|
7320
|
+
const key = vue.ref(0);
|
|
7321
|
+
function forceUpdate() {
|
|
7322
|
+
key.value++;
|
|
7323
|
+
}
|
|
7324
|
+
return [forceUpdate, key];
|
|
7325
|
+
}
|
|
7326
|
+
function notify(node) {
|
|
7327
|
+
return !node.isLayoutDirty && node.willUpdate(false);
|
|
7328
|
+
}
|
|
7329
|
+
function nodeGroup() {
|
|
7330
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
7331
|
+
const subscriptions = /* @__PURE__ */ new WeakMap();
|
|
7332
|
+
const dirtyAll = () => nodes.forEach(notify);
|
|
7333
|
+
return {
|
|
7334
|
+
add: (node) => {
|
|
7335
|
+
nodes.add(node);
|
|
7336
|
+
subscriptions.set(
|
|
7337
|
+
node,
|
|
7338
|
+
node.addEventListener("willUpdate", dirtyAll)
|
|
7339
|
+
);
|
|
7340
|
+
},
|
|
7341
|
+
remove: (node) => {
|
|
7342
|
+
nodes.delete(node);
|
|
7343
|
+
const unsubscribe = subscriptions.get(node);
|
|
7344
|
+
if (unsubscribe) {
|
|
7345
|
+
unsubscribe();
|
|
7346
|
+
subscriptions.delete(node);
|
|
7347
|
+
}
|
|
7348
|
+
dirtyAll();
|
|
7349
|
+
},
|
|
7350
|
+
dirty: dirtyAll
|
|
7351
|
+
};
|
|
7352
|
+
}
|
|
7353
|
+
function useLayoutGroup(props) {
|
|
7354
|
+
const parentGroup = injectLayoutGroup(null);
|
|
7355
|
+
const [forceRender, key] = useForceUpdate();
|
|
7356
|
+
const context = {
|
|
7357
|
+
id: getGroupId(props, parentGroup),
|
|
7358
|
+
group: getGroup(props, parentGroup),
|
|
7359
|
+
forceRender,
|
|
7360
|
+
key
|
|
7361
|
+
};
|
|
7362
|
+
vue.watch(key, () => {
|
|
7363
|
+
context.id = getGroupId(props, parentGroup);
|
|
7364
|
+
});
|
|
7365
|
+
provideLayoutGroup(context);
|
|
7366
|
+
return context;
|
|
7367
|
+
}
|
|
7368
|
+
function getGroupId(props, parentGroup) {
|
|
7369
|
+
const shouldInherit = props.inherit === true || props.inherit === "id";
|
|
7370
|
+
const parentId = parentGroup == null ? void 0 : parentGroup.id;
|
|
7371
|
+
if (shouldInherit && parentId) {
|
|
7372
|
+
return props.id ? `${parentId}-${props.id}` : parentId;
|
|
7373
|
+
}
|
|
7374
|
+
return props.id;
|
|
7375
|
+
}
|
|
7376
|
+
function getGroup(props, parentGroup) {
|
|
7377
|
+
const shouldInherit = props.inherit === true || props.inherit === "group";
|
|
7378
|
+
return shouldInherit ? (parentGroup == null ? void 0 : parentGroup.group) || nodeGroup() : nodeGroup();
|
|
7379
|
+
}
|
|
7380
|
+
function usePopLayout(props) {
|
|
7381
|
+
const styles = /* @__PURE__ */ new WeakMap();
|
|
7382
|
+
function addPopStyle(state2) {
|
|
7383
|
+
if (props.mode !== "popLayout")
|
|
7384
|
+
return;
|
|
7385
|
+
const size = {
|
|
7386
|
+
height: state2.element.offsetHeight || 0,
|
|
7387
|
+
width: state2.element.offsetWidth || 0,
|
|
7388
|
+
top: state2.element.offsetTop,
|
|
7389
|
+
left: state2.element.offsetLeft
|
|
7390
|
+
};
|
|
7391
|
+
state2.element.dataset.motionPopId = state2.id;
|
|
7392
|
+
const style2 = document.createElement("style");
|
|
7393
|
+
styles.set(state2, style2);
|
|
7394
|
+
document.head.appendChild(style2);
|
|
7395
|
+
style2.textContent = `
|
|
7396
|
+
[data-motion-pop-id="${state2.id}"] {
|
|
7397
|
+
animation: pop 0.3s ease-in-out;
|
|
7398
|
+
}
|
|
7399
|
+
`;
|
|
7400
|
+
if (style2.sheet) {
|
|
7401
|
+
style2.sheet.insertRule(`
|
|
7402
|
+
[data-motion-pop-id="${state2.id}"] {
|
|
7403
|
+
position: absolute !important;
|
|
7404
|
+
width: ${size.width}px !important;
|
|
7405
|
+
height: ${size.height}px !important;
|
|
7406
|
+
top: ${size.top}px !important;
|
|
7407
|
+
left: ${size.left}px !important;
|
|
7408
|
+
}
|
|
7409
|
+
`);
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
function removePopStyle(state2) {
|
|
7413
|
+
const style2 = styles.get(state2);
|
|
7414
|
+
if (style2) {
|
|
7415
|
+
styles.delete(state2);
|
|
7416
|
+
document.head.removeChild(style2);
|
|
7417
|
+
}
|
|
7418
|
+
}
|
|
7419
|
+
return {
|
|
7420
|
+
addPopStyle,
|
|
7421
|
+
removePopStyle
|
|
7422
|
+
};
|
|
7423
|
+
}
|
|
7190
7424
|
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
|
|
7191
7425
|
...{
|
|
7192
7426
|
name: "AnimatePresence",
|
|
@@ -7215,17 +7449,26 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7215
7449
|
}
|
|
7216
7450
|
removeDoneCallback(el);
|
|
7217
7451
|
state2.setActive("exit", false);
|
|
7452
|
+
unPresenceDom.value.delete(el);
|
|
7218
7453
|
}
|
|
7454
|
+
const layoutGroup = useLayoutGroup(props);
|
|
7455
|
+
const { addPopStyle, removePopStyle } = usePopLayout(props);
|
|
7219
7456
|
function exit(el, done) {
|
|
7457
|
+
unPresenceDom.value.set(el, true);
|
|
7220
7458
|
const state2 = mountedStates.get(el);
|
|
7221
7459
|
if (!state2) {
|
|
7222
7460
|
return done();
|
|
7223
7461
|
}
|
|
7224
7462
|
removeDoneCallback(el);
|
|
7463
|
+
addPopStyle(state2);
|
|
7225
7464
|
function doneCallback(e) {
|
|
7226
|
-
var _a;
|
|
7465
|
+
var _a, _b, _c;
|
|
7466
|
+
removePopStyle(state2);
|
|
7227
7467
|
if ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.isExit) {
|
|
7228
7468
|
removeDoneCallback(el);
|
|
7469
|
+
unPresenceDom.value.delete(el);
|
|
7470
|
+
(_b = state2.visualElement.projection) == null ? void 0 : _b.willUpdate();
|
|
7471
|
+
(_c = layoutGroup.forceRender) == null ? void 0 : _c.call(layoutGroup);
|
|
7229
7472
|
done();
|
|
7230
7473
|
if (!el.isConnected) {
|
|
7231
7474
|
state2.unmount();
|
|
@@ -7252,40 +7495,6 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
|
|
|
7252
7495
|
};
|
|
7253
7496
|
}
|
|
7254
7497
|
});
|
|
7255
|
-
function notify(node) {
|
|
7256
|
-
return !node.isLayoutDirty && node.willUpdate(false);
|
|
7257
|
-
}
|
|
7258
|
-
function nodeGroup() {
|
|
7259
|
-
const nodes = /* @__PURE__ */ new Set();
|
|
7260
|
-
const subscriptions = /* @__PURE__ */ new WeakMap();
|
|
7261
|
-
const dirtyAll = () => nodes.forEach(notify);
|
|
7262
|
-
return {
|
|
7263
|
-
add: (node) => {
|
|
7264
|
-
nodes.add(node);
|
|
7265
|
-
subscriptions.set(
|
|
7266
|
-
node,
|
|
7267
|
-
node.addEventListener("willUpdate", dirtyAll)
|
|
7268
|
-
);
|
|
7269
|
-
},
|
|
7270
|
-
remove: (node) => {
|
|
7271
|
-
nodes.delete(node);
|
|
7272
|
-
const unsubscribe = subscriptions.get(node);
|
|
7273
|
-
if (unsubscribe) {
|
|
7274
|
-
unsubscribe();
|
|
7275
|
-
subscriptions.delete(node);
|
|
7276
|
-
}
|
|
7277
|
-
dirtyAll();
|
|
7278
|
-
},
|
|
7279
|
-
dirty: dirtyAll
|
|
7280
|
-
};
|
|
7281
|
-
}
|
|
7282
|
-
function useForceUpdate() {
|
|
7283
|
-
const key = vue.ref(0);
|
|
7284
|
-
function forceUpdate() {
|
|
7285
|
-
key.value++;
|
|
7286
|
-
}
|
|
7287
|
-
return [forceUpdate, key];
|
|
7288
|
-
}
|
|
7289
7498
|
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
7290
7499
|
__name: "LayoutGroup",
|
|
7291
7500
|
props: {
|
|
@@ -7294,25 +7503,7 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
7294
7503
|
},
|
|
7295
7504
|
setup(__props) {
|
|
7296
7505
|
const props = __props;
|
|
7297
|
-
|
|
7298
|
-
const [forceRender, key] = useForceUpdate();
|
|
7299
|
-
function generateId() {
|
|
7300
|
-
const upstreamId = layoutGroup == null ? void 0 : layoutGroup.id;
|
|
7301
|
-
return shouldInheritId(props.inherit) && upstreamId ? props.id ? `${upstreamId}-${props.id}` : upstreamId : props.id;
|
|
7302
|
-
}
|
|
7303
|
-
function generateGroup() {
|
|
7304
|
-
return shouldInheritGroup(props.inherit) ? (layoutGroup == null ? void 0 : layoutGroup.group) || nodeGroup() : nodeGroup();
|
|
7305
|
-
}
|
|
7306
|
-
const memoizedContext = {
|
|
7307
|
-
id: generateId(),
|
|
7308
|
-
group: generateGroup(),
|
|
7309
|
-
forceRender,
|
|
7310
|
-
key
|
|
7311
|
-
};
|
|
7312
|
-
vue.watch(key, () => {
|
|
7313
|
-
memoizedContext.id = generateId();
|
|
7314
|
-
});
|
|
7315
|
-
provideLayoutGroup(memoizedContext);
|
|
7506
|
+
useLayoutGroup(props);
|
|
7316
7507
|
return (_ctx, _cache) => {
|
|
7317
7508
|
return vue.renderSlot(_ctx.$slots, "default");
|
|
7318
7509
|
};
|
|
@@ -7522,7 +7713,7 @@ function useVelocity(value) {
|
|
|
7522
7713
|
const components = {
|
|
7523
7714
|
motion: [
|
|
7524
7715
|
"Motion",
|
|
7525
|
-
"
|
|
7716
|
+
"AnimatePresence",
|
|
7526
7717
|
"LayoutGroup"
|
|
7527
7718
|
]
|
|
7528
7719
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { defineComponent, toRefs, openBlock, createBlock, resolveDynamicComponent, TransitionGroup, Transition, withCtx, renderSlot } from "vue";
|
|
2
2
|
import { mountedStates } from "../state/motion-state.mjs";
|
|
3
|
-
import { provideAnimatePresence, doneCallbacks, removeDoneCallback } from "./presence.mjs";
|
|
3
|
+
import { provideAnimatePresence, doneCallbacks, removeDoneCallback, unPresenceDom } from "./presence.mjs";
|
|
4
|
+
import { useLayoutGroup } from "./use-layout-group.mjs";
|
|
5
|
+
import { usePopLayout } from "./use-pop-layout.mjs";
|
|
4
6
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
7
|
...{
|
|
6
8
|
name: "AnimatePresence",
|
|
@@ -29,17 +31,26 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
29
31
|
}
|
|
30
32
|
removeDoneCallback(el);
|
|
31
33
|
state.setActive("exit", false);
|
|
34
|
+
unPresenceDom.value.delete(el);
|
|
32
35
|
}
|
|
36
|
+
const layoutGroup = useLayoutGroup(props);
|
|
37
|
+
const { addPopStyle, removePopStyle } = usePopLayout(props);
|
|
33
38
|
function exit(el, done) {
|
|
39
|
+
unPresenceDom.value.set(el, true);
|
|
34
40
|
const state = mountedStates.get(el);
|
|
35
41
|
if (!state) {
|
|
36
42
|
return done();
|
|
37
43
|
}
|
|
38
44
|
removeDoneCallback(el);
|
|
45
|
+
addPopStyle(state);
|
|
39
46
|
function doneCallback(e) {
|
|
40
|
-
var _a;
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
removePopStyle(state);
|
|
41
49
|
if ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.isExit) {
|
|
42
50
|
removeDoneCallback(el);
|
|
51
|
+
unPresenceDom.value.delete(el);
|
|
52
|
+
(_b = state.visualElement.projection) == null ? void 0 : _b.willUpdate();
|
|
53
|
+
(_c = layoutGroup.forceRender) == null ? void 0 : _c.call(layoutGroup);
|
|
43
54
|
done();
|
|
44
55
|
if (!el.isConnected) {
|
|
45
56
|
state.unmount();
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { defineComponent,
|
|
2
|
-
import {
|
|
3
|
-
import { nodeGroup } from "./group.mjs";
|
|
4
|
-
import { useForceUpdate } from "./use-force-update.mjs";
|
|
1
|
+
import { defineComponent, renderSlot } from "vue";
|
|
2
|
+
import { useLayoutGroup } from "./use-layout-group.mjs";
|
|
5
3
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
4
|
__name: "LayoutGroup",
|
|
7
5
|
props: {
|
|
@@ -10,25 +8,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
10
8
|
},
|
|
11
9
|
setup(__props) {
|
|
12
10
|
const props = __props;
|
|
13
|
-
|
|
14
|
-
const [forceRender, key] = useForceUpdate();
|
|
15
|
-
function generateId() {
|
|
16
|
-
const upstreamId = layoutGroup == null ? void 0 : layoutGroup.id;
|
|
17
|
-
return shouldInheritId(props.inherit) && upstreamId ? props.id ? `${upstreamId}-${props.id}` : upstreamId : props.id;
|
|
18
|
-
}
|
|
19
|
-
function generateGroup() {
|
|
20
|
-
return shouldInheritGroup(props.inherit) ? (layoutGroup == null ? void 0 : layoutGroup.group) || nodeGroup() : nodeGroup();
|
|
21
|
-
}
|
|
22
|
-
const memoizedContext = {
|
|
23
|
-
id: generateId(),
|
|
24
|
-
group: generateGroup(),
|
|
25
|
-
forceRender,
|
|
26
|
-
key
|
|
27
|
-
};
|
|
28
|
-
watch(key, () => {
|
|
29
|
-
memoizedContext.id = generateId();
|
|
30
|
-
});
|
|
31
|
-
provideLayoutGroup(memoizedContext);
|
|
11
|
+
useLayoutGroup(props);
|
|
32
12
|
return (_ctx, _cache) => {
|
|
33
13
|
return renderSlot(_ctx.$slots, "default");
|
|
34
14
|
};
|