UNPKG

@razorpay/blade

Version:

The Design System that powers Razorpay

61 lines (55 loc) 3.42 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // This type is exported in new framer-motion versions but does not exist in earlier versions so adding it manually here var motionTriggersArrayToGesturePropsMap = { mount: 'animate', hover: 'whileHover', 'in-view': 'whileInView', tap: 'whileTap', focus: 'whileFocus' }; var makeAnimationVariables = function makeAnimationVariables(motionTriggers, _ref) { var animateVisibility = _ref.animateVisibility; var interactionVariables = motionTriggers.reduce(function (prevProps, currentTrigger) { if (currentTrigger === 'on-animate-interactions') { return prevProps; } // Sometimes animations are conditional. In those cases we use those conditional values in animate if (currentTrigger === 'mount' && animateVisibility) { prevProps.animate = animateVisibility; return prevProps; } prevProps[motionTriggersArrayToGesturePropsMap[currentTrigger]] = 'animate'; return prevProps; }, {}); return _objectSpread({ initial: 'initial', exit: 'exit' }, interactionVariables); }; var useMotionVariants = function useMotionVariants(motionVariants, type) { var _motionVariants$anima, _motionVariants$anima2, _motionVariants$anima3, _motionVariants$exit$; if (!motionVariants) { return undefined; } var shouldSkipEntryAnimation = type === 'out'; var shouldSkipExitAnimation = type === 'in'; // We override durations to stop animations but still continue with the expected position changes var newMotionVariants = { initial: _objectSpread({}, motionVariants.initial), animate: _objectSpread(_objectSpread({}, motionVariants.animate), {}, { transition: _objectSpread(_objectSpread({}, (_motionVariants$anima = motionVariants.animate) === null || _motionVariants$anima === void 0 ? void 0 : _motionVariants$anima.transition), {}, { duration: shouldSkipEntryAnimation ? 0.0001 : (_motionVariants$anima2 = motionVariants.animate) === null || _motionVariants$anima2 === void 0 ? void 0 : (_motionVariants$anima3 = _motionVariants$anima2.transition) === null || _motionVariants$anima3 === void 0 ? void 0 : _motionVariants$anima3.duration }) }), exit: _objectSpread(_objectSpread({}, motionVariants.exit), {}, { transition: _objectSpread(_objectSpread({}, motionVariants.exit.transition), {}, { duration: shouldSkipExitAnimation ? 0.0001 : (_motionVariants$exit$ = motionVariants.exit.transition) === null || _motionVariants$exit$ === void 0 ? void 0 : _motionVariants$exit$.duration }) }) }; return newMotionVariants; }; export { makeAnimationVariables, useMotionVariants }; //# sourceMappingURL=baseMotionUtils.js.map