motion-v 0.11.0-beta.4 → 0.11.0-beta.5
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 +74 -61
- package/dist/es/animation/hooks/animation-controls.mjs +2 -0
- package/dist/es/components/animate-presence/AnimatePresence.vue.mjs +13 -9
- package/dist/es/components/motion/Motion.vue.mjs +1 -4
- package/dist/es/components/reorder/Group.vue.mjs +1 -1
- package/dist/es/components/reorder/Item.d.ts +4 -4
- package/dist/es/components/reorder/Item.vue.mjs +1 -1
- package/dist/es/features/gestures/drag/types.d.ts +2 -2
- package/dist/es/features/gestures/focus/types.d.ts +2 -2
- package/dist/es/features/gestures/hover/types.d.ts +2 -2
- package/dist/es/features/gestures/in-view/types.d.ts +2 -2
- package/dist/es/features/gestures/press/types.d.ts +2 -2
- package/dist/es/features/layout/layout.mjs +11 -6
- package/dist/es/state/animate-updates.mjs +4 -2
- package/dist/es/state/motion-state.d.ts +1 -0
- package/dist/es/state/motion-state.mjs +25 -33
- package/dist/es/state/utils/is-variant-labels.d.ts +2 -0
- package/dist/es/state/utils/is-variant-labels.mjs +6 -0
- package/dist/es/state/utils.mjs +7 -2
- package/dist/es/types/framer-motion.d.ts +1 -1
- package/dist/es/types/state.d.ts +15 -11
- package/dist/es/utils/delay.d.ts +1 -0
- package/dist/es/utils/delay.mjs +8 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -4875,7 +4875,7 @@ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease: ease2 } = {})
|
|
|
4875
4875
|
return startDelay + delay2;
|
|
4876
4876
|
};
|
|
4877
4877
|
}
|
|
4878
|
-
function delay(callback, timeout) {
|
|
4878
|
+
function delay$1(callback, timeout) {
|
|
4879
4879
|
const start = time.now();
|
|
4880
4880
|
const checkElapsed = ({ timestamp }) => {
|
|
4881
4881
|
const elapsed = timestamp - start;
|
|
@@ -4888,7 +4888,7 @@ function delay(callback, timeout) {
|
|
|
4888
4888
|
return () => cancelFrame(checkElapsed);
|
|
4889
4889
|
}
|
|
4890
4890
|
function delayInSeconds(callback, timeout) {
|
|
4891
|
-
return delay(callback, secondsToMilliseconds$1(timeout));
|
|
4891
|
+
return delay$1(callback, secondsToMilliseconds$1(timeout));
|
|
4892
4892
|
}
|
|
4893
4893
|
const distance = (a, b) => Math.abs(a - b);
|
|
4894
4894
|
function distance2D(a, b) {
|
|
@@ -4987,7 +4987,12 @@ function getContextWindow({ current }) {
|
|
|
4987
4987
|
const [injectMotion, provideMotion] = createContext("Motion");
|
|
4988
4988
|
const [injectLayoutGroup, provideLayoutGroup] = createContext("LayoutGroup");
|
|
4989
4989
|
function resolveVariant(definition, variants, custom) {
|
|
4990
|
-
if (
|
|
4990
|
+
if (Array.isArray(definition)) {
|
|
4991
|
+
return definition.reduce((acc, item) => {
|
|
4992
|
+
const resolvedVariant = resolveVariant(item, variants, custom);
|
|
4993
|
+
return resolvedVariant ? { ...acc, ...resolvedVariant } : acc;
|
|
4994
|
+
}, {});
|
|
4995
|
+
} else if (typeof definition === "object") {
|
|
4991
4996
|
return definition;
|
|
4992
4997
|
} else if (definition && variants) {
|
|
4993
4998
|
const variant = variants[definition];
|
|
@@ -5012,7 +5017,7 @@ function shallowCompare(next, prev) {
|
|
|
5012
5017
|
return true;
|
|
5013
5018
|
}
|
|
5014
5019
|
function getOptions(options, key) {
|
|
5015
|
-
return options[key] ? { ...options, ...options[key] } : { ...options };
|
|
5020
|
+
return options[key] ? { ...options, ...options[key], [key]: void 0 } : { ...options };
|
|
5016
5021
|
}
|
|
5017
5022
|
function isCssVar(name) {
|
|
5018
5023
|
return name == null ? void 0 : name.startsWith("--");
|
|
@@ -6422,22 +6427,22 @@ class LayoutFeature extends Feature {
|
|
|
6422
6427
|
}
|
|
6423
6428
|
didUpdate() {
|
|
6424
6429
|
var _a, _b;
|
|
6425
|
-
if (this.state.options.layout || this.state.options.layoutId)
|
|
6430
|
+
if (this.state.options.layout || this.state.options.layoutId || this.state.options.drag)
|
|
6426
6431
|
(_b = (_a = this.state.visualElement.projection) == null ? void 0 : _a.root) == null ? void 0 : _b.didUpdate();
|
|
6427
6432
|
}
|
|
6428
6433
|
mount() {
|
|
6429
6434
|
var _a;
|
|
6430
6435
|
const options = this.state.options;
|
|
6431
6436
|
const layoutGroup = this.state.options.layoutGroup;
|
|
6432
|
-
if (options.layout || options.layoutId
|
|
6437
|
+
if (options.layout || options.layoutId) {
|
|
6433
6438
|
const projection = this.state.visualElement.projection;
|
|
6434
6439
|
if (projection) {
|
|
6435
6440
|
projection.promote();
|
|
6436
6441
|
(_a = layoutGroup == null ? void 0 : layoutGroup.group) == null ? void 0 : _a.add(projection);
|
|
6437
6442
|
}
|
|
6438
|
-
this.didUpdate();
|
|
6439
6443
|
globalProjectionState.hasEverUpdated = true;
|
|
6440
6444
|
}
|
|
6445
|
+
this.didUpdate();
|
|
6441
6446
|
}
|
|
6442
6447
|
beforeUnmount() {
|
|
6443
6448
|
const projection = this.state.visualElement.projection;
|
|
@@ -6452,11 +6457,16 @@ class LayoutFeature extends Feature {
|
|
|
6452
6457
|
}
|
|
6453
6458
|
}
|
|
6454
6459
|
unmount() {
|
|
6460
|
+
var _a, _b;
|
|
6455
6461
|
const layoutGroup = this.state.options.layoutGroup;
|
|
6456
6462
|
const projection = this.state.visualElement.projection;
|
|
6457
|
-
if (
|
|
6458
|
-
layoutGroup.group
|
|
6459
|
-
|
|
6463
|
+
if (projection) {
|
|
6464
|
+
if (layoutGroup == null ? void 0 : layoutGroup.group) {
|
|
6465
|
+
layoutGroup.group.remove(projection);
|
|
6466
|
+
}
|
|
6467
|
+
if ((_b = (_a = projection.getStack()) == null ? void 0 : _a.lead) == null ? void 0 : _b.animationProgress) {
|
|
6468
|
+
return;
|
|
6469
|
+
}
|
|
6460
6470
|
this.didUpdate();
|
|
6461
6471
|
}
|
|
6462
6472
|
}
|
|
@@ -6971,7 +6981,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6971
6981
|
attachResizeListener(instance, () => {
|
|
6972
6982
|
this.root.updateBlockedByResize = true;
|
|
6973
6983
|
cancelDelay && cancelDelay();
|
|
6974
|
-
cancelDelay = delay(resizeUnblockUpdate, 250);
|
|
6984
|
+
cancelDelay = delay$1(resizeUnblockUpdate, 250);
|
|
6975
6985
|
if (globalProjectionState.hasAnimatedSinceResize) {
|
|
6976
6986
|
globalProjectionState.hasAnimatedSinceResize = false;
|
|
6977
6987
|
this.nodes.forEach(finishAnimation);
|
|
@@ -8168,12 +8178,14 @@ function setupChildAnimations(transition, controlActiveState, isFallback) {
|
|
|
8168
8178
|
const childAnimations = Array.from(this.visualElement.variantChildren).map((child, index) => {
|
|
8169
8179
|
const childDelay = delayChildren + generateStaggerDuration(index);
|
|
8170
8180
|
return child.state.animateUpdates({
|
|
8171
|
-
controlActiveState
|
|
8181
|
+
controlActiveState,
|
|
8172
8182
|
controlDelay: isFallback ? 0 : childDelay
|
|
8173
8183
|
});
|
|
8174
8184
|
}).filter(Boolean);
|
|
8175
8185
|
return {
|
|
8176
|
-
getChildAnimations: () => Promise.all(childAnimations.map((animation) =>
|
|
8186
|
+
getChildAnimations: () => Promise.all(childAnimations.map((animation) => {
|
|
8187
|
+
return typeof animation === "function" ? animation() : animation;
|
|
8188
|
+
})),
|
|
8177
8189
|
childAnimations
|
|
8178
8190
|
};
|
|
8179
8191
|
}
|
|
@@ -8204,6 +8216,9 @@ function executeAnimations(factories, getChildAnimations, childAnimations, trans
|
|
|
8204
8216
|
};
|
|
8205
8217
|
return controlActiveState ? getAnimationPromise : getAnimationPromise();
|
|
8206
8218
|
}
|
|
8219
|
+
function isVariantLabels(value) {
|
|
8220
|
+
return typeof value === "string" || Array.isArray(value);
|
|
8221
|
+
}
|
|
8207
8222
|
const mountedStates = /* @__PURE__ */ new WeakMap();
|
|
8208
8223
|
let id = 0;
|
|
8209
8224
|
const mountedLayoutIds = /* @__PURE__ */ new Set();
|
|
@@ -8225,6 +8240,8 @@ class MotionState {
|
|
|
8225
8240
|
this.parent = parent;
|
|
8226
8241
|
(_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.add(this);
|
|
8227
8242
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
8243
|
+
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
8244
|
+
this.initTarget(initialVariantSource);
|
|
8228
8245
|
this.visualElement = createVisualElement(this.options.as, {
|
|
8229
8246
|
presenceContext: null,
|
|
8230
8247
|
parent: parent == null ? void 0 : parent.visualElement,
|
|
@@ -8242,12 +8259,12 @@ class MotionState {
|
|
|
8242
8259
|
vars: {},
|
|
8243
8260
|
attrs: {}
|
|
8244
8261
|
},
|
|
8245
|
-
latestValues: {
|
|
8262
|
+
latestValues: {
|
|
8263
|
+
...this.baseTarget
|
|
8264
|
+
}
|
|
8246
8265
|
},
|
|
8247
8266
|
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
8248
8267
|
});
|
|
8249
|
-
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
8250
|
-
this.initTarget(initialVariantSource);
|
|
8251
8268
|
this.featureManager = new FeatureManager(this);
|
|
8252
8269
|
}
|
|
8253
8270
|
// Get animation context, falling back to parent context for inheritance
|
|
@@ -8256,7 +8273,7 @@ class MotionState {
|
|
|
8256
8273
|
const handler = {
|
|
8257
8274
|
get: (target, prop) => {
|
|
8258
8275
|
var _a;
|
|
8259
|
-
return
|
|
8276
|
+
return isVariantLabels(this.options[prop]) ? this.options[prop] : (_a = this.parent) == null ? void 0 : _a.context[prop];
|
|
8260
8277
|
}
|
|
8261
8278
|
};
|
|
8262
8279
|
this._context = new Proxy({}, handler);
|
|
@@ -8266,9 +8283,6 @@ class MotionState {
|
|
|
8266
8283
|
// Initialize animation target values
|
|
8267
8284
|
initTarget(initialVariantSource) {
|
|
8268
8285
|
this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
|
|
8269
|
-
for (const key in this.baseTarget) {
|
|
8270
|
-
this.visualElement.setStaticValue(key, this.baseTarget[key]);
|
|
8271
|
-
}
|
|
8272
8286
|
this.target = {};
|
|
8273
8287
|
}
|
|
8274
8288
|
// Update visual element with new options
|
|
@@ -8322,34 +8336,26 @@ class MotionState {
|
|
|
8322
8336
|
unmount(unMountChildren = false) {
|
|
8323
8337
|
const shouldDelay = this.options.layoutId && !mountedLayoutIds.has(this.options.layoutId);
|
|
8324
8338
|
const unmount = () => {
|
|
8325
|
-
var _a, _b, _c;
|
|
8326
|
-
mountedStates.delete(this.element);
|
|
8327
|
-
this.featureManager.unmount();
|
|
8328
|
-
if (unMountChildren && !shouldDelay) {
|
|
8329
|
-
frame.render(() => {
|
|
8330
|
-
var _a2;
|
|
8331
|
-
(_a2 = this.visualElement) == null ? void 0 : _a2.unmount();
|
|
8332
|
-
});
|
|
8333
|
-
} else {
|
|
8334
|
-
(_a = this.visualElement) == null ? void 0 : _a.unmount();
|
|
8335
|
-
}
|
|
8336
8339
|
if (unMountChildren) {
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8340
|
+
Array.from(this.children).reverse().forEach(this.unmountChild);
|
|
8341
|
+
}
|
|
8342
|
+
const unmountState = () => {
|
|
8343
|
+
var _a, _b, _c;
|
|
8344
|
+
(_b = (_a = this.parent) == null ? void 0 : _a.children) == null ? void 0 : _b.delete(this);
|
|
8345
|
+
mountedStates.delete(this.element);
|
|
8346
|
+
this.featureManager.unmount();
|
|
8347
|
+
(_c = this.visualElement) == null ? void 0 : _c.unmount();
|
|
8348
|
+
};
|
|
8349
|
+
if (shouldDelay) {
|
|
8350
|
+
Promise.resolve().then(unmountState);
|
|
8351
|
+
} else {
|
|
8352
|
+
unmountState();
|
|
8343
8353
|
}
|
|
8344
|
-
(_c = (_b = this.parent) == null ? void 0 : _b.children) == null ? void 0 : _c.delete(this);
|
|
8345
8354
|
};
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
} else {
|
|
8351
|
-
unmount();
|
|
8352
|
-
}
|
|
8355
|
+
unmount();
|
|
8356
|
+
}
|
|
8357
|
+
unmountChild(child) {
|
|
8358
|
+
child.unmount(true);
|
|
8353
8359
|
}
|
|
8354
8360
|
// Called before updating, executes in parent-to-child order
|
|
8355
8361
|
beforeUpdate() {
|
|
@@ -8376,7 +8382,7 @@ class MotionState {
|
|
|
8376
8382
|
});
|
|
8377
8383
|
if (isAnimate) {
|
|
8378
8384
|
this.animateUpdates({
|
|
8379
|
-
isFallback: !isActive
|
|
8385
|
+
isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants
|
|
8380
8386
|
});
|
|
8381
8387
|
}
|
|
8382
8388
|
}
|
|
@@ -8425,7 +8431,7 @@ const _sfc_main$6 = /* @__PURE__ */ vue.defineComponent({
|
|
|
8425
8431
|
asChild: { type: Boolean },
|
|
8426
8432
|
whileDrag: {},
|
|
8427
8433
|
custom: {},
|
|
8428
|
-
initial: { type: [String, Object, Boolean] },
|
|
8434
|
+
initial: { type: [String, Array, Object, Boolean] },
|
|
8429
8435
|
animate: {},
|
|
8430
8436
|
exit: {},
|
|
8431
8437
|
variants: {},
|
|
@@ -8562,9 +8568,6 @@ const _sfc_main$6 = /* @__PURE__ */ vue.defineComponent({
|
|
|
8562
8568
|
Object.assign(attrsProps, attributes);
|
|
8563
8569
|
Object.assign(styleProps, style2);
|
|
8564
8570
|
}
|
|
8565
|
-
if (!state2.isMounted()) {
|
|
8566
|
-
Object.assign(styleProps, state2.baseTarget);
|
|
8567
|
-
}
|
|
8568
8571
|
if (props.drag && props.dragListener !== false) {
|
|
8569
8572
|
Object.assign(styleProps, {
|
|
8570
8573
|
userSelect: "none",
|
|
@@ -8699,6 +8702,11 @@ function usePopLayout(props) {
|
|
|
8699
8702
|
styles
|
|
8700
8703
|
};
|
|
8701
8704
|
}
|
|
8705
|
+
function delay(fn) {
|
|
8706
|
+
return Promise.resolve().then(() => {
|
|
8707
|
+
fn();
|
|
8708
|
+
});
|
|
8709
|
+
}
|
|
8702
8710
|
const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
|
|
8703
8711
|
...{
|
|
8704
8712
|
name: "AnimatePresence",
|
|
@@ -8734,20 +8742,21 @@ const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
|
|
|
8734
8742
|
removePopStyle(state2);
|
|
8735
8743
|
state2.isVShow = true;
|
|
8736
8744
|
removeDoneCallback(el);
|
|
8737
|
-
|
|
8745
|
+
delay(() => {
|
|
8746
|
+
state2.setActive("exit", false);
|
|
8747
|
+
});
|
|
8738
8748
|
}
|
|
8739
8749
|
const exitDom = /* @__PURE__ */ new Map();
|
|
8740
8750
|
vue.onUnmounted(() => {
|
|
8741
8751
|
exitDom.clear();
|
|
8742
8752
|
});
|
|
8743
8753
|
function exit(el, done) {
|
|
8744
|
-
|
|
8745
|
-
if (!state2) {
|
|
8746
|
-
if (!props.unwrapElement) {
|
|
8747
|
-
return done();
|
|
8748
|
-
}
|
|
8754
|
+
if (props.unwrapElement) {
|
|
8749
8755
|
el = el.firstElementChild;
|
|
8750
|
-
|
|
8756
|
+
}
|
|
8757
|
+
const state2 = mountedStates.get(el);
|
|
8758
|
+
if (!state2) {
|
|
8759
|
+
return done();
|
|
8751
8760
|
}
|
|
8752
8761
|
exitDom.set(el, true);
|
|
8753
8762
|
removeDoneCallback(el);
|
|
@@ -8770,14 +8779,16 @@ const _sfc_main$5 = /* @__PURE__ */ vue.defineComponent({
|
|
|
8770
8779
|
removePopStyle(state2);
|
|
8771
8780
|
}
|
|
8772
8781
|
done();
|
|
8773
|
-
if (!
|
|
8782
|
+
if (!el.isConnected) {
|
|
8774
8783
|
state2.unmount(true);
|
|
8775
8784
|
}
|
|
8776
8785
|
}
|
|
8777
8786
|
}
|
|
8778
8787
|
doneCallbacks.set(el, doneCallback);
|
|
8779
8788
|
el.addEventListener("motioncomplete", doneCallback);
|
|
8780
|
-
|
|
8789
|
+
delay(() => {
|
|
8790
|
+
state2.setActive("exit", true);
|
|
8791
|
+
});
|
|
8781
8792
|
}
|
|
8782
8793
|
const transitionProps = vue.computed(() => {
|
|
8783
8794
|
if (props.multiple) {
|
|
@@ -8878,7 +8889,7 @@ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
|
|
|
8878
8889
|
asChild: { type: Boolean },
|
|
8879
8890
|
whileDrag: {},
|
|
8880
8891
|
custom: {},
|
|
8881
|
-
initial: { type: [String, Object, Boolean] },
|
|
8892
|
+
initial: { type: [String, Array, Object, Boolean] },
|
|
8882
8893
|
animate: {},
|
|
8883
8894
|
exit: {},
|
|
8884
8895
|
variants: {},
|
|
@@ -9202,7 +9213,7 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
|
|
|
9202
9213
|
asChild: { type: Boolean },
|
|
9203
9214
|
whileDrag: { default: void 0 },
|
|
9204
9215
|
custom: {},
|
|
9205
|
-
initial: { type: [String, Object, Boolean], default: void 0 },
|
|
9216
|
+
initial: { type: [String, Array, Object, Boolean], default: void 0 },
|
|
9206
9217
|
animate: { default: void 0 },
|
|
9207
9218
|
exit: {},
|
|
9208
9219
|
variants: {},
|
|
@@ -9533,6 +9544,8 @@ function animationControls() {
|
|
|
9533
9544
|
function setValues(state2, definition) {
|
|
9534
9545
|
if (typeof definition === "string") {
|
|
9535
9546
|
return setVariants(state2, [definition]);
|
|
9547
|
+
} else if (Array.isArray(definition)) {
|
|
9548
|
+
return setVariants(state2, definition);
|
|
9536
9549
|
} else {
|
|
9537
9550
|
setStateTarget(state2, definition);
|
|
9538
9551
|
setTarget(state2.visualElement, definition);
|
|
@@ -64,6 +64,8 @@ function animationControls() {
|
|
|
64
64
|
function setValues(state, definition) {
|
|
65
65
|
if (typeof definition === "string") {
|
|
66
66
|
return setVariants(state, [definition]);
|
|
67
|
+
} else if (Array.isArray(definition)) {
|
|
68
|
+
return setVariants(state, definition);
|
|
67
69
|
} else {
|
|
68
70
|
setStateTarget(state, definition);
|
|
69
71
|
setTarget(state.visualElement, definition);
|
|
@@ -2,6 +2,7 @@ import { defineComponent, onMounted, onUnmounted, computed, openBlock, createBlo
|
|
|
2
2
|
import { mountedStates } from "../../state/motion-state.mjs";
|
|
3
3
|
import { provideAnimatePresence, removeDoneCallback, doneCallbacks } from "../presence.mjs";
|
|
4
4
|
import { usePopLayout } from "./use-pop-layout.mjs";
|
|
5
|
+
import { delay } from "../../utils/delay.mjs";
|
|
5
6
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
7
|
...{
|
|
7
8
|
name: "AnimatePresence",
|
|
@@ -37,20 +38,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
37
38
|
removePopStyle(state);
|
|
38
39
|
state.isVShow = true;
|
|
39
40
|
removeDoneCallback(el);
|
|
40
|
-
|
|
41
|
+
delay(() => {
|
|
42
|
+
state.setActive("exit", false);
|
|
43
|
+
});
|
|
41
44
|
}
|
|
42
45
|
const exitDom = /* @__PURE__ */ new Map();
|
|
43
46
|
onUnmounted(() => {
|
|
44
47
|
exitDom.clear();
|
|
45
48
|
});
|
|
46
49
|
function exit(el, done) {
|
|
47
|
-
|
|
48
|
-
if (!state) {
|
|
49
|
-
if (!props.unwrapElement) {
|
|
50
|
-
return done();
|
|
51
|
-
}
|
|
50
|
+
if (props.unwrapElement) {
|
|
52
51
|
el = el.firstElementChild;
|
|
53
|
-
|
|
52
|
+
}
|
|
53
|
+
const state = mountedStates.get(el);
|
|
54
|
+
if (!state) {
|
|
55
|
+
return done();
|
|
54
56
|
}
|
|
55
57
|
exitDom.set(el, true);
|
|
56
58
|
removeDoneCallback(el);
|
|
@@ -73,14 +75,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
73
75
|
removePopStyle(state);
|
|
74
76
|
}
|
|
75
77
|
done();
|
|
76
|
-
if (!
|
|
78
|
+
if (!el.isConnected) {
|
|
77
79
|
state.unmount(true);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
doneCallbacks.set(el, doneCallback);
|
|
82
84
|
el.addEventListener("motioncomplete", doneCallback);
|
|
83
|
-
|
|
85
|
+
delay(() => {
|
|
86
|
+
state.setActive("exit", true);
|
|
87
|
+
});
|
|
84
88
|
}
|
|
85
89
|
const transitionProps = computed(() => {
|
|
86
90
|
if (props.multiple) {
|
|
@@ -18,7 +18,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
18
18
|
asChild: { type: Boolean },
|
|
19
19
|
whileDrag: {},
|
|
20
20
|
custom: {},
|
|
21
|
-
initial: { type: [String, Object, Boolean] },
|
|
21
|
+
initial: { type: [String, Array, Object, Boolean] },
|
|
22
22
|
animate: {},
|
|
23
23
|
exit: {},
|
|
24
24
|
variants: {},
|
|
@@ -155,9 +155,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
155
155
|
Object.assign(attrsProps, attributes);
|
|
156
156
|
Object.assign(styleProps, style);
|
|
157
157
|
}
|
|
158
|
-
if (!state.isMounted()) {
|
|
159
|
-
Object.assign(styleProps, state.baseTarget);
|
|
160
|
-
}
|
|
161
158
|
if (props.drag && props.dragListener !== false) {
|
|
162
159
|
Object.assign(styleProps, {
|
|
163
160
|
userSelect: "none",
|
|
@@ -17,7 +17,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
17
17
|
asChild: { type: Boolean },
|
|
18
18
|
whileDrag: {},
|
|
19
19
|
custom: {},
|
|
20
|
-
initial: { type: [String, Object, Boolean] },
|
|
20
|
+
initial: { type: [String, Array, Object, Boolean] },
|
|
21
21
|
animate: {},
|
|
22
22
|
exit: {},
|
|
23
23
|
variants: {},
|
|
@@ -51,10 +51,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
|
|
|
51
51
|
layoutScroll: boolean;
|
|
52
52
|
layoutRoot: boolean;
|
|
53
53
|
crossfade: boolean;
|
|
54
|
-
initial:
|
|
55
|
-
animate:
|
|
56
|
-
inView:
|
|
57
|
-
hover:
|
|
54
|
+
initial: import('../../types').VariantLabels | import('../../types').Variant | boolean;
|
|
55
|
+
animate: import('../../types').VariantLabels | import('../../types').Variant | import('../../animation/types').AnimationControls;
|
|
56
|
+
inView: import('../../types').VariantLabels | import('../../types').Variant;
|
|
57
|
+
hover: import('../../types').VariantLabels | import('../../types').Variant;
|
|
58
58
|
whileDrag: import('../../types').Options["whileDrag"];
|
|
59
59
|
dragElastic: number;
|
|
60
60
|
dragMomentum: boolean;
|
|
@@ -17,7 +17,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
17
17
|
asChild: { type: Boolean },
|
|
18
18
|
whileDrag: { default: void 0 },
|
|
19
19
|
custom: {},
|
|
20
|
-
initial: { type: [String, Object, Boolean], default: void 0 },
|
|
20
|
+
initial: { type: [String, Array, Object, Boolean], default: void 0 },
|
|
21
21
|
animate: { default: void 0 },
|
|
22
22
|
exit: {},
|
|
23
23
|
variants: {},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DragControls } from './use-drag-controls';
|
|
2
|
-
import { Variant } from '../../../types';
|
|
2
|
+
import { Variant, VariantLabels } from '../../../types';
|
|
3
3
|
import { Axis, BoundingBox, DragElastic, InertiaOptions, PanInfo } from 'framer-motion';
|
|
4
4
|
export interface ResolvedConstraints {
|
|
5
5
|
x: Partial<Axis>;
|
|
@@ -221,5 +221,5 @@ export interface DragProps extends DragHandlers {
|
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
223
|
dragControls?: DragControls;
|
|
224
|
-
whileDrag?:
|
|
224
|
+
whileDrag?: VariantLabels | Variant;
|
|
225
225
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Variant } from '../../../types';
|
|
1
|
+
import { Variant, VariantLabels } from '../../../types';
|
|
2
2
|
export type FocusProps = {
|
|
3
|
-
focus?:
|
|
3
|
+
focus?: VariantLabels | Variant;
|
|
4
4
|
onFocus?: (e: FocusEvent) => void;
|
|
5
5
|
onBlur?: (e: FocusEvent) => void;
|
|
6
6
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Variant } from '../../../types';
|
|
1
|
+
import { Variant, VariantLabels } from '../../../types';
|
|
2
2
|
import { EventInfo } from 'framer-motion';
|
|
3
3
|
export type HoverEvent = (event: MouseEvent, info: EventInfo) => void;
|
|
4
4
|
export interface HoverProps {
|
|
5
|
-
hover?:
|
|
5
|
+
hover?: VariantLabels | Variant;
|
|
6
6
|
onHoverStart?: HoverEvent;
|
|
7
7
|
onHoverEnd?: HoverEvent;
|
|
8
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Variant } from '../../../types';
|
|
1
|
+
import { Variant, VariantLabels } from '../../../types';
|
|
2
2
|
type MarginValue = `${number}${'px' | '%'}`;
|
|
3
3
|
type MarginType = MarginValue | `${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue} ${MarginValue}`;
|
|
4
4
|
export interface InViewOptions {
|
|
@@ -11,7 +11,7 @@ export interface InViewProps {
|
|
|
11
11
|
inViewOptions?: InViewOptions & {
|
|
12
12
|
once?: boolean;
|
|
13
13
|
};
|
|
14
|
-
inView?:
|
|
14
|
+
inView?: VariantLabels | Variant;
|
|
15
15
|
onViewportEnter?: ViewportEventHandler;
|
|
16
16
|
onViewportLeave?: ViewportEventHandler;
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Variant } from '../../../types';
|
|
1
|
+
import { Variant, VariantLabels } from '../../../types';
|
|
2
2
|
import { EventInfo } from 'framer-motion';
|
|
3
3
|
export type PressEvent = (event: PointerEvent, info: EventInfo) => void;
|
|
4
4
|
export interface PressProps {
|
|
@@ -6,7 +6,7 @@ export interface PressProps {
|
|
|
6
6
|
* If `true`, the press gesture will attach its start listener to window.
|
|
7
7
|
*/
|
|
8
8
|
globalPressTarget?: boolean;
|
|
9
|
-
press?:
|
|
9
|
+
press?: VariantLabels | Variant;
|
|
10
10
|
onPressStart?: PressEvent;
|
|
11
11
|
onPress?: PressEvent;
|
|
12
12
|
onPressCancel?: PressEvent;
|
|
@@ -15,22 +15,22 @@ class LayoutFeature extends Feature {
|
|
|
15
15
|
}
|
|
16
16
|
didUpdate() {
|
|
17
17
|
var _a, _b;
|
|
18
|
-
if (this.state.options.layout || this.state.options.layoutId)
|
|
18
|
+
if (this.state.options.layout || this.state.options.layoutId || this.state.options.drag)
|
|
19
19
|
(_b = (_a = this.state.visualElement.projection) == null ? void 0 : _a.root) == null ? void 0 : _b.didUpdate();
|
|
20
20
|
}
|
|
21
21
|
mount() {
|
|
22
22
|
var _a;
|
|
23
23
|
const options = this.state.options;
|
|
24
24
|
const layoutGroup = this.state.options.layoutGroup;
|
|
25
|
-
if (options.layout || options.layoutId
|
|
25
|
+
if (options.layout || options.layoutId) {
|
|
26
26
|
const projection = this.state.visualElement.projection;
|
|
27
27
|
if (projection) {
|
|
28
28
|
projection.promote();
|
|
29
29
|
(_a = layoutGroup == null ? void 0 : layoutGroup.group) == null ? void 0 : _a.add(projection);
|
|
30
30
|
}
|
|
31
|
-
this.didUpdate();
|
|
32
31
|
globalProjectionState.hasEverUpdated = true;
|
|
33
32
|
}
|
|
33
|
+
this.didUpdate();
|
|
34
34
|
}
|
|
35
35
|
beforeUnmount() {
|
|
36
36
|
const projection = this.state.visualElement.projection;
|
|
@@ -45,11 +45,16 @@ class LayoutFeature extends Feature {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
unmount() {
|
|
48
|
+
var _a, _b;
|
|
48
49
|
const layoutGroup = this.state.options.layoutGroup;
|
|
49
50
|
const projection = this.state.visualElement.projection;
|
|
50
|
-
if (
|
|
51
|
-
layoutGroup.group
|
|
52
|
-
|
|
51
|
+
if (projection) {
|
|
52
|
+
if (layoutGroup == null ? void 0 : layoutGroup.group) {
|
|
53
|
+
layoutGroup.group.remove(projection);
|
|
54
|
+
}
|
|
55
|
+
if ((_b = (_a = projection.getStack()) == null ? void 0 : _a.lead) == null ? void 0 : _b.animationProgress) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
53
58
|
this.didUpdate();
|
|
54
59
|
}
|
|
55
60
|
}
|
|
@@ -88,12 +88,14 @@ function setupChildAnimations(transition, controlActiveState, isFallback) {
|
|
|
88
88
|
const childAnimations = Array.from(this.visualElement.variantChildren).map((child, index) => {
|
|
89
89
|
const childDelay = delayChildren + generateStaggerDuration(index);
|
|
90
90
|
return child.state.animateUpdates({
|
|
91
|
-
controlActiveState
|
|
91
|
+
controlActiveState,
|
|
92
92
|
controlDelay: isFallback ? 0 : childDelay
|
|
93
93
|
});
|
|
94
94
|
}).filter(Boolean);
|
|
95
95
|
return {
|
|
96
|
-
getChildAnimations: () => Promise.all(childAnimations.map((animation) =>
|
|
96
|
+
getChildAnimations: () => Promise.all(childAnimations.map((animation) => {
|
|
97
|
+
return typeof animation === "function" ? animation() : animation;
|
|
98
|
+
})),
|
|
97
99
|
childAnimations
|
|
98
100
|
};
|
|
99
101
|
}
|
|
@@ -29,6 +29,7 @@ export declare class MotionState {
|
|
|
29
29
|
mount(element: HTMLElement, options: Options, notAnimate?: boolean): void;
|
|
30
30
|
beforeUnmount(): void;
|
|
31
31
|
unmount(unMountChildren?: boolean): void;
|
|
32
|
+
private unmountChild;
|
|
32
33
|
beforeUpdate(): void;
|
|
33
34
|
update(options: Options): void;
|
|
34
35
|
setActive(name: StateType, isActive: boolean, isAnimate?: boolean): void;
|
|
@@ -5,6 +5,7 @@ import { FeatureManager } from "../features/feature-manager.mjs";
|
|
|
5
5
|
import { createVisualElement } from "./create-visual-element.mjs";
|
|
6
6
|
import { doneCallbacks } from "../components/presence.mjs";
|
|
7
7
|
import { animateUpdates } from "./animate-updates.mjs";
|
|
8
|
+
import { isVariantLabels } from "./utils/is-variant-labels.mjs";
|
|
8
9
|
import { frame } from "../external/.pnpm/framer-motion@11.16.6/external/framer-motion/dist/es/frameloop/frame.mjs";
|
|
9
10
|
const mountedStates = /* @__PURE__ */ new WeakMap();
|
|
10
11
|
let id = 0;
|
|
@@ -27,6 +28,8 @@ class MotionState {
|
|
|
27
28
|
this.parent = parent;
|
|
28
29
|
(_a = parent == null ? void 0 : parent.children) == null ? void 0 : _a.add(this);
|
|
29
30
|
this.depth = (parent == null ? void 0 : parent.depth) + 1 || 0;
|
|
31
|
+
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
32
|
+
this.initTarget(initialVariantSource);
|
|
30
33
|
this.visualElement = createVisualElement(this.options.as, {
|
|
31
34
|
presenceContext: null,
|
|
32
35
|
parent: parent == null ? void 0 : parent.visualElement,
|
|
@@ -44,12 +47,12 @@ class MotionState {
|
|
|
44
47
|
vars: {},
|
|
45
48
|
attrs: {}
|
|
46
49
|
},
|
|
47
|
-
latestValues: {
|
|
50
|
+
latestValues: {
|
|
51
|
+
...this.baseTarget
|
|
52
|
+
}
|
|
48
53
|
},
|
|
49
54
|
reducedMotionConfig: options.motionConfig.reduceMotion
|
|
50
55
|
});
|
|
51
|
-
const initialVariantSource = options.initial === false ? "animate" : "initial";
|
|
52
|
-
this.initTarget(initialVariantSource);
|
|
53
56
|
this.featureManager = new FeatureManager(this);
|
|
54
57
|
}
|
|
55
58
|
// Get animation context, falling back to parent context for inheritance
|
|
@@ -58,7 +61,7 @@ class MotionState {
|
|
|
58
61
|
const handler = {
|
|
59
62
|
get: (target, prop) => {
|
|
60
63
|
var _a;
|
|
61
|
-
return
|
|
64
|
+
return isVariantLabels(this.options[prop]) ? this.options[prop] : (_a = this.parent) == null ? void 0 : _a.context[prop];
|
|
62
65
|
}
|
|
63
66
|
};
|
|
64
67
|
this._context = new Proxy({}, handler);
|
|
@@ -68,9 +71,6 @@ class MotionState {
|
|
|
68
71
|
// Initialize animation target values
|
|
69
72
|
initTarget(initialVariantSource) {
|
|
70
73
|
this.baseTarget = resolveVariant(this.options[initialVariantSource] || this.context[initialVariantSource], this.options.variants) || {};
|
|
71
|
-
for (const key in this.baseTarget) {
|
|
72
|
-
this.visualElement.setStaticValue(key, this.baseTarget[key]);
|
|
73
|
-
}
|
|
74
74
|
this.target = {};
|
|
75
75
|
}
|
|
76
76
|
// Update visual element with new options
|
|
@@ -124,34 +124,26 @@ class MotionState {
|
|
|
124
124
|
unmount(unMountChildren = false) {
|
|
125
125
|
const shouldDelay = this.options.layoutId && !mountedLayoutIds.has(this.options.layoutId);
|
|
126
126
|
const unmount = () => {
|
|
127
|
-
var _a, _b, _c;
|
|
128
|
-
mountedStates.delete(this.element);
|
|
129
|
-
this.featureManager.unmount();
|
|
130
|
-
if (unMountChildren && !shouldDelay) {
|
|
131
|
-
frame.render(() => {
|
|
132
|
-
var _a2;
|
|
133
|
-
(_a2 = this.visualElement) == null ? void 0 : _a2.unmount();
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
(_a = this.visualElement) == null ? void 0 : _a.unmount();
|
|
137
|
-
}
|
|
138
127
|
if (unMountChildren) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
Array.from(this.children).reverse().forEach(this.unmountChild);
|
|
129
|
+
}
|
|
130
|
+
const unmountState = () => {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
(_b = (_a = this.parent) == null ? void 0 : _a.children) == null ? void 0 : _b.delete(this);
|
|
133
|
+
mountedStates.delete(this.element);
|
|
134
|
+
this.featureManager.unmount();
|
|
135
|
+
(_c = this.visualElement) == null ? void 0 : _c.unmount();
|
|
136
|
+
};
|
|
137
|
+
if (shouldDelay) {
|
|
138
|
+
Promise.resolve().then(unmountState);
|
|
139
|
+
} else {
|
|
140
|
+
unmountState();
|
|
145
141
|
}
|
|
146
|
-
(_c = (_b = this.parent) == null ? void 0 : _b.children) == null ? void 0 : _c.delete(this);
|
|
147
142
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else {
|
|
153
|
-
unmount();
|
|
154
|
-
}
|
|
143
|
+
unmount();
|
|
144
|
+
}
|
|
145
|
+
unmountChild(child) {
|
|
146
|
+
child.unmount(true);
|
|
155
147
|
}
|
|
156
148
|
// Called before updating, executes in parent-to-child order
|
|
157
149
|
beforeUpdate() {
|
|
@@ -178,7 +170,7 @@ class MotionState {
|
|
|
178
170
|
});
|
|
179
171
|
if (isAnimate) {
|
|
180
172
|
this.animateUpdates({
|
|
181
|
-
isFallback: !isActive
|
|
173
|
+
isFallback: !isActive && name !== "exit" && this.visualElement.isControllingVariants
|
|
182
174
|
});
|
|
183
175
|
}
|
|
184
176
|
}
|
package/dist/es/state/utils.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
function resolveVariant(definition, variants, custom) {
|
|
2
|
-
if (
|
|
2
|
+
if (Array.isArray(definition)) {
|
|
3
|
+
return definition.reduce((acc, item) => {
|
|
4
|
+
const resolvedVariant = resolveVariant(item, variants, custom);
|
|
5
|
+
return resolvedVariant ? { ...acc, ...resolvedVariant } : acc;
|
|
6
|
+
}, {});
|
|
7
|
+
} else if (typeof definition === "object") {
|
|
3
8
|
return definition;
|
|
4
9
|
} else if (definition && variants) {
|
|
5
10
|
const variant = variants[definition];
|
|
@@ -24,7 +29,7 @@ function shallowCompare(next, prev) {
|
|
|
24
29
|
return true;
|
|
25
30
|
}
|
|
26
31
|
function getOptions(options, key) {
|
|
27
|
-
return options[key] ? { ...options, ...options[key] } : { ...options };
|
|
32
|
+
return options[key] ? { ...options, ...options[key], [key]: void 0 } : { ...options };
|
|
28
33
|
}
|
|
29
34
|
function isCssVar(name) {
|
|
30
35
|
return name == null ? void 0 : name.startsWith("--");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Inertia, Keyframes, None, Repeat, Spring, Tween } from 'framer-motion';
|
|
2
|
+
export type { Point } from 'framer-motion';
|
|
2
3
|
export interface FrameData {
|
|
3
4
|
delta: number;
|
|
4
5
|
timestamp: number;
|
|
@@ -40,4 +41,3 @@ type TransitionMap = Orchestration & TransitionDefinition & {
|
|
|
40
41
|
[key: string]: TransitionDefinition;
|
|
41
42
|
};
|
|
42
43
|
export type $Transition = (Orchestration & Repeat & TransitionDefinition) | (Orchestration & Repeat & TransitionMap);
|
|
43
|
-
export {};
|
package/dist/es/types/state.d.ts
CHANGED
|
@@ -17,7 +17,11 @@ export type TargetResolver = (custom: any, current: Target, velocity: Target) =>
|
|
|
17
17
|
export interface Variant extends DOMKeyframesDefinition {
|
|
18
18
|
transition?: $Transition;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Either a string, or array of strings, that reference variants defined via the `variants` prop.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export type VariantLabels = string | string[];
|
|
21
25
|
interface BoundingBox {
|
|
22
26
|
top: number;
|
|
23
27
|
right: number;
|
|
@@ -29,15 +33,15 @@ export interface DragOptions {
|
|
|
29
33
|
dragSnapToOrigin?: boolean;
|
|
30
34
|
}
|
|
31
35
|
export type MotionStyle = Partial<{
|
|
32
|
-
[K in keyof Variant]: Variant[K] | MotionValue;
|
|
36
|
+
[K in keyof (Variant & TransformProperties)]: (Variant & TransformProperties)[K] | MotionValue;
|
|
33
37
|
}>;
|
|
34
38
|
export type ElementType = keyof IntrinsicElementAttributes;
|
|
35
39
|
export interface Options<T = any> extends LayoutOptions, PressProps, HoverProps, InViewProps, DragProps, PanProps, FocusProps {
|
|
36
40
|
custom?: T;
|
|
37
41
|
as?: ElementType;
|
|
38
|
-
initial?:
|
|
39
|
-
animate?:
|
|
40
|
-
exit?:
|
|
42
|
+
initial?: VariantLabels | Variant | boolean;
|
|
43
|
+
animate?: VariantLabels | Variant | AnimationControls;
|
|
44
|
+
exit?: VariantLabels | Variant;
|
|
41
45
|
variants?: {
|
|
42
46
|
[k: string]: Variant | ((custom: T) => Variant);
|
|
43
47
|
};
|
|
@@ -52,12 +56,12 @@ export interface Options<T = any> extends LayoutOptions, PressProps, HoverProps,
|
|
|
52
56
|
onUpdate?: (latest: ResolvedValues) => void;
|
|
53
57
|
}
|
|
54
58
|
export interface MotionStateContext {
|
|
55
|
-
initial?:
|
|
56
|
-
animate?:
|
|
57
|
-
inView?:
|
|
58
|
-
hover?:
|
|
59
|
-
press?:
|
|
60
|
-
exit?:
|
|
59
|
+
initial?: VariantLabels;
|
|
60
|
+
animate?: VariantLabels;
|
|
61
|
+
inView?: VariantLabels;
|
|
62
|
+
hover?: VariantLabels;
|
|
63
|
+
press?: VariantLabels;
|
|
64
|
+
exit?: VariantLabels;
|
|
61
65
|
}
|
|
62
66
|
export type AnimationFactory = () => AnimationPlaybackControls | undefined;
|
|
63
67
|
export interface CssPropertyDefinition {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function delay(fn: () => void): Promise<void>;
|