"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SlideIn = exports.Scale = exports.Slide = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _reactSpring = require("react-spring");

var _styles = _interopRequireDefault(require("./styles"));

var __jsx = _react["default"].createElement;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

// Easing function from d3-ease: https://github.com/d3/d3-ease/blob/master/src/exp.js
function expOut(t) {
  return 1 - Math.pow(2, -10 * t);
} // function expInOut(t) {
//   return (
//     ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) /
//     2
//   );
// }


var Slide = function Slide(_ref) {
  var inProp = _ref["in"],
      children = _ref.children,
      duration = _ref.duration,
      from = _ref.from,
      finalHeight = _ref.finalHeight,
      finalWidth = _ref.finalWidth;

  var _useTransitionStyle = (0, _styles["default"])({
    from: from,
    finalHeight: finalHeight,
    finalWidth: finalWidth
  }),
      slide = _useTransitionStyle.slide;

  var root = slide.root,
      placement = slide.placement,
      transitionOption = slide.transitionOption;
  var slideDuration = duration || root.duration;
  var transform = transitionOption.transform,
      offset = transitionOption.offset;
  return __jsx(_reactSpring.Transition, {
    items: inProp,
    from: {
      opacity: 0,
      offset: offset
    },
    enter: {
      opacity: 1,
      offset: '0%'
    },
    leave: {
      opacity: 0,
      offset: offset
    },
    config: {
      duration: slideDuration,
      easing: expOut
    }
  }, function (inPropI) {
    return inPropI && function (styles) {
      return children(_objectSpread({
        willChange: 'opacity, transform',
        opacity: styles.opacity,
        transform: transform(styles.offset)
      }, placement), null, null);
    };
  });
};

exports.Slide = Slide;

var Scale = function Scale(_ref2) {
  var inProp = _ref2["in"],
      initialScale = _ref2.initialScale,
      duration = _ref2.duration,
      children = _ref2.children,
      rest = (0, _objectWithoutProperties2["default"])(_ref2, ["in", "initialScale", "duration", "children"]);

  var _useTransitionStyle2 = (0, _styles["default"])({}),
      scale = _useTransitionStyle2.scale;

  var scaleInitialScale = initialScale || scale.initialScale;
  var scaleDuration = duration || scale.duration;
  return __jsx(_reactSpring.Transition, (0, _extends2["default"])({
    items: inProp,
    config: {
      duration: scaleDuration
    },
    from: {
      opacity: 0,
      transform: "scale(".concat(scaleInitialScale, ")")
    },
    enter: {
      opacity: 1,
      transform: "scale(1)"
    },
    leave: {
      opacity: 0,
      transform: "scale(".concat(scaleInitialScale, ")")
    }
  }, rest), function (inPropI) {
    return inPropI && function (styles) {
      return children(_objectSpread(_objectSpread({
        willChange: 'opacity, transform'
      }, styles), rest));
    };
  });
};

exports.Scale = Scale;

var SlideIn = function SlideIn(_ref3) {
  var inProp = _ref3["in"],
      offset = _ref3.offset,
      duration = _ref3.duration,
      children = _ref3.children,
      rest = (0, _objectWithoutProperties2["default"])(_ref3, ["in", "offset", "duration", "children"]);

  var _useTransitionStyle3 = (0, _styles["default"])({}),
      slideIn = _useTransitionStyle3.slideIn;

  var slideInOffset = offset || slideIn.offset;
  var slideInDuration = duration || slideIn.duration;
  return __jsx(_reactSpring.Transition, (0, _extends2["default"])({
    items: inProp,
    config: {
      duration: slideInDuration
    },
    from: {
      opacity: 0,
      transform: "translate3d(0, ".concat(slideInOffset, ", 0)")
    },
    enter: {
      opacity: 1,
      transform: "translate3d(0, 0, 0)"
    },
    leave: {
      opacity: 0,
      transform: "translate3d(0, ".concat(slideInOffset, ", 0)")
    }
  }, rest), function (inPropI) {
    return inPropI && function (styles) {
      return children(_objectSpread(_objectSpread({
        willChange: 'opacity, transform'
      }, styles), rest));
    };
  });
};

exports.SlideIn = SlideIn;
//# sourceMappingURL=Transition.js.map