framer-motion 12.20.5 → 12.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var create = require('./create-BOq2yHIj.js');
5
+ var create = require('./create-C-c1JfhA.js');
6
6
  require('motion-dom');
7
7
  require('motion-utils');
8
8
  require('react/jsx-runtime');
@@ -3764,7 +3764,7 @@ function animateVariant(visualElement, variant, options = {}) {
3764
3764
  const getChildAnimations = visualElement.variantChildren && visualElement.variantChildren.size
3765
3765
  ? (forwardDelay = 0) => {
3766
3766
  const { delayChildren = 0, staggerChildren, staggerDirection, } = transition;
3767
- return animateChildren(visualElement, variant, delayChildren + forwardDelay, staggerChildren, staggerDirection, options);
3767
+ return animateChildren(visualElement, variant, forwardDelay, delayChildren, staggerChildren, staggerDirection, options);
3768
3768
  }
3769
3769
  : () => Promise.resolve();
3770
3770
  /**
@@ -3782,19 +3782,26 @@ function animateVariant(visualElement, variant, options = {}) {
3782
3782
  return Promise.all([getAnimation(), getChildAnimations(options.delay)]);
3783
3783
  }
3784
3784
  }
3785
- function animateChildren(visualElement, variant, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
3785
+ function animateChildren(visualElement, variant, delay = 0, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
3786
3786
  const animations = [];
3787
- const maxStaggerDuration = (visualElement.variantChildren.size - 1) * staggerChildren;
3788
- const generateStaggerDuration = staggerDirection === 1
3789
- ? (i = 0) => i * staggerChildren
3790
- : (i = 0) => maxStaggerDuration - i * staggerChildren;
3787
+ const numChildren = visualElement.variantChildren.size;
3788
+ const maxStaggerDuration = (numChildren - 1) * staggerChildren;
3789
+ const delayIsFunction = typeof delayChildren === "function";
3790
+ const generateStaggerDuration = delayIsFunction
3791
+ ? (i) => delayChildren(i, numChildren)
3792
+ : // Support deprecated staggerChildren
3793
+ staggerDirection === 1
3794
+ ? (i = 0) => i * staggerChildren
3795
+ : (i = 0) => maxStaggerDuration - i * staggerChildren;
3791
3796
  Array.from(visualElement.variantChildren)
3792
3797
  .sort(sortByTreeOrder)
3793
3798
  .forEach((child, i) => {
3794
3799
  child.notify("AnimationStart", variant);
3795
3800
  animations.push(animateVariant(child, variant, {
3796
3801
  ...options,
3797
- delay: delayChildren + generateStaggerDuration(i),
3802
+ delay: delay +
3803
+ (delayIsFunction ? 0 : delayChildren) +
3804
+ generateStaggerDuration(i),
3798
3805
  }).then(() => child.notify("AnimationComplete", variant)));
3799
3806
  });
3800
3807
  return Promise.all(animations);
@@ -4317,7 +4324,7 @@ function distance2D(a, b) {
4317
4324
  * @internal
4318
4325
  */
4319
4326
  class PanSession {
4320
- constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
4327
+ constructor(event, handlers, { transformPagePoint, contextWindow = window, dragSnapToOrigin = false, distanceThreshold = 3, } = {}) {
4321
4328
  /**
4322
4329
  * @internal
4323
4330
  */
@@ -4345,8 +4352,8 @@ class PanSession {
4345
4352
  const isPanStarted = this.startEvent !== null;
4346
4353
  // Only start panning if the offset is larger than 3 pixels. If we make it
4347
4354
  // any larger than this we'll want to reset the pointer history
4348
- // on the first update to avoid visual snapping to the cursoe.
4349
- const isDistancePastThreshold = distance2D(info.offset, { x: 0, y: 0 }) >= 3;
4355
+ // on the first update to avoid visual snapping to the cursor.
4356
+ const isDistancePastThreshold = distance2D(info.offset, { x: 0, y: 0 }) >= this.distanceThreshold;
4350
4357
  if (!isPanStarted && !isDistancePastThreshold)
4351
4358
  return;
4352
4359
  const { point } = info;
@@ -4386,6 +4393,7 @@ class PanSession {
4386
4393
  this.dragSnapToOrigin = dragSnapToOrigin;
4387
4394
  this.handlers = handlers;
4388
4395
  this.transformPagePoint = transformPagePoint;
4396
+ this.distanceThreshold = distanceThreshold;
4389
4397
  this.contextWindow = contextWindow || window;
4390
4398
  const info = extractEventInfo(event);
4391
4399
  const initialInfo = transformPoint(info, this.transformPagePoint);
@@ -4584,10 +4592,6 @@ function resolvePointElastic(dragElastic, label) {
4584
4592
  }
4585
4593
 
4586
4594
  const elementDragControls = new WeakMap();
4587
- /**
4588
- *
4589
- */
4590
- // let latestPointerEvent: PointerEvent
4591
4595
  class VisualElementDragControls {
4592
4596
  constructor(visualElement) {
4593
4597
  this.openDragLock = null;
@@ -4603,9 +4607,17 @@ class VisualElementDragControls {
4603
4607
  * The per-axis resolved elastic values.
4604
4608
  */
4605
4609
  this.elastic = createBox();
4610
+ /**
4611
+ * The latest pointer event. Used as fallback when the `cancel` and `stop` functions are called without arguments.
4612
+ */
4613
+ this.latestPointerEvent = null;
4614
+ /**
4615
+ * The latest pan info. Used as fallback when the `cancel` and `stop` functions are called without arguments.
4616
+ */
4617
+ this.latestPanInfo = null;
4606
4618
  this.visualElement = visualElement;
4607
4619
  }
4608
- start(originEvent, { snapToCursor = false } = {}) {
4620
+ start(originEvent, { snapToCursor = false, distanceThreshold } = {}) {
4609
4621
  /**
4610
4622
  * Don't start dragging if this component is exiting
4611
4623
  */
@@ -4632,6 +4644,8 @@ class VisualElementDragControls {
4632
4644
  if (!this.openDragLock)
4633
4645
  return;
4634
4646
  }
4647
+ this.latestPointerEvent = event;
4648
+ this.latestPanInfo = info;
4635
4649
  this.isDragging = true;
4636
4650
  this.currentDirection = null;
4637
4651
  this.resolveConstraints();
@@ -4668,7 +4682,8 @@ class VisualElementDragControls {
4668
4682
  animationState && animationState.setActive("whileDrag", true);
4669
4683
  };
4670
4684
  const onMove = (event, info) => {
4671
- // latestPointerEvent = event
4685
+ this.latestPointerEvent = event;
4686
+ this.latestPanInfo = info;
4672
4687
  const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
4673
4688
  // If we didn't successfully receive the gesture lock, early return.
4674
4689
  if (!dragPropagation && !this.openDragLock)
@@ -4699,7 +4714,13 @@ class VisualElementDragControls {
4699
4714
  */
4700
4715
  onDrag && onDrag(event, info);
4701
4716
  };
4702
- const onSessionEnd = (event, info) => this.stop(event, info);
4717
+ const onSessionEnd = (event, info) => {
4718
+ this.latestPointerEvent = event;
4719
+ this.latestPanInfo = info;
4720
+ this.stop(event, info);
4721
+ this.latestPointerEvent = null;
4722
+ this.latestPanInfo = null;
4723
+ };
4703
4724
  const resumeAnimation = () => eachAxis((axis) => this.getAnimationState(axis) === "paused" &&
4704
4725
  this.getAxisMotionValue(axis).animation?.play());
4705
4726
  const { dragSnapToOrigin } = this.getProps();
@@ -4712,21 +4733,30 @@ class VisualElementDragControls {
4712
4733
  }, {
4713
4734
  transformPagePoint: this.visualElement.getTransformPagePoint(),
4714
4735
  dragSnapToOrigin,
4736
+ distanceThreshold,
4715
4737
  contextWindow: getContextWindow(this.visualElement),
4716
4738
  });
4717
4739
  }
4718
- stop(event, info) {
4740
+ /**
4741
+ * @internal
4742
+ */
4743
+ stop(event, panInfo) {
4744
+ const finalEvent = event || this.latestPointerEvent;
4745
+ const finalPanInfo = panInfo || this.latestPanInfo;
4719
4746
  const isDragging = this.isDragging;
4720
4747
  this.cancel();
4721
- if (!isDragging)
4748
+ if (!isDragging || !finalPanInfo || !finalEvent)
4722
4749
  return;
4723
- const { velocity } = info;
4750
+ const { velocity } = finalPanInfo;
4724
4751
  this.startAnimation(velocity);
4725
4752
  const { onDragEnd } = this.getProps();
4726
4753
  if (onDragEnd) {
4727
- motionDom.frame.postRender(() => onDragEnd(event, info));
4754
+ motionDom.frame.postRender(() => onDragEnd(finalEvent, finalPanInfo));
4728
4755
  }
4729
4756
  }
4757
+ /**
4758
+ * @internal
4759
+ */
4730
4760
  cancel() {
4731
4761
  this.isDragging = false;
4732
4762
  const { projection, animationState } = this.visualElement;
package/dist/cjs/dom.js CHANGED
@@ -2421,29 +2421,6 @@ function inView(elementOrSelector, onStart, { root, margin: rootMargin, amount =
2421
2421
  return () => observer.disconnect();
2422
2422
  }
2423
2423
 
2424
- function getOriginIndex(from, total) {
2425
- if (from === "first") {
2426
- return 0;
2427
- }
2428
- else {
2429
- const lastIndex = total - 1;
2430
- return from === "last" ? lastIndex : lastIndex / 2;
2431
- }
2432
- }
2433
- function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
2434
- return (i, total) => {
2435
- const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total);
2436
- const distance = Math.abs(fromIndex - i);
2437
- let delay = duration * distance;
2438
- if (ease) {
2439
- const maxDelay = total * duration;
2440
- const easingFunction = motionUtils.easingDefinitionToFunction(ease);
2441
- delay = easingFunction(delay / maxDelay) * maxDelay;
2442
- }
2443
- return startDelay + delay;
2444
- };
2445
- }
2446
-
2447
2424
  /**
2448
2425
  * Timeout defined in ms
2449
2426
  */
@@ -2480,7 +2457,6 @@ exports.distance2D = distance2D;
2480
2457
  exports.inView = inView;
2481
2458
  exports.scroll = scroll;
2482
2459
  exports.scrollInfo = scrollInfo;
2483
- exports.stagger = stagger;
2484
2460
  Object.keys(motionDom).forEach(function (k) {
2485
2461
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2486
2462
  enumerable: true,
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
- var create = require('./create-BOq2yHIj.js');
7
+ var create = require('./create-C-c1JfhA.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
@@ -1807,29 +1807,6 @@ function inView(elementOrSelector, onStart, { root, margin: rootMargin, amount =
1807
1807
  return () => observer.disconnect();
1808
1808
  }
1809
1809
 
1810
- function getOriginIndex(from, total) {
1811
- if (from === "first") {
1812
- return 0;
1813
- }
1814
- else {
1815
- const lastIndex = total - 1;
1816
- return from === "last" ? lastIndex : lastIndex / 2;
1817
- }
1818
- }
1819
- function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
1820
- return (i, total) => {
1821
- const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total);
1822
- const distance = Math.abs(fromIndex - i);
1823
- let delay = duration * distance;
1824
- if (ease) {
1825
- const maxDelay = total * duration;
1826
- const easingFunction = motionUtils.easingDefinitionToFunction(ease);
1827
- delay = easingFunction(delay / maxDelay) * maxDelay;
1828
- }
1829
- return startDelay + delay;
1830
- };
1831
- }
1832
-
1833
1810
  const createMinimalMotionComponent =
1834
1811
  /*@__PURE__*/ create.createMotionComponentFactory();
1835
1812
 
@@ -2332,6 +2309,34 @@ class DragControls {
2332
2309
  controls.start(event.nativeEvent || event, options);
2333
2310
  });
2334
2311
  }
2312
+ /**
2313
+ * Cancels a drag gesture.
2314
+ *
2315
+ * ```jsx
2316
+ * dragControls.cancel()
2317
+ * ```
2318
+ *
2319
+ * @public
2320
+ */
2321
+ cancel() {
2322
+ this.componentControls.forEach((controls) => {
2323
+ controls.cancel();
2324
+ });
2325
+ }
2326
+ /**
2327
+ * Stops a drag gesture.
2328
+ *
2329
+ * ```jsx
2330
+ * dragControls.stop()
2331
+ * ```
2332
+ *
2333
+ * @public
2334
+ */
2335
+ stop() {
2336
+ this.componentControls.forEach((controls) => {
2337
+ controls.stop();
2338
+ });
2339
+ }
2335
2340
  }
2336
2341
  const createDragControls = () => new DragControls();
2337
2342
  /**
@@ -2887,7 +2892,6 @@ exports.m = m;
2887
2892
  exports.motion = motion;
2888
2893
  exports.scroll = scroll;
2889
2894
  exports.scrollInfo = scrollInfo;
2890
- exports.stagger = stagger;
2891
2895
  exports.startOptimizedAppearAnimation = startOptimizedAppearAnimation;
2892
2896
  exports.unwrapMotionComponent = unwrapMotionComponent;
2893
2897
  exports.useAnimate = useAnimate;
package/dist/dom.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UnresolvedValueKeyframe, MotionValue, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, AnyResolvedKeyframe, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, AnimationPlaybackControls, DynamicOption } from 'motion-dom';
1
+ import { UnresolvedValueKeyframe, MotionValue, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, AnyResolvedKeyframe, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, AnimationPlaybackControls } from 'motion-dom';
2
2
  export * from 'motion-dom';
3
3
  import { Easing, EasingFunction, Point } from 'motion-utils';
4
4
  export * from 'motion-utils';
@@ -142,18 +142,10 @@ interface InViewOptions {
142
142
  }
143
143
  declare function inView(elementOrSelector: ElementOrSelector, onStart: (element: Element, entry: IntersectionObserverEntry) => void | ViewChangeHandler, { root, margin: rootMargin, amount }?: InViewOptions): VoidFunction;
144
144
 
145
- type StaggerOrigin = "first" | "last" | "center" | number;
146
- type StaggerOptions = {
147
- startDelay?: number;
148
- from?: StaggerOrigin;
149
- ease?: Easing;
150
- };
151
- declare function stagger(duration?: number, { startDelay, from, ease }?: StaggerOptions): DynamicOption<number>;
152
-
153
145
  type DelayedFunction = (overshoot: number) => void;
154
146
  declare function delayInSeconds(callback: DelayedFunction, timeout: number): () => void;
155
147
 
156
148
  declare const distance: (a: number, b: number) => number;
157
149
  declare function distance2D(a: Point, b: Point): number;
158
150
 
159
- export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo, stagger };
151
+ export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo };