/**
 * @title: 贝塞尔曲线
 * @description:
 * @param {CardAnimaProps} param1
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2023-04-03 15:25
 */
export var cubicBezier = function cubicBezier(_ref) {
  var position = _ref.position,
    cartElementId = _ref.cartElementId;
  var left = position.x;
  var top = position.y;
  var collect = cartElementId.startsWith('#') ? document.querySelector(cartElementId) : document.getElementById(cartElementId) || document.querySelector(cartElementId);
  var duration = top > 400 ? '.4s' : '.6s';
  var ball = document.createElement('div');
  ball.style.position = 'fixed';
  ball.style.left = left - 10 + 'px';
  ball.style.top = top - 10 + 'px';
  ball.style.width = '20px';
  ball.style.height = '20px';
  ball.style.borderRadius = '50%';
  ball.style.backgroundColor = 'var(--theme-color)';
  ball.style.zIndex = '9999';
  ball.style.transition = "left ".concat(duration, " linear, top ").concat(duration, " cubic-bezier(0.5, -0.5, 1, 1)");
  ball.innerHTML = '+';
  ball.style.color = '#ffffff';
  ball.style.textAlign = 'center';
  ball.style.lineHeight = '20px';
  if (collect) {
    document.body.appendChild(ball);
    setTimeout(function () {
      ball.style.left = collect.offsetLeft + collect.offsetWidth / 2 + 'px';
      ball.style.top = getOffsetTop(collect) + 'px';
    }, 0);

    // 防止 transitionend 不触发，超时兜底销毁
    var endTimeout = setTimeout(function () {
      ball.remove();
    }, top > 400 ? 400 : 600);
    ball.ontransitionend = function () {
      ball.remove();
      clearTimeout(endTimeout);
    };
  }
};

/**
 * @title: 递归获取元素距离窗口的位置
 * @description:
 * @param {any} element
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2023-04-03 15:46
 */
var getOffsetTop = function getOffsetTop(element) {
  var offsetTop = element.offsetTop;
  if (element.offsetParent) {
    offsetTop += getOffsetTop(element.offsetParent);
  }
  return offsetTop;
};