motion-dom 12.17.2 → 12.18.1

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 (2) hide show
  1. package/dist/index.d.ts +1307 -94
  2. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Box, Easing, EasingFunction, BezierDefinition } from 'motion-utils';
1
+ import { Box, Easing, EasingFunction, BezierDefinition, Point, BoundingBox, Axis } from 'motion-utils';
2
2
 
3
3
  interface SVGAttributes {
4
4
  accentHeight?: number | string | undefined;
@@ -364,7 +364,7 @@ interface ValueAnimationOptions<V extends string | number = number> extends Valu
364
364
  element?: any;
365
365
  name?: string;
366
366
  motionValue?: MotionValue<V>;
367
- from?: V;
367
+ from?: any;
368
368
  isHandoff?: boolean;
369
369
  allowFlatten?: boolean;
370
370
  finalKeyframe?: V;
@@ -373,7 +373,8 @@ type GeneratorFactoryFunction = (options: ValueAnimationOptions<any>) => Keyfram
373
373
  interface GeneratorFactory extends GeneratorFactoryFunction {
374
374
  applyToOptions?: (options: Transition) => Transition;
375
375
  }
376
- type AnimationGeneratorType = GeneratorFactory | "decay" | "spring" | "keyframes" | "tween" | "inertia";
376
+ type AnimationGeneratorName = "decay" | "spring" | "keyframes" | "tween" | "inertia";
377
+ type AnimationGeneratorType = GeneratorFactory | AnimationGeneratorName | false;
377
378
  interface AnimationPlaybackLifecycles<V> {
378
379
  onUpdate?: (latest: V) => void;
379
380
  onPlay?: () => void;
@@ -381,84 +382,284 @@ interface AnimationPlaybackLifecycles<V> {
381
382
  onRepeat?: () => void;
382
383
  onStop?: () => void;
383
384
  }
384
- interface ValueAnimationTransition<V = any> extends Transition, AnimationPlaybackLifecycles<V> {
385
+ interface ValueAnimationTransition<V = any> extends ValueTransition, AnimationPlaybackLifecycles<V> {
385
386
  isSync?: boolean;
386
387
  }
387
388
  type RepeatType = "loop" | "reverse" | "mirror";
388
389
  interface AnimationPlaybackOptions {
390
+ /**
391
+ * The number of times to repeat the transition. Set to `Infinity` for perpetual repeating.
392
+ *
393
+ * Without setting `repeatType`, this will loop the animation.
394
+ *
395
+ * @public
396
+ */
389
397
  repeat?: number;
398
+ /**
399
+ * How to repeat the animation. This can be either:
400
+ *
401
+ * "loop": Repeats the animation from the start
402
+ *
403
+ * "reverse": Alternates between forward and backwards playback
404
+ *
405
+ * "mirror": Switches `from` and `to` alternately
406
+ *
407
+ * @public
408
+ */
390
409
  repeatType?: RepeatType;
410
+ /**
411
+ * When repeating an animation, `repeatDelay` will set the
412
+ * duration of the time to wait, in seconds, between each repetition.
413
+ *
414
+ * @public
415
+ */
391
416
  repeatDelay?: number;
392
417
  }
393
418
  interface VelocityOptions {
394
419
  velocity?: number;
420
+ /**
421
+ * End animation if absolute speed (in units per second) drops below this
422
+ * value and delta is smaller than `restDelta`. Set to `0.01` by default.
423
+ *
424
+ * @public
425
+ */
395
426
  restSpeed?: number;
427
+ /**
428
+ * End animation if distance is below this value and speed is below
429
+ * `restSpeed`. When animation ends, spring gets "snapped" to. Set to
430
+ * `0.01` by default.
431
+ *
432
+ * @public
433
+ */
396
434
  restDelta?: number;
397
435
  }
398
436
  interface DurationSpringOptions {
437
+ /**
438
+ * The total duration of the animation. Set to `0.3` by default.
439
+ *
440
+ * @public
441
+ */
399
442
  duration?: number;
443
+ /**
444
+ * If visualDuration is set, this will override duration.
445
+ *
446
+ * The visual duration is a time, set in seconds, that the animation will take to visually appear to reach its target.
447
+ *
448
+ * In other words, the bulk of the transition will occur before this time, and the "bouncy bit" will mostly happen after.
449
+ *
450
+ * This makes it easier to edit a spring, as well as visually coordinate it with other time-based animations.
451
+ *
452
+ * @public
453
+ */
400
454
  visualDuration?: number;
455
+ /**
456
+ * `bounce` determines the "bounciness" of a spring animation.
457
+ *
458
+ * `0` is no bounce, and `1` is extremely bouncy.
459
+ *
460
+ * If `duration` is set, this defaults to `0.25`.
461
+ *
462
+ * Note: `bounce` and `duration` will be overridden if `stiffness`, `damping` or `mass` are set.
463
+ *
464
+ * @public
465
+ */
401
466
  bounce?: number;
402
467
  }
403
468
  interface SpringOptions extends DurationSpringOptions, VelocityOptions {
469
+ /**
470
+ * Stiffness of the spring. Higher values will create more sudden movement.
471
+ * Set to `100` by default.
472
+ *
473
+ * @public
474
+ */
404
475
  stiffness?: number;
476
+ /**
477
+ * Strength of opposing force. If set to 0, spring will oscillate
478
+ * indefinitely. Set to `10` by default.
479
+ *
480
+ * @public
481
+ */
405
482
  damping?: number;
483
+ /**
484
+ * Mass of the moving object. Higher values will result in more lethargic
485
+ * movement. Set to `1` by default.
486
+ *
487
+ * @public
488
+ */
406
489
  mass?: number;
407
490
  }
408
491
  interface DecayOptions extends VelocityOptions {
409
492
  keyframes?: number[];
493
+ /**
494
+ * A higher power value equals a further target. Set to `0.8` by default.
495
+ *
496
+ * @public
497
+ */
410
498
  power?: number;
499
+ /**
500
+ * Adjusting the time constant will change the duration of the
501
+ * deceleration, thereby affecting its feel. Set to `700` by default.
502
+ *
503
+ * @public
504
+ */
411
505
  timeConstant?: number;
506
+ /**
507
+ * A function that receives the automatically-calculated target and returns a new one. Useful for snapping the target to a grid.
508
+ *
509
+ * @public
510
+ */
412
511
  modifyTarget?: (v: number) => number;
413
512
  }
414
513
  interface InertiaOptions extends DecayOptions {
514
+ /**
515
+ * If `min` or `max` is set, this affects the stiffness of the bounce
516
+ * spring. Higher values will create more sudden movement. Set to `500` by
517
+ * default.
518
+ *
519
+ * @public
520
+ */
415
521
  bounceStiffness?: number;
522
+ /**
523
+ * If `min` or `max` is set, this affects the damping of the bounce spring.
524
+ * If set to `0`, spring will oscillate indefinitely. Set to `10` by
525
+ * default.
526
+ *
527
+ * @public
528
+ */
416
529
  bounceDamping?: number;
530
+ /**
531
+ * Minimum constraint. If set, the value will "bump" against this value (or immediately spring to it if the animation starts as less than this value).
532
+ *
533
+ * @public
534
+ */
417
535
  min?: number;
536
+ /**
537
+ * Maximum constraint. If set, the value will "bump" against this value (or immediately snap to it, if the initial animation value exceeds this value).
538
+ *
539
+ * @public
540
+ */
418
541
  max?: number;
419
542
  }
543
+ interface AnimationOrchestrationOptions {
544
+ /**
545
+ * Delay the animation by this duration (in seconds). Defaults to `0`.
546
+ *
547
+ * @public
548
+ */
549
+ delay?: number;
550
+ /**
551
+ * Describes the relationship between the transition and its children. Set
552
+ * to `false` by default.
553
+ *
554
+ * @remarks
555
+ * When using variants, the transition can be scheduled in relation to its
556
+ * children with either `"beforeChildren"` to finish this transition before
557
+ * starting children transitions, `"afterChildren"` to finish children
558
+ * transitions before starting this transition.
559
+ *
560
+ * @public
561
+ */
562
+ when?: false | "beforeChildren" | "afterChildren" | string;
563
+ /**
564
+ * When using variants, children animations will start after this duration
565
+ * (in seconds). You can add the `transition` property to both the `Frame` and the `variant` directly. Adding it to the `variant` generally offers more flexibility, as it allows you to customize the delay per visual state.
566
+ *
567
+ * @public
568
+ */
569
+ delayChildren?: number;
570
+ /**
571
+ * When using variants, animations of child components can be staggered by this
572
+ * duration (in seconds).
573
+ *
574
+ * For instance, if `staggerChildren` is `0.01`, the first child will be
575
+ * delayed by `0` seconds, the second by `0.01`, the third by `0.02` and so
576
+ * on.
577
+ *
578
+ * The calculated stagger delay will be added to `delayChildren`.
579
+ *
580
+ * @public
581
+ */
582
+ staggerChildren?: number;
583
+ /**
584
+ * The direction in which to stagger children.
585
+ *
586
+ * A value of `1` staggers from the first to the last while `-1`
587
+ * staggers from the last to the first.
588
+ *
589
+ * @public
590
+ */
591
+ staggerDirection?: number;
592
+ }
420
593
  interface KeyframeOptions {
421
594
  ease?: Easing | Easing[];
422
595
  times?: number[];
423
596
  }
424
- interface Transition extends AnimationPlaybackOptions, Omit<SpringOptions, "keyframes">, Omit<InertiaOptions, "keyframes">, KeyframeOptions {
597
+ interface ValueTransition extends AnimationOrchestrationOptions, AnimationPlaybackOptions, Omit<SpringOptions, "keyframes">, Omit<InertiaOptions, "keyframes">, KeyframeOptions {
598
+ /**
599
+ * Delay the animation by this duration (in seconds). Defaults to `0`.
600
+ *
601
+ * @public
602
+ */
425
603
  delay?: number;
604
+ /**
605
+ * The duration of time already elapsed in the animation. Set to `0` by
606
+ * default.
607
+ */
426
608
  elapsed?: number;
427
609
  driver?: Driver;
610
+ /**
611
+ * Type of animation to use.
612
+ *
613
+ * - "tween": Duration-based animation with ease curve
614
+ * - "spring": Physics or duration-based spring animation
615
+ * - false: Use an instant animation
616
+ */
428
617
  type?: AnimationGeneratorType;
618
+ /**
619
+ * The duration of the tween animation. Set to `0.3` by default, 0r `0.8` if animating a series of keyframes.
620
+ *
621
+ * @public
622
+ */
429
623
  duration?: number;
430
624
  autoplay?: boolean;
431
625
  startTime?: number;
626
+ from?: any;
432
627
  }
628
+ type SVGForcedAttrTransitions = {
629
+ [K in keyof SVGForcedAttrProperties]: ValueTransition;
630
+ };
433
631
  type SVGPathTransitions = {
434
- [K in keyof SVGPathProperties]: Transition;
632
+ [K in keyof SVGPathProperties]: ValueTransition;
435
633
  };
436
634
  type SVGTransitions = {
437
- [K in keyof SVGAttributes]: Transition;
635
+ [K in keyof Omit<SVGAttributes, "from">]: ValueTransition;
438
636
  };
439
637
  type VariableTransitions = {
440
- [key: `--${string}`]: Transition;
638
+ [key: `--${string}`]: ValueTransition;
441
639
  };
442
640
  type StyleTransitions = {
443
- [K in keyof CSSStyleDeclarationWithTransform]?: Transition;
641
+ [K in keyof CSSStyleDeclarationWithTransform]?: ValueTransition;
444
642
  };
445
- type ValueKeyframe = string | number;
446
- type UnresolvedValueKeyframe = ValueKeyframe | null;
643
+ type ValueKeyframe<T extends string | number = string | number> = T;
644
+ type UnresolvedValueKeyframe<T extends string | number = string | number> = ValueKeyframe<T> | null;
447
645
  type ResolvedValueKeyframe = ValueKeyframe | ValueKeyframe[];
448
646
  type ValueKeyframesDefinition = ValueKeyframe | ValueKeyframe[] | UnresolvedValueKeyframe[];
449
647
  type StyleKeyframesDefinition = {
450
648
  [K in keyof CSSStyleDeclarationWithTransform]?: ValueKeyframesDefinition;
451
649
  };
452
650
  type SVGKeyframesDefinition = {
453
- [K in keyof SVGAttributes]?: ValueKeyframesDefinition;
651
+ [K in keyof Omit<SVGAttributes, "from">]?: ValueKeyframesDefinition;
454
652
  };
455
653
  type VariableKeyframesDefinition = {
456
654
  [key: `--${string}`]: ValueKeyframesDefinition;
457
655
  };
656
+ type SVGForcedAttrKeyframesDefinition = {
657
+ [K in keyof SVGForcedAttrProperties]?: ValueKeyframesDefinition;
658
+ };
458
659
  type SVGPathKeyframesDefinition = {
459
660
  [K in keyof SVGPathProperties]?: ValueKeyframesDefinition;
460
661
  };
461
- type DOMKeyframesDefinition = StyleKeyframesDefinition & SVGKeyframesDefinition & SVGPathKeyframesDefinition & VariableKeyframesDefinition;
662
+ type DOMKeyframesDefinition = StyleKeyframesDefinition & SVGKeyframesDefinition & SVGPathKeyframesDefinition & SVGForcedAttrKeyframesDefinition & VariableKeyframesDefinition;
462
663
  interface CSSStyleDeclarationWithTransform extends Omit<CSSStyleDeclaration, "direction" | "transition" | "x" | "y" | "z"> {
463
664
  x: number | string;
464
665
  y: number | string;
@@ -472,9 +673,12 @@ interface CSSStyleDeclarationWithTransform extends Omit<CSSStyleDeclaration, "di
472
673
  skewX: number | string;
473
674
  skewY: number | string;
474
675
  }
475
- type AnimationOptionsWithValueOverrides<V = any> = StyleTransitions & SVGPathTransitions & SVGTransitions & VariableTransitions & ValueAnimationTransition<V>;
676
+ type Transition<V = any> = StyleTransitions & SVGPathTransitions & SVGForcedAttrTransitions & SVGTransitions & VariableTransitions & ValueAnimationTransition<V> & {
677
+ default?: ValueTransition;
678
+ layout?: ValueTransition;
679
+ };
476
680
  type DynamicOption<T> = (i: number, total: number) => T;
477
- interface AnimationOptions extends Omit<AnimationOptionsWithValueOverrides, "delay"> {
681
+ interface AnimationOptions extends Omit<Transition, "delay"> {
478
682
  delay?: number | DynamicOption<number>;
479
683
  }
480
684
  interface TransformProperties {
@@ -501,6 +705,11 @@ interface TransformProperties {
501
705
  perspective?: string | number;
502
706
  transformPerspective?: string | number;
503
707
  }
708
+ interface SVGForcedAttrProperties {
709
+ attrX?: number;
710
+ attrY?: number;
711
+ attrScale?: number;
712
+ }
504
713
  interface SVGPathProperties {
505
714
  pathLength?: number;
506
715
  pathOffset?: number;
@@ -524,13 +733,13 @@ interface MotionValueEventCallbacks<V> {
524
733
  renderRequest: () => void;
525
734
  destroy: () => void;
526
735
  }
527
- interface ResolvedValues {
736
+ interface ResolvedValues$1 {
528
737
  [key: string]: string | number;
529
738
  }
530
739
  interface Owner {
531
740
  current: HTMLElement | unknown;
532
741
  getProps: () => {
533
- onUpdate?: (latest: ResolvedValues) => void;
742
+ onUpdate?: (latest: ResolvedValues$1) => void;
534
743
  transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
535
744
  };
536
745
  }
@@ -1061,7 +1270,7 @@ declare const supportedWaapiEasing: {
1061
1270
  backOut: string;
1062
1271
  };
1063
1272
 
1064
- declare function startWaapiAnimation(element: Element, valueName: string, keyframes: ValueKeyframesDefinition, { delay, duration, repeat, repeatType, ease, times, }?: Transition, pseudoElement?: string | undefined): Animation;
1273
+ declare function startWaapiAnimation(element: Element, valueName: string, keyframes: ValueKeyframesDefinition, { delay, duration, repeat, repeatType, ease, times, }?: ValueTransition, pseudoElement?: string | undefined): Animation;
1065
1274
 
1066
1275
  declare const supportsPartialKeyframes: () => boolean;
1067
1276
 
@@ -1153,6 +1362,93 @@ declare function isDragActive(): boolean;
1153
1362
 
1154
1363
  declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
1155
1364
 
1365
+ /**
1366
+ * Passed in to pan event handlers like `onPan` the `PanInfo` object contains
1367
+ * information about the current state of the tap gesture such as its
1368
+ * `point`, `delta`, `offset` and `velocity`.
1369
+ *
1370
+ * ```jsx
1371
+ * <motion.div onPan={(event, info) => {
1372
+ * console.log(info.point.x, info.point.y)
1373
+ * }} />
1374
+ * ```
1375
+ *
1376
+ * @public
1377
+ */
1378
+ interface PanInfo {
1379
+ /**
1380
+ * Contains `x` and `y` values for the current pan position relative
1381
+ * to the device or page.
1382
+ *
1383
+ * ```jsx
1384
+ * function onPan(event, info) {
1385
+ * console.log(info.point.x, info.point.y)
1386
+ * }
1387
+ *
1388
+ * <motion.div onPan={onPan} />
1389
+ * ```
1390
+ *
1391
+ * @public
1392
+ */
1393
+ point: Point;
1394
+ /**
1395
+ * Contains `x` and `y` values for the distance moved since
1396
+ * the last event.
1397
+ *
1398
+ * ```jsx
1399
+ * function onPan(event, info) {
1400
+ * console.log(info.delta.x, info.delta.y)
1401
+ * }
1402
+ *
1403
+ * <motion.div onPan={onPan} />
1404
+ * ```
1405
+ *
1406
+ * @public
1407
+ */
1408
+ delta: Point;
1409
+ /**
1410
+ * Contains `x` and `y` values for the distance moved from
1411
+ * the first pan event.
1412
+ *
1413
+ * ```jsx
1414
+ * function onPan(event, info) {
1415
+ * console.log(info.offset.x, info.offset.y)
1416
+ * }
1417
+ *
1418
+ * <motion.div onPan={onPan} />
1419
+ * ```
1420
+ *
1421
+ * @public
1422
+ */
1423
+ offset: Point;
1424
+ /**
1425
+ * Contains `x` and `y` values for the current velocity of the pointer, in px/ms.
1426
+ *
1427
+ * ```jsx
1428
+ * function onPan(event, info) {
1429
+ * console.log(info.velocity.x, info.velocity.y)
1430
+ * }
1431
+ *
1432
+ * <motion.div onPan={onPan} />
1433
+ * ```
1434
+ *
1435
+ * @public
1436
+ */
1437
+ velocity: Point;
1438
+ }
1439
+ type PanHandler = (event: Event, info: PanInfo) => void;
1440
+
1441
+ type DragHandler = (event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => void;
1442
+ type DragElastic = boolean | number | Partial<BoundingBox>;
1443
+ interface ResolvedConstraints {
1444
+ x: Partial<Axis>;
1445
+ y: Partial<Axis>;
1446
+ }
1447
+ interface ResolvedElastic {
1448
+ x: Axis;
1449
+ y: Axis;
1450
+ }
1451
+
1156
1452
  type ElementOrSelector = Element | Element[] | NodeListOf<Element> | string;
1157
1453
  interface WithQuerySelectorAll {
1158
1454
  querySelectorAll: Element["querySelectorAll"];
@@ -1252,79 +1548,1002 @@ declare const isNodeOrChild: (parent: Element | null, child?: Element | null) =>
1252
1548
 
1253
1549
  declare const isPrimaryPointer: (event: PointerEvent) => boolean;
1254
1550
 
1255
- declare function defaultTransformValue(name: string): number;
1256
- declare function parseValueFromTransform(transform: string | undefined, name: string): number;
1257
- declare const readTransformValue: (instance: HTMLElement, name: string) => number;
1258
-
1259
- declare function getComputedStyle(element: HTMLElement | SVGElement, name: string): string;
1260
-
1261
- declare function setStyle(element: HTMLElement | SVGElement, name: string, value: string | number): void;
1262
-
1263
- declare const positionalKeys: Set<string>;
1264
-
1551
+ interface EventInfo {
1552
+ point: Point;
1553
+ }
1265
1554
  /**
1266
- * Generate a list of every possible transform key.
1555
+ * A generic set of string/number values
1267
1556
  */
1268
- declare const transformPropOrder: string[];
1557
+ interface ResolvedValues {
1558
+ [key: string]: string | number;
1559
+ }
1560
+ type AnimationDefinition = VariantLabels | TargetAndTransition | TargetResolver;
1269
1561
  /**
1270
- * A quick lookup for transform props.
1562
+ * An object that specifies values to animate to. Each value may be set either as
1563
+ * a single value, or an array of values.
1564
+ *
1565
+ * It may also option contain these properties:
1566
+ *
1567
+ * - `transition`: Specifies transitions for all or individual values.
1568
+ * - `transitionEnd`: Specifies values to set when the animation finishes.
1569
+ *
1570
+ * ```jsx
1571
+ * const target = {
1572
+ * x: "0%",
1573
+ * opacity: 0,
1574
+ * transition: { duration: 1 },
1575
+ * transitionEnd: { display: "none" }
1576
+ * }
1577
+ * ```
1578
+ *
1579
+ * @public
1271
1580
  */
1272
- declare const transformProps: Set<string>;
1273
-
1274
- interface ResizeInfo {
1275
- width: number;
1276
- height: number;
1277
- }
1278
- type ResizeHandler<I> = (element: I, info: ResizeInfo) => void;
1279
- type WindowResizeHandler = (info: ResizeInfo) => void;
1280
-
1281
- declare function resize(onResize: WindowResizeHandler): VoidFunction;
1282
- declare function resize(target: ElementOrSelector, onResize: ResizeHandler<Element>): VoidFunction;
1283
-
1284
- type Update = (progress: number) => void;
1285
- declare function observeTimeline(update: Update, timeline: ProgressTimeline): () => void;
1286
-
1287
- declare const stepsOrder: StepId[];
1288
- type StepNames = (typeof stepsOrder)[number];
1289
-
1290
- interface Summary {
1291
- min: number;
1292
- max: number;
1293
- avg: number;
1294
- }
1295
- type FrameloopStatNames = "rate" | StepNames;
1296
- interface Stats<T> {
1297
- frameloop: {
1298
- [key in FrameloopStatNames]: T;
1299
- };
1300
- animations: {
1301
- mainThread: T;
1302
- waapi: T;
1303
- layout: T;
1304
- };
1305
- layoutProjection: {
1306
- nodes: T;
1307
- calculatedTargetDeltas: T;
1308
- calculatedProjections: T;
1309
- };
1310
- }
1311
- type StatsBuffer = number[];
1312
- type FrameStats = Stats<number>;
1313
- type StatsRecording = Stats<StatsBuffer>;
1314
- type StatsSummary = Stats<Summary>;
1315
-
1316
- declare function reportStats(): StatsSummary;
1317
- declare function recordStats(): typeof reportStats;
1318
-
1319
- declare const activeAnimations: {
1320
- layout: number;
1321
- mainThread: number;
1322
- waapi: number;
1323
- };
1324
-
1325
- type InactiveStatsBuffer = {
1326
- value: null;
1327
- addProjectionMetrics: null;
1581
+ type TargetAndTransition = DOMKeyframesDefinition & {
1582
+ transition?: Transition;
1583
+ transitionEnd?: ResolvedValues;
1584
+ };
1585
+ type TargetResolver = (custom: any, current: ResolvedValues, velocity: ResolvedValues) => TargetAndTransition | string;
1586
+ /**
1587
+ * Either a string, or array of strings, that reference variants defined via the `variants` prop.
1588
+ * @public
1589
+ */
1590
+ type VariantLabels = string | string[];
1591
+ type Variant = TargetAndTransition | TargetResolver;
1592
+ interface Variants {
1593
+ [key: string]: Variant;
1594
+ }
1595
+ /**
1596
+ * @deprecated
1597
+ */
1598
+ type LegacyAnimationControls = {
1599
+ /**
1600
+ * Subscribes a component's animation controls to this.
1601
+ *
1602
+ * @param controls - The controls to subscribe
1603
+ * @returns An unsubscribe function.
1604
+ */
1605
+ subscribe(visualElement: any): () => void;
1606
+ /**
1607
+ * Starts an animation on all linked components.
1608
+ *
1609
+ * @remarks
1610
+ *
1611
+ * ```jsx
1612
+ * controls.start("variantLabel")
1613
+ * controls.start({
1614
+ * x: 0,
1615
+ * transition: { duration: 1 }
1616
+ * })
1617
+ * ```
1618
+ *
1619
+ * @param definition - Properties or variant label to animate to
1620
+ * @param transition - Optional `transition` to apply to a variant
1621
+ * @returns - A `Promise` that resolves when all animations have completed.
1622
+ *
1623
+ * @public
1624
+ */
1625
+ start(definition: AnimationDefinition, transitionOverride?: Transition): Promise<any>;
1626
+ /**
1627
+ * Instantly set to a set of properties or a variant.
1628
+ *
1629
+ * ```jsx
1630
+ * // With properties
1631
+ * controls.set({ opacity: 0 })
1632
+ *
1633
+ * // With variants
1634
+ * controls.set("hidden")
1635
+ * ```
1636
+ *
1637
+ * @privateRemarks
1638
+ * We could perform a similar trick to `.start` where this can be called before mount
1639
+ * and we maintain a list of of pending actions that get applied on mount. But the
1640
+ * expectation of `set` is that it happens synchronously and this would be difficult
1641
+ * to do before any children have even attached themselves. It's also poor practise
1642
+ * and we should discourage render-synchronous `.start` calls rather than lean into this.
1643
+ *
1644
+ * @public
1645
+ */
1646
+ set(definition: AnimationDefinition): void;
1647
+ /**
1648
+ * Stops animations on all linked components.
1649
+ *
1650
+ * ```jsx
1651
+ * controls.stop()
1652
+ * ```
1653
+ *
1654
+ * @public
1655
+ */
1656
+ stop(): void;
1657
+ mount(): () => void;
1658
+ };
1659
+ interface MotionNodeAnimationOptions {
1660
+ /**
1661
+ * Properties, variant label or array of variant labels to start in.
1662
+ *
1663
+ * Set to `false` to initialise with the values in `animate` (disabling the mount animation)
1664
+ *
1665
+ * ```jsx
1666
+ * // As values
1667
+ * <motion.div initial={{ opacity: 1 }} />
1668
+ *
1669
+ * // As variant
1670
+ * <motion.div initial="visible" variants={variants} />
1671
+ *
1672
+ * // Multiple variants
1673
+ * <motion.div initial={["visible", "active"]} variants={variants} />
1674
+ *
1675
+ * // As false (disable mount animation)
1676
+ * <motion.div initial={false} animate={{ opacity: 0 }} />
1677
+ * ```
1678
+ */
1679
+ initial?: TargetAndTransition | VariantLabels | boolean;
1680
+ /**
1681
+ * Values to animate to, variant label(s), or `LegacyAnimationControls`.
1682
+ *
1683
+ * ```jsx
1684
+ * // As values
1685
+ * <motion.div animate={{ opacity: 1 }} />
1686
+ *
1687
+ * // As variant
1688
+ * <motion.div animate="visible" variants={variants} />
1689
+ *
1690
+ * // Multiple variants
1691
+ * <motion.div animate={["visible", "active"]} variants={variants} />
1692
+ *
1693
+ * // LegacyAnimationControls
1694
+ * <motion.div animate={animation} />
1695
+ * ```
1696
+ */
1697
+ animate?: TargetAndTransition | VariantLabels | boolean | LegacyAnimationControls;
1698
+ /**
1699
+ * A target to animate to when this component is removed from the tree.
1700
+ *
1701
+ * This component **must** be the first animatable child of an `AnimatePresence` to enable this exit animation.
1702
+ *
1703
+ * This limitation exists because React doesn't allow components to defer unmounting until after
1704
+ * an animation is complete. Once this limitation is fixed, the `AnimatePresence` component will be unnecessary.
1705
+ *
1706
+ * ```jsx
1707
+ * import { AnimatePresence, motion } from 'framer-motion'
1708
+ *
1709
+ * export const MyComponent = ({ isVisible }) => {
1710
+ * return (
1711
+ * <AnimatePresence>
1712
+ * {isVisible && (
1713
+ * <motion.div
1714
+ * initial={{ opacity: 0 }}
1715
+ * animate={{ opacity: 1 }}
1716
+ * exit={{ opacity: 0 }}
1717
+ * />
1718
+ * )}
1719
+ * </AnimatePresence>
1720
+ * )
1721
+ * }
1722
+ * ```
1723
+ */
1724
+ exit?: TargetAndTransition | VariantLabels;
1725
+ /**
1726
+ * Variants allow you to define animation states and organise them by name. They allow
1727
+ * you to control animations throughout a component tree by switching a single `animate` prop.
1728
+ *
1729
+ * Using `transition` options like `delayChildren` and `staggerChildren`, you can orchestrate
1730
+ * when children animations play relative to their parent.
1731
+
1732
+ *
1733
+ * After passing variants to one or more `motion` component's `variants` prop, these variants
1734
+ * can be used in place of values on the `animate`, `initial`, `whileFocus`, `whileTap` and `whileHover` props.
1735
+ *
1736
+ * ```jsx
1737
+ * const variants = {
1738
+ * active: {
1739
+ * backgroundColor: "#f00"
1740
+ * },
1741
+ * inactive: {
1742
+ * backgroundColor: "#fff",
1743
+ * transition: { duration: 2 }
1744
+ * }
1745
+ * }
1746
+ *
1747
+ * <motion.div variants={variants} animate="active" />
1748
+ * ```
1749
+ */
1750
+ variants?: Variants;
1751
+ /**
1752
+ * Default transition. If no `transition` is defined in `animate`, it will use the transition defined here.
1753
+ * ```jsx
1754
+ * const spring = {
1755
+ * type: "spring",
1756
+ * damping: 10,
1757
+ * stiffness: 100
1758
+ * }
1759
+ *
1760
+ * <motion.div transition={spring} animate={{ scale: 1.2 }} />
1761
+ * ```
1762
+ */
1763
+ transition?: Transition;
1764
+ }
1765
+ interface MotionNodeEventOptions {
1766
+ /**
1767
+ * Callback with latest motion values, fired max once per frame.
1768
+ *
1769
+ * ```jsx
1770
+ * function onUpdate(latest) {
1771
+ * console.log(latest.x, latest.opacity)
1772
+ * }
1773
+ *
1774
+ * <motion.div animate={{ x: 100, opacity: 0 }} onUpdate={onUpdate} />
1775
+ * ```
1776
+ */
1777
+ onUpdate?(latest: ResolvedValues): void;
1778
+ /**
1779
+ * Callback when animation defined in `animate` begins.
1780
+ *
1781
+ * The provided callback will be called with the triggering animation definition.
1782
+ * If this is a variant, it'll be the variant name, and if a target object
1783
+ * then it'll be the target object.
1784
+ *
1785
+ * This way, it's possible to figure out which animation has started.
1786
+ *
1787
+ * ```jsx
1788
+ * function onStart() {
1789
+ * console.log("Animation started")
1790
+ * }
1791
+ *
1792
+ * <motion.div animate={{ x: 100 }} onAnimationStart={onStart} />
1793
+ * ```
1794
+ */
1795
+ onAnimationStart?(definition: AnimationDefinition): void;
1796
+ /**
1797
+ * Callback when animation defined in `animate` is complete.
1798
+ *
1799
+ * The provided callback will be called with the triggering animation definition.
1800
+ * If this is a variant, it'll be the variant name, and if a target object
1801
+ * then it'll be the target object.
1802
+ *
1803
+ * This way, it's possible to figure out which animation has completed.
1804
+ *
1805
+ * ```jsx
1806
+ * function onComplete() {
1807
+ * console.log("Animation completed")
1808
+ * }
1809
+ *
1810
+ * <motion.div
1811
+ * animate={{ x: 100 }}
1812
+ * onAnimationComplete={definition => {
1813
+ * console.log('Completed animating', definition)
1814
+ * }}
1815
+ * />
1816
+ * ```
1817
+ */
1818
+ onAnimationComplete?(definition: AnimationDefinition): void;
1819
+ onBeforeLayoutMeasure?(box: Box): void;
1820
+ onLayoutMeasure?(box: Box, prevBox: Box): void;
1821
+ onLayoutAnimationStart?(): void;
1822
+ onLayoutAnimationComplete?(): void;
1823
+ }
1824
+ interface MotionNodePanHandlers {
1825
+ /**
1826
+ * Callback function that fires when the pan gesture is recognised on this element.
1827
+ *
1828
+ * **Note:** For pan gestures to work correctly with touch input, the element needs
1829
+ * touch scrolling to be disabled on either x/y or both axis with the
1830
+ * [touch-action](https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action) CSS rule.
1831
+ *
1832
+ * ```jsx
1833
+ * function onPan(event, info) {
1834
+ * console.log(info.point.x, info.point.y)
1835
+ * }
1836
+ *
1837
+ * <motion.div onPan={onPan} />
1838
+ * ```
1839
+ *
1840
+ * @param event - The originating pointer event.
1841
+ * @param info - A {@link PanInfo} object containing `x` and `y` values for:
1842
+ *
1843
+ * - `point`: Relative to the device or page.
1844
+ * - `delta`: Distance moved since the last event.
1845
+ * - `offset`: Offset from the original pan event.
1846
+ * - `velocity`: Current velocity of the pointer.
1847
+ */
1848
+ onPan?(event: PointerEvent, info: PanInfo): void;
1849
+ /**
1850
+ * Callback function that fires when the pan gesture begins on this element.
1851
+ *
1852
+ * ```jsx
1853
+ * function onPanStart(event, info) {
1854
+ * console.log(info.point.x, info.point.y)
1855
+ * }
1856
+ *
1857
+ * <motion.div onPanStart={onPanStart} />
1858
+ * ```
1859
+ *
1860
+ * @param event - The originating pointer event.
1861
+ * @param info - A {@link PanInfo} object containing `x`/`y` values for:
1862
+ *
1863
+ * - `point`: Relative to the device or page.
1864
+ * - `delta`: Distance moved since the last event.
1865
+ * - `offset`: Offset from the original pan event.
1866
+ * - `velocity`: Current velocity of the pointer.
1867
+ */
1868
+ onPanStart?(event: PointerEvent, info: PanInfo): void;
1869
+ /**
1870
+ * Callback function that fires when we begin detecting a pan gesture. This
1871
+ * is analogous to `onMouseStart` or `onTouchStart`.
1872
+ *
1873
+ * ```jsx
1874
+ * function onPanSessionStart(event, info) {
1875
+ * console.log(info.point.x, info.point.y)
1876
+ * }
1877
+ *
1878
+ * <motion.div onPanSessionStart={onPanSessionStart} />
1879
+ * ```
1880
+ *
1881
+ * @param event - The originating pointer event.
1882
+ * @param info - An {@link EventInfo} object containing `x`/`y` values for:
1883
+ *
1884
+ * - `point`: Relative to the device or page.
1885
+ */
1886
+ onPanSessionStart?(event: PointerEvent, info: EventInfo): void;
1887
+ /**
1888
+ * Callback function that fires when the pan gesture ends on this element.
1889
+ *
1890
+ * ```jsx
1891
+ * function onPanEnd(event, info) {
1892
+ * console.log(info.point.x, info.point.y)
1893
+ * }
1894
+ *
1895
+ * <motion.div onPanEnd={onPanEnd} />
1896
+ * ```
1897
+ *
1898
+ * @param event - The originating pointer event.
1899
+ * @param info - A {@link PanInfo} object containing `x`/`y` values for:
1900
+ *
1901
+ * - `point`: Relative to the device or page.
1902
+ * - `delta`: Distance moved since the last event.
1903
+ * - `offset`: Offset from the original pan event.
1904
+ * - `velocity`: Current velocity of the pointer.
1905
+ */
1906
+ onPanEnd?(event: PointerEvent, info: PanInfo): void;
1907
+ }
1908
+ interface MotionNodeHoverHandlers {
1909
+ /**
1910
+ * Properties or variant label to animate to while the hover gesture is recognised.
1911
+ *
1912
+ * ```jsx
1913
+ * <motion.div whileHover={{ scale: 1.2 }} />
1914
+ * ```
1915
+ */
1916
+ whileHover?: VariantLabels | TargetAndTransition;
1917
+ /**
1918
+ * Callback function that fires when pointer starts hovering over the component.
1919
+ *
1920
+ * ```jsx
1921
+ * <motion.div onHoverStart={() => console.log('Hover starts')} />
1922
+ * ```
1923
+ */
1924
+ onHoverStart?(event: MouseEvent, info: EventInfo): void;
1925
+ /**
1926
+ * Callback function that fires when pointer stops hovering over the component.
1927
+ *
1928
+ * ```jsx
1929
+ * <motion.div onHoverEnd={() => console.log("Hover ends")} />
1930
+ * ```
1931
+ */
1932
+ onHoverEnd?(event: MouseEvent, info: EventInfo): void;
1933
+ }
1934
+ /**
1935
+ * Passed in to tap event handlers like `onTap` the `TapInfo` object contains
1936
+ * information about the tap gesture such as it‘s location.
1937
+ *
1938
+ * ```jsx
1939
+ * function onTap(event, info) {
1940
+ * console.log(info.point.x, info.point.y)
1941
+ * }
1942
+ *
1943
+ * <motion.div onTap={onTap} />
1944
+ * ```
1945
+ *
1946
+ * @public
1947
+ */
1948
+ interface TapInfo {
1949
+ /**
1950
+ * Contains `x` and `y` values for the tap gesture relative to the
1951
+ * device or page.
1952
+ *
1953
+ * ```jsx
1954
+ * function onTapStart(event, info) {
1955
+ * console.log(info.point.x, info.point.y)
1956
+ * }
1957
+ *
1958
+ * <motion.div onTapStart={onTapStart} />
1959
+ * ```
1960
+ *
1961
+ * @public
1962
+ */
1963
+ point: Point;
1964
+ }
1965
+ interface MotionNodeTapHandlers {
1966
+ /**
1967
+ * Callback when the tap gesture successfully ends on this element.
1968
+ *
1969
+ * ```jsx
1970
+ * function onTap(event, info) {
1971
+ * console.log(info.point.x, info.point.y)
1972
+ * }
1973
+ *
1974
+ * <motion.div onTap={onTap} />
1975
+ * ```
1976
+ *
1977
+ * @param event - The originating pointer event.
1978
+ * @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
1979
+ */
1980
+ onTap?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
1981
+ /**
1982
+ * Callback when the tap gesture starts on this element.
1983
+ *
1984
+ * ```jsx
1985
+ * function onTapStart(event, info) {
1986
+ * console.log(info.point.x, info.point.y)
1987
+ * }
1988
+ *
1989
+ * <motion.div onTapStart={onTapStart} />
1990
+ * ```
1991
+ *
1992
+ * @param event - The originating pointer event.
1993
+ * @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
1994
+ */
1995
+ onTapStart?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
1996
+ /**
1997
+ * Callback when the tap gesture ends outside this element.
1998
+ *
1999
+ * ```jsx
2000
+ * function onTapCancel(event, info) {
2001
+ * console.log(info.point.x, info.point.y)
2002
+ * }
2003
+ *
2004
+ * <motion.div onTapCancel={onTapCancel} />
2005
+ * ```
2006
+ *
2007
+ * @param event - The originating pointer event.
2008
+ * @param info - An {@link TapInfo} object containing `x` and `y` values for the `point` relative to the device or page.
2009
+ */
2010
+ onTapCancel?(event: MouseEvent | TouchEvent | PointerEvent, info: TapInfo): void;
2011
+ /**
2012
+ * Properties or variant label to animate to while the component is pressed.
2013
+ *
2014
+ * ```jsx
2015
+ * <motion.div whileTap={{ scale: 0.8 }} />
2016
+ * ```
2017
+ */
2018
+ whileTap?: VariantLabels | TargetAndTransition;
2019
+ /**
2020
+ * If `true`, the tap gesture will attach its start listener to window.
2021
+ *
2022
+ * Note: This is not supported publically.
2023
+ */
2024
+ globalTapTarget?: boolean;
2025
+ }
2026
+ interface MotionNodeFocusHandlers {
2027
+ /**
2028
+ * Properties or variant label to animate to while the focus gesture is recognised.
2029
+ *
2030
+ * ```jsx
2031
+ * <motion.input whileFocus={{ scale: 1.2 }} />
2032
+ * ```
2033
+ */
2034
+ whileFocus?: VariantLabels | TargetAndTransition;
2035
+ }
2036
+ /**
2037
+ * TODO: Replace with types from inView()
2038
+ */
2039
+ type ViewportEventHandler = (entry: IntersectionObserverEntry | null) => void;
2040
+ interface ViewportOptions {
2041
+ root?: {
2042
+ current: Element | null;
2043
+ };
2044
+ once?: boolean;
2045
+ margin?: string;
2046
+ amount?: "some" | "all" | number;
2047
+ }
2048
+ interface MotionNodeViewportOptions {
2049
+ whileInView?: VariantLabels | TargetAndTransition;
2050
+ onViewportEnter?: ViewportEventHandler;
2051
+ onViewportLeave?: ViewportEventHandler;
2052
+ viewport?: ViewportOptions;
2053
+ }
2054
+ interface MotionNodeDraggableOptions {
2055
+ /**
2056
+ * Enable dragging for this element. Set to `false` by default.
2057
+ * Set `true` to drag in both directions.
2058
+ * Set `"x"` or `"y"` to only drag in a specific direction.
2059
+ *
2060
+ * ```jsx
2061
+ * <motion.div drag="x" />
2062
+ * ```
2063
+ */
2064
+ drag?: boolean | "x" | "y";
2065
+ /**
2066
+ * Properties or variant label to animate to while the drag gesture is recognised.
2067
+ *
2068
+ * ```jsx
2069
+ * <motion.div whileDrag={{ scale: 1.2 }} />
2070
+ * ```
2071
+ */
2072
+ whileDrag?: VariantLabels | TargetAndTransition;
2073
+ /**
2074
+ * If `true`, this will lock dragging to the initially-detected direction. Defaults to `false`.
2075
+ *
2076
+ * ```jsx
2077
+ * <motion.div drag dragDirectionLock />
2078
+ * ```
2079
+ */
2080
+ dragDirectionLock?: boolean;
2081
+ /**
2082
+ * Allows drag gesture propagation to child components. Set to `false` by
2083
+ * default.
2084
+ *
2085
+ * ```jsx
2086
+ * <motion.div drag="x" dragPropagation />
2087
+ * ```
2088
+ */
2089
+ dragPropagation?: boolean;
2090
+ /**
2091
+ * Applies constraints on the permitted draggable area.
2092
+ *
2093
+ * It can accept an object of optional `top`, `left`, `right`, and `bottom` values, measured in pixels.
2094
+ * This will define a distance from the named edge of the draggable component.
2095
+ *
2096
+ * Alternatively, it can accept a `ref` to another component created with React's `useRef` hook.
2097
+ * This `ref` should be passed both to the draggable component's `dragConstraints` prop, and the `ref`
2098
+ * of the component you want to use as constraints.
2099
+ *
2100
+ * ```jsx
2101
+ * // In pixels
2102
+ * <motion.div
2103
+ * drag="x"
2104
+ * dragConstraints={{ left: 0, right: 300 }}
2105
+ * />
2106
+ *
2107
+ * // As a ref to another component
2108
+ * const MyComponent = () => {
2109
+ * const constraintsRef = useRef(null)
2110
+ *
2111
+ * return (
2112
+ * <motion.div ref={constraintsRef}>
2113
+ * <motion.div drag dragConstraints={constraintsRef} />
2114
+ * </motion.div>
2115
+ * )
2116
+ * }
2117
+ * ```
2118
+ */
2119
+ dragConstraints?: false | Partial<BoundingBox> | {
2120
+ current: Element | null;
2121
+ };
2122
+ /**
2123
+ * The degree of movement allowed outside constraints. 0 = no movement, 1 =
2124
+ * full movement.
2125
+ *
2126
+ * Set to `0.5` by default. Can also be set as `false` to disable movement.
2127
+ *
2128
+ * By passing an object of `top`/`right`/`bottom`/`left`, individual values can be set
2129
+ * per constraint. Any missing values will be set to `0`.
2130
+ *
2131
+ * ```jsx
2132
+ * <motion.div
2133
+ * drag
2134
+ * dragConstraints={{ left: 0, right: 300 }}
2135
+ * dragElastic={0.2}
2136
+ * />
2137
+ * ```
2138
+ */
2139
+ dragElastic?: DragElastic;
2140
+ /**
2141
+ * Apply momentum from the pan gesture to the component when dragging
2142
+ * finishes. Set to `true` by default.
2143
+ *
2144
+ * ```jsx
2145
+ * <motion.div
2146
+ * drag
2147
+ * dragConstraints={{ left: 0, right: 300 }}
2148
+ * dragMomentum={false}
2149
+ * />
2150
+ * ```
2151
+ */
2152
+ dragMomentum?: boolean;
2153
+ /**
2154
+ * Allows you to change dragging inertia parameters.
2155
+ * When releasing a draggable Frame, an animation with type `inertia` starts. The animation is based on your dragging velocity. This property allows you to customize it.
2156
+ * See {@link https://motion.dev/docs/react-motion-component#dragtransition | Inertia} for all properties you can use.
2157
+ *
2158
+ * ```jsx
2159
+ * <motion.div
2160
+ * drag
2161
+ * dragTransition={{ bounceStiffness: 600, bounceDamping: 10 }}
2162
+ * />
2163
+ * ```
2164
+ */
2165
+ dragTransition?: InertiaOptions;
2166
+ /**
2167
+ * Usually, dragging is initiated by pressing down on a component and moving it. For some
2168
+ * use-cases, for instance clicking at an arbitrary point on a video scrubber, we
2169
+ * might want to initiate dragging from a different component than the draggable one.
2170
+ *
2171
+ * By creating a `dragControls` using the `useDragControls` hook, we can pass this into
2172
+ * the draggable component's `dragControls` prop. It exposes a `start` method
2173
+ * that can start dragging from pointer events on other components.
2174
+ *
2175
+ * ```jsx
2176
+ * const dragControls = useDragControls()
2177
+ *
2178
+ * function startDrag(event) {
2179
+ * dragControls.start(event, { snapToCursor: true })
2180
+ * }
2181
+ *
2182
+ * return (
2183
+ * <>
2184
+ * <div onPointerDown={startDrag} />
2185
+ * <motion.div drag="x" dragControls={dragControls} />
2186
+ * </>
2187
+ * )
2188
+ * ```
2189
+ */
2190
+ dragControls?: any;
2191
+ /**
2192
+ * If true, element will snap back to its origin when dragging ends.
2193
+ *
2194
+ * Enabling this is the equivalent of setting all `dragConstraints` axes to `0`
2195
+ * with `dragElastic={1}`, but when used together `dragConstraints` can define
2196
+ * a wider draggable area and `dragSnapToOrigin` will ensure the element
2197
+ * animates back to its origin on release.
2198
+ */
2199
+ dragSnapToOrigin?: boolean;
2200
+ /**
2201
+ * By default, if `drag` is defined on a component then an event listener will be attached
2202
+ * to automatically initiate dragging when a user presses down on it.
2203
+ *
2204
+ * By setting `dragListener` to `false`, this event listener will not be created.
2205
+ *
2206
+ * ```jsx
2207
+ * const dragControls = useDragControls()
2208
+ *
2209
+ * function startDrag(event) {
2210
+ * dragControls.start(event, { snapToCursor: true })
2211
+ * }
2212
+ *
2213
+ * return (
2214
+ * <>
2215
+ * <div onPointerDown={startDrag} />
2216
+ * <motion.div
2217
+ * drag="x"
2218
+ * dragControls={dragControls}
2219
+ * dragListener={false}
2220
+ * />
2221
+ * </>
2222
+ * )
2223
+ * ```
2224
+ */
2225
+ dragListener?: boolean;
2226
+ /**
2227
+ * If `dragConstraints` is set to a React ref, this callback will call with the measured drag constraints.
2228
+ *
2229
+ * @public
2230
+ */
2231
+ onMeasureDragConstraints?: (constraints: BoundingBox) => BoundingBox | void;
2232
+ /**
2233
+ * Usually, dragging uses the layout project engine, and applies transforms to the underlying VisualElement.
2234
+ * Passing MotionValues as _dragX and _dragY instead applies drag updates to these motion values.
2235
+ * This allows you to manually control how updates from a drag gesture on an element is applied.
2236
+ *
2237
+ * @public
2238
+ */
2239
+ _dragX?: MotionValue<number>;
2240
+ /**
2241
+ * Usually, dragging uses the layout project engine, and applies transforms to the underlying VisualElement.
2242
+ * Passing MotionValues as _dragX and _dragY instead applies drag updates to these motion values.
2243
+ * This allows you to manually control how updates from a drag gesture on an element is applied.
2244
+ *
2245
+ * @public
2246
+ */
2247
+ _dragY?: MotionValue<number>;
2248
+ }
2249
+ interface MotionNodeDragHandlers {
2250
+ /**
2251
+ * Callback function that fires when dragging starts.
2252
+ *
2253
+ * ```jsx
2254
+ * <motion.div
2255
+ * drag
2256
+ * onDragStart={
2257
+ * (event, info) => console.log(info.point.x, info.point.y)
2258
+ * }
2259
+ * />
2260
+ * ```
2261
+ *
2262
+ * @public
2263
+ */
2264
+ onDragStart?(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void;
2265
+ /**
2266
+ * Callback function that fires when dragging ends.
2267
+ *
2268
+ * ```jsx
2269
+ * <motion.div
2270
+ * drag
2271
+ * onDragEnd={
2272
+ * (event, info) => console.log(info.point.x, info.point.y)
2273
+ * }
2274
+ * />
2275
+ * ```
2276
+ *
2277
+ * @public
2278
+ */
2279
+ onDragEnd?(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void;
2280
+ /**
2281
+ * Callback function that fires when the component is dragged.
2282
+ *
2283
+ * ```jsx
2284
+ * <motion.div
2285
+ * drag
2286
+ * onDrag={
2287
+ * (event, info) => console.log(info.point.x, info.point.y)
2288
+ * }
2289
+ * />
2290
+ * ```
2291
+ *
2292
+ * @public
2293
+ */
2294
+ onDrag?(event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void;
2295
+ /**
2296
+ * Callback function that fires a drag direction is determined.
2297
+ *
2298
+ * ```jsx
2299
+ * <motion.div
2300
+ * drag
2301
+ * dragDirectionLock
2302
+ * onDirectionLock={axis => console.log(axis)}
2303
+ * />
2304
+ * ```
2305
+ *
2306
+ * @public
2307
+ */
2308
+ onDirectionLock?(axis: "x" | "y"): void;
2309
+ /**
2310
+ * Callback function that fires when drag momentum/bounce transition finishes.
2311
+ *
2312
+ * ```jsx
2313
+ * <motion.div
2314
+ * drag
2315
+ * onDragTransitionEnd={() => console.log('Drag transition complete')}
2316
+ * />
2317
+ * ```
2318
+ *
2319
+ * @public
2320
+ */
2321
+ onDragTransitionEnd?(): void;
2322
+ }
2323
+ interface MotionNodeLayoutOptions {
2324
+ /**
2325
+ * If `true`, this component will automatically animate to its new position when
2326
+ * its layout changes.
2327
+ *
2328
+ * ```jsx
2329
+ * <motion.div layout />
2330
+ * ```
2331
+ *
2332
+ * This will perform a layout animation using performant transforms. Part of this technique
2333
+ * involved animating an element's scale. This can introduce visual distortions on children,
2334
+ * `boxShadow` and `borderRadius`.
2335
+ *
2336
+ * To correct distortion on immediate children, add `layout` to those too.
2337
+ *
2338
+ * `boxShadow` and `borderRadius` will automatically be corrected if they are already being
2339
+ * animated on this component. Otherwise, set them directly via the `initial` prop.
2340
+ *
2341
+ * If `layout` is set to `"position"`, the size of the component will change instantly and
2342
+ * only its position will animate.
2343
+ *
2344
+ * If `layout` is set to `"size"`, the position of the component will change instantly and
2345
+ * only its size will animate.
2346
+ *
2347
+ * If `layout` is set to `"preserve-aspect"`, the component will animate size & position if
2348
+ * the aspect ratio remains the same between renders, and just position if the ratio changes.
2349
+ *
2350
+ * @public
2351
+ */
2352
+ layout?: boolean | "position" | "size" | "preserve-aspect";
2353
+ /**
2354
+ * Enable shared layout transitions between different components with the same `layoutId`.
2355
+ *
2356
+ * When a component with a layoutId is removed from the React tree, and then
2357
+ * added elsewhere, it will visually animate from the previous component's bounding box
2358
+ * and its latest animated values.
2359
+ *
2360
+ * ```jsx
2361
+ * {items.map(item => (
2362
+ * <motion.li layout>
2363
+ * {item.name}
2364
+ * {item.isSelected && <motion.div layoutId="underline" />}
2365
+ * </motion.li>
2366
+ * ))}
2367
+ * ```
2368
+ *
2369
+ * If the previous component remains in the tree it will crossfade with the new component.
2370
+ *
2371
+ * @public
2372
+ */
2373
+ layoutId?: string;
2374
+ /**
2375
+ * A callback that will fire when a layout animation on this component starts.
2376
+ *
2377
+ * @public
2378
+ */
2379
+ onLayoutAnimationStart?(): void;
2380
+ /**
2381
+ * A callback that will fire when a layout animation on this component completes.
2382
+ *
2383
+ * @public
2384
+ */
2385
+ onLayoutAnimationComplete?(): void;
2386
+ /**
2387
+ * @public
2388
+ */
2389
+ layoutDependency?: any;
2390
+ /**
2391
+ * Whether a projection node should measure its scroll when it or its descendants update their layout.
2392
+ *
2393
+ * @public
2394
+ */
2395
+ layoutScroll?: boolean;
2396
+ /**
2397
+ * Whether an element should be considered a "layout root", where
2398
+ * all children will be forced to resolve relatively to it.
2399
+ * Currently used for `position: sticky` elements in Framer.
2400
+ */
2401
+ layoutRoot?: boolean;
2402
+ /**
2403
+ * Attached to a portal root to ensure we attach the child to the document root and don't
2404
+ * perform scale correction on it.
2405
+ */
2406
+ "data-framer-portal-id"?: string;
2407
+ /**
2408
+ * By default, shared layout elements will crossfade. By setting this
2409
+ * to `false`, this element will take its default opacity throughout the animation.
2410
+ */
2411
+ layoutCrossfade?: boolean;
2412
+ }
2413
+ type TransformTemplate = (transform: TransformProperties, generatedTransform: string) => string;
2414
+ interface MotionNodeAdvancedOptions {
2415
+ /**
2416
+ * Custom data to use to resolve dynamic variants differently for each animating component.
2417
+ *
2418
+ * ```jsx
2419
+ * const variants = {
2420
+ * visible: (custom) => ({
2421
+ * opacity: 1,
2422
+ * transition: { delay: custom * 0.2 }
2423
+ * })
2424
+ * }
2425
+ *
2426
+ * <motion.div custom={0} animate="visible" variants={variants} />
2427
+ * <motion.div custom={1} animate="visible" variants={variants} />
2428
+ * <motion.div custom={2} animate="visible" variants={variants} />
2429
+ * ```
2430
+ *
2431
+ * @public
2432
+ */
2433
+ custom?: any;
2434
+ /**
2435
+ * @public
2436
+ * Set to `false` to prevent inheriting variant changes from its parent.
2437
+ */
2438
+ inherit?: boolean;
2439
+ /**
2440
+ * @public
2441
+ * Set to `false` to prevent throwing an error when a `motion` component is used within a `LazyMotion` set to strict.
2442
+ */
2443
+ ignoreStrict?: boolean;
2444
+ /**
2445
+ * Provide a set of motion values to perform animations on.
2446
+ */
2447
+ values?: {
2448
+ [key: string]: MotionValue<number> | MotionValue<string>;
2449
+ };
2450
+ /**
2451
+ * By default, Motion generates a `transform` property with a sensible transform order. `transformTemplate`
2452
+ * can be used to create a different order, or to append/preprend the automatically generated `transform` property.
2453
+ *
2454
+ * ```jsx
2455
+ * <motion.div
2456
+ * style={{ x: 0, rotate: 180 }}
2457
+ * transformTemplate={
2458
+ * ({ x, rotate }) => `rotate(${rotate}deg) translateX(${x}px)`
2459
+ * }
2460
+ * />
2461
+ * ```
2462
+ *
2463
+ * @param transform - The latest animated transform props.
2464
+ * @param generatedTransform - The transform string as automatically generated by Motion
2465
+ *
2466
+ * @public
2467
+ */
2468
+ transformTemplate?: TransformTemplate;
2469
+ "data-framer-appear-id"?: string;
2470
+ }
2471
+ interface MotionNodeOptions extends MotionNodeAnimationOptions, MotionNodeEventOptions, MotionNodePanHandlers, MotionNodeTapHandlers, MotionNodeHoverHandlers, MotionNodeFocusHandlers, MotionNodeViewportOptions, MotionNodeDragHandlers, MotionNodeDraggableOptions, MotionNodeLayoutOptions, MotionNodeAdvancedOptions {
2472
+ }
2473
+
2474
+ declare function defaultTransformValue(name: string): number;
2475
+ declare function parseValueFromTransform(transform: string | undefined, name: string): number;
2476
+ declare const readTransformValue: (instance: HTMLElement, name: string) => number;
2477
+
2478
+ declare function getComputedStyle(element: HTMLElement | SVGElement, name: string): string;
2479
+
2480
+ declare function setStyle(element: HTMLElement | SVGElement, name: string, value: string | number): void;
2481
+
2482
+ declare const positionalKeys: Set<string>;
2483
+
2484
+ /**
2485
+ * Generate a list of every possible transform key.
2486
+ */
2487
+ declare const transformPropOrder: string[];
2488
+ /**
2489
+ * A quick lookup for transform props.
2490
+ */
2491
+ declare const transformProps: Set<string>;
2492
+
2493
+ interface ResizeInfo {
2494
+ width: number;
2495
+ height: number;
2496
+ }
2497
+ type ResizeHandler<I> = (element: I, info: ResizeInfo) => void;
2498
+ type WindowResizeHandler = (info: ResizeInfo) => void;
2499
+
2500
+ declare function resize(onResize: WindowResizeHandler): VoidFunction;
2501
+ declare function resize(target: ElementOrSelector, onResize: ResizeHandler<Element>): VoidFunction;
2502
+
2503
+ type Update = (progress: number) => void;
2504
+ declare function observeTimeline(update: Update, timeline: ProgressTimeline): () => void;
2505
+
2506
+ declare const stepsOrder: StepId[];
2507
+ type StepNames = (typeof stepsOrder)[number];
2508
+
2509
+ interface Summary {
2510
+ min: number;
2511
+ max: number;
2512
+ avg: number;
2513
+ }
2514
+ type FrameloopStatNames = "rate" | StepNames;
2515
+ interface Stats<T> {
2516
+ frameloop: {
2517
+ [key in FrameloopStatNames]: T;
2518
+ };
2519
+ animations: {
2520
+ mainThread: T;
2521
+ waapi: T;
2522
+ layout: T;
2523
+ };
2524
+ layoutProjection: {
2525
+ nodes: T;
2526
+ calculatedTargetDeltas: T;
2527
+ calculatedProjections: T;
2528
+ };
2529
+ }
2530
+ type StatsBuffer = number[];
2531
+ type FrameStats = Stats<number>;
2532
+ type StatsRecording = Stats<StatsBuffer>;
2533
+ type StatsSummary = Stats<Summary>;
2534
+
2535
+ declare function reportStats(): StatsSummary;
2536
+ declare function recordStats(): typeof reportStats;
2537
+
2538
+ declare const activeAnimations: {
2539
+ layout: number;
2540
+ mainThread: number;
2541
+ waapi: number;
2542
+ };
2543
+
2544
+ type InactiveStatsBuffer = {
2545
+ value: null;
2546
+ addProjectionMetrics: null;
1328
2547
  };
1329
2548
  type ActiveStatsBuffer = {
1330
2549
  value: StatsRecording;
@@ -1498,9 +2717,6 @@ interface TransformOptions<T> {
1498
2717
  * Every value in the output range must be of the same type and in the same format.
1499
2718
  *
1500
2719
  * ```jsx
1501
- * import * as React from "react"
1502
- * import { transform } from "framer-motion"
1503
- *
1504
2720
  * export function MyComponent() {
1505
2721
  * const inputRange = [0, 200]
1506
2722
  * const outputRange = [0, 1]
@@ -1530,9 +2746,6 @@ declare function transform<T>(inputValue: number, inputRange: number[], outputRa
1530
2746
  * Every value in the output range must be of the same type and in the same format.
1531
2747
  *
1532
2748
  * ```jsx
1533
- * import * as React from "react"
1534
- * import { Frame, transform } from "framer"
1535
- *
1536
2749
  * export function MyComponent() {
1537
2750
  * const inputRange = [-200, -100, 100, 200]
1538
2751
  * const outputRange = [0, 1, 1, 0]
@@ -1866,4 +3079,4 @@ declare const sync: Batcher;
1866
3079
  */
1867
3080
  declare const cancelSync: Record<string, (process: Process) => void>;
1868
3081
 
1869
- export { type AcceptedAnimations, type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, type DecayOptions, type DurationSpringOptions, type DynamicOption, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, type InactiveStatsBuffer, type InertiaOptions, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, type MapInputRange, type Mixer, type MixerFactory, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NumberMap, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RGBA, type RepeatType, type ResolvedKeyframes, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SingleTransformer, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformProperties, type Transformer, type Transition, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, acceleratedValues, activeAnimations, addAttrValue, addStyleValue, alpha, analyseComplexValue, animateValue, animateView, animationMapKey, applyPxDefaults, attachSpring, attrEffect, calcGeneratorDuration, cancelFrame, cancelMicrotask, cancelSync, collectMotionValues, color, complex, convertOffsetToTimes, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, dimensionValueTypes, fillOffset, fillWildcards, findDimensionValueType, findValueType, flushKeyframeResolvers, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultValueType, getMixer, getValueAsType, getValueTransition, getVariableValue, hex, hover, hsla, hslaToRgba, inertia, interpolate, invisibleValues, isCSSVariableName, isCSSVariableToken, isDragActive, isDragging, isGenerator, isHTMLElement, isMotionValue, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isWaapiSupportedEasing, keyframes, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixVisibility, motionValue, number, numberValueTypes, observeTimeline, parseCSSVariable, parseValueFromTransform, percent, positionalKeys, press, progressPercentage, propEffect, px, readTransformValue, recordStats, resize, resolveElements, rgbUnit, rgba, scale, setDragLock, setStyle, spring, springValue, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, svgEffect, sync, testValueType, time, transform, transformPropOrder, transformProps, transformValue, transformValueTypes, vh, vw };
3082
+ export { type AcceptedAnimations, type ActiveStatsBuffer, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, type DecayOptions, type DragElastic, type DragHandler, type DurationSpringOptions, type DynamicOption, type ElementOrSelector, type EventInfo, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, type InactiveStatsBuffer, type InertiaOptions, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, type LegacyAnimationControls, type MapInputRange, type Mixer, type MixerFactory, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NumberMap, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RGBA, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SingleTransformer, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewportEventHandler, type ViewportOptions, type WithQuerySelectorAll, acceleratedValues, activeAnimations, addAttrValue, addStyleValue, alpha, analyseComplexValue, animateValue, animateView, animationMapKey, applyPxDefaults, attachSpring, attrEffect, calcGeneratorDuration, cancelFrame, cancelMicrotask, cancelSync, collectMotionValues, color, complex, convertOffsetToTimes, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, dimensionValueTypes, fillOffset, fillWildcards, findDimensionValueType, findValueType, flushKeyframeResolvers, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultValueType, getMixer, getValueAsType, getValueTransition, getVariableValue, hex, hover, hsla, hslaToRgba, inertia, interpolate, invisibleValues, isCSSVariableName, isCSSVariableToken, isDragActive, isDragging, isGenerator, isHTMLElement, isMotionValue, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isWaapiSupportedEasing, keyframes, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixVisibility, motionValue, number, numberValueTypes, observeTimeline, parseCSSVariable, parseValueFromTransform, percent, positionalKeys, press, progressPercentage, propEffect, px, readTransformValue, recordStats, resize, resolveElements, rgbUnit, rgba, scale, setDragLock, setStyle, spring, springValue, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, svgEffect, sync, testValueType, time, transform, transformPropOrder, transformProps, transformValue, transformValueTypes, vh, vw };