framer-motion 12.20.5 → 12.22.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-Dr1Bf9gl.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;
@@ -4605,7 +4609,7 @@ class VisualElementDragControls {
4605
4609
  this.elastic = createBox();
4606
4610
  this.visualElement = visualElement;
4607
4611
  }
4608
- start(originEvent, { snapToCursor = false } = {}) {
4612
+ start(originEvent, { snapToCursor = false, distanceThreshold } = {}) {
4609
4613
  /**
4610
4614
  * Don't start dragging if this component is exiting
4611
4615
  */
@@ -4712,6 +4716,7 @@ class VisualElementDragControls {
4712
4716
  }, {
4713
4717
  transformPagePoint: this.visualElement.getTransformPagePoint(),
4714
4718
  dragSnapToOrigin,
4719
+ distanceThreshold,
4715
4720
  contextWindow: getContextWindow(this.visualElement),
4716
4721
  });
4717
4722
  }
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-Dr1Bf9gl.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
 
@@ -2887,7 +2864,6 @@ exports.m = m;
2887
2864
  exports.motion = motion;
2888
2865
  exports.scroll = scroll;
2889
2866
  exports.scrollInfo = scrollInfo;
2890
- exports.stagger = stagger;
2891
2867
  exports.startOptimizedAppearAnimation = startOptimizedAppearAnimation;
2892
2868
  exports.unwrapMotionComponent = unwrapMotionComponent;
2893
2869
  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 };