framer-motion 10.2.2 → 10.2.4

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 (36) hide show
  1. package/dist/cjs/dom-entry.js +1 -1
  2. package/dist/cjs/index.js +18 -20
  3. package/dist/cjs/{wrap-b7ab39cb.js → wrap-62da7859.js} +456 -438
  4. package/dist/dom-entry.d.ts +497 -49
  5. package/dist/es/animation/GroupPlaybackControls.mjs +25 -0
  6. package/dist/es/animation/animate.mjs +2 -4
  7. package/dist/es/animation/create-instant-animation.mjs +13 -3
  8. package/dist/es/animation/generators/inertia.mjs +87 -0
  9. package/dist/es/animation/{legacy-popmotion → generators}/keyframes.mjs +8 -15
  10. package/dist/es/animation/{legacy-popmotion/find-spring.mjs → generators/spring/find.mjs} +6 -5
  11. package/dist/es/animation/generators/spring/index.mjs +129 -0
  12. package/dist/es/animation/generators/utils/velocity.mjs +9 -0
  13. package/dist/es/animation/index.mjs +2 -10
  14. package/dist/es/animation/js/driver-frameloop.mjs +12 -0
  15. package/dist/es/animation/js/index.mjs +206 -0
  16. package/dist/es/animation/optimized-appear/handoff.mjs +3 -1
  17. package/dist/es/animation/waapi/create-accelerated-animation.mjs +16 -10
  18. package/dist/es/frameloop/index.mjs +3 -4
  19. package/dist/es/gestures/pan/PanSession.mjs +2 -2
  20. package/dist/es/index.mjs +2 -3
  21. package/dist/es/render/utils/motion-values.mjs +1 -1
  22. package/dist/es/utils/time-conversion.mjs +2 -1
  23. package/dist/es/value/index.mjs +3 -3
  24. package/dist/es/value/use-spring.mjs +1 -1
  25. package/dist/es/value/use-velocity.mjs +4 -6
  26. package/dist/framer-motion.dev.js +475 -459
  27. package/dist/framer-motion.js +1 -1
  28. package/dist/index.d.ts +70 -114
  29. package/dist/projection.dev.js +5849 -5831
  30. package/dist/three-entry.d.ts +11 -9
  31. package/package.json +7 -7
  32. package/dist/es/animation/legacy-popmotion/decay.mjs +0 -34
  33. package/dist/es/animation/legacy-popmotion/index.mjs +0 -163
  34. package/dist/es/animation/legacy-popmotion/inertia.mjs +0 -90
  35. package/dist/es/animation/legacy-popmotion/spring.mjs +0 -143
  36. package/dist/es/frameloop/on-next-frame.mjs +0 -12
package/dist/index.d.ts CHANGED
@@ -877,13 +877,6 @@ interface CustomValueType {
877
877
  toValue: () => number | string;
878
878
  }
879
879
 
880
- interface Animation$1<V> {
881
- next: (t: number) => {
882
- value: V;
883
- done: boolean;
884
- };
885
- flipTarget: () => void;
886
- }
887
880
  /**
888
881
  * An update function. It accepts a timestamp used to advance the animation.
889
882
  */
@@ -895,9 +888,17 @@ declare type Update = (timestamp: number) => void;
895
888
  interface DriverControls {
896
889
  start: () => void;
897
890
  stop: () => void;
891
+ now: () => number;
898
892
  }
899
893
  declare type Driver = (update: Update) => DriverControls;
900
894
 
895
+ /**
896
+ * @public
897
+ */
898
+ interface AnimationPlaybackControls {
899
+ currentTime: number;
900
+ stop: () => void;
901
+ }
901
902
  interface VelocityOptions {
902
903
  velocity?: number;
903
904
  restSpeed?: number;
@@ -940,11 +941,12 @@ interface KeyframeOptions {
940
941
  ease?: Easing | Easing[];
941
942
  times?: number[];
942
943
  }
943
- interface AnimationOptions$2<V = any> extends AnimationLifecycleOptions<V>, AnimationPlaybackOptions, Omit<SpringOptions, "keyframes">, Omit<InertiaOptions$1, "keyframes">, KeyframeOptions {
944
+ interface AnimationOptions$1<V = any> extends AnimationLifecycleOptions<V>, AnimationPlaybackOptions, Omit<SpringOptions, "keyframes">, Omit<InertiaOptions$1, "keyframes">, KeyframeOptions {
945
+ delay?: number;
944
946
  keyframes: V[];
945
947
  elapsed?: number;
946
948
  driver?: Driver;
947
- type?: "decay" | "spring" | "keyframes" | "tween";
949
+ type?: "decay" | "spring" | "keyframes" | "tween" | "inertia";
948
950
  duration?: number;
949
951
  autoplay?: boolean;
950
952
  }
@@ -952,10 +954,6 @@ interface AnimationOptions$2<V = any> extends AnimationLifecycleOptions<V>, Anim
952
954
  * @public
953
955
  */
954
956
  declare type ControlsAnimationDefinition = string | string[] | TargetAndTransition | TargetResolver;
955
- interface PlaybackControls {
956
- stop: () => void;
957
- currentTime?: number;
958
- }
959
957
  /**
960
958
  * @public
961
959
  */
@@ -1346,59 +1344,6 @@ declare class NodeStack {
1346
1344
  removeLeadSnapshot(): void;
1347
1345
  }
1348
1346
 
1349
- /**
1350
- * @public
1351
- */
1352
- interface AnimationPlaybackControls {
1353
- stop: () => void;
1354
- isAnimating: () => boolean;
1355
- }
1356
- /**
1357
- * @public
1358
- */
1359
- interface AnimationPlaybackLifecycles<V> {
1360
- onUpdate?: (latest: V) => void;
1361
- onPlay?: () => void;
1362
- onComplete?: () => void;
1363
- onRepeat?: () => void;
1364
- onStop?: () => void;
1365
- }
1366
- /**
1367
- * @public
1368
- */
1369
- declare type AnimationOptions$1<V> = (Tween | Spring) & AnimationPlaybackLifecycles<V> & {
1370
- delay?: number;
1371
- type?: "tween" | "spring";
1372
- };
1373
- /**
1374
- * Animate a single value or a `MotionValue`.
1375
- *
1376
- * The first argument is either a `MotionValue` to animate, or an initial animation value.
1377
- *
1378
- * The second is either a value to animate to, or an array of keyframes to animate through.
1379
- *
1380
- * The third argument can be either tween or spring options, and optional lifecycle methods: `onUpdate`, `onPlay`, `onComplete`, `onRepeat` and `onStop`.
1381
- *
1382
- * Returns `AnimationPlaybackControls`, currently just a `stop` method.
1383
- *
1384
- * ```javascript
1385
- * const x = useMotionValue(0)
1386
- *
1387
- * useEffect(() => {
1388
- * const controls = animate(x, 100, {
1389
- * type: "spring",
1390
- * stiffness: 2000,
1391
- * onComplete: v => {}
1392
- * })
1393
- *
1394
- * return controls.stop
1395
- * })
1396
- * ```
1397
- *
1398
- * @public
1399
- */
1400
- declare function animate<V>(from: MotionValue<V> | V, to: V | V[], transition?: AnimationOptions$1<V>): AnimationPlaybackControls;
1401
-
1402
1347
  interface WithDepth {
1403
1348
  depth: number;
1404
1349
  }
@@ -1572,9 +1517,12 @@ declare function MeasureLayout(props: MotionProps & {
1572
1517
  visualElement: VisualElement;
1573
1518
  }): JSX.Element;
1574
1519
 
1520
+ interface FeatureClass<Props = unknown> {
1521
+ new (props: Props): Feature<Props>;
1522
+ }
1575
1523
  declare type HydratedFeatureDefinition = {
1576
1524
  isEnabled: (props: MotionProps) => boolean;
1577
- Feature: typeof Feature<unknown>;
1525
+ Feature: FeatureClass<unknown>;
1578
1526
  ProjectionNode?: any;
1579
1527
  MeasureLayout?: typeof MeasureLayout;
1580
1528
  };
@@ -1623,7 +1571,7 @@ declare type AnimationOptions = {
1623
1571
  };
1624
1572
  declare function animateVisualElement(visualElement: VisualElement, definition: AnimationDefinition, options?: AnimationOptions): Promise<void>;
1625
1573
 
1626
- interface AnimationState {
1574
+ interface AnimationState$1 {
1627
1575
  animateChanges: (options?: AnimationOptions, type?: AnimationType) => Promise<any>;
1628
1576
  setActive: (type: AnimationType, isActive: boolean, options?: AnimationOptions) => Promise<any>;
1629
1577
  setAnimateFunction: (fn: any) => void;
@@ -1802,7 +1750,7 @@ declare abstract class VisualElement<Instance = unknown, RenderState = unknown,
1802
1750
  /**
1803
1751
  * The AnimationState, this is hydrated by the animation Feature.
1804
1752
  */
1805
- animationState?: AnimationState;
1753
+ animationState?: AnimationState$1;
1806
1754
  /**
1807
1755
  * The options used to create this VisualElement. The Options type is defined
1808
1756
  * by the inheriting VisualElement and is passed straight through to the render functions.
@@ -3716,6 +3664,45 @@ declare const Reorder: {
3716
3664
  } & React$1.RefAttributes<any>>;
3717
3665
  };
3718
3666
 
3667
+ /**
3668
+ * @public
3669
+ */
3670
+ interface AnimationPlaybackLifecycles<V> {
3671
+ onUpdate?: (latest: V) => void;
3672
+ onPlay?: () => void;
3673
+ onComplete?: () => void;
3674
+ onRepeat?: () => void;
3675
+ onStop?: () => void;
3676
+ }
3677
+ /**
3678
+ * Animate a single value or a `MotionValue`.
3679
+ *
3680
+ * The first argument is either a `MotionValue` to animate, or an initial animation value.
3681
+ *
3682
+ * The second is either a value to animate to, or an array of keyframes to animate through.
3683
+ *
3684
+ * The third argument can be either tween or spring options, and optional lifecycle methods: `onUpdate`, `onPlay`, `onComplete`, `onRepeat` and `onStop`.
3685
+ *
3686
+ * Returns `AnimationPlaybackControls`, currently just a `stop` method.
3687
+ *
3688
+ * ```javascript
3689
+ * const x = useMotionValue(0)
3690
+ *
3691
+ * useEffect(() => {
3692
+ * const controls = animate(x, 100, {
3693
+ * type: "spring",
3694
+ * stiffness: 2000,
3695
+ * onComplete: v => {}
3696
+ * })
3697
+ *
3698
+ * return controls.stop
3699
+ * })
3700
+ * ```
3701
+ *
3702
+ * @public
3703
+ */
3704
+ declare function animate<V>(from: MotionValue<V> | V, to: V | V[], transition?: Transition & AnimationPlaybackLifecycles<V>): AnimationPlaybackControls;
3705
+
3719
3706
  interface AxisScrollInfo {
3720
3707
  current: number;
3721
3708
  offset: number[];
@@ -4418,44 +4405,19 @@ declare function useResetProjection(): () => void;
4418
4405
  */
4419
4406
  declare function buildTransform(transform: HTMLRenderState["transform"], { enableHardwareAcceleration, allowTransformNone, }: DOMVisualElementOptions, transformIsDefault: boolean, transformTemplate?: MotionProps["transformTemplate"]): string;
4420
4407
 
4421
- declare function animateValue<V = number>({ duration, driver, elapsed, repeat: repeatMax, repeatType, repeatDelay, keyframes, autoplay, onPlay, onStop, onComplete, onRepeat, onUpdate, type, ...options }: AnimationOptions$2<V>): {
4422
- stop: () => void;
4423
- /**
4424
- * Set the current time of the animation. This is purposefully
4425
- * mirroring the WAAPI animation API to make them interchanagable.
4426
- * Going forward this file should be ported more towards
4427
- * https://github.com/motiondivision/motionone/blob/main/packages/animation/src/Animation.ts
4428
- * Which behaviourally adheres to WAAPI as far as possible.
4429
- *
4430
- * WARNING: This is not safe to use for most animations. We currently
4431
- * only use it for handoff from WAAPI within Framer.
4432
- *
4433
- * This animation function consumes time every frame rather than being sampled for time.
4434
- * So the sample() method performs some headless frames to ensure
4435
- * repeats are handled correctly. Ideally in the future we will replace
4436
- * that method with this, once repeat calculations are pure.
4437
- */
4438
- currentTime: number;
4439
- /**
4440
- * animate() can't yet be sampled for time, instead it
4441
- * consumes time. So to sample it we have to run a low
4442
- * temporal-resolution version.
4443
- *
4444
- * isControlled should be set to true if sample is being run within
4445
- * a loop. This indicates that we're not arbitrarily sampling
4446
- * the animation but running it one step after another. Therefore
4447
- * we don't need to run a low-res version here. This is a stop-gap
4448
- * until a rewrite can sample for time.
4449
- */
4450
- sample: (t: number, isControlled?: boolean) => {
4451
- done: boolean;
4452
- value: V;
4453
- };
4454
- };
4408
+ interface AnimationState<V> {
4409
+ value: V;
4410
+ done: boolean;
4411
+ }
4412
+ interface KeyframeGenerator<V> {
4413
+ calculatedDuration: null | number;
4414
+ next: (t: number) => AnimationState<V>;
4415
+ }
4455
4416
 
4456
- declare function inertia({ keyframes, velocity, min, max, power, timeConstant, bounceStiffness, bounceDamping, restDelta, modifyTarget, driver, onUpdate, onComplete, onStop, }: AnimationOptions$2): {
4457
- stop: () => void;
4458
- };
4417
+ interface MainThreadAnimationControls<V> extends AnimationPlaybackControls {
4418
+ sample: (t: number) => AnimationState<V>;
4419
+ }
4420
+ declare function animateValue<V = number>({ autoplay, delay, driver, keyframes, type, repeat, repeatDelay, repeatType, onPlay, onStop, onComplete, onUpdate, ...options }: AnimationOptions$1<V>): MainThreadAnimationControls<V>;
4459
4421
 
4460
4422
  declare type Transformer = (v: any) => any;
4461
4423
  declare type ValueType = {
@@ -4516,13 +4478,7 @@ declare function startOptimizedAppearAnimation(element: HTMLElement, name: strin
4516
4478
 
4517
4479
  declare const optimizedAppearDataAttribute: string;
4518
4480
 
4519
- /**
4520
- * This is based on the spring implementation of Wobble https://github.com/skevy/wobble
4521
- */
4522
- declare function spring({ keyframes, restDelta, restSpeed, ...options }: AnimationOptions$2<number>): Animation$1<number>;
4523
- declare namespace spring {
4524
- var needsInterpolation: (a: any, b: any) => boolean;
4525
- }
4481
+ declare function spring({ keyframes, restDelta, restSpeed, ...options }: AnimationOptions$1<number>): KeyframeGenerator<number>;
4526
4482
 
4527
4483
  interface NodeGroup {
4528
4484
  add: (node: IProjectionNode) => void;
@@ -4587,4 +4543,4 @@ declare function useInvertedScale(scale?: Partial<ScaleMotionValues>): ScaleMoti
4587
4543
 
4588
4544
  declare const AnimateSharedLayout: React$1.FunctionComponent<React$1.PropsWithChildren<unknown>>;
4589
4545
 
4590
- export { AnimatePresence, AnimatePresenceProps, AnimateSharedLayout, AnimationControls, AnimationLifecycleOptions, AnimationLifecycles, AnimationOptions$1 as AnimationOptions, AnimationPlaybackControls, AnimationPlaybackOptions, AnimationProps, AnimationType, Axis, AxisDelta, BezierDefinition, BoundingBox, Box, ControlsAnimationDefinition, CreateVisualElement, CustomDomComponent, CustomValueType, Cycle, CycleState, DecayOptions, DelayedFunction, Delta, DeprecatedLayoutGroupContext, DevMessage, DragControls, DragElastic, DragHandlers, DraggableProps, DurationSpringOptions, Easing, EasingDefinition, EasingFunction, EasingModifier, EventInfo, FeatureBundle, FeatureDefinition, FeatureDefinitions, FeaturePackage, FeaturePackages, FlatTree, FocusHandlers, ForwardRefComponent, HTMLMotionProps, HoverHandlers, HydratedFeatureDefinition, HydratedFeatureDefinitions, IProjectionNode, Inertia, InertiaOptions$1 as InertiaOptions, InterpolateOptions, KeyframeOptions, Keyframes, KeyframesTarget, LayoutGroup, LayoutGroupContext, LayoutProps, LazyFeatureBundle$1 as LazyFeatureBundle, LazyMotion, LazyProps, MixerFactory, MotionAdvancedProps, MotionConfig, MotionConfigContext, MotionConfigProps, MotionContext, MotionProps, MotionStyle, MotionTransform, MotionValue, None, Orchestration, PanHandlers, PanInfo, PassiveEffect, PlaybackControls, Point, PresenceContext, RelayoutInfo, RenderComponent, Reorder, Repeat, ResolveLayoutTransition, ResolvedKeyframesTarget, ResolvedSingleTarget, ResolvedValueTarget, ResolvedValues, SVGAttributesAsMotionValues, SVGMotionProps, ScrapeMotionValuesFromProps, ScrollMotionValues, SingleTarget, Spring, SpringOptions, Subscriber, SwitchLayoutGroupContext, TapHandlers, TapInfo, Target, TargetAndTransition, TransformPoint, Transition, Tween, ValueTarget, ValueType, Variant, VariantLabels, Variants, VelocityOptions, VisualElement, VisualState, addPointerEvent, addPointerInfo, addScaleCorrector, animate, animateValue, animateVisualElement, animationControls, animations, anticipate, backIn, backInOut, backOut, buildTransform, calcLength, checkTargetForNewValues, circIn, circInOut, circOut, clamp, color, complex, createBox, createDomMotionComponent, createMotionComponent, cubicBezier, delay, distance, distance2D, domAnimation, domMax, easeIn, easeInOut, easeOut, filterProps, frameData, inView, inertia, interpolate, invariant, isBrowser, isDragActive, isMotionComponent, isMotionValue, isValidMotionProp, m, makeUseVisualState, mix, motion, motionValue, optimizedAppearDataAttribute, pipe, progress, px, resolveMotionValue, scroll, spring, startOptimizedAppearAnimation, sync, transform, unwrapMotionComponent, useAnimation, useAnimationControls, useAnimationFrame, useCycle, useAnimatedState as useDeprecatedAnimatedState, useInvertedScale as useDeprecatedInvertedScale, useDomEvent, useDragControls, useElementScroll, useForceUpdate, useInView, useInstantLayoutTransition, useInstantTransition, useIsPresent, useIsomorphicLayoutEffect, useMotionTemplate, useMotionValue, useMotionValueEvent, usePresence, useReducedMotion, useReducedMotionConfig, useResetProjection, useScroll, useSpring, useTime, useTransform, useUnmountEffect, useVelocity, useViewportScroll, useWillChange, warning, wrap };
4546
+ export { AnimatePresence, AnimatePresenceProps, AnimateSharedLayout, AnimationControls, AnimationLifecycleOptions, AnimationLifecycles, AnimationOptions$1 as AnimationOptions, AnimationPlaybackControls, AnimationPlaybackOptions, AnimationProps, AnimationType, Axis, AxisDelta, BezierDefinition, BoundingBox, Box, ControlsAnimationDefinition, CreateVisualElement, CustomDomComponent, CustomValueType, Cycle, CycleState, DecayOptions, DelayedFunction, Delta, DeprecatedLayoutGroupContext, DevMessage, DragControls, DragElastic, DragHandlers, DraggableProps, DurationSpringOptions, Easing, EasingDefinition, EasingFunction, EasingModifier, EventInfo, FeatureBundle, FeatureDefinition, FeatureDefinitions, FeaturePackage, FeaturePackages, FlatTree, FocusHandlers, ForwardRefComponent, HTMLMotionProps, HoverHandlers, HydratedFeatureDefinition, HydratedFeatureDefinitions, IProjectionNode, Inertia, InertiaOptions$1 as InertiaOptions, InterpolateOptions, KeyframeOptions, Keyframes, KeyframesTarget, LayoutGroup, LayoutGroupContext, LayoutProps, LazyFeatureBundle$1 as LazyFeatureBundle, LazyMotion, LazyProps, MixerFactory, MotionAdvancedProps, MotionConfig, MotionConfigContext, MotionConfigProps, MotionContext, MotionProps, MotionStyle, MotionTransform, MotionValue, None, Orchestration, PanHandlers, PanInfo, PassiveEffect, Point, PresenceContext, RelayoutInfo, RenderComponent, Reorder, Repeat, ResolveLayoutTransition, ResolvedKeyframesTarget, ResolvedSingleTarget, ResolvedValueTarget, ResolvedValues, SVGAttributesAsMotionValues, SVGMotionProps, ScrapeMotionValuesFromProps, ScrollMotionValues, SingleTarget, Spring, SpringOptions, Subscriber, SwitchLayoutGroupContext, TapHandlers, TapInfo, Target, TargetAndTransition, TransformPoint, Transition, Tween, ValueTarget, ValueType, Variant, VariantLabels, Variants, VelocityOptions, VisualElement, VisualState, addPointerEvent, addPointerInfo, addScaleCorrector, animate, animateValue, animateVisualElement, animationControls, animations, anticipate, backIn, backInOut, backOut, buildTransform, calcLength, checkTargetForNewValues, circIn, circInOut, circOut, clamp, color, complex, createBox, createDomMotionComponent, createMotionComponent, cubicBezier, delay, distance, distance2D, domAnimation, domMax, easeIn, easeInOut, easeOut, filterProps, frameData, inView, interpolate, invariant, isBrowser, isDragActive, isMotionComponent, isMotionValue, isValidMotionProp, m, makeUseVisualState, mix, motion, motionValue, optimizedAppearDataAttribute, pipe, progress, px, resolveMotionValue, scroll, spring, startOptimizedAppearAnimation, sync, transform, unwrapMotionComponent, useAnimation, useAnimationControls, useAnimationFrame, useCycle, useAnimatedState as useDeprecatedAnimatedState, useInvertedScale as useDeprecatedInvertedScale, useDomEvent, useDragControls, useElementScroll, useForceUpdate, useInView, useInstantLayoutTransition, useInstantTransition, useIsPresent, useIsomorphicLayoutEffect, useMotionTemplate, useMotionValue, useMotionValueEvent, usePresence, useReducedMotion, useReducedMotionConfig, useResetProjection, useScroll, useSpring, useTime, useTransform, useUnmountEffect, useVelocity, useViewportScroll, useWillChange, warning, wrap };