text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = dragAndDrop;
  
  var _utils = require("../../utils");
  
  const ACTION_BUTTON = 0;
  
  async function dragAndDrop(target, duration = 100) {
    if (!target || target.constructor.name !== 'Element') {
      throw new Error('command dragAndDrop requires an WebdriverIO Element as first parameter');
    }
  
    if (!this.isW3C) {
      await this.moveTo();
      await this.buttonDown(ACTION_BUTTON);
      await target.moveTo();
      return this.buttonUp(ACTION_BUTTON);
    }
  
    const {
      scrollX,
      scrollY
    } = await (0, _utils.getScrollPosition)(this);
    const sourceRect = await (0, _utils.getElementRect)(this);
    const targetRect = await (0, _utils.getElementRect)(target);
    const sourceX = parseInt(sourceRect.x - scrollX + sourceRect.width / 2, 10);
    const sourceY = parseInt(sourceRect.y - scrollY + sourceRect.height / 2, 10);
    const targetX = parseInt(targetRect.x - scrollX + targetRect.width / 2, 10) - sourceX;
    const targetY = parseInt(targetRect.y - scrollY + targetRect.height / 2, 10) - sourceY;
    return this.performActions([{
      type: 'pointer',
      id: 'finger1',
      parameters: {
        pointerType: 'mouse'
      },
      actions: [{
        type: 'pointerMove',
        duration: 0,
        x: sourceX,
        y: sourceY
      }, {
        type: 'pointerDown',
        button: ACTION_BUTTON
      }, {
        type: 'pause',
        duration: 10
      }, {
        type: 'pointerMove',
        duration,
        origin: 'pointer',
        x: targetX,
        y: targetY
      }, {
        type: 'pointerUp',
        button: ACTION_BUTTON
      }]
    }]).then(() => this.releaseActions());
  }