motion-v 0.13.1 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/index.js +1000 -961
  2. package/dist/es/components/index.d.ts +2 -0
  3. package/dist/es/components/lazy-motion/context.d.ts +7 -0
  4. package/dist/es/components/lazy-motion/context.mjs +6 -0
  5. package/dist/es/components/lazy-motion/index.d.ts +26 -0
  6. package/dist/es/components/lazy-motion/index.mjs +36 -0
  7. package/dist/es/components/motion/index.d.ts +179 -2
  8. package/dist/es/components/motion/index.mjs +8 -0
  9. package/dist/es/components/motion/m.d.ts +178 -0
  10. package/dist/es/components/motion/m.mjs +7 -0
  11. package/dist/es/components/motion/props.d.ts +227 -0
  12. package/dist/es/components/motion/props.mjs +93 -0
  13. package/dist/es/components/motion/{Motion.d.ts → types.d.ts} +12 -9
  14. package/dist/es/components/motion/use-motion-state.d.ts +790 -0
  15. package/dist/es/components/motion/use-motion-state.mjs +115 -0
  16. package/dist/es/components/motion/utils.d.ts +20 -5
  17. package/dist/es/components/motion/utils.mjs +122 -1
  18. package/dist/es/components/reorder/Group.vue.mjs +5 -2
  19. package/dist/es/components/reorder/Item.vue.mjs +5 -2
  20. package/dist/es/components/reorder/index.d.ts +12 -0
  21. package/dist/es/features/animation/animation.d.ts +32 -0
  22. package/dist/es/features/animation/animation.mjs +152 -5
  23. package/dist/es/features/animation/types.d.ts +17 -0
  24. package/dist/es/features/dom-animation.d.ts +2 -0
  25. package/dist/es/features/dom-animation.mjs +19 -0
  26. package/dist/es/features/dom-max.d.ts +2 -0
  27. package/dist/es/features/dom-max.mjs +23 -0
  28. package/dist/es/features/feature-manager.mjs +20 -20
  29. package/dist/es/features/gestures/drag/VisualElementDragControls.d.ts +1 -1
  30. package/dist/es/features/gestures/hover/index.d.ts +2 -0
  31. package/dist/es/features/gestures/hover/index.mjs +13 -2
  32. package/dist/es/features/gestures/in-view/index.mjs +3 -3
  33. package/dist/es/features/gestures/index.d.ts +0 -1
  34. package/dist/es/features/gestures/press/index.mjs +17 -19
  35. package/dist/es/features/index.d.ts +2 -0
  36. package/dist/es/index.d.ts +1 -0
  37. package/dist/es/index.mjs +17 -9
  38. package/dist/es/state/motion-state.d.ts +6 -5
  39. package/dist/es/state/motion-state.mjs +7 -12
  40. package/dist/es/state/style.mjs +2 -2
  41. package/dist/es/state/transform.d.ts +0 -1
  42. package/dist/es/state/transform.mjs +0 -1
  43. package/dist/es/types/state.d.ts +1 -0
  44. package/dist/nuxt/index.cjs +3 -1
  45. package/dist/nuxt/index.mjs +3 -1
  46. package/dist/resolver/index.cjs +3 -1
  47. package/dist/resolver/index.mjs +3 -1
  48. package/package.json +1 -1
  49. package/dist/es/components/motion/Motion.vue.mjs +0 -241
  50. package/dist/es/components/motion/Motion.vue2.mjs +0 -4
  51. package/dist/es/components/motion/NameSpace.d.ts +0 -15
  52. package/dist/es/components/motion/NameSpace.mjs +0 -48
  53. package/dist/es/components/motion/Primitive.d.ts +0 -57
  54. package/dist/es/components/motion/Primitive.mjs +0 -45
  55. package/dist/es/components/motion/Slot.d.ts +0 -5
  56. package/dist/es/components/motion/Slot.mjs +0 -36
  57. package/dist/es/components/motion/renderSlotFragments.mjs +0 -13
  58. package/dist/es/features/gestures/base.d.ts +0 -8
  59. package/dist/es/state/animate-updates.d.ts +0 -20
  60. package/dist/es/state/animate-updates.mjs +0 -147
  61. package/dist/es/utils/noop.d.ts +0 -1
@@ -0,0 +1,115 @@
1
+ import { injectMotion, injectLayoutGroup, provideMotion } from "../context.mjs";
2
+ import { getMotionElement } from "../hooks/use-motion-elm.mjs";
3
+ import { useLazyMotionContext } from "../lazy-motion/context.mjs";
4
+ import { checkMotionIsHidden } from "./utils.mjs";
5
+ import { injectAnimatePresence } from "../presence.mjs";
6
+ import { MotionState } from "../../state/motion-state.mjs";
7
+ import { convertSvgStyleToAttributes, createStyles } from "../../state/style.mjs";
8
+ import { warning, invariant } from "hey-listen";
9
+ import { ref, useAttrs, getCurrentInstance, onBeforeMount, onMounted, onBeforeUnmount, onUnmounted, onBeforeUpdate, onUpdated } from "vue";
10
+ import { useMotionConfig } from "../motion-config/context.mjs";
11
+ import { isMotionValue } from "../../utils/motion-value.mjs";
12
+ function useMotionState(props) {
13
+ var _a;
14
+ const parentState = injectMotion(null);
15
+ const layoutGroup = injectLayoutGroup({});
16
+ const config = useMotionConfig();
17
+ const animatePresenceContext = injectAnimatePresence({});
18
+ const lazyMotionContext = useLazyMotionContext({
19
+ features: ref([]),
20
+ strict: false
21
+ });
22
+ if (process.env.NODE_ENV !== "production" && ((_a = props.features) == null ? void 0 : _a.length) && lazyMotionContext.strict) {
23
+ const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
24
+ props.ignoreStrict ? warning(false, strictMessage) : invariant(false, strictMessage);
25
+ }
26
+ const attrs = useAttrs();
27
+ function getLayoutId() {
28
+ if (layoutGroup.id && props.layoutId)
29
+ return `${layoutGroup.id}-${props.layoutId}`;
30
+ return props.layoutId || void 0;
31
+ }
32
+ function getProps() {
33
+ return {
34
+ ...props,
35
+ lazyMotionContext,
36
+ layoutId: getLayoutId(),
37
+ transition: props.transition ?? config.value.transition,
38
+ layoutGroup,
39
+ motionConfig: config.value,
40
+ inViewOptions: props.inViewOptions ?? config.value.inViewOptions,
41
+ animatePresenceContext,
42
+ initial: animatePresenceContext.initial === false ? animatePresenceContext.initial : props.initial === true ? void 0 : props.initial
43
+ };
44
+ }
45
+ function getMotionProps() {
46
+ return {
47
+ ...attrs,
48
+ ...getProps()
49
+ };
50
+ }
51
+ const state = new MotionState(
52
+ getMotionProps(),
53
+ parentState
54
+ );
55
+ provideMotion(state);
56
+ function getAttrs() {
57
+ const isSVG = state.visualElement.type === "svg";
58
+ const attrsProps = { ...attrs };
59
+ Object.keys(attrs).forEach((key) => {
60
+ if (isMotionValue(attrs[key]))
61
+ attrsProps[key] = attrs[key].get();
62
+ });
63
+ let styleProps = {
64
+ ...props.style,
65
+ ...isSVG ? {} : state.visualElement.latestValues
66
+ };
67
+ if (isSVG) {
68
+ const { attributes, style } = convertSvgStyleToAttributes({
69
+ ...state.isMounted() ? state.target : state.baseTarget,
70
+ ...styleProps
71
+ });
72
+ Object.assign(attrsProps, attributes);
73
+ styleProps = style;
74
+ }
75
+ if (props.drag && props.dragListener !== false) {
76
+ Object.assign(styleProps, {
77
+ userSelect: "none",
78
+ WebkitUserSelect: "none",
79
+ WebkitTouchCallout: "none",
80
+ touchAction: props.drag === true ? "none" : `pan-${props.drag === "x" ? "y" : "x"}`
81
+ });
82
+ }
83
+ attrsProps.style = createStyles(styleProps);
84
+ return attrsProps;
85
+ }
86
+ const instance = getCurrentInstance().proxy;
87
+ onBeforeMount(() => {
88
+ state.beforeMount();
89
+ });
90
+ onMounted(() => {
91
+ state.mount(getMotionElement(instance.$el), getMotionProps(), checkMotionIsHidden(instance));
92
+ });
93
+ onBeforeUnmount(() => state.beforeUnmount());
94
+ onUnmounted(() => {
95
+ const el = getMotionElement(instance.$el);
96
+ if (!(el == null ? void 0 : el.isConnected)) {
97
+ state.unmount();
98
+ }
99
+ });
100
+ onBeforeUpdate(() => {
101
+ state.beforeUpdate();
102
+ });
103
+ onUpdated(() => {
104
+ state.update(getMotionProps());
105
+ });
106
+ return {
107
+ getProps,
108
+ getAttrs,
109
+ layoutGroup,
110
+ state
111
+ };
112
+ }
113
+ export {
114
+ useMotionState
115
+ };
@@ -1,7 +1,22 @@
1
- import { ComponentPublicInstance } from 'vue';
1
+ import { Component, ComponentPublicInstance, DefineComponent, IntrinsicElementAttributes } from 'vue';
2
+ import { MotionProps } from './types';
3
+ import { Feature } from '../../features';
4
+ import { ComponentProps, MotionHTMLAttributes } from '../../types';
5
+ type MotionCompProps = {
6
+ create: <T extends DefineComponent>(T: any, options?: MotionCreateOptions) => DefineComponent<Omit<MotionProps<any, unknown>, 'as' | 'asChild'> & ComponentProps<T>>;
7
+ };
8
+ export interface MotionCreateOptions {
9
+ forwardMotionProps?: boolean;
10
+ features?: Feature[];
11
+ }
12
+ export declare function checkMotionIsHidden(instance: ComponentPublicInstance): boolean;
2
13
  /**
3
- * 检查是否是隐藏的 motion 元素
4
- * @param instance
5
- * @returns
14
+ * Creates a motion component from a base component or HTML tag
15
+ * Caches string-based components for reuse
6
16
  */
7
- export declare function checkMotionIsHidden(instance: ComponentPublicInstance): boolean;
17
+ export declare function createMotionComponent(component: string | DefineComponent, options?: MotionCreateOptions): Component;
18
+ type MotionNameSpace = {
19
+ [K in keyof IntrinsicElementAttributes]: DefineComponent<Omit<MotionProps<K, unknown>, 'as' | 'asChild'> & MotionHTMLAttributes<K>, 'create'>;
20
+ } & MotionCompProps;
21
+ export declare function createMotionComponentWithFeatures(features?: Feature[]): MotionNameSpace;
22
+ export {};
@@ -1,10 +1,131 @@
1
1
  import { getMotionElement } from "../hooks/use-motion-elm.mjs";
2
+ import { defineComponent, h, Comment, mergeProps, cloneVNode } from "vue";
3
+ import { useMotionState } from "./use-motion-state.mjs";
4
+ import { MotionComponentProps } from "./props.mjs";
2
5
  function checkMotionIsHidden(instance) {
3
6
  var _a;
4
7
  const isHidden = ((_a = getMotionElement(instance.$el)) == null ? void 0 : _a.style.display) === "none";
5
8
  const hasTransition = instance.$.vnode.transition;
6
9
  return hasTransition && isHidden;
7
10
  }
11
+ const componentMaxCache = /* @__PURE__ */ new Map();
12
+ const componentMiniCache = /* @__PURE__ */ new Map();
13
+ function renderSlotFragments(fragments) {
14
+ if (!Array.isArray(fragments))
15
+ return [fragments];
16
+ const result = [];
17
+ for (const item of fragments) {
18
+ if (Array.isArray(item))
19
+ result.push(...item);
20
+ else
21
+ result.push(item);
22
+ }
23
+ return result;
24
+ }
25
+ const SELF_CLOSING_TAGS = ["area", "img", "input"];
26
+ function handlePrimitiveAndSlot(asTag, allAttrs, slots) {
27
+ var _a, _b;
28
+ if (typeof asTag === "string" && SELF_CLOSING_TAGS.includes(asTag)) {
29
+ return h(asTag, allAttrs);
30
+ }
31
+ if (asTag === "template") {
32
+ if (!slots.default)
33
+ return null;
34
+ const childrens = renderSlotFragments(slots.default());
35
+ const firstNonCommentChildrenIndex = childrens.findIndex((child) => child.type !== Comment);
36
+ if (firstNonCommentChildrenIndex === -1)
37
+ return childrens;
38
+ const firstNonCommentChildren = childrens[firstNonCommentChildrenIndex];
39
+ (_a = firstNonCommentChildren.props) == null ? true : delete _a.ref;
40
+ const mergedProps = firstNonCommentChildren.props ? mergeProps(allAttrs, firstNonCommentChildren.props) : allAttrs;
41
+ if (allAttrs.class && ((_b = firstNonCommentChildren.props) == null ? void 0 : _b.class))
42
+ delete firstNonCommentChildren.props.class;
43
+ const cloned = cloneVNode(firstNonCommentChildren, mergedProps);
44
+ for (const prop in mergedProps) {
45
+ if (prop.startsWith("on")) {
46
+ cloned.props || (cloned.props = {});
47
+ cloned.props[prop] = mergedProps[prop];
48
+ }
49
+ }
50
+ if (childrens.length === 1)
51
+ return cloned;
52
+ childrens[firstNonCommentChildrenIndex] = cloned;
53
+ return childrens;
54
+ }
55
+ return null;
56
+ }
57
+ function createMotionComponent(component, options = {}) {
58
+ var _a;
59
+ const isString = typeof component === "string";
60
+ const name = isString ? component : component.name || "";
61
+ const componentCache = ((_a = options.features) == null ? void 0 : _a.length) > 0 ? componentMaxCache : componentMiniCache;
62
+ if (isString && (componentCache == null ? void 0 : componentCache.has(component))) {
63
+ return componentCache.get(component);
64
+ }
65
+ const motionComponent = defineComponent({
66
+ inheritAttrs: false,
67
+ props: {
68
+ ...MotionComponentProps,
69
+ features: {
70
+ type: Object,
71
+ default: () => options.features || []
72
+ },
73
+ as: { type: [String, Object], default: component || "div" }
74
+ },
75
+ name: name ? `motion.${name}` : "Motion",
76
+ setup(props, { slots }) {
77
+ const { getProps, getAttrs, state } = useMotionState(props);
78
+ function onVnodeUpdated() {
79
+ const el = state.element;
80
+ const isComponent = typeof props.as === "object";
81
+ if ((!isComponent || props.asChild) && el) {
82
+ const { style } = getAttrs();
83
+ for (const [key, val] of Object.entries(style)) {
84
+ el.style[key] = val;
85
+ }
86
+ }
87
+ }
88
+ return () => {
89
+ const motionProps = getProps();
90
+ const motionAttrs = getAttrs();
91
+ const asTag = props.asChild ? "template" : props.as;
92
+ const allAttrs = {
93
+ ...options.forwardMotionProps || props.forwardMotionProps ? motionProps : {},
94
+ ...motionAttrs,
95
+ onVnodeUpdated
96
+ };
97
+ const primitiveOrSlotResult = handlePrimitiveAndSlot(asTag, allAttrs, slots);
98
+ if (primitiveOrSlotResult !== null) {
99
+ return primitiveOrSlotResult;
100
+ }
101
+ return h(asTag, {
102
+ ...allAttrs
103
+ }, slots);
104
+ };
105
+ }
106
+ });
107
+ if (isString) {
108
+ componentCache == null ? void 0 : componentCache.set(component, motionComponent);
109
+ }
110
+ return motionComponent;
111
+ }
112
+ function createMotionComponentWithFeatures(features = []) {
113
+ return new Proxy({}, {
114
+ get(target, prop) {
115
+ if (prop === "create") {
116
+ return (component, options) => createMotionComponent(component, {
117
+ ...options,
118
+ features
119
+ });
120
+ }
121
+ return createMotionComponent(prop, {
122
+ features
123
+ });
124
+ }
125
+ });
126
+ }
8
127
  export {
9
- checkMotionIsHidden
128
+ checkMotionIsHidden,
129
+ createMotionComponent,
130
+ createMotionComponentWithFeatures
10
131
  };
@@ -1,8 +1,8 @@
1
1
  import { defineComponent, toRefs, onUpdated, useAttrs, openBlock, createBlock, unref, normalizeProps, guardReactiveProps, withCtx, renderSlot, createTextVNode, toDisplayString } from "vue";
2
+ import { Motion } from "../motion/index.mjs";
2
3
  import { invariant } from "hey-listen";
3
4
  import { reorderContextProvider } from "./context.mjs";
4
5
  import { compareMin, checkReorder, getValue } from "./utils.mjs";
5
- import _sfc_main$1 from "../motion/Motion.vue.mjs";
6
6
  const _sfc_main = /* @__PURE__ */ defineComponent({
7
7
  ...{
8
8
  name: "ReorderGroup",
@@ -25,6 +25,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25
25
  whileInView: {},
26
26
  whileFocus: {},
27
27
  forwardMotionProps: { type: Boolean },
28
+ features: {},
29
+ ignoreStrict: { type: Boolean },
28
30
  custom: {},
29
31
  initial: { type: [String, Array, Object, Boolean] },
30
32
  animate: {},
@@ -38,6 +40,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
38
40
  motionConfig: {},
39
41
  onAnimationComplete: {},
40
42
  onUpdate: {},
43
+ onAnimationStart: {},
41
44
  layout: { type: [Boolean, String] },
42
45
  layoutId: {},
43
46
  layoutScroll: { type: Boolean },
@@ -126,7 +129,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
126
129
  };
127
130
  }
128
131
  return (_ctx, _cache) => {
129
- return openBlock(), createBlock(unref(_sfc_main$1), normalizeProps(guardReactiveProps(bindProps())), {
132
+ return openBlock(), createBlock(unref(Motion), normalizeProps(guardReactiveProps(bindProps())), {
130
133
  default: withCtx(() => [
131
134
  renderSlot(_ctx.$slots, "default"),
132
135
  createTextVNode(" " + toDisplayString(warning()), 1)
@@ -1,9 +1,9 @@
1
1
  import { defineComponent, toRefs, useAttrs, computed, ref, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString } from "vue";
2
+ import { Motion } from "../motion/index.mjs";
2
3
  import { useReorderContext } from "./context.mjs";
3
4
  import { useDefaultMotionValue } from "./utils.mjs";
4
5
  import { invariant } from "hey-listen";
5
6
  import { useTransform } from "../../value/use-transform.mjs";
6
- import _sfc_main$1 from "../motion/Motion.vue.mjs";
7
7
  const _sfc_main = /* @__PURE__ */ defineComponent({
8
8
  ...{
9
9
  name: "ReorderItem",
@@ -25,6 +25,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25
25
  whileInView: {},
26
26
  whileFocus: {},
27
27
  forwardMotionProps: { type: Boolean },
28
+ features: {},
29
+ ignoreStrict: { type: Boolean },
28
30
  custom: {},
29
31
  initial: { type: [String, Array, Object, Boolean], default: void 0 },
30
32
  animate: { default: void 0 },
@@ -38,6 +40,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
38
40
  motionConfig: {},
39
41
  onAnimationComplete: {},
40
42
  onUpdate: {},
43
+ onAnimationStart: {},
41
44
  layoutId: { default: void 0 },
42
45
  layoutScroll: { type: Boolean, default: false },
43
46
  layoutRoot: { type: Boolean, default: false },
@@ -116,7 +119,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
116
119
  });
117
120
  const isDragging = ref(false);
118
121
  return (_ctx, _cache) => {
119
- return openBlock(), createBlock(unref(_sfc_main$1), mergeProps(bindProps(), {
122
+ return openBlock(), createBlock(unref(Motion), mergeProps(bindProps(), {
120
123
  drag: drag.value,
121
124
  "drag-snap-to-origin": true,
122
125
  onDrag: _cache[0] || (_cache[0] = (event, gesturePoint) => {
@@ -21,6 +21,8 @@ export declare const ReorderGroup: <T, K, V>(__VLS_props: NonNullable<Awaited<ty
21
21
  whileInView?: import('../..').Options["whileInView"];
22
22
  whileFocus?: import('../..').Options["whileFocus"];
23
23
  forwardMotionProps?: boolean;
24
+ features?: import('../../features').Feature[];
25
+ ignoreStrict?: boolean;
24
26
  custom?: K;
25
27
  initial?: import('../..').VariantLabels | import('../..').Variant | boolean;
26
28
  animate?: import('../..').VariantLabels | import('../..').Variant | import('../../animation/types').AnimationControls;
@@ -739,6 +741,7 @@ export declare const ReorderGroup: <T, K, V>(__VLS_props: NonNullable<Awaited<ty
739
741
  motionConfig?: import('../motion-config/types').MotionConfigState;
740
742
  onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
741
743
  onUpdate?: (latest: import('framer-motion').ResolvedValues) => void;
744
+ onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
742
745
  layout?: boolean | "position" | "size" | "preserve-aspect";
743
746
  layoutId?: string;
744
747
  layoutScroll?: boolean;
@@ -819,6 +822,8 @@ export declare const ReorderItem: <T extends import('../..').ElementType = "li",
819
822
  whileInView?: import('../..').Options["whileInView"];
820
823
  whileFocus?: import('../..').Options["whileFocus"];
821
824
  forwardMotionProps?: boolean;
825
+ features?: import('../../features').Feature[];
826
+ ignoreStrict?: boolean;
822
827
  custom?: unknown;
823
828
  initial?: import('../..').VariantLabels | import('../..').Variant | boolean;
824
829
  animate?: import('../..').VariantLabels | import('../..').Variant | import('../../animation/types').AnimationControls;
@@ -1537,6 +1542,7 @@ export declare const ReorderItem: <T extends import('../..').ElementType = "li",
1537
1542
  motionConfig?: import('../motion-config/types').MotionConfigState;
1538
1543
  onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
1539
1544
  onUpdate?: (latest: import('framer-motion').ResolvedValues) => void;
1545
+ onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
1540
1546
  layoutId?: string;
1541
1547
  layoutScroll?: boolean;
1542
1548
  layoutRoot?: boolean;
@@ -1618,6 +1624,8 @@ export declare const Reorder: {
1618
1624
  whileInView?: import('../..').Options["whileInView"];
1619
1625
  whileFocus?: import('../..').Options["whileFocus"];
1620
1626
  forwardMotionProps?: boolean;
1627
+ features?: import('../../features').Feature[];
1628
+ ignoreStrict?: boolean;
1621
1629
  custom?: K;
1622
1630
  initial?: import('../..').VariantLabels | import('../..').Variant | boolean;
1623
1631
  animate?: import('../..').VariantLabels | import('../..').Variant | import('../../animation/types').AnimationControls;
@@ -2336,6 +2344,7 @@ export declare const Reorder: {
2336
2344
  motionConfig?: import('../motion-config/types').MotionConfigState;
2337
2345
  onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
2338
2346
  onUpdate?: (latest: import('framer-motion').ResolvedValues) => void;
2347
+ onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
2339
2348
  layout?: boolean | "position" | "size" | "preserve-aspect";
2340
2349
  layoutId?: string;
2341
2350
  layoutScroll?: boolean;
@@ -2416,6 +2425,8 @@ export declare const Reorder: {
2416
2425
  whileInView?: import('../..').Options["whileInView"];
2417
2426
  whileFocus?: import('../..').Options["whileFocus"];
2418
2427
  forwardMotionProps?: boolean;
2428
+ features?: import('../../features').Feature[];
2429
+ ignoreStrict?: boolean;
2419
2430
  custom?: unknown;
2420
2431
  initial?: import('../..').VariantLabels | import('../..').Variant | boolean;
2421
2432
  animate?: import('../..').VariantLabels | import('../..').Variant | import('../../animation/types').AnimationControls;
@@ -3134,6 +3145,7 @@ export declare const Reorder: {
3134
3145
  motionConfig?: import('../motion-config/types').MotionConfigState;
3135
3146
  onAnimationComplete?: (definition: import('../..').Options["animate"]) => void;
3136
3147
  onUpdate?: (latest: import('framer-motion').ResolvedValues) => void;
3148
+ onAnimationStart?: (definition: import('../..').Options["animate"]) => void;
3137
3149
  layoutId?: string;
3138
3150
  layoutScroll?: boolean;
3139
3151
  layoutRoot?: boolean;
@@ -1,9 +1,40 @@
1
+ import { AnimateUpdates } from './types';
1
2
  import { Feature } from '../feature';
2
3
  import { MotionState } from '../../state';
4
+ import { $Transition, AnimationFactory, Options } from '../../types';
5
+ declare const STATE_TYPES: readonly ["initial", "animate", "whileInView", "whileHover", "whilePress", "whileDrag", "whileFocus", "exit"];
6
+ export type StateType = typeof STATE_TYPES[number];
3
7
  export declare class AnimationFeature extends Feature {
4
8
  unmountControls?: () => void;
5
9
  constructor(state: MotionState);
6
10
  updateAnimationControlsSubscription(): void;
11
+ animateUpdates: AnimateUpdates;
12
+ executeAnimations({ factories, getChildAnimations, transition, controlActiveState, isExit, }: {
13
+ factories: AnimationFactory[];
14
+ getChildAnimations: () => Promise<any>;
15
+ childAnimations: (() => Promise<any>)[];
16
+ transition: $Transition | undefined;
17
+ controlActiveState: Partial<Record<string, boolean>> | undefined;
18
+ isExit: boolean;
19
+ }): Promise<any> | (() => Promise<any>);
20
+ /**
21
+ * Setup child animations
22
+ */
23
+ setupChildAnimations(transition: $Transition | undefined, controlActiveState: Partial<Record<string, boolean>> | undefined, isFallback: boolean): {
24
+ getChildAnimations: () => Promise<void>;
25
+ childAnimations: any[];
26
+ } | {
27
+ getChildAnimations: () => Promise<any[]>;
28
+ childAnimations: (() => Promise<any>)[];
29
+ };
30
+ createAnimationFactories(prevTarget: Record<string, any>, animationOptions: $Transition, controlDelay: number): AnimationFactory[];
31
+ resolveStateAnimation({ controlActiveState, directAnimate, directTransition, }: {
32
+ controlActiveState: Partial<Record<string, boolean>> | undefined;
33
+ directAnimate: Options['animate'];
34
+ directTransition: $Transition | undefined;
35
+ }): $Transition & {
36
+ layout?: $Transition;
37
+ };
7
38
  /**
8
39
  * Subscribe any provided AnimationControls to the component's VisualElement
9
40
  */
@@ -11,3 +42,4 @@ export declare class AnimationFeature extends Feature {
11
42
  update(): void;
12
43
  unmount(): void;
13
44
  }
45
+ export {};
@@ -1,15 +1,162 @@
1
1
  import { isAnimationControls } from "../../animation/utils.mjs";
2
2
  import { Feature } from "../feature.mjs";
3
+ import { motionEvent } from "../../state/event.mjs";
4
+ import { style } from "../../state/style.mjs";
5
+ import { transformResetValue } from "../../state/transform.mjs";
6
+ import { hasChanged, resolveVariant } from "../../state/utils.mjs";
7
+ import { isDef } from "@vueuse/core";
8
+ import { animate } from "../../external/.pnpm/framer-motion@12.5.0/external/framer-motion/dist/es/animation/animate/index.mjs";
9
+ import { noop } from "../../external/.pnpm/motion-utils@12.5.0/external/motion-utils/dist/es/noop.mjs";
10
+ import "../../external/.pnpm/motion-utils@12.5.0/external/motion-utils/dist/es/errors.mjs";
11
+ const STATE_TYPES = ["initial", "animate", "whileInView", "whileHover", "whilePress", "whileDrag", "whileFocus", "exit"];
3
12
  class AnimationFeature extends Feature {
4
13
  constructor(state) {
5
14
  super(state);
15
+ this.animateUpdates = ({
16
+ controlActiveState,
17
+ directAnimate,
18
+ directTransition,
19
+ controlDelay = 0,
20
+ isFallback,
21
+ isExit
22
+ } = {}) => {
23
+ const prevTarget = this.state.target;
24
+ this.state.target = { ...this.state.baseTarget };
25
+ let animationOptions = {};
26
+ const transition = { ...this.state.options.transition };
27
+ animationOptions = this.resolveStateAnimation({
28
+ controlActiveState,
29
+ directAnimate,
30
+ directTransition
31
+ });
32
+ const factories = this.createAnimationFactories(prevTarget, animationOptions, controlDelay);
33
+ const { getChildAnimations, childAnimations } = this.setupChildAnimations(animationOptions, controlActiveState, isFallback);
34
+ return this.executeAnimations({
35
+ factories,
36
+ getChildAnimations,
37
+ childAnimations,
38
+ transition,
39
+ controlActiveState,
40
+ isExit
41
+ });
42
+ };
43
+ this.state.animateUpdates = this.animateUpdates;
6
44
  }
7
45
  updateAnimationControlsSubscription() {
8
- const { animate } = this.state.options;
9
- if (isAnimationControls(animate)) {
10
- this.unmountControls = animate.subscribe(this.state);
46
+ const { animate: animate2 } = this.state.options;
47
+ if (isAnimationControls(animate2)) {
48
+ this.unmountControls = animate2.subscribe(this.state);
11
49
  }
12
50
  }
51
+ executeAnimations({
52
+ factories,
53
+ getChildAnimations,
54
+ transition,
55
+ controlActiveState,
56
+ isExit = false
57
+ }) {
58
+ const getAnimation = () => Promise.all(factories.map((factory) => factory()).filter(Boolean));
59
+ const animationTarget = { ...this.state.target };
60
+ const element = this.state.element;
61
+ const finishAnimation = (animationPromise) => {
62
+ var _a, _b;
63
+ element.dispatchEvent(motionEvent("motionstart", animationTarget));
64
+ (_b = (_a = this.state.options).onAnimationStart) == null ? void 0 : _b.call(_a, animationTarget);
65
+ animationPromise.then(() => {
66
+ var _a2, _b2;
67
+ element.dispatchEvent(motionEvent("motioncomplete", animationTarget, isExit));
68
+ (_b2 = (_a2 = this.state.options).onAnimationComplete) == null ? void 0 : _b2.call(_a2, animationTarget);
69
+ }).catch(noop);
70
+ };
71
+ const getAnimationPromise = () => {
72
+ const animationPromise = (transition == null ? void 0 : transition.when) ? (transition.when === "beforeChildren" ? getAnimation() : getChildAnimations()).then(() => transition.when === "beforeChildren" ? getChildAnimations() : getAnimation()) : Promise.all([getAnimation(), getChildAnimations()]);
73
+ finishAnimation(animationPromise);
74
+ return animationPromise;
75
+ };
76
+ return controlActiveState ? getAnimationPromise : getAnimationPromise();
77
+ }
78
+ /**
79
+ * Setup child animations
80
+ */
81
+ setupChildAnimations(transition, controlActiveState, isFallback) {
82
+ var _a;
83
+ if (!((_a = this.state.visualElement.variantChildren) == null ? void 0 : _a.size) || !controlActiveState)
84
+ return { getChildAnimations: () => Promise.resolve(), childAnimations: [] };
85
+ const { staggerChildren = 0, staggerDirection = 1, delayChildren = 0 } = transition || {};
86
+ const maxStaggerDuration = (this.state.visualElement.variantChildren.size - 1) * staggerChildren;
87
+ const generateStaggerDuration = staggerDirection === 1 ? (i = 0) => i * staggerChildren : (i = 0) => maxStaggerDuration - i * staggerChildren;
88
+ const childAnimations = Array.from(this.state.visualElement.variantChildren).map((child, index) => {
89
+ const childDelay = delayChildren + generateStaggerDuration(index);
90
+ return child.state.animateUpdates({
91
+ controlActiveState,
92
+ controlDelay: isFallback ? 0 : childDelay
93
+ });
94
+ }).filter(Boolean);
95
+ return {
96
+ getChildAnimations: () => Promise.all(childAnimations.map((animation) => {
97
+ return animation == null ? void 0 : animation();
98
+ })),
99
+ childAnimations
100
+ };
101
+ }
102
+ createAnimationFactories(prevTarget, animationOptions, controlDelay) {
103
+ const factories = [];
104
+ Object.keys(this.state.target).forEach((key) => {
105
+ var _a;
106
+ if (!hasChanged(prevTarget[key], this.state.target[key]))
107
+ return;
108
+ (_a = this.state.baseTarget)[key] ?? (_a[key] = style.get(this.state.element, key));
109
+ const keyValue = this.state.target[key] === "none" && isDef(transformResetValue[key]) ? transformResetValue[key] : this.state.target[key];
110
+ factories.push(() => {
111
+ var _a2;
112
+ return animate(
113
+ this.state.element,
114
+ { [key]: keyValue },
115
+ {
116
+ ...(animationOptions == null ? void 0 : animationOptions[key]) || animationOptions,
117
+ delay: (((_a2 = animationOptions == null ? void 0 : animationOptions[key]) == null ? void 0 : _a2.delay) || (animationOptions == null ? void 0 : animationOptions.delay) || 0) + controlDelay
118
+ }
119
+ );
120
+ });
121
+ });
122
+ return factories;
123
+ }
124
+ resolveStateAnimation({
125
+ controlActiveState,
126
+ directAnimate,
127
+ directTransition
128
+ }) {
129
+ let variantTransition = this.state.options.transition;
130
+ let variant = {};
131
+ const { variants, custom, transition, animatePresenceContext } = this.state.options;
132
+ const customValue = isDef(custom) ? custom : animatePresenceContext == null ? void 0 : animatePresenceContext.custom;
133
+ this.state.activeStates = { ...this.state.activeStates, ...controlActiveState };
134
+ STATE_TYPES.forEach((name) => {
135
+ if (!this.state.activeStates[name] || isAnimationControls(this.state.options[name]))
136
+ return;
137
+ const definition = this.state.options[name];
138
+ let resolvedVariant = isDef(definition) ? resolveVariant(definition, variants, customValue) : void 0;
139
+ if (this.state.visualElement.isVariantNode) {
140
+ const controlVariant = resolveVariant(this.state.context[name], variants, customValue);
141
+ resolvedVariant = controlVariant ? Object.assign(controlVariant || {}, resolvedVariant) : variant;
142
+ }
143
+ if (!resolvedVariant)
144
+ return;
145
+ if (name !== "initial")
146
+ variantTransition = resolvedVariant.transition || this.state.options.transition || {};
147
+ variant = Object.assign(variant, resolvedVariant);
148
+ });
149
+ if (directAnimate) {
150
+ variant = resolveVariant(directAnimate, variants, customValue);
151
+ variantTransition = variant.transition || directTransition || transition;
152
+ }
153
+ Object.entries(variant).forEach(([key, value]) => {
154
+ if (key === "transition")
155
+ return;
156
+ this.state.target[key] = value;
157
+ });
158
+ return variantTransition;
159
+ }
13
160
  /**
14
161
  * Subscribe any provided AnimationControls to the component's VisualElement
15
162
  */
@@ -17,9 +164,9 @@ class AnimationFeature extends Feature {
17
164
  this.updateAnimationControlsSubscription();
18
165
  }
19
166
  update() {
20
- const { animate } = this.state.options;
167
+ const { animate: animate2 } = this.state.options;
21
168
  const { animate: prevAnimate } = this.state.visualElement.prevProps || {};
22
- if (animate !== prevAnimate) {
169
+ if (animate2 !== prevAnimate) {
23
170
  this.updateAnimationControlsSubscription();
24
171
  }
25
172
  }
@@ -0,0 +1,17 @@
1
+ import { $Transition, Options } from '../../types';
2
+ /**
3
+ * Core animation update function that handles all animation state changes and execution
4
+ * @param controlActiveState - Animation states that need to be updated
5
+ * @param controlDelay - Animation delay time
6
+ * @param directAnimate - Direct animation target value
7
+ * @param directTransition - Direct animation transition config
8
+ */
9
+ export interface AnimateUpdatesOptions {
10
+ controlActiveState?: Partial<Record<string, boolean>>;
11
+ controlDelay?: number;
12
+ directAnimate?: Options['animate'];
13
+ directTransition?: $Transition;
14
+ isFallback?: boolean;
15
+ isExit?: boolean;
16
+ }
17
+ export type AnimateUpdates = (options?: AnimateUpdatesOptions) => Promise<any> | (() => Promise<any>);
@@ -0,0 +1,2 @@
1
+ import { Feature } from './feature';
2
+ export declare const domAnimation: Feature[];