motion-v 0.4.1 → 0.5.0-beta.2

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.
Files changed (30) hide show
  1. package/dist/cjs/index.js +294 -96
  2. package/dist/es/components/AnimatePresence.vue.mjs +13 -2
  3. package/dist/es/components/LayoutGroup.vue.mjs +3 -23
  4. package/dist/es/components/Motion.vue.mjs +16 -15
  5. package/dist/es/components/presence.mjs +5 -2
  6. package/dist/es/components/use-layout-group.mjs +34 -0
  7. package/dist/es/components/use-pop-layout.mjs +47 -0
  8. package/dist/es/components/utils.mjs +8 -0
  9. package/dist/es/constants/index.mjs +1 -1
  10. package/dist/es/features/gestures/hover.mjs +4 -0
  11. package/dist/es/features/gestures/in-view.mjs +4 -0
  12. package/dist/es/features/layout/layout.mjs +7 -4
  13. package/dist/es/state/animate-variants-children.mjs +72 -0
  14. package/dist/es/state/motion-state.mjs +74 -20
  15. package/dist/es/state/schedule.mjs +1 -1
  16. package/dist/src/components/AnimatePresence.d.ts +2 -7
  17. package/dist/src/components/LayoutGroup.d.ts +1 -5
  18. package/dist/src/components/Motion.d.ts +1 -3
  19. package/dist/src/components/presence.d.ts +2 -1
  20. package/dist/src/components/type.d.ts +5 -24
  21. package/dist/src/components/use-layout-group.d.ts +20 -0
  22. package/dist/src/components/use-pop-layout.d.ts +6 -0
  23. package/dist/src/components/utils.d.ts +1 -0
  24. package/dist/src/features/layout/types.d.ts +1 -1
  25. package/dist/src/index.d.ts +5 -3
  26. package/dist/src/state/animate-variants-children.d.ts +15 -0
  27. package/dist/src/state/motion-state.d.ts +8 -7
  28. package/dist/src/types/state.d.ts +11 -2
  29. package/package.json +4 -3
  30. /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.unmount();
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.getDepth() - b.getDepth();
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,16 +6899,84 @@ 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;
6973
+ this.isFirstAnimate = true;
6896
6974
  this.activeStates = {
6897
6975
  initial: true,
6898
6976
  animate: true
6899
6977
  };
6900
6978
  this._context = null;
6979
+ this.id = `motion-state-${id++}`;
6901
6980
  this.options = options;
6902
6981
  this.parent = parent;
6903
6982
  this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
@@ -6905,7 +6984,10 @@ class MotionState {
6905
6984
  presenceContext: null,
6906
6985
  parent: parent == null ? void 0 : parent.visualElement,
6907
6986
  props: {
6908
- ...this.options
6987
+ ...this.options,
6988
+ whileHover: this.options.hover,
6989
+ whileTap: this.options.press,
6990
+ whileInView: this.options.inView
6909
6991
  },
6910
6992
  visualState: {
6911
6993
  renderState: {
@@ -6941,19 +7023,29 @@ class MotionState {
6941
7023
  get initial() {
6942
7024
  return isDef(this.options.initial) ? this.options.initial : this.context.initial;
6943
7025
  }
6944
- mount(element) {
7026
+ updateOptions() {
6945
7027
  var _a;
7028
+ this.visualElement.update({
7029
+ ...this.options,
7030
+ whileHover: this.options.hover,
7031
+ whileTap: this.options.press,
7032
+ whileInView: this.options.inView
7033
+ }, (_a = this.parent) == null ? void 0 : _a.context);
7034
+ }
7035
+ mount(element, options) {
6946
7036
  invariant(
6947
7037
  Boolean(element),
6948
7038
  "Animation state must be mounted with valid Element"
6949
7039
  );
6950
7040
  this.element = element;
7041
+ this.options = options;
6951
7042
  mountedStates.set(element, this);
6952
7043
  if (!visualElementStore.get(element)) {
6953
7044
  this.visualElement.mount(element);
6954
7045
  visualElementStore.set(element, this.visualElement);
6955
7046
  }
6956
- this.visualElement.update(this.options, (_a = this.parent) == null ? void 0 : _a.context);
7047
+ this.visualElement.state = this;
7048
+ this.updateOptions();
6957
7049
  if (typeof this.initial === "object") {
6958
7050
  for (const key in this.initial) {
6959
7051
  this.visualElement.setStaticValue(key, this.initial[key]);
@@ -6964,6 +7056,7 @@ class MotionState {
6964
7056
  }
6965
7057
  }
6966
7058
  this.featureManager.mount();
7059
+ scheduleAnimation(this);
6967
7060
  }
6968
7061
  unmount() {
6969
7062
  var _a;
@@ -6973,14 +7066,13 @@ class MotionState {
6973
7066
  this.featureManager.unmount();
6974
7067
  }
6975
7068
  update(options) {
6976
- var _a;
6977
7069
  this.options = options;
6978
- this.visualElement.update(this.options, (_a = this.parent) == null ? void 0 : _a.context);
7070
+ this.updateOptions();
6979
7071
  this.featureManager.update();
6980
7072
  scheduleAnimation(this);
6981
7073
  }
6982
7074
  setActive(name, isActive) {
6983
- if (!this.element)
7075
+ if (!this.element || this.activeStates[name] === isActive)
6984
7076
  return;
6985
7077
  this.activeStates[name] = isActive;
6986
7078
  scheduleAnimation(this);
@@ -6988,15 +7080,31 @@ class MotionState {
6988
7080
  *animateUpdates() {
6989
7081
  const prevTarget = this.target;
6990
7082
  this.target = {};
7083
+ const activeState = {};
6991
7084
  const animationOptions = {};
7085
+ let transition;
6992
7086
  for (const name of STATE_TYPES) {
7087
+ if (name === "initial") {
7088
+ if (!this.isFirstAnimate) {
7089
+ continue;
7090
+ }
7091
+ this.isFirstAnimate = false;
7092
+ }
6993
7093
  if (!this.activeStates[name])
6994
7094
  continue;
7095
+ const definition = isDef(this.options[name]) ? this.options[name] : this.context[name];
6995
7096
  const variant = resolveVariant(
6996
- isDef(this.options[name]) ? this.options[name] : this.context[name],
7097
+ definition,
6997
7098
  this.options.variants,
6998
7099
  this.options.custom
6999
7100
  );
7101
+ transition = Object.assign({}, this.options.transition, variant == null ? void 0 : variant.transition);
7102
+ if (typeof definition === "string") {
7103
+ activeState[name] = {
7104
+ definition,
7105
+ transition
7106
+ };
7107
+ }
7000
7108
  if (!variant)
7001
7109
  continue;
7002
7110
  const allTarget = { ...prevTarget, ...variant };
@@ -7005,7 +7113,7 @@ class MotionState {
7005
7113
  continue;
7006
7114
  this.target[key] = variant[key];
7007
7115
  animationOptions[key] = getOptions(
7008
- variant.transition ?? this.options.transition ?? {},
7116
+ transition,
7009
7117
  key
7010
7118
  );
7011
7119
  }
@@ -7022,12 +7130,13 @@ class MotionState {
7022
7130
  }
7023
7131
  if (hasChanged(prevTarget[key], this.target[key])) {
7024
7132
  (_a = this.baseTarget)[key] ?? (_a[key] = style.get(this.element, key));
7133
+ const keyValue = this.target[key] === "none" ? transformResetValue[key] : this.target[key];
7025
7134
  animationFactories.push(
7026
7135
  () => {
7027
7136
  return animate(
7028
7137
  this.element,
7029
7138
  {
7030
- [key]: this.target[key] === "none" ? transformResetValue[key] : this.target[key]
7139
+ [key]: keyValue
7031
7140
  },
7032
7141
  animationOptions[key] || {}
7033
7142
  );
@@ -7035,14 +7144,40 @@ class MotionState {
7035
7144
  );
7036
7145
  }
7037
7146
  });
7147
+ let getChildAnimations = () => Promise.resolve();
7148
+ let childAnimations = [];
7149
+ if (Object.keys(activeState).length) {
7150
+ const { getAnimations, animations: animations2 } = animateVariantsChildren(this, activeState);
7151
+ getChildAnimations = getAnimations;
7152
+ childAnimations = animations2;
7153
+ }
7038
7154
  yield;
7039
- const animations = animationFactories.map((factory) => factory()).filter(Boolean);
7040
- if (!animations.length)
7155
+ let animations;
7156
+ const getAnimation = () => {
7157
+ animations = animationFactories.map((factory) => factory()).filter(Boolean);
7158
+ return Promise.all(animations);
7159
+ };
7160
+ const { when } = transition;
7161
+ let animationPromise;
7162
+ if (when) {
7163
+ const [first, last] = when === "beforeChildren" ? [getAnimation, getChildAnimations] : [getChildAnimations, getAnimation];
7164
+ animationPromise = first().then(() => last());
7165
+ } else {
7166
+ animationPromise = Promise.all([getAnimation(), getChildAnimations()]);
7167
+ }
7168
+ const isExit = this.activeStates.exit;
7169
+ if (!(animations == null ? void 0 : animations.length) && !childAnimations.length) {
7170
+ if (isExit) {
7171
+ this.element.dispatchEvent(motionEvent("motionstart", this.target));
7172
+ this.element.dispatchEvent(motionEvent("motioncomplete", {
7173
+ ...this.target
7174
+ }, isExit));
7175
+ }
7041
7176
  return;
7177
+ }
7042
7178
  const animationTarget2 = this.target;
7043
7179
  this.element.dispatchEvent(motionEvent("motionstart", animationTarget2));
7044
- const isExit = this.activeStates.exit;
7045
- Promise.all(animations).then(() => {
7180
+ animationPromise.then(() => {
7046
7181
  this.element.dispatchEvent(motionEvent("motioncomplete", {
7047
7182
  ...animationTarget2
7048
7183
  }, isExit));
@@ -7051,17 +7186,12 @@ class MotionState {
7051
7186
  isMounted() {
7052
7187
  return Boolean(this.element);
7053
7188
  }
7054
- getDepth() {
7055
- return this.depth;
7056
- }
7057
7189
  getOptions() {
7058
7190
  return this.options;
7059
7191
  }
7060
- getTarget() {
7061
- return this.target;
7062
- }
7063
7192
  }
7064
- const doneCallbacks = /* @__PURE__ */ new Map();
7193
+ const doneCallbacks = /* @__PURE__ */ new WeakMap();
7194
+ const unPresenceDom = vue.ref(/* @__PURE__ */ new WeakMap());
7065
7195
  function removeDoneCallback(element) {
7066
7196
  const prevDoneCallback = doneCallbacks.get(element);
7067
7197
  if (prevDoneCallback) {
@@ -7070,6 +7200,11 @@ function removeDoneCallback(element) {
7070
7200
  doneCallbacks.delete(element);
7071
7201
  }
7072
7202
  const [injectAnimatePresence, provideAnimatePresence] = createContext("AnimatePresenceContext");
7203
+ function getMotionElement(el) {
7204
+ if ((el == null ? void 0 : el.nodeType) === 3 || (el == null ? void 0 : el.nodeType) === 8)
7205
+ return getMotionElement(el.nextSibling);
7206
+ return el;
7207
+ }
7073
7208
  const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
7074
7209
  ...{
7075
7210
  name: "Motion",
@@ -7099,7 +7234,7 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
7099
7234
  onPressEnd: { type: Function },
7100
7235
  onViewEnter: { type: Function },
7101
7236
  onViewLeave: { type: Function },
7102
- layout: { type: Boolean },
7237
+ layout: { type: [Boolean, String] },
7103
7238
  layoutId: {},
7104
7239
  layoutScroll: { type: Boolean },
7105
7240
  layoutRoot: { type: Boolean },
@@ -7130,16 +7265,16 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
7130
7265
  parentState
7131
7266
  );
7132
7267
  provideMotion(state2);
7133
- const instance = vue.getCurrentInstance();
7268
+ const instance = vue.getCurrentInstance().proxy;
7134
7269
  vue.onMounted(() => {
7135
- state2.mount(instance == null ? void 0 : instance.vnode.el);
7136
- state2.update({
7270
+ state2.mount(getMotionElement(instance.$el), {
7137
7271
  ...attrs,
7138
- ...props
7272
+ ...props,
7273
+ initial: presenceInitial.value === false ? presenceInitial.value : props.initial === true ? void 0 : props.initial
7139
7274
  });
7140
7275
  });
7141
7276
  vue.onUnmounted(() => {
7142
- if (safeUnmount(instance == null ? void 0 : instance.vnode.el))
7277
+ if (safeUnmount(getMotionElement(instance.$el)))
7143
7278
  state2.unmount();
7144
7279
  });
7145
7280
  vue.onUpdated(() => {
@@ -7150,22 +7285,23 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
7150
7285
  });
7151
7286
  });
7152
7287
  function getProps() {
7288
+ const isSVG = state2.visualElement.type === "svg";
7153
7289
  const attrsProps = { ...attrs };
7154
7290
  Object.keys(attrs).forEach((key) => {
7155
7291
  if (isMotionValue(attrs[key]))
7156
7292
  attrsProps[key] = attrs[key].get();
7157
7293
  });
7158
7294
  let styleProps = {
7159
- ...props.style
7295
+ ...props.style,
7296
+ ...isSVG ? {} : state2.visualElement.latestValues
7160
7297
  };
7298
+ if (isSVG) {
7299
+ const { attributes, style: style2 } = convertSvgStyleToAttributes(state2.target);
7300
+ Object.assign(attrsProps, attributes);
7301
+ Object.assign(styleProps, style2, props.style);
7302
+ }
7161
7303
  if (!state2.isMounted()) {
7162
- if (isSVGElement$1(props.as)) {
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
- }
7304
+ Object.assign(styleProps, state2.target, props.style);
7169
7305
  }
7170
7306
  styleProps = createStyles(styleProps);
7171
7307
  attrsProps.style = styleProps;
@@ -7187,6 +7323,111 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
7187
7323
  };
7188
7324
  }
7189
7325
  });
7326
+ function useForceUpdate() {
7327
+ const key = vue.ref(0);
7328
+ function forceUpdate() {
7329
+ key.value++;
7330
+ }
7331
+ return [forceUpdate, key];
7332
+ }
7333
+ function notify(node) {
7334
+ return !node.isLayoutDirty && node.willUpdate(false);
7335
+ }
7336
+ function nodeGroup() {
7337
+ const nodes = /* @__PURE__ */ new Set();
7338
+ const subscriptions = /* @__PURE__ */ new WeakMap();
7339
+ const dirtyAll = () => nodes.forEach(notify);
7340
+ return {
7341
+ add: (node) => {
7342
+ nodes.add(node);
7343
+ subscriptions.set(
7344
+ node,
7345
+ node.addEventListener("willUpdate", dirtyAll)
7346
+ );
7347
+ },
7348
+ remove: (node) => {
7349
+ nodes.delete(node);
7350
+ const unsubscribe = subscriptions.get(node);
7351
+ if (unsubscribe) {
7352
+ unsubscribe();
7353
+ subscriptions.delete(node);
7354
+ }
7355
+ dirtyAll();
7356
+ },
7357
+ dirty: dirtyAll
7358
+ };
7359
+ }
7360
+ function useLayoutGroup(props) {
7361
+ const parentGroup = injectLayoutGroup(null);
7362
+ const [forceRender, key] = useForceUpdate();
7363
+ const context = {
7364
+ id: getGroupId(props, parentGroup),
7365
+ group: getGroup(props, parentGroup),
7366
+ forceRender,
7367
+ key
7368
+ };
7369
+ vue.watch(key, () => {
7370
+ context.id = getGroupId(props, parentGroup);
7371
+ });
7372
+ provideLayoutGroup(context);
7373
+ return context;
7374
+ }
7375
+ function getGroupId(props, parentGroup) {
7376
+ const shouldInherit = props.inherit === true || props.inherit === "id";
7377
+ const parentId = parentGroup == null ? void 0 : parentGroup.id;
7378
+ if (shouldInherit && parentId) {
7379
+ return props.id ? `${parentId}-${props.id}` : parentId;
7380
+ }
7381
+ return props.id;
7382
+ }
7383
+ function getGroup(props, parentGroup) {
7384
+ const shouldInherit = props.inherit === true || props.inherit === "group";
7385
+ return shouldInherit ? (parentGroup == null ? void 0 : parentGroup.group) || nodeGroup() : nodeGroup();
7386
+ }
7387
+ function usePopLayout(props) {
7388
+ const styles = /* @__PURE__ */ new WeakMap();
7389
+ function addPopStyle(state2) {
7390
+ if (props.mode !== "popLayout")
7391
+ return;
7392
+ const size = {
7393
+ height: state2.element.offsetHeight || 0,
7394
+ width: state2.element.offsetWidth || 0,
7395
+ top: state2.element.offsetTop,
7396
+ left: state2.element.offsetLeft
7397
+ };
7398
+ state2.element.dataset.motionPopId = state2.id;
7399
+ const style2 = document.createElement("style");
7400
+ styles.set(state2, style2);
7401
+ document.head.appendChild(style2);
7402
+ style2.textContent = `
7403
+ [data-motion-pop-id="${state2.id}"] {
7404
+ animation: pop 0.3s ease-in-out;
7405
+ }
7406
+ `;
7407
+ if (style2.sheet) {
7408
+ style2.sheet.insertRule(`
7409
+ [data-motion-pop-id="${state2.id}"] {
7410
+ position: absolute !important;
7411
+ width: ${size.width}px !important;
7412
+ height: ${size.height}px !important;
7413
+ top: ${size.top}px !important;
7414
+ left: ${size.left}px !important;
7415
+ }
7416
+ `);
7417
+ }
7418
+ }
7419
+ function removePopStyle(state2) {
7420
+ const style2 = styles.get(state2);
7421
+ if (style2) {
7422
+ styles.delete(state2);
7423
+ document.head.removeChild(style2);
7424
+ }
7425
+ }
7426
+ return {
7427
+ addPopStyle,
7428
+ removePopStyle
7429
+ };
7430
+ }
7190
7431
  const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
7191
7432
  ...{
7192
7433
  name: "AnimatePresence",
@@ -7215,17 +7456,26 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
7215
7456
  }
7216
7457
  removeDoneCallback(el);
7217
7458
  state2.setActive("exit", false);
7459
+ unPresenceDom.value.delete(el);
7218
7460
  }
7461
+ const layoutGroup = useLayoutGroup(props);
7462
+ const { addPopStyle, removePopStyle } = usePopLayout(props);
7219
7463
  function exit(el, done) {
7464
+ unPresenceDom.value.set(el, true);
7220
7465
  const state2 = mountedStates.get(el);
7221
7466
  if (!state2) {
7222
7467
  return done();
7223
7468
  }
7224
7469
  removeDoneCallback(el);
7470
+ addPopStyle(state2);
7225
7471
  function doneCallback(e) {
7226
- var _a;
7472
+ var _a, _b, _c;
7473
+ removePopStyle(state2);
7227
7474
  if ((_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.isExit) {
7228
7475
  removeDoneCallback(el);
7476
+ unPresenceDom.value.delete(el);
7477
+ (_b = state2.visualElement.projection) == null ? void 0 : _b.willUpdate();
7478
+ (_c = layoutGroup.forceRender) == null ? void 0 : _c.call(layoutGroup);
7229
7479
  done();
7230
7480
  if (!el.isConnected) {
7231
7481
  state2.unmount();
@@ -7252,40 +7502,6 @@ const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
7252
7502
  };
7253
7503
  }
7254
7504
  });
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
7505
  const _sfc_main = /* @__PURE__ */ vue.defineComponent({
7290
7506
  __name: "LayoutGroup",
7291
7507
  props: {
@@ -7294,25 +7510,7 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
7294
7510
  },
7295
7511
  setup(__props) {
7296
7512
  const props = __props;
7297
- const layoutGroup = injectLayoutGroup(null);
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);
7513
+ useLayoutGroup(props);
7316
7514
  return (_ctx, _cache) => {
7317
7515
  return vue.renderSlot(_ctx.$slots, "default");
7318
7516
  };
@@ -7522,7 +7720,7 @@ function useVelocity(value) {
7522
7720
  const components = {
7523
7721
  motion: [
7524
7722
  "Motion",
7525
- "MotionPresence",
7723
+ "AnimatePresence",
7526
7724
  "LayoutGroup"
7527
7725
  ]
7528
7726
  };
@@ -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();