Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dragAndDrop.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const utils_1 = require("../../utils");
  4. const ACTION_BUTTON = 0;
  5. const sleep = (time = 0) => new Promise((resolve) => setTimeout(resolve, time));
  6. async function dragAndDrop(target, { duration = 10 } = {}) {
  7. const moveToCoordinates = target;
  8. const moveToElement = target;
  9. if (!target ||
  10. (target.constructor.name !== 'Element' &&
  11. (typeof moveToCoordinates.x !== 'number' ||
  12. typeof moveToCoordinates.y !== 'number'))) {
  13. throw new Error('command dragAndDrop requires an WebdriverIO Element or and object with "x" and "y" variables as first parameter');
  14. }
  15. const isMovingToElement = target.constructor.name === 'Element';
  16. if (!this.isW3C) {
  17. await this.moveTo();
  18. await this.buttonDown(ACTION_BUTTON);
  19. if (isMovingToElement) {
  20. await moveToElement.moveTo();
  21. }
  22. else {
  23. await this.moveToElement(null, moveToCoordinates.x, moveToCoordinates.y);
  24. }
  25. await sleep(duration);
  26. return this.buttonUp(ACTION_BUTTON);
  27. }
  28. const { scrollX, scrollY } = await utils_1.getScrollPosition(this);
  29. const sourceRect = await utils_1.getElementRect(this);
  30. const sourceX = Math.floor(sourceRect.x - scrollX + (sourceRect.width / 2));
  31. const sourceY = Math.floor(sourceRect.y - scrollY + (sourceRect.height / 2));
  32. let targetX, targetY;
  33. if (isMovingToElement) {
  34. const targetRect = await utils_1.getElementRect(moveToElement);
  35. targetX = Math.floor(targetRect.x - scrollX + (targetRect.width / 2) - sourceX);
  36. targetY = Math.floor(targetRect.y - scrollY + (targetRect.height / 2) - sourceY);
  37. }
  38. else {
  39. targetX = moveToCoordinates.x;
  40. targetY = moveToCoordinates.y;
  41. }
  42. return this.performActions([{
  43. type: 'pointer',
  44. id: 'finger1',
  45. parameters: { pointerType: 'mouse' },
  46. actions: [
  47. { type: 'pointerMove', duration: 0, x: sourceX, y: sourceY },
  48. { type: 'pointerDown', button: ACTION_BUTTON },
  49. { type: 'pause', duration: 10 },
  50. { type: 'pointerMove', duration, origin: 'pointer', x: targetX, y: targetY },
  51. { type: 'pointerUp', button: ACTION_BUTTON }
  52. ]
  53. }]).then(() => this.releaseActions());
  54. }
  55. exports.default = dragAndDrop;