framer-motion 2.1.0 → 2.2.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.
@@ -22,6 +22,11 @@ export declare function addScaleCorrection(correctors: ScaleCorrectionDefinition
22
22
 
23
23
  declare type AlwaysPresent = [true, null];
24
24
 
25
+ /**
26
+ * @public
27
+ */
28
+ export declare const AnimateLayoutFeature: MotionFeature;
29
+
25
30
  /**
26
31
  * `AnimatePresence` enables the animation of components that have been removed from the tree.
27
32
  *
@@ -359,6 +364,11 @@ declare interface AnimationControlsConfig {
359
364
 
360
365
  declare type AnimationDefinition = VariantLabels | TargetAndTransition | TargetResolver;
361
366
 
367
+ /**
368
+ * @public
369
+ */
370
+ export declare const AnimationFeature: MotionFeature;
371
+
362
372
  declare type AnimationOptions = {
363
373
  delay?: number;
364
374
  priority?: number;
@@ -620,36 +630,16 @@ declare interface ControlsProp {
620
630
  *
621
631
  * @internal
622
632
  */
623
- export declare function createMotionComponent<P extends {}, E>(Component: string | React.ComponentType<P>, { useVisualElement, render, animationControlsConfig, }: MotionComponentConfig<E>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P & MotionProps> & React.RefAttributes<E>>;
633
+ export declare function createMotionComponent<P extends {}, E>(Component: string | React.ComponentType<P>, { defaultFeatures, useVisualElement, render, animationControlsConfig, }: MotionComponentConfig<E>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P & MotionProps> & React.RefAttributes<E>>;
624
634
 
625
635
  declare type CSSPropertiesWithoutTransitionOrSingleTransforms = Omit<CSSProperties, "transition" | "rotate" | "scale" | "perspective">;
626
636
 
627
- /**
628
- * Convert any React component into a `motion` component. The provided component
629
- * **must** use `React.forwardRef` to the underlying DOM component you want to animate.
630
- *
631
- * ```jsx
632
- * const Component = React.forwardRef((props, ref) => {
633
- * return <div ref={ref} />
634
- * })
635
- *
636
- * const MotionComponent = motion.custom(Component)
637
- * ```
638
- *
639
- * @public
640
- */
641
- declare function custom<Props>(Component: string | React.ComponentType<Props>): CustomDomComponent<Props>;
642
-
643
637
  /**
644
638
  * I'd rather the return type of `custom` to be implicit but this throws
645
639
  * incorrect relative paths in the exported types and API Extractor throws
646
640
  * a wobbly.
647
641
  */
648
- declare type CustomDomComponent<Props> = React.ForwardRefExoticComponent<React.PropsWithoutRef<Props & MotionProps> & React.RefAttributes<SVGElement | HTMLElement>>;
649
-
650
- declare type CustomMotionComponent = {
651
- custom: typeof custom;
652
- };
642
+ export declare type CustomDomComponent<Props> = React.ForwardRefExoticComponent<React.PropsWithoutRef<Props & MotionProps> & React.RefAttributes<SVGElement | HTMLElement>>;
653
643
 
654
644
  declare interface CustomStyles {
655
645
  /**
@@ -791,6 +781,11 @@ declare interface DragControlsProps extends DraggableProps {
791
781
 
792
782
  declare type DragDirection = "x" | "y";
793
783
 
784
+ /**
785
+ * @public
786
+ */
787
+ export declare const DragFeature: MotionFeature;
788
+
794
789
  /**
795
790
  * @public
796
791
  */
@@ -1265,6 +1260,11 @@ export declare interface EventInfo {
1265
1260
  point: Point;
1266
1261
  }
1267
1262
 
1263
+ /**
1264
+ * @public
1265
+ */
1266
+ export declare const ExitFeature: MotionFeature;
1267
+
1268
1268
  /**
1269
1269
  * @public
1270
1270
  */
@@ -1285,6 +1285,11 @@ export declare type ForwardRefComponent<T, P> = ForwardRefExoticComponent<PropsW
1285
1285
  */
1286
1286
  export declare type GestureHandlers = PanHandlers & TapHandlers & HoverHandlers;
1287
1287
 
1288
+ /**
1289
+ * @public
1290
+ */
1291
+ export declare const GesturesFeature: MotionFeature;
1292
+
1288
1293
  /**
1289
1294
  * @public
1290
1295
  */
@@ -1445,11 +1450,6 @@ declare class HTMLVisualElement<E extends HTMLElement | SVGElement = HTMLElement
1445
1450
  * ========================================
1446
1451
  */
1447
1452
  isLayoutProjectionEnabled: boolean;
1448
- /**
1449
- * A boolean that flags whether this component has children that need to be update
1450
- * when this component changes layout.
1451
- */
1452
- hasLayoutChildren: boolean;
1453
1453
  enableLayoutProjection(): void;
1454
1454
  /**
1455
1455
  * A set of layout update event handlers. These are only called once all layouts have been read,
@@ -1501,7 +1501,7 @@ declare class HTMLVisualElement<E extends HTMLElement | SVGElement = HTMLElement
1501
1501
  *
1502
1502
  * This is considered mutable to avoid object creation on each frame.
1503
1503
  */
1504
- private targetBoxFinal;
1504
+ protected targetBoxFinal: AxisBox2D;
1505
1505
  /**
1506
1506
  * Can be used to store a snapshot of the measured viewport bounding box before
1507
1507
  * a re-render.
@@ -1532,6 +1532,12 @@ declare class HTMLVisualElement<E extends HTMLElement | SVGElement = HTMLElement
1532
1532
  * This is considered mutable to avoid object creation on each frame.
1533
1533
  */
1534
1534
  deltaFinal: BoxDelta;
1535
+ /**
1536
+ * The computed transform string to apply deltaFinal to the element. Currently this is only
1537
+ * being used to diff and decide whether to render on the current frame, but a minor optmisation
1538
+ * could be to provide this to the buildHTMLStyle function.
1539
+ */
1540
+ deltaTransform: string;
1535
1541
  /**
1536
1542
  *
1537
1543
  */
@@ -1599,11 +1605,13 @@ declare class HTMLVisualElement<E extends HTMLElement | SVGElement = HTMLElement
1599
1605
  */
1600
1606
  startLayoutAxisAnimation(axis: "x" | "y", transition: Transition): Promise<void>;
1601
1607
  stopLayoutAnimation(): void;
1608
+ updateLayoutDelta: () => void;
1602
1609
  /**
1603
1610
  * Update the layout deltas to reflect the relative positions of the layout
1604
1611
  * and the desired target box
1605
1612
  */
1606
- updateLayoutDeltas(isReactRender: boolean): void;
1613
+ updateLayoutDeltas(): void;
1614
+ updateTransformDeltas(): void;
1607
1615
  /**
1608
1616
  * ========================================
1609
1617
  * Build & render
@@ -1612,7 +1620,7 @@ declare class HTMLVisualElement<E extends HTMLElement | SVGElement = HTMLElement
1612
1620
  /**
1613
1621
  * Build a style prop using the latest resolved MotionValues
1614
1622
  */
1615
- build(isReactRender: boolean): void;
1623
+ build(): void;
1616
1624
  /**
1617
1625
  * Render the Element by rebuilding and applying the latest styles and vars.
1618
1626
  */
@@ -2158,6 +2166,9 @@ export declare interface Keyframes {
2158
2166
  */
2159
2167
  export declare type KeyframesTarget = ResolvedKeyframesTarget | [null, ...CustomValueType[]] | CustomValueType[];
2160
2168
 
2169
+ /**
2170
+ * @public
2171
+ */
2161
2172
  export declare interface LayoutProps {
2162
2173
  /**
2163
2174
  * If `true`, this component will automatically animate to its new position when
@@ -2176,6 +2187,9 @@ export declare interface LayoutProps {
2176
2187
  * `boxShadow` and `borderRadius` will automatically be corrected if they are already being
2177
2188
  * animated on this component. Otherwise, set them directly via the `initial` prop.
2178
2189
  *
2190
+ * If `layout` is set to `"position"`, the size of the component will change instantly and
2191
+ * only its position will animate.
2192
+ *
2179
2193
  * @public
2180
2194
  */
2181
2195
  layout?: boolean | "position";
@@ -2240,6 +2254,13 @@ declare class LayoutStack {
2240
2254
 
2241
2255
  declare type LayoutUpdateHandler = (layout: AxisBox2D, prev: AxisBox2D, config?: SharedLayoutAnimationConfig) => void;
2242
2256
 
2257
+ /**
2258
+ * @public
2259
+ */
2260
+ export declare const m: HTMLMotionComponents & SVGMotionComponents & {
2261
+ custom: <Props>(Component: string | React.ComponentClass<Props, any> | React.FunctionComponent<Props>) => CustomDomComponent<Props>;
2262
+ };
2263
+
2243
2264
  declare type MakeCustomValueType<T> = {
2244
2265
  [K in keyof T]: T[K] | CustomValueType;
2245
2266
  };
@@ -2258,15 +2279,15 @@ declare type MakeTargetAnimatable = (visualElement: VisualElement, target: Targe
2258
2279
  transitionEnd?: Target;
2259
2280
  };
2260
2281
 
2261
- declare type Motion = HTMLMotionComponents & SVGMotionComponents & CustomMotionComponent;
2262
-
2263
2282
  /**
2264
2283
  * HTML & SVG components, optimised for use with gestures and animation. These can be used as
2265
2284
  * drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
2266
2285
  *
2267
2286
  * @public
2268
2287
  */
2269
- export declare const motion: Motion;
2288
+ export declare const motion: HTMLMotionComponents & SVGMotionComponents & {
2289
+ custom: <Props>(Component: string | React.ComponentClass<Props, any> | React.FunctionComponent<Props>) => CustomDomComponent<Props>;
2290
+ };
2270
2291
 
2271
2292
  /**
2272
2293
  * @public
@@ -2402,11 +2423,61 @@ export declare interface MotionCallbacks {
2402
2423
  }
2403
2424
 
2404
2425
  declare interface MotionComponentConfig<E> {
2426
+ defaultFeatures: MotionFeature[];
2405
2427
  useVisualElement: UseVisualElement<E>;
2406
2428
  render: RenderComponent;
2407
2429
  animationControlsConfig: AnimationControlsConfig;
2408
2430
  }
2409
2431
 
2432
+ /**
2433
+ * MotionConfig can be used in combination with the `m` component to cut bundle size
2434
+ * and dynamically load only the features you use.
2435
+ *
2436
+ * ```jsx
2437
+ * import {
2438
+ * m as motion,
2439
+ * AnimationFeature,
2440
+ * MotionConfig
2441
+ * } from "framer-motion"
2442
+ *
2443
+ * export function App() {
2444
+ * return (
2445
+ * <MotionConfig features={[AnimationFeature]}>
2446
+ * <motion.div animate={{ x: 100 }} />
2447
+ * </MotionConfig>
2448
+ * )
2449
+ * }
2450
+ * ```
2451
+ *
2452
+ * @public
2453
+ */
2454
+ export declare function MotionConfig({ children, features, ...props }: MotionConfigProps): JSX.Element;
2455
+
2456
+ /**
2457
+ * @public
2458
+ */
2459
+ export declare interface MotionConfigContext {
2460
+ /**
2461
+ * @internal
2462
+ */
2463
+ transformPagePoint: TransformPoint2D;
2464
+ /**
2465
+ * An array of features to provide to children.
2466
+ *
2467
+ * @public
2468
+ */
2469
+ features: MotionFeature[];
2470
+ }
2471
+
2472
+ /**
2473
+ * @public
2474
+ */
2475
+ export declare const MotionConfigContext: React.Context<MotionConfigContext>;
2476
+
2477
+ declare interface MotionConfigProps extends Partial<MotionConfigContext> {
2478
+ children?: React.ReactNode;
2479
+ }
2480
+
2410
2481
  /**
2411
2482
  * @internal
2412
2483
  */
@@ -2431,29 +2502,7 @@ declare type MotionCSS = MakeMotion<Omit<CSSProperties, "rotate" | "scale" | "pe
2431
2502
  export declare interface MotionFeature {
2432
2503
  key: string;
2433
2504
  shouldRender: (props: MotionProps, parentContext: MotionContextProps) => boolean;
2434
- Component: React.ComponentType<FeatureProps>;
2435
- }
2436
-
2437
- /**
2438
- * @internal
2439
- */
2440
- export declare const MotionPluginContext: React.Context<MotionPluginsContext>;
2441
-
2442
- declare interface MotionPluginProps extends Partial<MotionPluginsContext> {
2443
- children?: React.ReactNode;
2444
- }
2445
-
2446
- /**
2447
- * @remarks For now I think this should remain a private API for our own use
2448
- * until we can figure out a nicer way of allowing people to add these
2449
- *
2450
- * @internal
2451
- */
2452
- export declare function MotionPlugins({ children, ...props }: MotionPluginProps): JSX.Element;
2453
-
2454
- declare interface MotionPluginsContext {
2455
- transformPagePoint: TransformPoint2D;
2456
- features: MotionFeature[];
2505
+ getComponent: (props: MotionProps) => React.ComponentType<FeatureProps> | undefined;
2457
2506
  }
2458
2507
 
2459
2508
  declare interface MotionPoint {
@@ -4649,7 +4698,7 @@ declare namespace React_2 {
4649
4698
  *
4650
4699
  * target - a reference to the element from which the event was originally dispatched.
4651
4700
  * This might be a child element to the element on which the event listener is registered.
4652
- * If you thought this should be `EventTarget & T`, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/12239
4701
+ * If you thought this should be `EventTarget & T`, see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11508#issuecomment-256045682
4653
4702
  */
4654
4703
  interface SyntheticEvent<T = Element, E = Event> extends BaseSyntheticEvent<E, EventTarget & T, EventTarget> {}
4655
4704
 
@@ -5476,6 +5525,7 @@ declare namespace React_2 {
5476
5525
 
5477
5526
  interface DetailsHTMLAttributes<T> extends HTMLAttributes<T> {
5478
5527
  open?: boolean;
5528
+ onToggle?: ReactEventHandler<T>;
5479
5529
  }
5480
5530
 
5481
5531
  interface DelHTMLAttributes<T> extends HTMLAttributes<T> {
@@ -6490,7 +6540,6 @@ declare interface SharedLayoutAnimationConfig {
6490
6540
  targetBox?: AxisBox2D;
6491
6541
  transition?: Transition;
6492
6542
  crossfadeOpacity?: MotionValue<number>;
6493
- onLayoutAnimationComplete?: () => void;
6494
6543
  }
6495
6544
 
6496
6545
  export declare interface SharedLayoutProps {
@@ -7796,6 +7845,8 @@ export declare function useDragControls(): DragControls;
7796
7845
  * - `scrollXProgress` — Horizontal scroll progress between `0` and `1`.
7797
7846
  * - `scrollYProgress` — Vertical scroll progress between `0` and `1`.
7798
7847
  *
7848
+ * This element must be set to `overflow: scroll` on either or both axes to report scroll offset.
7849
+ *
7799
7850
  * @library
7800
7851
  *
7801
7852
  * ```jsx
@@ -8192,6 +8243,7 @@ declare enum VisibilityAction {
8192
8243
  */
8193
8244
  declare abstract class VisualElement<E = any> {
8194
8245
  parent?: VisualElement<E>;
8246
+ rootParent: VisualElement<E>;
8195
8247
  children: Set<VisualElement<E>>;
8196
8248
  prevSnapshot?: Snapshot;
8197
8249
  private removeFromParent?;
@@ -8221,10 +8273,12 @@ declare abstract class VisualElement<E = any> {
8221
8273
  abstract clean(): void;
8222
8274
  abstract readNativeValue(key: string): string | number;
8223
8275
  abstract getBoundingBox(): AxisBox2D;
8276
+ abstract updateLayoutDelta(): void;
8224
8277
  private setSingleStaticValue;
8225
8278
  setStaticValues(values: string | ResolvedValues, value?: string | number): void;
8226
8279
  triggerRender: () => void;
8227
8280
  scheduleRender: () => import("framesync").Process;
8281
+ scheduleUpdateLayoutDelta(): void;
8228
8282
  private subscribeToValue;
8229
8283
  protected mount(element: E): void;
8230
8284
  private unmount;
@@ -8454,11 +8508,6 @@ declare class VisualElementDragControls {
8454
8508
  prepareBoundingBox(): void;
8455
8509
  resolveDragConstraints(): void;
8456
8510
  resolveRefConstraints(layoutBox: AxisBox2D, constraints: RefObject<Element>): {
8457
- /**
8458
- * Instantiate a PanSession for the drag gesture
8459
- *
8460
- * @public
8461
- */
8462
8511
  x: {
8463
8512
  min: number;
8464
8513
  max: number;