motion-dom 12.29.2 → 12.30.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.
package/dist/cjs/index.js CHANGED
@@ -2134,7 +2134,8 @@ class NativeAnimation extends WithPromise {
2134
2134
  * while deferring the commit until the next animation frame.
2135
2135
  */
2136
2136
  commitStyles() {
2137
- if (!this.isPseudoElement) {
2137
+ const element = this.options?.element;
2138
+ if (!this.isPseudoElement && element?.isConnected) {
2138
2139
  this.animation.commitStyles?.();
2139
2140
  }
2140
2141
  }
@@ -2835,7 +2836,8 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
2835
2836
  }
2836
2837
  }
2837
2838
  if (motionUtils.MotionGlobalConfig.instantAnimations ||
2838
- motionUtils.MotionGlobalConfig.skipAnimations) {
2839
+ motionUtils.MotionGlobalConfig.skipAnimations ||
2840
+ element?.shouldSkipAnimations) {
2839
2841
  shouldSkip = true;
2840
2842
  makeAnimationInstant(options);
2841
2843
  options.delay = 0;
@@ -4280,7 +4282,7 @@ const isPrimaryPointer = (event) => {
4280
4282
  }
4281
4283
  };
4282
4284
 
4283
- const interactiveElements = new Set([
4285
+ const keyboardAccessibleElements = new Set([
4284
4286
  "BUTTON",
4285
4287
  "INPUT",
4286
4288
  "SELECT",
@@ -4288,15 +4290,27 @@ const interactiveElements = new Set([
4288
4290
  "A",
4289
4291
  ]);
4290
4292
  /**
4291
- * Checks if an element is an interactive form element that should prevent
4292
- * drag gestures from starting when clicked.
4293
- *
4294
- * This specifically targets form controls, buttons, and links - not just any
4295
- * element with tabIndex, since motion elements with tap handlers automatically
4296
- * get tabIndex=0 for keyboard accessibility.
4293
+ * Checks if an element is natively keyboard accessible (focusable).
4294
+ * Used by the press gesture to determine if we need to add tabIndex.
4297
4295
  */
4298
4296
  function isElementKeyboardAccessible(element) {
4299
- return (interactiveElements.has(element.tagName) ||
4297
+ return (keyboardAccessibleElements.has(element.tagName) ||
4298
+ element.isContentEditable === true);
4299
+ }
4300
+ const textInputElements = new Set(["INPUT", "SELECT", "TEXTAREA"]);
4301
+ /**
4302
+ * Checks if an element has text selection or direct interaction behavior
4303
+ * that should block drag gestures from starting.
4304
+ *
4305
+ * This specifically targets form controls where the user might want to select
4306
+ * text or interact with the control (e.g., sliders, dropdowns).
4307
+ *
4308
+ * Buttons and links are NOT included because they don't have click-and-move
4309
+ * actions of their own - they only respond to click events, so dragging
4310
+ * should still work when initiated from these elements.
4311
+ */
4312
+ function isElementTextInput(element) {
4313
+ return (textInputElements.has(element.tagName) ||
4300
4314
  element.isContentEditable === true);
4301
4315
  }
4302
4316
 
@@ -5379,7 +5393,7 @@ class VisualElement {
5379
5393
  scrapeMotionValuesFromProps(_props, _prevProps, _visualElement) {
5380
5394
  return {};
5381
5395
  }
5382
- constructor({ parent, props, presenceContext, reducedMotionConfig, blockInitialAnimation, visualState, }, options = {}) {
5396
+ constructor({ parent, props, presenceContext, reducedMotionConfig, skipAnimations, blockInitialAnimation, visualState, }, options = {}) {
5383
5397
  /**
5384
5398
  * A reference to the current underlying Instance, e.g. a HTMLElement
5385
5399
  * or Three.Mesh etc.
@@ -5402,6 +5416,11 @@ class VisualElement {
5402
5416
  * like it could be set globally.
5403
5417
  */
5404
5418
  this.shouldReduceMotion = null;
5419
+ /**
5420
+ * Decides whether animations should be skipped for this VisualElement.
5421
+ * Useful for E2E tests and visual regression testing.
5422
+ */
5423
+ this.shouldSkipAnimations = false;
5405
5424
  /**
5406
5425
  * A map of all motion values attached to this visual element. Motion
5407
5426
  * values are source of truth for any given animated value. A motion
@@ -5459,6 +5478,7 @@ class VisualElement {
5459
5478
  this.presenceContext = presenceContext;
5460
5479
  this.depth = parent ? parent.depth + 1 : 0;
5461
5480
  this.reducedMotionConfig = reducedMotionConfig;
5481
+ this.skipAnimationsConfig = skipAnimations;
5462
5482
  this.options = options;
5463
5483
  this.blockInitialAnimation = Boolean(blockInitialAnimation);
5464
5484
  this.isControllingVariants = isControllingVariants(props);
@@ -5515,6 +5535,10 @@ class VisualElement {
5515
5535
  if (process.env.NODE_ENV !== "production") {
5516
5536
  motionUtils.warnOnce(this.shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.", "reduced-motion-disabled");
5517
5537
  }
5538
+ /**
5539
+ * Set whether animations should be skipped based on the config.
5540
+ */
5541
+ this.shouldSkipAnimations = this.skipAnimationsConfig ?? false;
5518
5542
  this.parent?.addChild(this);
5519
5543
  this.update(this.props, this.presenceContext);
5520
5544
  }
@@ -9287,6 +9311,11 @@ function getOrCreateRecord(element, parentProjection, projectionOptions) {
9287
9311
  if (!visualElement.current) {
9288
9312
  visualElement.mount(element);
9289
9313
  }
9314
+ else if (!visualElement.projection.instance) {
9315
+ // Mount projection if VisualElement is already mounted but projection isn't
9316
+ // This happens when animate() was called before animateLayout()
9317
+ visualElement.projection.mount(element);
9318
+ }
9290
9319
  if (!existing) {
9291
9320
  visualElementStore.set(element, visualElement);
9292
9321
  }
@@ -9491,6 +9520,7 @@ exports.isDeltaZero = isDeltaZero;
9491
9520
  exports.isDragActive = isDragActive;
9492
9521
  exports.isDragging = isDragging;
9493
9522
  exports.isElementKeyboardAccessible = isElementKeyboardAccessible;
9523
+ exports.isElementTextInput = isElementTextInput;
9494
9524
  exports.isForcedMotionValue = isForcedMotionValue;
9495
9525
  exports.isGenerator = isGenerator;
9496
9526
  exports.isHTMLElement = isHTMLElement;