UNPKG

framer-motion

Version:

A simple and powerful JavaScript animation library

1,198 lines (1,122 loc) • 60.9 kB
/// <reference types="react" /> import { F as FeatureBundle, M as MotionProps, a as MotionConfigContext, H as HTMLMotionProps, b as HTMLElements, G as GenericKeyframesTarget, O as OnScrollInfo, S as ScrollInfoOptions, P as Point, D as DOMMotionComponents, c as MotionComponentProps, d as HTMLMotionComponents, e as SVGMotionComponents, E as EventInfo, f as FeaturePackages, A as Axis, B as Box, C as CustomValueType, V as ValueAnimationOptionsWithRenderContext, R as ResolvedKeyframes, K as KeyframeResolver, g as AnimationControls, h as VisualElement, i as AnimationDefinition, j as VisualElementAnimationOptions, I as IProjectionNode, k as ResolvedValues, l as HTMLRenderState } from '../types.d-B50aGbjN.js'; export { a2 as AnimationLifecycles, W as AnimationProps, p as AnimationType, ax as AxisDelta, aw as BoundingBox, a3 as CreateVisualElement, ay as Delta, q as DragControls, L as DragElastic, Q as DragHandlers, N as DraggableProps, ar as FeatureDefinition, as as FeatureDefinitions, at as FeaturePackage, a4 as FlatTree, s as FocusHandlers, $ as ForwardRefComponent, t as HoverHandlers, ap as HydratedFeatureDefinition, aq as HydratedFeatureDefinitions, a5 as Inertia, a6 as Keyframes, a7 as KeyframesTarget, U as LayoutProps, au as LazyFeatureBundle, X as MotionAdvancedProps, Y as MotionStyle, Z as MotionTransform, a8 as None, a9 as Orchestration, v as PanHandlers, r as PanInfo, z as PresenceContext, av as RenderComponent, aa as Repeat, an as ResolveKeyframes, ab as ResolvedKeyframesTarget, ac as ResolvedSingleTarget, ad as ResolvedValueTarget, a0 as SVGAttributesAsMotionValues, a1 as SVGMotionProps, m as ScrapeMotionValuesFromProps, ae as SingleTarget, af as Spring, J as SwitchLayoutGroupContext, T as TapHandlers, w as TapInfo, ag as Target, ah as TargetAndTransition, az as TransformPoint, ai as Transition, aj as Tween, ak as ValueTarget, al as Variant, _ as VariantLabels, am as Variants, o as VisualState, x as createRendererMotionComponent, n as makeUseVisualState, y as optimizedAppearDataAttribute, ao as scroll, u as useDragControls } from '../types.d-B50aGbjN.js'; import * as react_jsx_runtime from 'react/jsx-runtime'; import * as React$1 from 'react'; import { useEffect, RefObject } from 'react'; import * as motion_dom from 'motion-dom'; import { MotionValue, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, Easing, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, EasingFunction, EasingModifier, ValueAnimationOptions, KeyframeGenerator, DynamicOption, MotionValueEventCallbacks, SpringOptions, RepeatType, AnimationPlaybackControls, AnimationState } from 'motion-dom'; export * from 'motion-dom'; export { BezierDefinition, Easing, EasingDefinition, EasingFunction, EasingModifier, MotionValue, cancelFrame, cancelSync, frame, frameData, hover, isDragActive, motionValue, press, sync, time } from 'motion-dom'; export { MotionGlobalConfig, invariant, noop, progress } from 'motion-utils'; /** * @public */ interface AnimatePresenceProps { /** * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children * that are present when the component is first rendered. * * ```jsx * <AnimatePresence initial={false}> * {isVisible && ( * <motion.div * key="modal" * initial={{ opacity: 0 }} * animate={{ opacity: 1 }} * exit={{ opacity: 0 }} * /> * )} * </AnimatePresence> * ``` * * @public */ initial?: boolean; /** * When a component is removed, there's no longer a chance to update its props. So if a component's `exit` * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`. * This will ensure all leaving components animate using the latest data. * * @public */ custom?: any; /** * Fires when all exiting nodes have completed animating out. * * @public */ onExitComplete?: () => void; /** * Determines how to handle entering and exiting elements. * * - `"sync"`: Default. Elements animate in and out as soon as they're added/removed. * - `"popLayout"`: Exiting elements are "popped" from the page layout, allowing sibling * elements to immediately occupy their new layouts. * - `"wait"`: Only renders one component at a time. Wait for the exiting component to animate out * before animating the next component in. * * @public */ mode?: "sync" | "popLayout" | "wait"; /** * Internal. Used in Framer to flag that sibling children *shouldn't* re-render as a result of a * child being removed. */ presenceAffectsLayout?: boolean; /** * If true, the `AnimatePresence` component will propagate parent exit animations * to its children. */ propagate?: boolean; /** * Internal. Set whether to anchor the x position of the exiting element to the left or right * when using `mode="popLayout"`. */ anchorX?: "left" | "right"; } /** * `AnimatePresence` enables the animation of components that have been removed from the tree. * * When adding/removing more than a single child, every child **must** be given a unique `key` prop. * * Any `motion` components that have an `exit` property defined will animate out when removed from * the tree. * * ```jsx * import { motion, AnimatePresence } from 'framer-motion' * * export const Items = ({ items }) => ( * <AnimatePresence> * {items.map(item => ( * <motion.div * key={item.id} * initial={{ opacity: 0 }} * animate={{ opacity: 1 }} * exit={{ opacity: 0 }} * /> * ))} * </AnimatePresence> * ) * ``` * * You can sequence exit animations throughout a tree using variants. * * If a child contains multiple `motion` components with `exit` props, it will only unmount the child * once all `motion` components have finished animating out. Likewise, any components using * `usePresence` all need to call `safeToRemove`. * * @public */ declare const AnimatePresence: ({ children, custom, initial, onExitComplete, presenceAffectsLayout, mode, propagate, anchorX, }: React$1.PropsWithChildren<AnimatePresenceProps>) => react_jsx_runtime.JSX.Element | null; type InheritOption = boolean | "id"; interface Props$2 { id?: string; inherit?: InheritOption; } declare const LayoutGroup: React$1.FunctionComponent<React$1.PropsWithChildren<Props$2>>; type LazyFeatureBundle = () => Promise<FeatureBundle>; /** * @public */ interface LazyProps { children?: React.ReactNode; /** * Can be used to provide a feature bundle synchronously or asynchronously. * * ```jsx * // features.js * import { domAnimation } from "framer-motion" * export default domAnimation * * // index.js * import { LazyMotion, m } from "framer-motion" * * const loadFeatures = import("./features.js") * .then(res => res.default) * * function Component() { * return ( * <LazyMotion features={loadFeatures}> * <m.div animate={{ scale: 1.5 }} /> * </LazyMotion> * ) * } * ``` * * @public */ features: FeatureBundle | LazyFeatureBundle; /** * If `true`, will throw an error if a `motion` component renders within * a `LazyMotion` component. * * ```jsx * // This component will throw an error that explains using a motion component * // instead of the m component will break the benefits of code-splitting. * function Component() { * return ( * <LazyMotion features={domAnimation} strict> * <motion.div /> * </LazyMotion> * ) * } * ``` * * @public */ strict?: boolean; } /** * Used in conjunction with the `m` component to reduce bundle size. * * `m` is a version of the `motion` component that only loads functionality * critical for the initial render. * * `LazyMotion` can then be used to either synchronously or asynchronously * load animation and gesture support. * * ```jsx * // Synchronous loading * import { LazyMotion, m, domAnimation } from "framer-motion" * * function App() { * return ( * <LazyMotion features={domAnimation}> * <m.div animate={{ scale: 2 }} /> * </LazyMotion> * ) * } * * // Asynchronous loading * import { LazyMotion, m } from "framer-motion" * * function App() { * return ( * <LazyMotion features={() => import('./path/to/domAnimation')}> * <m.div animate={{ scale: 2 }} /> * </LazyMotion> * ) * } * ``` * * @public */ declare function LazyMotion({ children, features, strict }: LazyProps): react_jsx_runtime.JSX.Element; type IsValidProp = (key: string) => boolean; declare function filterProps(props: MotionProps, isDom: boolean, forwardMotionProps: boolean): MotionProps; interface MotionConfigProps extends Partial<MotionConfigContext> { children?: React$1.ReactNode; isValidProp?: IsValidProp; } /** * `MotionConfig` is used to set configuration options for all children `motion` components. * * ```jsx * import { motion, MotionConfig } from "framer-motion" * * export function App() { * return ( * <MotionConfig transition={{ type: "spring" }}> * <motion.div animate={{ x: 100 }} /> * </MotionConfig> * ) * } * ``` * * @public */ declare function MotionConfig({ children, isValidProp, ...config }: MotionConfigProps): react_jsx_runtime.JSX.Element; interface Props$1<V> { /** * A HTML element to render this component as. Defaults to `"ul"`. * * @public */ as?: keyof HTMLElements; /** * The axis to reorder along. By default, items will be draggable on this axis. * To make draggable on both axes, set `<Reorder.Item drag />` * * @public */ axis?: "x" | "y"; /** * A callback to fire with the new value order. For instance, if the values * are provided as a state from `useState`, this could be the set state function. * * @public */ onReorder: (newOrder: V[]) => void; /** * The latest values state. * * ```jsx * function Component() { * const [items, setItems] = useState([0, 1, 2]) * * return ( * <Reorder.Group values={items} onReorder={setItems}> * {items.map((item) => <Reorder.Item key={item} value={item} />)} * </Reorder.Group> * ) * } * ``` * * @public */ values: V[]; } type ReorderGroupProps<V> = Props$1<V> & Omit<HTMLMotionProps<any>, "values"> & React$1.PropsWithChildren<{}>; declare function ReorderGroupComponent<V>({ children, as, axis, onReorder, values, ...props }: ReorderGroupProps<V>, externalRef?: React$1.ForwardedRef<any>): react_jsx_runtime.JSX.Element; declare const ReorderGroup: <V>(props: ReorderGroupProps<V> & { ref?: React$1.ForwardedRef<any>; }) => ReturnType<typeof ReorderGroupComponent>; interface Props<V> { /** * A HTML element to render this component as. Defaults to `"li"`. * * @public */ as?: keyof HTMLElements; /** * The value in the list that this component represents. * * @public */ value: V; /** * A subset of layout options primarily used to disable layout="size" * * @public * @default true */ layout?: true | "position"; } type ReorderItemProps<V> = Props<V> & HTMLMotionProps<any> & React$1.PropsWithChildren<{}>; declare function ReorderItemComponent<V>({ children, style, value, as, onDrag, layout, ...props }: ReorderItemProps<V>, externalRef?: React$1.ForwardedRef<any>): react_jsx_runtime.JSX.Element; declare const ReorderItem: <V>(props: ReorderItemProps<V> & { ref?: React$1.ForwardedRef<any>; }) => ReturnType<typeof ReorderItemComponent>; declare namespace namespace_d { export { ReorderGroup as Group, ReorderItem as Item }; } type ObjectTarget<O> = { [K in keyof O]?: O[K] | GenericKeyframesTarget<O[K]>; }; type SequenceTime = number | "<" | `+${number}` | `-${number}` | `${string}`; type SequenceLabel = string; interface SequenceLabelWithTime { name: SequenceLabel; at: SequenceTime; } interface At { at?: SequenceTime; } type MotionValueSegment = [ MotionValue, UnresolvedValueKeyframe | UnresolvedValueKeyframe[] ]; type MotionValueSegmentWithTransition = [ MotionValue, UnresolvedValueKeyframe | UnresolvedValueKeyframe[], Transition & At ]; type DOMSegment = [ElementOrSelector, DOMKeyframesDefinition]; type DOMSegmentWithTransition = [ ElementOrSelector, DOMKeyframesDefinition, AnimationOptions & At ]; type ObjectSegment<O extends {} = {}> = [O, ObjectTarget<O>]; type ObjectSegmentWithTransition<O extends {} = {}> = [ O, ObjectTarget<O>, AnimationOptions & At ]; type Segment = ObjectSegment | ObjectSegmentWithTransition | SequenceLabel | SequenceLabelWithTime | MotionValueSegment | MotionValueSegmentWithTransition | DOMSegment | DOMSegmentWithTransition; type AnimationSequence = Segment[]; interface SequenceOptions extends AnimationPlaybackOptions { delay?: number; duration?: number; defaultTransition?: Transition; } interface AbsoluteKeyframe { value: string | number | null; at: number; easing?: Easing; } type ValueSequence = AbsoluteKeyframe[]; interface SequenceMap { [key: string]: ValueSequence; } type ResolvedAnimationDefinition = { keyframes: { [key: string]: UnresolvedValueKeyframe[]; }; transition: { [key: string]: Transition; }; }; type ResolvedAnimationDefinitions = Map<Element | MotionValue, ResolvedAnimationDefinition>; /** * Creates an animation function that is optionally scoped * to a specific element. */ declare function createScopedAnimate(scope?: AnimationScope): { (sequence: AnimationSequence, options?: SequenceOptions): AnimationPlaybackControlsWithThen; (value: string | MotionValue<string>, keyframes: string | GenericKeyframesTarget<string>, options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen; (value: number | MotionValue<number>, keyframes: number | GenericKeyframesTarget<number>, options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen; <V>(value: V | MotionValue<V>, keyframes: V | GenericKeyframesTarget<V>, options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen; (element: ElementOrSelector, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen; <O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: AnimationOptions): AnimationPlaybackControlsWithThen; }; declare const animate: { (sequence: AnimationSequence, options?: SequenceOptions): AnimationPlaybackControlsWithThen; (value: string | MotionValue<string>, keyframes: string | GenericKeyframesTarget<string>, options?: ValueAnimationTransition<string>): AnimationPlaybackControlsWithThen; (value: number | MotionValue<number>, keyframes: number | GenericKeyframesTarget<number>, options?: ValueAnimationTransition<number>): AnimationPlaybackControlsWithThen; <V>(value: V | MotionValue<V>, keyframes: V | GenericKeyframesTarget<V>, options?: ValueAnimationTransition<V>): AnimationPlaybackControlsWithThen; (element: ElementOrSelector, keyframes: DOMKeyframesDefinition, options?: AnimationOptions): AnimationPlaybackControlsWithThen; <O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: AnimationOptions): AnimationPlaybackControlsWithThen; }; declare const animateMini: (elementOrSelector: ElementOrSelector, keyframes: DOMKeyframesDefinition, options?: AnimationOptions) => AnimationPlaybackControlsWithThen; declare function scrollInfo(onScroll: OnScrollInfo, { container, ...options }?: ScrollInfoOptions): () => void; type ViewChangeHandler = (entry: IntersectionObserverEntry) => void; type MarginValue = `${number}${"px" | "%"}`; type MarginType = MarginValue | `${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue}` | `${MarginValue} ${MarginValue} ${MarginValue} ${MarginValue}`; interface InViewOptions { root?: Element | Document; margin?: MarginType; amount?: "some" | "all" | number; } declare function inView(elementOrSelector: ElementOrSelector, onStart: (element: Element, entry: IntersectionObserverEntry) => void | ViewChangeHandler, { root, margin: rootMargin, amount }?: InViewOptions): VoidFunction; declare const anticipate: (p: number) => number; declare const backOut: (t: number) => number; declare const backIn: motion_dom.EasingFunction; declare const backInOut: motion_dom.EasingFunction; declare const circIn: EasingFunction; declare const circOut: EasingFunction; declare const circInOut: EasingFunction; declare function cubicBezier(mX1: number, mY1: number, mX2: number, mY2: number): (t: number) => number; declare const easeIn: (t: number) => number; declare const easeOut: (t: number) => number; declare const easeInOut: (t: number) => number; declare const mirrorEasing: EasingModifier; declare const reverseEasing: EasingModifier; type Direction = "start" | "end"; declare function steps(numSteps: number, direction?: Direction): EasingFunction; declare function inertia({ keyframes, velocity, power, timeConstant, bounceDamping, bounceStiffness, modifyTarget, min, max, restDelta, restSpeed, }: ValueAnimationOptions<number>): KeyframeGenerator<number>; declare function keyframes<T extends string | number>({ duration, keyframes: keyframeValues, times, ease, }: ValueAnimationOptions<T>): KeyframeGenerator<T>; declare function spring(optionsOrVisualDuration?: ValueAnimationOptions<number> | number, bounce?: number): KeyframeGenerator<number>; declare namespace spring { var applyToOptions: (options: Transition) => Transition; } type StaggerOrigin = "first" | "last" | "center" | number; type StaggerOptions = { startDelay?: number; from?: StaggerOrigin; ease?: Easing; }; declare function stagger(duration?: number, { startDelay, from, ease }?: StaggerOptions): DynamicOption<number>; declare const clamp: (min: number, max: number, v: number) => number; type DelayedFunction = (overshoot: number) => void; /** * Timeout defined in ms */ declare function delay(callback: DelayedFunction, timeout: number): () => void; declare const distance: (a: number, b: number) => number; declare function distance2D(a: Point, b: Point): number; type Mix<T> = (v: number) => T; type MixerFactory<T> = (from: T, to: T) => Mix<T>; interface InterpolateOptions<T> { clamp?: boolean; ease?: EasingFunction | EasingFunction[]; mixer?: MixerFactory<T>; } /** * Create a function that maps from a numerical input array to a generic output array. * * Accepts: * - Numbers * - Colors (hex, hsl, hsla, rgb, rgba) * - Complex (combinations of one or more numbers or strings) * * ```jsx * const mixColor = interpolate([0, 1], ['#fff', '#000']) * * mixColor(0.5) // 'rgba(128, 128, 128, 1)' * ``` * * TODO Revist this approach once we've moved to data models for values, * probably not needed to pregenerate mixer functions. * * @public */ declare function interpolate<T>(input: number[], output: T[], { clamp: isClamp, ease, mixer }?: InterpolateOptions<T>): (v: number) => T; type Mixer<T> = (p: number) => T; declare function mix<T>(from: T, to: T): Mixer<T>; declare function mix(from: number, to: number, p: number): number; declare const pipe: (...transformers: Function[]) => Function; /** * @public */ interface TransformOptions<T> { /** * Clamp values to within the given range. Defaults to `true` * * @public */ clamp?: boolean; /** * Easing functions to use on the interpolations between each value in the input and output ranges. * * If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition **between** each. * * @public */ ease?: EasingFunction | EasingFunction[]; /** * Provide a function that can interpolate between any two values in the provided range. * * @public */ mixer?: (from: T, to: T) => (v: number) => any; } /** * Transforms numbers into other values by mapping them from an input range to an output range. * Returns the type of the input provided. * * @remarks * * Given an input range of `[0, 200]` and an output range of * `[0, 1]`, this function will return a value between `0` and `1`. * The input range must be a linear series of numbers. The output range * can be any supported value type, such as numbers, colors, shadows, arrays, objects and more. * Every value in the output range must be of the same type and in the same format. * * ```jsx * import * as React from "react" * import { transform } from "framer-motion" * * export function MyComponent() { * const inputRange = [0, 200] * const outputRange = [0, 1] * const output = transform(100, inputRange, outputRange) * * // Returns 0.5 * return <div>{output}</div> * } * ``` * * @param inputValue - A number to transform between the input and output ranges. * @param inputRange - A linear series of numbers (either all increasing or decreasing). * @param outputRange - A series of numbers, colors, strings, or arrays/objects of those. Must be the same length as `inputRange`. * @param options - Clamp: Clamp values to within the given range. Defaults to `true`. * * @public */ declare function transform<T>(inputValue: number, inputRange: number[], outputRange: T[], options?: TransformOptions<T>): T; /** * * Transforms numbers into other values by mapping them from an input range to an output range. * * Given an input range of `[0, 200]` and an output range of * `[0, 1]`, this function will return a value between `0` and `1`. * The input range must be a linear series of numbers. The output range * can be any supported value type, such as numbers, colors, shadows, arrays, objects and more. * Every value in the output range must be of the same type and in the same format. * * ```jsx * import * as React from "react" * import { Frame, transform } from "framer" * * export function MyComponent() { * const inputRange = [-200, -100, 100, 200] * const outputRange = [0, 1, 1, 0] * const convertRange = transform(inputRange, outputRange) * const output = convertRange(-150) * * // Returns 0.5 * return <div>{output}</div> * } * * ``` * * @param inputRange - A linear series of numbers (either all increasing or decreasing). * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`. * @param options - Clamp: clamp values to within the given range. Defaults to `true`. * * @public */ declare function transform<T>(inputRange: number[], outputRange: T[], options?: TransformOptions<T>): (inputValue: number) => T; declare const wrap: (min: number, max: number, v: number) => number; declare const m: (<Props, TagName extends string = "div">(Component: string | TagName | React$1.ComponentType<Props>, { forwardMotionProps }?: { forwardMotionProps: boolean; }) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "path" | "image" | "circle" | "switch" | "stop" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] : React$1.ComponentType<Omit<MotionComponentProps<Props>, "children"> & { children?: ("children" extends keyof Props ? Props[keyof Props & "children"] | MotionComponentProps<Props>[keyof Props & "children"] : MotionComponentProps<Props>["children"]) | undefined; }>) & HTMLMotionComponents & SVGMotionComponents & { create: <Props, TagName extends string = "div">(Component: string | TagName | React$1.ComponentType<Props>, { forwardMotionProps }?: { forwardMotionProps: boolean; }) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "path" | "image" | "circle" | "switch" | "stop" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] : React$1.ComponentType<Omit<MotionComponentProps<Props>, "children"> & { children?: ("children" extends keyof Props ? Props[keyof Props & "children"] | MotionComponentProps<Props>[keyof Props & "children"] : MotionComponentProps<Props>["children"]) | undefined; }>; }; declare const motion: (<Props, TagName extends string = "div">(Component: string | TagName | React$1.ComponentType<Props>, { forwardMotionProps }?: { forwardMotionProps: boolean; }) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "path" | "image" | "circle" | "switch" | "stop" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] : React$1.ComponentType<Omit<MotionComponentProps<Props>, "children"> & { children?: ("children" extends keyof Props ? Props[keyof Props & "children"] | MotionComponentProps<Props>[keyof Props & "children"] : MotionComponentProps<Props>["children"]) | undefined; }>) & HTMLMotionComponents & SVGMotionComponents & { create: <Props, TagName extends string = "div">(Component: string | TagName | React$1.ComponentType<Props>, { forwardMotionProps }?: { forwardMotionProps: boolean; }) => TagName extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "text" | "animate" | "path" | "image" | "circle" | "switch" | "stop" | "svg" | keyof HTMLElements | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "line" | "linearGradient" | "metadata" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "textPath" | "tspan" | "use" | "view" ? DOMMotionComponents[TagName] : React$1.ComponentType<Omit<MotionComponentProps<Props>, "children"> & { children?: ("children" extends keyof Props ? Props[keyof Props & "children"] | MotionComponentProps<Props>[keyof Props & "children"] : MotionComponentProps<Props>["children"]) | undefined; }>; }; type EventListenerWithPointInfo = (e: PointerEvent, info: EventInfo) => void; declare const addPointerInfo: (handler: EventListenerWithPointInfo) => EventListener; declare function addPointerEvent(target: EventTarget, eventName: string, handler: EventListenerWithPointInfo, options?: AddEventListenerOptions): () => void; declare const animations: FeaturePackages; declare function calcLength(axis: Axis): number; declare const createBox: () => Box; declare const isBrowser: boolean; declare function useForceUpdate(): [VoidFunction, number]; declare const useIsomorphicLayoutEffect: typeof useEffect; declare function useUnmountEffect(callback: () => void): void; declare const isMotionValue: (value: any) => value is MotionValue<any>; /** * @public */ declare const domAnimation: FeatureBundle; /** * @public */ declare const domMax: FeatureBundle; /** * @public */ declare const domMin: FeatureBundle; declare function useMotionValueEvent<V, EventName extends keyof MotionValueEventCallbacks<V>>(value: MotionValue<V>, event: EventName, callback: MotionValueEventCallbacks<V>[EventName]): void; /** * @deprecated useElementScroll is deprecated. Convert to useScroll({ container: ref }) */ declare function useElementScroll(ref: RefObject<HTMLElement | null>): { scrollX: motion_dom.MotionValue<number>; scrollY: motion_dom.MotionValue<number>; scrollXProgress: motion_dom.MotionValue<number>; scrollYProgress: motion_dom.MotionValue<number>; }; /** * @deprecated useViewportScroll is deprecated. Convert to useScroll() */ declare function useViewportScroll(): { scrollX: motion_dom.MotionValue<number>; scrollY: motion_dom.MotionValue<number>; scrollXProgress: motion_dom.MotionValue<number>; scrollYProgress: motion_dom.MotionValue<number>; }; /** * Combine multiple motion values into a new one using a string template literal. * * ```jsx * import { * motion, * useSpring, * useMotionValue, * useMotionTemplate * } from "framer-motion" * * function Component() { * const shadowX = useSpring(0) * const shadowY = useMotionValue(0) * const shadow = useMotionTemplate`drop-shadow(${shadowX}px ${shadowY}px 20px rgba(0,0,0,0.3))` * * return <motion.div style={{ filter: shadow }} /> * } * ``` * * @public */ declare function useMotionTemplate(fragments: TemplateStringsArray, ...values: Array<MotionValue | number | string>): MotionValue<string>; /** * Creates a `MotionValue` to track the state and velocity of a value. * * Usually, these are created automatically. For advanced use-cases, like use with `useTransform`, you can create `MotionValue`s externally and pass them into the animated component via the `style` prop. * * ```jsx * export const MyComponent = () => { * const scale = useMotionValue(1) * * return <motion.div style={{ scale }} /> * } * ``` * * @param initial - The initial state. * * @public */ declare function useMotionValue<T>(initial: T): MotionValue<T>; interface UseScrollOptions extends Omit<ScrollInfoOptions, "container" | "target"> { container?: RefObject<HTMLElement | null>; target?: RefObject<HTMLElement | null>; layoutEffect?: boolean; } declare function useScroll({ container, target, layoutEffect, ...options }?: UseScrollOptions): { scrollX: motion_dom.MotionValue<number>; scrollY: motion_dom.MotionValue<number>; scrollXProgress: motion_dom.MotionValue<number>; scrollYProgress: motion_dom.MotionValue<number>; }; /** * Creates a `MotionValue` that, when `set`, will use a spring animation to animate to its new state. * * It can either work as a stand-alone `MotionValue` by initialising it with a value, or as a subscriber * to another `MotionValue`. * * @remarks * * ```jsx * const x = useSpring(0, { stiffness: 300 }) * const y = useSpring(x, { damping: 10 }) * ``` * * @param inputValue - `MotionValue` or number. If provided a `MotionValue`, when the input `MotionValue` changes, the created `MotionValue` will spring towards that value. * @param springConfig - Configuration options for the spring. * @returns `MotionValue` * * @public */ declare function useSpring(source: MotionValue<string>, config?: SpringOptions): MotionValue<string>; declare function useSpring(source: string, config?: SpringOptions): MotionValue<string>; declare function useSpring(source: MotionValue<number>, config?: SpringOptions): MotionValue<number>; declare function useSpring(source: number, config?: SpringOptions): MotionValue<number>; declare function useTime(): motion_dom.MotionValue<number>; type InputRange = number[]; type SingleTransformer<I, O> = (input: I) => O; type MultiTransformer<I, O> = (input: I[]) => O; /** * Create a `MotionValue` that transforms the output of another `MotionValue` by mapping it from one range of values into another. * * @remarks * * Given an input range of `[-200, -100, 100, 200]` and an output range of * `[0, 1, 1, 0]`, the returned `MotionValue` will: * * - When provided a value between `-200` and `-100`, will return a value between `0` and `1`. * - When provided a value between `-100` and `100`, will return `1`. * - When provided a value between `100` and `200`, will return a value between `1` and `0` * * * The input range must be a linear series of numbers. The output range * can be any value type supported by Motion: numbers, colors, shadows, etc. * * Every value in the output range must be of the same type and in the same format. * * ```jsx * export const MyComponent = () => { * const x = useMotionValue(0) * const xRange = [-200, -100, 100, 200] * const opacityRange = [0, 1, 1, 0] * const opacity = useTransform(x, xRange, opacityRange) * * return ( * <motion.div * animate={{ x: 200 }} * style={{ opacity, x }} * /> * ) * } * ``` * * @param inputValue - `MotionValue` * @param inputRange - A linear series of numbers (either all increasing or decreasing) * @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`. * @param options - * * - clamp: boolean. Clamp values to within the given range. Defaults to `true` * - ease: EasingFunction[]. Easing functions to use on the interpolations between each value in the input and output ranges. If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition between each. * * @returns `MotionValue` * * @public */ declare function useTransform<I, O>(value: MotionValue<number>, inputRange: InputRange, outputRange: O[], options?: TransformOptions<O>): MotionValue<O>; /** * Create a `MotionValue` that transforms the output of another `MotionValue` through a function. * In this example, `y` will always be double `x`. * * ```jsx * export const MyComponent = () => { * const x = useMotionValue(10) * const y = useTransform(x, value => value * 2) * * return <motion.div style={{ x, y }} /> * } * ``` * * @param input - A `MotionValue` that will pass its latest value through `transform` to update the returned `MotionValue`. * @param transform - A function that accepts the latest value from `input` and returns a new value. * @returns `MotionValue` * * @public */ declare function useTransform<I, O>(input: MotionValue<I>, transformer: SingleTransformer<I, O>): MotionValue<O>; /** * Pass an array of `MotionValue`s and a function to combine them. In this example, `z` will be the `x` multiplied by `y`. * * ```jsx * export const MyComponent = () => { * const x = useMotionValue(0) * const y = useMotionValue(0) * const z = useTransform([x, y], ([latestX, latestY]) => latestX * latestY) * * return <motion.div style={{ x, y, z }} /> * } * ``` * * @param input - An array of `MotionValue`s that will pass their latest values through `transform` to update the returned `MotionValue`. * @param transform - A function that accepts the latest values from `input` and returns a new value. * @returns `MotionValue` * * @public */ declare function useTransform<I, O>(input: MotionValue<string>[] | MotionValue<number>[] | MotionValue<string | number>[], transformer: MultiTransformer<I, O>): MotionValue<O>; declare function useTransform<I, O>(transformer: () => O): MotionValue<O>; /** * Creates a `MotionValue` that updates when the velocity of the provided `MotionValue` changes. * * ```javascript * const x = useMotionValue(0) * const xVelocity = useVelocity(x) * const xAcceleration = useVelocity(xVelocity) * ``` * * @public */ declare function useVelocity(value: MotionValue<number>): MotionValue<number>; interface WillChange extends MotionValue<string> { add(name: string): void; } declare function useWillChange(): WillChange; declare class WillChangeMotionValue extends MotionValue<string> implements WillChange { private values; add(name: string): void; private update; } /** * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself * * TODO: Remove and move to library */ declare function resolveMotionValue(value?: string | number | CustomValueType | MotionValue): string | number; /** * A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting. * * This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing * `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion. * * It will actively respond to changes and re-render your components with the latest setting. * * ```jsx * export function Sidebar({ isOpen }) { * const shouldReduceMotion = useReducedMotion() * const closedX = shouldReduceMotion ? 0 : "-100%" * * return ( * <motion.div animate={{ * opacity: isOpen ? 1 : 0, * x: isOpen ? 0 : closedX * }} /> * ) * } * ``` * * @return boolean * * @public */ declare function useReducedMotion(): boolean | null; declare function useReducedMotionConfig(): boolean | null; interface ValueAnimationOptionsWithDefaults<T extends string | number> extends ValueAnimationOptionsWithRenderContext<T> { autoplay: boolean; delay: number; repeat: number; repeatDelay: number; repeatType: RepeatType; } declare abstract class BaseAnimation<T extends string | number, Resolved> implements AnimationPlaybackControls { protected options: ValueAnimationOptionsWithDefaults<T>; protected resolveFinishedPromise: VoidFunction; protected currentFinishedPromise: Promise<void>; protected isStopped: boolean; protected _resolved: Resolved & { keyframes: ResolvedKeyframes<T>; }; protected hasAttemptedResolve: boolean; protected resolver: KeyframeResolver<T>; private createdAt; private resolvedAt; constructor({ autoplay, delay, type, repeat, repeatDelay, repeatType, ...options }: ValueAnimationOptions<T>); /** * This method uses the createdAt and resolvedAt to calculate the * animation startTime. *Ideally*, we would use the createdAt time as t=0 * as the following frame would then be the first frame of the animation in * progress, which would feel snappier. * * However, if there's a delay (main thread work) between the creation of * the animation and the first commited frame, we prefer to use resolvedAt * to avoid a sudden jump into the animation. */ calcStartTime(): number; protected abstract initPlayback(keyframes: ResolvedKeyframes<T>, finalKeyframe?: T): Resolved | false; abstract play(): void; abstract pause(): void; abstract stop(): void; abstract cancel(): void; abstract complete(): void; abstract get speed(): number; abstract set speed(newSpeed: number); abstract get time(): number; abstract set time(newTime: number); abstract get duration(): number; abstract get state(): AnimationPlayState; abstract get startTime(): number | null; abstract get finished(): Promise<void>; /** * A getter for resolved data. If keyframes are not yet resolved, accessing * this.resolved will synchronously flush all pending keyframe resolvers. * This is a deoptimisation, but at its worst still batches read/writes. */ get resolved(): (Resolved & { keyframes: ResolvedKeyframes<T>; finalKeyframe?: T; }) | undefined; /** * A method to be called when the keyframes resolver completes. This method * will check if its possible to run the animation and, if not, skip it. * Otherwise, it will call initPlayback on the implementing class. */ protected onKeyframesResolved(keyframes: ResolvedKeyframes<T>, finalKeyframe?: T): void; onPostResolved(): void; /** * Allows the returned animation to be awaited or promise-chained. Currently * resolves when the animation finishes at all but in a future update could/should * reject if its cancels. */ then(resolve: VoidFunction, reject?: VoidFunction): Promise<void>; flatten(): void; protected updateFinishedPromise(): void; } interface AcceleratedValueAnimationOptions<T extends string | number = number> extends ValueAnimationOptions<T> { name: string; motionValue: MotionValue<T>; } interface ResolvedAcceleratedAnimation { animation: Animation; duration: number; times: ValueAnimationOptions["times"]; type: ValueAnimationOptions["type"]; ease: ValueAnimationOptions["ease"]; keyframes: string[] | number[]; } declare class AcceleratedAnimation<T extends string | number> extends BaseAnimation<T, ResolvedAcceleratedAnimation> { protected options: ValueAnimationOptionsWithDefaults<T> & { name: string; motionValue: MotionValue<T>; }; constructor(options: ValueAnimationOptionsWithRenderContext<T>); /** * An AnimationTimline to attach to the WAAPI animation once it's created. */ private pendingTimeline; protected initPlayback(keyframes: ResolvedKeyframes<T>, finalKeyframe: T): false | { animation: Animation; duration: number; times: number[] | undefined; type: motion_dom.AnimationGeneratorType | undefined; ease: motion_dom.Easing | motion_dom.Easing[] | undefined; keyframes: number[] | string[]; }; get duration(): number; get time(): number; set time(newTime: number); get speed(): number; get finished(): Promise<void>; set speed(newSpeed: number); get state(): AnimationPlayState; get startTime(): number | null; /** * Replace the default DocumentTimeline with another AnimationTimeline. * Currently used for scroll animations. */ attachTimeline(timeline: any): (any: void) => void; play(): void; pause(): void; stop(): void; complete(): void; cancel(): void; static supports(options: ValueAnimationOptionsWithRenderContext): options is AcceleratedValueAnimationOptions; } interface ResolvedData<T extends string | number> { generator: KeyframeGenerator<T>; mirroredGenerator: KeyframeGenerator<T> | undefined; mapPercentToKeyframes: ((v: number) => T) | undefined; /** * Duration of the animation as calculated by the generator. */ calculatedDuration: number; /** * Duration of the animation plus repeatDelay. */ resolvedDuration: number; /** * Total duration of the animation including repeats. */ totalDuration: number; } /** * Animation that runs on the main thread. Designed to be WAAPI-spec in the subset of * features we expose publically. Mostly the compatibility is to ensure visual identity * between both WAAPI and main thread animations. */ declare class MainThreadAnimation<T extends string | number> extends BaseAnimation<T, ResolvedData<T>> { /** * The driver that's controlling the animation loop. Normally this is a requestAnimationFrame loop * but in tests we can pass in a synchronous loop. */ private driver?; /** * The time at which the animation was paused. */ private holdTime; /** * The time at which the animation was cancelled. */ private cancelTime; /** * The current time of the animation. */ private currentTime; /** * Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed. */ private playbackSpeed; /** * The state of the animation to apply when the animation is resolved. This * allows calls to the public API to control the animation before it is resolved, * without us having to resolve it first. */ private pendingPlayState; /** * The time at which the animation was started. */ startTime: number | null; constructor(options: ValueAnimationOptions<T>); flatten(): void; protected initPlayback(keyframes: ResolvedKeyframes<T>): { generator: KeyframeGenerator<any>; mirroredGenerator: KeyframeGenerator<T> | undefined; mapPercentToKeyframes: ((v: number) => T) | undefined; calculatedDuration: number; resolvedDuration: number; totalDuration: number; }; onPostResolved(): void; tick(timestamp: number, sample?: boolean): { done: boolean; value: T; }; state: AnimationPlayState; get duration(): number; get time(): number; set time(newTime: number); get speed(): number; set speed(newSpeed: number); play(): void; pause(): void; /** * This method is bound to the instance to fix a pattern where * animation.stop is returned as a reference from a useEffect. */ stop: () => void; complete(): void; finish(): void; cancel(): void; private teardown; private stopDriver; sample(time: number): AnimationState<T>; get finished(): Promise<void>; } declare function animateValue(options: ValueAnimationOptionsWithRenderContext<any>): MainThreadAnimation<any>; /** * @public */ declare function animationControls(): AnimationControls; declare function useAnimate<T extends Element = any>(): [AnimationScope<T>, { (sequence: AnimationSequence, options?: SequenceOptions | undefined): motion_dom.AnimationPlaybackControlsWithThen; (value: string | motion_dom.MotionValue<string>, keyframes: string | GenericKeyframesTarget<string>, options?: motion_dom.ValueAnimationTransition<string> | undefined): motion_dom.AnimationPlaybackControlsWithThen; (value: number | motion_dom.MotionValue<number>, keyframes: number | GenericKeyframesTarget<number>, options?: motion_dom.ValueAnimationTransition<number> | undefined): motion_dom.AnimationPlaybackControlsWithThen; <V>(value: V | motion_dom.MotionValue<V>, keyframes: V | GenericKeyframesTarget<V>, options?: motion_dom.ValueAnimationTransition<V> | undefined): motion_dom.AnimationPlaybackControlsWithThen; (element: motion_dom.ElementOrSelector, keyframes: motion_dom.DOMKeyframesDefinition, options?: motion_dom.AnimationOptions | undefined): motion_dom.AnimationPlaybackControlsWithThen; <O extends {}>(object: O | O[], keyframes: ObjectTarget<O>, options?: motion_dom.AnimationOptions | undefined): motion_dom.AnimationPlaybackControlsWithThen; }]; declare function useAnimateMini<T extends Element = any>(): [AnimationScope<T>, (elementOrSelector: motion_dom.ElementOrSelector, keyframes: motion_dom.DOMKeyframesDefinition, options?: motion_dom.AnimationOptions | undefined) => motion_dom.AnimationPlaybackControlsWithThen]; /** * Creates `AnimationControls`, which can be used to manually start, stop * and sequence animations on one or more components. * * The returned `AnimationControls` should be passed to the `animate` property * of the components you want to animate. * * These components can then be animated with the `start` method. * * ```jsx * import * as React from 'react' * import { motion, useAnimation } from 'framer-motion' * * export function MyComponent(props) { * const controls = useAnimation() * * controls.start({ * x: 100, * transition: { duration: 0.5 }, * }) * * return <motion.div animate={controls} /> * } * ``` * * @returns Animation controller with `start` and `stop` methods * * @public */ declare function useAnimationControls(): AnimationControls; declare const useAnimation: typeof useAnimationControls; declare function animateVisualElement(visualElement: VisualElement, definition: AnimationDefinition, options?: VisualElementAnimationOptions): Promise<void>; type SafeToRemove = () => void; type AlwaysPresent = [true, null]; type Present = [true]; type NotPresent = [false, SafeToRemove]; /** * When a component is the child of `AnimatePresence`, it can use `usePresence` * to access information about whether it's still present in the React tree. * * ```jsx * import { usePresence } from "framer-motion" * * export const Component = () => { * const [isPresent, safeToRemove] = usePresence() * * useEffect(() => { * !isPresent && setTimeout(safeToRemove, 1000) * }, [isPresent]) * * return <div /> * } * ``` * * If `isPresent` is `false`, it means that a component has been removed the tree, but * `AnimatePresence` won't really remove it until `safeToRemove` has been called. * * @public */ declare function usePresence(subscribe?: boolean