@tamagui/animations-motion 3.0.0-beta.924.1 → 3.0.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.
@@ -39,17 +39,6 @@ var import_web = require("@tamagui/web");
39
39
  var import_internal_runtime = require("@tamagui/web/internal-runtime");
40
40
  var import_react = require("motion/react");
41
41
  var import_react2 = __toESM(require("react"), 1);
42
- function _instanceof(left, right) {
43
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
44
- return !!right[Symbol.hasInstance](left);
45
- } else {
46
- return left instanceof right;
47
- }
48
- }
49
- function _type_of(obj) {
50
- "@swc/helpers - typeof";
51
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
52
- }
53
42
  var isServer = typeof window === "undefined";
54
43
  function useAnimateSSRSafe() {
55
44
  if (isServer) {
@@ -58,7 +47,7 @@ function useAnimateSSRSafe() {
58
47
  return (0, import_react.useAnimate)();
59
48
  }
60
49
  var asStyleRecord = function(style) {
61
- return style && (typeof style === "undefined" ? "undefined" : _type_of(style)) === "object" && !Array.isArray(style) ? style : {};
50
+ return style && typeof style === "object" && !Array.isArray(style) ? style : {};
62
51
  };
63
52
  function assignInlineStyles(node, styles) {
64
53
  for (var key in styles) {
@@ -116,8 +105,9 @@ function createAnimations(animations) {
116
105
  if (isHydratingGlobal === void 0 && !(0, import_web.getConfig)().settings.disableSSR) {
117
106
  isHydratingGlobal = true;
118
107
  }
119
- var { props, style, componentState, stateRef, useStyleEmitter, presence, onTransition, styleProps } = animationProps;
120
- var animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition;
108
+ var { props, style, componentState, stateRef, useStyleEmitter, presence, onTransition, styleProps, styleState } = animationProps;
109
+ var _styleState_effectiveTransition;
110
+ var effectiveTransition = (_styleState_effectiveTransition = styleState === null || styleState === void 0 ? void 0 : styleState.effectiveTransition) !== null && _styleState_effectiveTransition !== void 0 ? _styleState_effectiveTransition : props.transition;
121
111
  var isComponentHydrating = componentState.unmounted === true;
122
112
  var isMounting = componentState.unmounted === "should-enter";
123
113
  var isEntering = !!componentState.unmounted;
@@ -166,7 +156,7 @@ function createAnimations(animations) {
166
156
  refs.current.wasEntering = isEntering;
167
157
  });
168
158
  var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
169
- var disableAnimation = isComponentHydrating || isMounting || !animationKey;
159
+ var disableAnimation = isComponentHydrating || isMounting || !effectiveTransition;
170
160
  var [scope] = useAnimateSSRSafe();
171
161
  refs.current.isExiting = isExiting;
172
162
  refs.current.sendExitComplete = sendExitComplete;
@@ -189,7 +179,7 @@ function createAnimations(animations) {
189
179
  emit("end", "exit", false);
190
180
  }
191
181
  }, [justStoppedExiting]);
192
- var { dontAnimate = {}, doAnimate, animationOptions } = getMotionAnimatedProps(props, style, disableAnimation, animationState);
182
+ var { dontAnimate = {}, doAnimate, animationOptions } = getMotionAnimatedProps(props, style, disableAnimation, animationState, effectiveTransition);
193
183
  var [firstRenderStyle] = (0, import_react2.useState)(style);
194
184
  if (refs.current.isFirstRender) {
195
185
  refs.current.lastDontAnimate = firstRenderStyle;
@@ -215,8 +205,7 @@ function createAnimations(animations) {
215
205
  if (isCurrentlyExiting && refs.current.frozenExitTarget) {
216
206
  doAnimate2 = refs.current.frozenExitTarget;
217
207
  }
218
- var _props_transition;
219
- var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((_props_transition = props.transition) !== null && _props_transition !== void 0 ? _props_transition : null, "exit") : passedOptions;
208
+ var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((0, import_animation_helpers.forAnimationState)((0, import_animation_helpers.resolveTransition)(effectiveTransition !== null && effectiveTransition !== void 0 ? effectiveTransition : null, { animations }), "exit")) : passedOptions;
220
209
  try {
221
210
  var node = stateRef.current.host;
222
211
  if (refs.current.isFirstRender) {
@@ -245,7 +234,7 @@ function createAnimations(animations) {
245
234
  console.groupEnd();
246
235
  }
247
236
  }
248
- if (!_instanceof(node, HTMLElement)) {
237
+ if (!(node instanceof HTMLElement)) {
249
238
  return;
250
239
  }
251
240
  var prevDont = refs.current.lastDontAnimate;
@@ -346,8 +335,8 @@ function createAnimations(animations) {
346
335
  }
347
336
  }
348
337
  var opts = animationOptions2;
349
- var _opts_transform, _ref;
350
- var positionTransition = (_ref = (_opts_transform = opts.transform) !== null && _opts_transform !== void 0 ? _opts_transform : opts.default) !== null && _ref !== void 0 ? _ref : animationOptions2;
338
+ var _opts_x, _ref, _ref1;
339
+ var positionTransition = (_ref1 = (_ref = (_opts_x = opts.x) !== null && _opts_x !== void 0 ? _opts_x : opts.transform) !== null && _ref !== void 0 ? _ref : opts.default) !== null && _ref1 !== void 0 ? _ref1 : animationOptions2;
351
340
  var cx = (0, import_react.animate)(entry.x, target.x, positionTransition);
352
341
  var cy = (0, import_react.animate)(entry.y, target.y, positionTransition);
353
342
  entry.stop = function() {
@@ -507,8 +496,8 @@ function createAnimations(animations) {
507
496
  }
508
497
  }
509
498
  };
510
- useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function(nextStyle, effectiveTransition) {
511
- var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
499
+ useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function(nextStyle, emittedTransition) {
500
+ var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, emittedTransition !== null && emittedTransition !== void 0 ? emittedTransition : effectiveTransition);
512
501
  flushAnimation(_$animationProps);
513
502
  });
514
503
  (0, import_web.useIsomorphicLayoutEffect)(function() {
@@ -535,7 +524,7 @@ function createAnimations(animations) {
535
524
  refs.current.wasNoClass = !!styleProps.noClass;
536
525
  if ((justEnabled || justStrippedClasses) && animationState !== "enter") {
537
526
  var node = stateRef.current.host;
538
- if (_instanceof(node, HTMLElement)) {
527
+ if (node instanceof HTMLElement) {
539
528
  if (dontAnimate) assignInlineStyles(node, dontAnimate);
540
529
  if (doAnimate) assignInlineStyles(node, doAnimate);
541
530
  var entry = PopperPositionAnims.get(node);
@@ -666,13 +655,13 @@ function createAnimations(animations) {
666
655
  return { dontAnimate: style };
667
656
  }
668
657
  var _ref;
669
- var animationOptions = getAnimationOptions((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, animationState);
658
+ var resolved = (0, import_animation_helpers.forAnimationState)((0, import_animation_helpers.resolveTransition)((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, { animations }), animationState);
659
+ var animationOptions = getAnimationOptions(resolved);
670
660
  var dontAnimate;
671
661
  var doAnimate;
672
- var animateOnly = props.animateOnly;
673
662
  for (var key in style) {
674
663
  var value = style[key];
675
- if (disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key)) {
664
+ if (disableAnimationProps.has(key) || !(0, import_animation_helpers.getTransitionForKey)(resolved, key)) {
676
665
  dontAnimate || (dontAnimate = {});
677
666
  dontAnimate[key] = value;
678
667
  } else {
@@ -686,51 +675,39 @@ function createAnimations(animations) {
686
675
  animationOptions
687
676
  };
688
677
  }
689
- function getAnimationOptions(transitionProp) {
690
- var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default";
691
- var normalized = (0, import_animation_helpers.normalizeTransition)(transitionProp);
692
- var effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
693
- if (!effectiveKey && animationState === "default") {
694
- effectiveKey = normalized.enter || normalized.exit || null;
695
- }
696
- var globalConfigOverride = normalized.config ? { ...normalized.config } : void 0;
697
- if (!effectiveKey && Object.keys(normalized.properties).length === 0 && !globalConfigOverride) {
698
- return {};
699
- }
700
- var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null;
701
- var delay = normalized.delay;
678
+ function getAnimationOptions(resolved) {
679
+ if (!(0, import_animation_helpers.hasTransition)(resolved)) return {};
702
680
  var result = {};
703
- if (defaultConfig) {
704
- Object.assign(result, defaultConfig);
705
- }
706
- if (globalConfigOverride) {
707
- Object.assign(result, globalConfigOverride);
708
- if (result.type === void 0 && result.duration !== void 0 && result.damping === void 0 && result.stiffness === void 0 && result.mass === void 0) {
709
- result.type = "tween";
710
- }
711
- }
712
- if (delay) {
713
- result.delay = delay;
714
- }
715
- if (defaultConfig || globalConfigOverride || delay) {
716
- result.default = {
717
- ...defaultConfig,
718
- ...globalConfigOverride,
719
- ...delay ? { delay } : null
720
- };
681
+ if (resolved.all) {
682
+ var base = entryToMotion(resolved.all);
683
+ Object.assign(result, base);
684
+ result.default = { ...base };
721
685
  }
722
686
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
723
687
  try {
724
- for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
725
- var [propName, animationNameOrConfig] = _step.value;
726
- if (typeof animationNameOrConfig === "string") {
727
- result[propName] = withInferredType(animations[animationNameOrConfig]);
728
- } else if (animationNameOrConfig && (typeof animationNameOrConfig === "undefined" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
729
- var baseConfig = animationNameOrConfig.type ? withInferredType(animations[animationNameOrConfig.type]) : defaultConfig;
730
- result[propName] = {
731
- ...baseConfig,
732
- ...animationNameOrConfig
733
- };
688
+ for (var _iterator = resolved.entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
689
+ var entry = _step.value;
690
+ if (entry.property === "all") continue;
691
+ var config = entryToMotion(entry);
692
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
693
+ try {
694
+ for (var _iterator1 = (0, import_animation_helpers.styleKeysForProperty)(entry.property)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
695
+ var key = _step1.value;
696
+ result[key] = { ...config };
697
+ }
698
+ } catch (err) {
699
+ _didIteratorError1 = true;
700
+ _iteratorError1 = err;
701
+ } finally {
702
+ try {
703
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
704
+ _iterator1.return();
705
+ }
706
+ } finally {
707
+ if (_didIteratorError1) {
708
+ throw _iteratorError1;
709
+ }
710
+ }
734
711
  }
735
712
  }
736
713
  } catch (err) {
@@ -747,36 +724,33 @@ function createAnimations(animations) {
747
724
  }
748
725
  }
749
726
  }
750
- convertMsToS(result);
751
- convertMsToS(result.default);
752
- for (var key in result) {
753
- if (key !== "default" && _type_of(result[key]) === "object") {
754
- convertMsToS(result[key]);
755
- }
756
- }
757
727
  return result;
758
728
  }
759
729
  }
760
- function withInferredType(config) {
761
- if (!config) {
762
- return { type: "spring" };
730
+ function entryToMotion(entry) {
731
+ var delay = entry.delayMs ? { delay: entry.delayMs / 1e3 } : null;
732
+ if (entry.timing.kind === "spring") {
733
+ return {
734
+ type: "spring",
735
+ stiffness: entry.timing.stiffness,
736
+ damping: entry.timing.damping,
737
+ mass: entry.timing.mass,
738
+ ...delay
739
+ };
763
740
  }
764
- var isTimingBased = config.duration !== void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
741
+ var bezier = (0, import_animation_helpers.easingToBezier)(entry.timing.easing);
765
742
  return {
766
- type: isTimingBased ? "tween" : "spring",
767
- ...config
743
+ type: "tween",
744
+ duration: entry.timing.durationMs / 1e3,
745
+ ...bezier ? { ease: [
746
+ bezier[0],
747
+ bezier[1],
748
+ bezier[2],
749
+ bezier[3]
750
+ ] } : null,
751
+ ...delay
768
752
  };
769
753
  }
770
- function convertMsToS(config) {
771
- if (!config) return;
772
- if (typeof config.delay === "number") config.delay = config.delay / 1e3;
773
- if (typeof config.duration === "number") {
774
- var isTimingBased = config.type === "tween" || config.type === void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
775
- if (isTimingBased) {
776
- config.duration = config.duration / 1e3;
777
- }
778
- }
779
- }
780
754
  function removeRemovedStyles(prev, next, node, dontClearIfIn) {
781
755
  for (var key in prev) {
782
756
  if (!(key in next)) {
@@ -1002,7 +976,7 @@ function createMotionView(defaultTag) {
1002
976
  (0, import_web.useIsomorphicLayoutEffect)(function() {
1003
977
  if (!animatedStyle) return;
1004
978
  var node = hostRef.current;
1005
- if (_instanceof(node, HTMLElement) && seededNode.current !== node) {
979
+ if (node instanceof HTMLElement && seededNode.current !== node) {
1006
980
  var currentStyle = animatedStyle.motionValues ? animatedStyle.getStyle(...animatedStyle.motionValues.map(function(value) {
1007
981
  return value.get();
1008
982
  })) : animatedStyle.motionValue ? animatedStyle.getStyle(animatedStyle.motionValue.get()) : null;
@@ -1029,7 +1003,7 @@ function createMotionView(defaultTag) {
1029
1003
  };
1030
1004
  };
1031
1005
  var animateNodeTo = function(nextStyle, transition, motionValue3) {
1032
- if (!_instanceof(node, HTMLElement) || hostRef.current !== node) return;
1006
+ if (!(node instanceof HTMLElement) || hostRef.current !== node) return;
1033
1007
  var webStyle2 = resolvedAnimatedStyle === null || resolvedAnimatedStyle === void 0 ? void 0 : resolvedAnimatedStyle.resolve(nextStyle);
1034
1008
  if (!webStyle2) return;
1035
1009
  settlePendingMotionOnFinish(motionValue3, animate(node, webStyle2, transition));