motion-v 0.5.2-beta.1 → 0.6.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 (34) hide show
  1. package/dist/cjs/index.js +205 -147
  2. package/dist/es/components/LayoutGroup.vue.mjs +1 -3
  3. package/dist/es/components/Motion.vue.mjs +35 -30
  4. package/dist/es/components/{AnimatePresence.vue.mjs → animate-presence/AnimatePresence.vue.mjs} +37 -14
  5. package/dist/es/components/{use-pop-layout.mjs → animate-presence/use-pop-layout.mjs} +1 -1
  6. package/dist/es/components/group.mjs +5 -2
  7. package/dist/es/components/presence.mjs +0 -2
  8. package/dist/es/components/utils.mjs +7 -0
  9. package/dist/es/constants/index.mjs +2 -1
  10. package/dist/es/features/layout/layout.mjs +17 -8
  11. package/dist/es/features/layout/projection.mjs +17 -1
  12. package/dist/es/index.mjs +4 -4
  13. package/dist/es/state/animate-variants-children.mjs +5 -3
  14. package/dist/es/state/motion-state.mjs +49 -22
  15. package/dist/es/state/schedule.mjs +2 -26
  16. package/dist/es/state/utils.mjs +0 -9
  17. package/dist/src/components/{AnimatePresence.d.ts → animate-presence/AnimatePresence.d.ts} +1 -1
  18. package/dist/src/components/animate-presence/index.d.ts +2 -0
  19. package/dist/src/components/{type.d.ts → animate-presence/types.d.ts} +2 -0
  20. package/dist/src/components/{use-pop-layout.d.ts → animate-presence/use-pop-layout.d.ts} +2 -2
  21. package/dist/src/components/animate-presence/use-presence.d.ts +2 -0
  22. package/dist/src/components/context.d.ts +1 -0
  23. package/dist/src/components/group.d.ts +1 -0
  24. package/dist/src/components/hooks/use-motion-elm.d.ts +13 -0
  25. package/dist/src/components/index.d.ts +2 -0
  26. package/dist/src/components/presence.d.ts +3 -5
  27. package/dist/src/components/utils.d.ts +7 -0
  28. package/dist/src/index.d.ts +1 -3
  29. package/dist/src/state/animate-variants-children.d.ts +1 -1
  30. package/dist/src/state/event.d.ts +1 -1
  31. package/dist/src/state/motion-state.d.ts +10 -7
  32. package/dist/src/types/state.d.ts +6 -2
  33. package/package.json +3 -2
  34. /package/dist/es/components/{AnimatePresence.vue2.mjs → animate-presence/AnimatePresence.vue2.mjs} +0 -0
@@ -3,4 +3,6 @@ export interface AnimatePresenceProps {
3
3
  initial?: boolean;
4
4
  multiple?: boolean;
5
5
  as?: string;
6
+ custom?: any;
7
+ onExitComplete?: VoidFunction;
6
8
  }
@@ -1,5 +1,5 @@
1
- import { AnimatePresenceProps } from './type';
2
- import { MotionState } from '../state';
1
+ import { AnimatePresenceProps } from './types';
2
+ import { MotionState } from '../../state';
3
3
  export declare function usePopLayout(props: AnimatePresenceProps): {
4
4
  addPopStyle: (state: MotionState) => void;
5
5
  removePopStyle: (state: MotionState) => void;
@@ -0,0 +1,2 @@
1
+ export declare const presenceMeasure: Map<HTMLElement, boolean>;
2
+ export declare function usePresence(): void;
@@ -6,6 +6,7 @@ export interface NodeGroup {
6
6
  add: (node: IProjectionNode) => void;
7
7
  remove: (node: IProjectionNode) => void;
8
8
  dirty: VoidFunction;
9
+ didUpdate: VoidFunction;
9
10
  }
10
11
  export interface LayoutGroupState {
11
12
  id?: string;
@@ -3,5 +3,6 @@ export interface NodeGroup {
3
3
  add: (node: IProjectionNode) => void;
4
4
  remove: (node: IProjectionNode) => void;
5
5
  dirty: VoidFunction;
6
+ didUpdate: VoidFunction;
6
7
  }
7
8
  export declare function nodeGroup(): NodeGroup;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get the actual motion element, skipping text and comment nodes
3
+ * @param el - The HTML element to check
4
+ * @returns The first non-text/comment element
5
+ */
6
+ export declare function getMotionElement(el: HTMLElement): HTMLElement;
7
+ /**
8
+ * Hook to get the motion element of current component instance
9
+ * @returns Function that returns the motion element
10
+ */
11
+ export declare function useMotionElm(): {
12
+ value: HTMLElement | null;
13
+ };
@@ -0,0 +1,2 @@
1
+ export * from './animate-presence';
2
+ export * from './motion-config';
@@ -1,9 +1,7 @@
1
- import { Ref } from 'vue';
2
- export declare const doneCallbacks: WeakMap<Element, VoidFunction>;
3
- export declare const unPresenceDom: Ref<WeakMap<Element, boolean> & Omit<WeakMap<Element, boolean>, keyof WeakMap<any, any>>>;
1
+ export declare const doneCallbacks: WeakMap<Element, (v?: any, safeUnmount?: boolean) => void>;
4
2
  export declare function removeDoneCallback(element: Element): void;
5
3
  export interface PresenceContext {
6
- initial: Ref<boolean>;
7
- safeUnmount: (el: Element) => boolean;
4
+ initial?: boolean;
5
+ custom?: any;
8
6
  }
9
7
  export declare const injectAnimatePresence: <T extends PresenceContext = PresenceContext>(fallback?: T) => T extends null ? PresenceContext : PresenceContext, provideAnimatePresence: (contextValue: PresenceContext) => PresenceContext;
@@ -1 +1,8 @@
1
+ import { ComponentPublicInstance } from 'vue';
1
2
  export declare function getMotionElement(el: HTMLElement): HTMLElement;
3
+ /**
4
+ * 检查是否是隐藏的 motion 元素
5
+ * @param instance
6
+ * @returns
7
+ */
8
+ export declare function checkMotionIsHidden(instance: ComponentPublicInstance): boolean;
@@ -1,12 +1,10 @@
1
1
  export * from 'framer-motion/dom';
2
2
  export { motionValue as useMotionValue } from 'framer-motion/dom';
3
3
  export { default as Motion, type MotionProps } from './components/Motion';
4
- export { default as AnimatePresence } from './components/AnimatePresence';
5
- export type { AnimatePresenceProps } from './components/type';
4
+ export * from './components';
6
5
  export { default as LayoutGroup } from './components/LayoutGroup';
7
6
  export { useLayoutGroup } from './components/use-layout-group';
8
7
  export type { LayoutGroupProps } from './components/use-layout-group';
9
- export * from './components/motion-config';
10
8
  export * from './components/context';
11
9
  export * from './value';
12
10
  export * from './constants';
@@ -6,7 +6,7 @@ export type ActiveVariant = {
6
6
  transition: AnimateOptions;
7
7
  };
8
8
  };
9
- export declare function animateVariantsChildren(state: MotionState, activeState: ActiveVariant): {
9
+ export declare function animateVariantsChildren(state: MotionState, activeState: ActiveVariant, isFirstAnimate?: boolean): {
10
10
  animations: any[];
11
11
  getAnimations: () => Promise<void>;
12
12
  } | {
@@ -1,5 +1,5 @@
1
1
  import { Variant } from '../types';
2
- export type MotionEventNames = 'motionstart' | 'motioncomplete' | 'hoverstart' | 'hoverend' | 'pressstart' | 'pressend' | 'viewenter' | 'viewleave';
2
+ export type MotionEventNames = 'motionstart' | 'motioncomplete';
3
3
  export declare function motionEvent(name: MotionEventNames, target: Variant, isExit?: boolean): CustomEvent<{
4
4
  target: Variant;
5
5
  isExit: boolean;
@@ -2,13 +2,15 @@ import { MotionStateContext, Options } from '../types';
2
2
  import { DOMKeyframesDefinition, VisualElement } from 'framer-motion';
3
3
  declare const STATE_TYPES: readonly ["initial", "animate", "inView", "hover", "press", "whileDrag", "exit"];
4
4
  type StateType = typeof STATE_TYPES[number];
5
- export declare const mountedStates: WeakMap<Element, MotionState>;
5
+ export declare const mountedStates: Map<string | Element, MotionState>;
6
6
  export declare class MotionState {
7
7
  readonly id: string;
8
8
  element: HTMLElement | null;
9
9
  private parent?;
10
10
  options: Options;
11
- private isFirstAnimate;
11
+ isSafeToRemove: boolean;
12
+ isFirstAnimate: boolean;
13
+ private children?;
12
14
  activeStates: Partial<Record<StateType, boolean>>;
13
15
  depth: number;
14
16
  baseTarget: DOMKeyframesDefinition;
@@ -22,14 +24,15 @@ export declare class MotionState {
22
24
  get initial(): string | boolean | import('../types').Variant;
23
25
  updateOptions(): void;
24
26
  beforeMount(): void;
25
- mount(element: HTMLElement, options: Options): void;
27
+ mount(element: HTMLElement, options: Options, notAnimate?: boolean): void;
26
28
  beforeUnmount(): void;
27
- unmount(): void;
29
+ unmount(unMountChildren?: boolean): void;
28
30
  beforeUpdate(): void;
29
- update(options: Options): void;
30
- setActive(name: StateType, isActive: boolean): void;
31
- animateUpdates(): Generator<any, void, unknown>;
31
+ update(options: Options, notAnimate?: boolean): void;
32
+ setActive(name: StateType, isActive: boolean, isAnimate?: boolean): void;
33
+ animateUpdates(isInitial?: boolean): void;
32
34
  isMounted(): boolean;
33
35
  getOptions(): Options<any>;
36
+ willUpdate(label: string): void;
34
37
  }
35
38
  export {};
@@ -1,4 +1,4 @@
1
- import { DOMKeyframesDefinition, DynamicAnimationOptions, Target, TargetAndTransition } from 'framer-motion';
1
+ import { DOMKeyframesDefinition, DynamicAnimationOptions, ResolvedValues, Target, TargetAndTransition } from 'framer-motion';
2
2
  import { MotionValue, animate } from 'framer-motion/dom';
3
3
  import { IntrinsicElementAttributes } from 'vue';
4
4
  import { TransformProperties } from './transform';
@@ -50,9 +50,13 @@ export interface Options<T = any> extends LayoutOptions, PressProps, HoverProps,
50
50
  };
51
51
  style?: MotionStyle;
52
52
  transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
53
- transition?: AnimateOptions;
53
+ transition?: AnimateOptions & {
54
+ layout?: DynamicAnimationOptions;
55
+ };
54
56
  layoutGroup?: LayoutGroupState;
55
57
  motionConfig?: MotionConfigState;
58
+ onAnimationComplete?: (definition: AnimateOptions) => void;
59
+ onUpdate?: (latest: ResolvedValues) => void;
56
60
  }
57
61
  export interface MotionStateContext {
58
62
  initial?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-v",
3
- "version": "0.5.2-beta.1",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -63,6 +63,7 @@
63
63
  "@vitest/coverage-v8": "^1.4.0",
64
64
  "@vue/test-utils": "^2.4.5",
65
65
  "framer-motion": "^11.15.0",
66
+ "happy-dom": "^16.0.1",
66
67
  "jsdom": "^24.0.0",
67
68
  "vite": "^5.4.8",
68
69
  "vite-plugin-dts": "^4.2.4",
@@ -71,7 +72,7 @@
71
72
  "scripts": {
72
73
  "dev": "vite build --watch",
73
74
  "build": "rm -rf dist && vite build",
74
- "test": "vitest",
75
+ "test": "vitest --dom",
75
76
  "coverage": "vitest run --coverage",
76
77
  "pub:release": "pnpm publish --access public"
77
78
  }