input.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var input_exports = {};
  20. __export(input_exports, {
  21. Keyboard: () => Keyboard,
  22. Mouse: () => Mouse,
  23. Touchscreen: () => Touchscreen
  24. });
  25. module.exports = __toCommonJS(input_exports);
  26. class Keyboard {
  27. constructor(page) {
  28. this._page = page;
  29. }
  30. async down(key) {
  31. await this._page._channel.keyboardDown({ key });
  32. }
  33. async up(key) {
  34. await this._page._channel.keyboardUp({ key });
  35. }
  36. async insertText(text) {
  37. await this._page._channel.keyboardInsertText({ text });
  38. }
  39. async type(text, options = {}) {
  40. await this._page._channel.keyboardType({ text, ...options });
  41. }
  42. async press(key, options = {}) {
  43. await this._page._channel.keyboardPress({ key, ...options });
  44. }
  45. }
  46. class Mouse {
  47. constructor(page) {
  48. this._page = page;
  49. }
  50. async move(x, y, options = {}) {
  51. await this._page._channel.mouseMove({ x, y, ...options });
  52. }
  53. async down(options = {}) {
  54. await this._page._channel.mouseDown({ ...options });
  55. }
  56. async up(options = {}) {
  57. await this._page._channel.mouseUp(options);
  58. }
  59. async click(x, y, options = {}) {
  60. await this._page._channel.mouseClick({ x, y, ...options });
  61. }
  62. async dblclick(x, y, options = {}) {
  63. await this._page._wrapApiCall(async () => {
  64. await this.click(x, y, { ...options, clickCount: 2 });
  65. }, { title: "Double click" });
  66. }
  67. async wheel(deltaX, deltaY) {
  68. await this._page._channel.mouseWheel({ deltaX, deltaY });
  69. }
  70. }
  71. class Touchscreen {
  72. constructor(page) {
  73. this._page = page;
  74. }
  75. async tap(x, y) {
  76. await this._page._channel.touchscreenTap({ x, y });
  77. }
  78. }
  79. // Annotate the CommonJS export names for ESM import in node:
  80. 0 && (module.exports = {
  81. Keyboard,
  82. Mouse,
  83. Touchscreen
  84. });