motion-v 0.11.1 → 0.11.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.
package/dist/cjs/index.js CHANGED
@@ -5193,19 +5193,23 @@ function isAnimateChanged(oldOptions, newOptions) {
5193
5193
  const newAnimate = newOptions.animate;
5194
5194
  if (oldAnimate === newAnimate)
5195
5195
  return false;
5196
- if (!oldAnimate || !newAnimate)
5196
+ if (!oldAnimate || !newAnimate) {
5197
5197
  return true;
5198
+ }
5198
5199
  if (typeof oldAnimate === "object" || typeof newAnimate === "object") {
5199
5200
  const oldKeys = Object.keys(oldAnimate);
5200
5201
  const newKeys = Object.keys(newAnimate);
5201
5202
  if (oldKeys.length !== newKeys.length)
5202
5203
  return true;
5203
5204
  return oldKeys.some((key) => {
5205
+ if (key === "transition")
5206
+ return false;
5204
5207
  const oldVal = oldAnimate[key];
5205
5208
  const newVal = newAnimate[key];
5206
5209
  return oldVal !== newVal;
5207
5210
  });
5208
5211
  }
5212
+ console.log(2344);
5209
5213
  return oldAnimate !== newAnimate;
5210
5214
  }
5211
5215
  const rotation = {
@@ -5436,7 +5440,7 @@ const Primitive = vue.defineComponent({
5436
5440
  const SELF_CLOSING_TAGS = ["area", "img", "input"];
5437
5441
  return () => {
5438
5442
  const motionProps = props.getProps();
5439
- const allAttrs = { ...attrs, ...motionProps };
5443
+ const allAttrs = { ...motionProps, ...attrs };
5440
5444
  if (typeof asTag === "string" && SELF_CLOSING_TAGS.includes(asTag))
5441
5445
  return vue.h(asTag, allAttrs);
5442
5446
  if (asTag !== "template") {
@@ -8191,7 +8195,8 @@ function animateUpdates({
8191
8195
  controlDelay = 0,
8192
8196
  directAnimate,
8193
8197
  directTransition,
8194
- isFallback = false
8198
+ isFallback = false,
8199
+ isExit = false
8195
8200
  } = {}) {
8196
8201
  const prevTarget = this.target;
8197
8202
  this.target = { ...this.baseTarget };
@@ -8203,7 +8208,14 @@ function animateUpdates({
8203
8208
  animationOptions = resolveStateAnimation.call(this, controlActiveState, transition);
8204
8209
  const factories = createAnimationFactories.call(this, prevTarget, animationOptions, controlDelay);
8205
8210
  const { getChildAnimations, childAnimations } = setupChildAnimations.call(this, transition, this.activeStates, isFallback);
8206
- return executeAnimations.call(this, factories, getChildAnimations, childAnimations, transition, controlActiveState);
8211
+ return executeAnimations.call(this, {
8212
+ factories,
8213
+ getChildAnimations,
8214
+ childAnimations,
8215
+ transition,
8216
+ controlActiveState,
8217
+ isExit
8218
+ });
8207
8219
  }
8208
8220
  function resolveDirectAnimation(directAnimate, directTransition) {
8209
8221
  const variant = resolveVariant(directAnimate, this.options.variants, this.options.custom);
@@ -8223,24 +8235,29 @@ function resolveStateAnimation(controlActiveState, transition) {
8223
8235
  if (controlActiveState)
8224
8236
  this.activeStates = { ...this.activeStates, ...controlActiveState };
8225
8237
  const transitionOptions = {};
8238
+ let variantTransition = {};
8239
+ let variant = {};
8226
8240
  STATE_TYPES.forEach((name) => {
8227
8241
  if (!this.activeStates[name] || isAnimationControls(this.options[name]))
8228
8242
  return;
8229
8243
  const definition = this.options[name];
8230
- let variant = core.isDef(definition) ? resolveVariant(definition, this.options.variants, this.options.custom) : void 0;
8244
+ let resolvedVariant = core.isDef(definition) ? resolveVariant(definition, this.options.variants, this.options.custom) : void 0;
8231
8245
  if (this.visualElement.isVariantNode) {
8232
8246
  const controlVariant = resolveVariant(this.context[name], this.options.variants, this.options.custom);
8233
- variant = controlVariant ? Object.assign(controlVariant || {}, variant) : variant;
8247
+ resolvedVariant = controlVariant ? Object.assign(controlVariant || {}, variant) : variant;
8234
8248
  }
8235
- if (!variant)
8249
+ if (!resolvedVariant)
8236
8250
  return;
8237
- Object.assign(transition, variant.transition);
8238
- Object.entries(variant).forEach(([key, value]) => {
8239
- if (key === "transition")
8240
- return;
8241
- this.target[key] = value;
8242
- transitionOptions[key] = getOptions(transition, key);
8243
- });
8251
+ if (name !== "initial")
8252
+ variantTransition = resolvedVariant.transition || this.options.transition;
8253
+ variant = Object.assign(variant, resolvedVariant);
8254
+ });
8255
+ Object.assign(transition, variantTransition);
8256
+ Object.entries(variant).forEach(([key, value]) => {
8257
+ if (key === "transition")
8258
+ return;
8259
+ this.target[key] = value;
8260
+ transitionOptions[key] = getOptions(transition, key);
8244
8261
  });
8245
8262
  return transitionOptions;
8246
8263
  }
@@ -8285,25 +8302,22 @@ function setupChildAnimations(transition, controlActiveState, isFallback) {
8285
8302
  childAnimations
8286
8303
  };
8287
8304
  }
8288
- function executeAnimations(factories, getChildAnimations, childAnimations, transition, controlActiveState) {
8289
- let animations;
8290
- const getAnimation = () => {
8291
- animations = factories.map((factory) => factory()).filter(Boolean);
8292
- return Promise.all(animations);
8293
- };
8294
- const isExit = this.activeStates.exit;
8305
+ function executeAnimations({
8306
+ factories,
8307
+ getChildAnimations,
8308
+ childAnimations,
8309
+ transition,
8310
+ controlActiveState,
8311
+ isExit = false
8312
+ }) {
8313
+ const getAnimation = () => Promise.all(factories.map((factory) => factory()).filter(Boolean));
8295
8314
  const animationTarget2 = { ...this.target };
8296
8315
  const element = this.element;
8297
8316
  const finishAnimation2 = (animationPromise) => {
8298
- if (!(animations == null ? void 0 : animations.length) && !childAnimations.length) {
8299
- if (isExit) {
8300
- element.dispatchEvent(motionEvent("motionstart", animationTarget2));
8301
- element.dispatchEvent(motionEvent("motioncomplete", animationTarget2, isExit));
8302
- }
8303
- return;
8304
- }
8305
8317
  element.dispatchEvent(motionEvent("motionstart", animationTarget2));
8306
- animationPromise.then(() => element.dispatchEvent(motionEvent("motioncomplete", animationTarget2, isExit))).catch(noop);
8318
+ animationPromise.then(() => {
8319
+ element.dispatchEvent(motionEvent("motioncomplete", animationTarget2, isExit));
8320
+ }).catch(noop);
8307
8321
  };
8308
8322
  const getAnimationPromise = () => {
8309
8323
  const animationPromise = (transition == null ? void 0 : transition.when) ? (transition.when === "beforeChildren" ? getAnimation() : getChildAnimations()).then(() => transition.when === "beforeChildren" ? getChildAnimations() : getAnimation()) : Promise.all([getAnimation(), getChildAnimations()]);
@@ -8337,7 +8351,7 @@ class MotionState {
8337
8351
  this.parent = parent;
8338
8352
  (_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.add(this);
8339
8353
  this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
8340
- const initialVariantSource = this.context.initial === false ? "animate" : "initial";
8354
+ const initialVariantSource = this.context.initial === false ? ["initial", "animate"] : ["initial"];
8341
8355
  this.initTarget(initialVariantSource);
8342
8356
  this.visualElement = createVisualElement(this.options.as, {
8343
8357
  presenceContext: null,
@@ -8379,7 +8393,12 @@ class MotionState {
8379
8393
  }
8380
8394
  // Initialize animation target values
8381
8395
  initTarget(initialVariantSource) {
8382
- this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
8396
+ this.baseTarget = initialVariantSource.reduce((acc, variant) => {
8397
+ return {
8398
+ ...acc,
8399
+ ...resolveVariant(this.options[variant] || this.context[variant], this.options.variants)
8400
+ };
8401
+ }, {});
8383
8402
  this.target = {};
8384
8403
  }
8385
8404
  // Update visual element with new options
@@ -8495,7 +8514,8 @@ class MotionState {
8495
8514
  });
8496
8515
  if (isAnimate) {
8497
8516
  this.animateUpdates({
8498
- isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants
8517
+ isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants,
8518
+ isExit: this.activeStates.exit
8499
8519
  });
8500
8520
  }
8501
8521
  }
@@ -8721,11 +8741,12 @@ const _sfc_main$6 = /* @__PURE__ */ vue.defineComponent({
8721
8741
  return attrsProps;
8722
8742
  }
8723
8743
  const PrimitiveRef = vue.ref();
8724
- function onMotionComplete() {
8725
- var _a;
8744
+ function onMotionComplete(e) {
8745
+ var _a, _b;
8726
8746
  if (props.asChild) {
8727
8747
  (_a = PrimitiveRef.value) == null ? void 0 : _a.$forceUpdate();
8728
8748
  }
8749
+ (_b = attrs.onMotioncomplete) == null ? void 0 : _b.call(attrs, e);
8729
8750
  }
8730
8751
  return (_ctx, _cache) => {
8731
8752
  var _a;
@@ -8921,10 +8942,10 @@ const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
8921
8942
  }
8922
8943
  }
8923
8944
  }
8924
- doneCallbacks.set(el, doneCallback);
8925
- el.addEventListener("motioncomplete", doneCallback);
8926
8945
  delay(() => {
8927
8946
  state2.setActive("exit", true);
8947
+ doneCallbacks.set(el, doneCallback);
8948
+ el.addEventListener("motioncomplete", doneCallback);
8928
8949
  });
8929
8950
  }
8930
8951
  const transitionProps = vue.computed(() => {
@@ -80,10 +80,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
80
80
  }
81
81
  }
82
82
  }
83
- doneCallbacks.set(el, doneCallback);
84
- el.addEventListener("motioncomplete", doneCallback);
85
83
  delay(() => {
86
84
  state.setActive("exit", true);
85
+ doneCallbacks.set(el, doneCallback);
86
+ el.addEventListener("motioncomplete", doneCallback);
87
87
  });
88
88
  }
89
89
  const transitionProps = computed(() => {
@@ -201,11 +201,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
201
201
  return attrsProps;
202
202
  }
203
203
  const PrimitiveRef = ref();
204
- function onMotionComplete() {
205
- var _a;
204
+ function onMotionComplete(e) {
205
+ var _a, _b;
206
206
  if (props.asChild) {
207
207
  (_a = PrimitiveRef.value) == null ? void 0 : _a.$forceUpdate();
208
208
  }
209
+ (_b = attrs.onMotioncomplete) == null ? void 0 : _b.call(attrs, e);
209
210
  }
210
211
  return (_ctx, _cache) => {
211
212
  var _a;
@@ -22,7 +22,7 @@ const Primitive = defineComponent({
22
22
  const SELF_CLOSING_TAGS = ["area", "img", "input"];
23
23
  return () => {
24
24
  const motionProps = props.getProps();
25
- const allAttrs = { ...attrs, ...motionProps };
25
+ const allAttrs = { ...motionProps, ...attrs };
26
26
  if (typeof asTag === "string" && SELF_CLOSING_TAGS.includes(asTag))
27
27
  return h(asTag, allAttrs);
28
28
  if (asTag !== "template") {
@@ -9,11 +9,12 @@ export type StateType = typeof STATE_TYPES[number];
9
9
  * @param directAnimate - 直接动画目标值
10
10
  * @param directTransition - 直接动画过渡配置
11
11
  */
12
- export declare function animateUpdates(this: MotionState, { controlActiveState, controlDelay, directAnimate, directTransition, isFallback, }?: {
12
+ export declare function animateUpdates(this: MotionState, { controlActiveState, controlDelay, directAnimate, directTransition, isFallback, isExit, }?: {
13
13
  controlActiveState?: Partial<Record<string, boolean>>;
14
14
  controlDelay?: number;
15
15
  directAnimate?: Options['animate'];
16
16
  directTransition?: $Transition;
17
17
  isFallback?: boolean;
18
+ isExit?: boolean;
18
19
  }): any;
19
20
  export {};
@@ -13,7 +13,8 @@ function animateUpdates({
13
13
  controlDelay = 0,
14
14
  directAnimate,
15
15
  directTransition,
16
- isFallback = false
16
+ isFallback = false,
17
+ isExit = false
17
18
  } = {}) {
18
19
  const prevTarget = this.target;
19
20
  this.target = { ...this.baseTarget };
@@ -25,7 +26,14 @@ function animateUpdates({
25
26
  animationOptions = resolveStateAnimation.call(this, controlActiveState, transition);
26
27
  const factories = createAnimationFactories.call(this, prevTarget, animationOptions, controlDelay);
27
28
  const { getChildAnimations, childAnimations } = setupChildAnimations.call(this, transition, this.activeStates, isFallback);
28
- return executeAnimations.call(this, factories, getChildAnimations, childAnimations, transition, controlActiveState);
29
+ return executeAnimations.call(this, {
30
+ factories,
31
+ getChildAnimations,
32
+ childAnimations,
33
+ transition,
34
+ controlActiveState,
35
+ isExit
36
+ });
29
37
  }
30
38
  function resolveDirectAnimation(directAnimate, directTransition) {
31
39
  const variant = resolveVariant(directAnimate, this.options.variants, this.options.custom);
@@ -45,24 +53,29 @@ function resolveStateAnimation(controlActiveState, transition) {
45
53
  if (controlActiveState)
46
54
  this.activeStates = { ...this.activeStates, ...controlActiveState };
47
55
  const transitionOptions = {};
56
+ let variantTransition = {};
57
+ let variant = {};
48
58
  STATE_TYPES.forEach((name) => {
49
59
  if (!this.activeStates[name] || isAnimationControls(this.options[name]))
50
60
  return;
51
61
  const definition = this.options[name];
52
- let variant = isDef(definition) ? resolveVariant(definition, this.options.variants, this.options.custom) : void 0;
62
+ let resolvedVariant = isDef(definition) ? resolveVariant(definition, this.options.variants, this.options.custom) : void 0;
53
63
  if (this.visualElement.isVariantNode) {
54
64
  const controlVariant = resolveVariant(this.context[name], this.options.variants, this.options.custom);
55
- variant = controlVariant ? Object.assign(controlVariant || {}, variant) : variant;
65
+ resolvedVariant = controlVariant ? Object.assign(controlVariant || {}, variant) : variant;
56
66
  }
57
- if (!variant)
67
+ if (!resolvedVariant)
58
68
  return;
59
- Object.assign(transition, variant.transition);
60
- Object.entries(variant).forEach(([key, value]) => {
61
- if (key === "transition")
62
- return;
63
- this.target[key] = value;
64
- transitionOptions[key] = getOptions(transition, key);
65
- });
69
+ if (name !== "initial")
70
+ variantTransition = resolvedVariant.transition || this.options.transition;
71
+ variant = Object.assign(variant, resolvedVariant);
72
+ });
73
+ Object.assign(transition, variantTransition);
74
+ Object.entries(variant).forEach(([key, value]) => {
75
+ if (key === "transition")
76
+ return;
77
+ this.target[key] = value;
78
+ transitionOptions[key] = getOptions(transition, key);
66
79
  });
67
80
  return transitionOptions;
68
81
  }
@@ -107,25 +120,22 @@ function setupChildAnimations(transition, controlActiveState, isFallback) {
107
120
  childAnimations
108
121
  };
109
122
  }
110
- function executeAnimations(factories, getChildAnimations, childAnimations, transition, controlActiveState) {
111
- let animations;
112
- const getAnimation = () => {
113
- animations = factories.map((factory) => factory()).filter(Boolean);
114
- return Promise.all(animations);
115
- };
116
- const isExit = this.activeStates.exit;
123
+ function executeAnimations({
124
+ factories,
125
+ getChildAnimations,
126
+ childAnimations,
127
+ transition,
128
+ controlActiveState,
129
+ isExit = false
130
+ }) {
131
+ const getAnimation = () => Promise.all(factories.map((factory) => factory()).filter(Boolean));
117
132
  const animationTarget = { ...this.target };
118
133
  const element = this.element;
119
134
  const finishAnimation = (animationPromise) => {
120
- if (!(animations == null ? void 0 : animations.length) && !childAnimations.length) {
121
- if (isExit) {
122
- element.dispatchEvent(motionEvent("motionstart", animationTarget));
123
- element.dispatchEvent(motionEvent("motioncomplete", animationTarget, isExit));
124
- }
125
- return;
126
- }
127
135
  element.dispatchEvent(motionEvent("motionstart", animationTarget));
128
- animationPromise.then(() => element.dispatchEvent(motionEvent("motioncomplete", animationTarget, isExit))).catch(noop);
136
+ animationPromise.then(() => {
137
+ element.dispatchEvent(motionEvent("motioncomplete", animationTarget, isExit));
138
+ }).catch(noop);
129
139
  };
130
140
  const getAnimationPromise = () => {
131
141
  const animationPromise = (transition == null ? void 0 : transition.when) ? (transition.when === "beforeChildren" ? getAnimation() : getChildAnimations()).then(() => transition.when === "beforeChildren" ? getChildAnimations() : getAnimation()) : Promise.all([getAnimation(), getChildAnimations()]);
@@ -29,7 +29,7 @@ class MotionState {
29
29
  this.parent = parent;
30
30
  (_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.add(this);
31
31
  this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
32
- const initialVariantSource = this.context.initial === false ? "animate" : "initial";
32
+ const initialVariantSource = this.context.initial === false ? ["initial", "animate"] : ["initial"];
33
33
  this.initTarget(initialVariantSource);
34
34
  this.visualElement = createVisualElement(this.options.as, {
35
35
  presenceContext: null,
@@ -71,7 +71,12 @@ class MotionState {
71
71
  }
72
72
  // Initialize animation target values
73
73
  initTarget(initialVariantSource) {
74
- this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
74
+ this.baseTarget = initialVariantSource.reduce((acc, variant) => {
75
+ return {
76
+ ...acc,
77
+ ...resolveVariant(this.options[variant] || this.context[variant], this.options.variants)
78
+ };
79
+ }, {});
75
80
  this.target = {};
76
81
  }
77
82
  // Update visual element with new options
@@ -187,7 +192,8 @@ class MotionState {
187
192
  });
188
193
  if (isAnimate) {
189
194
  this.animateUpdates({
190
- isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants
195
+ isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants,
196
+ isExit: this.activeStates.exit
191
197
  });
192
198
  }
193
199
  }
@@ -104,19 +104,23 @@ function isAnimateChanged(oldOptions, newOptions) {
104
104
  const newAnimate = newOptions.animate;
105
105
  if (oldAnimate === newAnimate)
106
106
  return false;
107
- if (!oldAnimate || !newAnimate)
107
+ if (!oldAnimate || !newAnimate) {
108
108
  return true;
109
+ }
109
110
  if (typeof oldAnimate === "object" || typeof newAnimate === "object") {
110
111
  const oldKeys = Object.keys(oldAnimate);
111
112
  const newKeys = Object.keys(newAnimate);
112
113
  if (oldKeys.length !== newKeys.length)
113
114
  return true;
114
115
  return oldKeys.some((key) => {
116
+ if (key === "transition")
117
+ return false;
115
118
  const oldVal = oldAnimate[key];
116
119
  const newVal = newAnimate[key];
117
120
  return oldVal !== newVal;
118
121
  });
119
122
  }
123
+ console.log(2344);
120
124
  return oldAnimate !== newAnimate;
121
125
  }
122
126
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-v",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",