motion 11.16.0 → 11.16.2

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
@@ -1357,7 +1357,7 @@ class MotionValue {
1357
1357
  * This will be replaced by the build step with the latest version number.
1358
1358
  * When MotionValues are provided to motion components, warn if versions are mixed.
1359
1359
  */
1360
- this.version = "11.16.0";
1360
+ this.version = "11.16.2";
1361
1361
  /**
1362
1362
  * Tracks whether this value can output a velocity. Currently this is only true
1363
1363
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4293,7 +4293,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4293
4293
  * and warn against mismatches.
4294
4294
  */
4295
4295
  if (process.env.NODE_ENV === "development") {
4296
- warnOnce(nextValue.version === "11.16.0", `Attempting to mix Motion versions ${nextValue.version} with 11.16.0 may not work as expected.`);
4296
+ warnOnce(nextValue.version === "11.16.2", `Attempting to mix Motion versions ${nextValue.version} with 11.16.2 may not work as expected.`);
4297
4297
  }
4298
4298
  }
4299
4299
  else if (isMotionValue(prevValue)) {
@@ -417,6 +417,25 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
417
417
  return cancel;
418
418
  }
419
419
 
420
+ /**
421
+ * Recursively traverse up the tree to check whether the provided child node
422
+ * is the parent or a descendant of it.
423
+ *
424
+ * @param parent - Element to find
425
+ * @param child - Element to test against parent
426
+ */
427
+ const isNodeOrChild = (parent, child) => {
428
+ if (!child) {
429
+ return false;
430
+ }
431
+ else if (parent === child) {
432
+ return true;
433
+ }
434
+ else {
435
+ return isNodeOrChild(parent, child.parentElement);
436
+ }
437
+ };
438
+
420
439
  const isPrimaryPointer = (event) => {
421
440
  if (event.pointerType === "mouse") {
422
441
  return typeof event.button !== "number" || event.button <= 0;
@@ -434,6 +453,17 @@ const isPrimaryPointer = (event) => {
434
453
  }
435
454
  };
436
455
 
456
+ const focusableElements = new Set([
457
+ "BUTTON",
458
+ "INPUT",
459
+ "SELECT",
460
+ "TEXTAREA",
461
+ "A",
462
+ ]);
463
+ function isElementKeyboardAccessible(element) {
464
+ return focusableElements.has(element.tagName) || element.tabIndex !== -1;
465
+ }
466
+
437
467
  const isPressing = new WeakSet();
438
468
 
439
469
  /**
@@ -471,36 +501,6 @@ const enableKeyboardPress = (focusEvent, eventOptions) => {
471
501
  element.addEventListener("blur", () => element.removeEventListener("keydown", handleKeydown), eventOptions);
472
502
  };
473
503
 
474
- const focusableElements = new Set([
475
- "BUTTON",
476
- "INPUT",
477
- "SELECT",
478
- "TEXTAREA",
479
- "A",
480
- ]);
481
- function isElementKeyboardAccessible(element) {
482
- return focusableElements.has(element.tagName) || element.tabIndex !== -1;
483
- }
484
-
485
- /**
486
- * Recursively traverse up the tree to check whether the provided child node
487
- * is the parent or a descendant of it.
488
- *
489
- * @param parent - Element to find
490
- * @param child - Element to test against parent
491
- */
492
- const isNodeOrChild = (parent, child) => {
493
- if (!child) {
494
- return false;
495
- }
496
- else if (parent === child) {
497
- return true;
498
- }
499
- else {
500
- return isNodeOrChild(parent, child.parentElement);
501
- }
502
- };
503
-
504
504
  /**
505
505
  * Filter out events that are not primary pointer events, or are triggering
506
506
  * while a Motion gesture is active.
@@ -557,7 +557,8 @@ function press(elementOrSelector, onPressStart, options = {}) {
557
557
  window.addEventListener("pointercancel", onPointerCancel, eventOptions);
558
558
  };
559
559
  elements.forEach((element) => {
560
- if (!isElementKeyboardAccessible(element)) {
560
+ if (!isElementKeyboardAccessible(element) &&
561
+ element.getAttribute("tabindex") === null) {
561
562
  element.tabIndex = 0;
562
563
  }
563
564
  const target = options.useGlobalTarget ? window : element;
@@ -903,7 +904,7 @@ class MotionValue {
903
904
  * This will be replaced by the build step with the latest version number.
904
905
  * When MotionValues are provided to motion components, warn if versions are mixed.
905
906
  */
906
- this.version = "11.16.0";
907
+ this.version = "11.16.2";
907
908
  /**
908
909
  * Tracks whether this value can output a velocity. Currently this is only true
909
910
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -8103,6 +8104,8 @@ const layout = {
8103
8104
  },
8104
8105
  };
8105
8106
 
8107
+ const LazyContext = react.createContext({ strict: false });
8108
+
8106
8109
  /**
8107
8110
  * @public
8108
8111
  */
@@ -8114,11 +8117,108 @@ const MotionConfigContext = react.createContext({
8114
8117
 
8115
8118
  const MotionContext = react.createContext({});
8116
8119
 
8120
+ function isControllingVariants(props) {
8121
+ return (isAnimationControls(props.animate) ||
8122
+ variantProps.some((name) => isVariantLabel(props[name])));
8123
+ }
8124
+ function isVariantNode(props) {
8125
+ return Boolean(isControllingVariants(props) || props.variants);
8126
+ }
8127
+
8128
+ function getCurrentTreeVariants(props, context) {
8129
+ if (isControllingVariants(props)) {
8130
+ const { initial, animate } = props;
8131
+ return {
8132
+ initial: initial === false || isVariantLabel(initial)
8133
+ ? initial
8134
+ : undefined,
8135
+ animate: isVariantLabel(animate) ? animate : undefined,
8136
+ };
8137
+ }
8138
+ return props.inherit !== false ? context : {};
8139
+ }
8140
+
8141
+ function useCreateMotionContext(props) {
8142
+ const { initial, animate } = getCurrentTreeVariants(props, react.useContext(MotionContext));
8143
+ return react.useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]);
8144
+ }
8145
+ function variantLabelsAsDependency(prop) {
8146
+ return Array.isArray(prop) ? prop.join(" ") : prop;
8147
+ }
8148
+
8117
8149
  const isBrowser = typeof window !== "undefined";
8118
8150
 
8119
- const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
8151
+ const featureProps = {
8152
+ animation: [
8153
+ "animate",
8154
+ "variants",
8155
+ "whileHover",
8156
+ "whileTap",
8157
+ "exit",
8158
+ "whileInView",
8159
+ "whileFocus",
8160
+ "whileDrag",
8161
+ ],
8162
+ exit: ["exit"],
8163
+ drag: ["drag", "dragControls"],
8164
+ focus: ["whileFocus"],
8165
+ hover: ["whileHover", "onHoverStart", "onHoverEnd"],
8166
+ tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"],
8167
+ pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"],
8168
+ inView: ["whileInView", "onViewportEnter", "onViewportLeave"],
8169
+ layout: ["layout", "layoutId"],
8170
+ };
8171
+ const featureDefinitions = {};
8172
+ for (const key in featureProps) {
8173
+ featureDefinitions[key] = {
8174
+ isEnabled: (props) => featureProps[key].some((name) => !!props[name]),
8175
+ };
8176
+ }
8120
8177
 
8121
- const LazyContext = react.createContext({ strict: false });
8178
+ function loadFeatures(features) {
8179
+ for (const key in features) {
8180
+ featureDefinitions[key] = {
8181
+ ...featureDefinitions[key],
8182
+ ...features[key],
8183
+ };
8184
+ }
8185
+ }
8186
+
8187
+ const motionComponentSymbol = Symbol.for("motionComponentSymbol");
8188
+
8189
+ /**
8190
+ * Creates a ref function that, when called, hydrates the provided
8191
+ * external ref and VisualElement.
8192
+ */
8193
+ function useMotionRef(visualState, visualElement, externalRef) {
8194
+ return react.useCallback((instance) => {
8195
+ instance && visualState.mount && visualState.mount(instance);
8196
+ if (visualElement) {
8197
+ if (instance) {
8198
+ visualElement.mount(instance);
8199
+ }
8200
+ else {
8201
+ visualElement.unmount();
8202
+ }
8203
+ }
8204
+ if (externalRef) {
8205
+ if (typeof externalRef === "function") {
8206
+ externalRef(instance);
8207
+ }
8208
+ else if (isRefObject(externalRef)) {
8209
+ externalRef.current = instance;
8210
+ }
8211
+ }
8212
+ },
8213
+ /**
8214
+ * Only pass a new ref callback to React if we've received a visual element
8215
+ * factory. Otherwise we'll be mounting/remounting every time externalRef
8216
+ * or other dependencies change.
8217
+ */
8218
+ [visualElement]);
8219
+ }
8220
+
8221
+ const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
8122
8222
 
8123
8223
  function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor) {
8124
8224
  var _a, _b;
@@ -8242,105 +8342,6 @@ function getClosestProjectingNode(visualElement) {
8242
8342
  : getClosestProjectingNode(visualElement.parent);
8243
8343
  }
8244
8344
 
8245
- /**
8246
- * Creates a ref function that, when called, hydrates the provided
8247
- * external ref and VisualElement.
8248
- */
8249
- function useMotionRef(visualState, visualElement, externalRef) {
8250
- return react.useCallback((instance) => {
8251
- instance && visualState.mount && visualState.mount(instance);
8252
- if (visualElement) {
8253
- if (instance) {
8254
- visualElement.mount(instance);
8255
- }
8256
- else {
8257
- visualElement.unmount();
8258
- }
8259
- }
8260
- if (externalRef) {
8261
- if (typeof externalRef === "function") {
8262
- externalRef(instance);
8263
- }
8264
- else if (isRefObject(externalRef)) {
8265
- externalRef.current = instance;
8266
- }
8267
- }
8268
- },
8269
- /**
8270
- * Only pass a new ref callback to React if we've received a visual element
8271
- * factory. Otherwise we'll be mounting/remounting every time externalRef
8272
- * or other dependencies change.
8273
- */
8274
- [visualElement]);
8275
- }
8276
-
8277
- function isControllingVariants(props) {
8278
- return (isAnimationControls(props.animate) ||
8279
- variantProps.some((name) => isVariantLabel(props[name])));
8280
- }
8281
- function isVariantNode(props) {
8282
- return Boolean(isControllingVariants(props) || props.variants);
8283
- }
8284
-
8285
- function getCurrentTreeVariants(props, context) {
8286
- if (isControllingVariants(props)) {
8287
- const { initial, animate } = props;
8288
- return {
8289
- initial: initial === false || isVariantLabel(initial)
8290
- ? initial
8291
- : undefined,
8292
- animate: isVariantLabel(animate) ? animate : undefined,
8293
- };
8294
- }
8295
- return props.inherit !== false ? context : {};
8296
- }
8297
-
8298
- function useCreateMotionContext(props) {
8299
- const { initial, animate } = getCurrentTreeVariants(props, react.useContext(MotionContext));
8300
- return react.useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]);
8301
- }
8302
- function variantLabelsAsDependency(prop) {
8303
- return Array.isArray(prop) ? prop.join(" ") : prop;
8304
- }
8305
-
8306
- const featureProps = {
8307
- animation: [
8308
- "animate",
8309
- "variants",
8310
- "whileHover",
8311
- "whileTap",
8312
- "exit",
8313
- "whileInView",
8314
- "whileFocus",
8315
- "whileDrag",
8316
- ],
8317
- exit: ["exit"],
8318
- drag: ["drag", "dragControls"],
8319
- focus: ["whileFocus"],
8320
- hover: ["whileHover", "onHoverStart", "onHoverEnd"],
8321
- tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"],
8322
- pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"],
8323
- inView: ["whileInView", "onViewportEnter", "onViewportLeave"],
8324
- layout: ["layout", "layoutId"],
8325
- };
8326
- const featureDefinitions = {};
8327
- for (const key in featureProps) {
8328
- featureDefinitions[key] = {
8329
- isEnabled: (props) => featureProps[key].some((name) => !!props[name]),
8330
- };
8331
- }
8332
-
8333
- function loadFeatures(features) {
8334
- for (const key in features) {
8335
- featureDefinitions[key] = {
8336
- ...featureDefinitions[key],
8337
- ...features[key],
8338
- };
8339
- }
8340
- }
8341
-
8342
- const motionComponentSymbol = Symbol.for("motionComponentSymbol");
8343
-
8344
8345
  /**
8345
8346
  * Create a `motion` component.
8346
8347
  *
@@ -8351,6 +8352,7 @@ const motionComponentSymbol = Symbol.for("motionComponentSymbol");
8351
8352
  * component "offline", or outside the React render cycle.
8352
8353
  */
8353
8354
  function createRendererMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component, }) {
8355
+ var _a, _b;
8354
8356
  preloadedFeatures && loadFeatures(preloadedFeatures);
8355
8357
  function MotionComponent(props, externalRef) {
8356
8358
  /**
@@ -8384,6 +8386,9 @@ function createRendererMotionComponent({ preloadedFeatures, createVisualElement,
8384
8386
  */
8385
8387
  return (jsxRuntime.jsxs(MotionContext.Provider, { value: context, children: [MeasureLayout && context.visualElement ? (jsxRuntime.jsx(MeasureLayout, { visualElement: context.visualElement, ...configAndProps })) : null, useRender(Component, props, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement)] }));
8386
8388
  }
8389
+ MotionComponent.displayName = `motion.${typeof Component === "string"
8390
+ ? Component
8391
+ : `create(${(_b = (_a = Component.displayName) !== null && _a !== void 0 ? _a : Component.name) !== null && _b !== void 0 ? _b : ""})`}`;
8387
8392
  const ForwardRefMotionComponent = react.forwardRef(MotionComponent);
8388
8393
  ForwardRefMotionComponent[motionComponentSymbol] = Component;
8389
8394
  return ForwardRefMotionComponent;
@@ -9170,7 +9175,7 @@ function updateMotionValuesFromProps(element, next, prev) {
9170
9175
  * and warn against mismatches.
9171
9176
  */
9172
9177
  if (process.env.NODE_ENV === "development") {
9173
- warnOnce(nextValue.version === "11.16.0", `Attempting to mix Motion versions ${nextValue.version} with 11.16.0 may not work as expected.`);
9178
+ warnOnce(nextValue.version === "11.16.2", `Attempting to mix Motion versions ${nextValue.version} with 11.16.2 may not work as expected.`);
9174
9179
  }
9175
9180
  }
9176
9181
  else if (isMotionValue(prevValue)) {